diff --git a/changelog b/changelog index 04a4914..377aa85 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,13 @@ +20080818 tpd src/input/Makefile biquat.input added +20080818 dxc src/input/biquat.input added +20080818 dxc "David Cyganski" (no known email) +20080818 tpd src/input/Makefile ifthenelse.input added +20080818 fxs src/input/ifthenelse.input added +20080818 tpd src/interp/setq.lisp add Fabio Stumbo +20080818 tpd readme add Fabio Stumbo +20080818 fxs "Fabio Stumbo" (no known email) +20080818 tpd src/input/Makefile sqrt3.input added +20080818 rhx src/input/sqrt3.input added 20080818 tpd src/input/Makefile typetower.input added 20080818 rhx src/input/typetower.input added 20080817 tpd src/algebra/vector.spad doc ravel from CartesianTensor diff --git a/readme b/readme index b2e20ab..7735016 100644 --- a/readme +++ b/readme @@ -240,8 +240,8 @@ at the axiom command prompt will prettyprint the list. "Gerhard Schneider Martin Schoenert Marshall Schor" "Frithjof Schulze Fritz Schwarz Nick Simicich" "William Sit Elena Smirnova Jonathan Steinbach" -"Christine Sundaresan Robert Sutor Moss E. Sweedler" -"Eugene Surowitz" +"Fabio Stumbo Christine Sundaresan Robert Sutor" +"Moss E. Sweedler Eugene Surowitz" "Max Tegmark James Thatcher Balbir Thomas" "Mike Thomas Dylan Thurston Barry Trager" "Themos T. Tsikas" diff --git a/src/input/Makefile.pamphlet b/src/input/Makefile.pamphlet index e70b0d9..0d919d6 100644 --- a/src/input/Makefile.pamphlet +++ b/src/input/Makefile.pamphlet @@ -278,7 +278,8 @@ REGRES= algaggr.regress algbrbf.regress algfacob.regress alist.regress \ arrows.regress asinatan.regress asinhatanh.regress \ assign.regress atansqrt.regress \ asec.regress bags.regress bbtree.regress besselk.regress \ - binary.regress bop.regress bstree.regress bouquet.regress \ + binary.regress biquat.regress \ + bop.regress bstree.regress bouquet.regress \ bug100.regress bug101.regress \ bug103.regress bug10069.regress \ bugs.regress bug10312.regress bug6357.regress bug9057.regress \ @@ -315,7 +316,8 @@ REGRES= algaggr.regress algbrbf.regress algfacob.regress alist.regress \ gstbl.regress heap.regress heat.regress help.regress \ herm.regress heugcd.regress \ hexadec.regress ico.regress ideal.regress \ - ifact.regress infprod.regress intaf.regress intbypart.regress \ + ifact.regress ifthenelse.regress \ + infprod.regress intaf.regress intbypart.regress \ intdeq.regress \ intef2.regress intef.regress intg0.regress intheory.regress \ intmix2.regress intmix.regress int.regress intrf.regress \ @@ -363,7 +365,8 @@ REGRES= algaggr.regress algbrbf.regress algfacob.regress alist.regress \ series2.regress series.regress sersolve.regress set.regress \ sincos.regress sinhcosh.regress \ sincosex.regress sint.regress skew.regress slowint.regress \ - solvetra.regress space3.regress sqmatrix.regress sregset.regress \ + solvetra.regress space3.regress sqmatrix.regress sqrt3.regress \ + sregset.regress \ stbl.regress stream2.regress stream.regress streams.regress \ string.regress strtbl.regress summation.regress \ symbol.regress t111293.regress table.regress tancot.regress \ @@ -518,7 +521,8 @@ FILES= ${OUT}/algaggr.input ${OUT}/algbrbf.input ${OUT}/algfacob.input \ ${OUT}/asec.input \ ${OUT}/bags.input ${OUT}/bbtree.input ${OUT}/besselk.input \ ${OUT}/bern.input \ - ${OUT}/bernpoly.input ${OUT}/binary.input ${OUT}/bop.input \ + ${OUT}/bernpoly.input ${OUT}/binary.input ${OUT}/biquat.input \ + ${OUT}/bop.input \ ${OUT}/bouquet.input ${OUT}/bstree.input ${OUT}/bug6357.input \ ${OUT}/bug9057.input ${OUT}/bug100.input ${OUT}/bug101.input \ ${OUT}/bug103.input \ @@ -574,6 +578,7 @@ FILES= ${OUT}/algaggr.input ${OUT}/algbrbf.input ${OUT}/algfacob.input \ ${OUT}/herm.input ${OUT}/heugcd.input \ ${OUT}/hexadec.input ${OUT}/huang.input \ ${OUT}/ico.input ${OUT}/ideal.input ${OUT}/ifact.input \ + ${OUT}/ifthenelse.input \ ${OUT}/images1.input ${OUT}/images1a.input ${OUT}/images3a.input \ ${OUT}/images3.input ${OUT}/images6.input ${OUT}/images6a.input \ ${OUT}/images7.input ${OUT}/images7a.input ${OUT}/infprod.input \ @@ -652,7 +657,8 @@ FILES= ${OUT}/algaggr.input ${OUT}/algbrbf.input ${OUT}/algfacob.input \ ${OUT}/sinsin2.input ${OUT}/sint.input ${OUT}/skew.input \ ${OUT}/slowint.input ${OUT}/solvetra.input ${OUT}/space3.input \ ${OUT}/spiral.input \ - ${OUT}/sqmatrix.input ${OUT}/sregset.input ${OUT}/stbl.input \ + ${OUT}/sqmatrix.input ${OUT}/sqrt3.input \ + ${OUT}/sregset.input ${OUT}/stbl.input \ ${OUT}/stream2.input ${OUT}/stream.input ${OUT}/streams.input \ ${OUT}/string.input ${OUT}/strtbl.input ${OUT}/summation.input \ ${OUT}/symbol.input \ @@ -722,6 +728,7 @@ DOCFILES= \ ${DOC}/bbtree.input.dvi ${DOC}/besselk.input.dvi \ ${DOC}/bern.input.dvi \ ${DOC}/bernpoly.input.dvi ${DOC}/binary.input.dvi \ + ${DOC}/biquat.input.dvi \ ${DOC}/bop.input.dvi ${DOC}/bouquet.input.dvi \ ${DOC}/bstree.input.dvi ${DOC}/bug10069.input.dvi \ ${DOC}/bug100.input.dvi ${DOC}/bug101.input.dvi \ @@ -860,6 +867,7 @@ DOCFILES= \ ${DOC}/hexadec.input.dvi ${DOC}/hilbert.as.dvi \ ${DOC}/huang.input.dvi ${DOC}/ico.input.dvi \ ${DOC}/ideal.input.dvi ${DOC}/ifact.input.dvi \ + ${DOC}/ifthenelse.input.dvi \ ${DOC}/images1a.input.dvi ${DOC}/images1.input.dvi \ ${DOC}/images2a.input.dvi ${DOC}/images2.input.dvi \ ${DOC}/images3a.input.dvi ${DOC}/images3.input.dvi \ @@ -993,7 +1001,8 @@ DOCFILES= \ ${DOC}/skew.input.dvi ${DOC}/slowint.input.dvi \ ${DOC}/solvetra.input.dvi ${DOC}/space3.input.dvi \ ${DOC}/spadprof.input.dvi ${DOC}/spiral.input.dvi \ - ${DOC}/sqmatrix.input.dvi ${DOC}/sregset.input.dvi \ + ${DOC}/sqmatrix.input.dvi ${DOC}/sqrt3.input.dvi \ + ${DOC}/sregset.input.dvi \ ${DOC}/stbl.input.dvi ${DOC}/stream2.input.dvi \ ${DOC}/stream.input.dvi ${DOC}/streams.input.dvi \ ${DOC}/string.input.dvi ${DOC}/strtbl.input.dvi \ diff --git a/src/input/biquat.input.pamphlet b/src/input/biquat.input.pamphlet new file mode 100644 index 0000000..bfb3165 --- /dev/null +++ b/src/input/biquat.input.pamphlet @@ -0,0 +1,790 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/input biquat.input} +\author{D. Cyganski} +\maketitle +\begin{abstract} +\end{abstract} +\eject +\tableofcontents +\eject +@ +<<*>>= +)spool biquat.output +)set message test on +)set message auto off +)clear all + +@ +\section{Hamiltonian Biquaternions} + +Define the type $Q$ of Hamiltonian biquaternions (not to be confused with +Clifford biquaternions which are an entirely different object) +<<*>>= + +--S 1 of 43 +C:=Complex Expression Integer +--R +--R +--R (1) Complex Expression Integer +--R Type: Domain +--E 1 + +--S 2 of 43 +Q:=Quaternion C +--R +--R +--R (2) Quaternion Complex Expression Integer +--R Type: Domain +--E 2 + +--S 3 of 43 +q:Q:=quatern(q0,q1,q2,q3) +--R +--R +--R (3) q0 + q1 i + q2 j + q3 k +--R Type: Quaternion Complex Expression Integer +--E 3 + +@ +Define a function that takes a complex list (parameter l) into a +quaternion +<<*>>= + +--S 4 of 43 +qlist(l:List C):Q==quatern(1.1,1.2,1.3,1.4) +--R +--R Function declaration qlist : List Complex Expression Integer -> +--R Quaternion Complex Expression Integer has been added to +--R workspace. +--R Type: Void +--E 4 + +@ +Define a function that takes a quaternion into a list +<<*>>= + +--S 5 of 43 +listq(x:Q):List C == [real x, imagI x, imagJ x, imagK x] +--R +--R Function declaration listq : Quaternion Complex Expression Integer +--R -> List Complex Expression Integer has been added to workspace. +--R Type: Void +--E 5 + +@ +Define a function that takes a biquat into a matrix +<<*>>= + +--S 6 of 43 +matrixq(x:Q):Matrix C == matrix _ + [[real x + %i*imagI(x), imagJ x + %i*imagK(x)],_ + [-imagJ(x) + %i*imagK(x), real x - %i*imagI(x)]] +--R +--R Function declaration matrixq : Quaternion Complex Expression Integer +--R -> Matrix Complex Expression Integer has been added to +--R workspace. +--R Type: Void +--E 6 + +@ +\section{The Pauli basis Biquaternions} + +The quaternion package in axiom is based upon the Hamiltonian basis, +i, j, k, in contrast to the Pauli basis used in the Morgan papers which +make certain operations correspond more closely (in the sense of +visualization as ordering of components is more natural so that +classical operations can be easily identified) to vector calculus +functions and connect with more directly with various spinor QM +formulations. To both follow these papers and obtain these visualization +benefits, we will define and use the Pauli basis also. + +The Pauli basis in terms of the Hamiltonian quaternion basis +<<*>>= + +--S 7 of 43 +sig0:=quatern(1,0,0,0)::Q +--R +--R +--R (7) 1 +--R Type: Quaternion Complex Expression Integer +--E 7 + +--S 8 of 43 +sig1:=%i*quatern(0,0,0,1)::Q +--R +--R +--R (8) %i k +--R Type: Quaternion Complex Expression Integer +--E 8 + +--S 9 of 43 +sig2:=%i*quatern(0,0,1,0)::Q +--R +--R +--R (9) %i j +--R Type: Quaternion Complex Expression Integer +--E 9 + +--S 10 of 43 +sig3:=-%i*quatern(0,1,0,0)::Q +--R +--R +--R (10) - %i i +--R Type: Quaternion Complex Expression Integer +--E 10 + +@ +For purposes of manipulation and display it would be best if we either +\begin{enumerate} +\item Copy the quaternion source code and edit it to use $\sigma_i$ as +symbols for the basis rather than i, j, k and change the definition of +multiplication to correspond to this Pauli basis so that all current +display and entry functions are flipped to the new basis +\item Use the $\sigma$ basis above with the existing package but define a +new display function, say sigrep, that can show us the results in Pauli +form at will, but otherwise show it in Hamiltonian basis +\end{enumerate} + +While 2 is not as natural and convenient, it is easier to code and would +automatically provide a development that could be seen in the visually +appealing Pauli form, or in the standard Hamiltonian form of biquaternions. + +After a quick review and finding no fast path to 2, and not wishing to get +into the mechanics of compiling an axiom package instead of working on +the physics, I have taken the yet easier path and simply defined the +simplest display function that gives me access to seeing Pauli basis +results: a list of the four Pauli basis coefficients. + +Define a function that produces the Pauli basis representation of the +biquaternion. +<<*>>= + +--S 11 of 43 +siglist(x:Q):List C == [real x, -imagK(x)*%i, -imagJ(x)*%i, %i*imagI(x)] +--R +--R Function declaration siglist : Quaternion Complex Expression Integer +--R -> List Complex Expression Integer has been added to workspace. +--R Type: Void +--E 11 + +@ +\section{Biquaternion Calculus} + +Define the quaternion derivative (Morgan, 2001, Eq. 2) +<<*>>= + +--S 12 of 43 +D(q:Q,x:Symbol,y:Symbol,z:Symbol):Q==sig1*D(q,x)+sig2*D(q,y)+sig3*D(q,z) +--R +--R Function declaration D : (Quaternion Complex Expression Integer, +--R Symbol,Symbol,Symbol) -> Quaternion Complex Expression Integer +--R has been added to workspace. +--R Type: Void +--E 12 + +@ +For testing the derivative we define this set of operators +<<*>>= + +--S 13 of 43 +Ft:=operator 'Ft +--R +--R +--R (13) Ft +--R Type: BasicOperator +--E 13 + +--S 14 of 43 +Fx:=operator 'Fx +--R +--R +--R (14) Fx +--R Type: BasicOperator +--E 14 + +--S 15 of 43 +Fy:=operator 'Fy +--R +--R +--R (15) Fy +--R Type: BasicOperator +--E 15 + +--S 16 of 43 +Fz:=operator 'Fz +--R +--R +--R (16) Fz +--R Type: BasicOperator +--E 16 + +@ +Now form a general quaternion which is a function of x, y, z +<<*>>= + +--S 17 of 43 +F:Q:=Ft(x,y,z)*sig0+Fx(x,y,z)*sig1+Fy(x,y,z)*sig2+Fz(x,y,z)*sig3 +--R +--R +--R (17) Ft(x,y,z) - Fz(x,y,z)%i i + Fy(x,y,z)%i j + Fx(x,y,z)%i k +--R Type: Quaternion Complex Expression Integer +--E 17 + +@ +In the Pauli basis the derivative of this biquat should produce +(Morgan 2001, eq 1): +\begin{verbatim} + D(Ft+F.sigma)=div(F)+(grad(Ft)+%i*curl(F)).sigma +\end{verbatim} +<<*>>= + +--S 18 of 43 +siglist(D(F,x,y,z)) +--R +--R Compiling function D with type (Quaternion Complex Expression +--R Integer,Symbol,Symbol,Symbol) -> Quaternion Complex Expression +--R Integer +--R Compiling function siglist with type Quaternion Complex Expression +--R Integer -> List Complex Expression Integer +--R +--R (18) +--R [Fz (x,y,z) + Fy (x,y,z) + Fx (x,y,z), +--R ,3 ,2 ,1 +--R Ft (x,y,z) + (Fz (x,y,z) - Fy (x,y,z))%i, +--R ,1 ,2 ,3 +--R Ft (x,y,z) + (- Fz (x,y,z) + Fx (x,y,z))%i, +--R ,2 ,1 ,3 +--R Ft (x,y,z) + (Fy (x,y,z) - Fx (x,y,z))%i] +--R ,3 ,1 ,2 +--R Type: List Complex Expression Integer +--E 18 + +@ +\section{Biquaternion Exponential} + +Define a function that evaluates the Biquat exponential by beginning +with the biquat rotation. + +First let's introduce some refinement to the language we will use. In +many texts and papers, the i, j, k or $\sigma_1$, $\sigma_2$, $\sigma_3$ +components of the biquaternion are called the imaginary components while +the scalar or $\sigma_0$ component are called real. This introduces vast +confusion when dealing with biquaternions in which there is a ``true'' +imaginary unit, \%i being used. We will adopt a variation on the language +used by Gsponer and others. A biquat $[{\bf a}, {\bf b}, {\bf c}, {\bf d}]$ +has scalar component ${\bf a}$ which may have itself an imaginary component. +The component $[{\bf 0}, {\bf b}, {\bf c}, {\bf d}]$ is its vector +component which again may be complex: +\begin{verbatim} + [0,b,c,d]=[0,Re(b),Re(c),Re(d)]+[0,Im(b),Im(c),Im(d)]=Re(Vec(q))+Im(Vec(q)) +\end{verbatim} +Thus, for us, a ``real quaternion'' has real scalar and vector components +and does not refer to a quaternion with only a scalar component as it would +in the language adopted by the quatern package in Axiom. + +The rotation is a function of real number, theta and a unit norm, real +vector quaternion. It's form is that of a simple complex quaternion +exponential, R($\theta$,q)=$e^a$ where $a$ is an Imaginary Vector quaternions +are like exponentials of pure imaginary numbers, resulting in each case in a +unit norm object of the same type. For many of our purposes in the +representation of relativistic and quantum mechanics it is the only type +of quaternion for which we will have to evaluate the exponential. + +Define a biquaternion rotation operator that takes a biquat through a +rotation of $\theta$ radians about the axis defined by the unit $q$ biquat +(Morgan 2001, Eq 3). +<<*>>= + +--S 19 of 43 +rot(theta:Expression Integer,q:Q):Q==cos(theta/2)-%i::Q*q*sin(theta/2) +--R +--R Function declaration rot : (Expression Integer,Quaternion Complex +--R Expression Integer) -> Quaternion Complex Expression Integer has +--R been added to workspace. +--R Type: Void +--E 19 + +@ +The rotation is a basis for defining the general exponential, since we +can always extract the unit vector corresponding to a given biquaternion, +all we need is the biquaternion abs operation, not provided by axiom +(note, many texts and papers label the abs which is a complex valued +$norm^2$ by the name ``norm'' -- very bad form -- I've adopted abs as +the name to avoid this confusion. +<<*>>= + +--S 20 of 43 +((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 20 + +--S 21 of 43 +abs(q:Q):C == sqrt((q*conjugate(q))::C) +--R +--R Function declaration abs : Quaternion Complex Expression Integer -> +--R Complex Expression Integer has been added to workspace. +--R Type: Void +--E 21 + +--S 22 of 43 +exp(q:Q):Q == (_ + q-conjugate(q)=0 => exp( (q+conjugate(q))::C/2)$C * sig0; _ + exp( (q+conjugate(q))::C/2)$C * (sig0*cos(abs(q)) +_ + (q-conjugate(q))/abs(q-conjugate(q))*sin(abs(q))) ) +--R +--R Function declaration exp : Quaternion Complex Expression Integer -> +--R Quaternion Complex Expression Integer has been added to +--R workspace. +--R Type: Void +--E 22 + +@ +If I've defined these correctly, then the rotation about the x axis +defined by qx below by 2 radians should give the same answer as +exponentiation of \%i*qx (not a very complete test). +<<*>>= + +--S 23 of 43 +qx:=sig1 +--R +--R +--R (23) %i k +--R Type: Quaternion Complex Expression Integer +--E 23 + +--S 24 of 43 +mm:=siglist(rot(2,qx)) +--R +--R Compiling function / with type (Quaternion Complex Expression +--R Integer,Quaternion Complex Expression Integer) -> Quaternion +--R Complex Expression Integer +--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 Compiling function rot with type (Expression Integer,Quaternion +--R Complex Expression Integer) -> Quaternion Complex Expression +--R Integer +--R +--R (24) +--R 2 3 3 2 +--R cos(1)sin(1) + cos(1) + cos(1) sin(1) + (cos(1) - 1)sin(1) +--R [-------------------------------- + ----------------------------- %i, +--R 2 2 2 2 +--R 2sin(1) + 2cos(1) 2sin(1) + 2cos(1) +--R 2 3 3 2 +--R - cos(1)sin(1) - cos(1) + cos(1) - sin(1) + (- cos(1) - 1)sin(1) +--R ---------------------------------- + --------------------------------- %i, +--R 2 2 2 2 +--R 2sin(1) + 2cos(1) 2sin(1) + 2cos(1) +--R 0, 0] +--R Type: List Complex Expression Integer +--E 24 + +--S 25 of 43 +nn:=siglist(exp(-%i::Q*qx)) +--R +--R There are 2 exposed and 7 unexposed library operations named exp +--R having 1 argument(s) but none was determined to be applicable. +--R Use HyperDoc Browse, or issue +--R )display op exp +--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 exp +--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 Compiling function exp with type Quaternion Complex Expression +--R Integer -> Quaternion Complex Expression Integer +--R Compiling function abs with type Quaternion Complex Expression +--R Integer -> Complex Expression Integer +--R +--R (25) +--R 2 3 3 2 +--R cos(1)sin(1) + cos(1) + cos(1) sin(1) + (cos(1) - 1)sin(1) +--R [-------------------------------- + ----------------------------- %i, +--R 2 2 2 2 +--R 2sin(1) + 2cos(1) 2sin(1) + 2cos(1) +--R 2 3 3 2 +--R - cos(1)sin(1) - cos(1) + cos(1) - sin(1) + (- cos(1) - 1)sin(1) +--R ---------------------------------- + --------------------------------- %i, +--R 2 2 2 2 +--R 2sin(1) + 2cos(1) 2sin(1) + 2cos(1) +--R 0, 0] +--R Type: List Complex Expression Integer +--E 25 + +--S 26 of 43 +(mm=nn)@Boolean +--R +--R +--R (26) true +--R Type: Boolean +--E 26 + +@ +To express a proof of equality such as: +\begin{verbatim} + rot(theta,q) = exp((-theta/2)*%i*q) +\end{verbatim} +for arbitrary real $\theta$ and biquaternion real using vector $q$ as one +would in Maple, we need to express the fact that $q$ is a vector quantity +with real coefficients in the Pauli basis representing a unit magnitude +vector. One way to represent this is to create a quaternion called $qnv$, +representing a general normalized (unit length) vector part only biquat with +two independent variables $q1$ and $q2$ representing its only degrees of +freedom. +<<*>>= + +--S 27 of 43 +qnv:=q1*sig1+q2*sig2+sqrt(1-q1^2-q2^2)*sig3 +--R +--R +--R +---------------+ +--R | 2 2 +--R (27) - \|- q2 - q1 + 1 %i i + q2 %i j + q1 %i k +--R Type: Quaternion Complex Expression Integer +--E 27 + +@ +\section{Assumptions about Variables} + +Now, in the equations that will result, we will obtain subexpressions of the +form $\sqrt{\theta^2}$. The positive root will always be appropriate in +this formula and one way to get it (in other computer algebra systems) +would be to restrict $\theta$ to positive values so as to avoid branches +that would otherwise have to be properly selected to get an equality. Thus, +one means to get the desired simplification is to perform the restriction +of $\theta$ to positive values. My current understanding is: Axiom does not +support variables with properties in the sense that Maple does (the +*assume* facility). + +\section{Problems} + +Returning to the case at hand, let's expand a test of equality to the +four biquat components and seek a way to prove that each component +is zero. +<<*>>= + +--S 28 of 43 +theta:=_\theta +--R +--R +--R (28) \theta +--R Type: Variable \theta +--E 28 + +--S 29 of 43 +testqeq:=map(simplify,siglist(rot(theta,qnv)-exp((-theta/2)*%i*qnv)))_ + ::List Expression Complex Integer +--R +--R +--R (29) +--R +-------+ +--R | 2 +--R \|\theta \theta +--R [- cos(----------) + cos(------), +--R 2 2 +--R +-------+ +--R +-------+ | 2 +--R | 2 \|\theta \theta +--R %i q1\|\theta sin(----------) - %i \theta q1 sin(------) +--R 2 2 +--R ---------------------------------------------------------, +--R \theta +--R +-------+ +--R +-------+ | 2 +--R | 2 \|\theta \theta +--R %i q2\|\theta sin(----------) - %i \theta q2 sin(------) +--R 2 2 +--R ---------------------------------------------------------, +--R \theta +--R +--R +-------+ +--R +---------------+ +-------+ | 2 +--R | 2 2 | 2 \|\theta +--R %i\|- q2 - q1 + 1 \|\theta sin(----------) +--R 2 +--R + +--R +---------------+ +--R \theta | 2 2 +--R - %i \theta sin(------)\|- q2 - q1 + 1 +--R 2 +--R / +--R \theta +--R ] +--R Type: List Expression Complex Integer +--E 29 + +@ +As is quite obvious from this result, the two equations would have been +shown to be equal if positivity of the theta variable was enforced. This +raises two questions +\begin{enumerate} +\item How would one perform a proof such as the above within the +allowed operations of Axiom? +\item How can Axiom be called a symbolic algebra system if basic notions +of algebraic proof such as restrictions of a variable to the semiring +of non-negative integers is disallowed? +\end{enumerate} +How are symbolic manipulations, proofs and solutions to be carried out +without this basic notion? I am let to think that Axiom can only be +considered a semi-numerical software system. + +\section{Rules and Pattern Matching} + +Let's try another way to answer question 1 by using symbolic pattern +matching ``rules''. Define a rule that recognizes the specific case of +the variable theta appearing in a construct that should be simplified +given its positivity. +<<*>>= + +--S 30 of 43 +posthetaRule:=rule sqrt(theta^2)==theta +--R +--R +--R +------+ +--R | 2 +--R (30) \|theta == theta +--R Type: RewriteRule(Integer,Integer,Expression Integer) +--E 30 + +@ +But, now we encounter two new problems. First, apparently ``map'' does +not work with rules, so I can't apply this rule in a simple fashion to +the entire List generated by our test case above for any x. + +The ``map'' function only maps functions but we can easily turn a rule +into an anonymous function. +<<*>>= + +--S 31 of 43 +map(x+->posthetaRule(x), [0,sqrt(theta^2),0,sqrt(theta^2)]) +--R +--R +--R (31) [0,\theta,0,\theta] +--R Type: List Expression Integer +--E 31 + +@ +But even if we were to split our list above, and try to apply this rule +to a component, we get this disappointing result: +<<*>>= + +--S 32 of 43 +posthetaRule testqeq.1 +--R +--R There are no library operations named posthetaRule +--R Use HyperDoc Browse or issue +--R )what op posthetaRule +--R to learn if there is any operation containing " posthetaRule " in +--R its name. +--R +--RDaly Bug +--R Cannot find a definition or applicable library operation named +--R posthetaRule with argument type(s) +--R Expression Complex Integer +--R +--R Perhaps you should use "@" to indicate the required return type, +--R or "$" to specify which version of the function you need. +--E 32 + +@ +Apparently rules have builtin assumptions about the construction of +the expression. If I override this for a real element of the list +we are testing I can successfully get one answer. +<<*>>= + +--S 33 of 43 +[posthetaRule (testqeq.i::Expression Integer) for i in 1..1] +--R +--R +--R (32) [0] +--R Type: List Expression Integer +--E 33 + +@ +But this doesn't extend to the remainder of the list. +<<*>>= + +--S 34 of 43 +[posthetaRule (testqeq.i::Expression Integer) for i in 1..4] +--R +--R +--RDaly Bug +--R Cannot convert from type Expression Complex Integer to Expression +--R Integer for value +--R +-------+ +--R +-------+ | 2 +--R | 2 \|\theta \theta +--R %i q1\|\theta sin(----------) - %i \theta q1 sin(------) +--R 2 2 +--R --------------------------------------------------------- +--R \theta +--R +--E 34 + +@ +because obviously we can't coerce an actually complex value into the +Expression Integer type that the rule seems to want. + +Here is one way to create the necessary rule. Like everything else in +Axiom rules are objects in some domain. We need to specify a domain +for the rule that is compatible with the domain we wish to manipulate. +So let's find out more about this domain: +<<*>>= + +--S 35 of 43 +)show RewriteRule +--R +--R RewriteRule(Base: SetCategory,R: Join(Ring,PatternMatchable Base,OrderedSet,ConvertibleTo Pattern Base),F: Join(FunctionSpace R,PatternMatchable Base,ConvertibleTo Pattern Base)) is a domain constructor +--R Abbreviation for RewriteRule is RULE +--R This constructor is exposed in this frame. +--R Issue )edit rule.spad.pamphlet to see algebra source code for RULE +--R +--R------------------------------- Operations -------------------------------- +--R ?=? : (%,%) -> Boolean coerce : Equation F -> % +--R coerce : % -> OutputForm elt : (%,F,PositiveInteger) -> F +--R ?.? : (%,F) -> F hash : % -> SingleInteger +--R latex : % -> String lhs : % -> F +--R pattern : % -> Pattern Base retract : % -> Equation F +--R rhs : % -> F rule : (F,F,List Symbol) -> % +--R rule : (F,F) -> % ?~=? : (%,%) -> Boolean +--R quotedOperators : % -> List Symbol +--R retractIfCan : % -> Union(Equation F,"failed") +--R suchThat : (%,List Symbol,(List F -> Boolean)) -> % +--R +--E 35 + +@ +We can provide satisfactory parameters of this domain constructor as follows: +<<*>>= + +--S 36 of 43 +Complex Integer has PatternMatchable Integer +--R +--R +--R (33) true +--R Type: Boolean +--E 36 + +--S 37 of 43 +Expression Complex Integer has FunctionSpace Complex Integer +--R +--R +--R (34) true +--R Type: Boolean +--E 37 + +--S 38 of 43 +Expression Complex Integer has PatternMatchable Integer +--R +--R +--R (35) true +--R Type: Boolean +--E 38 + +@ +So the following simplification works as hoped: +<<*>>= + +--S 39 of 43 +posxRule:=(rule sqrt('theta^2)==theta)$RewriteRule(Integer,Complex Integer,_ + Expression Complex Integer) +--R +--R +--R +------+ +--R | 2 +--R (36) \|theta == theta +--R Type: RewriteRule(Integer,Complex Integer,Expression Complex Integer) +--E 39 + +--S 40 of 43 +map(x+->posxRule x, testqeq) +--R +--R +--R (37) [0,0,0,0] +--R Type: List Expression Complex Integer +--E 40 + +@ +\section{Algebraic Domain of Computation} + +Recall that Axiom does things in a fundamentally {\sl algebraic} rather +than {\sl symbolic} way. So although the pattern matching approach +works, it goes somewhat against the overall philosophy of Axiom. It is +possible to do almost anything by using rewrite rules including things +that are mathematically incorrect. In this case the rule is simple and +the results obvious but if it gets more complicated this can be a problem. + +Is there some ``axiomatic'', i.e. algebraic way to express the fact that +$\theta$ is a positive real? well, what we really need is that +$$\sqrt{\theta^2} = \theta$$ +be satisfied. Now consider that by definition $\sqrt{}$: +<<*>>= + +--S 41 of 43 +test (sqrt(x)^2=x) +--R +--R +--R (38) true +--R Type: Boolean +--E 41 + +@ +and so +<<*>>= + +--S 42 of 43 +test (sqrt(sqrt(x)^2)=sqrt(x)) +--R +--R +--R (39) true +--R Type: Boolean +--E 42 + +@ +for any $x$. So the expression $\sqrt{(x)}$ is one such thing that has +the desired property in the Expression domain. {\sl With exactly the +appropriate loss of generality}, let us just suppose that $\theta$ is +$\sqrt{(\beta)}$ for some $\beta$. Then if necessary we can also +perform a change of variable back to $\theta$. +<<*>>= + +--S 43 of 43 +eval(eval(testqeq,theta=sqrt(beta)),sqrt(beta)=theta) +--R +--R +--R (40) [0,0,0,0] +--R Type: List Expression Complex Integer +--E 43 + +)spool +)lisp (bye) + +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/input/ifthenelse.input.pamphlet b/src/input/ifthenelse.input.pamphlet new file mode 100644 index 0000000..29c75b4 --- /dev/null +++ b/src/input/ifthenelse.input.pamphlet @@ -0,0 +1,299 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/input ifthenelse.input} +\author{Fabio Stumbo} +\maketitle +\begin{abstract} +{\bf if-then-else: what is wrong?} +\end{abstract} +\eject +\tableofcontents +\eject +@ +<<*>>= +)spool ifthenelse.output +)set message test on +)set message auto off +)clear all + +@ +I am having some problem with the if-then-else syntax in .input files + +{\bf Problem 1}: I refer to the Axiom book which ships with the program +(version 2005/09). At page 204 it says that the usual rules for piling +are suspended in conditional expressions and it gives 5 different ways +which should be equivalent, namely: +\begin{verbatim} + + if i>0 then output("positive") else output("nonpositive") + + if i>0 then output("positive") + else output("nonpositive") + + if i>0 then output("positive") + else output("nonpositive") + + if i>0 + then output("positive") + else output("nonpositive") + + if i>0 + then output("positive") + else output("nonpositive") +\end{verbatim} + +Well, I tried all of them, creating each time a blank r.input file with +inside only: +<<*>>= + +--S 1 of 20 +i:=2 +--R +--R +--R (1) 2 +--R Type: PositiveInteger +--E 1 + +@ +followed by one of the ``if$\ldots$''. + +The result of the first two are ok, whereas the other three +give some syntax error (different each time). +<<*>>= + +--S 2 of 20 +for i in 2..2 repeat + if i>0 then output("positive") else output("nonpositive") +--R +--R positive +--R Type: Void +--E 2 + +--S 3 of 20 +for i in 2..2 repeat + if i>0 then output("positive") + else output("nonpositive") +--R +--R positive +--R Type: Void +--E 3 + +--S 4 of 20 +for i in 2..2 repeat + if i>0 then output("positive") + else output("nonpositive") +--R +--R positive +--R Type: Void +--E 4 + +--S 5 of 20 +for i in 2..2 repeat + if i>0 + then output("positive") + else output("nonpositive") +--R +--R positive +--R Type: Void +--E 5 + +--S 6 of 20 +for i in 2..2 repeat + if i>0 + then output("positive") + else output("nonpositive") +--R +--R Line 47: --R +--R Line 48: --R positive +--R Line 49: --R Type: Void +--R Line 50: --E 5 +--R Line 51: +--R Line 52: --S 6 of 20 +--R Line 53: for i in 2..2 repeat +--R Line 54: if i>0 +--R ..A +--R Error A: (from #\A and on) Ignored from here +--R Line 55: then output("positive") +--R ....A +--R Error A: Improper syntax. +--R Error A: (from #\A up to ) Ignored. +--R Line 56: else output("nonpositive") +--R ....A........................B +--R Error A: Improper syntax. +--R Error A: (from #\A up to #\B) Ignored. +--R Error B: Possibly missing a then +--R Error B: (up to #\B) to here. +--R 7 error(s) parsing +--E 6 + +--S 7 of 20 +i:=2 +--R +--R +--R (6) 2 +--R Type: PositiveInteger +--E 7 + +--S 8 of 20 +for i in 2..2 repeat + if i>0 then + output(i) + output("positive") + else + output(i) + else output("nonpositive") +--R +--R Line 83: --R +--R Line 84: --R +--R Line 85: --R (6) 2 +--R Line 86: --R Type: PositiveInteger +--R Line 87: --E 7 +--R Line 88: +--R Line 89: --S 8 of 20 +--R Line 90: for i in 2..2 repeat +--R Line 91: if i>0 then +--R Line 92: output(i) +--R Line 93: output("positive") +--R Line 94: else +--R Line 95: output(i) +--R Line 96: else output("nonpositive") +--R ....A +--R Error A: (from #\A up to ) Ignored. +--R Error A: Improper syntax. +--R 2 error(s) parsing +--E 8 + +--S 9 of 20 +i:=1.5 +--R +--R +--R (7) 1.5 +--R Type: Float +--E 9 + +--S 10 of 20 +a:= + if i > 0 then + j:=sin(i*pi()) + exp(j+1/j) + else + j:=cos(i*0.5*pi()) + log(abs(j)**5+1) +--R +--R +--R (8) 0.1353352832 3661269189 +--R Type: Float +--E 10 + +@ +{\bf Problem 2:} again with if then else, in a complex function I +noticed a wrong result (the function itself was ok). Simplifying, +you can produce the same error with something like: +<<*>>= + +--S 11 of 20 +test: (INT,INT) -> List(INT) +--R +--R Type: Void +--E 11 + +--S 12 of 20 +test(a,b) == + x:=0; y:=0 + if (a rem b = 0) and b < 0 then + x := 1 + y := 1 + [x,y] +--R +--R Type: Void +--E 12 + +--S 13 of 20 +4 rem -2 +--R +--R +--R (11) 0 +--R Type: NonNegativeInteger +--E 13 + +--S 14 of 20 +test(4,-2) +--R +--R Compiling function test with type (Integer,Integer) -> List Integer +--R +--R (12) [1,1] +--R Type: List Integer +--E 14 + +@ +returns correctly [1,1], but +<<*>>= + +--S 15 of 20 +4 rem -3 +--R +--R +--R (13) 1 +--R Type: PositiveInteger +--E 15 + +--S 16 of 20 +test(4,-3) +--R +--R +--R (14) [0,0] +--R Type: List Integer +--E 16 + +@ +or +<<*>>= + +--S 17 of 20 +4 rem 2 +--R +--R +--R (15) 0 +--R Type: NonNegativeInteger +--E 17 + +--S 18 of 20 +test(4,2) +--R +--R +--R (16) [0,0] +--R Type: List Integer +--E 18 + +@ +wrongly returns [0,1]. The same happens if I write +<<*>>= + +--S 19 of 20 +test1: (INT,INT) -> List(INT) +--R +--R Type: Void +--E 19 + +--S 20 of 20 +test1(a,b) == + x := 0; y := 0 + if (a rem b = 0) and b < 0 then x := 1 ; y := 1 + [x,y] +--R +--R Type: Void +--E 20 + +@ +Why? +<<*>>= +)spool +)lisp (bye) + +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/input/sqrt3.input.pamphlet b/src/input/sqrt3.input.pamphlet new file mode 100644 index 0000000..ad20ab9 --- /dev/null +++ b/src/input/sqrt3.input.pamphlet @@ -0,0 +1,249 @@ +\documentclass{article} +\usepackage{axiom} +\begin{document} +\title{\$SPAD/src/input sqrt3.input} +\author{Ralf Hemmecke} +\maketitle +\begin{abstract} +A demo involving the algebraic number $\sqrt{3}$. +\end{abstract} +\eject +\tableofcontents +\eject +@ +<<*>>= +)spool sqrt3.output +)set message test on +)set message auto off +)clear all + +--S 1 of 23 +t1:=(sqrt(3)-3)*(sqrt(3)+1)/6 +--R +--R +--R +-+ +--R \|3 +--R (1) - ---- +--R 3 +--R Type: AlgebraicNumber +--E 1 + +--S 2 of 23 +tt1:=-1/sqrt(3) +--R +--R +--R +-+ +--R \|3 +--R (2) - ---- +--R 3 +--R Type: AlgebraicNumber +--E 2 + +--S 3 of 23 +t2:=sqrt(3)/6 +--R +--R +--R +-+ +--R \|3 +--R (3) ---- +--R 6 +--R Type: AlgebraicNumber +--E 3 + +--S 4 of 23 +t1+t2 +--R +--R +--R +-+ +--R \|3 +--R (4) - ---- +--R 6 +--R Type: AlgebraicNumber +--E 4 + +--S 5 of 23 +tt1+t2 +--R +--R +--R +-+ +--R \|3 +--R (5) - ---- +--R 6 +--R Type: AlgebraicNumber +--E 5 + +--S 6 of 23 +RAN ==> RECLOS FRAC INT +--R +--R Type: Void +--E 6 + +--S 7 of 23 +x1:=(sqrt(3)$RAN-3)*(sqrt(3)$RAN+1)/6 +--R +--R +--R 1 +-+ 1 +-+ 1 +-+ 1 +--R (7) (- \|3 - -)\|3 + - \|3 - - +--R 6 2 6 2 +--R Type: RealClosure Fraction Integer +--E 7 + +--S 8 of 23 +xx1:=-1/sqrt(3)$RAN +--R +--R +--R 1 +-+ +--R (8) - - \|3 +--R 3 +--R Type: RealClosure Fraction Integer +--E 8 + +--S 9 of 23 +(x1=xx1)@Boolean +--R +--R +--R (9) true +--R Type: Boolean +--E 9 + +--S 10 of 23 +s3:=sqrt(3)$RAN +--R +--R +--R +-+ +--R (10) \|3 +--R Type: RealClosure Fraction Integer +--E 10 + +--S 11 of 23 +(s3-3)*(s3+1)/6 +--R +--R +--R 1 +-+ +--R (11) - - \|3 +--R 3 +--R Type: RealClosure Fraction Integer +--E 11 + +--S 12 of 23 +f3:=sqrt(3,5)$RAN +--R +--R +--R 5+-+ +--R (12) \|3 +--R Type: RealClosure Fraction Integer +--E 12 + +--S 13 of 23 +f25:=sqrt(1/25,5)$RAN +--R +--R +--R +--+ +--R | 1 +--R (13) 5|-- +--R \|25 +--R Type: RealClosure Fraction Integer +--E 13 + +--S 14 of 23 +f32:=sqrt(32/5,5)$RAN +--R +--R +--R +--+ +--R |32 +--R (14) 5|-- +--R \| 5 +--R Type: RealClosure Fraction Integer +--E 14 + +--S 15 of 23 +f27:=sqrt(27/5,5)$RAN +--R +--R +--R +--+ +--R |27 +--R (15) 5|-- +--R \| 5 +--R Type: RealClosure Fraction Integer +--E 15 + +--S 16 of 23 +expr1:=sqrt(f32-f27,3) +--R +--R +--R +---------------+ +--R | +--+ +--+ +--R | |27 |32 +--R (16) 3|- 5|-- + 5|-- +--R \| \| 5 \| 5 +--R Type: RealClosure Fraction Integer +--E 16 + +--S 17 of 23 +expr2:=(1+f3-f3^2) +--R +--R +--R 5+-+2 5+-+ +--R (17) - \|3 + \|3 + 1 +--R Type: RealClosure Fraction Integer +--E 17 + +--S 18 of 23 +expr1-f25*expr2 +--R +--R +--R (18) 0 +--R Type: RealClosure Fraction Integer +--E 18 + +--S 19 of 23 +s:=sqrt(190)$RAN+sqrt(1751)$RAN-sqrt(208)$RAN-sqrt(1698)$RAN +--R +--R +--R +----+ +---+ +----+ +---+ +--R (19) - \|1698 - \|208 + \|1751 + \|190 +--R Type: RealClosure Fraction Integer +--E 19 + +--S 20 of 23 +approximate(s,10^-15)::Float +--R +--R +--R (20) - 0.2341060678 6455900874 E -10 +--R Type: Float +--E 20 + +--S 21 of 23 +t:=sqrt(190)+sqrt(1751)-sqrt(208)-sqrt(1698) +--R +--R +--R +----+ +----+ +---+ +--+ +--R (21) \|1751 - \|1698 + \|190 - 4\|13 +--R Type: AlgebraicNumber +--E 21 + +--S 22 of 23 +digits(30) +--R +--R +--R (22) 20 +--R Type: PositiveInteger +--E 22 + +--S 23 of 23 +numeric t - approximate(s,10^-30)::Float +--R +--R +--R (23) - 0.5522026336 5 E -29 +--R Type: Float +--E 23 + +)spool +)lisp (bye) + +@ +\eject +\begin{thebibliography}{99} +\bibitem{1} nothing +\end{thebibliography} +\end{document} diff --git a/src/interp/setq.lisp.pamphlet b/src/interp/setq.lisp.pamphlet index f6e1c05..e9b34ec 100644 --- a/src/interp/setq.lisp.pamphlet +++ b/src/interp/setq.lisp.pamphlet @@ -651,8 +651,8 @@ "Gerhard Schneider Martin Schoenert Marshall Schor" "Frithjof Schulze Fritz Schwarz Nick Simicich" "William Sit Elena Smirnova Jonathan Steinbach" -"Christine Sundaresan Robert Sutor Moss E. Sweedler" -"Eugene Surowitz" +"Fabio Stumbo Christine Sundaresan Robert Sutor" +"Moss E. Sweedler Eugene Surowitz" "Max Tegmark James Thatcher Balbir Thomas" "Mike Thomas Dylan Thurston Barry Trager" "Themos T. Tsikas"