[sympycore] r1211 committed - Added expand to polynomial head. Minor fixes.

1 view
Skip to first unread message

codesite...@google.com

unread,
Sep 19, 2011, 4:56:36 PM9/19/11
to sympycor...@googlegroups.com
Revision: 1211
Author: pearu.peterson
Date: Mon Sep 19 13:56:01 2011
Log: Added expand to polynomial head. Minor fixes.
http://code.google.com/p/sympycore/source/detail?r=1211

Modified:
/trunk/sympycore/calculus/algebra.py
/trunk/sympycore/heads/base.py
/trunk/sympycore/heads/polynomial.py
/trunk/sympycore/polynomials/algebra.py

=======================================
--- /trunk/sympycore/calculus/algebra.py Thu Apr 16 13:30:13 2009
+++ /trunk/sympycore/calculus/algebra.py Mon Sep 19 13:56:01 2011
@@ -8,7 +8,7 @@

from ..core import classes, defined_functions
from ..utils import TERMS, str_PRODUCT, SYMBOL, NUMBER
-from ..heads import APPLY, CALLABLE
+from ..heads import APPLY, CALLABLE, TERM_COEFF
from ..heads import BASE_EXP_DICT as FACTORS
from ..basealgebra import Algebra, Verbatim
from ..ring import CommutativeRing
@@ -205,6 +205,10 @@
break
if l is not None:
return cls(f(*l))
+ if head is TERM_COEFF:
+ term, coeff = data
+ coeff = coeff * float_one
+ return cls(head, (term, coeff))
return target
return head.walk(evalf, type(self), data, self)

=======================================
--- /trunk/sympycore/heads/base.py Sat Jan 16 11:58:33 2010
+++ /trunk/sympycore/heads/base.py Mon Sep 19 13:56:01 2011
@@ -542,7 +542,7 @@
"""
Return the expanded expression of expr, i.e. open parenthesis.
"""
- return self
+ return expr

def expand_intpow(self, Algebra, base, exp):
"""
=======================================
--- /trunk/sympycore/heads/polynomial.py Sun Sep 18 14:34:28 2011
+++ /trunk/sympycore/heads/polynomial.py Mon Sep 19 13:56:01 2011
@@ -85,6 +85,12 @@
new_data[new_exp] = coeff * n
return cls(new_data)

+ def expand(self, cls, expr):
+ new_data = {}
+ for exp, coeff in expr.data.iteritems():
+ new_data[exp] = coeff.expand()
+ return cls(new_data)
+
class DensepolyHead(Head):
"""
DensepolyHead is a head for dense polynomials represented
=======================================
--- /trunk/sympycore/polynomials/algebra.py Sun Sep 18 14:34:28 2011
+++ /trunk/sympycore/polynomials/algebra.py Mon Sep 19 13:56:01 2011
@@ -473,6 +473,11 @@
return type(self)(head, d)

def variable_integrate(self, variable, *bounds):
+ """ Return integral over variable.
+
+ poly.variable_integrate(x) -> indefinite integral
+ poly.variable_integrate(x, a, b) -> definite integral
+ """
try:
index = list(self.variables).index(variable)
except ValueError:
@@ -486,6 +491,8 @@
raise NotImplementedError(`self.variables, variable, index`)

def variable_subs(self, variable, newexpr):
+ """ Substitute variable with newexpr that must be instance of the
same ring.
+ """
cls = type(self)
newexpr = cls(newexpr)
try:

Reply all
Reply to author
Forward
0 new messages