Ask Your Question
0

Symbolic arithmetic in a number field

asked 2024-01-17 22:46:28 +0200

kejv2 gravatar image

updated 2024-01-18 21:40:31 +0200

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.

edit retag flag offensive close merge delete

Comments

1

Defining a as a polynomial generator over E helps some, but doesn't get what you want: a = polygen(E) and then evaluate (w+a)^2.

John Palmieri gravatar imageJohn Palmieri ( 2024-01-17 22:57:19 +0200 )edit

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 gives Symbolic Ring instead of a Polynomial Ring over E.

kejv2 gravatar imagekejv2 ( 2024-01-18 20:05:21 +0200 )edit

You could try R(A) to convert the solution to an element of R. parent(R(A)) should return Univariate Polynomial Ring in a over Cyclotomic Field of order 3 and degree 2.

John Palmieri gravatar imageJohn Palmieri ( 2024-01-18 20:57:28 +0200 )edit

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".

kejv2 gravatar imagekejv2 ( 2024-01-18 21:36:26 +0200 )edit

I've enhanced my original question with the real use case.

kejv2 gravatar imagekejv2 ( 2024-01-18 21:40:54 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2024-01-18 22:14:31 +0200

Max Alekseyev gravatar image

updated 2024-01-18 22:49:18 +0200

A possible approach is to define w, a, b etc. as polynomial variables, and define an ideal generated by cyclotomic_polynomial(3,w) and whatever other relations between the variables. Then you can reduce your polynomial with respect to this ideal, and access the coefficients of w^i via .coefficient({w:i}). For example

K.<w,a,b,c> = QQ[]
J = K.ideal( [cyclotomic_polynomial(3,w), a+b+c] )
f = ((a+b*w+c*w^2)^3).reduce(J)
print( ' + '.join(f'({f.coefficient({{w:i}})} * w^{i}' for i in range(f.degree(w)+1)) )

prints

(3*b^3 - 9*b^2*c - 18*b*c^2 - 3*c^3) * w^0 + (6*b^3 + 9*b^2*c - 9*b*c^2 - 6*c^3) * w^1


Alternatively, you can define w over the quotient ring in a, b, c - like

K.<a_,b_,c_> = QQ[]
Q.<a,b,c> = K.quotient( [a_+b_+c_] )
E.<w> = Q[]
f = (a+b*w+c*w^2)^3 % cyclotomic_polynomial(3,w)
print(f)

which prints

(6*b^3 + 9*b^2*c - 9*b*c^2 - 6*c^3)*w + 3*b^3 - 9*b^2*c - 18*b*c^2 - 3*c^3

edit flag offensive delete link more

Comments

I've learned one thing from your alternate solution which is useful in general: That defining the target poly ring incrementally (QQ[a,b,c][w] instead of QQ[a,b,c,w]) leads to more natural presentation of the polys. Is there any way how to change between those representations? E.g. I would like to convert f from QQ[a,b,c][w] to QQ[w][a,b,c].

The actual use case is to evaluate the poly piecewise. Sometimes I want to plug in w, sometimes a,b,c. Perhaps there's a simpler way to achieve this than changing the poly ring representation, though.

kejv2 gravatar imagekejv2 ( 2024-01-20 22:38:22 +0200 )edit

If you need both QQ[a,b,c][w] and QQ[a,b,c][w], then it's better to use universal QQ[a,b,c,w] (where you can plug in a,b,c or w as you like). Conversion is possible (e.g. via intermediate conversion into SR) but it's not elegant nor efficient.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-01-21 00:59:00 +0200 )edit

I've found out that for partial evaluation of a polynomial, there is the SpecializationMorphism. This works for whichever stacking you use for the definition of the poly ring.

kejv2 gravatar imagekejv2 ( 2024-02-18 10:43:10 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-01-17 22:46:28 +0200

Seen: 169 times

Last updated: Jan 18