Detecting conservation, loss, or gain in a crafting game with items and recipes

Suppose we’re designing a game like Minecraft where we have lots of items $ i_1,i_2,…,i_n\in I$ and a bunch of recipes $ r_1,r_2,…,r_m\in R$ . Recipes are functions $ r:(I\times\mathbb{N})^n\rightarrow I\times\mathbb{N}$ , that is they take some items with non-negative integer weights and produce an integer quantity of another item.

For example, the recipe for cake in Minecraft is:

3 milk + 3 wheat + 2 sugar + 1 egg $ \rightarrow$ 1 cake

… and the recipe for torches is:

1 stick + 1 coal $ \rightarrow$ 4 torches

Some recipes could even be reversible, for example: 9 diamonds $ \leftrightarrow$ 1 diamond block

If there’s some combination of recipes we can repeatedly apply to get more of the items that we started with then the game is poorly balanced and this can be exploited by players. It’s more desirable that we design the game with recipes that conserve items or possibly lose some items (thermodynamic entropy in the real world – you can’t easily un-burn the toast).

Is there an efficient algorithm that can decide if a set of recipes will:

  • conserve items?
  • lose items to inefficiency?
  • gain items?

Is there an efficient algorithm that can find the problematic recipes if a game is imbalanced?

My first thoughts are that there is a graph structure / maximum flow problem here but it’s very complex, and that it resembles a knapsack problem. Or maybe it could be formulated as a SAT problem – this is what I’m considering to code it at the moment but something more efficient might exist.

We could encode recipes in a matrix $ \mathbf{R}^{m \times n}$ where rows correspond to recipes and columns correspond to items. Column entries are negative if an item is consumed by a recipe, positive if it’s produced by the recipe, and zero if it’s unused. Similar to a well known matrix method for graph cycle detection, we could raise $ \mathbf{R}$ to some high power and get sums of each row to see if item totals keep going up, stay balanced, or go negative. However, I’m not confident this always works.

Any discussion, code, or recommended reading is very appreciated.

Are there rules (or at least relevant statements) in 5e about conservation of mass with magic?

Since some spells (such as enlarge/reduce) seem to reduce or increase the amount of mass that is present in game-play with no explanation as to how this happens, some interpret that to mean that conservation of mass is “thrown out the window” in 5e.

However, another view is that the RAW is silent on how those spells work, which leaves it up to the DM to either enforce or discard conservation of mass. The detailed mechanics of enlarge, for example, might be that it draws molecular matter from deep within the earth and/or from the environment or atmosphere, or even from another plane, such that conservation of mass holds true. Or then again, it might not. The spell description doesn’t say.

In a couple of answers about 3.5e (such as this one and this one), it has been softly asserted that conservation of mass is not really respected in D&D, and the topic was touched upon in comments to an answer to a 5e question, but the issue has not been definitively put to rest, that I can see.

Is this indeed ambiguous according to RAW, perhaps intentionally (perhaps the rules authors are avoiding over-managing the campaign settings of various tables)? To put it differently: Is the RAW silent on conservation of mass? Or is there a definitive RAW answer to this somewhere that I have not come across?

How would one simulate the law of conservation of energy?

I’m new to computer science, but I’ve studied physics for a while. I’m just curious, if one wanted to make a simulation of the law of conservation of energy, on a large scale, how would it be done? Most simulations take shortcuts for objects off screen, or may even skip them entirely during iterations. The objects may be frozen in place of screen, or grouped together if not interacting. Can these tricks be applied when simulating conservation of energy, without violating the law? Thanks.

Existence and uniqueness of entropy solutions for a scalar conservation law

Consider the conservation law

$ $ (\ast) \qquad u_t + \partial_x(u^\alpha) = 0$ $ where $ \alpha > 0$ .

For what values of $ \alpha$ is it known that there exists a (unique) entropy solution for the initial value problem associated to $ (\ast)$ ?

In particular, I’m interested in knowing what happens in the case $ \alpha \in (1,3]$ .

Find weak solution for conservation law


We have equation: $ u_t + 2 u u_x = 0 $ and characteristics are given by $ t’ = 1 $ and $ x’ = 2u $ and $ u’ = 0$ and so $ u = const$ , $ t = s$ , $ x = 2 u s + r $ so that $ $ x = 2 u(x,0) t + r $ $ are characteristicts. so that $ $ x = \begin{cases} 2 u_l t + r, \; \; r < 0 \ 2 u_r t + r, \; \; r > 0 \end{cases} $ $ so thereis a shock formation at $ x=0$ . Any help in how to continue this problem?

Deformation gradient conservation law from Larangian to Eulerian formulation

In the following, I use the standard notation for (solid) mechanics and conservation laws, i.e. $ F$ the formation gradient, $ H$ the cofactor, $ v$ the velocity field and $ J$ the Jacobian. Moreover, $ X$ is for the initial configuration where functions and fields are expressed using a bar and $ x$ is for the mapped {current) configuration.

The rate of deformation gradient can be expressed as: $ \frac{\partial F}{\partial t} = \nabla \bar{v} $ .

Now I know how to derive the total (TLF) $ \frac{d}{dt}\int_V F \; dV = \int_{\partial V} \bar{v}\otimes N \; dA$ and updated (ULF) $ \int_{v(t)} J^{-1} \left.\frac{\partial F}{\partial t}\right\vert_{X} \; dv = \int_{v(t)} \nabla\cdot (v\otimes H) dv$ lagrangian formulations.

I would like to get, if it exists, the Eulerian formulation of the above, as well as the ALE and Total ALE formulation of it.

To do so, I tried to start from TLF, I switch to the current configuration $ v(t)$ using $ J$ and I use the Reynold’s transport theorem to get rid of the total time derivative on the integral and to get the convective term. I end up with:

$ \int_{v(t)} \frac{\partial J^{-1}F}{\partial t} + \nabla\cdot(J^{-1}F\otimes v) \; dv = \int_{v(t)} \nabla\cdot (v\otimes H^{-1}) \; dv$

Are the mathematics correct? And can I reach these formulations? May I say that I prefer integral forms..