I have a system for equations that is structured hierarchically:
- Level 0: these are base variables that I can measure from a process (e.g. a,b,c)
- Level 1: these are variables derived from Level 0 variables (e.g. d=a+b, e=bc)
- Level 2: these are variables derived from Level 1 variables (e.g. f=d

For all Levels >0 I have only expressions that use variables from one level below, but I want to express those in terms of Level 0 variables. In this case, I want to give Mathematica the expressions for a,b,c,d,e,f in the above form and have it show me that f=d*e=abc+b²c.

Thank you so much for any help
- a Mathematica beginner


Maybe I missed the point, but if you just copy and paste your expressions (and insert spaces to give multiplication) you get:

d = a + b;
e = b c;
f = d e

which gives you b (a + b) c, which is equivalent to your given f. Is this all you were asking?


I'm guessing you are looking for the list of replacements that need to be made going down to level 0 instead of just showing the level 0 results. Are you looking for something like this?

assignments[d] = a + b;
assignments[e] = b c;
assignments[f] = d e;
assignments[x_] := x;

FixedPointList[Map[assignments, #, {-1}] &, {f}][[;; -2, 1]]

{f, d e, b (a + b) c}

  • $\begingroup$ It really was that easy, thank you! I thought I had to keep everything in the format d[a_,b_]:=a+b $\endgroup$ – F. E. Apr 17 '15 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.