Re: delayed rule evaluation order
- To: mathgroup at smc.vnet.net
- Subject: [mg68002] Re: [mg67967] delayed rule evaluation order
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Thu, 20 Jul 2006 06:04:44 -0400 (EDT)
- References: <11710934.1153306359682.JavaMail.root@eastrmwml07.mgt.cox.net> <acbec1a40607190514x62d0f07byeb91cf8b496bca33@mail.gmail.com>
- Sender: owner-wri-mathgroup at wolfram.com
It seems to me that a variant of my first suggestion works fine:
In[1]:=
f[1]=1;
f[n_Integer]/;n>1=n f[n-1];
InputForm[z=Trace[f[2]]];
InputForm[z/.{HoldForm[a_]:>HoldForm@@{SetPrecision[a,3]}}]
Out[4]//InputForm=
{HoldForm[2.`2.9999999999999973],
{HoldForm[True], HoldForm[True]},
HoldForm[2.`2.9999999999999973],
{{HoldForm[1.`2.9999999999999973],
HoldForm[1.`2.9999999999999973]},
HoldForm[1.`2.9999999999999973],
HoldForm[1.`2.9999999999999973]},
HoldForm[2.`2.9999999999999973],
HoldForm[2.`2.9999999999999973]}
Or is this not what you wanted?
Andrzej Kozlowski
On 19 Jul 2006, at 14:14, Chris Chiasson wrote:
> Thanks to Kozlowski's, Hanlon's and Pein's solutions (haven't received
> any others so far), I am now using this type of replacement:
>
> Hold[5.55555555]/.{blah_?InexactNumberQ:>
> junk[SetPrecision[blah,3]]}/.junk->Evaluate
>
> Hold[5.56]
>
> However, this still does not totally work on Trace's output:
>
> In[1]:=
> f[1]=1;
> f[n_Integer]/;n>1=n f[n-1];
> InputForm[z=Trace[f[2]]]
>
> Out[3]//InputForm=
> {HoldForm[f[2]], {HoldForm[2 > 1], HoldForm[True]}, HoldForm[2*f[-1
> + 2]],
> {{HoldForm[-1 + 2], HoldForm[1]}, HoldForm[f[1]], HoldForm[1]},
> HoldForm[2*1], HoldForm[2]}
>
> In[4]:=
> InputForm[z/.{blah_?ExactNumberQ:>junk[SetPrecision[blah,3]]}/.junk-
> >Evaluate]
>
> Out[4]//InputForm=
> {HoldForm[2.`2.9999999999999996], {HoldForm[Evaluate[SetPrecision[2,
> 3]] > Evaluate[SetPrecision[1, 3]]],
> HoldForm[True]}, HoldForm[2.`2.9999999999999996],
> {{HoldForm[1.`2.9999999999999996], HoldForm[1.`2.9999999999999996]},
> HoldForm[1.`2.9999999999999996],
> HoldForm[1.`2.9999999999999996]}, HoldForm[2.`2.9999999999999996],
> HoldForm[2.`2.9999999999999996]}
>
> Notice the leftover Evaluate and SetPrecision commands. Does anyone
> have ideas on how to get this to work?
>
> On 7/19/06, Bob Hanlon <hanlonr at cox.net> wrote:
>> Hold[{2, 3}] /.
>> {Hold[{x_, y_}] :> Hold[Evaluate[x^y]]}
>>
>> Hold[8]
>>
>>
>> Bob Hanlon
>>
>> ---- Chris Chiasson <chris at chiasson.name> wrote:
>> > Hold[{2, 3}] /. {{x_, y_} :> x^y}
>> >
>> > the result is Hold[Power[2,3]]
>> >
>> > I would like the result to be Hold[8]
>> >
>> > The original context is post-processing of a large Trace output
>> (via
>> > SetPrecision to get rid of digits and improve readability).
>> >
>> > Any ideas?
>> >
>> > --
>> > http://chris.chiasson.name/
>> >
>>
>> --
>>
>> Bob Hanlon
>> hanlonr at cox.net
>>
>>
>>
>
>
> --
> http://chris.chiasson.name/