diff --git a/changelog b/changelog index 3ba51a4..965fce8 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +20080822 tpd src/input/Makefile add linalg, overload regression tests +20080822 tpd src/input/linalg.input recovered +20080822 tpd src/input/overload.input recovered 20080821 tpd src/algebra/Makefile add MappingPackage4 20080821 tpd src/algebra/exposed.lsp add MappingPackage4 20080821 tpd src/algebra/mappkg.spad add MAPPKG4 diff --git a/src/input/Makefile.pamphlet b/src/input/Makefile.pamphlet index 0d919d6..3f80d67 100644 --- a/src/input/Makefile.pamphlet +++ b/src/input/Makefile.pamphlet @@ -244,9 +244,6 @@ WRAPPED=loop.output # Error: Value stack overflow. VALUESTACK=tutchap67.output -# Broken at |MATCAT-;*;3S;29|. Type :H for Help. -MATCAT=linalg.output - # Broken at |STAGG-;ELT;AIS;5|. Type :H for Help. STAGG=reductio.output @@ -326,7 +323,8 @@ REGRES= algaggr.regress algbrbf.regress algfacob.regress alist.regress \ kamke0.regress kamke1.regress kamke2.regress kamke3.regress \ kamke4.regress kamke5.regress kamke6.regress kamke7.regress \ kernel.regress knot2.regress kovacic.regress kuipers.regress \ - laplace.regress leg.regress limit.regress lindep.regress \ + laplace.regress leg.regress limit.regress linalg.regress \ + lindep.regress \ list.regress lode.regress lodesys.regress lodo1.regress \ lodo2.regress lodo3.regress lodof.regress lodo.regress \ log.regress \ @@ -341,6 +339,7 @@ REGRES= algaggr.regress algbrbf.regress algfacob.regress alist.regress \ nqip.regress nsfip.regress numbers.regress octonion.regress \ oct.regress ode.regress odpol.regress op1.regress \ opalg.regress operator.regress op.regress ovar.regress \ + overload.regress \ padic.regress parabola.regress pascal1.regress pascal.regress \ patch51.regress page.regress \ patmatch.regress pat.regress perman.regress perm.regress \ @@ -594,6 +593,7 @@ FILES= ${OUT}/algaggr.input ${OUT}/algbrbf.input ${OUT}/algfacob.input \ ${OUT}/kovacic.input ${OUT}/kuipers.input \ ${OUT}/laplace.input ${OUT}/leg.input ${OUT}/lexp.input \ ${OUT}/lextripk.input ${OUT}/lib.input ${OUT}/limit.input \ + ${OUT}/linalg.input \ ${OUT}/lindep.input ${OUT}/liss1.input ${OUT}/liss2.input \ ${OUT}/list.input ${OUT}/lode.input ${OUT}/lodesys.input \ ${OUT}/lodo1.input ${OUT}/lodo2.input ${OUT}/lodof.input \ @@ -613,10 +613,10 @@ FILES= ${OUT}/algaggr.input ${OUT}/algbrbf.input ${OUT}/algfacob.input \ ${OUT}/nepip.input ${OUT}/newton.input \ ${OUT}/nlode.input ${OUT}/none.input ${OUT}/noonburg.input \ ${OUT}/noptip.input ${OUT}/nqip.input ${OUT}/nsfip.input \ - ${OUT}/ntube.input ${OUT}/oct.input ${OUT}/ode.input \ + ${OUT}/ntube.input ${OUT}/oct.input ${OUT}/ode.input \ ${OUT}/octonion.input ${OUT}/odpol.input \ ${OUT}/opalg.input ${OUT}/operator.input ${OUT}/op.input \ - ${OUT}/op1.input ${OUT}/ovar.input \ + ${OUT}/op1.input ${OUT}/ovar.input ${OUT}/overload.input \ ${OUT}/padic.input ${OUT}/palette.input \ ${OUT}/parpcurv.input ${OUT}/parscurv.input ${OUT}/parsurf.input \ ${OUT}/pascal1.input \ @@ -927,6 +927,7 @@ DOCFILES= \ ${DOC}/odpol.input.dvi ${DOC}/op1.input.dvi \ ${DOC}/opalg.input.dvi ${DOC}/operator.input.dvi \ ${DOC}/op.input.dvi ${DOC}/ovar.input.dvi \ + ${DOC}/overload.input.dvi \ ${DOC}/padic.input.dvi ${DOC}/palette.input.dvi \ ${DOC}/parabola.input.dvi ${DOC}/parpcurv.input.dvi \ ${DOC}/parscurv.input.dvi ${DOC}/parsurf.input.dvi \ diff --git a/src/input/linalg.input.pamphlet b/src/input/linalg.input.pamphlet index c39e5c7..17156fe 100644 --- a/src/input/linalg.input.pamphlet +++ b/src/input/linalg.input.pamphlet @@ -10,104 +10,929 @@ \tableofcontents \eject <<*>>= +)spool linalg.output +)set message test on +)set message auto off +)set break resume +)clear all -- Input for page MatrixMoreFunctionsPage )clear all +--S 1 of 82 m1 := matrix([[1,-2,1],[4,2,-4]]) +--R +--R +1 - 2 1 + +--R (1) | | +--R +4 2 - 4+ +--R Type: Matrix Integer +--E 1 + +--S 2 of 82 m2 := matrix([[0,1,2],[2,3,4],[3,4,5]]) +--R +--R +0 1 2+ +--R | | +--R (2) |2 3 4| +--R | | +--R +3 4 5+ +--R Type: Matrix Integer +--E 2 + +--S 3 of 82 m3 := matrix([[1,2,3],[2,4,6]]) +--R +--R +1 2 3+ +--R (3) | | +--R +2 4 6+ +--R Type: Matrix Integer +--E 3 + +--S 4 of 82 m1 + m3 +--R +--R +2 0 4+ +--R (4) | | +--R +6 6 2+ +--R Type: Matrix Integer +--E 4 + +--S 5 of 82 100 * m1 +--R +--R +100 - 200 100 + +--R (5) | | +--R +400 200 - 400+ +--R Type: Matrix Integer +--E 5 + +--S 6 of 82 m1 * m2 +--R +--R +- 1 - 1 - 1+ +--R (6) | | +--R +- 8 - 6 - 4+ +--R Type: Matrix Integer +--E 6 + +--S 7 of 82 -m1 + m3 * m2 +--R +--R +12 21 24+ +--R (7) | | +--R +22 36 54+ +--R Type: Matrix Integer +--E 7 + +--S 8 of 82 m2 * m1 +--R +--R +--RDaly Bug +--R >> Error detected within library code: +--R can't multiply matrices of incompatible dimensions +--R +--R Continuing to read the file... +--R +--E 8 + +--S 9 of 82 v := vector([1,0,1]) +--R +--R (8) [1,0,1] +--R Type: Vector NonNegativeInteger +--E 9 + +--S 10 of 82 m3 * v +--R +--R (9) [4,8] +--R Type: Vector Integer +--E 10 + +--S 11 of 82 m5 : MATRIX POLY INT := new(4,4,1) +--R +--R +1 1 1 1+ +--R | | +--R |1 1 1 1| +--R (10) | | +--R |1 1 1 1| +--R | | +--R +1 1 1 1+ +--R Type: Matrix Polynomial Integer +--E 11 + +--S 12 of 82 vars : LIST POLY INT := [x,y,z,u] +--R +--R (11) [x,y,z,u] +--R Type: List Polynomial Integer +--E 12 + +--S 13 of 82 for i in 1..4 repeat for j in 1..3 repeat m5(i,j + 1) := (vars.i)**j +--R Type: Void +--E 13 + +--S 14 of 82 m5 +--R +--R + 2 3+ +--R |1 x x x | +--R | | +--R | 2 3| +--R |1 y y y | +--R (13) | | +--R | 2 3| +--R |1 z z z | +--R | | +--R | 2 3| +--R +1 u u u + +--R Type: Matrix Polynomial Integer +--E 14 + +--S 15 of 82 trace(m5) +--R +--R 2 3 +--R (14) z + y + u + 1 +--R Type: Polynomial Integer +--E 15 + +--S 16 of 82 det := determinant(m5) +--R +--R (15) +--R 2 2 2 2 2 3 +--R ((- x + u)y + (x - u )y - u x + u x)z +--R + +--R 3 3 3 3 3 2 +--R ((x - u)y + (- x + u )y + u x - u x)z +--R + +--R 2 2 3 3 3 2 2 3 3 2 2 2 3 +--R ((- x + u )y + (x - u )y - u x + u x )z + (u x - u x)y +--R + +--R 3 3 2 2 3 3 2 +--R (- u x + u x)y + (u x - u x )y +--R Type: Polynomial Integer +--E 16 + +--S 17 of 82 factor(det) +--R +--R (16) - (x - u)(y - x)(y - u)(z - y)(z - x)(z - u) +--R Type: Factored Polynomial Integer +--E 17 + +--S 18 of 82 m6 := matrix([[1,2,1],[-2,3,4],[-1,5,6]]) +--R +--R + 1 2 1+ +--R | | +--R (17) |- 2 3 4| +--R | | +--R +- 1 5 6+ +--R Type: Matrix Integer +--E 18 + +--S 19 of 82 m6inv := inverse(m6) +--R +--R + 2 5 + +--R |- - - 1 - | +--R | 7 7 | +--R | | +--R (18) | 8 6| +--R | - 1 - -| +--R | 7 7| +--R | | +--R +- 1 - 1 1 + +--R Type: Union(Matrix Fraction Integer,...) +--E 19 + +--S 20 of 82 m6 * m6inv +--R +--R +1 0 0+ +--R | | +--R (19) |0 1 0| +--R | | +--R +0 0 1+ +--R Type: Matrix Fraction Integer +--E 20 + +--S 21 of 82 m7 := matrix([[1,2,1],[-2,3,4],[-1,5,5]]) +--R +--R + 1 2 1+ +--R | | +--R (20) |- 2 3 4| +--R | | +--R +- 1 5 5+ +--R Type: Matrix Integer +--E 21 + +--S 22 of 82 inverse(m7) +--R +--R (21) "failed" +--R Type: Union("failed",...) +--E 22 + +--S 23 of 82 determinant(m7) +--R +--R (22) 0 +--R Type: NonNegativeInteger +--E 23 + +--S 24 of 82 m8 : SQMATRIX(2,INT) := matrix([[1,2],[2,3]]) +--R +--R +1 2+ +--R (23) | | +--R +2 3+ +--R Type: SquareMatrix(2,Integer) +--E 24 + +--S 25 of 82 m9 : SQMATRIX(2,INT) := matrix([[1,1],[0,1]]) +--R +--R +1 1+ +--R (24) | | +--R +0 1+ +--R Type: SquareMatrix(2,Integer) +--E 25 + +--S 26 of 82 m8 ** 2 +--R +--R +5 8 + +--R (25) | | +--R +8 13+ +--R Type: SquareMatrix(2,Integer) +--E 26 + +--S 27 of 82 m9 ** 3 +--R +--R +1 3+ +--R (26) | | +--R +0 1+ +--R Type: SquareMatrix(2,Integer) +--E 27 + +--S 28 of 82 mm : SQMATRIX(2,SQMATRIX(2,INT)) := matrix([[1,m8],[m9,0]]) +--R +--R ++1 0+ +1 2++ +--R || | | || +--R |+0 1+ +2 3+| +--R (27) | | +--R |+1 1+ +0 0+| +--R || | | || +--R ++0 1+ +0 0++ +--R Type: SquareMatrix(2,SquareMatrix(2,Integer)) +--E 28 + +--S 29 of 82 100 * mm +--R +--R ++100 0 + +100 200++ +--R || | | || +--R |+ 0 100+ +200 300+| +--R (28) | | +--R |+100 100+ +0 0+ | +--R || | | | | +--R ++ 0 100+ +0 0+ + +--R Type: SquareMatrix(2,SquareMatrix(2,Integer)) +--E 29 + +--S 30 of 82 m8 * mm +--R +--R ++1 2+ +5 8 ++ +--R || | | || +--R |+2 3+ +8 13+| +--R (29) | | +--R |+1 3+ +0 0+ | +--R || | | | | +--R ++2 5+ +0 0+ + +--R Type: SquareMatrix(2,SquareMatrix(2,Integer)) +--E 30 + +--S 31 of 82 mm * mm +--R +--R ++2 3+ +1 2++ +--R || | | || +--R |+2 6+ +2 3+| +--R (30) | | +--R |+1 1+ +3 5+| +--R || | | || +--R ++0 1+ +2 3++ +--R Type: SquareMatrix(2,SquareMatrix(2,Integer)) +--E 31 + +--S 32 of 82 p : POLY SQMATRIX(2,INT) := m8 * x**2 + m9 * x + m8 * m9 +--R +--R +1 2+ 2 +1 1+ +1 3+ +--R (31) | |x + | |x + | | +--R +2 3+ +0 1+ +2 5+ +--R Type: Polynomial SquareMatrix(2,Integer) +--E 32 + +--S 33 of 82 100 * p +--R +--R +100 200+ 2 +100 100+ +100 300+ +--R (32) | |x + | |x + | | +--R +200 300+ + 0 100+ +200 500+ +--R Type: Polynomial SquareMatrix(2,Integer) +--E 33 + +--S 34 of 82 m8 * p +--R +--R +5 8 + 2 +1 3+ +5 13+ +--R (33) | |x + | |x + | | +--R +8 13+ +2 5+ +8 21+ +--R Type: Polynomial SquareMatrix(2,Integer) +--E 34 + +--S 35 of 82 p * p +--R +--R +5 8 + 4 +4 8+ 3 +13 26+ 2 +4 12+ +7 18+ +--R (34) | |x + | |x + | |x + | |x + | | +--R +8 13+ +4 8+ +20 41+ +4 12+ +12 31+ +--R Type: Polynomial SquareMatrix(2,Integer) +--E 35 -- Input for page MatrixCanonicalFormsPage )clear all +--S 36 of 82 m1 := matrix([[0,4,1],[5,3,-7],[-5,5,9]]) +--R +--R + 0 4 1 + +--R | | +--R (1) | 5 3 - 7| +--R | | +--R +- 5 5 9 + +--R Type: Matrix Integer +--E 36 + +--S 37 of 82 rank(m1) +--R +--R (2) 2 +--R Type: PositiveInteger +--E 37 + +--S 38 of 82 rowEchelon(m1) +--R +--R +5 3 - 7+ +--R | | +--R (3) |0 4 1 | +--R | | +--R +0 0 0 + +--R Type: Matrix Integer +--E 38 + +--S 39 of 82 nullSpace(m1) +--R +--R (4) [[31,- 5,20]] +--R Type: List Vector Integer +--E 39 + +--S 40 of 82 t := eigenMatrix(m1) +--R +--R + +----+ +----+ + +--R |\|- 11 + 2 - \|- 11 + 2 31 | +--R |----------- ------------- -- | +--R | 5 5 20 | +--R | | +--R (5) | +----+ +----+ | +--R |2\|- 11 - 1 - 2\|- 11 - 1 1| +--R |------------ -------------- - -| +--R | 5 5 4| +--R | | +--R + 1 1 1 + +--R Type: Union(Matrix Expression Integer,...) +--E 40 + +--S 41 of 82 inverse(t) * m1 * t +--R +--R + +----+ + +--R |5581634906\|- 11 - 55255461173 | +--R |------------------------------- 0 0| +--R | +----+ | +--R | 1888197247\|- 11 - 5747548576 | +--R | | +--R (6) | +----+ | +--R | 6\|- 11 + 11 | +--R | 0 ------------- 0| +--R | +----+ | +--R | \|- 11 | +--R | | +--R + 0 0 0+ +--R Type: Matrix Expression Integer +--E 41 -- Input for page MatrixBasicFunctionsPage )clear all +--S 42 of 82 m1 := matrix([[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7]]) +--R +--R +1 2 3 4+ +--R | | +--R |2 3 4 5| +--R (1) | | +--R |3 4 5 6| +--R | | +--R +4 5 6 7+ +--R Type: Matrix Integer +--E 42 + +--S 43 of 82 m2 := matrix([[1,0,2],[20,30,10],[0,200,100]]) +--R +--R +1 0 2 + +--R | | +--R (2) |20 30 10 | +--R | | +--R +0 200 100+ +--R Type: Matrix Integer +--E 43 + +--S 44 of 82 (m3,m4) : MATRIX PF 7 +--R Type: Void +--E 44 + +--S 45 of 82 m3 := matrix([[1,0,1],[5,0,1]]) +--R +--R +1 0 1+ +--R (4) | | +--R +5 0 1+ +--R Type: Matrix PrimeField 7 +--E 45 + +--S 46 of 82 m4 := matrix([[1],[2],[5],[6]]) +--R +--R +1+ +--R | | +--R |2| +--R (5) | | +--R |5| +--R | | +--R +6+ +--R Type: Matrix PrimeField 7 +--E 46 + +--S 47 of 82 m2(1,1) +--R +--R (6) 1 +--R Type: PositiveInteger +--E 47 + +--S 48 of 82 m2(1,1) := 99 +--R +--R (7) 99 +--R Type: PositiveInteger +--E 48 + +--S 49 of 82 m2 +--R +--R +99 0 2 + +--R | | +--R (8) |20 30 10 | +--R | | +--R +0 200 100+ +--R Type: Matrix Integer +--E 49 + +--S 50 of 82 row(m2,2) +--R +--R (9) [20,30,10] +--R Type: Vector Integer +--E 50 + +--S 51 of 82 setRow!(m2,2,vector [66,77,88]) +--R +--R +99 0 2 + +--R | | +--R (10) |66 77 88 | +--R | | +--R +0 200 100+ +--R Type: Matrix Integer +--E 51 + +--S 52 of 82 r := column(m2,1) +--R +--R (11) [99,66,0] +--R Type: Vector Integer +--E 52 + +--S 53 of 82 setColumn!(m2,2,r) +--R +--R +99 99 2 + +--R | | +--R (12) |66 66 88 | +--R | | +--R +0 0 100+ +--R Type: Matrix Integer +--E 53 + +--S 54 of 82 nrows(m1) +--R +--R (13) 4 +--R Type: PositiveInteger +--E 54 + +--S 55 of 82 m5 : MATRIX INT := new(12,12,0) +--R +--R +0 0 0 0 0 0 0 0 0 0 0 0+ +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R (14) | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 0| +--R | | +--R +0 0 0 0 0 0 0 0 0 0 0 0+ +--R Type: Matrix Integer +--E 55 + +--S 56 of 82 for i in 2..nrows(m5) repeat m5(i-1,i):= 1 +--R Type: Void +--E 56 + +--S 57 of 82 m5 +--R +--R +0 1 0 0 0 0 0 0 0 0 0 0+ +--R | | +--R |0 0 1 0 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 1 0 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 1 0 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 1 0 0 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 1 0 0 0 0 0| +--R (16) | | +--R |0 0 0 0 0 0 0 1 0 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 1 0 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 1 0 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 1 0| +--R | | +--R |0 0 0 0 0 0 0 0 0 0 0 1| +--R | | +--R +0 0 0 0 0 0 0 0 0 0 0 0+ +--R Type: Matrix Integer +--E 57 + +--S 58 of 82 d : MATRIX INT := diagonalMatrix([1,2,3,2,1]) +--R +--R +1 0 0 0 0+ +--R | | +--R |0 2 0 0 0| +--R | | +--R (17) |0 0 3 0 0| +--R | | +--R |0 0 0 2 0| +--R | | +--R +0 0 0 0 1+ +--R Type: Matrix Integer +--E 58 + +--S 59 of 82 m6 := matrix([[0,1,2,3,4],[5,6,7,8,9],[10,11,12,13,14]]) +--R +--R +0 1 2 3 4 + +--R | | +--R (18) |5 6 7 8 9 | +--R | | +--R +10 11 12 13 14+ +--R Type: Matrix Integer +--E 59 + +--S 60 of 82 m7 := subMatrix(m6,1,3,2,4) +--R +--R +1 2 3 + +--R | | +--R (19) |6 7 8 | +--R | | +--R +11 12 13+ +--R Type: Matrix Integer +--E 60 + +--S 61 of 82 horizConcat(m6,m7) +--R +--R +0 1 2 3 4 1 2 3 + +--R | | +--R (20) |5 6 7 8 9 6 7 8 | +--R | | +--R +10 11 12 13 14 11 12 13+ +--R Type: Matrix Integer +--E 61 + +--S 62 of 82 vertConcat(m6,subMatrix(m6,1,1,1,5)) +--R +--R +0 1 2 3 4 + +--R | | +--R |5 6 7 8 9 | +--R (21) | | +--R |10 11 12 13 14| +--R | | +--R +0 1 2 3 4 + +--R Type: Matrix Integer +--E 62 + +--S 63 of 82 transpose(m6) -setsubMatrix(m6,1,3,1,3,transpose(subMatrix(m6,1,3,1,3))) +--R +--R +0 5 10+ +--R | | +--R |1 6 11| +--R | | +--R (22) |2 7 12| +--R | | +--R |3 8 13| +--R | | +--R +4 9 14+ +--R Type: Matrix Integer +--E 63 + +--S 64 of 82 +setsubMatrix!(m6,1,3,transpose(subMatrix(m6,1,3,1,3))) +--R +--R +0 1 0 5 10+ +--R | | +--R (23) |5 6 1 6 11| +--R | | +--R +10 11 2 7 12+ +--R Type: Matrix Integer +--E 64 + +--S 65 of 82 m6 +--R +--R +0 1 0 5 10+ +--R | | +--R (24) |5 6 1 6 11| +--R | | +--R +10 11 2 7 12+ +--R Type: Matrix Integer +--E 65 + +--S 66 of 82 m8 := matrix([[1,2],[3,4]]) +--R +--R +1 2+ +--R (25) | | +--R +3 4+ +--R Type: Matrix Integer +--E 66 + +--S 67 of 82 m9 := m8 +--R +--R +1 2+ +--R (26) | | +--R +3 4+ +--R Type: Matrix Integer +--E 67 + +--S 68 of 82 m10 := copy(m8) +--R +--R +1 2+ +--R (27) | | +--R +3 4+ +--R Type: Matrix Integer +--E 68 + +--S 69 of 82 m8(1,1) := 1000000 +--R +--R (28) 1000000 +--R Type: PositiveInteger +--E 69 + +--S 70 of 82 m8 +--R +--R +1000000 2+ +--R (29) | | +--R + 3 4+ +--R Type: Matrix Integer +--E 70 + +--S 71 of 82 m9 +--R +--R +1000000 2+ +--R (30) | | +--R + 3 4+ +--R Type: Matrix Integer +--E 71 + +--S 72 of 82 m10 +--R +--R +1 2+ +--R (31) | | +--R +3 4+ +--R Type: Matrix Integer +--E 72 -- Input for page EigenPage )clear all +--S 73 of 82 m1 : MATRIX FRAC INT := [[1,2,1],[2,1,-2],[1,-2,4]] +--R +--R +1 2 1 + +--R | | +--R (1) |2 1 - 2| +--R | | +--R +1 - 2 4 + +--R Type: Matrix Fraction Integer +--E 73 + +--S 74 of 82 leig := eigenvalues(m1) +--R +--R 2 +--I (2) [5,%A | %A - %A - 5] +--RType: List Union(Fraction Polynomial Integer,SuchThat(Symbol,Polynomial Integer)) +--E 74 + +--S 75 of 82 eigenvector(first(leig),m1) +--R +--R + 0 + +--R | | +--R | 1| +--R (3) [|- -|] +--R | 2| +--R | | +--R + 1 + +--R Type: List Matrix Fraction Polynomial Fraction Integer +--E 75 + +--S 76 of 82 eigenvectors(m1) +--R +--R (4) +--R + 0 + +--R | | +--R | 1| +--R [[eigval= 5,eigmult= 1,eigvec= [|- -|]], +--R | 2| +--R | | +--R + 1 + +--R +%C+ +--R 2 | | +--R [eigval= (%C | %C - %C - 5),eigmult= 1,eigvec= [|2 |]]] +--R | | +--R +1 + +--RType: List Record(eigval: Union(Fraction Polynomial Integer,SuchThat(Symbol,Polynomial Integer)),eigmult: NonNegativeInteger,eigvec: List Matrix Fraction Polynomial Integer) +--E 76 + +--S 77 of 82 radicalEigenvectors(m1) +--R +--R (5) +--R + +--+ + +--R +--+ |\|21 + 1| +--R \|21 + 1 |---------| +--R [[radval= ---------,radmult= 1,radvect= [| 2 |]], +--R 2 | | +--R | 2 | +--R | | +--R + 1 + +--R + +--+ + +--R +--+ |- \|21 + 1| +--R - \|21 + 1 |-----------| +--R [radval= -----------,radmult= 1,radvect= [| 2 |]], +--R 2 | | +--R | 2 | +--R | | +--R + 1 + +--R + 0 + +--R | | +--R | 1| +--R [radval= 5,radmult= 1,radvect= [|- -|]]] +--R | 2| +--R | | +--R + 1 + +--RType: List Record(radval: Expression Integer,radmult: Integer,radvect: List Matrix Expression Integer) +--E 77 + +--S 78 of 82 eigenMatrix(m1) +--R +--R + +--+ +--+ + +--R |\|21 + 1 - \|21 + 1 | +--R |--------- ----------- 0 | +--R | 2 2 | +--R (6) | | +--R | 1| +--R | 2 2 - -| +--R | 2| +--R | | +--R + 1 1 1 + +--R Type: Union(Matrix Expression Integer,...) +--E 78 + +--S 79 of 82 m2 : MATRIX FRAC INT := [[-5,-2],[18,7]] +--R +--R +- 5 - 2+ +--R (7) | | +--R +18 7 + +--R Type: Matrix Fraction Integer +--E 79 + +--S 80 of 82 eigenMatrix(m2) +--R +--R (8) "failed" +--R Type: Union("failed",...) +--E 80 + +--S 81 of 82 m3 : MATRIX FRAC INT := [[1,2],[2,1]] +--R +--R +1 2+ +--R (9) | | +--R +2 1+ +--R Type: Matrix Fraction Integer +--E 81 + +--S 82 of 82 orthonormalBasis(m3) +--R +--R + 1 + + 1 + +--R |- ----| |----| +--R | +-+| | +-+| +--R | \|2 | |\|2 | +--R (10) [| |,| |] +--R | 1 | | 1 | +--R | ---- | |----| +--R | +-+ | | +-+| +--R + \|2 + +\|2 + +--R Type: List Matrix Expression Integer +--E 82 + +)spool +)lisp (bye) + @ \eject \begin{thebibliography}{99} diff --git a/src/input/overload.input.pamphlet b/src/input/overload.input.pamphlet new file mode 100644 index 0000000..2db85a7 --- /dev/null +++ b/src/input/overload.input.pamphlet @@ -0,0 +1,680 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/input overload.input} +\author{David Cyganski} +\maketitle +\begin{abstract} +Type conversion and overload problems +\end{abstract} +\eject +\tableofcontents +\eject +<<*>>= +)spool overload.output +)set message test on +)set message auto off +)clear all +@ +\section{Type Conversion and Overload problems} +Several non-intuitive problems with overloading and type conversions +arose while developing the biquaternion (see biquat.input) support +function collection. I have extracted the minimum code set to illustrate +each of these problems. + +\section{Implicit and Explicit Type Conversions} +We begin by illustrating function calling with variously typed +arguments and conversion which we will break in various ways, some +understandable, some not(?), below. + +The cos function will produce float outcomes for float arguments +<<*>>= + +--S 1 of 28 +cos(1.237) +--R +--R +--R (1) 0.3276321705 9891498386 +--R Type: Float +--E 1 + +@ +can handle expressions that mix floats and integers +<<*>>= + +--S 2 of 28 +cos(1.237/2) +--R +--R +--R (2) 0.8147490934 6341557739 +--R Type: Float +--E 2 + +@ +but will respect an integer expression, as we would want it to, +by not evaluating +<<*>>= + +--S 3 of 28 +cos(2/3) +--R +--R +--R 2 +--R (3) cos(-) +--R 3 +--R Type: Expression Integer +--E 3 + +@ +We can coerce the evaluation as a float by forcing the floating point +evaluation of the division and typing of the outcome in a variety of +ways. Each of the following forms is effective in some appropriate +and understandable way. Some act explicitly on the ``/'' operator +to force a polymorphic choice, others convert the type of the second +constand in each expression which results in a proper implicit selection +of which ``/'' definitition to use. +<<*>>= + +--S 4 of 28 +cos(2/3::Float) +--R +--R +--R (4) 0.7858872607 7694800072 +--R Type: Float +--E 4 + +--S 5 of 28 +cos((2/3)::Float) +--R +--R +--R (5) 0.7858872607 7694800072 +--R Type: Float +--E 5 + +--S 6 of 28 +cos(2/3$Float) +--R +--R +--R (6) 0.7858872607 7694800072 +--R Type: Float +--E 6 + +--S 7 of 28 +cos((2/3)$Float) +--R +--R +--R (7) 0.7858872607 7694800072 +--R Type: Float +--E 7 + +--S 8 of 28 +cos(2/3@Float) +--R +--R +--R (8) 0.7858872607 7694800072 +--R Type: Float +--E 8 + +--S 9 of 28 +cos((2/3)@Float) +--R +--R +--R (9) 0.7858872607 7694800072 +--R Type: Float +--E 9 + +@ +But, as we would expect, it is too late to attempt coercion after the +fact. Coercion operates ``on the surface and not deeply'' as illustrated +here. +<<*>>= + +--S 10 of 28 +cos(2/3)::Float +--R +--R +--RDaly Bug +--R Cannot convert from type Expression Integer to Float for value +--R 2 +--R cos(-) +--R 3 +--R +--E 10 + +@ +However, there is a real need for a deep coercion operator that operates +on the innermost atomic constants. Suppose we define +<<*>>= + +--S 11 of 28 +cosf(x:Expression Integer):Expression Integer == 1+cos(x/2) +--R +--R Function declaration cosf : Expression Integer -> Expression Integer +--R has been added to workspace. +--R Type: Void +--E 11 + +@ +which is an example of a simple function that might be defined in the +course of typical work. We wish to declare functions as having integer +based fractions, rather than forming approximate decimal expansions, which +is preferred for purposes of analytic examination and simplification for +both the human and the Axiom system. The Axiom book and online resources +are full of examples in which this choice has been made by the authors +thanks to the power of this form of expression -- even though it amounts +to lying to Axiom in many cases as to the ultimate destiny of the function +being defined. But woe to us if we wish later to evaluate it in a more +general way because it is a tangled web we weave when we practice to +decieve. +<<*>>= + +--S 12 of 28 +cosf(2/3) +--R +--R Compiling function cosf with type Expression Integer -> Expression +--R Integer +--R +--R 1 +--R (11) cos(-) + 1 +--R 3 +--R Type: Expression Integer +--E 12 + +--S 13 of 28 +cosf((2/3)::Float) +--R +--R Conversion failed in the compiled user function cosf . +--R +--RDaly Bug +--R Cannot convert from type Float to Expression Integer for value +--R 0.6666666666 6666666667 +--R +--E 13 + +@ +Thus in effect once we wrap a function around an integer base definition, +we are stuck and unable to evaluate it as a float later, unlike the core +basic functions that can be used either way. This forces us to choose the +Float type throughout at a loss of comprehensibility and analyzability, +unless we seek to more than double our development type by supplying an +overloaded integer base and Float base version of {\bf every} step of a +sequential development of a formula. + +Bizarrely, the draw function seems to have the power to override the +type problem as shown here +<<*>>= + +--S 14 of 28 +--draw(cosf(x),x=0..15) +--E 14 + +@ +Why can't we grant this deep coercion power to some new form of floating +point conversion operation which can be applied at will? If draw has +this power, why not put it in the hands of the user? + +Alternatively, it would be best to have a {\bf mixed} type -- mixed += Integer/Float. Like Maple expressions it would leave integers as +integers and floats as floats, unmolested and treated as generic +constant quantities with distinguishable parts until an {\bf evalf} +like function that would force them entirely into the Float type. For +example, in Maple ``cos(2/3)+1.2323'' remains as is, while in Axiom +we get +<<*>>= + +--S 15 of 28 +cos(2/3)+1.2323 +--R +--R +--R (12) 2.0181872607 769480007 +--R Type: Expression Float +--E 15 + +@ +In a way, Axiom already has a quantity treated like this -- the constant +%pi is treated as a special float which remains unevaluated and does not +force combination of itself with an Integer. It simply results in a new +kind of Integer evaluation of type Pi +<<*>>= + +--S 16 of 28 +3/4+%pi +--R +--R +--R 4%pi + 3 +--R (13) -------- +--R 4 +--R Type: Pi +--E 16 + +@ +\section{Overloading problems} +Now let's examine properties and problems with overloading. + +Define the type $Q$ of Hamiltonian biquaternions +<<*>>= + +--S 17 of 28 +C:=Complex Expression Integer +--R +--R +--R (14) Complex Expression Integer +--R Type: Domain +--E 17 + +--S 18 of 28 +Q:=Quaternion C +--R +--R +--R (15) Quaternion Complex Expression Integer +--R Type: Domain +--E 18 + +@ +While developing the support functions, this definition of biquat +division was introduced to simplify the format of the formulae +<<*>>= + +--S 19 of 28 +((x:Q)/(y:Q)):Q == x*inv(y) +--R +--R Function declaration ?/? : (Quaternion Complex Expression Integer, +--R Quaternion Complex Expression Integer) -> Quaternion Complex +--R Expression Integer has been added to workspace. +--R Type: Void +--E 19 + +@ +But is this typed function in any way actually restricted to quaternions? +On the face, it would appear all is normal, here's an example of +integer division +<<*>>= + +--S 20 of 28 +x:=15/6 +--R +--R Compiling function / with type (Quaternion Complex Expression +--R Integer,Quaternion Complex Expression Integer) -> Quaternion +--R Complex Expression Integer +--R +--R 5 +--R (17) - +--R 2 +--R Type: Quaternion Complex Expression Integer +--E 20 + +@ +But though the answer was right, the type is now a biquat. If we don't +notice this, and proceed, some things seem still to act normally, +for example, no complaint from Axiom with +<<*>>= + +--S 21 of 28 +cos(x) +--R +--R +--R 5 +--R (18) cos(-) +--R 2 +--R Type: Expression Integer +--E 21 + +@ +Of course, we still get a correct answer with +<<*>>= + +--S 22 of 28 +cos(1.237) +--R +--R +--R (19) 0.3276321705 9891498386 +--R Type: Float +--E 22 + +@ +But let's try to apply this as a simple mixed float/integer function +<<*>>= + +--S 23 of 28 +cos(15.457/6) +--R +--R Conversion failed in the compiled user function / . +--R +--RDaly Bug +--R Cannot convert from type Float to Quaternion Complex Expression +--R Integer for value +--R 15.457 +--R +--E 23 + +@ +Obviously the quaternion version of ``/'' is being invoked despite +mismatches of the arguments and the supposed overloading in effect. +Well, what if we built a new cosine function that forced the form of +the arguments into certain types to avoid mismatch? +<<*>>= + +--S 24 of 28 +c(y:Float):Float == cos(y) +--R +--R Function declaration c : Float -> Float has been added to workspace. +--R Type: Void +--E 24 + +@ +At first this seems to work, we can still evaluate a float +<<*>>= + +--S 25 of 28 +c(1.237) +--R +--R Compiling function c with type Float -> Float +--R +--R (21) 0.3276321705 9891498386 +--R Type: Float +--E 25 + +@ +and we can even get a float answer when we introduce the integer coercible +biquat variable value generated from the above. +<<*>>= + +--S 26 of 28 +c(x) +--R +--R +--R (22) - 0.8011436155 4693371483 +--R Type: Float +--E 26 + +@ +But that was only misdirection, because this breaks down for reasonable +expressions because of the ``/'' operation still not being resolved +correctly. +<<*>>= + +--S 27 of 28 +c(1.237/2) +--R +--R Conversion failed in the compiled user function / . +--R +--RDaly Bug +--R Cannot convert from type Float to Quaternion Complex Expression +--R Integer for value +--R 1.237 +--R +--E 27 + +@ +Rather than complaining about it, what if we tried the various coercions +that served to solve the similar type conversion problem we had when +just dealing with Integer Fraction versus Floats at the top of the page. +Our results are mixed. Recall that each of the following worked in the +previous case, producing the correct floating result in each case. +<<*>>= + +--S 28 of 28 +cos(2/3::Float) +--R +--R +--R 2 +--R (23) cos(-) +--R 3 +--R Type: Expression Integer +--E 28 + +--S 29 of 28 +cos((2/3)::Float) +--R +--R +--R (24) 0.7858872607 7694800072 +--R Type: Float +--E 29 + +--S 30 of 28 +cos(2/3$Float) +--R +--R +--R 2 +--R (25) cos(-) +--R 3 +--R Type: Expression Integer +--E 30 + +--S 31 of 28 +cos((2/3)$Float) +--R +--R +--R (26) 0.7858872607 7694800072 +--R Type: Float +--E 31 + +--S 32 of 28 +cos(2/3@Float) +--R +--R +--R 2 +--R (27) cos(-) +--R 3 +--R Type: Expression Integer +--E 32 + +--S 33 of 28 +cos((2/3)@Float) +--R +--R +--RDaly Bug +--R An expression involving @ Float actually evaluated to one of type +--R Quaternion Complex Expression Integer . Perhaps you should use :: +--R Float . +--E 33 + +@ +Try these examples with our type constrained function, which has better +luck now +<<*>>= + +--S 34 of 28 +c(2/3::Float) +--R +--R +--R (28) 0.7858872607 7694800072 +--R Type: Float +--E 34 + +--S 35 of 28 +c((2/3)::Float) +--R +--R +--R (29) 0.7858872607 7694800072 +--R Type: Float +--E 35 + +--S 36 of 28 +c(2/3$Float) +--R +--R +--R (30) 0.7858872607 7694800072 +--R Type: Float +--E 36 + +--S 37 of 28 +c((2/3)$Float) +--R +--R +--R (31) 0.7858872607 7694800072 +--R Type: Float +--E 37 + +--S 38 of 28 +c(2/3@Float) +--R +--R +--R (32) 0.7858872607 7694800072 +--R Type: Float +--E 38 + +--S 39 of 28 +c((2/3)@Float) +--R +--R +--RDaly Bug +--R An expression involving @ Float actually evaluated to one of type +--R Quaternion Complex Expression Integer . Perhaps you should use :: +--R Float . +--E 39 + +@ +Could the above problems have been avoided by not assigning types +to the function we defined? Let's repeat the entire example with +this single change for the function c2 +<<*>>= + +--S 40 of 28 +c2(y) == cos(y) +--R +--R Type: Void +--E 40 + +--S 41 of 28 +c2(1.237) +--R +--R Compiling function c2 with type Float -> Float +--R +--R (34) 0.3276321705 9891498386 +--R Type: Float +--E 41 + +--S 42 of 28 +c2(x) +--R +--R There are 2 exposed and 6 unexposed library operations named cos +--R having 1 argument(s) but none was determined to be applicable. +--R Use HyperDoc Browse, or issue +--R )display op cos +--R to learn more about the available operations. Perhaps +--R package-calling the operation or using coercions on the arguments +--R will allow you to apply the operation. +--R Cannot find a definition or applicable library operation named cos +--R with argument type(s) +--R Quaternion Complex Expression Integer +--R +--R Perhaps you should use "@" to indicate the required return type, +--R or "$" to specify which version of the function you need. +--R AXIOM will attempt to step through and interpret the code. +--R +--R 5 +--R (35) cos(-) +--R 2 +--R Type: Expression Integer +--E 42 + +@ +But that was only misdirection, because this breaks down for +reasonable expressions +<<*>>= + +--S 43 of 28 +c2(1.237/2) +--R +--R Conversion failed in the compiled user function / . +--R +--RDaly Bug +--R Cannot convert from type Float to Quaternion Complex Expression +--R Integer for value +--R 1.237 +--R +--E 43 + +@ +and various attempts at coercion also fail -- compare these results +to the previous ones +<<*>>= + +--S 44 of 28 +c2(2/3::Float) +--R +--R +--R 2 +--R (36) cos(-) +--R 3 +--R Type: Expression Integer +--E 44 + +--S 45 of 28 +c2((2/3)::Float) +--R +--R +--R (37) 0.7858872607 7694800072 +--R Type: Float +--E 45 + +--S 46 of 28 +c2(2/3$Float) +--R +--R +--R 2 +--R (38) cos(-) +--R 3 +--R Type: Expression Integer +--E 46 + +--S 47 of 28 +c2((2/3)$Float) +--R +--R +--R (39) 0.7858872607 7694800072 +--R Type: Float +--E 47 + +--S 48 of 28 +c2(2/3@Float) +--R +--R +--R 2 +--R (40) cos(-) +--R 3 +--R Type: Expression Integer +--E 48 + +--S 49 of 28 +c2((2/3)@Float) +--R +--R +--RDaly Bug +--R An expression involving @ Float actually evaluated to one of type +--R Quaternion Complex Expression Integer . Perhaps you should use :: +--R Float . +--E 49 + +@ +Lastly, we cannot now use the graph function, draw, on such a function +since the wrong ``/'' function is used, contrary to the bypassing of +internal types we saw take place with draw in the example prior to the +introduction of operator overloading. +<<*>>= + +--S 50 of 28 +--draw(c(x),x=0..15) +--E 50 + +@ +{\sl Not safe at any speed}. Most oddly, the ordinary cos() function which +exposes no ``/'' division Now fails to work with draw despite the fact +that we just saw it above still working with Integer and Float arguments +applied directly. +<<*>>= + +--S 51 of 28 +--draw(cos(x),x=0..15) +--E 51 + +)spool +)lisp (bye) + +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document}