login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBoxTensorProductPolynomial revision 6 of 13

1 2 3 4 5 6 7 8 9 10 11 12 13
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:


\label{eq1}
(v_1+v_2)\otimes w - (v_1\otimes w+v_2\otimes w) = 0
(1)

\label{eq2}
v\otimes (w_1+w_2) - (v\otimes w_1+v\otimes w_2) = 0
(2)

\label{eq3}
cv\otimes w=v\otimes cw=c(v\otimes w)
(3)

We can use the domain constructor Sum [SandBoxSum]?

fricas
(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

fricas
scanPoly(p,n) == _
  (p=0 => 0; mapMonomial(leadingMonomial(p),n)+scanPoly(reductum p,n))
Type: Void
fricas
mapMonomial(p,n) == _
  monomial(coefficient(p,degree p),scanIndex(degree(p),n))$SMP(Integer,Sum(Symbol,Symbol))
Type: Void
fricas
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))
Type: Void

For example:

fricas
-- 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:

fricas
tensorPoly(p,q) == _
  scanPoly(p,1)*scanPoly(q,2)
Type: Void

For example:

fricas
p:=2*x^2+3

\label{eq4}{2 \ {{x}^{2}}}+ 3(4)
Type: Polynomial(Integer)
fricas
q:=5*x*y+7*y+11

\label{eq5}{{\left({5 \  x}+ 7 \right)}\  y}+{11}(5)
Type: Polynomial(Integer)
fricas
r:=tensorPoly(p,q)
>> System error: The function BOOT::PUT is undefined.

Demonstrating the axioms (1) (2) and (3) of the tensor product:

fricas
w:= 13*y^2+17*y+19

\label{eq6}{{13}\ {{y}^{2}}}+{{17}\  y}+{19}(6)
Type: Polynomial(Integer)
fricas
test( tensorPoly(p+q,w) = (tensorPoly(p,w) + tensorPoly(q,w)) )
fricas
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.

spad
)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)
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/7467299293205133182-25px007.spad
      using system compiler.
   TPROD abbreviates package TensorProduct 
------------------------------------------------------------------------
   initializing NRLIB TPROD for TensorProduct 
   compiling into NRLIB TPROD 
   compiling local scanIndex : (IE,Integer) -> IEP
   Semantic Errors: 
      [1]  IEP is not a known type
      [2]  IE is not a known type
****** comp fails at level 4 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 4 ****** x:= x m:= R f:= ((((#:G15 #) (|n| # #) (|x| # #) (|scanIndex| #) ...)))
>> Apparent user error: Cannot coerce x of mode IE to mode (Integer)

fricas
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.