Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*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 2001

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

Search the Archive

Re: Recursive Rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg31152] Re: [mg31147] Recursive Rules
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sun, 14 Oct 2001 04:11:45 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I depends what you mean. The following are essentially equivalent

In[1]:=
f[t_] :=  a + b*f[t-1]

In[2]:=
f[1]=1;

In[3]:=
f[4]//Expand

Out[3]=
a + a*b + a*b^2 + b^3

and

In[4]:=
Clear[f]

In[5]:=
f[1]=1;

In[6]:=
a+b f[3]//.f[t_/;t>1]-> a + b*f[t-1]//Expand

Out[6]=
a + a*b + a*b^2 + b^3

On the other hand, the really important thing about your original 
example was "dynamic programming", produced by the construction 
f[t_]:=f[t] = ...  I don't think there is any way to do this using Rule 
for after all Rule does not assign any global values. (Maybe someone can 
think of some fiendish trick to do so but if so it will probably involve 
some sort of cheating, like using = somewhere )

Andrzej Kozlowski
Toyama International University
JAPAN
http://platon.c.u-tokyo.ac.jp/andrzej/

On Saturday, October 13, 2001, at 03:47  PM, Mark S. Coleman wrote:

> Greetings,
>
> I know that a recurrent/recursive function can be written
>
> f[t_] := f[t] = a + b*f[t-1].
>
> So that once an initial value is stipulated, e.g., f[0]=0, then the
> function "remembers" past values and can correctly calculate f[] for
> any t.
>
> I was wondering if it was possible to do the same thing with a Rule?
>
> Thanks,
>
> -Mark
>
>



  • Prev by Date: Re: How do I eliminate premultipliers of "1." ?
  • Next by Date: Re: How do I eliminate premultipliers of "1." ?
  • Previous by thread: Re: Recursive Rules
  • Next by thread: Problem with building mathlink programs