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.Sun, 08 Sep 2019 19:12:37 +0200How to evaluate polynomial in a polynomial ring at a particular valuehttps://ask.sagemath.org/question/47780/how-to-evaluate-polynomial-in-a-polynomial-ring-at-a-particular-value/ Apologies in advance if this question is too simple. I have the following situation: I have a vector space over a polynomial ring, and at some point in my program I need to sub in a value for the indeterminate $t$, and evaluate the polynomial. The set up is as follows:
P.<x> = QQ[]
R.<t> = QuotientRing(P, P.ideal(x^2 - 2))
v = VectorSpace(R,4)
Then for example I have the vector:
(2*t, 3, 2, 0)
I simply want to evaluate $2*t$ at $t = sqrt(2)$ as a function from $\mathbb{R}$ to $\mathbb{R}$.
What is the easiest way to go about this?
Sat, 07 Sep 2019 04:12:38 +0200https://ask.sagemath.org/question/47780/how-to-evaluate-polynomial-in-a-polynomial-ring-at-a-particular-value/Answer by rburing for <p>Apologies in advance if this question is too simple. I have the following situation: I have a vector space over a polynomial ring, and at some point in my program I need to sub in a value for the indeterminate $t$, and evaluate the polynomial. The set up is as follows:</p>
<pre><code>P.<x> = QQ[]
R.<t> = QuotientRing(P, P.ideal(x^2 - 2))
v = VectorSpace(R,4)
</code></pre>
<p>Then for example I have the vector:</p>
<pre><code>(2*t, 3, 2, 0)
</code></pre>
<p>I simply want to evaluate $2*t$ at $t = sqrt(2)$ as a function from $\mathbb{R}$ to $\mathbb{R}$.</p>
<p>What is the easiest way to go about this? </p>
https://ask.sagemath.org/question/47780/how-to-evaluate-polynomial-in-a-polynomial-ring-at-a-particular-value/?answer=47792#post-id-47792Note `R` is not a polynomial ring but a quotient of one.
Let's name the vector
w = v([2*t, 3, 2, 0])
One thing you can do is lift all the elements to be *polynomials* in `x` again and do a substitution:
w.apply_map(lambda z: z.lift().subs({x : sqrt(2)}))
This lands in the vector space over the symbolic ring, because `sqrt(2)` is symbolic.
You can also replace `sqrt(2)` by things like `sqrt(RR(2))` or `sqrt(AA(2))`.
---
More appropriate in this situation is to recognize that you are working in an abstract number field $K = \mathbb{Q}(t) = \mathbb{Q}[x]/(x^2-2)$, and you want to use an embedding:
sage: K.<t> = NumberField(x^2 - 2)
sage: V = VectorSpace(K,4)
sage: w = V([2*t, 3, 2, 0])
sage: w.apply_map(K.embeddings(AA)[1])
(2.828427124746190?, 3, 2, 0)
Here `K.embeddings(AA)[1]` is the embedding of $K$ into $\mathbb{R}$ that sends $t \mapsto \sqrt{2}$.
The other embedding `K.embeddings(AA)[0]` is the one that sends $t \mapsto -\sqrt{2}$:
sage: w.apply_map(K.embeddings(AA)[0])
(-2.828427124746190?, 3, 2, 0)
Again here you can replace the algebraic reals `AA` by other fields like `QQbar`, `RR` and `CC`.Sun, 08 Sep 2019 19:12:37 +0200https://ask.sagemath.org/question/47780/how-to-evaluate-polynomial-in-a-polynomial-ring-at-a-particular-value/?answer=47792#post-id-47792