print.Rd
Print methods for free algebra objects. The indeterminates are represented using lowercase letters a-z (currently hard coded).
# S3 method for class 'freealg'
print(x,...)
The print method does not change the internal representation of a
freealg
object, which is a two-element list, the first of which
is a list of integer vectors representing words, and the second is a
numeric vector of coefficients.
The print method uses lowercase letters a-z to represent the indeterminates; this is currently hard coded:
> (x <- as.freealg("6abbbc + 7cax"))
free algebra element algebraically equal to
+ 6*abbbc + 7*cax
> unclass(x)
$indices
$indices[[1]]
[1] 1 2 2 2 3
$indices[[2]]
[1] 3 1 24
$coeffs
[1] 6 7
The print method has special dispensation for length-zero freealg objects but these are not handled entirely consistently.
The print method is sensitive to the value of
getOption("usecaret")
, defaulting to “FALSE”. The default
is to use uppercase letters to represent multiplicative inverses. Thus,
the inverse of a
appears as either “a^-1
” if
usecaret
is TRUE
, and “A
” if FALSE
.
Carets become cumbersome for powers above the first. For example, the
default notation for \(aba^{-2}\) is abAA
but becomes
aba^-1a^-1
if usecaret
is TRUE
.
The symbols for the indeterminates are currently hardcoded as
c(letters,LETTERS)
. The intent is to be able to signify 52
distinct indeterminates, a-z,A-Z
. This works fine if option
usecaret
is TRUE
. But if option usecaret
is
FALSE
, this can be confusing: for example, indeterminate number 1
appears as a
, and its inverse would appear as “A
”.
But indeterminate number 27 also appears as “A
”. They
look the same, but no warning is given: caveat emptor!
The method is also sensitive to getOption("mulsym")
, defaulting
to NULL
. This is the multiplication symbol used between the
coefficient and the indeterminate string. Sometimes an asterisk,
*
or a space, might be useful. If mulsym
takes its
default of NULL
[or a length zero string], the print method
suppresses coefficients of \(\pm 1\).
Integers exceeding SHRT_MAX
are reserved for infinitesimals,
which are printed as “da
”; see the note at deriv.Rd
for details.
rfalg()
#> free algebra element algebraically equal to
#> + 13aaca + 3abbb + 5acc + 2baa + caaa + 4cb
x <- rfalg(inc=TRUE)
x # default
#> free algebra element algebraically equal to
#> + 3CC + 7BccB + AA + 5AbA + 4a + 2bba + 6bc
options("usecaret" = TRUE) # use caret
x
#> free algebra element algebraically equal to
#> + 3c^-1c^-1 + 7b^-1ccb^-1 + a^-1a^-1 + 5a^-1ba^-1 + 4a + 2bba + 6bc
options("usecaret" = FALSE) # back to the default
x
#> free algebra element algebraically equal to
#> + 3CC + 7BccB + AA + 5AbA + 4a + 2bba + 6bc
x <- freealg(list(5,1:4,3,8,7),c(1,1,1,3,22))
x
#> free algebra element algebraically equal to
#> + abcd + c + e + 22g + 3h
options(mulsym = "*")
x
#> free algebra element algebraically equal to
#> + 1*abcd + 1*c + 1*e + 22*g + 3*h
options(mulsym = NULL) # restore default