Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Sympy from rearranging the equation

Tags:

python

sympy

Perhaps im overlooking the obvious but how do you prevent sympy from rearranging equations?

Im using Sympy in the iPython notebook so i can easily copy-paste the Latex code to Lyx, but i want the equations in the same order as i defined them.

For example, the formula for grey-body radiation as a function of its temperature:

enter image description here

Sympy automatically places the Temperature component to the front, which gives a very unusual representation of the formula. Is there anyway to prevent this?

like image 989
Rutger Kassies Avatar asked Jan 31 '13 11:01

Rutger Kassies


1 Answers

If you want the arguments of a product to appear in a given order you can create a Mul from those args and then tell the printer that you don't want them reordered as shown here for an Add. So for your example you could do

>>> var('epsilon, sigma, T')
(epsilon, sigma, T)
>>> this = Mul(epsilon, sigma, T**4, evaluate=False)
>>> StrPrinter({'order':'none'})._print_Mul(this)
epsilon*sigma*T**4
like image 101
smichr Avatar answered Oct 15 '22 14:10

smichr