freealg objectgrade.RdThe free algebra \(\mathcal B\) is a graded algebra: that is, for each integer \(n\geqslant 0\) there is a homogeneous subspace \(\mathcal{B}_n\) with \(\mathcal{B}_0=\mathcal{R}\) and
$$ \mathcal{B}=\bigoplus_{n=0}^\infty\mathcal{B}_n,\quad\mbox{and}\quad\mathcal{B}_n\mathcal{B}_m\subseteq\mathcal{B}_{n+m}\quad\mbox{for all $m,n\geqslant 0.$} $$
The elements of \(\cup_{n\geqslant 0}\mathcal{B}_n\) are called homogeneous and those of \(\mathcal{B}_n\) are called homogeneous of degree (or grade) \(n\).
The grade of a term is the number of symbols in it. Thus the
grade of xxx and 4xxy is 3; the grade of a constant is
zero. Because the terms are stored in an implementation-specific way,
the grade of a multi-term object is a disord object.
The grade of the zero freealg object,
grade(as.freealg(0)), is defined to be \(-\infty\),
as per Knuth [TAOCP, volume 2, p436]. This ensures that
max(grades(abelianize(x))) <= max(grades(x)) is always satisfied.
However, a case for NULL could be made.
grades(x)
grade(x, n, drop=FALSE)
grade(x, n) <- value
deg(x)grades(x) returns the grade (number of symbols) in each term
of a freealg object x.
deg(x) returns the maximum of the grades of each symbol of
x; max(grades(x)).
grade(x,n) returns the freealg object comprising terms with
grade n (which may be a vector). Note that this function is
considerably less efficient than clifford::grade().
The drop argument to grade() only makes a difference if
either the result is zero, or that n=0 (that is, extracting the
constant). It defaults to FALSE on the grounds that
constant() returns a dropped value.
grade(x,n) <- value sets the coefficients of terms with grade
n. For value, a length-one numeric vector is accepted
(notably zero, which kills terms of grade n) and also a
freealg object comprising terms of grade n.
Returns a disord object
H. Munthe-Kaas and B. Owren 1999. “Computations in a free Lie algebra”, Phil. Trans. R. Soc. Lond. A, 357:957–981 (theorem 3.8)
The clifford package includes a similar concept, also called grade.
X <- as.freealg("1 -x + 5*y + 6*x*y -8*x*x*x*x*y*x")
X
#> free algebra element algebraically equal to
#> + 1 - x - 8xxxxyx + 6xy + 5y
grades(X)
#> A disord object with hash 55749095669cc08d7e66c42699d38acf64666dad and elements
#> [1] 0 1 6 2 1
#> (in some order)
a <- rfalg(30)
a
#> free algebra element algebraically equal to
#> + 6aaaa + 3ab + 4abc + ac + 9acaa + 97b + 31ba + 22bab + 26bb + 7bbbb + 14bccb
#> + 80c + 38ca + 30cabb + 19cacc + 24cbca + 37cc + 5ccbb + 12ccca
grades(a)
#> A disord object with hash 75a7a9350c257ebc32ba9f8630b8c93555a26124 and elements
#> [1] 4 2 3 2 4 1 2 3 2 4 4 1 2 4 4 4 2 4 4
#> (in some order)
grade(a, 2)
#> free algebra element algebraically equal to
#> + 3ab + ac + 31ba + 26bb + 38ca + 37cc
grade(a, 2) <- 0 # kill all grade-2 terms
a
#> free algebra element algebraically equal to
#> + 6aaaa + 4abc + 9acaa + 97b + 22bab + 7bbbb + 14bccb + 80c + 30cabb + 19cacc +
#> 24cbca + 5ccbb + 12ccca
grade(a, 1) <- grade(a, 1) * 888
a
#> free algebra element algebraically equal to
#> + 6aaaa + 4abc + 9acaa + 86136b + 22bab + 7bbbb + 14bccb + 71040c + 30cabb +
#> 19cacc + 24cbca + 5ccbb + 12ccca