## Mirroring: Reversing Order of a Vector's Components

Given an $N$-dimensional euclidean vector space, the reversal of a vectors components can be produced by $k$-reflections in hyperplanes normal to $n_i$

$$ a^{'} = -(n_1 n_{2}\cdots n_{k }) a (n_k \cdots n_2 n_1 )$$

where 
$$ k =  N/2 $$

and 

$$ n_i = e_i-e_{N-i} $$

Note that for vector spaces with an odd number of dimensions the middle component cancels it self out. Bellow are some explicit examples, illustrating the operation for various dimensions.


```
from sympy import * 
from galgebra.ga import Ga
import sympy

```

### 2D


```
(ga,e1,e2) = Ga.build('e1 e2',g=[1,1])
a=ga.mv('a','vector')

n = sqrt(2)/2*(e1-e2)
-n*a*n
```




\begin{equation*} a^{2} e_{1} + a^{1} e_{2} \end{equation*}



### 3D


```
(ga,e1,e2,e3) = Ga.build('e1 e2 e3',g=[1,1,1])
a=ga.mv('a','vector')


n = sqrt(2)/2*(e1-e3)
-n*a*n
```




\begin{equation*} a^{3} e_{1} + a^{2} e_{2} + a^{1} e_{3} \end{equation*}



### 4D


```
(ga,e1,e2,e3,e4) = Ga.build('e1 e2 e3 e4',g=[1,1,1,1])
a=ga.mv('a','vector')
n = sqrt(2)/2*(e1-e4)
m = sqrt(2)/2*(e2-e3)

m*n*a*n*m
```




\begin{equation*} a^{4} e_{1} + a^{3} e_{2} + a^{2} e_{3} + a^{1} e_{4} \end{equation*}



### 5D


```
(ga,e1,e2,e3,e4, e5) = Ga.build('e1 e2 e3 e4 e5',g=[1,1,1,1,1])
a=ga.mv('a','vector')
n = sqrt(2)/2*(e1-e5)
m = sqrt(2)/2*(e2-e4)

a_flip = m*n*a*n*m
a_flip
```




\begin{equation*} a^{5} e_{1} + a^{4} e_{2} + a^{3} e_{3} + a^{2} e_{4} + a^{1} e_{5} \end{equation*}



### 6D


```
(ga,e1,e2,e3,e4, e5, e6) = Ga.build('e1 e2 e3 e4 e5 e6',g=[1,1,1,1,1,1])
a=ga.mv('a','vector')
n = sqrt(2)/2*(e1-e6)
m = sqrt(2)/2*(e2-e5)
o = sqrt(2)/2*(e3-e4)

a_flip = -m*n*o*a*o*n*m
a_flip
```




\begin{equation*} a^{6} e_{1} + a^{5} e_{2} + a^{4} e_{3} + a^{3} e_{4} + a^{2} e_{5} + a^{1} e_{6} \end{equation*}



### Ok, lets write a function for n-D


```

def mirror(a):
    e = a.Ga.mv_basis  # vector basis
    N = len(e)       # dimension of space
    n = range(N-1)   # reflection vectors
    a_mir = a        # outputs
    for i in range(len(e)/2):
        n[i] = sqrt(2)/2* (e[i] - e[N-1-i])
        a_mir = -n[i]*a_mir*n[i]
    return a_mir

a_mir = mirror(a)
a_mir
```




\begin{equation*} a^{6} e_{1} + a^{5} e_{2} + a^{4} e_{3} + a^{3} e_{4} + a^{2} e_{5} + a^{1} e_{6} \end{equation*}



## Even and Odd modes

A discrete function of length $N$ can be thought of as an $N$-dimensional vector. Any such function may broken up into *even* and *odd* modes. 

\begin{eqnarray*}
a &=& {\frac{1}{2} (a+a^{'})} + \frac{1}{2} (a-a^{'})\\
a &=&  a_e + a_o
\end{eqnarray*}

where $a^{'}$ is the mirrored version of $a$, as described above.


```
half = Rational(1,2)
even = lambda a: half*(a+mirror(a))
odd = lambda a: half*(a-mirror(a))
```

### 2D


```
(ga,e1,e2) = Ga.build('e1 e2',g=[1,1])

a = ga.mv('a','vector')
a_e = even(a)
a_e
```




\begin{equation*} \left ( \frac{a^{1}}{2} + \frac{a^{2}}{2}\right ) e_{1} + \left ( \frac{a^{1}}{2} + \frac{a^{2}}{2}\right ) e_{2} \end{equation*}




```
a_o = odd(a)
a_o
```




\begin{equation*} \left ( \frac{a^{1}}{2} - \frac{a^{2}}{2}\right ) e_{1} + \left ( - \frac{a^{1}}{2} + \frac{a^{2}}{2}\right ) e_{2} \end{equation*}



5c96bc859865bba91e37e62a5364b6c886ba0adc
ipynb
Jupyter Notebook
notebooks/Even and Odd Functions.ipynb
arsenovic/ga-examples
69672c543f29125cfdaaab4f3957260baf69b6aa
BSD-2-Clause
2019-05-01T20:44:48.000Z
2019-05-01T20:44:48.000Z
notebooks/Even and Odd Functions.ipynb
arsenovic/ga-examples
69672c543f29125cfdaaab4f3957260baf69b6aa
BSD-2-Clause
notebooks/Even and Odd Functions.ipynb
arsenovic/ga-examples
69672c543f29125cfdaaab4f3957260baf69b6aa
BSD-2-Clause
Qwen/Qwen-72B
1. YES
2. YES