It is also worth noting that in many cases, you might just want to use
the assumptions system, like x.is_real (this will evaluate to None if
it is unknown).

Aaron Meurer

On Mon, Nov 4, 2024 at 4:53 AM Oscar Benjamin
<[email protected]> wrote:
>
> SymPy can represent various sets and you can use Contains e.g.:
>
> In [44]: Contains(x, Reals)
> Out[44]: x ∈ ℝ
>
> In [45]: Not(Contains(x, Reals))
> Out[45]: ¬x ∈ ℝ
>
> In [46]: Contains(x, ImageSet(Lambda(n, 2*n), Integers))
> Out[46]: x ∈ {2⋅n │ n ∊ ℤ}
>
> Usually it is better though to express the same statements using
> ordinary Booleans rather than Sets e.g.:
>
> In [47]: Eq(x % 2, 0)
> Out[47]: x mod 2 = 0
>
> In [51]: Ne(x % 2, 1)
> Out[51]: x mod 2 ≠ 1
>
> --
> Oscar
>
> On Mon, 4 Nov 2024 at 10:45, Paul Royik <[email protected]> wrote:
> >
> > Is there any way to represent in Sympy the following: `x is Real`, `x is 
> > not odd`.
> >
> > In other words, is there a possibility to represent the fact that 
> > expression belongs or doesn't belong to some set?
> >
> > --
> > 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 visit 
> > https://groups.google.com/d/msgid/sympy/6803ee83-25e7-4733-a33e-36fd90fa641fn%40googlegroups.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 visit 
> https://groups.google.com/d/msgid/sympy/CAHVvXxRw-MWT53vVxjFoc6m3FVSqMN369DrDeZdnuP-qU5gocA%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 visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6Jn3Upj_A3sHCOPLKcoDE1UuccMdNBUoAU08V_ZhtTVbQ%40mail.gmail.com.

Reply via email to