check for compatible physical dimension in symbolic algebra operations?

68 views
Skip to first unread message

hei...@pik-potsdam.de

unread,
Mar 2, 2017, 11:15:57 AM3/2/17
to sympy
I wonder whether it is currently (or will soon be) possible to specify which physical dimension (or unit) a symbol has and have sympy check that these are compatible when, say, adding symbols or expressions, and compute the resulting dimension (or unit) when, say, multiplying symbols or expressions?

I imagine something like


>>> x = Symbol("x", dimension=length/time)
>>> y = Symbol("y", dimension=time)
>>> x + y
DimensionError: incompatible dimensions cannot be added
>>> (x * y).dimension
length


I know that sympy has now units, but it seems they are only used in numerical computations, not in symbolic ones, am I right?

If the imagined functionality is not present or planned to be added soon, how would you advise me to add it for my project by subclassing? Would it be sufficient to subclass sympy.Expr or would I have to subclass Add, Mul, etc. as well?

Thanks, Jobst

Aaron Meurer

unread,
Mar 2, 2017, 1:24:10 PM3/2/17
to sy...@googlegroups.com
I believe the sympy.physics.unitsystems module is capable of doing
this. http://docs.sympy.org/latest/modules/physics/unitsystems/index.html

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/1ce09588-af7d-4781-9ce9-cac5cf858086%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

hei...@pik-potsdam.de

unread,
Mar 3, 2017, 6:04:56 AM3/3/17
to sympy
I was hoping so, but apparently unitsystems.Quantity currently only allows numerical computations, not symbolic ones.

At least, when I try

>>> x = Quantity(factor=Symbol("x"))

I get a NotImplementedError (see also code at http://docs.sympy.org/dev/_modules/sympy/physics/unitsystems/quantities.html).

I interpret this to mean that hopefully support for symbolic physical quantities is planned, but I'd like to get an idea of when it might be available...

Francesco Bonazzi

unread,
Mar 3, 2017, 7:52:50 AM3/3/17
to sympy
Ideally we'd like units to be used seamlessly everywhere. Unfortunately there's still a bit of work to do to reach that level.
Reply all
Reply to author
Forward
0 new messages