The goal of pauliframes is to provide a quick way create Pauli frames, data frames which resemble Pauli matrices. Developers and tinkerers can use this tool to test out new functions.
You can install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("mncube/pauliframes")
Use the pauli constructor function to create the initial pauli object:
library(pauliframes)
(pf <- pauli())
#> $sig0
#> x y
#> 1 1 0
#> 2 0 1
#>
#> $sig1
#> x y
#> 1 0 1
#> 2 1 0
#>
#> $sig2
#> x y
#> 1 0+0i 0-1i
#> 2 0+1i 0+0i
#>
#> $sig3
#> x y
#> 1 1 0
#> 2 0 -1
#>
#> attr(,"class")
#> [1] "pauli"
In this package, i() is syntactic sugar for sqrt(-1+0i)
i()
#> [1] 0+1i
Use the opop (operate on pauli) function to quickly operate on pauli frames and return an object of class pauli_d (pauli descendent) frame:
(pf2 <- opop(pf, function(x)x^2 - 1))
#> $sig0
#> x y
#> 1 0 -1
#> 2 -1 0
#>
#> $sig1
#> x y
#> 1 -1 0
#> 2 0 -1
#>
#> $sig2
#> x y
#> 1 -1 -2
#> 2 -2 -1
#>
#> $sig3
#> x y
#> 1 0 -1
#> 2 -1 0
#>
#> attr(,"class")
#> [1] "pauli_d"
pauli objects have a plot method
plot(pf)
As do pauli_d objects
plot(pf2)
And another pauli_d plot
pf3 <- opop(pf, function(x)x^3 - 2*x^2)
plot(pf3)
Another pauli_d plot
pf4 <- opop(pf, function(x)x + i())
plot(pf4)
And one last pauli_d plot
pf5 <- opop(pf, function(x) cos(x) + i()*sin(x))
plot(pf5)
The opop function makes use of the pauliframes::coerce_Re function. After the provided anonymous function operates on the pauli (or pauli_d) object, coerce_Re checks each cell for non-zero imaginary parts. If all cells lack a non-zero imaginary part, then the returned data frame drops the imaginary part from all cells. However, if any cell has a non-zero imaginary part, all cells in the output will be complex. For an example, compare pf (above) to pf_ii below where each cell in each data frame is multiplied by i()
(pf_ii <- opop(pf, function(x)x*i()))
#> $sig0
#> x y
#> 1 0+1i 0+0i
#> 2 0+0i 0+1i
#>
#> $sig1
#> x y
#> 1 0+0i 0+1i
#> 2 0+1i 0+0i
#>
#> $sig2
#> x y
#> 1 0 1
#> 2 -1 0
#>
#> $sig3
#> x y
#> 1 0+1i 0+0i
#> 2 0+0i 0-1i
#>
#> attr(,"class")
#> [1] "pauli_d"
Recall that with pf, only sig2 was plotted using the Real and the Img axis. Since sig2 is the only data frame in pf_ii that lacks a non-zero imaginary part, now sig2 is the only frame plotted on the x and the y axis.
plot(pf_ii)
To get the determinant of a pauli (or pauli_d) frame, use the pdet function which returns a list of determinants and assigns the class attribute “pdet” to the object. Note that R does not compute determinants for matrices with complex numbers. For example, the commented out block below produced the following error during development:
#det(as.matrix(data.frame(x = c(i(), 1), y = c(-i(), -1))))
Error in determinant.matrix(x, logarithm = TRUE, …) : ‘determinant’ not currently defined for complex matrices
As such, for the pauli frame, the pdet object is
pdet(pf)
#> $sig0
#> [1] 1
#>
#> $sig1
#> [1] -1
#>
#> $sig2
#> [1] -1
#>
#> $sig3
#> [1] -1
#>
#> attr(,"class")
#> [1] "pdet"
And for the more complicated pf5, which was computed as opop(pf, function(x) cos(x) + i()*sin(x)), the pdet object is
pdet(pf5)
#> $sig0
#> [1] -1.416147+0.909297i
#>
#> $sig1
#> [1] 1.416147-0.909297i
#>
#> $sig2
#> [1] 0
#>
#> $sig3
#> [1] 0
#>
#> attr(,"class")
#> [1] "pdet"
The transpose method transposes each data frame within a pauli (pauli_d) frame then converts from matrices back to data frames and returns a pauli_d object. In the example below, notice that only the non-symmetric data frame (pf$sig2) changes.
t(pf)
#> $sig0
#> x y
#> 1 1 0
#> 2 0 1
#>
#> $sig1
#> x y
#> 1 0 1
#> 2 1 0
#>
#> $sig2
#> x y
#> 1 0+0i 0+1i
#> 2 0-1i 0+0i
#>
#> $sig3
#> x y
#> 1 1 0
#> 2 0 -1
#>
#> attr(,"class")
#> [1] "pauli_d"
Starting with the pauli_d frame pf5, the transpose method returns:
t(pf5)
#> $sig0
#> x y
#> 1 0.5403023+0.841471i 1.0000000+0.000000i
#> 2 1.0000000+0.000000i 0.5403023+0.841471i
#>
#> $sig1
#> x y
#> 1 1.0000000+0.000000i 0.5403023+0.841471i
#> 2 0.5403023+0.841471i 1.0000000+0.000000i
#>
#> $sig2
#> x y
#> 1 1.000000 0.3678794
#> 2 2.718282 1.0000000
#>
#> $sig3
#> x y
#> 1 0.5403023+0.841471i 1.0000000+0.000000i
#> 2 1.0000000+0.000000i 0.5403023-0.841471i
#>
#> attr(,"class")
#> [1] "pauli_d"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.