Tutorial: Implementing Algebraic Structures

<span id="tutorial-implementing-algebraic-structures"></span>



<p>This tutorial will discuss five concepts:</p>
<ul class="simple">
<li>constructing and manipulating new modules/vector spaces</li>
<li>adding more algebraic structure</li>
<li>defining morphisms</li>
<li>defining coercions and conversions</li>
<li>algebraic structures with several realizations</li>
</ul>
<p>At the end of this tutorial, the reader should be able to reimplement
by himself the example of algebra with several realizations:</p>

{{{id=0|
Sets().WithRealizations()
///
}}}

<p>Namely, we consider an algebra $A(S)$ whose basis is indexed by the
subsets $s$ of a given set $S$. $A(S)$ is endowed with three natural
basis: <tt class="docutils literal"><span class="pre">F</span></tt>, <tt class="docutils literal"><span class="pre">In</span></tt>, <tt class="docutils literal"><span class="pre">Out</span></tt>; in the first basis, the product is
given by the union of the indexing sets. The <tt class="docutils literal"><span class="pre">In</span></tt> basis and <tt class="docutils literal"><span class="pre">Out</span></tt>
basis are defined respectively by:</p>
<blockquote>

<p>Unknown directive type &quot;math&quot;.</p>
<pre class="literal-block">
.. math::

    In_s  = \sum_{&nbsp;t\subset s}&nbsp; F_t \qquad
    F_s   = \sum_{&nbsp;t\supset s}&nbsp; Out_t


</pre></blockquote>
<p>Each such basis gives a realization of $A$, where the elements are
represented by their expansion in this basis. In the running exercises
we will progressively implement this algebra and its three
realizations, with coercions and mixed arithmetic between them.</p>
<p>This tutorial heavily depends on the <a href="#id22"><span class="problematic" id="id23">`tutorial-using-free-modules`_</span></a>.</p>

<h1>Subclassing free modules and including category information</h1>
<p>As a warm-up, we implement the group algebra of the additive group
$ZZ/5ZZ$. Of course this is solely for pedagogical purposes; group
algebras are already implemented (see <tt class="docutils literal"><span class="pre">ZMod(5).algebra(ZZ)</span></tt>). Recall
that a fully functional $ZZ$-module over this group can be created
with the simple command:</p>

{{{id=1|
A = CombinatorialFreeModule(ZZ, Zmod(5), prefix='a')
///
}}}

<p>We reproduce the same, but by deriving a subclass of
<a href="#id2"><span class="problematic" id="id3">:class:`CombinatorialFreeModule`</span></a>:</p>

{{{id=2|
class MyCyclicGroupModule(CombinatorialFreeModule):
       &quot;&quot;&quot;An absolutely minimal implementation of a module whose basis is a cyclic group&quot;&quot;&quot;
       def __init__(self, R, n, *args, **kwargs):
           CombinatorialFreeModule.__init__(self, R, Zmod(n), *args, **kwargs)
///
}}}

{{{id=3|
A = MyCyclicGroupModule(QQ, 6, prefix='a') # or 4 or 5 or 11     ...
a = A.basis()
A.an_element()
///
a[0] + 3*a[1] + 3*a[2]
}}}

<p>We now want to endow $A$ with its natural product structure, to get
the desired group algebra. To define a multiplication, we should be in
a category where multiplication makes sense, which is not yet the
case:</p>

{{{id=4|
A.category()
///
Category of modules with basis over Rational Field
}}}

<p>We can look at the available categories from the documentation in the
reference manual: <a class="reference external" href="http://sagemath.com/doc/reference/categories.html">http://sagemath.com/doc/reference/categories.html</a></p>
<p>Or we can use introspection:</p>

{{{id=5|
sage.categories.  # Look through the list of categories to pick one we want
///
}}}

<p>Once we have chosen an appropriate category (here
<a href="#id4"><span class="problematic" id="id5">:class:`AlgebrasWithBasis`</span></a>), one can look at one example:</p>

{{{id=6|
E = AlgebrasWithBasis(QQ).example(); E
///
An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field
}}}

{{{id=7|
e = E.an_element(); e
///
B[word: ] + 2*B[word: a] + 3*B[word: b]
}}}

<p>and browse through its code:</p>

{{{id=8|
E??
///
}}}

<p>This code is meant as a template from which to start implementing a
new algebra. In particular it suggests that we need to implement the
methods <tt class="docutils literal"><span class="pre">product_on_basis</span></tt>, <tt class="docutils literal"><span class="pre">one_basis</span></tt>, <tt class="docutils literal"><span class="pre">_repr_</span></tt> and
<tt class="docutils literal"><span class="pre">algebra_generators</span></tt>. Another way to get this list of methods is to
ask the category (TODO: find a slicker idiom for this):</p>

{{{id=9|
from sage.misc.abstract_method import abstract_methods_of_class
abstract_methods_of_class(AlgebrasWithBasis(QQ).element_class)
///
{'required': [], 'optional': ['_add_', '_mul_']}
}}}

{{{id=10|
abstract_methods_of_class(AlgebrasWithBasis(QQ).parent_class)
///
{'required': ['__contains__'], 'optional': ['one_basis', 'product_on_basis']}
}}}

<p class="first admonition-title">Warning</p>
<p class="last">the result above is not yet necessarily complete; many</p>


<p>required methods in the categories are not yet marked as
<a href="#id6"><span class="problematic" id="id7">:function:`abstract_methods`</span></a>. We also recommend browsing the
documentation of this category: <a href="#id8"><span class="problematic" id="id9">:class:`AlgebrasWithBasis`</span></a>.</p>

<p>Here is the obtained implementation of the group algebra:</p>

{{{id=11|
class MyCyclicGroupAlgebra(CombinatorialFreeModule):

       def __init__(self, R, n, **keywords):
           self._group = Zmod(n)
           CombinatorialFreeModule.__init__(self, R, self._group,
               category=AlgebrasWithBasis(R), **keywords)

       def product_on_basis(self, left, right):
           return self.monomial( left + right )

       def one_basis(self):
           return self._group.zero()

       def algebra_generators(self):
           return Family( [self.monomial( self._group(1) ) ] )

       def _repr_(self):
           return &quot;Jason's group algebra of %s over %s&quot;%(self._group, self.base_ring())
///
}}}

<p>Some notes about this implementation:</p>
<ul>
<li><p class="first">Alternatively, we could have defined <tt class="docutils literal"><span class="pre">product</span></tt> instead of
<tt class="docutils literal"><span class="pre">product_on_basis</span></tt>:</p>
<pre class="literal-block">
...       # def product(self, left, right):
...       #     return ## something ##

</pre></li>
<li><p class="first">For the sake of readability in this tutorial, we have stripped out
all the documentation strings. Of course all of those should be
present as in <tt class="docutils literal"><span class="pre">E</span></tt>.</p>
</li>
<li><p class="first">The purpose of <tt class="docutils literal"><span class="pre">**keywords</span></tt> is to pass down options like
<tt class="docutils literal"><span class="pre">prefix</span></tt> to <a href="#id10"><span class="problematic" id="id11">:class:`CombinatorialFreeModules`</span></a>.</p>

</li>
</ul>
<p>Let us do some calculations:</p>

{{{id=12|
A = MyCyclicGroupAlgebra(QQ, 2, prefix='a') # or 4 or 5 or 11     ...
a = A.basis();
f = A.an_element();
A, f
///
(Jason's group algebra of the cyclic group Zmod(2) over Rational Field, a[0] + 3*a[1])
}}}

{{{id=13|
f * f
///
10*a[0] + 6*a[1]
}}}

{{{id=14|
f.
f.is_idempotent()
///
False
}}}

{{{id=15|
A.one()
///
a[0]
}}}

{{{id=16|
x = A.algebra_generators().first() # Typically x,y,    ... = A.algebra_generators()
[x^i for i in range(4)]
///
[a[0], a[1], a[0], a[1]]
}}}

{{{id=17|
g = 2*a[1]; (f + g)*f == f*f + g*f
///
True
}}}

<p>This seems to work fine, but we would like to put more stress on our
implementation to shake potential bugs out of it. To this end, we will
use <a href="#id12"><span class="problematic" id="id13">:class:`TestSuite`</span></a>, a tool which will perform many routine tests
on our algebra for us:</p>

{{{id=18|
TestSuite(A).run(verbose=True)
///
running ._test_additive_associativity() . . . passrunning ._test_an_element() . . . passrunning ._test_associativity() . . . passrunning ._test_category() . . . passrunning ._test_elements() . . .  Running the test suite of self.an_element()  running ._test_category() . . . pass  running ._test_not_implemented_methods() . . . pass  running ._test_pickling() . . . pass  passrunning ._test_not_implemented_methods() . . . passrunning ._test_one() . . . passrunning ._test_pickling() . . . passrunning ._test_prod() . . . passrunning ._test_some_elements() . . . passrunning ._test_zero() . . . pass
}}}

<p>For more information on categories, see:</p>

{{{id=19|
sage.categories.primer?
///
}}}

<h2>Review</h2>
<p>We wanted to create an algebra, so we:</p>
<pre class="literal-block">
# Created the underlying vector space using :class:`CombinatorialFreeModule`
# Looked at ``sage.categories.&lt;tab&gt;`` to find an appropriate category
# Loaded an example of that category to see what methods we needed to write
# Added the category information and other necessary methods to our class
# Ran :class:`TestSuite` to catch potential discrepancies

</pre><h2>Exercises</h2>
<ol class="arabic">
<li><p class="first">Make a tiny modification to product_on_basis in
&quot;MyCyclicGroupAlgebra&quot; to implement the <em>dual</em> of the group algebra
of the cyclic group instead of its group algebra (product given by
$b_fb_g=delta_{f,g}bf$).</p>
<p>Run the <a href="#id14"><span class="problematic" id="id15">:class:`TestSuite`</span></a> tests (you may ignore the &quot;pickling&quot;
errors). What do you notice?</p>

<p>Fix the implementation of <tt class="docutils literal"><span class="pre">one</span></tt> and check that the tests now pass.</p>
<p>Add the hopf algebra structure. Hint: look at the example:</p>

{{{id=20|
C = HopfAlgebrasWithBasis(QQ).example()
///
}}}

</li>
<li><p class="first">Given a set $S$, say:</p>

{{{id=21|
S = Set([1,2,3,4,5])
///
}}}

<p>and a base ring, say:</p>

{{{id=22|
R = QQ
///
}}}

<p>implement an $R$-algebra:</p>

{{{id=23|
F = SubsetAlgebraOnFundamentalBasis(S, R)   # todo: not implemented
///
}}}

<p>whose basis <tt class="docutils literal"><span class="pre">(b_s)_{s\subset</span> <span class="pre">S}</span></tt> is indexed by the subsets of <tt class="docutils literal"><span class="pre">S</span></tt>:</p>

{{{id=24|
Subsets(S)
///
Subsets of {1, 2, 3, 4, 5}
}}}

<p>and where the product is defined by $b_s b_t = b_{scup t}$.</p>
</li>
</ol>



<h1>Morphisms</h1>
<p>To better understand relationships between algebraic spaces, one wants
to consider morphisms between them:</p>

{{{id=25|
A.module_morphism?
A = MyCyclicGroupAlgebra(QQ, 2, prefix='a')
B = MyCyclicGroupAlgebra(QQ, 6, prefix='b')
A, B
///
(Jason's group algebra of the cyclic group Zmod(2) over Rational Field, Jason's group algebra of the cyclic group Zmod(6) over Rational Field)
}}}


{{{id=26|
def func_on_basis(g):
       r&quot;&quot;&quot;
       This function is the 'brain' of a (linear) morphism
       from A --&gt; B.  The input is the index of basis
       element of the domain (A).  The output is an element of the
       codomain (B).
       &quot;&quot;&quot;
       if g==1: return B.monomial(Zmod(6)(3))
       else:    return B.one()
///
}}}

<p>We can now define a morphism which extends this function to $A$ by
linearity:</p>

{{{id=27|
phi = A.module_morphism(func_on_basis, codomain=B)
f = A.an_element()
f
///
a[0] + 3*a[1]
}}}

{{{id=28|
phi(f)
///
b[0] + 3*b[3]
}}}

<h2>Exercise</h2>
<p>Define a new free module <tt class="docutils literal"><span class="pre">In</span></tt> with basis indexed by the subsets of
$S$, and a morphism <tt class="docutils literal"><span class="pre">phi</span></tt> from <tt class="docutils literal"><span class="pre">In</span></tt> to <tt class="docutils literal"><span class="pre">F</span></tt> defined by</p>
<blockquote>

<pre class="literal-block">
.. math:: \phi(In_s) = \sum_{&nbsp;t\subset s}&nbsp; F_t



</pre></blockquote>



<h1>Diagonal and Triangular Morphisms</h1>
<p>We now illustrate how to specify that a given morphism is diagonal or
triangular with respect to some order on the basis which makes it
invertible. Currently this feature requires the domain and codomain to
have the same index set (in progress ...).</p>

{{{id=29|
X = CombinatorialFreeModule(QQ, Partitions(), prefix='x'); x = X.basis();
Y = CombinatorialFreeModule(QQ, Partitions(), prefix='y'); y = Y.basis();
///
}}}

<p>A diagonal module morphism takes as argument a function whose input is
the index of a basis element of the domain, and whose output is the
coefficient of the corresponding basis element of the codomain:</p>

{{{id=30|
def diag_func(p):
       if len(p)==0: return 1
       else: return p[0]


diag_func(Partition([3,2,1]))
///
3
}}}

{{{id=31|
X_to_Y = X.module_morphism(diagonal=diag_func, codomain=Y)
f = X.an_element();
f
///
x[[]] + 2*x[[1]] + 3*x[[2]]
}}}

{{{id=32|
X_to_Y(f)
///
y[[]] + 2*y[[1]] + 6*y[[2]]
}}}

<p>Python fun-fact: <tt class="docutils literal"><span class="pre">~</span></tt> is the inversion operator (but be careful with
int's!):</p>

{{{id=33|
~2
///
1/2
}}}

{{{id=34|
~(int(2))
///
-3
}}}

<p>Diagonal module morphisms are invertible:</p>

{{{id=35|
Y_to_X = ~X_to_Y
f = y[Partition([3])] - 2*y[Partition([2,1])]
f
///
-2*y[[2, 1]] + y[[3]]
}}}

{{{id=36|
Y_to_X(f)
///
-x[[2, 1]] + 1/3*x[[3]]
}}}

{{{id=37|
X_to_Y(Y_to_X(f))
///
-2*y[[2, 1]] + y[[3]]
}}}

<p>For triangular morphisms, just like ordinary morphisms, we need a
function which accepts as input the index of a basis element of the
domain and returns an element of the codomain.  We think of this
function as representing the columns of the matrix of the linear
transformation:</p>

{{{id=38|
def triang_on_basis(p):
       return Y.sum_of_monomials(mu for mu in Partitions(sum(p)) if mu &gt;= p)

triang_on_basis([3,2])
///
y[[3, 2]] + y[[4, 1]] + y[[5]]
}}}

{{{id=39|
X_to_Y = X.module_morphism(triang_on_basis, triangular='lower', unitriangular=True, codomain=Y)
f = x[Partition([1,1,1])] + 2*x[Partition([3,2])];
f
///
x[[1, 1, 1]] + 2*x[[3, 2]]
}}}


{{{id=40|
X_to_Y(f)
///
y[[1, 1, 1]] + y[[2, 1]] + y[[3]] + 2*y[[3, 2]] + 2*y[[4, 1]] + 2*y[[5]]
}}}

<p>Triangular module_morphisms are also invertible, even if <tt class="docutils literal"><span class="pre">X</span></tt> and
<tt class="docutils literal"><span class="pre">Y</span></tt> are both infinite-dimensional:</p>

{{{id=41|
Y_to_X = ~X_to_Y
f
///
x[[1, 1, 1]] + 2*x[[3, 2]]
}}}

{{{id=42|
Y_to_X(X_to_Y(f))
///
x[[1, 1, 1]] + 2*x[[3, 2]]
}}}

<p>For details, see
<a href="#id16"><span class="problematic" id="id17">:meth:`ModulesWithBasis.ParentMethods.module_morphism`</span></a> (and also
<a href="#id18"><span class="problematic" id="id19">:class:`sage.categories.modules_with_basis.TriangularModuleMorphism`</span></a>):</p>


{{{id=43|
A.module_morphism?
///
}}}

<h2>Exercise</h2>
<p>Redefine the morphism <tt class="docutils literal"><span class="pre">phi</span></tt> from the previous exercise to specify
that it is triangular w.r.t. inclusion of subsets, and inverse this
morphism. You may want to use the following comparison function as
<tt class="docutils literal"><span class="pre">cmp</span></tt> argument to <tt class="docutils literal"><span class="pre">modules_morphism</span></tt>:</p>

{{{id=44|
def subset_cmp(s, t):
       &quot;&quot;&quot;
       A comparison function on sets which gives a linear extension
       of the inclusion order.

       INPUT:

        - ``x``, ``y`` -- sets
       EXAMPLES::

           sage: sorted(Subsets([1,2,3]), subset_cmp)
           [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}]
       &quot;&quot;&quot;
       s = cmp(len(x), len(y))
       if s != 0:
           return s
       return cmp(list(x), list(y))
///
}}}

<h1>Coercions</h1>
<p>Once we have defined a morphism from $X to Y$, we can register it as
a coercion.  This will allow Sage to apply the morphism automatically
whenever we combine elements of $X$ and $Y$ together. See
<a class="reference external" href="http://sagemath.com/doc/reference/coercion.html">http://sagemath.com/doc/reference/coercion.html</a> for more
information. As a training step, let us first define a morphism $X$ to
$h$, and register it as a coercion:</p>

{{{id=45|
def triang_on_basis(p):
       return h.sum_of_monomials(mu for mu in Partitions(sum(p)) if mu &gt;= p)

triang_on_basis([3,2])
///
h[3, 2] + h[4, 1] + h[5]
}}}

{{{id=46|
X_to_h = X.module_morphism(triang_on_basis, triangular='lower', unitriangular=True, codomain=h)
X_to_h.
X_to_h.register_as_coercion()
///
}}}

<p>Now we can convert elements from $X$ to $h$, but also do mixed
arithmetic with them:</p>

{{{id=47|
h(x[Partition([3,2])])
///
h[3, 2] + h[4, 1] + h[5]
}}}

{{{id=48|
h([2,2,1]) + x[Partition([2,2,1])]
///
2*h[2, 2, 1] + h[3, 1, 1] + h[3, 2] + h[4, 1] + h[5]
}}}

<h2>Exercise</h2>
<p>Use the inverse of <tt class="docutils literal"><span class="pre">phi</span></tt> to implement the inverse coercion from
<tt class="docutils literal"><span class="pre">F</span></tt> to <tt class="docutils literal"><span class="pre">In</span></tt>. Reimplement <tt class="docutils literal"><span class="pre">In</span></tt> as an algebra, with a product
method making it use <tt class="docutils literal"><span class="pre">phi</span></tt> and its inverse.</p>



<h1>Application: new basis and quotients of symmetric functions</h1>
<p>In the sequel, we show how to combine everything we have seen to
implement a new basis of the algebra of symmetric functions:</p>

{{{id=49|
SF = SymmetricFunctions(QQ);  # A GradedHopfAlgebraWithBasis
h  = SF.homogeneous()         # A particular basis, indexed by partitions (with some additional magic)
///
}}}

<p>$h$ is a graded algebra whose basis is indexed by partitions. Namely
<tt class="docutils literal"><span class="pre">h([i])</span></tt> represents the sum of all monomials of degree $i$:</p>
<blockquote>
sage: h([2]).expand(4)
x0^2 + x0*x1 + x1^2 + x0*x2 + x1*x2 + x2^2 + x0*x3 + x1*x3 + x2*x3 + x3^2</blockquote>
<p>and <tt class="docutils literal"><span class="pre">h(\mu)</span> <span class="pre">=</span> <span class="pre">prod(</span> <span class="pre">h(p)</span> <span class="pre">for</span> <span class="pre">p</span> <span class="pre">in</span> <span class="pre">mu</span> <span class="pre">)</span></tt>:</p>

{{{id=50|
h([3,2,2,1]) == h([3]) * h([2]) * h([2]) * h([1])
///
True
}}}


{{{id=51|
class MySFBasis(CombinatorialFreeModule):
       r&quot;&quot;&quot;
       Note: We would typically use SymmetricFunctionAlgebra_generic
       for this. This is as an example only.
       &quot;&quot;&quot;

       def __init__(self, R, *args, **kwargs):
           &quot;&quot;&quot; TODO: Informative doc-string and examples &quot;&quot;&quot;
           CombinatorialFreeModule.__init__(self, R, Partitions(), category=AlgebrasWithBasis(R), *args, **kwargs)
           self._h = SymmetricFunctions(R).homogeneous()
           self._to_h = self.module_morphism( self._to_h_on_basis, triangular='lower', unitriangular=True, codomain=self._h)
           self._from_h = ~(self._to_h)
           self._to_h.register_as_coercion()
           self._from_h.register_as_coercion()

       def _to_h_on_basis(self, la):
           return self._h.sum_of_monomials(mu for mu in Partitions(sum(la)) if mu &gt;= la)

       def product(self, left, right):
           return self( self._h(left) * self._h(right) )

       def _repr_(self):
           return &quot;Jason's basis for symmetric functions over %s&quot;%self.base_ring()

       &#64;cached_method
       def one_basis(self):
           r&quot;&quot;&quot; Returns the index of the basis element which is equal to '1'.&quot;&quot;&quot;
           return Partition([])
X = MySFBasis(QQ, prefix='x'); x = X.basis(); h = SymmetricFunctions(QQ).homogeneous()
f = X(h([2,1,1]) - 2*h([2,2]))  # Note the capital X
f
h(f)
///
x[[2, 1, 1]] - 3*x[[2, 2]] + 2*x[[3, 1]]h[2, 1, 1] - 2*h[2, 2]
}}}

{{{id=52|
f*f*f
///
x[[2, 2, 2, 1, 1, 1, 1, 1, 1]] - 7*x[[2, 2, 2, 2, 1, 1, 1, 1]] + 18*x[[2, 2, 2, 2, 2, 1, 1]] - 20*x[[2, 2, 2, 2, 2, 2]] + 8*x[[3, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
}}}

{{{id=53|
h(f*f)
///
h[2, 2, 1, 1, 1, 1] - 4*h[2, 2, 2, 1, 1] + 4*h[2, 2, 2, 2]
}}}

<p>As a final example, we implement a quotient of the algebra of
symmetric functions:</p>

{{{id=54|
class MySFQuotient(CombinatorialFreeModule):
       r&quot;&quot;&quot;
       The quotient of the ring of symmetric functions by the ideal generated
       by those monomial symmetric functions whose part is larger than some fixed
       number ``k``.
       &quot;&quot;&quot;

       def __init__(self, R, k, prefix=None, *args, **kwargs):

           #  Note: Setting self._prefix is equivalent to using the prefix keyword
           #  in CombinatorialFreeModule.__init__

           if prefix is not None:
               self._prefix = prefix
           else:
               self._prefix = 'mm'

           CombinatorialFreeModule.__init__(self, R,
               Partitions(NonNegativeIntegers(), max_part=k),
               category = GradedHopfAlgebrasWithBasis(R), *args, **kwargs)

           self._k = k
           self._m = SymmetricFunctions(R).monomial()

           self.lift = self.module_morphism(self._m.monomial)
           self.retract = self._m.module_morphism(self._retract_on_basis, codomain=self)

           self.lift.register_as_coercion()
           self.retract.register_as_coercion()

       def _retract_on_basis(self, mu):
           r&quot;&quot;&quot; Takes the index of a basis element of a monomial
           symmetric function, and returns the projection of that
           element to the quotient.&quot;&quot;&quot;

           if len(mu) &gt; 0 and mu[0] &gt; self._k:
               return self.zero()
           return self.monomial(mu)

       &#64;cached_method
       def one_basis(self):
           return Partition([])

       def product(self, left, right):
           return self( self._m(left) * self._m(right) )
MM = MySFQuotient(QQ, 3)
mm = MM.basis()
m = SymmetricFunctions(QQ).monomial()
P = Partition
f = mm[P([3,2,1])] + 2*mm[P([3,3])]
f
///
mm[[3, 2, 1]] + 2*mm[[3, 3]]
}}}

{{{id=55|
m(f)
///
m[3, 2, 1] + 2*m[3, 3]
}}}

{{{id=56|
(m(f))^2
///
8*m[3, 3, 2, 2, 1, 1] + 12*m[3, 3, 2, 2, 2] + 24*m[3, 3, 3, 2, 1] + 48*m[3, 3, 3, 3] + 4*m[4, 3, 2, 2, 1] + 4*m[4, 3, 3, 1, 1] + 14*m[4, 3, 3, 2] + 4*m[4, 4, 2, 2] + 4*m[4, 4, 3, 1] + 6*m[4, 4, 4] + 4*m[5, 3, 2, 1, 1] + 4*m[5, 3, 2, 2] + 12*m[5, 3, 3, 1] + 2*m[5, 4, 2, 1] + 6*m[5, 4, 3] + 4*m[5, 5, 1, 1] + 2*m[5, 5, 2] + 4*m[6, 2, 2, 1, 1] + 6*m[6, 2, 2, 2] + 6*m[6, 3, 2, 1] + 10*m[6, 3, 3] + 2*m[6, 4, 1, 1] + 5*m[6, 4, 2] + 4*m[6, 5, 1] + 4*m[6, 6]
}}}

{{{id=57|
f^2
///
8*mm[[3, 3, 2, 2, 1, 1]] + 12*mm[[3, 3, 2, 2, 2]] + 24*mm[[3, 3, 3, 2, 1]] + 48*mm[[3, 3, 3, 3]]
}}}

{{{id=58|
(m(f))^2 - m(f^2)
///
4*m[4, 3, 2, 2, 1] + 4*m[4, 3, 3, 1, 1] + 14*m[4, 3, 3, 2] + 4*m[4, 4, 2, 2] + 4*m[4, 4, 3, 1] + 6*m[4, 4, 4] + 4*m[5, 3, 2, 1, 1] + 4*m[5, 3, 2, 2] + 12*m[5, 3, 3, 1] + 2*m[5, 4, 2, 1] + 6*m[5, 4, 3] + 4*m[5, 5, 1, 1] + 2*m[5, 5, 2] + 4*m[6, 2, 2, 1, 1] + 6*m[6, 2, 2, 2] + 6*m[6, 3, 2, 1] + 10*m[6, 3, 3] + 2*m[6, 4, 1, 1] + 5*m[6, 4, 2] + 4*m[6, 5, 1] + 4*m[6, 6]
}}}

{{{id=59|
MM( (m(f))^2 - m(f^2) )
///
0
}}}