Formal sums¶
AUTHORS:
David Harvey (2006-09-20): changed FormalSum not to derive from “list” anymore, because that breaks new Element interface
Nick Alexander (2006-12-06): added test cases.
William Stein (2006, 2009): wrote the first version in 2006, documented it in 2009.
Volker Braun (2010-07-19): new-style coercions, documentation added. FormalSums now derives from UniqueRepresentation.
FUNCTIONS:
FormalSums(ring)
– create the module of formal finite sums with coefficients in the given ringFormalSum(list of pairs (coeff, number))
– create a formal sum
EXAMPLES:
sage: A = FormalSum([(1, 2/3)]); A
2/3
sage: B = FormalSum([(3, 1/5)]); B
3*1/5
sage: -B
-3*1/5
sage: A + B
2/3 + 3*1/5
sage: A - B
2/3 - 3*1/5
sage: B*3
9*1/5
sage: 2*A
2*2/3
sage: list(2*A + A)
[(3, 2/3)]
>>> from sage.all import *
>>> A = FormalSum([(Integer(1), Integer(2)/Integer(3))]); A
2/3
>>> B = FormalSum([(Integer(3), Integer(1)/Integer(5))]); B
3*1/5
>>> -B
-3*1/5
>>> A + B
2/3 + 3*1/5
>>> A - B
2/3 - 3*1/5
>>> B*Integer(3)
9*1/5
>>> Integer(2)*A
2*2/3
>>> list(Integer(2)*A + A)
[(3, 2/3)]
- class sage.structure.formal_sum.FormalSum(x, parent=None, check=True, reduce=True)[source]¶
Bases:
ModuleElement
A formal sum over a ring.
- class sage.structure.formal_sum.FormalSums[source]¶
Bases:
UniqueRepresentation
,Module
The R-module of finite formal sums with coefficients in some ring R.
EXAMPLES:
sage: FormalSums() Abelian Group of all Formal Finite Sums over Integer Ring sage: FormalSums(ZZ) Abelian Group of all Formal Finite Sums over Integer Ring sage: FormalSums(GF(7)) Abelian Group of all Formal Finite Sums over Finite Field of size 7 sage: FormalSums(ZZ[sqrt(2)]) # needs sage.rings.number_field sage.symbolic Abelian Group of all Formal Finite Sums over Maximal Order generated by sqrt2 in Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095? sage: FormalSums(GF(9,'a')) # needs sage.rings.finite_rings Abelian Group of all Formal Finite Sums over Finite Field in a of size 3^2
>>> from sage.all import * >>> FormalSums() Abelian Group of all Formal Finite Sums over Integer Ring >>> FormalSums(ZZ) Abelian Group of all Formal Finite Sums over Integer Ring >>> FormalSums(GF(Integer(7))) Abelian Group of all Formal Finite Sums over Finite Field of size 7 >>> FormalSums(ZZ[sqrt(Integer(2))]) # needs sage.rings.number_field sage.symbolic Abelian Group of all Formal Finite Sums over Maximal Order generated by sqrt2 in Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095? >>> FormalSums(GF(Integer(9),'a')) # needs sage.rings.finite_rings Abelian Group of all Formal Finite Sums over Finite Field in a of size 3^2
- base_extend(R)[source]¶
EXAMPLES:
sage: F7 = FormalSums(ZZ).base_extend(GF(7)); F7 Abelian Group of all Formal Finite Sums over Finite Field of size 7
>>> from sage.all import * >>> F7 = FormalSums(ZZ).base_extend(GF(Integer(7))); F7 Abelian Group of all Formal Finite Sums over Finite Field of size 7
The following tests against a bug that was fixed at Issue #18795:
sage: isinstance(F7, F7.category().parent_class) True
>>> from sage.all import * >>> isinstance(F7, F7.category().parent_class) True