Skip to content

Commit 3da3354

Browse files
committed
adding conversion of symmetric functions to magma and back
1 parent dc99dc8 commit 3da3354

File tree

7 files changed

+77
-0
lines changed

7 files changed

+77
-0
lines changed

src/sage/combinat/sf/elementary.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ 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+
B = magma(self.base_ring())
106+
Bref = B._ref()
107+
return f"SymmetricFunctionAlgebraElementary({Bref})"
108+
101109
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
102110
def omega(self):
103111
r"""

src/sage/combinat/sf/homogeneous.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ 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+
B = magma(self.base_ring())
133+
Bref = B._ref()
134+
return f"SymmetricFunctionAlgebraHomogeneous({Bref})"
135+
128136
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
129137
def omega(self):
130138
r"""

src/sage/combinat/sf/monomial.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ 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+
B = magma(self.base_ring())
284+
Bref = B._ref()
285+
return f"SymmetricFunctionAlgebraMonomial({Bref})"
286+
279287
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
280288
def expand(self, n, alphabet='x'):
281289
"""

src/sage/combinat/sf/powersum.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ 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+
B = magma(self.base_ring())
224+
Bref = B._ref()
225+
return f"SymmetricFunctionAlgebraPower({Bref})"
226+
219227
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
220228
def omega(self):
221229
r"""

src/sage/combinat/sf/schur.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ 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+
B = magma(self.base_ring())
232+
Bref = B._ref()
233+
return f"SymmetricFunctionAlgebraSchur({Bref})"
234+
227235
class Element(classical.SymmetricFunctionAlgebra_classical.Element):
228236
def __pow__(self, n):
229237
"""

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

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

236+
/* Symmetric functions */
237+
238+
intrinsic Sage(X::AlgSym) -> MonStgElt, BoolElt
239+
{}
240+
if HasSchurBasis(X) then
241+
return Sprintf("SymmetricFunctions(%o).s()", Sage(BaseRing(X))), false;
242+
elif HasHomogeneousBasis(X) then
243+
return Sprintf("SymmetricFunctions(%o).h()", Sage(BaseRing(X))), false;
244+
elif HasElementaryBasis(X) then
245+
return Sprintf("SymmetricFunctions(%o).e()", Sage(BaseRing(X))), false;
246+
elif HasPowerSumBasis(X) then
247+
return Sprintf("SymmetricFunctions(%o).p()", Sage(BaseRing(X))), false;
248+
elif HasMonomialBasis(X) then
249+
return Sprintf("SymmetricFunctions(%o).m()", Sage(BaseRing(X))), false;
250+
end if;
251+
end intrinsic;
252+
253+
intrinsic Sage(X::AlgSymElt) -> MonStgElt, BoolElt
254+
{}
255+
PA := Parent(X);
256+
SF := Sage(PA);
257+
BR := Sage(BaseRing(PA));
258+
parts, coeffs := Support(X);
259+
dict := (&* [ Sprintf("Partition(%o):%o(%o),", Sage(parts[i]), BR, Sage(coeffs[i])) : i in [1..#parts] ]);
260+
return Sprintf("%o._from_dict({%o})", SF, dict), false;
261+
end intrinsic;
262+
236263
/* Elliptic curves */
237264

238265
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)