Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Recursion inspection technique : HoldForm but release variables

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66420] Re: Recursion inspection technique : HoldForm but release variables
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 11 May 2006 05:36:25 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <e3um8v$hfr$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

flatmax wrote:
> Hi,
> 
> If I define a recursion and hold its form to inspect it :
> Clear[test]
> test[j_Integer?Positive] :=
>                               test[j] = k[j] HoldForm[ test[j - 1] ]
> 
> then This is what happens :
> 
>    In[22]:= test[4]
> 
> Out[22]:= test[4 - 1] k[4]
> 
> But I would like it to be with the variable evaluated :
> 
> Out[22]:= test[3] k[4]
> 
> Whats the trick ???
> 
> thanks
> Matt InIn
> 
Hi Matt,

Use *ReleaseHold* [1] (see In[5]) to go step by step or a transformation 
rule applied repeatedly (*ReplaceRepeated* or //., not /.) [2] to 
release all the *HoldForm* {see In[6]).

In[1]:=
Clear[test];
test[0] = 1;
test[(j_Integer)?Positive] :=
   test[j] = k[j]*HoldForm[test[j - 1]]

In[4]:=
test[4]

Out[4]=
test[4-1] k[4]

In[5]:=
ReleaseHold[%]

Out[5]=
test[3-1] k[3] k[4]

In[6]:=
test[4] //. HoldForm[x_] :> ReleaseHold[HoldForm[x]]

Out[6]=
k[1] k[2] k[3] k[4]

Best regards,
Jean-Marc

[1] http://documents.wolfram.com/mathematica/functions/ReleaseHold

[2] http://documents.wolfram.com/mathematica/functions/ReplaceRepeated


  • Prev by Date: Re: Dynamic iterators in Do loop
  • Next by Date: Re: Evaluating integrals
  • Previous by thread: Recursion inspection technique : HoldForm but release variables
  • Next by thread: Re: Recursion inspection technique : HoldForm but release variables