Bases: sage.structure.unique_representation.UniqueRepresentation, sage.structure.parent.Parent
An example of parent endowed with several realizations
We consider an algebra whose bases are indexed by the
subsets
of a given set
. We consider three natural basis of
this algebra: F, In, and Out. In the first basis, the
product is given by the union of the indexing sets. That is, for any
The In basis and Out basis are defined respectively by:
Each such basis gives a realization of , 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
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()
Injecting F as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis
...
Injecting In as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the In 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}]
Bases: sage.categories.realizations.Category_realization_of_parent
The category of the realizations of the subset algebra
alias of Bases.ParentMethods
EXAMPLES:
sage: A = Sets().WithRealizations().example(); A
The subset algebra of {1, 2, 3} over Rational Field
sage: C = A.Bases(); C
Category of bases of The subset algebra of {1, 2, 3} over Rational Field
sage: C.super_categories()
[Join of Category of algebras over Rational Field and Category of realizations of magmas,
Category of realizations of The subset algebra of {1, 2, 3} over Rational Field,
Category of algebras with basis over Rational Field]
Bases: sage.combinat.free_module.CombinatorialFreeModule, sage.misc.bindable_class.BindableClass
The Subset algebra, in the fundamental basis
INPUT:
EXAMPLES:
sage: A = Sets().WithRealizations().example()
sage: A.F()
The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis
sage: A.Fundamental()
The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis
EXAMPLES:
sage: A = AlgebrasWithBasis(QQ).example()
sage: A.one_basis()
word:
sage: A.one()
B[word: ]
Returns the index of the basis element which is equal to ‘1’.
EXAMPLES:
sage: F = Sets().WithRealizations().example().F(); F
The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis
sage: F.one_basis()
{}
sage: F.one()
F[{}]
Product of basis elements, as per AlgebrasWithBasis.ParentMethods.product_on_basis().
INPUT:
EXAMPLES:
sage: F = Sets().WithRealizations().example().F(); F
The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis
sage: S = F.basis().keys(); S
Subsets of {1, 2, 3}
sage: F.product_on_basis(S([]), S([]))
F[{}]
sage: F.product_on_basis(S({1}), S({3}))
F[{1, 3}]
sage: F.product_on_basis(S({1,2}), S({2,3}))
F[{1, 2, 3}]
Bases: sage.combinat.free_module.CombinatorialFreeModule, sage.misc.bindable_class.BindableClass
The Subset Algebra, in the In basis
INPUT:
EXAMPLES:
sage: A = Sets().WithRealizations().example()
sage: A.In()
The subset algebra of {1, 2, 3} over Rational Field in the In basis
TESTS:
The product in this basis is computed by converting to the fundamental basis, computing the product there, and then converting back:
sage: In = Sets().WithRealizations().example().In(); In
The subset algebra of {1, 2, 3} over Rational Field in the In basis
sage: x = In.an_element()
sage: y = In.an_element()
sage: In.product
<bound method ....product_by_coercion ...>
sage: In.product.__module__
'sage.categories.magmas'
sage: In.product(x, y)
-21*In[{}] - 2*In[{1}] + 19*In[{2}] + 53*In[{1, 2}]
Bases: sage.combinat.free_module.CombinatorialFreeModule, sage.misc.bindable_class.BindableClass
The Subset Algebra, in the basis
INPUT:
EXAMPLES:
sage: A = Sets().WithRealizations().example()
sage: A.Out()
The subset algebra of {1, 2, 3} over Rational Field in the Out basis
TESTS:
The product in this basis is computed by converting to the fundamental basis, computing the product there, and then converting back:
sage: Out = Sets().WithRealizations().example().Out(); Out
The subset algebra of {1, 2, 3} over Rational Field in the Out basis
sage: x = Out.an_element()
sage: y = Out.an_element()
sage: Out.product
<bound method ....product_by_coercion ...>
sage: Out.product.__module__
'sage.categories.magmas'
sage: Out.product(x, y)
Out[{}] + 4*Out[{1}] + 9*Out[{2}] + Out[{1, 2}]
Returns the default realization of self
EXAMPLES:
sage: A = Sets().WithRealizations().example(); A
The subset algebra of {1, 2, 3} over Rational Field
sage: A.a_realization()
The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis
EXAMPLES:
sage: A = Sets().WithRealizations().example(); A
The subset algebra of {1, 2, 3} over Rational Field
sage: A.base_set()
{1, 2, 3}
The objects that index the basis elements of this algebra.
EXAMPLES:
sage: A = Sets().WithRealizations().example(); A
The subset algebra of {1, 2, 3} over Rational Field
sage: A.indices()
Subsets of {1, 2, 3}
A comparison function on sets which gives a linear extension of the inclusion order.
INPUT:
EXAMPLES:
sage: A = Sets().WithRealizations().example(); A
The subset algebra of {1, 2, 3} over Rational Field
sage: sorted(A.indices(), A.indices_cmp)
[{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}]
Returns all the subsets of containing set
INPUT:
EXAMPLES:
sage: A = Sets().WithRealizations().example(); A
The subset algebra of {1, 2, 3} over Rational Field
sage: A.supsets(Set((2,)))
[{1, 2, 3}, {2, 3}, {1, 2}, {2}]