[Date Index]
[Thread Index]
[Author Index]
MapAt changes its response towards different expressions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg55473] MapAt changes its response towards different expressions
*From*: Jacco van Beek <jabe at nmr.phys.chem.ethz.ch>
*Date*: Fri, 25 Mar 2005 05:48:15 -0500 (EST)
*Organization*: Swiss Federal Institute of Technology (ETHZ)
*Sender*: owner-wri-mathgroup at wolfram.com
I have noticed that when I use MapAt to evaluate similar expressions of
form MapAt[Evaluate, Hold[Expression], Coordinates] that Mathematica
(version 5.1, Solaris) somehow executes these differently. The following
example from below demonstrates the problem:
I have defined a function MXP that produces an output statement and
furthermore returns the input expression. I also define three similar
expressions TRS which are all on Hold and which are of form
Hold[a*MXP[b]+c], where a, b and c are either numbers or expressions. I
replace all occurences of Times in the TRS expressions by a temporary
function TempTimes, which is not defined. Then I locate the position of
the TempTimes within the TRS expressions, and use this as coordinates
for the MapAt function. The following example shows a different
execution in the second example even though the expression is very
similar to the other two. Somehow, in the second example the call to MXP
is evaluated, thus causing the output "Hello", and an error in my real
application of a similar construct.
Is this normal behaviour or is this a bug? It's easily solved by adding
a 0 to all terms but I'd like to know what's causing this.
Jacco van Beek
ETH Zuerich
Sample code:
$Pre=.;
MXP[xxx_] := Module[{}, Print["Hello"]; Return[xxx]];
TRS = Hold[MXP[SPR[1,x]SPR[2,y]]]//.{Times :> TempTimes}
Position[TRS, _TempTimes]
MapAt[Evaluate, TRS, Position[TRS, _TempTimes]]
Out[47]= Hold[MXP[TempTimes[SPR[1,x],SPR[2,y]]]]
Out[48]= {{1,1}}
Out[49]= Hold[MXP[Evaluate[TempTimes[SPR[1,x],SPR[2,y]]]]]
TRS = Hold[3*MXP[SPR[1,x]SPR[2,y]]]//.{Times :> TempTimes}
Position[TRS, _TempTimes]
MapAt[Evaluate, TRS, Position[TRS, _TempTimes]]
Out[50]= Hold[TempTimes[3,MXP[TempTimes[SPR[1,x],SPR[2,y]]]]]
Out[51]= {{1,2,1},{1}}
From In[50]:= Hello
Out[52]= Hold[TempTimes[3,TempTimes[SPR[1,x],SPR[2,y]]]]
TRS = Hold[3*MXP[SPR[1,x]SPR[2,y]]+0]//.{Times :> TempTimes}
Position[TRS, _TempTimes]
MapAt[Evaluate, TRS, Position[TRS, _TempTimes]]
Out[53]= Hold[TempTimes[3,MXP[TempTimes[SPR[1,x],SPR[2,y]]]]+0]
Out[54]= {{1,1,2,1},{1,1}}
Out[55]=
Hold[Evaluate[TempTimes[3,MXP[Evaluate[TempTimes[SPR[1,x],SPR[2,y]]]]]]+0]
Prev by Date:
**Re: Hypergeometric integral looks wrong ?**
Next by Date:
**Re: FindFit & restricting fitting parameter**
Previous by thread:
**Re: symbolic quaternionic analysis**
Next by thread:
**Re: MapAt changes its response towards different expressions**
| |