Examples of parents endowed with multiple realizations¶
- class sage.categories.examples.with_realizations.SubsetAlgebra(R, S)[source]¶
- Bases: - UniqueRepresentation,- Parent- 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, and- Out. 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 - Inbasis and- Outbasis 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 
- 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 - >>> from sage.all import * >>> A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field >>> 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 - >>> from sage.all import * >>> F = A.F() ; F The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis >>> In = A.In() ; In The subset algebra of {1, 2, 3} over Rational Field in the In basis >>> 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 - >>> from sage.all import * >>> 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}]] - >>> from sage.all import * >>> 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}] - >>> from sage.all import * >>> F.from_set(Integer(2),Integer(3)) F[{2, 3}] >>> In.from_set(Integer(1),Integer(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}] - >>> from sage.all import * >>> F[Integer(2),Integer(3)] F[{2, 3}] >>> In[Integer(1),Integer(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}] - >>> from sage.all import * >>> F(In[Integer(2),Integer(3)]) F[{}] + F[{2}] + F[{3}] + F[{2, 3}] >>> In(F[Integer(2),Integer(3)]) In[{}] - In[{2}] - In[{3}] + In[{2, 3}] >>> Out(F[Integer(3)]) Out[{3}] + Out[{1, 3}] + Out[{2, 3}] + Out[{1, 2, 3}] >>> F(Out[Integer(3)]) F[{3}] - F[{1, 3}] - F[{2, 3}] + F[{1, 2, 3}] >>> Out(In[Integer(2),Integer(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}] - >>> from sage.all import * >>> (Integer(1) + Out[Integer(1)]) * In[Integer(2),Integer(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}] - class Bases(parent_with_realization)[source]¶
- Bases: - Category_realization_of_parent- The category of the realizations of the subset algebra - class ParentMethods[source]¶
- Bases: - object- from_set(*args)[source]¶
- Construct the monomial indexed by the set containing the elements passed as arguments. - EXAMPLES: - sage: In = Sets().WithRealizations().example().In(); In The subset algebra of {1, 2, 3} over Rational Field in the In basis sage: In.from_set(2,3) In[{2, 3}] - >>> from sage.all import * >>> In = Sets().WithRealizations().example().In(); In The subset algebra of {1, 2, 3} over Rational Field in the In basis >>> In.from_set(Integer(2),Integer(3)) In[{2, 3}] - As a shorthand, one can construct elements using the following notation: - sage: In[2,3] In[{2, 3}] - >>> from sage.all import * >>> In[Integer(2),Integer(3)] In[{2, 3}] 
 - one()[source]¶
- Return the unit of this algebra. - This default implementation takes the unit in the fundamental basis, and coerces it in - self.- EXAMPLES: - sage: A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field sage: In = A.In(); Out = A.Out() sage: In.one() In[{}] sage: Out.one() Out[{}] + Out[{1}] + Out[{2}] + Out[{3}] + Out[{1, 2}] + Out[{1, 3}] + Out[{2, 3}] + Out[{1, 2, 3}] - >>> from sage.all import * >>> A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field >>> In = A.In(); Out = A.Out() >>> In.one() In[{}] >>> Out.one() Out[{}] + Out[{1}] + Out[{2}] + Out[{3}] + Out[{1, 2}] + Out[{1, 3}] + Out[{2, 3}] + Out[{1, 2, 3}] 
 
 - super_categories()[source]¶
- 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() [Category of realizations of The subset algebra of {1, 2, 3} over Rational Field, Join of Category of algebras with basis over Rational Field and Category of commutative algebras over Rational Field and Category of realizations of unital magmas] - >>> from sage.all import * >>> A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field >>> C = A.Bases(); C Category of bases of The subset algebra of {1, 2, 3} over Rational Field >>> C.super_categories() [Category of realizations of The subset algebra of {1, 2, 3} over Rational Field, Join of Category of algebras with basis over Rational Field and Category of commutative algebras over Rational Field and Category of realizations of unital magmas] 
 
 - F[source]¶
- alias of - Fundamental
 - class Fundamental(A)[source]¶
- Bases: - CombinatorialFreeModule,- BindableClass- The Subset algebra, in the fundamental basis. - INPUT: - A– a parent with realization in- SubsetAlgebra
 - 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 - >>> from sage.all import * >>> A = Sets().WithRealizations().example() >>> A.F() The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis >>> A.Fundamental() The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis - one()[source]¶
- Return the multiplicative unit element. - EXAMPLES: - sage: A = AlgebrasWithBasis(QQ).example() # needs sage.combinat sage.modules sage: A.one_basis() # needs sage.combinat sage.modules word: sage: A.one() # needs sage.combinat sage.modules B[word: ] - >>> from sage.all import * >>> A = AlgebrasWithBasis(QQ).example() # needs sage.combinat sage.modules >>> A.one_basis() # needs sage.combinat sage.modules word: >>> A.one() # needs sage.combinat sage.modules B[word: ] 
 - one_basis()[source]¶
- Return 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[{}] - >>> from sage.all import * >>> F = Sets().WithRealizations().example().F(); F The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis >>> F.one_basis() {} >>> F.one() F[{}] 
 - product_on_basis(left, right)[source]¶
- Product of basis elements, as per - AlgebrasWithBasis.ParentMethods.product_on_basis().- INPUT: - left,- right– sets indexing basis elements
 - 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}] - >>> from sage.all import * >>> F = Sets().WithRealizations().example().F(); F The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis >>> S = F.basis().keys(); S Subsets of {1, 2, 3} >>> F.product_on_basis(S([]), S([])) F[{}] >>> F.product_on_basis(S({Integer(1)}), S({Integer(3)})) F[{1, 3}] >>> F.product_on_basis(S({Integer(1),Integer(2)}), S({Integer(2),Integer(3)})) F[{1, 2, 3}] 
 
 - class In(A)[source]¶
- Bases: - CombinatorialFreeModule,- BindableClass- The Subset Algebra, in the - Inbasis.- INPUT: - A– a parent with realization in- SubsetAlgebra
 - EXAMPLES: - sage: A = Sets().WithRealizations().example() sage: A.In() The subset algebra of {1, 2, 3} over Rational Field in the In basis - >>> from sage.all import * >>> A = Sets().WithRealizations().example() >>> A.In() The subset algebra of {1, 2, 3} over Rational Field in the In basis 
 - class Out(A)[source]¶
- Bases: - CombinatorialFreeModule,- BindableClass- The Subset Algebra, in the \(Out\) basis. - INPUT: - A– a parent with realization in- SubsetAlgebra
 - EXAMPLES: - sage: A = Sets().WithRealizations().example() sage: A.Out() The subset algebra of {1, 2, 3} over Rational Field in the Out basis - >>> from sage.all import * >>> A = Sets().WithRealizations().example() >>> A.Out() The subset algebra of {1, 2, 3} over Rational Field in the Out basis 
 - a_realization()[source]¶
- Return 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 - >>> from sage.all import * >>> A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field >>> A.a_realization() The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis 
 - base_set()[source]¶
- EXAMPLES: - sage: A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field sage: A.base_set() {1, 2, 3} - >>> from sage.all import * >>> A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field >>> A.base_set() {1, 2, 3} 
 - indices()[source]¶
- 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} - >>> from sage.all import * >>> A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field >>> A.indices() Subsets of {1, 2, 3} 
 - indices_key(x)[source]¶
- A key function on a set which gives a linear extension of the inclusion order. - INPUT: - x– set
 - EXAMPLES: - sage: A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field sage: sorted(A.indices(), key=A.indices_key) [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] - >>> from sage.all import * >>> A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field >>> sorted(A.indices(), key=A.indices_key) [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] 
 - supsets(set)[source]¶
- Return all the subsets of \(S\) containing - set.- INPUT: - set– a subset of the base set \(S\) of- self
 - 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}] - >>> from sage.all import * >>> A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field >>> A.supsets(Set((Integer(2),))) [{1, 2, 3}, {2, 3}, {1, 2}, {2}]