Max Alekseyev on Sun, 26 Mar 2023 17:02:45 +0200

 Re: from t_POL to t_CLOSURE (and back)

• To: pari-users@pari.math.u-bordeaux.fr
• Subject: Re: from t_POL to t_CLOSURE (and back)
• From: Max Alekseyev <maxale@gmail.com>
• Date: Sun, 26 Mar 2023 11:00:56 -0400
• Delivery-date: Sun, 26 Mar 2023 17:02:45 +0200
• References: <CAJkPp5POGV5=LmFOTWr0f+-vgDANnsE6A6ot06YouUqxf7njYg@mail.gmail.com> <ZB91bujSOLFfbvS7@seventeen> <CAJkPp5P=+yb45NFt3oEunWBRn7PwrprxUQsaEvTF+zXMNcHdLg@mail.gmail.com> <CAJkPp5Ot=7NFVuma2B=+t16hgBBc870TPTwfv9Ld_tZcuuVWnA@mail.gmail.com>

f = eval(strprintf("%s -> %s", variable(p), p));
is a little bit more intuitive. Is it the best way available?
Regards,
Max

On Sun, Mar 26, 2023 at 10:51 AM Max Alekseyev <maxale@gmail.com> wrote:
Perhaps, I should clarify my question. The definition
f = z -> subst(p,variable(p),z)
looks inefficient (and ugly) to me. I'd like to have a direct way to get the corresponding t_CLOSURE from a given polynomial, like I'd do for a fixed polynomial:
f(x) = x^3 + x + 1

My best attempt so far is

? p = x^3 + x + 1
%1 = x^3 + x + 1
? eval(strprintf("f(%s) = %s", variable(p), p))
%2 = (x)->x^3+x+1
? type(f)
%3 = "t_CLOSURE"

It seems to archive what I want but using eval(strprintf(...)) is somewhat cumbersome.

Regards,
Max

On Sat, Mar 25, 2023 at 8:41 PM Max Alekseyev <maxale@gmail.com> wrote:
f(x)=eval(p) requires us to know that the variable of p is x, doesn't it?
This does not work:
f(variable(p)) = eval(p)

Regards,
Max

On Sat, Mar 25, 2023 at 6:28 PM Bill Allombert <Bill.Allombert@math.u-bordeaux.fr> wrote:
On Sat, Mar 25, 2023 at 05:54:10PM -0400, Max Alekseyev wrote:
> Is there any more straightforward/logical way than the following?
>
> ? p = x^3 + x + 1
> %1 = x^3 + x + 1
> ? type(p)
> %2 = "t_POL"
> ? f = z -> subst(p,variable(p),z)
> %3 = (z)->subst(p,variable(p),z)
> ? type(f)
> %4 = "t_CLOSURE"
> ? q = f('x)
> %5 = x^3 + x + 1
> ? type(q)
> %6 = "t_POL"

I do not know what is more straightforward/logical, but you can do

f(x)=eval(p)

Cheers,
Bill