Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6230 > unrolled thread
| Started by | "David Park" <djmpark@comcast.net> |
|---|---|
| First post | 2011-11-06 11:02 +0000 |
| Last post | 2011-11-08 12:15 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How to evaluate parts of an expression, but not other parts? "David Park" <djmpark@comcast.net> - 2011-11-06 11:02 +0000
Re: How to evaluate parts of an expression, but not other parts? "andre.robin3" <andre.robin3@wanadoo.fr> - 2011-11-07 10:51 +0000
Re: How to evaluate parts of an expression, but not other parts? "andre.robin3" <andre.robin3@wanadoo.fr> - 2011-11-08 12:20 +0000
Re: How to evaluate parts of an expression, but not other parts? Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2011-11-08 12:15 +0000
| From | "David Park" <djmpark@comcast.net> |
|---|---|
| Date | 2011-11-06 11:02 +0000 |
| Subject | Re: How to evaluate parts of an expression, but not other parts? |
| Message-ID | <j95pg2$m87$1@smc.vnet.net> |
I'm sure that you will obtain some answers to do this with plain
Mathematica, but the Presentations package does have routines that allow
selective manipulation of expressions.
Along with HoldForm your can use EvaluateAt or EvaluateAtPattern to do
selective evaluations of held expressions. You can also use
CreateSubexpression, OperateSubexlression and ReleaseSubexpressions to tag
and group things together to prevent Mathematica from mixing there elements
with other elements outside the subexpressions. Tagged Subexpressions also
show the tag in a tooltip when the mouse hovers over the Subexpression. We
also have MapLevelParts that allows an operation to be performed on selected
level parts in an expression (usually a sum, product or list).
So, as a simple example we could do:
<<Presentations`
a = 1; b = 2; c = 3; d = 4;
HoldForm[a + b] + HoldForm[c + d]
% // EvaluateAt[{1, 1}]
% // EvaluateAt[{2, 1}]
% // ReleaseHold
(a+b)+(c+d)
3+(c+d)
3+7
10
Using tagged Subexpressions we could do the following. We can also specify
that a subexpression should always show parentheses.
a = 1; b = 2; c = 3; d = 4;
CreateSubexpression[HoldForm[a + b], True, tag1] +
CreateSubexpression[HoldForm[c + d], True, tag2]
% // OperateSubexpression[ReleaseHold, tag1]
% // OperateSubexpression[ReleaseHold, tag2]
% // ReleaseSubexpressions[All]
(a+b)+(c+d)
(3)+(c+d)
(3)+(7)
10
If we want to show the individual values before they are combined in a
Subexpression we could use nested Subexpressions and the following more
complicated construction.
Clear[a, b, c, d]
step1 = Plus @@
MapThread[
CreateSubexpression[#1, #2] &, {HoldForm /@ {a, b, c, d}, {taga,
tagb, tagc, tagd}}]
a = 1; b = 2; c = 3; d = 4;
step2 = step1 //
MapLevelParts[CreateSubexpression[#, tagcd] &, {{3, 4}}];
step3 = step2 //
MapLevelParts[CreateSubexpression[#, tagab] &, {{1, 2}}]
step4 = Fold[OperateSubexpression[ReleaseHold, #2][#1] &,
step3, {taga, tagb, tagc, tagd}]
step5 = Fold[ReleaseSubexpressions[#2][#1] &,
step4, {taga, tagb, tagc, tagd}]
FixedPoint[ReleaseSubexpressions[All], step5]
(a)+(b)+(c)+(d)
((a)+(b))+((c)+(d))
((1)+(2))+((3)+(4))
(3)+(7)
10
David Park
djmpark@comcast.net
http://home.comcast.net/~djmpark/
From: Julian Francis [mailto:julian.w.francis@gmail.com]
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.
[toc] | [next] | [standalone]
| From | "andre.robin3" <andre.robin3@wanadoo.fr> |
|---|---|
| Date | 2011-11-07 10:51 +0000 |
| Message-ID | <j98d70$3ka$1@smc.vnet.net> |
| In reply to | #6230 |
EvaluateAt[] is not part of Mathematica.
So far I kown it was a idea from Villegas (from Wolfram, see his
presentation
"workingwith unevaluated expression". It is not for beginners).
Ted Ersek also has developped a EvaluateAt[].
For such a problem I suggest rather to try to use Mathematica
existing functions. (there are so many !)
"David Park" <djmpark@comcast.net> a écrit dans le message de news:
j95pg2$m87$1@smc.vnet.net...
> I'm sure that you will obtain some answers to do this with plain
> Mathematica, but the Presentations package does have routines that allow
> selective manipulation of expressions.
>
> Along with HoldForm your can use EvaluateAt or EvaluateAtPattern to do
> selective evaluations of held expressions. You can also use
> CreateSubexpression, OperateSubexlression and ReleaseSubexpressions to tag
> and group things together to prevent Mathematica from mixing there
> elements
> with other elements outside the subexpressions. Tagged Subexpressions also
> show the tag in a tooltip when the mouse hovers over the Subexpression. We
> also have MapLevelParts that allows an operation to be performed on
> selected
> level parts in an expression (usually a sum, product or list).
>
> So, as a simple example we could do:
>
> <<Presentations`
>
> a = 1; b = 2; c = 3; d = 4;
> HoldForm[a + b] + HoldForm[c + d]
> % // EvaluateAt[{1, 1}]
> % // EvaluateAt[{2, 1}]
> % // ReleaseHold
>
> (a+b)+(c+d)
>
> 3+(c+d)
>
> 3+7
>
> 10
>
> Using tagged Subexpressions we could do the following. We can also specify
> that a subexpression should always show parentheses.
>
> a = 1; b = 2; c = 3; d = 4;
> CreateSubexpression[HoldForm[a + b], True, tag1] +
> CreateSubexpression[HoldForm[c + d], True, tag2]
> % // OperateSubexpression[ReleaseHold, tag1]
> % // OperateSubexpression[ReleaseHold, tag2]
> % // ReleaseSubexpressions[All]
>
> (a+b)+(c+d)
>
> (3)+(c+d)
>
> (3)+(7)
>
> 10
>
> If we want to show the individual values before they are combined in a
> Subexpression we could use nested Subexpressions and the following more
> complicated construction.
>
> Clear[a, b, c, d]
> step1 = Plus @@
> MapThread[
> CreateSubexpression[#1, #2] &, {HoldForm /@ {a, b, c, d}, {taga,
> tagb, tagc, tagd}}]
> a = 1; b = 2; c = 3; d = 4;
> step2 = step1 //
> MapLevelParts[CreateSubexpression[#, tagcd] &, {{3, 4}}];
> step3 = step2 //
> MapLevelParts[CreateSubexpression[#, tagab] &, {{1, 2}}]
> step4 = Fold[OperateSubexpression[ReleaseHold, #2][#1] &,
> step3, {taga, tagb, tagc, tagd}]
> step5 = Fold[ReleaseSubexpressions[#2][#1] &,
> step4, {taga, tagb, tagc, tagd}]
> FixedPoint[ReleaseSubexpressions[All], step5]
>
> (a)+(b)+(c)+(d)
>
> ((a)+(b))+((c)+(d))
>
> ((1)+(2))+((3)+(4))
>
> (3)+(7)
>
> 10
>
>
> David Park
> djmpark@comcast.net
> http://home.comcast.net/~djmpark/
>
>
> From: Julian Francis [mailto:julian.w.francis@gmail.com]
>
> 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.
>
>
[toc] | [prev] | [next] | [standalone]
| From | "andre.robin3" <andre.robin3@wanadoo.fr> |
|---|---|
| Date | 2011-11-08 12:20 +0000 |
| Message-ID | <j9b6r3$4tp$1@smc.vnet.net> |
| In reply to | #6243 |
sorry, I didn't saw the introducing text in the mail from David Park
yesterday.
All is OK.
"andre.robin3" <andre.robin3@wanadoo.fr> a écrit dans le message de news:
j98d70$3ka$1@smc.vnet.net...
> EvaluateAt[] is not part of Mathematica.
>
> So far I kown it was a idea from Villegas (from Wolfram, see his
> presentation
> "workingwith unevaluated expression". It is not for beginners).
> Ted Ersek also has developped a EvaluateAt[].
>
> For such a problem I suggest rather to try to use Mathematica
> existing functions. (there are so many !)
>
>
>
> "David Park" <djmpark@comcast.net> a écrit dans le message de news:
> j95pg2$m87$1@smc.vnet.net...
>> I'm sure that you will obtain some answers to do this with plain
>> Mathematica, but the Presentations package does have routines that allow
>> selective manipulation of expressions.
>>
>> Along with HoldForm your can use EvaluateAt or EvaluateAtPattern to do
>> selective evaluations of held expressions. You can also use
>> CreateSubexpression, OperateSubexlression and ReleaseSubexpressions to
>> tag
>> and group things together to prevent Mathematica from mixing there
>> elements
>> with other elements outside the subexpressions. Tagged Subexpressions
>> also
>> show the tag in a tooltip when the mouse hovers over the Subexpression.
>> We
>> also have MapLevelParts that allows an operation to be performed on
>> selected
>> level parts in an expression (usually a sum, product or list).
>>
>> So, as a simple example we could do:
>>
>> <<Presentations`
>>
>> a = 1; b = 2; c = 3; d = 4;
>> HoldForm[a + b] + HoldForm[c + d]
>> % // EvaluateAt[{1, 1}]
>> % // EvaluateAt[{2, 1}]
>> % // ReleaseHold
>>
>> (a+b)+(c+d)
>>
>> 3+(c+d)
>>
>> 3+7
>>
>> 10
>>
>> Using tagged Subexpressions we could do the following. We can also
>> specify
>> that a subexpression should always show parentheses.
>>
>> a = 1; b = 2; c = 3; d = 4;
>> CreateSubexpression[HoldForm[a + b], True, tag1] +
>> CreateSubexpression[HoldForm[c + d], True, tag2]
>> % // OperateSubexpression[ReleaseHold, tag1]
>> % // OperateSubexpression[ReleaseHold, tag2]
>> % // ReleaseSubexpressions[All]
>>
>> (a+b)+(c+d)
>>
>> (3)+(c+d)
>>
>> (3)+(7)
>>
>> 10
>>
>> If we want to show the individual values before they are combined in a
>> Subexpression we could use nested Subexpressions and the following more
>> complicated construction.
>>
>> Clear[a, b, c, d]
>> step1 = Plus @@
>> MapThread[
>> CreateSubexpression[#1, #2] &, {HoldForm /@ {a, b, c, d}, {taga,
>> tagb, tagc, tagd}}]
>> a = 1; b = 2; c = 3; d = 4;
>> step2 = step1 //
>> MapLevelParts[CreateSubexpression[#, tagcd] &, {{3, 4}}];
>> step3 = step2 //
>> MapLevelParts[CreateSubexpression[#, tagab] &, {{1, 2}}]
>> step4 = Fold[OperateSubexpression[ReleaseHold, #2][#1] &,
>> step3, {taga, tagb, tagc, tagd}]
>> step5 = Fold[ReleaseSubexpressions[#2][#1] &,
>> step4, {taga, tagb, tagc, tagd}]
>> FixedPoint[ReleaseSubexpressions[All], step5]
>>
>> (a)+(b)+(c)+(d)
>>
>> ((a)+(b))+((c)+(d))
>>
>> ((1)+(2))+((3)+(4))
>>
>> (3)+(7)
>>
>> 10
>>
>>
>> David Park
>> djmpark@comcast.net
>> http://home.comcast.net/~djmpark/
>>
>>
>> From: Julian Francis [mailto:julian.w.francis@gmail.com]
>>
>> 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.
>>
>>
>
>
>
[toc] | [prev] | [next] | [standalone]
| From | Andrzej Kozlowski <akoz@mimuw.edu.pl> |
|---|---|
| Date | 2011-11-08 12:15 +0000 |
| Message-ID | <j9b6gi$4pu$1@smc.vnet.net> |
| In reply to | #6230 |
It is called the Strzebonski-Trott (or Trott-Strzebonski) trick - after
the people who first noticed it (or at least made it public). Villegas
just reported it (with proper credit).
Andrzej Kozlowski
On 7 Nov 2011, at 11:50, andre.robin3 wrote:
> EvaluateAt[] is not part of Mathematica.
>
> So far I kown it was a idea from Villegas (from Wolfram, see his
> presentation
> "workingwith unevaluated expression". It is not for beginners).
> Ted Ersek also has developped a EvaluateAt[].
>
> For such a problem I suggest rather to try to use Mathematica
> existing functions. (there are so many !)
>
>
>
> "David Park" <djmpark@comcast.net> a =E9crit dans le message de news:
> j95pg2$m87$1@smc.vnet.net...
>> I'm sure that you will obtain some answers to do this with plain
>> Mathematica, but the Presentations package does have routines that allow
>> selective manipulation of expressions.
>>
>> Along with HoldForm your can use EvaluateAt or EvaluateAtPattern to do
>> selective evaluations of held expressions. You can also use
>> CreateSubexpression, OperateSubexlression and ReleaseSubexpressions to tag
>> and group things together to prevent Mathematica from mixing there
>> elements
>> with other elements outside the subexpressions. Tagged Subexpressions also
>> show the tag in a tooltip when the mouse hovers over the Subexpression. We
>> also have MapLevelParts that allows an operation to be performed on
>> selected
>> level parts in an expression (usually a sum, product or list).
>>
>> So, as a simple example we could do:
>>
>> <<Presentations`
>>
>> a = 1; b = 2; c = 3; d = 4;
>> HoldForm[a + b] + HoldForm[c + d]
>> % // EvaluateAt[{1, 1}]
>> % // EvaluateAt[{2, 1}]
>> % // ReleaseHold
>>
>> (a+b)+(c+d)
>>
>> 3+(c+d)
>>
>> 3+7
>>
>> 10
>>
>> Using tagged Subexpressions we could do the following. We can also specify
>> that a subexpression should always show parentheses.
>>
>> a = 1; b = 2; c = 3; d = 4;
>> CreateSubexpression[HoldForm[a + b], True, tag1] +
>> CreateSubexpression[HoldForm[c + d], True, tag2]
>> % // OperateSubexpression[ReleaseHold, tag1]
>> % // OperateSubexpression[ReleaseHold, tag2]
>> % // ReleaseSubexpressions[All]
>>
>> (a+b)+(c+d)
>>
>> (3)+(c+d)
>>
>> (3)+(7)
>>
>> 10
>>
>> If we want to show the individual values before they are combined in a
>> Subexpression we could use nested Subexpressions and the following more
>> complicated construction.
>>
>> Clear[a, b, c, d]
>> step1 = Plus @@
>> MapThread[
>> CreateSubexpression[#1, #2] &, {HoldForm /@ {a, b, c, d}, {taga,
>> tagb, tagc, tagd}}]
>> a = 1; b = 2; c = 3; d = 4;
>> step2 = step1 //
>> MapLevelParts[CreateSubexpression[#, tagcd] &, {{3, 4}}];
>> step3 = step2 //
>> MapLevelParts[CreateSubexpression[#, tagab] &, {{1, 2}}]
>> step4 = Fold[OperateSubexpression[ReleaseHold, #2][#1] &,
>> step3, {taga, tagb, tagc, tagd}]
>> step5 = Fold[ReleaseSubexpressions[#2][#1] &,
>> step4, {taga, tagb, tagc, tagd}]
>> FixedPoint[ReleaseSubexpressions[All], step5]
>>
>> (a)+(b)+(c)+(d)
>>
>> ((a)+(b))+((c)+(d))
>>
>> ((1)+(2))+((3)+(4))
>>
>> (3)+(7)
>>
>> 10
>>
>>
>> David Park
>> djmpark@comcast.net
>> http://home.comcast.net/~djmpark/
>>
>>
>> From: Julian Francis [mailto:julian.w.francis@gmail.com]
>>
>> 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.
>>
>>
>
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web