---
title: "The `kinner()` function in the `stokes` package"
author: "Robin K. S. Hankin"
bibliography: stokes.bib
link-citations: true
output:
  pdf_document:
    extra_dependencies: ["blkarray", "bigstrut"]
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{kinner}
  %\usepackage[utf8]{inputenc}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(rmarkdown.html_vignette.check_title = FALSE)
library("stokes")
set.seed(1)
```

\hfill![](`r system.file("help/figures/stokes.png", package = "stokes")`){width=10%}


```{r}
kinner
```

To cite the `stokes` package in publications, please use
@hankin2022_stokes.  Given two $k$-forms $\alpha,\beta$, function
`kinner()` returns an inner product
$\left\langle\cdot,\cdot\right\rangle$ of $\alpha$ and $\beta$.  If
$\alpha=\alpha_1\wedge\cdots\wedge\alpha_k$ and
$\beta=\beta_1\wedge\cdots\wedge\beta_k$, and we have an inner product
$\left\langle\alpha_i,\beta_j\right\rangle$ then

$$\left\langle\cdot,\cdot\right\rangle=
\det\left(\left\langle\alpha_i,\beta_j\right\rangle_{ij}\right)$$

We extend this inner product by bilinearity to the whole of
$\Lambda^k(V)$.

# Some simple examples

[Michael Penn](https://www.youtube.com/watch?v=vDRfADusqYQ&list=PL22w63XsKjqzQZtDZO_9s2HEMRJnaOTX7&index=20&ab_channel=MichaelPenn) uses a metric of

$$
\begin{blockarray}{crrrr}
& dt & dx & dy & dz\\
\begin{block}{c[rrrr]}
dt &  1 &  0 &  0 & 0 \bigstrut[t] \\
dx &  0 & -1 &  0 & 0 \\
dy &  0 &  0 & -1 & 0 \bigstrut[b]\\
dz &  0 &  0 &  0 &-1 \bigstrut[b]\\
\end{block}
\end{blockarray}
$$


and shows that

$$
\begin{blockarray}{crrrrrrr}
 & dt\wedge dx & dt\wedge dy & dt\wedge dz & dx\wedge dy & dx\wedge dz& dy\wedge dz\\
 \begin{block}{c[rrrrrrr]}
dt\wedge dx & -1 &  0 &  0 &0&0&0&\bigstrut[t] \\
dt\wedge dy &  0 & -1 &  0 &0&0&0& \\
dt\wedge dz &  0 &  0 & -1 &0&0&0&\bigstrut[b]\\
dx\wedge dy &  0 &  0 &  0 &1&0&0&\bigstrut[b]\\
dx\wedge dz &  0 &  0 &  0 &0&1&0&\bigstrut[b]\\
dy\wedge dz &  0 &  0 &  0 &0&0&1&\bigstrut[b]\\
\end{block}
\end{blockarray}
$$

so, for example, $\left\langle dt\wedge dx,dt\wedge
dx\right\rangle=-1$ and $\left\langle dt\wedge dx,dt\wedge
dy\right\rangle=0$.  We can reproduce this relatively easily in the
package as follows.  First we need to over-write the default values of
`dx`, `dy`, and `dz` (which are defined in three dimensions) and
define `dt dx dy dz`:

```{r}
dt <- d(1)
dx <- d(2)
dy <- d(3)
dz <- d(4)
p <- c("dt^dx","dt^dy","dt^dz","dx^dy","dx^dz","dy^dz")

mink <- diag(c(1,-1,-1,-1)) # Minkowski metric

M <- matrix(NA,6,6)
rownames(M) <- p
colnames(M) <- p

do <- function(x){eval(parse(text=x))}
for(i in seq_len(6)){
  for(j in seq_len(6)){
    M[i,j] <- kinner(do(p[i]),do(p[j]),M=mink)
  }
}	
M
```

Slightly slicker:

```{r}
outer(p,p,Vectorize(function(i,j){kinner(do(i),do(j),M=mink)}))
```

# Tidyup

It is important to remove the `dt`, `dx`, `dt`, `dx` as created above
because they will interfere with the other vignettes:

```{r removedtdxdydz}
rm(dt,dx,dy,dz)
```


```{r reset_default_print_method, include=FALSE}
options(kform_symbolic_print = NULL)
```

## References {-}
