Policy on `is_foo` predicates

24 views
Skip to first unread message

Matthew Rocklin

unread,
Apr 28, 2014, 9:39:09 AM4/28/14
to sy...@googlegroups.com, Sergey Kirpichev, amits...@gmail.com
When making a predicate on a sympy class should we always use is_foo as in is_Real or should we use isfoo as in isinstance?  What is the standard style for denoting that something is a predicate?

This came up in https://github.com/sympy/sympy/pull/7346 for Set.issubset / Set.is_subset.

Sergey B Kirpichev

unread,
Apr 28, 2014, 9:57:41 AM4/28/14
to sy...@googlegroups.com, Matthew Rocklin, amits...@gmail.com
On Mon, Apr 28, 2014 at 06:39:09AM -0700, Matthew Rocklin wrote:
> When making a predicate on a sympy class should we always use is_foo as in
> is_Real or should we use isfoo as in isinstance?  What is the standard
> style for denoting that something is a predicate?

Well, here is an argument from statistics:
$ grep --exclude-dir='mpmath' -R 'def is_[a-z]' sympy/|wc -l
259

vs

$ grep --exclude-dir='mpmath' -R 'def is[a-z]' sympy/
sympy/core/evalf.py:def iszero(mpf, scaled=False):
sympy/utilities/lambdify.py: def isiter(l):
sympy/ntheory/primetest.py:def isprime(n):
sympy/polys/numberfields.py:def isolate(alg, eps=None, fast=False):

It seems, there is no isfoo *methods* at all.

Aaron Meurer

unread,
Apr 28, 2014, 10:12:06 AM4/28/14
to sy...@googlegroups.com, Matthew Rocklin, amits...@gmail.com
Yes, it seems the sympy way is to use the underscore. Also note that
almost all is_ attributes in sympy are either assumptions or class
classifications. The exceptions I know of are is_polynomial and
is_rationalfunction.

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 post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/20140428135741.GA29595%40darkstar.order.hcn-strela.ru.
> For more options, visit https://groups.google.com/d/optout.

Joachim Durchholz

unread,
Apr 28, 2014, 10:17:14 AM4/28/14
to sy...@googlegroups.com
Am 28.04.2014 15:39, schrieb Matthew Rocklin:
> When making a predicate on a sympy class should we always use is_foo as in
> is_Real or should we use isfoo as in isinstance? What is the standard
> style for denoting that something is a predicate?

Here's a quick scan in my SymPy installation.
It's old-ish (six months) so current numbers may vary.

is with underscore:
$ cat `find -name "*.py"`|grep -c "def is[_]"
264

is without underscore:
$ cat `find -name "*.py"`|grep "def is[^_]"
22

So I guess the standard is is_ with an underscore.
Reply all
Reply to author
Forward
0 new messages