I'm fairly new to sympy and have what might be a basic question. Or I might simply be misinterpreting how sympy is supposed to be used.
Is there a way to create an expression that is not represented by atoms, but by a combination of other expressions?
Ex:
>>> from sympy.physics.units import *
>>> expr1 = m/s
>>> expr2 = mile/hour
>>> expr1
m/s
>>> expr2
1397*m/(3125*s)
>>> expr1.in_terms_of([mile,hour]) #in my dreams?
3125*mile/(1397*hour)
>>>
On a side note: Can i find an 'official' pdf (or other printable) version of the complete sympy documentation. (I'm under draconian internet usage restrictions at work and am tired of doing work at home on the weekend.)
Update:
This is what I ended up with following Prelude's suggestion, however it's not likely to get much use like this as it feels dirty. Comments and WTF's welcome.
def in_terms_of(self, terms):
expr2 = eval(str(self), physics.units.__dict__)
converter = {}
for term in terms:
term_expr = physics.units.__dict__[term]
coeff = term_expr.as_coeff_terms()[0]
unit = physics.units.Unit('my_'+term, term)
converter[term_expr/coeff] = unit/coeff
return str(expr2.subs(converter))
Usage:
>>> x = in_terms_of('J',['gram','mile','hour'])
>>> x
'9765625000*mile**2*gram/(1951609*hour**2)'
>>> in_terms_of(x,['J'])
'J'