Hi Aaron, Yes, if we had Equation we should disallow its use in an expression. I don't see any situation where it would make sense. We would need a clear distinction between Equation and Equality as well as methods to convert between them.
1. Equality is a Boolean 2. Equation is Basic 3. Neither is Expr 4. You can use `.as_Boolean/.as_Equation` or something to convert between 5. Equation should be used instead of Equality for e.g. passing equations to solve/dsolve and for returning solutions. 6. Equation should be invalid in any Boolean context 7. Equality should not support any of the arithmetic manipulations that Equation does 8. Equation should be usable in subs or subseq or something (but Equality should not) 9. Equation should have a solve method for making something the lhs 10. Documentation should find a way of making this understandable... -- Oscar On Fri, 1 May 2020 at 00:15, Aaron Meurer <[email protected]> wrote: > > 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. -- 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/CAHVvXxRj_vWHPqG3Ds1%2B71_tQmDst%2BoFVwMenfC17-qS_Bt9aA%40mail.gmail.com.
