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, 20 Jan 2024 09:06:08 +0100Evaluate polynomial over extension ringhttps://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/Given a ring and polynomial like:
_.<I> = RR[]
K.<i> = RR.extension(I^2 + 1)
L.<a, b> = K[]
f = a + i*b
then I would expect that `f(i=0)` would give me `a`. But instead it just returns the same value again.
Any ideas how to do this? ThanksFri, 19 Jan 2024 09:52:40 +0100https://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/Comment by narodnik for <p>Given a ring and polynomial like:</p>
<pre><code>_.<I> = RR[]
K.<i> = RR.extension(I^2 + 1)
L.<a, b> = K[]
f = a + i*b
</code></pre>
<p>then I would expect that <code>f(i=0)</code> would give me <code>a</code>. But instead it just returns the same value again.</p>
<p>Any ideas how to do this? Thanks</p>
https://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/?comment=75585#post-id-75585thanks a lot!Sat, 20 Jan 2024 09:06:08 +0100https://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/?comment=75585#post-id-75585Comment by FrédéricC for <p>Given a ring and polynomial like:</p>
<pre><code>_.<I> = RR[]
K.<i> = RR.extension(I^2 + 1)
L.<a, b> = K[]
f = a + i*b
</code></pre>
<p>then I would expect that <code>f(i=0)</code> would give me <code>a</code>. But instead it just returns the same value again.</p>
<p>Any ideas how to do this? Thanks</p>
https://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/?comment=75565#post-id-75565Does not make really sense, but
sage: f.map_coefficients(lambda cf:cf[0])
aFri, 19 Jan 2024 12:12:20 +0100https://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/?comment=75565#post-id-75565Answer by Max Alekseyev for <p>Given a ring and polynomial like:</p>
<pre><code>_.<I> = RR[]
K.<i> = RR.extension(I^2 + 1)
L.<a, b> = K[]
f = a + i*b
</code></pre>
<p>then I would expect that <code>f(i=0)</code> would give me <code>a</code>. But instead it just returns the same value again.</p>
<p>Any ideas how to do this? Thanks</p>
https://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/?answer=75568#post-id-75568The issue here is that you want to make substitution not into `f` but into each of its coefficients. Direct approach using `.map_coefficients()` is given by @FrédéricC in the comments.
However, with the `i` being the imaginary unit, there is no need to define it over `RR`, since one can work in `CC` where the imaginary unit is already defined as `I`. So, you can go directly with
L.<a, b> = CC[]
f = a + I*b
f.map_coefficients(real)
---
Alternative general approach is to define all `a`, `b`, `i` as polynomial variables and work in the quotient ring:
F.<I,A,B> = RR[]
K.<i,a,b> = F.quotient( [I^2 + 1] )
f = a + i*b
f.lift().subs({I:0})
Instead of `f.lift().subs({I:0})` giving result in `F`, you can use `f.lift().specialization({I:0})`, which gives result in the polynomial ring of `A` and `B` only.Fri, 19 Jan 2024 16:04:51 +0100https://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/?answer=75568#post-id-75568Comment by narodnik for <p>The issue here is that you want to make substitution not into <code>f</code> but into each of its coefficients. Direct approach using <code>.map_coefficients()</code> is given by <a href="/users/1557/fredericc/">@FrédéricC</a> in the comments.</p>
<p>However, with the <code>i</code> being the imaginary unit, there is no need to define it over <code>RR</code>, since one can work in <code>CC</code> where the imaginary unit is already defined as <code>I</code>. So, you can go directly with</p>
<pre><code>L.<a, b> = CC[]
f = a + I*b
f.map_coefficients(real)
</code></pre>
<hr>
<p>Alternative general approach is to define all <code>a</code>, <code>b</code>, <code>i</code> as polynomial variables and work in the quotient ring:</p>
<pre><code>F.<I,A,B> = RR[]
K.<i,a,b> = F.quotient( [I^2 + 1] )
f = a + i*b
f.lift().subs({I:0})
</code></pre>
<p>Instead of <code>f.lift().subs({I:0})</code> giving result in <code>F</code>, you can use <code>f.lift().specialization({I:0})</code>, which gives result in the polynomial ring of <code>A</code> and <code>B</code> only.</p>
https://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/?comment=75584#post-id-75584thanks a lot! Gives me a load of stuff to look into now. Good daySat, 20 Jan 2024 09:05:38 +0100https://ask.sagemath.org/question/75561/evaluate-polynomial-over-extension-ring/?comment=75584#post-id-75584