Skip to content

Symbolic API: isinstance(x**2, Pow) or (x**2).is_Pow? #2360

Open
@certik

Description

@certik

Currently in SymPy (as well as symengine.py) you can use both (x**2).is_Pow and isinstance(x**2, sym.Pow):

In [1]: import sympy as sym

In [3]: sym.var("x")
Out[3]: x

In [4]: (x**2).is_Pow
Out[4]: True

In [5]: isinstance(x**2, sym.Pow)
Out[5]: True

But you can only use isinstance(sym.log(x), sym.log) but not sym.log(x).is_Log or sym.log(x).is_log:

In [6]: isinstance(sym.log(x), sym.log)
Out[6]: True

In [7]: sym.log(x).is_Log
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 sym.log(x).is_Log

AttributeError: 'log' object has no attribute 'is_Log'

In [8]: sym.log(x).is_log
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [8], in <cell line: 1>()
----> 1 sym.log(x).is_log

AttributeError: 'log' object has no attribute 'is_log'

In order to be consistent ("just one way of doing it"), wouldn't it make sense to only support isinstance(log(x), log) and isinstance(x**2, Pow), but not (x**2).is_Pow?

CC @isuruf, @asmeurer, @oscarbenjamin

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions