Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

How to get sage to keep the same form as an expression from sympy?

asked 7 years ago

ensaba gravatar image

I have this expression:

โˆ’23t1+23y1

and would like to rewrite it as follows:

23(โˆ’t1+y1)

Using sympy, I can get something close:

import sympy as sp

var('y1 t1')
expr1 = -2/3*t1 + 2/3*y1
sp.factor(sp.sympify(expr1))

This gives:

๐Ÿธ*(โŽฏ๐š๐Ÿท+๐šข๐Ÿท)/๐Ÿน

But when I convert it back to Sage:

sp.factor(sp.sympify(expr1))._sage_()

The result reverts to expr1.

How can I get the call to _sage_() not do any rewrites on the sympy expression?

Preview: (hide)

Comments

1

Is the following (purely) algebraic framework ok?

sage: R.<y,t> = PolynomialRing(QQ)
sage: E = -2/3*t +2/3*y
sage: E
2/3*y - 2/3*t
sage: E.factor()
(2/3) * (y - t)
dan_fulea gravatar imagedan_fulea ( 7 years ago )

1 Answer

Sort by ยป oldest newest most voted
0

answered 7 years ago

mforets gravatar image

in the symbolic ring you can do:

sage: var('y1, t1');
sage: (y1-t1).mul(2/3, hold=true)
2/3*(-t1 + y1)

i'm afraid there's no easy out-of-the-box way to tune the exact order in which the expressions are displayed. of course, sage provides all functions needed to get the information, such as variables(), coefficients(), and so on.

moreover, it becomes less clear what would such a function do. what if the expression involves more than two terms? lexicographic order is provided in a polynomial ring, an answer which has been given elsewhere by dan_fulea.

hope that helps!

Preview: (hide)
link

Comments

If I type (y1-t1).mul(2/3, hold=true) it means that I already know the factorized form of the expression I want to factor. What if I don't know what the factorized form of the expression that I want to factor will look like?

ensaba gravatar imageensaba ( 7 years ago )

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: 7 years ago

Seen: 493 times

Last updated: Aug 11 '17