-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
138 lines (100 loc) · 3.03 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
title: "The Free Algebra in R"
output:
github_document:
pandoc_args: --webtex
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<img src="man/figures/freealg.png" width = "150" align="right" />
<!-- badges: start -->
[![Total Downloads](https://cranlogs.r-pkg.org/badges/grand-total/freealg)](https://CRAN.R-project.org/package=freealg)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/freealg)](https://cran.r-project.org/package=freealg)
<!-- badges: end -->
# Overview
The free algebra is an interesting and useful object. Here I present
the `freealg` package which provides some functionality for free
algebra in the R programming environment. The package uses the `C++
map` class for efficiency and conforms to `disordR` discipline.
Several use-cases are provided.
# Installation
You can install the released version of `freealg` from
[CRAN](https://CRAN.R-project.org) with:
```{r, message=FALSE}
# install.packages("freealg") # uncomment this to install the package
library("freealg")
```
# The free algebra
The free algebra is the free R-module with a basis consisting of all
words over an alphabet of symbols with multiplication of words defined
as concatenation. Thus, with an alphabet of $\{x,y,z\}$ and
\[
A=\alpha x^2yx + \beta zy
\]
and
\[
B=\gamma z + \delta y^4
\]
we would have
\[
AB=\left(\alpha x^2yx+\beta zy\right)\left(\gamma z+\delta y^4\right)=\alpha\gamma x^2yxz+\alpha\delta x^2yxy^4+\beta\gamma zyz+\beta\delta zy^5
\]
and
\[
BA=\left(\gamma z+\delta y^4\right)\left(\alpha x^2yx+\beta zy\right)=\alpha\gamma zx^2yx + \alpha\delta y^4 x^2yx + \beta\gamma z^2y + \beta\delta y^4zy.
\]
A natural and easily implemented extension is to use upper-case
symbols to represent multiplicative inverses of the lower-case
equivalents (formally we would use the presentation $xX=1$). Thus if
\[
C=\epsilon\left(x^{-1}\right)^2=\epsilon X^2\]
we would have
\[
AC=\left(\alpha x^2yx+\beta zy\right)\epsilon X^2=
\alpha\epsilon x^2yX + \beta\epsilon zyX^2
\]
and
\[
CA=\epsilon X^2\left(\alpha x^2yx+\beta zy\right)=
\alpha\epsilon yx + \beta\epsilon X^2zy.
\]
The system inherits associativity from associativity of concatenation,
and distributivity is assumed, but it is not commutative.
# The `freealg` package in use
Creating a free algebra object is straightforward. We can coerce from
a character string with natural idiom:
```{r}
X <- as.freealg("1 + 3a + 5b + 5abba")
X
```
or use a more formal method:
```{r}
freealg(sapply(1:5,seq_len),1:5)
```
```{r}
Y <- as.freealg("6 - 4a +2aaab")
X+Y
X*Y
X^2
```
We can demonstrate associativity (which is non-trivial):
```{r}
set.seed(0)
(x1 <- rfalg(inc=TRUE))
(x2 <- rfalg(inc=TRUE))
(x3 <- rfalg(inc=TRUE))
```
(function `rfalg()` generates random `freealg` objects). Then
```{r}
x1*(x2*x3) == (x1*x2)*x3
```
# Further information
For more detail, see the package vignette
`vignette("freealg")`