stats.P doesn't work well with ==

20 views
Skip to first unread message

Gábor Horváth

unread,
Nov 8, 2025, 8:51:35 AM (4 days ago) Nov 8
to sympy

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
>>>
```

Aaron Meurer

unread,
Nov 8, 2025, 11:13:30 AM (4 days ago) Nov 8
to sy...@googlegroups.com
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
> --
> 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+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sympy/fd662394-3e69-f9f0-70a7-388a01a669a%40SamsungLaptop.WORKGROUP.
Reply all
Reply to author
Forward
0 new messages