Symbolic arithmetic in a number field
How to prevent expanding the value of the generating element in symbolic expressions?
E.<w> = CyclotomicField(3)
w^4 # shows w
(w+1)^2 # shows w
a = var('a')
(w + a)^2 # shows an expression with w expanded as a complex number
How can I make the last expression show up as $w^2 + 2aw + a^2$?
My use case is to expand $(a+bw+cw^2)^3$ so that the result is expressed as a rational (or integer) combination of 1, w, w^2
.
Defining
a
as a polynomial generator overE
helps some, but doesn't get what you want:a = polygen(E)
and then evaluate(w+a)^2
.Thanks! How can I transfer the "polynomialness" of the parameters also to the solutions of equations? E.g.
R.<a> = E[]; A = solve([a-x == 0], x)[0].right(); A.parent()
. This givesSymbolic Ring
instead of aPolynomial Ring over E
.You could try
R(A)
to convert the solution to an element ofR
.parent(R(A))
should returnUnivariate Polynomial Ring in a over Cyclotomic Field of order 3 and degree 2
.Unfortunately this works only in the simplest case. Anything non-trivial, e,g, solving
[a-x^2 == 0]
and then converting to R, leads to the error "no conversion of this rational to integer".I've enhanced my original question with the real use case.