Ask Your Question
0

Trouble with subs

asked 2024-06-27 15:11:03 +0100

I have this code:

var("L E t c")
D=(1-c)*(L+3*E)
Dt=D-t*E
Dt_E=Dt*E;
Dt_E=Dt_E.expand()
print(Dt_E.subs(E*L==1/2, E*E==-1/6, L*L==-1/2, E*L*c==c*1/2))

I get:

-E*L*c + 1/2*c + 1/6*t

I get the same if I drop the last equality. What do I have to do for ELc to be replaced by c/2?

edit retag flag offensive close merge delete

Comments

I answer myself. If I add - in front of the ELC substitution, it works. I suppose this happens because for some reason sage is thinking E and -E are different things? How can I work over a commutative ring or even a field?

Jesus Martinez Garcia gravatar imageJesus Martinez Garcia ( 2024-06-27 15:20:59 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2024-06-28 07:14:29 +0100

Max Alekseyev gravatar image

updated 2024-06-28 07:43:12 +0100

One can have a better control such substitutions using polynomial machinery, reducing a polynomial modulo the ideal generated by desired substitutions:

K.<L, E, t, c> = QQ[]
D=(1-c)*(L+3*E)
Dt=D-t*E
Dt_E=Dt*E
J = ideal([E*L-1/2, E*E+1/6, L*L+1/2])
print( Dt_E.reduce(J) )
edit flag offensive delete link more

Comments

Thank you. That's quite clever. May I ask if these rings are commutative by default?

Jesus Martinez Garcia gravatar imageJesus Martinez Garcia ( 2024-06-28 09:47:08 +0100 )edit

Yes, they are commutative.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-06-28 12:18:51 +0100 )edit

Actually, it doesn't work as intended. In input:

R.<L, E, t, c> = PolynomialRing(QQ)
D=(1-c)*(L+3*E)
Dt=D-t*E
Dt_E=Dt*E
J = R.ideal([E*L-1/2, E*E+1/6, L*L+1/2])
print(Dt_E)
print(J)
print( Dt_E.reduce(J) )

The output is

-E^2*t - L*E*c - 3*E^2*c + L*E + 3*E^2
Ideal (L*E - 1/2, E^2 + 1/6, L^2 + 1/2) of Multivariate Polynomial Ring in L, E, t, c over Rational Field
0

But the last entry shouldn't be a 0. It should have $-t/6$ summand, shouldn't it?

Jesus Martinez Garcia gravatar imageJesus Martinez Garcia ( 2024-07-01 16:37:11 +0100 )edit

That's because your substitutions are inconsistent with each other: multiplying E*E==-1/6, L*L==-1/2, gives E*E*L*L==1/12; however multiplying E*L==1/2 by itself gives E*E*L*L==1/4. In terms of the ideals, they generate the ideal J coinciding with the whole R, and thus everything reduces to 0 modulo J.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-07-01 16:53:48 +0100 )edit

Ohhh I see. Thank you. I think the issue is that I am (should be?) working on a graded ring where negatively graded parts are 0 and where multiplication should really be "pairing", i.e if deg(E)=1, then deg(<e,e>)=0, bringing me one degree less, rather than up. So deg(EELL)=deg(<<<e,e>,L>,L>)=-2 and thus EELL=0.

So I guess this is not a solution for my problem. I know this is possible mathematically because it is what intersection theory on a surface (where the E, L are curves) in algebraic geometry/topology is about and it is actually defined using dimension of quotient rings (different rings) but I was hoping to be able to get around without having to implement all this (which is why I was using subs).

Jesus Martinez Garcia gravatar imageJesus Martinez Garcia ( 2024-07-02 10:44:58 +0100 )edit
0

answered 2024-06-28 10:10:15 +0100

Emmanuel Charpentier gravatar image

Alternative : Sympy's subsis recursive :

sage: Dt_E._sympy_().subs({u.lhs()._sympy_():u.rhs()._sympy_() for u in (E*L==1/2, E*E==-1/6, L*L==-1/2, E*L*c==c*1/2)})._sage_()
1/6*t

HTH,

edit flag offensive delete link more

Comments

I tried this but it fails:

AttributeError: 'Add' object has no attribute '_sympy_'
Jesus Martinez Garcia gravatar imageJesus Martinez Garcia ( 2024-06-28 19:00:38 +0100 )edit

This is what I import:

from sage.symbolic.integration.integral import definite_integral
from sage.symbolic.assumptions import GenericDeclaration
from sympy import symbols
from sympy import expand
Jesus Martinez Garcia gravatar imageJesus Martinez Garcia ( 2024-06-28 19:01:24 +0100 )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-06-27 15:11:03 +0100

Seen: 242 times

Last updated: Jun 28