You can't use == for symbolic operations anywhere in SymPy, because ==
always does a direct structural equality check, and always results in
either True or False

>>> import sympy.stats as stats
>>> D = stats.Die('D', 6)
>>> D == 3
False

If you want to create an equality object you should use Eq(), like

>>> Eq(D, 3)
Eq(D, 3)
>>> stats.P(Eq(D, 3))
1/6

Aaron Meurer

On Sat, Nov 8, 2025 at 6:51 AM Gábor Horváth <[email protected]> wrote:
>
>
> Hi Team!
>
> I played around a bit with sympy's stats module, and seems to me that
> stats.P can't evaluate equality conditions well. Didn't debug it further,
> just wondering if I'm missing something trivial here, or is this a bug?
>
> Thanks,
> Gábor
>
> ```
> Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sympy
> >>> sympy.__version__
> '1.14.0'
> >>> import sympy.stats as stats
> >>> D = stats.Die('D', 6)
> >>> stats.P(D == 3)
> 0
> >>> stats.P(D > 3)
> 1/2
> >>> stats.P((D > 2) & (D < 4))
> 1/6
> >>> stats.P((D >= 3) & (D <= 3))
> 1/6
> >>>
> ```
>
> --
> 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/fd662394-3e69-f9f0-70a7-388a01a669a%40SamsungLaptop.WORKGROUP.

-- 
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%3D6JX55SMSPB0jgqoWT-%3D%3DVHwzt-igTKcz1ZgCvOC2s3FxQ%40mail.gmail.com.

Reply via email to