freealg.Rd
Create, test for, and coerce to, freealg
objects
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)
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
Numeric vector corresponding to the coefficients of each
element of the word
list
Character string
Character vector
Vector of integers
Object possibly of class freealg
Further arguments, passed to the methods
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 (although it does
use heuristics for the coefficients if not supplied).
Low-level helper 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.
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
\({}\pm r\) for
infinitesimals, where r
is the integer for a symbol. This
system might change in the future.
freealg(list(1:2, 2:1,numeric(0),1:6),1:4)
#> free algebra element algebraically equal to
#> + 3 + ab + 4abcdef + 2ba
freealg(list(1:2, 2:1,numeric(0),1:6)) # heuristics for coeffs: assume 1
#> free algebra element algebraically equal to
#> + 1 + ab + abcdef + ba
freealg(sapply(1:5,seq_len),1:5)
#> free algebra element algebraically equal to
#> + a + 2ab + 3abc + 4abcd + 5abcde
freealg(replicate(5,sample(-5:5,rgeom(1,1/5),replace=TRUE)),1:5)
#> free algebra element algebraically equal to
#> + 3 + 5a + bcDBAbAB + 4cB + 2eeca
as.freealg("1+xaX")^5
#> free algebra element algebraically equal to
#> + 1 + 5xaX + 10xaaX + 10xaaaX + 5xaaaaX + xaaaaaX