freealg (version 1.0-0)

freealg: The free algebra

Description

Create, test for, an 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 [1,2,-1,3,2] corresponds to abACB (uppercase, or negative number, means inverse)

coeffs

Numeric vector corresponding to the coefficients to 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

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.

Examples

Run this code
# NOT RUN {
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


# }

Run the code above in your browser using DataLab