|
|
last edited 11 years ago by test1 |
1 2 3 4 5 6 7 8 9 10 11 12 | ||
Editor: Bill Page
Time: 2008/08/26 13:06:12 GMT-7 |
||
Note: spad version tests |
changed: - _/_\: (P,P) -> SMP _\_/: (P,P) -> SMP changed: - _/_\(p:P,q:P):SMP == scanPoly(p,1)*scanPoly(q,2) (p:P \/ q:P):SMP == scanPoly(p,1)*scanPoly(q,2) added: \begin{axiom} test( p\/q = r ) test( (p+q) \/ w = (p\/w) + (q\/w) ) test( p \/ (q+w) = (p\/q) + (p\/w) ) test( p \/ (23*w) = 23*(p\/w) ) test( (23*p) \/ w = 23*(p\/w) ) \end{axiom}
http://en.wikipedia.org/wiki/Tensor_product
A tensor product is "the most general bilinear operation" available in a specified domain of computation, satisfying:
(1) |
(2) |
(3) |
We can use the domain constructor Sum
[SandBoxSum]?
)lib SUM
Sum is now explicitly exposed in frame initial Sum will be automatically loaded when needed from /var/zope2/var/LatexWiki/SUM.NRLIB/code.o
First we can define some recursive operations on the polynomials
scanPoly(p,n) == _ (p=0 => 0; mapMonomial(leadingMonomial(p),n)+scanPoly(reductum p,n))
mapMonomial(p,n) == _ monomial(coefficient(p,degree p),scanIndex(degree(p),n))$SMP(Integer,Sum(Symbol,Symbol))
scanIndex(p,n) == _ (zero? p => 0$IndexedExponents(Sum(Symbol,Symbol)); _ monomial(leadingCoefficient(p), _ if n=1 then in1(leadingSupport(p))$Sum(Symbol,Symbol) _ else in2(leadingSupport(p))$Sum(Symbol,Symbol) _ )$IndexedExponents(Sum(Symbol,Symbol))+ _ scanIndex(reductum(p),n))
For example:
-- functions are first compiled here -- scanPoly(x,1)
Compiling function scanIndex with type (IndexedExponents Symbol, Integer) -> IndexedExponents Sum(Symbol,Symbol) ; (DEFUN |*2;scanIndex;1;initial| ...) is being compiled. ;; The variable |*2;scanIndex;1;initial;MV| is undefined. ;; The compiler will assume this variable is a global.
Compiling function mapMonomial with type (Polynomial Integer,Integer ) -> SparseMultivariatePolynomial(Integer,Sum(Symbol,Symbol)) ; (DEFUN |*2;mapMonomial;1;initial| ...) is being compiled. ;; The variable |*2;mapMonomial;1;initial;MV| is undefined. ;; The compiler will assume this variable is a global.
Compiling function scanPoly with type (Polynomial Integer,Integer) -> SparseMultivariatePolynomial(Integer,Sum(Symbol,Symbol)) ; (DEFUN |*2;scanPoly;3;initial| ...) is being compiled. ;; The variable |*2;scanPoly;3;initial;MV| is undefined. ;; The compiler will assume this variable is a global.
Compiling function scanPoly with type (Polynomial Integer,Integer) -> SparseMultivariatePolynomial(Integer,Sum(Symbol,Symbol))
;;; *** |*2;scanPoly;3;initial| REDEFINED ; (DEFUN |*2;scanPoly;3;initial| ...) is being compiled. ;; The variable |*2;scanPoly;3;initial;MV| is undefined. ;; The compiler will assume this variable is a global.
Compiling function scanPoly with type (Variable x,Integer) -> SparseMultivariatePolynomial(Integer,Sum(Symbol,Symbol)) ; (DEFUN |*2;scanPoly;1;initial| ...) is being compiled. ;; The variable |*2;scanPoly;1;initial;MV| is undefined. ;; The compiler will assume this variable is a global.
(4) |
injects the polynomial x
in to the tensor product. So
now the full tensor product is just:
tensorPoly(p,q) == _ scanPoly(p,1)*scanPoly(q,2)
For example:
p:=2*x^2+3
(5) |
q:=5*x*y+7*y+11
(6) |
r:=tensorPoly(p,q)
Compiling function tensorPoly with type (Polynomial Integer, Polynomial Integer) -> SparseMultivariatePolynomial(Integer,Sum( Symbol,Symbol)) ; (DEFUN |*2;tensorPoly;1;initial| ...) is being compiled. ;; The variable |*2;tensorPoly;1;initial;MV| is undefined. ;; The compiler will assume this variable is a global.
(7) |
monomials(r)
(8) |
Demonstrating the axioms (1) (2) and (3) of the tensor product:
w:= 13*y^2+17*y+19
(9) |
test( tensorPoly(p+q,w) = (tensorPoly(p,w) + tensorPoly(q,w)) )
(10) |
test( tensorPoly(p,q+w) = (tensorPoly(p,q) + tensorPoly(p,w)) )
(11) |
test( tensorPoly(p,23*w) = 23*tensorPoly(p,w) )
(12) |
test( tensorPoly(23*p,w) = 23*tensorPoly(p,w) )
(13) |
I suppose that we could give an inductive proof that this implementation of the tensor product of polynomials is correct ... but for now lets take this demonstration as reassurance.
Re-coding the interpreter functions as library package.
)abbrev package TPROD TensorProduct macro IE == IndexedExponents(VAR) macro IEP == IndexedExponents(Sum(VAR,VAR)) macro SMP == SparseMultivariatePolynomial(R,Sum(VAR,VAR))
TensorProduct(R:Ring, VAR: OrderedSet, P:PolynomialCategory(R,IE,VAR)): with _\_/: (P,P) -> SMP == add scanIndex(x:IE,n:Integer):IEP == zero? x => 0 monomial(leadingCoefficient(x), _ if n=1 then in1(leadingSupport(x))$Sum(VAR,VAR) _ else in2(leadingSupport(x))$Sum(VAR,VAR) _ ) + scanIndex(reductum(x),n) mapMonomial(p:P,n:Integer):SMP == monomial(coefficient(p,degree p),scanIndex(degree(p),n))$SMP scanPoly(p:P,n:Integer):SMP == p=0 => 0 mapMonomial(leadingMonomial(p),n)+scanPoly(reductum p,n)
(p:P \/ q:P):SMP == scanPoly(p,1)*scanPoly(q,2)
Compiling OpenAxiom source code from file /var/zope2/var/LatexWiki/7467299293205133182-25px007.spad using Spad compiler. TPROD abbreviates package TensorProduct processing macro definition IE ==> IndexedExponents VAR
processing macro definition IEP ==> IndexedExponents Sum(VAR,VAR)
processing macro definition SMP ==> SparseMultivariatePolynomial(R,Sum(VAR,VAR))
------------------------------------------------------------------------ initializing NRLIB TPROD for TensorProduct compiling into NRLIB TPROD Adding $ modemaps Adding R modemaps Adding VAR modemaps Adding P modemaps Adding IndexedExponents Sum(VAR,VAR) modemaps Adding Integer modemaps Adding IndexedExponents VAR modemaps compiling local scanIndex : (IndexedExponents VAR,Integer) -> IndexedExponents Sum(VAR,VAR) Adding Boolean modemaps Adding NonNegativeInteger modemaps Adding Sum(VAR,VAR) modemaps Time: 0.13 SEC.
Adding SparseMultivariatePolynomial(R,Sum(VAR,VAR)) modemaps Adding Integer modemaps compiling local mapMonomial : (P,Integer) -> SparseMultivariatePolynomial(R,Sum(VAR,VAR)) Adding IndexedExponents VAR modemaps Time: 0.01 SEC.
Adding Integer modemaps compiling local scanPoly : (P,Integer) -> SparseMultivariatePolynomial(R,Sum(VAR,VAR)) Adding Boolean modemaps Time: 0.01 SEC.
compiling exported \/ : (P,P) -> SparseMultivariatePolynomial(R,Sum(VAR,VAR)) Adding Integer modemaps Adding NonNegativeInteger modemaps Adding PositiveInteger modemaps Adding Fraction Integer modemaps Time: 0.04 SEC.
(time taken in buildFunctor: 0)
;;; *** |TensorProduct| REDEFINED
;;; *** |TensorProduct| REDEFINED Time: 0.01 SEC.
Warnings: [1] scanIndex: not known that OrderedSet is of mode CATEGORY(domain,IF(has(VAR,Finite),IF(has(VAR,Finite),Finite,%noBranch),%noBranch),IF(has(VAR,Monoid),IF(has(VAR,Monoid),Monoid,%noBranch),%noBranch),IF(has(VAR,AbelianMonoid),IF(has(VAR,AbelianMonoid),AbelianMonoid,%noBranch),%noBranch),IF(has(VAR,CancellationAbelianMonoid),IF(has(VAR,CancellationAbelianMonoid),CancellationAbelianMonoid,%noBranch),%noBranch),IF(has(VAR,Group),IF(has(VAR,Group),Group,%noBranch),%noBranch),IF(has(VAR,AbelianGroup),IF(has(VAR,AbelianGroup),AbelianGroup,%noBranch),%noBranch),IF(has(VAR,OrderedAbelianMonoidSup),IF(has(VAR,OrderedAbelianMonoidSup),OrderedAbelianMonoidSup,%noBranch),%noBranch),IF(has(VAR,OrderedSet),IF(has(VAR,OrderedSet),OrderedSet,%noBranch),%noBranch),selectsum: % -> Union(acomp: VAR,bcomp: VAR),in1: VAR -> %,in2: VAR -> %) [2] mapMonomial: not known that OrderedSet is of mode CATEGORY(domain,IF(has(VAR,Finite),IF(has(VAR,Finite),Finite,%noBranch),%noBranch),IF(has(VAR,Monoid),IF(has(VAR,Monoid),Monoid,%noBranch),%noBranch),IF(has(VAR,AbelianMonoid),IF(has(VAR,AbelianMonoid),AbelianMonoid,%noBranch),%noBranch),IF(has(VAR,CancellationAbelianMonoid),IF(has(VAR,CancellationAbelianMonoid),CancellationAbelianMonoid,%noBranch),%noBranch),IF(has(VAR,Group),IF(has(VAR,Group),Group,%noBranch),%noBranch),IF(has(VAR,AbelianGroup),IF(has(VAR,AbelianGroup),AbelianGroup,%noBranch),%noBranch),IF(has(VAR,OrderedAbelianMonoidSup),IF(has(VAR,OrderedAbelianMonoidSup),OrderedAbelianMonoidSup,%noBranch),%noBranch),IF(has(VAR,OrderedSet),IF(has(VAR,OrderedSet),OrderedSet,%noBranch),%noBranch),selectsum: % -> Union(acomp: VAR,bcomp: VAR),in1: VAR -> %,in2: VAR -> %)
Cumulative Statistics for Constructor TensorProduct Time: 0.20 seconds
finalizing NRLIB TPROD Processing TensorProduct for Browser database: --->-->TensorProduct((\/ (SMP P P))): Not documented!!!! --->-->TensorProduct(constructor): Not documented!!!! --->-->TensorProduct(): Missing Description ------------------------------------------------------------------------ TensorProduct is now explicitly exposed in frame initial TensorProduct will be automatically loaded when needed from /var/zope2/var/LatexWiki/TPROD.NRLIB/code.o
test( p\/q = r )
(14) |
test( (p+q) \/ w = (p\/w) + (q\/w) )
(15) |
test( p \/ (q+w) = (p\/q) + (p\/w) )
(16) |
test( p \/ (23*w) = 23*(p\/w) )
(17) |
test( (23*p) \/ w = 23*(p\/w) )
(18) |