Karim Belabas on Thu, 22 Jul 2004 10:25:47 +0200

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

 Re: Constructing polynomials

```* Justin Walker [2004-07-22 04:53]:
> I would like to construct a polynomial/series dynamically, ending up
> with an "object" that I can evaluate, a la "f(1)", where 'f' is the
> thing constructed.
>
> I've looked through the doc and the archives (although it's hard to
> know what to look for), and don't see any indication that it's
> possible.
>
> In psuedo-code terms, I'd like to do something like
>
> MyProc(a,b)=
> {
>     f(x)=(x+a)^b;
>     for (i=1,limit, print(f(i)));
> }
>
> Is this (a) feasible; (b) not easy; (c) Forgetaboutit?

Why not:

MyProc(a,b)=
{
f=(x+a)^b;
for (i=1,limit, print(subst(f, x, i)));
}

? If you insist on defining a user function, then you can use

MyProc(a,b)=
{
( f(x) = (x+a)^b );
for (i=1,limit, print(f(i)));
}

[ which is more efficient using the standard GP parser ]

Cheers,

Karim.
--
Karim Belabas                     Tel: (+33) (0)1 69 15 57 48
Dep. de Mathematiques, Bat. 425   Fax: (+33) (0)1 69 15 60 19
Universite Paris-Sud              http://www.math.u-psud.fr/~belabas/
F-91405 Orsay (France)            http://pari.math.u-bordeaux.fr/  [PARI/GP]

```