An element in an indexed free module#
AUTHORS:
Travis Scrimshaw (03-2017): Moved code from
sage.combinat.free_module
.Travis Scrimshaw (29-08-2022): Implemented
copy
as the identity map.
- class sage.modules.with_basis.indexed_element.IndexedFreeModuleElement#
Bases:
ModuleElement
Element class for
CombinatorialFreeModule
- monomial_coefficients(copy=True)#
Return the internal dictionary which has the combinatorial objects indexing the basis as keys and their corresponding coefficients as values.
INPUT:
copy
– (default:True
) ifself
is internally represented by a dictionaryd
, then make a copy ofd
; ifFalse
, then this can cause undesired behavior by mutatingd
EXAMPLES:
sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) sage: B = F.basis() sage: f = B['a'] + 3*B['c'] sage: d = f.monomial_coefficients() sage: d['a'] 1 sage: d['c'] 3
To run through the monomials of an element, it is better to use the idiom:
sage: for (t,c) in f: ....: print("{} {}".format(t,c)) a 1 c 3
sage: s = SymmetricFunctions(QQ).schur() sage: a = s([2,1])+2*s([3,2]) sage: d = a.monomial_coefficients() sage: type(d) <... 'dict'> sage: d[ Partition([2,1]) ] 1 sage: d[ Partition([3,2]) ] 2
- to_vector(new_base_ring=None, order=None, sparse=False)#
Return
self
as a vector.INPUT:
new_base_ring
– a ring (default:None
)order
– (optional) an ordering of the support ofself
sparse
– (default:False
) whether to return a sparse vector or a dense vector
OUTPUT: a
FreeModule()
vectorWarning
This will crash/run forever if
self
is infinite dimensional!See also
CombinatorialFreeModule._dense_free_module()
EXAMPLES:
sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) sage: B = F.basis() sage: f = B['a'] - 3*B['c'] sage: f._vector_() (1, 0, -3)
One can use equivalently:
sage: f.to_vector() (1, 0, -3) sage: vector(f) (1, 0, -3)
More examples:
sage: QS3 = SymmetricGroupAlgebra(QQ, 3) sage: a = 2*QS3([1,2,3]) + 4*QS3([3,2,1]) sage: a._vector_() (2, 0, 0, 0, 0, 4) sage: a.to_vector() (2, 0, 0, 0, 0, 4) sage: vector(a) (2, 0, 0, 0, 0, 4) sage: a == QS3.from_vector(a.to_vector()) True sage: a.to_vector(sparse=True) (2, 0, 0, 0, 0, 4)
If
new_base_ring
is specified, then a vector overnew_base_ring
is returned:sage: a._vector_(RDF) (2.0, 0.0, 0.0, 0.0, 0.0, 4.0)
Note
github issue #13406: the current implementation has been optimized, at the price of breaking the encapsulation for FreeModule elements creation, with the following use case as metric, on a 2008’ Macbook Pro:
sage: F = CombinatorialFreeModule(QQ, range(10)) sage: f = F.an_element() sage: %timeit f._vector_() # not tested 625 loops, best of 3: 17.5 micros per loop Other use cases may call for different or further optimizations.