Re: Reducing a function to one argument
- To: mathgroup at smc.vnet.net
- Subject: [mg36166] Re: [mg36155] Reducing a function to one argument
- From: BobHanlon at aol.com
- Date: Mon, 26 Aug 2002 04:15:43 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 8/23/02 10:22:57 PM, nitlion at mindspring.com writes:
>I'm trying to figure out the correct syntax to do the following. I have
>some function with three arguments, and I want to syntactically describe
>the
>single-argument function that holds two of those arguments constant (i.e.
>without creating that single-argument function).
>
>More specifically, I have defined
>
> Machine[radix_,multiplier_,state_] := Module [{c,s},
> c = Floor[state/base]; s = Mod[state,base];
> multiplier*s + c
> ]
>
>where I have a generalize 'machine', defined by the radix and multiplier,
>which converts one state into another state. So I'd like to be able to
>do
>something like this:
>
> NestList[Machine[10,7,#], 3, 22]
>
>to get the series of states that the radix-10 multiplier-7 machine runs
>through (starting with state 3). However, this syntax doesn't seem to
>do
>what I want.
>
>I hope that description makes sense. It seems like there must be a syntax
>to describe the function Machine[10,7,#].
>
I assume that you want "base" rather than "radix" in the definition (or vice
versa).
Machine[base_, multiplier_, state_]:=
Module[{c, s},
c=Floor[state/base];
s=Mod[state, base];
multiplier*s+c];
NestList[Function[Machine[10,7,#]],3,22]
{3, 21, 9, 63, 27, 51, 12, 15, 36,
45, 39, 66, 48, 60, 6, 42, 18,
57, 54, 33, 24, 30, 3}
The abbreviation for Function[body] is body&
%==NestList[Machine[10, 7, #]&, 3, 22]
True
Bob Hanlon
Chantilly, VA USA