Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to substitute pint Quantity into equation?

I am exploring ways to check for consistency of units in equations (see also http://ask.sagemath.org/question/10218/units-tests/) and found that pint (http://pint.readthedocs.org/en/0.6/) seems very convenient, but for some reason it does not work with .subs in sage. Here is an example:

sage: from pint import UnitRegistry
sage: ureg = UnitRegistry()    
sage: b*ureg.meter*c*ureg.meter
<Quantity(1, 'meter ** 2')>
sage: f = (b*c).subs({b: ureg.meter, c: ureg.meter})
Traceback (click to the left of this block for traceback)
...
TypeError: no canonical coercion from <class 'pint.unit.Quantity'>
to Symbolic Ring

Any ideas what could be the reason and if it could be solved easily?

how to substitute pint Quantity into equation?

I am exploring ways to check for consistency of units in equations (see also http://ask.sagemath.org/question/10218/units-tests/) and found that pint (http://pint.readthedocs.org/en/0.6/) seems very convenient, but for some reason it does not work with .subs in sage. Here is an example:

sage: from pint import UnitRegistry
sage: ureg = UnitRegistry()    
sage: var('a b c')
sage: b*ureg.meter*c*ureg.meter
<Quantity(1, 'meter ** 2')>
sage: f = (b*c).subs({b: ureg.meter, c: ureg.meter})
Traceback (click to the left of this block for traceback)
...
TypeError: no canonical coercion from <class 'pint.unit.Quantity'>
to Symbolic Ring

Any ideas what could be the reason and if it could be solved easily?