Re: How to evaluate parts of an expression, but not other parts?
- To: mathgroup at smc.vnet.net
- Subject: [mg122689] Re: How to evaluate parts of an expression, but not other parts?
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Sun, 6 Nov 2011 05:55:23 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201111050945.EAA10308@smc.vnet.net>
a = f[x]; b = g[x]; c = 2 f[x]; d = f[x] + 3 g[x]; expr = Hold[((a + b) + (c + d))]; ReplacePart[expr, { Position[expr, Literal[a]] -> a, Position[expr, Literal[b]] -> b, Position[expr, Literal[c]] -> c, Position[expr, Literal[d]] -> d}] Hold[(f[x] + g[x]) + (2 f[x] + (f[x] + 3 g[x]))] Bob Hanlon On Sat, Nov 5, 2011 at 5:45 AM, Julian Francis <julian.w.francis at gmail.com> wrote: > Dear all, > > I'd like to use the TreePlot function to visualise the expression of a > dynamic programming problem I am working on. > > If I have something like: ( (a+b) + (c+d ) > > Mathematica helpfully simplifies this to: a + b + c + d > > But I'd prefer it to be in the original form. > > I can't write Hold[ ( (a+b) + (c+d) )] because I do want a,b,c & d to > be evaluated. > > I want to write something like: > Hold[ ( (Evaluate[a]+Evaluate[b]) + (Evaluate[c]+Evaluate[d]) ) ] > > But this just leaves the Evaluate expressions unevaluated. > > Any help greatly appreciated. > > Thanks, > Julian. >
- References:
- How to evaluate parts of an expression, but not other parts?
- From: Julian Francis <julian.w.francis@gmail.com>
- How to evaluate parts of an expression, but not other parts?