|
|
last edited 11 years ago by test1 |
1 2 3 4 5 6 7 8 9 10 11 12 | ||
Editor: test1
Time: 2013/04/25 19:55:41 GMT+0 |
||
Note: |
changed: -macro IE == IndexedExponents(VAR) -macro IEP == IndexedExponents(Sum(VAR,VAR)) -macro SMP == SparseMultivariatePolynomial(R,Sum(VAR,VAR)) IE ==> IndexedExponents(VAR) IEP ==> IndexedExponents(Sum(VAR,VAR)) SMP ==> SparseMultivariatePolynomial(R,Sum(VAR,VAR)) changed: - (p:P \/ q:P):SMP == scanPoly(p,1)*scanPoly(q,2) _\_/(p:P, q:P) : SMP == scanPoly(p,1)*scanPoly(q,2) changed: -macro IE1 == IndexedExponents(VAR1) -macro IE2 == IndexedExponents(VAR2) -macro S == Sum(VAR1,VAR2) -macro IEP == IndexedExponents(S) -macro SMP == SparseMultivariatePolynomial(R,S) IE1 ==> IndexedExponents(VAR1) IE2 ==> IndexedExponents(VAR2) S ==> Sum(VAR1,VAR2) IEP ==> IndexedExponents(S) SMP ==> SparseMultivariatePolynomial(R,S) changed: - (p:P \/ q:Q):SMP == scanPoly1(p)*scanPoly2(q) _\_/(p:P, q:Q) : SMP == scanPoly1(p)*scanPoly2(q)
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
(1) -> )lib SUM
Sum is now explicitly exposed in frame initial Sum will be automatically loaded when needed from /var/aw/var/LatexWiki/SUM.NRLIB/SUM
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)
There are 1 exposed and 3 unexposed library operations named leadingMonomial having 1 argument(s) but none was determined to be applicable. Use HyperDoc Browse,or issue )display op leadingMonomial to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named leadingMonomial with argument type(s) Variable(x)
Perhaps you should use "@" to indicate the required return type,or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code. There are 1 exposed and 3 unexposed library operations named leadingMonomial having 1 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op leadingMonomial to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named leadingMonomial with argument type(s) Variable(x)
Perhaps you should use "@" to indicate the required return type,or "$" to specify which version of the function you need.
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
(4) |
q:=5*x*y+7*y+11
(5) |
r:=tensorPoly(p,q)
>> System error: #<SB-SYS:FD-STREAM for "file /var/aw/var/LatexWiki/SUM.NRLIB/SUM.fasl" {10021C7463}> is a fasl file compiled with SBCL 1.1.1,and can't be loaded into SBCL 2.2.9.debian.
Demonstrating the axioms (1) (2) and (3) of the tensor product:
w:= 13*y^2+17*y+19
(6) |
test( tensorPoly(p+q,w) = (tensorPoly(p, w) + tensorPoly(q, w)) )
Compiling function tensorPoly with type (Polynomial(Integer),Polynomial(Integer)) -> NonNegativeInteger
>> System error: The function BOOT::|*2;scanPoly;1;initial| is undefined.
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 IE ==> IndexedExponents(VAR) IEP ==> IndexedExponents(Sum(VAR,VAR)) 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 FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6318234874982058351-25px007.spad using old system compiler. TPROD abbreviates package TensorProduct ------------------------------------------------------------------------ initializing NRLIB TPROD for TensorProduct compiling into NRLIB TPROD compiling local scanIndex : (IndexedExponents VAR,Integer) -> IndexedExponents Sum(VAR, VAR) ****** comp fails at level 7 with expression: ****** error in function scanIndex
(SEQ (|:=| (|:| #1=#:G15 (|Boolean|)) (|zero?| |x|)) (|exit| 1 (IF #1# 0 (+ (|monomial| (|leadingCoefficient| |x|) (IF (= |n| 1) | << | ((|Sel| (|Sum| VAR VAR) |in1|) (|leadingSupport| |x|)) | >> | ((|Sel| (|Sum| VAR VAR) |in2|) (|leadingSupport| |x|)))) (|scanIndex| (|reductum| |x|) |n|))))) ****** level 7 ****** $x:= ((Sel (Sum VAR VAR) in1) (leadingSupport x)) $m:= VAR $f:= ((((#:G15 # #) (|n| # #) (|x| # #) (|scanIndex| #) ...)))
>> Apparent user error: Cannot coerce x of mode (IndexedExponents VAR) to mode ##3
test( p\/q = r )
There are 2 exposed and 1 unexposed library operations named \/ having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse,or issue )display op \/ to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named \/ with argument type(s) Polynomial(Integer) Polynomial(Integer)
Perhaps you should use "@" to indicate the required return type,or "$" to specify which version of the function you need.
Here's another way to write this - maybe better this way as first step to express associativity of the tensor product.
)abbrev package TPROD2 TensorProduct2 IE1 ==> IndexedExponents(VAR1) IE2 ==> IndexedExponents(VAR2) S ==> Sum(VAR1,VAR2) IEP ==> IndexedExponents(S) SMP ==> SparseMultivariatePolynomial(R, S)
TensorProduct2(R:Ring,VAR1: OrderedSet, VAR2: OrderedSet, P:PolynomialCategory(R, IE1, VAR1), Q:PolynomialCategory(R, IE2, VAR2)): with _\_/: (P, Q) -> SMP == add scanIndex1(x:IE1):IEP == zero? x => 0 monomial(leadingCoefficient(x), in1(leadingSupport(x))$S) + scanIndex1(reductum(x)) scanIndex2(x:IE2):IEP == zero? x => 0 monomial(leadingCoefficient(x), in2(leadingSupport(x))$S) + scanIndex2(reductum(x)) mapMonomial1(p:P):SMP == monomial(coefficient(p, degree p), scanIndex1(degree(p)))$SMP mapMonomial2(q:Q):SMP == monomial(coefficient(q, degree q), scanIndex2(degree(q)))$SMP scanPoly1(p:P):SMP == p=0 => 0 mapMonomial1(leadingMonomial(p))+scanPoly1(reductum p) scanPoly2(q:Q):SMP == q=0 => 0 mapMonomial2(leadingMonomial(q))+scanPoly2(reductum q)
_\_/(p:P,q:Q) : SMP == scanPoly1(p)*scanPoly2(q)
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/4565958775469301848-25px009.spad using old system compiler. TPROD2 abbreviates package TensorProduct2 ------------------------------------------------------------------------ initializing NRLIB TPROD2 for TensorProduct2 compiling into NRLIB TPROD2 compiling local scanIndex1 : IndexedExponents VAR1 -> IndexedExponents Sum(VAR1,VAR2) ****** comp fails at level 6 with expression: ****** error in function scanIndex1
(SEQ (|:=| (|:| #1=#:G16 (|Boolean|)) (|zero?| |x|)) (|exit| 1 (IF #1# 0 (+ (|monomial| (|leadingCoefficient| |x|) | << | ((|Sel| (|Sum| VAR1 VAR2) |in1|) (|leadingSupport| |x|)) | >> |) (|scanIndex1| (|reductum| |x|)))))) ****** level 6 ****** $x:= ((Sel (Sum VAR1 VAR2) in1) (leadingSupport x)) $m:= VAR1 $f:= ((((#:G16 # #) (|x| # . #1=#) (|scanIndex1| #) (|x| . #1#) ...)))
>> Apparent user error: Cannot coerce x of mode (IndexedExponents VAR1) to mode ##5
test( p\/q = r )
There are 2 exposed and 1 unexposed library operations named \/ having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse,or issue )display op \/ to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named \/ with argument type(s) Polynomial(Integer) Polynomial(Integer)
Perhaps you should use "@" to indicate the required return type,or "$" to specify which version of the function you need.
Associativity of the tensor product means these two expressions should be identical:
(p\/q)\/w
There are 2 exposed and 1 unexposed library operations named \/ having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse,or issue )display op \/ to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named \/ with argument type(s) Polynomial(Integer) Polynomial(Integer)
Perhaps you should use "@" to indicate the required return type,or "$" to specify which version of the function you need.