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

Edit detail for SandBoxBiQuaternions revision 1 of 3

1 2 3
Editor:
Time: 2007/11/18 17:47:24 GMT-8
Note: Added a link to OverloadProb page

changed:
-
The Biquaternion calculus support function collection

**D. Cyganski - May-June 2007**

Hamiltonian Biquaternions

  Define the type Q of Hamiltonian biquaternions (not to be confused
with Clifford biquaternions which are an entirely different object)
\begin{axiom}
C:=Complex Expression Integer
Q:=Quaternion C
q:Q:=quatern(q0,q1,q2,q3)
\end{axiom}

Define a function that takes a complex list (parameter l) into a quaternion
\begin{axiom}
qlist(l:List C):Q==quatern(l.1,l.2,l.3,l.4)
\end{axiom}

Define a function that takes a quaternion into a list
\begin{axiom}
listq(x:Q):List C == [real x, imagI x, imagJ x, imagK x]
\end{axiom}

Define a function that takes a biquat into a matrix
\begin{axiom}
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)]]
\end{axiom}


The Pauli basis Biquaternions

  The quaternion package in axiom is based upon the Hamiltonian
basis, i,j,k, in constrast to the Pauli basis used in the Mogan
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
\begin{axiom}
sig0:=quatern(1,0,0,0)::Q
sig1:=%i*quatern(0,0,0,1)::Q
sig2:=%i*quatern(0,0,1,0)::Q
sig3:=-%i*quatern(0,1,0,0)::Q
\end{axiom}

For purposes of manipulation and display it would be best if we either:

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

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

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
the four Pauli basis coefficients.

Define a function that produces the Pauli basis representation of the biquaternion
\begin{axiom}
siglist(x:Q):List C == [real x, -imagK(x)*%i,-imagJ(x)*%i,%i*imagI(x)]
\end{axiom}


Biquaternion Calculus

  Define the quaternion derivative (Morgan, 2001, Eq. 2)

\begin{axiom}
D(q:Q,x:Symbol,y:Symbol,z:Symbol):Q==sig1*D(q,x)+sig2*D(q,y)+sig3*D(q,z)
\end{axiom}


For testing the derivative we define this set of operators
\begin{axiom}
Ft:=operator 'Ft; Fx:=operator 'Fx; Fy:=operator 'Fy; Fz:=operator 'Fz;
\end{axiom}

Now form a general quaternion which is a function of x,y,z
\begin{axiom}
F:Q:=Ft(x,y,z)*sig0+Fx(x,y,z)*sig1+Fy(x,y,z)*sig2+Fz(x,y,z)*sig3
\end{axiom}


In the Pauli basis the derivative of this biquat should produce (Morgan 2001, eq 1)::

  D(Ft+F.sigma)=div(F)+(grad(Ft)+%i*curl(F)).sigma

which it does
\begin{axiom}
siglist(D(F,x,y,z))
\end{axiom}


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 sigma1, sigma2, sigma3 components of the
biquaternion are called the imaginary components while the scalar or sigma0
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
$[a,b,c,d]$ has scalar component a which may have itself an imaginary component.
The component $[0,b,c,d]$ is its vector component which again may be complex::

  [0,b,c,d]=[0,Re(b),Re(c),Re(d)]+[0,Im(b),Im(c),Im(d)]=Re(Vec(q))+Im(Vec(q))

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) = exp(a) where a is an Imaginary Vector quaternion. The result is
Unit Norm, Vector quaternion. That is, exponentials of pure imaginary, pure
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).
\begin{axiom}
rot(theta:Expression Integer,q:Q):Q==cos(theta/2)-%i::Q*q*sin(theta/2)
\end{axiom}

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.

\begin{axiom}
((x:Q)/(y:Q)):Q == x*inv(y)
abs(q:Q):C == sqrt((q*conjugate(q))::C)
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))) )
\end{axiom}


Test (comment out this test later)

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 to '-%i*qx' (not a very complete test)
\begin{axiom}
qx:=sig1
siglist(rot(2,qx))
siglist(exp(-%i::Q*qx))
\end{axiom}

which it does
\begin{axiom}
(%%(-1)=%%(-2))@Boolean
\end{axiom}

To express a proof of equality such as::

   rot(theta,q) = exp((-theta/2)*%i*q)

for arbitrary real $\theta$ and biquaternion real unit 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
\begin{axiom}
qnv:=q1*sig1+q2*sig2+sqrt(1-q1^2-q2^2)*sig3
\end{axiom}

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 of 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).

Problems

  Returning to the case at hand, let's expand a test of equality of the four biquat
components and seek a way to prove that each component is zero.
\begin{axiom}
theta := _\theta
testqeq:=map(simplify, siglist( rot(theta,qnv) - exp((-theta/2)*%i*qnv)))_
         ::List Expression Complex Integer
\end{axiom}
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:
(1) How would one perform a proof such as the above within the allowed operations of Axiom?
(2) How can Axiom be called an symbolic algebra system if basic notions of algebraic proof such as
restrictions of a variable to the semiring of non-negative integers is disallowed? How are
symbolic manipulations, proofs and solutions to be carried out without this basic notion?
I am led to think that axiom can only be considered a semi-numerical software system.

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

\begin{axiom}
posthetaRule:=rule sqrt(theta^2)==theta
\end{axiom}

But, now we encounter two new problems...
 a) 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.

'map' only maps *functions* but we can easily turn a rule into an anonymous function:
\begin{axiom}
map(x+->posthetaRule(x), [0,sqrt(theta^2),0,sqrt(theta^2)])
\end{axiom}

b) But even if we were to split our list above, and try to apply this rule to a component,
we get this disappointing result
\begin{axiom}
posthetaRule testqeq.1
\end{axiom}
Apparently rules have built in assumption 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
\begin{axiom}
[posthetaRule (testqeq.i::Expression Integer) for i in 1..1]
\end{axiom}
But this doesn't extend to the remainder of the list
\begin{axiom}
[posthetaRule (testqeq.i::Expression Integer) for i in 1..4]
\end{axiom}
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:
\begin{axiom}
)show RewriteRule
\end{axiom}
We can provide satisfactory parameters of this domain constructor as follows:
\begin{axiom}
Complex Integer has PatternMatchable Integer
Expression Complex Integer has FunctionSpace Complex Integer
Expression Complex Integer has PatternMatchable Integer
\end{axiom}

So the following simplification works as hoped:
\begin{axiom}
posxRule:=(rule sqrt('theta^2)==theta)$RewriteRule(Integer,Complex Integer,Expression Complex Integer)
map(x+->posxRule x, testqeq)
\end{axiom}

Algebraic Domain of Computation

  Recall that Axiom does things in an fundamentally _algebraic_ rather than
_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 it more complicated
situations 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 of $\sqrt{\ }$:
\begin{axiom}
test (sqrt(x)^2=x)
\end{axiom}
and so
\begin{axiom}
test (sqrt(sqrt(x)^2)=sqrt(x))
\end{axiom}
for any x. So the expression $\sqrt(x)$ is one such thing that has the desired property in
the Expression domain. *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$
\begin{axiom}
eval(eval(testqeq ,theta=sqrt(beta)),sqrt(beta)=theta)
\end{axiom}

See OverloadProb for some interesting observations and problems that resulted from further
development of this work with regard to type conversions and function overloading

The Biquaternion calculus support function collection

D. Cyganski - May-June 2007

Hamiltonian Biquaternions

Define the type Q of Hamiltonian biquaternions (not to be confused with Clifford biquaternions which are an entirely different object)

axiom
C:=Complex Expression Integer
LatexWiki Image(1)
Type: Domain
axiom
Q:=Quaternion C
LatexWiki Image(2)
Type: Domain
axiom
q:Q:=quatern(q0,q1,q2,q3)
LatexWiki Image(3)
Type: Quaternion Complex Expression Integer

Define a function that takes a complex list (parameter l) into a quaternion

axiom
qlist(l:List C):Q==quatern(l.1,l.2,l.3,l.4)
Function declaration qlist : List Complex Expression Integer -> Quaternion Complex Expression Integer has been added to workspace.
Type: Void

Define a function that takes a quaternion into a list

axiom
listq(x:Q):List C == [real x, imagI x, imagJ x, imagK x]
Function declaration listq : Quaternion Complex Expression Integer -> List Complex Expression Integer has been added to workspace.
Type: Void

Define a function that takes a biquat into a matrix

axiom
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)]]
Function declaration matrixq : Quaternion Complex Expression Integer -> Matrix Complex Expression Integer has been added to workspace.
Type: Void

The Pauli basis Biquaternions

The quaternion package in axiom is based upon the Hamiltonian basis, i,j,k, in constrast to the Pauli basis used in the Mogan 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

axiom
sig0:=quatern(1,0,0,0)::Q
LatexWiki Image(4)
Type: Quaternion Complex Expression Integer
axiom
sig1:=%i*quatern(0,0,0,1)::Q
LatexWiki Image(5)
Type: Quaternion Complex Expression Integer
axiom
sig2:=%i*quatern(0,0,1,0)::Q
LatexWiki Image(6)
Type: Quaternion Complex Expression Integer
axiom
sig3:=-%i*quatern(0,1,0,0)::Q
LatexWiki Image(7)
Type: Quaternion Complex Expression Integer

For purposes of manipulation and display it would be best if we either:

  1. 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
  2. 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

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 the four Pauli basis coefficients.

Define a function that produces the Pauli basis representation of the biquaternion

axiom
siglist(x:Q):List C == [real x, -imagK(x)*%i,-imagJ(x)*%i,%i*imagI(x)]
Function declaration siglist : Quaternion Complex Expression Integer -> List Complex Expression Integer has been added to workspace.
Type: Void

Biquaternion Calculus

Define the quaternion derivative (Morgan, 2001, Eq. 2)

axiom
D(q:Q,x:Symbol,y:Symbol,z:Symbol):Q==sig1*D(q,x)+sig2*D(q,y)+sig3&#
42;D(q,z)
Function declaration D : (Quaternion Complex Expression Integer, Symbol,Symbol,Symbol) -> Quaternion Complex Expression Integer has been added to workspace.
Type: Void

For testing the derivative we define this set of operators

axiom
Ft:=operator 'Ft; Fx:=operator 'Fx; Fy:=operator 'Fy;
Fz:=operator 'Fz;
Type: BasicOperator?

Now form a general quaternion which is a function of x,y,z

axiom
F:Q:=Ft(x,y,z)*sig0+Fx(x,y,z)*sig1+Fy(x,y,z)*sig2+Fz(x,y,z)*sig3
LatexWiki Image(8)
Type: Quaternion Complex Expression Integer

In the Pauli basis the derivative of this biquat should produce (Morgan 2001, eq 1):

  D(Ft+F.sigma)=div(F)+(grad(Ft)+%i*curl(F)).sigma

which it does

axiom
siglist(D(F,x,y,z))
axiom
Compiling function D with type (Quaternion Complex Expression 
      Integer,Symbol,Symbol,Symbol) -> Quaternion Complex Expression 
      Integer
axiom
Compiling function siglist with type Quaternion Complex Expression 
      Integer -> List Complex Expression Integer
LatexWiki Image(9)
Type: List Complex Expression Integer

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 sigma1, sigma2, sigma3 components of the biquaternion are called the imaginary components while the scalar or sigma0 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 LatexWiki Image has scalar component a which may have itself an imaginary component. The component LatexWiki Image is its vector component which again may be complex:

  [0,b,c,d]=[0,Re(b),Re(c),Re(d)]+[0,Im(b),Im(c),Im(d)]=Re(Vec(q))+Im(Vec(q))

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) = exp(a) where a is an Imaginary Vector quaternion. The result is Unit Norm, Vector quaternion. That is, exponentials of pure imaginary, pure 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).

axiom
rot(theta:Expression
Integer,q:Q):Q==cos(theta/2)-%i::Q*q*sin(theta/2)
Function declaration rot : (Expression Integer,Quaternion Complex Expression Integer) -> Quaternion Complex Expression Integer has been added to workspace.
Type: Void

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.

axiom
((x:Q)/(y:Q)):Q == x*inv(y)
Function declaration ?/? : (Quaternion Complex Expression Integer, Quaternion Complex Expression Integer) -> Quaternion Complex Expression Integer has been added to workspace.
Type: Void
axiom
abs(q:Q):C == sqrt((q*conjugate(q))::C)
Function declaration abs : Quaternion Complex Expression Integer -> Complex Expression Integer has been added to workspace.
Type: Void
axiom
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))) )
Function declaration exp : Quaternion Complex Expression Integer -> Quaternion Complex Expression Integer has been added to workspace.
Type: Void

Test (comment out this test later)

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 to -%i*qx (not a very complete test)

axiom
qx:=sig1
LatexWiki Image(10)
Type: Quaternion Complex Expression Integer
axiom
siglist(rot(2,qx))
axiom
Compiling function / with type (Quaternion Complex Expression 
      Integer,Quaternion Complex Expression Integer) -> Quaternion 
      Complex Expression Integer 
   There are 1 exposed and 7 unexposed library operations named cos 
      having 1 argument(s) but none was determined to be applicable. 
      Use HyperDoc Browse, or issue
                               )display op cos
      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 cos 
      with argument type(s) 
                    Quaternion Complex Expression Integer
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.
axiom
Compiling function rot with type (Expression Integer,Quaternion 
      Complex Expression Integer) -> Quaternion Complex Expression 
      Integer
LatexWiki Image(11)
Type: List Complex Expression Integer
axiom
siglist(exp(-%i::Q*qx))
There are 1 exposed and 8 unexposed library operations named exp having 1 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op exp 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 exp with argument type(s) Quaternion Complex Expression Integer
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.
axiom
Compiling function exp with type Quaternion Complex Expression 
      Integer -> Quaternion Complex Expression Integer
axiom
Compiling function abs with type Quaternion Complex Expression 
      Integer -> Complex Expression Integer
LatexWiki Image(12)
Type: List Complex Expression Integer

which it does

axiom
(%%(-1)=%%(-2))@Boolean
LatexWiki Image(13)
Type: Boolean

To express a proof of equality such as:

   rot(theta,q) = exp((-theta/2)*%i*q)

for arbitrary real LatexWiki Image and biquaternion real unit 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

axiom
qnv:=q1*sig1+q2*sig2+sqrt(1-q1^2-q2^2)*sig3
LatexWiki Image(14)
Type: Quaternion Complex Expression Integer

Assumptions about Variables

Now, in the equations that will result, we will obtain subexpressions of the form LatexWiki Image. 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 of 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).

Problems

Returning to the case at hand, let's expand a test of equality of the four biquat components and seek a way to prove that each component is zero.

axiom
theta := _\theta
LatexWiki Image(15)
Type: Variable \theta
axiom
testqeq:=map(simplify, siglist( rot(theta,qnv) - exp((-theta/2)*%i*qnv)))_
         ::List Expression Complex Integer
LatexWiki Image(16)
Type: List Expression Complex Integer

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: (1) How would one perform a proof such as the above within the allowed operations of Axiom? (2) How can Axiom be called an symbolic algebra system if basic notions of algebraic proof such as restrictions of a variable to the semiring of non-negative integers is disallowed? How are symbolic manipulations, proofs and solutions to be carried out without this basic notion? I am led to think that axiom can only be considered a semi-numerical software system.

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

axiom
posthetaRule:=rule sqrt(theta^2)==theta
LatexWiki Image(17)
Type: RewriteRule?(Integer,Integer,Expression Integer)

But, now we encounter two new problems... a) 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.

map only maps functions but we can easily turn a rule into an anonymous function:

axiom
map(x+->posthetaRule(x), [0,sqrt(theta^2),0,sqrt(theta^2)])
LatexWiki Image(18)
Type: List Expression Integer

b) But even if we were to split our list above, and try to apply this rule to a component, we get this disappointing result

axiom
posthetaRule testqeq.1
There are no library operations named posthetaRule Use HyperDoc Browse or issue )what op posthetaRule to learn if there is any operation containing " posthetaRule " in its name.
Cannot find a definition or applicable library operation named posthetaRule with argument type(s) Expression Complex Integer
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

Apparently rules have built in assumption 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

axiom
[posthetaRule (testqeq.i::Expression Integer) for i in 1..1]
LatexWiki Image(19)
Type: List Expression Integer

But this doesn't extend to the remainder of the list

axiom
[posthetaRule (testqeq.i::Expression Integer) for i in 1..4]
Cannot convert from type Expression Complex Integer to Expression Integer for value +-------+ +-------+ | 2 | 2 \|\theta \theta %i q1\|\theta sin(----------) - %i \theta q1 sin(------) 2 2 --------------------------------------------------------- \theta

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:

axiom
)show RewriteRule
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 Abbreviation for RewriteRule is RULE This constructor is exposed in this frame. Issue )edit /usr/local/lib/axiom/target/x86_64-unknown-linux/../../src/algebra/RULE.spad to see algebra source code for RULE
------------------------------- Operations -------------------------------- ?=? : (%,%) -> Boolean coerce : Equation F -> % coerce : % -> OutputForm elt : (%,F,PositiveInteger) -> F ?.? : (%,F) -> F hash : % -> SingleInteger latex : % -> String lhs : % -> F pattern : % -> Pattern Base retract : % -> Equation F rhs : % -> F rule : (F,F,List Symbol) -> % rule : (F,F) -> % ?~=? : (%,%) -> Boolean quotedOperators : % -> List Symbol retractIfCan : % -> Union(Equation F,"failed") suchThat : (%,List Symbol,(List F -> Boolean)) -> %

We can provide satisfactory parameters of this domain constructor as follows:

axiom
Complex Integer has PatternMatchable Integer
LatexWiki Image(20)
Type: Boolean
axiom
Expression Complex Integer has FunctionSpace Complex Integer
LatexWiki Image(21)
Type: Boolean
axiom
Expression Complex Integer has PatternMatchable Integer
LatexWiki Image(22)
Type: Boolean

So the following simplification works as hoped:

axiom
posxRule:=(rule sqrt('theta^2)==theta)$RewriteRule(Integer,Complex
Integer,Expression Complex Integer)
LatexWiki Image(23)
Type: RewriteRule?(Integer,Complex Integer,Expression Complex Integer)
axiom
map(x+->posxRule x, testqeq)
LatexWiki Image(24)
Type: List Expression Complex Integer

Algebraic Domain of Computation

Recall that Axiom does things in an fundamentally algebraic rather than 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 it more complicated situations this can be a problem.

Is there some "axiomatic", i.e. algebraic way to express the fact that LatexWiki Image is a positive real? Well, what we really need is that

LatexWiki Image 

be satisfied. Now consider that by definition of LatexWiki Image:

axiom
test (sqrt(x)^2=x)
LatexWiki Image(25)
Type: Boolean

and so

axiom
test (sqrt(sqrt(x)^2)=sqrt(x))
LatexWiki Image(26)
Type: Boolean

for any x. So the expression LatexWiki Image is one such thing that has the desired property in the Expression domain. With exactly the appropriate loss of generality, let us just suppose that LatexWiki Image is LatexWiki Image for some LatexWiki Image. Then if necessary we can also perform a change of variable back to LatexWiki Image

axiom
eval(eval(testqeq ,theta=sqrt(beta)),sqrt(beta)=theta)
LatexWiki Image(27)
Type: List Expression Complex Integer

See OverloadProb? for some interesting observations and problems that resulted from further development of this work with regard to type conversions and function overloading