freealg: The free algebra

freealgR Documentation

The free algebra

Description

Create, test for, and coerce to, freealg objects

Usage

freealg(words, coeffs)
is_ok_free(words,coeffs)
is.freealg(x)
as.freealg(x,...)
char_to_freealg(ch)
natural_char_to_freealg(string)
string_to_freealg(string)
vector_to_free(v,coeffs)

Arguments

words

Terms of the algebra object, eg c(1,2,-1,-3,-2) corresponds to abACB because a=1, b=2 etc; uppercase, or negative number, means inverse

coeffs

Numeric vector corresponding to the coefficients of each element of the word list

string

Character string

ch

Character vector

v

Vector of integers

x

Object possibly of class freealg

...

Further arguments, passed to the methods

Details

\loadmathjax

Function freealg() is the formal creation mechanism for freealg objects. However, it is not very user-friendly; it is better to use as.freealg() in day-to-day use.

Function is_ok_freealg() checks for consistency of its arguments.

A freealg object is a two-element list. The first element is a list of integer vectors representing the indices and the second is a numeric vector of coefficients. Thus, for example:

> as.freealg("a+4bd+3abbbbc")
free algebra element algebraically equal to
 + 1*a + 3*abbbbc + 4*bd
> dput(as.freealg("a+4bd+3abbbbc"))
structure(list(indices = list(1L, c(1L, 2L, 2L, 2L, 2L, 3L), 
    c(2L, 4L)), coeffs = c(1, 3, 4)), class = "freealg")

Observe that the order of the terms is not preserved and indeed is undefined (implementation-specific). Zero entries are stripped out.

Character strings may be coerced to freealg objects; as.freealg() calls natural_char_to_freealg(), which is user-friendly. Functions char_to_freealg() and string_to_freealg() are low-level helper functions. These functions assume that upper-case letters are the multiplicative inverses of the lower-case equivalents; so for example as.freealg("aA") and as.freealg(aBcCbA) evaluate to one. This can be confusing with the default print method.

Even though individual symbols have multiplicative inverses, a general element of the free algebra will not have a multiplicative inverse. For example, 1+x does not have an inverse. The free algebra is not a division algebra, in general.

Note

Internally, the package uses signed integers and as such can have .Machine$integer.max different symbols; on my machine this is 2147483647. Of course the print method cannot deal with this as it only has 26 symbols for letters a-z (and A-Z for the inverses), but the objects themselves do not care about the print method. Note also that the experimental calculus facility (as per deriv()) reserves numbers in the range SHRT_MAX\mjeqn\pm r+/-r for infinitesimals, where r is the integer for a symbol. This system might change in the future.

Author(s)

Robin K. S. Hankin

Examples


freealg(list(1:2, 2:1,numeric(0),1:6),1:4)

freealg(sapply(1:5,seq_len),1:5)

freealg(replicate(5,sample(-5:5,rgeom(1,1/5),replace=TRUE)),1:5)


as.freealg("1+xaX")^5



freealg documentation built on Aug. 28, 2022, 9:05 a.m.