environmentalscience / essm

This package contains helpers to deal with physical variables and units.
https://environmentalscience.github.io/essm/
GNU General Public License v2.0
12 stars 5 forks source link

Now that variables are symbols, we can implement assumptions #56

Closed schymans closed 5 years ago

schymans commented 5 years ago

The standard domain of Variable is "real", but this is not injected as an assumption when defining the symbol. We should add real = True in BaseVariable(Symbol) or whatever the prescribed domain is.

schymans commented 5 years ago

Example using assumptions in sympy:

from sympy import Symbol, solve
x = Symbol("x")
print(solve(x**2 - 1))
pos = Symbol("pos", positive=True)
print(solve(pos**2 - 1))

gives

[-1, 1] [1]

How could we do this with Variable?

schymans commented 5 years ago

Here is a possible behaviour:

from essm.variables import Variable
from sympy import solve
from sympy.physics.units import second
class x(Variable):
     """Positive real variable."""  
     assumptions = {'positive': True, 'real': True}

print(solve(x**2 - 1))

[1] Under the hood, the variable should be defined as: Symbol(x, **assumptions)

schymans commented 5 years ago

PR #62 solved this issue.