Oscar Benjamin
unread,Oct 27, 2018, 1:44:09 PM10/27/18Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sy...@googlegroups.com
Hi all,
I find the behaviour of operations involving Eq strange. I would
really like to be able to use Eqs for algebra but they don't seem to
do anything useful. Is this behaviour intentional or is it something
that could be improved?
Setup:
>>> from sympy import *
>>> x = Symbol('x')
>>> y = Symbol('y')
>>> eq = Eq(x, y)
>>> eq
Eq(x, y)
>>> pprint(eq)
x = y
I don't understand what any of these mean:
>>> pprint(2*eq)
2⋅(x = y)
>>> pprint((2*eq).expand())
2⋅(x = y)
>>> exp(eq)
exp(Eq(x, y))
>>> pprint(abs(eq))
│x = y│
>>> eq - 1
-1 + Eq(x, y)
>>> pprint(eq - 1)
-1 + (x = y)
Integration works but differentiation doesn't:
>>> pprint(integrate(eq, x))
⌠ ⌠
⎮ x dx = ⎮ y dx
⌡ ⌡
>>> pprint(integrate(eq, x).doit())
2
x
── = x⋅y
2
>>> diff(eq, x)
Derivative(Eq(x, y), x)
>>> pprint(diff(eq, x))
∂
──(x = y)
∂x
>>> pprint(diff(eq, x).doit())
∂
──(x = y)
∂x
Functions of Eq raise errors:
>>> sin(eq)
...
TypeError: cannot determine truth value of Relational
It looks as if I can chain equations and inequalities but does it
actually mean what it looks like mathematically?
>>> eq < 3
Eq(x, y) < 3
>>> pprint(eq < 3)
x = y < 3
Apart from the inequality example at the end I would like it if all of
the above operations acted on both lhs and rhs separately as in the
case of integration e.g.:
>>> eq
x = y
>>> 2*eq
2*x = 2*y
>>> sin(eq)
sin(x) = sin(y)
The other thing that I don't understand although it is clearly
documented is this:
>>> Eq(1, 1)
True
>>> Eq(1, 0)
False
These True/False values are annoying if you are building up Eqs
programatically e.g. to pass to solve:
>>> solve([Eq(1, 1), Eq(x, y), Eq(x, 1)], [x, y])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/enojb/current/sympy/sympy/sympy/solvers/solvers.py",
line 980, in solve
return reduce_inequalities(f, symbols=symbols)
File "/Users/enojb/current/sympy/sympy/sympy/solvers/inequalities.py",
line 987, in reduce_inequalities
rv = _reduce_inequalities(inequalities, symbols)
File "/Users/enojb/current/sympy/sympy/sympy/solvers/inequalities.py",
line 907, in _reduce_inequalities
'''))
NotImplementedError:
inequality has more than one symbol of interest.
You can solve this last problem with evaluate=False but I really don't
understand why any evaluation is desirable here. I think that solve
has probably gotten confused here for the same reason that any other
code would: the True/False objects don't have any of the same
attributes that an Eq would have:
>>> Eq(0, 1).lhs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'BooleanFalse' object has no attribute 'lhs'
--
Oscar