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
djm...@comcast.net
http://home.comcast.net/~djmpark/