Examples of parents endowed with multiple realizations¶
-
sage.categories.examples.with_realizations.
SubsetAlgebra
¶ An example of parent endowed with several realizations
We consider an algebra \(A(S)\) whose bases are indexed by the subsets \(s\) of a given set \(S\). We consider three natural basis of this algebra:
F
,In
, andOut
. In the first basis, the product is given by the union of the indexing sets. That is, for any \(s, t\subset S\)\[F_s F_t = F_{s\cup t}\]The
In
basis andOut
basis are defined respectively by:\[In_s = \sum_{t\subset s} F_t \qquad\text{and}\qquad F_s = \sum_{t\supset s} Out_t\]Each such basis gives a realization of \(A\), where the elements are represented by their expansion in this basis.
This parent, and its code, demonstrate how to implement this algebra and its three realizations, with coercions and mixed arithmetic between them.
See also
Sets().WithRealizations
- the Implementing Algebraic Structures thematic tutorial.
EXAMPLES:
sage: A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field sage: A.base_ring() Rational Field
The three bases of
A
:sage: F = A.F() ; F The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis sage: In = A.In() ; In The subset algebra of {1, 2, 3} over Rational Field in the In basis sage: Out = A.Out(); Out The subset algebra of {1, 2, 3} over Rational Field in the Out basis
One can quickly define all the bases using the following shortcut:
sage: A.inject_shorthands() Defining F as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis Defining In as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the In basis Defining Out as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the Out basis
Accessing the basis elements is done with
basis()
method:sage: F.basis().list() [F[{}], F[{1}], F[{2}], F[{3}], F[{1, 2}], F[{1, 3}], F[{2, 3}], F[{1, 2, 3}]]
To access a particular basis element, you can use the
from_set()
method:sage: F.from_set(2,3) F[{2, 3}] sage: In.from_set(1,3) In[{1, 3}]
or as a convenient shorthand, one can use the following notation:
sage: F[2,3] F[{2, 3}] sage: In[1,3] In[{1, 3}]
Some conversions:
sage: F(In[2,3]) F[{}] + F[{2}] + F[{3}] + F[{2, 3}] sage: In(F[2,3]) In[{}] - In[{2}] - In[{3}] + In[{2, 3}] sage: Out(F[3]) Out[{3}] + Out[{1, 3}] + Out[{2, 3}] + Out[{1, 2, 3}] sage: F(Out[3]) F[{3}] - F[{1, 3}] - F[{2, 3}] + F[{1, 2, 3}] sage: Out(In[2,3]) Out[{}] + Out[{1}] + 2*Out[{2}] + 2*Out[{3}] + 2*Out[{1, 2}] + 2*Out[{1, 3}] + 4*Out[{2, 3}] + 4*Out[{1, 2, 3}]
We can now mix expressions:
sage: (1 + Out[1]) * In[2,3] Out[{}] + 2*Out[{1}] + 2*Out[{2}] + 2*Out[{3}] + 2*Out[{1, 2}] + 2*Out[{1, 3}] + 4*Out[{2, 3}] + 4*Out[{1, 2, 3}]