Help with simplification of algebraic fractions

23 views
Skip to first unread message

Nicholas Daskalovic

unread,
Feb 19, 2022, 6:19:54 PM2/19/22
to sympy
Hi,

I'm using Sympy to generate latex for a webpage, but I have an issue when converting algebraic fractions into latex. I have attached an image with an example, I use sympy.Eq() to set up an equation and then convert it to latex using sympy.latex(). Is there anyway to prevent sympy from splitting these fractions up?

Thanks!
Screenshot 2022-02-19 at 23.01.56.png

gu...@uwosh.edu

unread,
Feb 19, 2022, 9:32:48 PM2/19/22
to sympy
1) Because of the way expressions are parsed in sympy before displaying I am not aware of a way of doing this. You can experiment with sympy.ratsimp(), but my tests show that you will get the same expanded expression output in the end.

2) You probably do not want to use sympy.Eq to represent an equation. sympy.Eq is a logical statement that when evaluated collapses to True, False or if that can't be determined maintains the expression. It does not support performing algebraic manipulations on the expression. Without more information about what you are trying to do I cannot be sure, but suspect you are looking for the equation capabilities contained in the the project Algebra_with_Sympy (https://github.com/gutow/Algebra_with_Sympy). There has been discussion of including the capabilities of that project in Sympy, but a decision on how to move forward has not been made yet.

In the interest of full disclosure I am the original author of the Algebra_with_Sympy package.

Regards,
Jonathan

gu...@uwosh.edu

unread,
Feb 19, 2022, 9:49:57 PM2/19/22
to sympy
Actually, I found what you are looking for. The operation sympy.factor(<sum of two fractions>) will combine them over one denominator. This will work for a sympy.Eq() as long as it does not evaluate to True or False.

Regards,
Jonathan

On Saturday, February 19, 2022 at 5:19:54 PM UTC-6 daskal...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages