ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 05 Mar 2022 21:19:53 +0100Partial evaluation of a MV Polynomial.https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/I have a polynomial defined as:
q = next_prime(2^128)
P.< x1, x2, x3, x4, x5> = GF(q)[]
p = (x1*x2) + (x3*x4)
I would like to obtain the resulting polynomial by partially evaluating by some variables.
Example partial polynomial p' generated by evaluating p at x2 = 2:
p' = (2*x1) + (x3*x4)
Is there a way to accomplish this?Sat, 05 Mar 2022 15:29:56 +0100https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/Answer by Emmanuel Charpentier for <p>I have a polynomial defined as:</p>
<pre><code>q = next_prime(2^128)
P.< x1, x2, x3, x4, x5> = GF(q)[]
p = (x1*x2) + (x3*x4)
</code></pre>
<p>I would like to obtain the resulting polynomial by partially evaluating by some variables. </p>
<p>Example partial polynomial p' generated by evaluating p at x2 = 2:</p>
<pre><code>p' = (2*x1) + (x3*x4)
</code></pre>
<p>Is there a way to accomplish this?</p>
https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?answer=61409#post-id-61409Simple:
sage: q = next_prime(2^128)
sage: p = (x1*x2) + (x3*x4)
sage: p(x2=2)
x3*x4 + 2*x1
But note that :
sage: p.subs(x2==2)
x1*x2 + x3*x4
doesn't work.
HTH,
Sat, 05 Mar 2022 18:17:26 +0100https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?answer=61409#post-id-61409Comment by Emmanuel Charpentier for <p>Simple:</p>
<pre><code>sage: q = next_prime(2^128)
sage: p = (x1*x2) + (x3*x4)
sage: p(x2=2)
x3*x4 + 2*x1
</code></pre>
<p>But note that :</p>
<pre><code>sage: p.subs(x2==2)
x1*x2 + x3*x4
</code></pre>
<p>doesn't work.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?comment=61417#post-id-61417> The term x1 disappearing shouldn't mean a polynomial doesn't have that variable as an input.
Nothing "disappears" :
sage: p=x1*x2+x3
sage: p(x2=0)
x3
sage: p(x2=0)(x1=3)
x3
sage: p(x2=0, x1=3)
x3
sage: p(x4=17)
x1*x2 + x3
*Any* polynomial element of P can be evaluated for any value of any P coefficient, whether it appears explicitly in the polynomial or not. Furthermore :
sage: p(x2=3*x1-2*x4)
3*x1^2 + 340282366920938463463374607431768211505*x1*x4 + x3
As this latter example shows, integer constants are coerced into elements of the base ring... In other words :
sage: p(x2=0, x1=3).parent()
Multivariate Polynomial Ring in x1, x2, x3, x4, x5 over Finite Field of size 340282366920938463463374607431768211507
HTH,Sat, 05 Mar 2022 21:13:04 +0100https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?comment=61417#post-id-61417Comment by Emmanuel Charpentier for <p>Simple:</p>
<pre><code>sage: q = next_prime(2^128)
sage: p = (x1*x2) + (x3*x4)
sage: p(x2=2)
x3*x4 + 2*x1
</code></pre>
<p>But note that :</p>
<pre><code>sage: p.subs(x2==2)
x1*x2 + x3*x4
</code></pre>
<p>doesn't work.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?comment=61418#post-id-61418I **strongly** recommend reading [this book](https://epubs.siam.org/doi/book/10.1137/1.9781611975468), freely [available](http://dl.lateralis.org/public/sagebook/sagebook-ba6596d.pdf)...Sat, 05 Mar 2022 21:19:53 +0100https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?comment=61418#post-id-61418Comment by cryptoqs for <p>Simple:</p>
<pre><code>sage: q = next_prime(2^128)
sage: p = (x1*x2) + (x3*x4)
sage: p(x2=2)
x3*x4 + 2*x1
</code></pre>
<p>But note that :</p>
<pre><code>sage: p.subs(x2==2)
x1*x2 + x3*x4
</code></pre>
<p>doesn't work.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?comment=61415#post-id-61415Alright, after working on it a little bit, I think that this behaviour is not implemented correctly. For p(x1, x2, x3) = x1*x2 + x3, if we evaluate it at x2 =0. The resulting object should be p'(x1, x3) = x3. However, what we obtain is p'(x3) = x3. The term x1 disappearing shouldn't mean a polynomial doesn't have that variable as an input. Is there a reason behind this?Sat, 05 Mar 2022 20:44:10 +0100https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?comment=61415#post-id-61415Comment by cryptoqs for <p>Simple:</p>
<pre><code>sage: q = next_prime(2^128)
sage: p = (x1*x2) + (x3*x4)
sage: p(x2=2)
x3*x4 + 2*x1
</code></pre>
<p>But note that :</p>
<pre><code>sage: p.subs(x2==2)
x1*x2 + x3*x4
</code></pre>
<p>doesn't work.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?comment=61413#post-id-61413Thanks! I actually did p(x2=1) and got 0 as a result and thought it was wrong, it was actually working. However, I still can not evaluate the resulting polynomial with one less variable. It says the length is not correctSat, 05 Mar 2022 18:48:26 +0100https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/?comment=61413#post-id-61413