Skip to content

Commit

Permalink
Basic.as_poly method moved to Expr.as_poly
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Aug 26, 2017
1 parent 1faa43f commit 6c76f75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
25 changes: 0 additions & 25 deletions diofant/core/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,31 +479,6 @@ def _sorted_args(self):
"""
return self.args

def as_poly(self, *gens, **args):
"""Converts ``self`` to a polynomial or returns ``None``.
Examples
========
>>> from diofant import sin
>>> from diofant.abc import x, y
>>> (x**2 + x*y).as_poly()
Poly(x**2 + x*y, x, y, domain='ZZ')
>>> (x**2 + x*y).as_poly(x, y)
Poly(x**2 + x*y, x, y, domain='ZZ')
>>> (x**2 + sin(y)).as_poly(x, y) is None
True
"""
from ..polys import Poly, PolynomialError

try:
return Poly(self, *gens, **args)
except PolynomialError:
pass

def subs(self, *args, **kwargs):
"""
Substitutes old for new in an expression after sympifying args.
Expand Down
25 changes: 25 additions & 0 deletions diofant/core/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,31 @@ def as_expr(self, *gens):
"""
return self

def as_poly(self, *gens, **args):
"""Converts ``self`` to a polynomial or returns ``None``.
Examples
========
>>> from diofant import sin
>>> from diofant.abc import x, y
>>> (x**2 + x*y).as_poly()
Poly(x**2 + x*y, x, y, domain='ZZ')
>>> (x**2 + x*y).as_poly(x, y)
Poly(x**2 + x*y, x, y, domain='ZZ')
>>> (x**2 + sin(y)).as_poly(x, y) is None
True
"""
from ..polys import Poly, PolynomialError

try:
return Poly(self, *gens, **args)
except PolynomialError:
pass

def as_coefficient(self, expr):
"""Extracts symbolic coefficient at the given expression.
Expand Down

0 comments on commit 6c76f75

Please sign in to comment.