Skip to content

Commit 00c299c

Browse files
author
Release Manager
committed
gh-39403: conversion of symmetric functions to and from magma as this can be useful ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #39403 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 4e338c6 + 24cd34a commit 00c299c

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed

src/sage/combinat/sf/elementary.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ def P(i):
9898
T = self.tensor_square()
9999
return T.sum_of_monomials( (P(j), P(i-j)) for j in range(i+1) )
100100

101+
def _magma_init_(self, magma):
102+
"""
103+
Used in converting this ring to the corresponding ring in MAGMA.
104+
105+
EXAMPLES::
106+
107+
sage: # optional - magma
108+
sage: E = SymmetricFunctions(QQ).e()
109+
sage: t = 4*E[3,2]+9
110+
sage: mt = magma(t); mt
111+
9 + 4*$.[3,2]
112+
sage: mt.sage()
113+
9*e[] + 4*e[3, 2]
114+
"""
115+
B = magma(self.base_ring())
116+
Bref = B._ref()
117+
return f"SymmetricFunctionAlgebraElementary({Bref})"
118+
101119
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
102120
def omega(self):
103121
r"""

src/sage/combinat/sf/homogeneous.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ def P(i):
125125
T = self.tensor_square()
126126
return T.sum_of_monomials( (P(j), P(i-j)) for j in range(i+1) )
127127

128+
def _magma_init_(self, magma):
129+
"""
130+
Used in converting this ring to the corresponding ring in MAGMA.
131+
132+
EXAMPLES::
133+
134+
sage: # optional - magma
135+
sage: H = SymmetricFunctions(QQ).h()
136+
sage: t = 4*H[3,2]+9
137+
sage: mt = magma(t); mt
138+
9 + 4*$.[3,2]
139+
sage: mt.sage()
140+
9*h[] + 4*h[3, 2]
141+
"""
142+
B = magma(self.base_ring())
143+
Bref = B._ref()
144+
return f"SymmetricFunctionAlgebraHomogeneous({Bref})"
145+
128146
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
129147
def omega(self):
130148
r"""

src/sage/combinat/sf/monomial.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,24 @@ def antipode_by_coercion(self, element):
276276
s = self.realization_of().schur()
277277
return self(s.antipode(s(element)))
278278

279+
def _magma_init_(self, magma):
280+
"""
281+
Used in converting this ring to the corresponding ring in MAGMA.
282+
283+
EXAMPLES::
284+
285+
sage: # optional - magma
286+
sage: M = SymmetricFunctions(QQ).m()
287+
sage: t = 4*M[3,2]+9
288+
sage: mt = magma(t); mt
289+
9 + 4*$.[3,2]
290+
sage: mt.sage()
291+
9*m[] + 4*m[3, 2]
292+
"""
293+
B = magma(self.base_ring())
294+
Bref = B._ref()
295+
return f"SymmetricFunctionAlgebraMonomial({Bref})"
296+
279297
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
280298
def expand(self, n, alphabet='x'):
281299
"""

src/sage/combinat/sf/powersum.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,24 @@ def eval_at_permutation_roots_on_generators(self, k, rho):
216216
"""
217217
return self.base_ring().sum(d*list(rho).count(d) for d in divisors(k))
218218

219+
def _magma_init_(self, magma):
220+
"""
221+
Used in converting this ring to the corresponding ring in MAGMA.
222+
223+
EXAMPLES::
224+
225+
sage: # optional - magma
226+
sage: P = SymmetricFunctions(QQ).p()
227+
sage: t = 4*P[3,2]+9
228+
sage: mt = magma(t); mt
229+
9 + 4*$.[3,2]
230+
sage: mt.sage()
231+
9*p[] + 4*p[3, 2]
232+
"""
233+
B = magma(self.base_ring())
234+
Bref = B._ref()
235+
return f"SymmetricFunctionAlgebraPower({Bref})"
236+
219237
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
220238
def omega(self):
221239
r"""

src/sage/combinat/sf/schur.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ def _repeated_bernstein_creation_operator_on_basis(self, la, nu):
224224
return (-1)**m * self([a+b for (a,b) in zip(ga, range(-r,0))])
225225
return self.zero()
226226

227+
def _magma_init_(self, magma):
228+
"""
229+
Used in converting this ring to the corresponding ring in MAGMA.
230+
231+
EXAMPLES::
232+
233+
sage: # optional - magma
234+
sage: S = SymmetricFunctions(QQ).s()
235+
sage: t = 4*S[3,2]+9
236+
sage: mt = magma(t); mt
237+
9 + 4*$.[3,2]
238+
sage: mt.sage()
239+
9*s[] + 4*s[3, 2]
240+
"""
241+
B = magma(self.base_ring())
242+
Bref = B._ref()
243+
return f"SymmetricFunctionAlgebraSchur({Bref})"
244+
227245
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
228246
def __pow__(self, n):
229247
"""

src/sage/ext_data/magma/sage/basic.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,33 @@ intrinsic Sage(I::RngOrdIdl) -> MonStgElt, BoolElt
245245
return Sprintf("%o.ideal(%o)", Sage(K),Sage(seq)), true;
246246
end intrinsic;
247247

248+
/* Symmetric functions */
249+
250+
intrinsic Sage(X::AlgSym) -> MonStgElt, BoolElt
251+
{}
252+
if HasSchurBasis(X) then
253+
return Sprintf("SymmetricFunctions(%o).s()", Sage(BaseRing(X))), false;
254+
elif HasHomogeneousBasis(X) then
255+
return Sprintf("SymmetricFunctions(%o).h()", Sage(BaseRing(X))), false;
256+
elif HasElementaryBasis(X) then
257+
return Sprintf("SymmetricFunctions(%o).e()", Sage(BaseRing(X))), false;
258+
elif HasPowerSumBasis(X) then
259+
return Sprintf("SymmetricFunctions(%o).p()", Sage(BaseRing(X))), false;
260+
elif HasMonomialBasis(X) then
261+
return Sprintf("SymmetricFunctions(%o).m()", Sage(BaseRing(X))), false;
262+
end if;
263+
end intrinsic;
264+
265+
intrinsic Sage(X::AlgSymElt) -> MonStgElt, BoolElt
266+
{}
267+
PA := Parent(X);
268+
SF := Sage(PA);
269+
BR := Sage(BaseRing(PA));
270+
parts, coeffs := Support(X);
271+
dict := (&* [ Sprintf("Partition(%o):%o(%o),", Sage(parts[i]), BR, Sage(coeffs[i])) : i in [1..#parts] ]);
272+
return Sprintf("%o._from_dict({%o})", SF, dict), false;
273+
end intrinsic;
274+
248275
/* Elliptic curves */
249276

250277
intrinsic Sage(X::CrvEll) -> MonStgElt, BoolElt

src/sage/modules/with_basis/indexed_element.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,16 @@ cdef class IndexedFreeModuleElement(ModuleElement):
10201020
x_inv = B(x) ** -1
10211021
return type(self)(F, scal(x_inv, D))
10221022

1023+
def _magma_init_(self, magma):
1024+
r"""
1025+
Convert ``self`` to Magma.
1026+
"""
1027+
# Get a reference to Magma version of parent.
1028+
R = magma(self.parent()).name()
1029+
# use dict {key: coefficient}.
1030+
return '+'.join(f"({c._magma_init_(magma)})*{R}.{m._magma_init_(magma)}"
1031+
for m, c in self.monomial_coefficients().items())
1032+
10231033

10241034
def _unpickle_element(C, d):
10251035
"""

0 commit comments

Comments
 (0)