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

Commit c67f957

Browse files
Implement distribute() in the multiplicative case.
1 parent a018030 commit c67f957

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/sage/symbolic/expression.pyx

+24-2
Original file line numberDiff line numberDiff line change
@@ -10395,6 +10395,8 @@ cdef class Expression(CommutativeRingElement):
1039510395
1039610396
- Integral (definite or not) of a sum ==> sum of integrals.
1039710397
10398+
_ Symbolic product of a product ==> product of symbolic products.
10399+
1039810400
INPUT:
1039910401
1040010402
- ``self`` - expression whose operator may be distributed.
@@ -10427,15 +10429,22 @@ cdef class Expression(CommutativeRingElement):
1042710429
sum(sum(Y(k), k, 1, q) + sum(Z(k), k, 1, q), j, 1, p) + sum(X(j), j, 1, p)
1042810430
sage: sum(X(j)+sum(Y(k)+Z(k),k,1,q),j,1,p).distribute(recursive=False)
1042910431
sum(X(j), j, 1, p) + sum(sum(Y(k) + Z(k), k, 1, q), j, 1, p)
10432+
sage: maxima("product(X(j)*Y(j),j,1,p)").sage()
10433+
product(X(j)*Y(j), j, 1, p)
10434+
sage: maxima("product(X(j)*Y(j),j,1,p)").sage().distribute()
10435+
product(X(j), j, 1, p)*product(Y(j), j, 1, p)
10436+
1043010437
1043110438
AUTHORS:
1043210439
1043310440
- Emmanuel Charpentier, Ralf Stephan (05-2017)
1043410441
"""
10435-
from sage.functions.other import symbolic_sum as opsum
10442+
from sage.functions.other import symbolic_sum as opsum, \
10443+
symbolic_product as opprod
1043610444
from sage.symbolic.integration.integral \
1043710445
import indefinite_integral as opii, definite_integral as opdi
10438-
from sage.symbolic.operators import add_vararg as opadd
10446+
from sage.symbolic.operators import add_vararg as opadd, \
10447+
mul_vararg as opmul
1043910448
def treat_term(op, term, args):
1044010449
l=sage.all.copy(args)
1044110450
l.insert(0, term)
@@ -10456,6 +10465,19 @@ cdef class Expression(CommutativeRingElement):
1045610465
aa))
1045710466
return sum(map(lambda t:treat_term(op, t, la), aa))
1045810467
return self
10468+
if op is opprod:
10469+
sa = self.operands()[0].expand()
10470+
op1 = sa.operator()
10471+
if op1 is opmul:
10472+
la = self.operands()[1:]
10473+
aa = sa.operands()
10474+
if recursive:
10475+
return sage.all.prod(map(lambda t:treat_term(op,
10476+
t.distribute(),
10477+
la),
10478+
aa))
10479+
return sage.all.prod(map(lambda t:treat_term(op, t, la), aa))
10480+
return self
1045910481
if recursive:
1046010482
return apply(op, map(lambda t:t.distribute(), self.operands()))
1046110483
return self

0 commit comments

Comments
 (0)