Change of variables in symbolic computation

I need to change Y into 1/2 *( y - a1 * x - a3) so that I can change variables in Elliptic curves.

var("X,Y,Z,x,y,a1,a2,a3,a4,a5,a6")
F = Y^2  *Z + a1 * X*Y *Z + a3 *Y *Z^2 - X^3 - a2 *X^2 * Z + a4*X*Z^ 2 + a6*Z^3
print(F)
F.substitute_expression(Y == 1/2 *( y - a1 * x - a3))
print(F)


This produces an error on the 4th line;

AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'substitute_expression'


What is the proper way to change the variables?

edit retag close merge delete

Sort by ยป oldest newest most voted

Use subs or substitute.

sage: var("X,Y,Z,x,y,a1,a2,a3,a4,a5,a6")
(X, Y, Z, x, y, a1, a2, a3, a4, a5, a6)
sage: F = Y^2  *Z + a1 * X*Y *Z + a3 *Y *Z^2 - X^3 - a2 *X^2 * Z + a4*X*Z^ 2 + a6*Z^3
sage: F
X*Y*Z*a1 - X^2*Z*a2 + Y*Z^2*a3 + X*Z^2*a4 + Z^3*a6 - X^3 + Y^2*Z
sage: F.subs(Y == 1/2 *( y - a1 * x - a3))
-1/2*(a1*x + a3 - y)*X*Z*a1 - X^2*Z*a2 - 1/2*(a1*x + a3 - y)*Z^2*a3
+ X*Z^2*a4 + Z^3*a6 - X^3 + 1/4*(a1*x + a3 - y)^2*Z

more

I guess substitute_expression is for something else, however, I couldn't find it in the docs.

( 2021-11-03 18:59:39 +0100 )edit

Also, I've seen this answer of yours and the function is not working, at least for me. Something has changed with Python3?

( 2021-11-03 19:04:16 +0100 )edit