### Re: function algebra

Daniel Ehrenberg <littledanehren <at> yahoo.com>

2003-11-01 04:42:41 GMT

> I couldn't stand not doing it :)
> It's a bit less readable, but should handle any
> numerical operation.
> It also handles the case of "f=Fun(math.sin) + 5"
> (so that in this case
> f(x) will be math.sin(x) + 5), plus it does
> composition:
>
> >>> cos=Fun(math.cos)
> >>> cs = cos.compose(math.sin)
> >>> cs(1)
> 0.66636674539288054
> >>> math.cos(math.sin(1))
> 0.66636674539288054
> >>>
>
> ------8<-------------
> # we don't need to add ____iadd____ and such as those
> fall back to using
> # ____add____ etc.
> unary_operators=['____neg____', '____pos____', '____abs____',
> '____invert____',
> '____complex____', '____int____',
> '____long____', '____float____',
> '____oct____', '____hex____']
> binary_operators=['____add____','____sub____','____mul____',
> '____floordiv____',
> '____mod____', '____divmod____',
> '____lshift____', '____rshift____',
> '____and____', '____xor____', '____or____',

(Continue reading)