MathGroup Archive 2003

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

Search the Archive

Re: Operator that Adds Arguments

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44843] Re: Operator that Adds Arguments
  • From: drbob at bigfoot.com (Bobby R. Treat)
  • Date: Wed, 3 Dec 2003 04:24:36 -0500 (EST)
  • References: <bqb7ch$nu6$1@bob.news.rcn.net>
  • Sender: owner-wri-mathgroup at wolfram.com

It's not clear what you want to do, but I'll take a stab at it. I
suggest beginning your own symbols with small letters, f rather than
F, and I suggest using f[a], f[a,b], f[a,b,c] etc. rather than
f[[1]][a], f[[2]][a,b], f[[3]][a,b,c] as you seem to intend.

First a pretty general version, which defines f for more than 1
arguments:

f[a__, b_] := g[f[a], b]
f[a]
f[a, b]
f[a, b, c]
f[a, b, c,d]

For g=Plus, we have:

Clear[f]
g=Plus;
f[a__, b_] := g[f[a], b]
f[a]
f[a, b]
f[a, b, c]

or we can write it as

Clear[f]
f[a__, b_] := f[a] + b
f[a]
f[a, b]
f[a, b, c]

g can be any function, so there's a LOT of flexibility. In each case,
you still have to define f for a single argument, and there's a lot of
flexibility there, too ... so long as g[f[a],b] will be defined when
you need it.

If the recursions get to be a performance problem we can do it this
way:

Clear[f]
f[a__, b_] := f[a,b] = g[f[a], b]

That way each calculated value of f (for more than one argument) is
stored for later use, so the recursion is never repeated for a given
set of arguments. That's part of the so-called "dynamic programming"
idea -- the other part being the recursive definition itself.

Bobby

"Scott Guthery" <sguthery at rcn.com> wrote in message news:<bqb7ch$nu6$1 at bob.news.rcn.net>...
> I've got a recursion that adds an argument at each step
> and I'd like to say something like ...
> 
> L = Length[F]
> NextOne[F_] = Append[F, Function[F[[L]][#1, #2, ..., #L]+#[L+1]]]]
> 
> and have F[[L+1]] be a function of L+1 arguments.
> 
> Any suggestions?
> 
> Thanks for your help.
> 
> Cheers, Scott


  • Prev by Date: Re: Operator that Adds Arguments
  • Next by Date: Re: subscribe and ask questions
  • Previous by thread: Re: Operator that Adds Arguments
  • Next by thread: Re: Operator that Adds Arguments