Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
17624: coerce factorizations to SR
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Oct 11, 2015
1 parent 2cc7f6c commit ec9cd10
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sage/symbolic/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ cdef class SymbolicRing(CommutativeRing):
sage: bool(si == CC.0)
True
Polynomial ring element factorizations::
sage: R.<x> = QQ[]
sage: SR(factor(x^2 - 1))
(x + 1)*(x - 1)
sage: R.<x,y> = QQ[]
sage: SR(factor(x^2 - y^2))
(x + y)*(x - y)
sage: R.<x,y,z> = QQ[]
sage: SR(factor(x^2*y^3 + x^2*y^2*z - x*y^3 - x*y^2*z - 2*x*y*z - 2*x*z^2 + 2*y*z + 2*z^2))
-(x*y^2 - 2*z)*(x - 1)*(y + z)
"""
cdef GEx exp

Expand All @@ -271,6 +283,7 @@ cdef class SymbolicRing(CommutativeRing):

from sage.rings.infinity import (infinity, minus_infinity,
unsigned_infinity)
from sage.structure.factorization import Factorization

if isinstance(x, (Integer, RealNumber, float, long, complex)):
GEx_construct_pyobject(exp, x)
Expand All @@ -284,6 +297,9 @@ cdef class SymbolicRing(CommutativeRing):
return new_Expression_from_GEx(self, g_UnsignedInfinity)
elif isinstance(x, (RingElement, Matrix)):
GEx_construct_pyobject(exp, x)
elif isinstance(x, Factorization):
from sage.misc.all import prod
return prod([SR(p)**e for p,e in x], SR.one())
else:
raise TypeError

Expand Down

0 comments on commit ec9cd10

Please sign in to comment.