freealg v1.0-0
Monthly downloads
The Free Algebra
The free algebra in R; multivariate polynomials with non-commuting indeterminates.
Readme
The Free Algebra in R
Overview
The free algebra is an interesting and useful object. Here I present the
freealg package which provides some functionality for free algebra.
The package uses C++’s STL map class for efficiency, which has the
downside that the order of the terms is undefined. This does not matter
as the mathematical value is unaffected by reordering; and the print
method does a good job in producing human-readable output.
Installation
You can install the released version of freealg from
CRAN with:
# 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
and
and
we would have
Note that multiplication is not commutative, but it is associative. A natural and easily implemented extension is to use upper-case symbols to represent multiplicative inverses of the lower-case equivalents. Thus if
we would have
and
The system inherits power associativity from distributivity and associativity of concatenation, but 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:
X <- as.freealg("1 + 3a + 5b + 5abba")
X
#> free algebra element algebraically equal to
#> + 1 + 3*a + 5*abba + 5*b
or use a more formal method:
freealg(sapply(1:5,seq_len),1:5)
#> free algebra element algebraically equal to
#> + 1*a + 2*ab + 3*abc + 4*abcd + 5*abcde
Y <- as.freealg("6 - 4a +2aaab")
X+Y
#> free algebra element algebraically equal to
#> + 7 - 1*a + 2*aaab + 5*abba + 5*b
X*Y
#> free algebra element algebraically equal to
#> + 6 + 14*a - 12*aa + 6*aaaab + 2*aaab + 30*abba - 20*abbaa + 10*abbaaaab + 30*b - 20*ba + 10*baaab
X^2
#> free algebra element algebraically equal to
#> + 1 + 6*a + 9*aa + 15*aabba + 15*ab + 10*abba + 15*abbaa + 25*abbaabba + 25*abbab + 10*b + 15*ba + 25*babba + 25*bb
We can demonstrate associativity (which is non-trivial):
set.seed(0)
(x1 <- rfalg(inc=TRUE))
#> free algebra element algebraically equal to
#> + 7*C + 6*Ca + 4*B + 3*BC + 1*a + 5*aCBB + 2*bc
(x2 <- rfalg(inc=TRUE))
#> free algebra element algebraically equal to
#> + 6 + 1*CAAA + 2*Ca + 3*Cbcb + 7*aaCA + 4*b + 5*c
(x3 <- rfalg(inc=TRUE))
#> free algebra element algebraically equal to
#> + 3*C + 5*CbAc + 1*BACB + 2*a + 10*b + 7*cb
(function rfalg() generates random freealg objects). Then
x1*(x2*x3) == (x1*x2)*x3
#> [1] TRUE
Further information
For more detail, see the package vignette
vignette("freealg")
Functions in freealg
| Name | Description | |
| accessor | Accessor methods for freealg objects | |
| rfalg | Random free algebra objects | |
| constant | The constant term | |
| zero | The zero algebraic object | |
| freealg-package | freealg | |
| Print freealg objects | ||
| freealg | The free algebra | |
| Ops.freealg | Arithmetic Ops methods for the the free algebra | |
| No Results! | ||
Vignettes of freealg
| Name | ||
| free.bib | ||
| freealg.Rmd | ||
| No Results! | ||
Last month downloads
Details
| Type | Package |
| License | GPL (>= 2) |
| LinkingTo | Rcpp |
| SystemRequirements | C++11 |
| VignetteBuilder | knitr |
| URL | https://github.com/RobinHankin/freealg.git |
| BugReports | https://github.com/RobinHankin/freealg/issues |
| NeedsCompilation | yes |
| Packaged | 2019-09-15 20:52:47 UTC; rhankin |
| Repository | CRAN |
| Date/Publication | 2019-09-23 14:50:02 UTC |
| suggests | knitr , testthat |
| imports | Rcpp (>= 0.12.3) |
| Contributors |
Include our badge in your README
[](http://www.rdocumentation.org/packages/freealg)