Closed schymans closed 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
?
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)
PR #62 solved this issue.
The standard domain of Variable is "real", but this is not injected as an assumption when defining the symbol. We should add
real = True
inBaseVariable(Symbol)
or whatever the prescribed domain is.