Why not just Lambda(x, Eq(x, 1))?

I don't think redefining __eq__ to return a symbolic result is a good
idea. You're liable to get a lot of "TypeError: cannot determine truth
value of Relational" errors from using that object.

Aaron Meurer

On Tue, Sep 28, 2021 at 12:42 AM Oscar Benjamin
<oscar.j.benja...@gmail.com> wrote:
>
> On Tue, 28 Sept 2021 at 04:13, Chris Smith <smi...@gmail.com> wrote:
>>
>> I would like to emulate something like this with Basic objects. I am drawing 
>> a blank on how that might be done. Does anyone have any ideas?
>>
>> >>> f=lambda x: x==1
>> >>> f(1)
>> True
>> >>> Lambda(x, f(x))(1) # doesn't work
>> False
>
>
> Something like this:
>
> In [7]: cat w.py
> class SymbolicEquality:
>     def __init__(self, sym):
>         self.sym = sym
>     def __eq__(self, other):
>         return Equality(self.sym, other)
>
> In [8]: f = lambda x: x == 1
>
> In [9]: y = Dummy('y')
>
> In [10]: F = Lambda(y, f(SymbolicEquality(y)))
>
> In [11]: F
> Out[11]: y ↦ y = 1
>
> --
> Oscar
>
> --
> 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 sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/CAHVvXxQO%3DOoH%2BVwTPm%2BLSOZ5GpE9ipyHUad1xB_xivJ8iff2aA%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 sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6JbOTsB_5OJP%3DAYcAECW9_Se%3DnSOJN-%2BonyG4e3fgrBaQ%40mail.gmail.com.

Reply via email to