---
title: "Clifford involutions following Hitzer and Sangwine"
author: "Robin K. S. Hankin"
date: "02/09/2020"
output:
  pdf_document: default
  html_document:
    df_print: paged
bibliography: clifford.bib
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{involutions}
  %\usepackage[utf8]{inputenc}
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Clifford inverses

Hitzer and Sangwine set up a number of involutions which I reproduce
for convenience below.  Given $M\in Cl(p,q)$ and 

\newcommand{\abr}[1]{\left\langle #1\right\rangle}

$$M=
\abr{M}_0+
\abr{M}_1+
\abr{M}_2+\cdots+\abr{M}_0
$$

we have a number of involutions, documented at `involutions.Rd`:

* The main grade involution
$\displaystyle\widehat{M}=\sum_{k=0}^n(-1)^k\abr{M}_k\qquad\mbox{\tt gradeinv(M)}$
* Reversion $\displaystyle\widetilde{M}=\sum_{k=0}^n(-1)^{k(k-1)/2}\abr{M}_k\qquad\mbox{\tt rev(M)}$
* Clifford conjugation $\displaystyle\overline{M}=\sum_{k=0}^n(-1)^{k(k+1)/2}\abr{M}_k\qquad\mbox{\tt cliffconj(M)}$
* Grade specific maps $\displaystyle m_{\overline{j},\overline{k}}(M)=M-2\left(\abr{M}_j+\abr{M}_k\right)\qquad\mbox{\tt neg(M)}$ 
* The generalised grade specific map $\displaystyle m_A(M)=M-\sum_{i\in A}\abr{M}i\qquad\mbox{\tt neg(M)}$


H\&S  assert that

$$\overline{M} = \widehat{\widetilde{M}} = \widetilde{\widehat{M}}
=
\sum_{k=0}^n(-1)^{k(k+1)/2}\abr{M}_k
$$

which we may verify numerically:

```{r,loadcliffordlibrary,echo=TRUE,print=FALSE,message=FALSE}
library(clifford)
```


```{r,label=equation2.6}
(M <- rcliff())
a1 <- cliffconj(M)
a2 <- gradeinv(rev(M))
a3 <- rev(gradeinv(M))
is.zero(a2-a1) & is.zero(a3-a1)
```

# $p+q=3$, three-dimensional vector spaces.

We now consider the case $p+q=3$.  If $x\in Cl(p,q)$ with $p+q=3$ then
equation 6.2 asserts that $x\overline{x}=r_0 +r_3 e_1e_2e_3$ for some
$r_0,r_3\in\mathbb{R}$:

```{r,label=equation6.2}
(x <- rcliff(d=3,g=3))
x*cliffconj(x)
```

and equation 6.3 asserts that
$x\overline{x}(x\overline{x})^\sim\in\mathbb{R}$:

```{r,label=defineequation6.3}
f <- function(x){
	jj <- x*cliffconj(x)
	is.real(jj*rev(jj))
}
```

```{r,label=executeequation6.3}
signature(0,3)
f(rcliff(d=3,g=3))
signature(1,2)
f(rcliff(d=3,g=3))
signature(2,1)
f(rcliff(d=3,g=3))
signature(3,0)
f(rcliff(d=3,g=3))
```

Thus equation 6.5, which asserts that the right inverse $x_r^{-1}$ is

\[
x_r^{-1}=\frac{
	 \overline{x}\hat{x}\tilde{x}      }{
	x\overline{x}\hat{x}\tilde{x}
		},\qquad xx_r^{-1}=1
\]


```{r,label=defineequation6.5}
RI3 <- function(x){ # right inverse
	jj <- cliffconj(x)*gradeinv(x)*rev(x)
	return(jj/drop(x*jj))
}

```{r}
a <- 5+rcliff(d=3,g=3)
a
RI3(a)
zap(a*RI3(a))
zap(RI3(a)*a)
```


Now equations 7.7 and 7.8, which assert that if
$x\overline{x}m_{\overline{3},\overline{4}}(x\overline{x})$ is
nonzero, we have

\[
x_r^{-1} = \frac{
     \overline{x}m_{\overline{3},\overline{4}}(x\overline{x})  }{
    x\overline{x}m_{\overline{3},\overline{4}}(x\overline{x})
	},\qquad xx_r^{-1}=1
\]

and 
		
\[
x_l^{-1} = \frac{
     \overline{x}m_{\overline{3},\overline{4}}(x\overline{x})  }{
     \overline{x}m_{\overline{3},\overline{4}}(x\overline{x})x
	},\qquad x_l^{-1}x=1
\]

Numerical verification:		

```{r,label=defineequation7.7}
f77 <- function(x){
	jj <- cliffconj(x)*neg(x*cliffconj(x),3:4)
	return(jj/drop(x*jj))
}

f78 <- function(x){
	jj <- neg(cliffconj(x)*x,3:4)*cliffconj(x)
	return(jj/drop(jj*x))
}

a <- 3 + rcliff(d=4)
a
f77(a)
zap(a*f77(a))
zap(f77(a)*a)
```

Try the different signatures:

```{r}
set.seed(0)
sigs <- 0:4
left <- rep(NA,5)
right <- rep(NA,5)
diff <- rep(NA,5)
for(i in seq_along(sigs)){
	signature(sigs[i])
	a <- sample(1:9,1) + rcliff(d=4)
	left[i]  <- Mod(a*f77(a) -1)
	right[i] <- Mod(f77(a)*a -1)
	diff[i] <- Mod(f77(a)-f78(a))
}
left
right
diff
```

Just to be explicit, the following DOES NOT WORK:

```
a <- rcliff()
a*f77(a)   # (denominator not real)
```

# The case $p+q\leq 5$

## Right inverse

Equation 8.21 asserts that, if $p+q\leq 5$ then
$z=x\overline{x}\hat{x}\tilde{x}m_{\overline{1},\overline{4}}(x\overline{x}\hat{x}\tilde{x})\in\mathbb{R}$.  
Equation 8.22 asserts that, if $z$ is nonzero, then

\[
x_r^{-1}=\frac{
 \overline{x}\hat{x}\tilde{x}m_{\overline{1},\overline{4}}(x\overline{x}\hat{x}\tilde{x})}{
x\overline{x}\hat{x}\tilde{x}m_{\overline{1},\overline{4}}(x\overline{x}\hat{x}\tilde{x})
},xx_r^{-1}=1.
\]

```{r,label=section8}
f822 <- function(x){
	jj <- cliffconj(x)*gradeinv(x)*rev(x)
	jj <- jj*neg(x*jj,c(1L,4L))
	jj/drop(zap(x*jj))
}
```

```{r}
a <- 7+clifford(list(1,3,5,1:2,c(1,5),c(3,4),1:3,2:4,c(2,3,5),1:4,2:5,c(1,2,3,5),1:5),1:13)
a
f822(a)
zap(a*f822(a))
zap(f822(a)*a)
```

And a similar set of verifications:


```{r}
sigs <- 0:6
diffl <- rep(NA,5)
diffr <- rep(NA,5)
for(i in seq_along(sigs)){
	signature(sigs[i])
	a <- sample(1:9,1) + rcliff(d=5)
	diffl[i] <- Mod(a*f822(a)-1)
	diffr[i] <- Mod(f822(a)*a-1)
}
diffl
diffr
```

## Left inverse

Similarly, equation 8.23 asserts that, if $p+q\leq 5$ then $z'=
m_{\overline{1},\overline{4}}(\tilde{x}\hat{x}\overline{x}x)
\tilde{x}\hat{x}\overline{x}x\in\mathbb{R}$.  And if $z'\neq 0$
equation 8.24 asserts that

\[
x_l^{-1} = \frac{
m_{\overline{1},\overline{4}}(\tilde{x}\hat{x}\overline{x}x)\tilde{x}\hat{x}\overline{x} }{
m_{\overline{1},\overline{4}}(\tilde{x}\hat{x}\overline{x}x)\tilde{x}\hat{x}\overline{x}x},\qquad
x_l^{-1}x = 1.
\]

The R idiom would be

```{r}
f824 <- function(x){  # left inverse
	jj <- rev(x)*gradeinv(x)*cliffconj(x)
	jj <- neg(jj*x,c(1L,4L))*jj
	jj/drop(zap(jj*x))
}
```

Check:

```{r}
zap(f824(x)*x)
zap(f822(x)*x)
```

It turns out that the left and right inverses coincide:

```{r}
signature(0,5)
Mod(f822(x) - f824(x))
signature(1,4)
Mod(f822(x) - f824(x))
signature(2,3)
Mod(f822(x) - f824(x))
signature(3,2)
Mod(f822(x) - f824(x))
signature(4,1)
Mod(f822(x) - f824(x))
```

# Cartan isomorphism

We will carry out Cartan's isomorphism from $Cl(p,q)$ to $Cl(p-4,q+4)$
numerically.  Here we specify $p+q=7$ by calling `rcliff()` with
argument `d=7`, and force $p=4$ by executing `signature(4)`:

```{r}
a <- rcliff(d=7)   # Cl(4,3)
b <- rcliff(d=7)   # Cl(4,3)
signature(4,3)     # e1^2 = e2^2 = e3^2 = e4^2 = +1; e5^2 = ... = -1
ab <- a*b          # multiplication in Cl(4,3)

signature(0,7)   # e1^2 = ... = -1
cartan(a)*cartan(b) == cartan(ab) # multiplication in Cl(0,7)
```

and again using `cartan_inverse()`:

```{r}
cartan_inverse(cartan(a) * cartan(b)) == ab  # precalculated product!
```

Now try mapping $Cl(5,2)\longrightarrow Cl(1,7)$:

```{r}
signature(5,2); ab_sig5 <- a*b

signature(1,7)
cartan(a,2) * cartan(b,2)  == cartan(ab_sig5,2)
cartan_inverse(cartan(a,2) * cartan(b,2),2)  == ab_sig5
```

