# Euler's Four-square Identity / Hamilton's Quaternions (quads)

Hamilton's quaternions participate in Euler's four-square formula:

```(a^2 + b^2 + c^2 + d^2)*(e^2 + f^2 + g^2 + h^2) =
(a*e - b*f - c*g - d*h)^2 +
(a*f + b*e - c*h + d*g)^2 +
(a*g + b*h + c*e - d*f)^2 +
(a*h - b*g + c*f + d*d)^2
```

As with comps, we can change the sign of the various terms, and maintain a normalized relationship. For example, changing the sign of b, c, and d in the product yields:

```(a^2 + b^2 + c^2 + d^2)*(e^2 + f^2 + g^2 + h^2) =
(a*e + b*f + c*g + d*h)^2 +
(a*f - b*e + c*h - d*g)^2 +
(a*g - b*h - c*e + d*f)^2 +
(a*h + b*g - c*f - d*d)^2
```

Writing the product using a sign matrix, we have

```(a^2 + b^2 + c^2 + d^2)*(e^2 + f^2 + g^2 + h^2) =
(S[0,0]*a*e + S[0,1]*b*f + S[0,2]*c*g + S[0,3]*d*h)^2 +
(S[1,0]*a*f + S[1,1]*b*e + S[1,2]*c*h + S[1,3]*d*g)^2 +
(S[2,0]*a*g + S[2,1]*b*h + S[2,2]*c*e + S[2,3]*d*f)^2 +
(S[3,0]*a*h + S[3,1]*b*g + S[3,2]*c*f + S[3,3]*d*d)^2
```

We have 2^16 possible values for the sign matrix. It is easy to write a small program quads.cp to step through each possibility, identifying which of these candidates happens to be true. Of these, 2^8 = 256 yield true statements. These are listed here. Four of these are associative, and correspond to left-handed and right-handed quaternions and their negates.
```r = (a,b,c,d)
s = (A,B,C,D)

index = 10318  r*s = (+a*A-b*B-c*C-d*D , +a*B+b*A-c*D+d*C , +a*C+b*D+c*A-d*B , +a*D-b*C+c*B+d*A) Associative
index = 17038  r*s = (+a*A-b*B-c*C-d*D , +a*B+b*A+c*D-d*C , +a*C-b*D+c*A+d*B , +a*D+b*C-c*B+d*A) Associative
index = 48497  r*s = (-a*A+b*B+c*C+d*D , -a*B-b*A-c*D+d*C , -a*C+b*D-c*A-d*B , -a*D-b*C+c*B-d*A) Associative
index = 55217  r*s = (-a*A+b*B+c*C+d*D , -a*B-b*A+c*D-d*C , -a*C-b*D-c*A+d*B , -a*D+b*C-c*B-d*A) Associative
```
For these associative terms, it is instructive to form the symmetric and anti-symmetric products.
```index = 10318  r*s = (+a*A-b*B-c*C-d*D , +a*B+b*A-c*D+d*C , +a*C+b*D+c*A-d*B , +a*D-b*C+c*B+d*A)
(r*s + s*r)/2 = (+a*A-b*B-c*C-d*D , a*B+b*A , a*C+c*A , a*D+d*A)
(r*s - s*r)/2 = (0 , -c*D+d*C , +b*D-d*B , -b*C+c*B)

index = 17038  r*s = (+a*A-b*B-c*C-d*D , +a*B+b*A+c*D-d*C , +a*C-b*D+c*A+d*B , +a*D+b*C-c*B+d*A)
(r*s + s*r)/2 = (+a*A-b*B-c*C-d*D , a*B+b*A , a*C+c*A , a*D+d*A)
(r*s - s*r)/2 = (0 , +c*D-d*C , -b*D+d*B , +b*C-c*B)

index = 48497  r*s = (-a*A+b*B+c*C+d*D , -a*B-b*A-c*D+d*C , -a*C+b*D-c*A-d*B , -a*D-b*C+c*B-d*A)
(r*s + s*r)/2 = (-a*A+b*B+c*C+d*D , -a*B-b*A , -a*C-c*A , -a*D-d*A)
(r*s - s*r)/2 = (0 , -c*D+C*d , +b*D-d*B , -b*C+c*B)

index = 55217  r*s = (-a*A+b*B+c*C+d*D , -a*B-b*A+c*D-d*C , -a*C-b*D-c*A+d*B , -a*D+b*C-c*B-d*A)
(r*s + s*r)/2 = (-a*A+b*B+c*C+d*D , -a*B-b*A , -a*C-c*A , -a*D-d*A)
(r*s - s*r)/2 = (0 , +c*D-d*C , -b*D+d*B , +b*C-c*B)

```
We see that these associative products have the symmetric product component as a four-vector, while the anti-symmetric product is a three-vector involving simple planes with no curl in time.

Sixteen of these are non-associative, but represent a differential angular form, where the zero component of the product is the dot product (symmetrical product) of the two incoming four vectors, while the remaining three components are an anti-symmetric product akin to the cross product or wedge product.
```r = (a,b,c,d)
s = (A,B,C,D)

index = 13904  r*s = (+a*A+b*B+c*C+d*D , -a*B+b*A-c*D+d*C , +a*C-b*D-c*A+d*B , -a*D-b*C+c*B+d*A)
index = 13984  r*s = (+a*A+b*B+c*C+d*D , +a*B-b*A+c*D-d*C , +a*C-b*D-c*A+d*B , -a*D-b*C+c*B+d*A)
index = 14672  r*s = (+a*A+b*B+c*C+d*D , -a*B+b*A-c*D+d*C , -a*C+b*D+c*A-d*B , -a*D-b*C+c*B+d*A)
index = 14752  r*s = (+a*A+b*B+c*C+d*D , +a*B-b*A+c*D-d*C , -a*C+b*D+c*A-d*B , -a*D-b*C+c*B+d*A)

index = 21344  r*s = (+a*A+b*B+c*C+d*D , +a*B-b*A-c*D+d*C , -a*C-b*D+c*A+d*B , -a*D+b*C-c*B+d*A)
index = 21392  r*s = (+a*A+b*B+c*C+d*D , -a*B+b*A+c*D-d*C , -a*C-b*D+c*A+d*B , -a*D+b*C-c*B+d*A)
index = 23648  r*s = (+a*A+b*B+c*C+d*D , +a*B-b*A-c*D+d*C , +a*C+b*D-c*A-d*B , -a*D+b*C-c*B+d*A)
index = 23696  r*s = (+a*A+b*B+c*C+d*D , -a*B+b*A+c*D-d*C , +a*C+b*D-c*A-d*B , -a*D+b*C-c*B+d*A)

index = 41824  r*s = (+a*A+b*B+c*C+d*D , +a*B-b*A-c*D+d*C , -a*C-b*D+c*A+d*B , +a*D-b*C+c*B-d*A)
index = 41872  r*s = (+a*A+b*B+c*C+d*D , -a*B+b*A+c*D-d*C , -a*C-b*D+c*A+d*B , +a*D-b*C+c*B-d*A)
index = 44128  r*s = (+a*A+b*B+c*C+d*D , +a*B-b*A-c*D+d*C , +a*C+b*D-c*A-d*B , +a*D-b*C+c*B-d*A)
index = 44176  r*s = (+a*A+b*B+c*C+d*D , -a*B+b*A+c*D-d*C , +a*C+b*D-c*A-d*B , +a*D-b*C+c*B-d*A)

index = 50768  r*s = (+a*A+b*B+c*C+d*D , -a*B+b*A-c*D+d*C , +a*C-b*D-c*A+d*B , +a*D+b*C-c*B-d*A)
index = 50848  r*s = (+a*A+b*B+c*C+d*D , +a*B-b*A+c*D-d*C , +a*C-b*D-c*A+d*B , +a*D+b*C-c*B-d*A)
index = 51536  r*s = (+a*A+b*B+c*C+d*D , -a*B+b*A-c*D+d*C , -a*C+b*D+c*A-d*B , +a*D+b*C-c*B-d*A)
index = 51616  r*s = (+a*A+b*B+c*C+d*D , +a*B-b*A+c*D-d*C , -a*C+b*D+c*A-d*B , +a*D+b*C-c*B-d*A)

index = 14672  r*s = (+a*A+b*B+c*C+d*D ,    <-- This is my candidate for a default form
-a*B+b*A-c*D+d*C ,        with anti-commutative numbers and vectors
-a*C+b*D+c*A-d*B ,        (Diagonal Descender Pattern)
-a*D-b*C+c*B+d*A)

index = 21392  r*s = (+a*A+b*B+c*C+d*D ,
-a*B+b*A+c*D-d*C ,
-a*C-b*D+c*A+d*B ,
-a*D+b*C-c*B+d*A)

index = 44128  r*s = (+a*A+b*B+c*C+d*D ,
+a*B-b*A-c*D+d*C ,
+a*C+b*D-c*A-d*B ,
+a*D-b*C+c*B-d*A)

index = 50848  r*s = (+a*A+b*B+c*C+d*D ,   <-- This is my candidate for a default form
+a*B-b*A+c*D-d*C ,       with commutative numbers and anti-commutative vectors
+a*C-b*D-c*A+d*B ,       (Gamma Pattern)
+a*D+b*C-c*B-d*A)

```
Solution 14672 is what I call the very democratic solution. Basis vectors and numbers are indistinguishable and both are anti-commutative. Solution 50848, on the other hand, keeps numbers commutative and vectors anti-commutative.

The symmetric/antisymmetric listing for 14672 and 50848 are
```index = 14672  r*s = (+a*A+b*B+c*C+d*D , -a*B+b*A-c*D+d*C , -a*C+b*D+c*A-d*B , -a*D-b*C+c*B+d*A)
(r*s + s*r)/2 = (+a*A+b*B+c*C+d*D , 0 , 0 , 0)
(r*s - s*r)/2 = (0 , -a*B+b*A-c*D+d*C , -a*C+b*D+c*A-d*B , -a*D-C*b+c*B+d*A)

index = 50848  r*s = (+a*A+b*B+c*C+d*D , +a*B-b*A+c*D-d*C , +a*C-b*D-c*A+d*B , +a*D+b*C-c*B-d*A)
(r*s + s*r)/2 = (+a*A+b*B+c*C+d*D , 0 , 0 , 0)
(r*s - s*r)/2 = (0 , +a*B-b*A+c*D-d*C , +a*C-b*D-c*A+d*B , +a*D+b*C-c*B-d*A)

```

### Four-square Relations

Having experimentally determined that eight bits of the sign matrix are independent, and eight bits determined by the others, we now want to identify a set of the independent bits, and the logic relations for the derived bits.

When the dot product is used to form the magnitude squared of a vector, the off diagonal terms will be zero if the basis sets are orthogonal, leaving tracelike terms in the sum. Consequently, I now look at orthogonality relationships among the product terms.

We start by writing the general form of the product using a sign matrix.
```(a,b,c,d)*(A,B,C,D) = (
(S[0,0]*a*A + S[0,1]*b*B + S[0,2]*c*C + S[0,3]*d*D),
(S[1,0]*a*B + S[1,1]*b*A + S[1,2]*c*D + S[1,3]*d*C),
(S[2,0]*a*C + S[2,1]*b*D + S[2,2]*c*A + S[2,3]*d*B),
(S[3,0]*a*D + S[3,1]*b*C + S[3,2]*c*B + S[3,3]*d*A)
)
```
We form a set of products where the individual basis vectors premultiply a generic vector.
```(1,0,0,0)*(A,B,C,D) = (S[0,0]*A, S[1,0]*B, S[2,0]*C, S[3,0]*D)  Eqn (1)
(0,1,0,0)*(A,B,C,D) = (S[0,1]*B, S[1,1]*A, S[2,1]*D, S[3,1]*C)  Eqn (2)
(0,0,1,0)*(A,B,C,D) = (S[0,2]*C, S[1,2]*D, S[2,2]*A, S[3,2]*B)  Eqn (3)
(0,0,0,1)*(A,B,C,D) = (S[0,3]*D, S[1,3]*C, S[2,3]*B, S[3,3]*A)  Eqn (4)

```
I would like these to be perpendicular to each other. Normality will provide two equations each from (1)dot(2), (1)dot(3), (1)dot(4), (2)dot(3), (2)dot(4), and (3)dot(4). Walking through the process explicity with (1)dot(2), we have
```(S[0,0]*A * S[0,1]*B) + (S[1,0]*B * S[1,1]*A) + (S[2,0]*C * S[2,1]*D) + (S[3,0]*D * S[3,1]*C) = 0
A*B*(S[0,0]*S[0,1] + S[1,0]*S[1,1]) + C*D*(S[2,0]*S[2,1] + S[3,0]*S[3,1]) = 0
S[0,0]*S[0,1] + S[1,0]*S[1,1] = 0  Eqn (5)
S[2,0]*S[2,1] + S[3,0]*S[3,1] = 0  Eqn (6)
```
The twelve normality relations we get here are
```S[0,0]*S[0,1] + S[1,0]*S[1,1] = 0  Eqn (5)
S[2,0]*S[2,1] + S[3,0]*S[3,1] = 0  Eqn (6)

S[0,0]*S[0,2] + S[2,0]*S[2,2] = 0  Eqn (7)
S[1,0]*S[1,2] + S[3,0]*S[3,2] = 0  Eqn (8)

S[0,0]*S[0,3] + S[3,0]*S[3,3] = 0  Eqn (9)
S[1,0]*S[1,3] + S[2,0]*S[2,3] = 0  Eqn (10)

S[0,1]*S[0,2] + S[3,1]*S[3,2] = 0  Eqn (11)
S[1,1]*S[1,2] + S[2,1]*S[2,2] = 0  Eqn (12)

S[0,1]*S[0,3] + S[2,1]*S[2,3] = 0  Eqn (13)
S[1,1]*S[1,3] + S[3,1]*S[3,3] = 0  Eqn (14)

S[0,2]*S[0,3] + S[1,2]*S[1,3] = 0  Eqn (15)
S[2,2]*S[2,3] + S[3,2]*S[3,3] = 0  Eqn (16)

```
Had we begin from postmultiplication by the basis, we would have the set of normals
```(a,b,c,d)*(1,0,0,0) = (S[0,0]*a, S[1,1]*b, S[2,2]*c, S[3,3]*d)
(a,b,c,d)*(0,1,0,0) = (S[0,1]*b, S[1,0]*a, S[2,3]*d, S[3,2]*c)
(a,b,c,d)*(0,0,1,0) = (S[0,2]*c, S[1,3]*d, S[2,0]*a, S[3,1]*b)
(a,b,c,d)*(0,0,0,1) = (S[0,3]*d, S[1,2]*c, S[2,1]*b, S[3,0]*a)

```
This set of twelve equations is
```S[0,0]*S[0,1] + S[1,1]*S[1,0] = 0  Eqn (5)
S[2,2]*S[2,3] + S[3,3]*S[3,2] = 0  Eqn (16)

S[0,0]*S[0,2] + S[2,2]*S[2,0] = 0  Eqn (7)
S[1,1]*S[1,3] + S[3,3]*S[3,1] = 0  Eqn (14)

S[0,0]*S[0,3] + S[3,3]*S[3,0] = 0  Eqn (9)
S[1,1]*S[1,2] + S[2,2]*S[2,1] = 0  Eqn (12)

S[0,1]*S[0,2] + S[3,2]*S[3,1] = 0  Eqn (11)
S[1,0]*S[1,3] + S[2,3]*S[2,0] = 0  Eqn (10)

S[0,1]*S[0,3] + S[2,3]*S[2,1] = 0  Eqn (13)
S[1,0]*S[1,2] + S[3,2]*S[3,0] = 0  Eqn (8)

S[0,2]*S[0,3] + S[1,3]*S[1,2] = 0  Eqn (15)
S[2,0]*S[2,1] + S[3,1]*S[3,0] = 0  Eqn (6)
```
We see that we get the same equations, just in a different order.

We can now make a little dictionary, giving each cell's value in terms of the other rows.
```S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S

S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S

S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S

S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S
S = -S*S/S  = -S*S/S  = -S*S/S

```
Here I have 16*3 = 48 equations, which clearly overspecify the eight free variables. The process will be to choose eight initial free variables in a fashion which does not clash among themselves, find the remaining expressions, and verify no conflicts in the full dictionary set above. As an example, S, S, S and S constitute a four-square. We can only specify three of these as independent variables, not all four.

We have many choices for the independent variables. Two choices I like are the Gamma pattern and the descending diagonal patterns.
```Gamma          Diagonal

I I I I        I I I I       I - independent variable
I x I x        x I x I       x - dependent term
I x x x        x x I x
I x x x        x x x I

```
Using the Gamma pattern QuadConsistencyCheck.cp , my independent variables are
```
Independent variables

S  S  S  S

S           S

S

S

```
Filling in the simplest of the expressions using our dictionary above,
```S = -S*S/S
S = -S*S/S
S = -S*S/S
S = -S*S/S
S = -S*S/S

```
We now have determined
```
Independent variables Upper Case, dependent variables lower case

S  S  S  S

S  s  S  s

S           s

S           s  s

```
We now work out our second level definitions
```	S =  (S*S*S)/(S*S)
S =  (S*S*S)/(S*S)
S = -(S*S*S)/(S*S)

```
We now check for consistency across the dictionary. We find in each row of the dictionary, that the last expression is a different formula from the proceeding. By dividing each row by the left hand side, we can easily see that consistency requires one more condition.
```S^2*S^2 = S^2*S^2

```
This is a non-obvious requirement! Since our signs are either +1 or -1, this condition is trivially met. However, we will be aware of this type of requirement as we develop octonions and sedenions.