Accessor methods for free algebra objects

words(x)
coeffs(x, drop=TRUE)
coeffs(x) <- value

Arguments

x

Object of class freealg

value

Numeric vector of length 1

drop

Boolean, with default TRUE meaning to drop the disord attribute, as per disordR::drop() and FALSE meaning to consistently return a disord object irregardless

Details

Access or set the different parts of a freealg object. The constant term is technically a coefficient but is documented under constant.Rd.

“Pure” extraction and replacement (as in a[i] and a[i] <- value is implemented experimentally. The code for extraction is cute but not particularly efficient.

Author

Robin K. S. Hankin

Note

There is an extended discussion of disordR discipline in the context of algebras in the mvp package at accessor.Rd.

See also

Examples

a <- rfalg()
a
#> free algebra element algebraically equal to
#> + 5accc + 2ba + 4c + ca + 7cbcb + 6cc + 3cca
coeffs(a)
#> A disord object with hash b37c1cae575a974384930b7e603f8638f2840c9e and elements
#> [1] 5 2 4 1 7 6 3
#> (in some order)
words(a)  # NB: hash is identical to that of coeffs(a)
#> A disord object with hash b37c1cae575a974384930b7e603f8638f2840c9e and elements
#> [[1]]
#> [1] 1 3 3 3
#> 
#> [[2]]
#> [1] 2 1
#> 
#> [[3]]
#> [1] 3
#> 
#> [[4]]
#> [1] 3 1
#> 
#> [[5]]
#> [1] 3 2 3 2
#> 
#> [[6]]
#> [1] 3 3
#> 
#> [[7]]
#> [1] 3 3 1
#> 
#> (in some order)

coeffs(a) <- 7   # replacement methods work 
a
#> free algebra element algebraically equal to
#> + 7accc + 7ba + 7c + 7ca + 7cbcb + 7cc + 7cca
coeffs(a)
#> [1] 7 7 7 7 7 7 7