To clarify the rationale of it being an error in 1.6, you should think of Eq as being a boolean type, that is, any Eq is either True or False. Doing arithmetic operations like + or * on booleans doesn't make sense. Rather, it should be used in boolean contexts like the condition of a Piecewise or in an And or Or. The Equation class which Oscar intends on adding will act like more an expression, so that arithmetic operations make sense on it.
More practically, in 1.5, Eq + Eq produces a result, but the result is complete nonsense. It only works because SymPy creates Add(Eq, Eq), but such a thing doesn't actually work in any function you would pass it to. A better model would be Equation, for which common operations would produce another Equation, and you want to pass it to a function that doesn't support Equation, you should pass the lhs and rhs separately. I think it would still be possible to have an Equation class nested inside of an expression, but such things should be avoided (or maybe we should try to disallow it). Aaron Meurer On Thu, Apr 30, 2020 at 4:54 PM Oscar Benjamin <[email protected]> wrote: > > Hi David, > > I agree entirely. Neither gives a sensible result in 1.5 and both will > give errors in 1.6. > > The Equation class I showed handles all of these though: > > In [27]: x, y = symbols('x, y', real=True) > > In [28]: eq = Equation(x, y) > > In [29]: eq > Out[29]: x = y > > In [30]: eq + 1 > Out[30]: x + 1 = y + 1 > > In [31]: eq + eq > Out[31]: 2*x = 2*y > > In [32]: eq1 = Equation(exp(I*x), cos(x)+I*sin(x)) > > In [33]: eq1 > Out[33]: exp(I*x) = I*sin(x) + cos(x) > > In [34]: eq2 = eq1.applyfunc(conjugate) > > In [35]: eq2 > Out[35]: exp(-I*x) = -I*sin(x) + cos(x) > > In [36]: (eq1 - eq2)/2 > Out[36]: exp(I*x)/2 - exp(-I*x)/2 = I*sin(x) > > In [37]: (eq1 + eq2)/2 > Out[37]: exp(I*x)/2 + exp(-I*x)/2 = cos(x) > > -- > Oscar > > On Thu, 30 Apr 2020 at 23:29, David Bailey <[email protected]> wrote: > > > > On 30/04/2020 19:18, Oscar Benjamin wrote: > > > > In 1.5 it just gives a nonsense object: > > > > In [1]: Eq(x, y) + Eq(z, t) > > Out[1]: (x = y) + (z = t) > > > > However, it should surely be valid to add an equation to an expression: > > > > >>> Eq(a-3,b-3)+3 > > > > 3 + Eq(a-3,b-3) > > > > >>> simplify(3 + Eq(a - 3, b - 3)) > > > > 3 + Eq(a - 3, b - 3) > > > > Obviously I thought that would produce Eq(a,b) > > > > At 1.5 the addition happens but the result doesn't simplify in the obvious > > way. Is there a rational to that? From what you say, I suspect this > > construct will also be banned at 1.6, but it seems perfectly meaningful. > > > > David > > > > -- > > 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 [email protected]. > > To view this discussion on the web visit > > https://groups.google.com/d/msgid/sympy/645e3ca5-267d-5368-b0e8-9837a7e47598%40dbailey.co.uk. > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/CAHVvXxQS4XeNKUOhVx-wr_wh_gs0b61xjXF9KWxRpDeYgdUs_A%40mail.gmail.com. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6KspoZG4Qxfw%2Bd3XShoKEqyUn9E8oJkEEqktXpxZqxE7A%40mail.gmail.com.
