Skip to content

Commit

Permalink
adding conversion of symmetric functions to magma and back
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Jan 28, 2025
1 parent dc99dc8 commit 3da3354
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/sage/combinat/sf/elementary.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ def P(i):
T = self.tensor_square()
return T.sum_of_monomials( (P(j), P(i-j)) for j in range(i+1) )

def _magma_init_(self, magma):
"""
Used in converting this ring to the corresponding ring in MAGMA.
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraElementary({Bref})"

class Element(classical.SymmetricFunctionAlgebra_classical.Element):
def omega(self):
r"""
Expand Down
8 changes: 8 additions & 0 deletions src/sage/combinat/sf/homogeneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ def P(i):
T = self.tensor_square()
return T.sum_of_monomials( (P(j), P(i-j)) for j in range(i+1) )

def _magma_init_(self, magma):
"""
Used in converting this ring to the corresponding ring in MAGMA.
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraHomogeneous({Bref})"

class Element(classical.SymmetricFunctionAlgebra_classical.Element):
def omega(self):
r"""
Expand Down
8 changes: 8 additions & 0 deletions src/sage/combinat/sf/monomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ def antipode_by_coercion(self, element):
s = self.realization_of().schur()
return self(s.antipode(s(element)))

def _magma_init_(self, magma):
"""
Used in converting this ring to the corresponding ring in MAGMA.
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraMonomial({Bref})"

class Element(classical.SymmetricFunctionAlgebra_classical.Element):
def expand(self, n, alphabet='x'):
"""
Expand Down
8 changes: 8 additions & 0 deletions src/sage/combinat/sf/powersum.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ def eval_at_permutation_roots_on_generators(self, k, rho):
"""
return self.base_ring().sum(d*list(rho).count(d) for d in divisors(k))

def _magma_init_(self, magma):
"""
Used in converting this ring to the corresponding ring in MAGMA.
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraPower({Bref})"

class Element(classical.SymmetricFunctionAlgebra_classical.Element):
def omega(self):
r"""
Expand Down
8 changes: 8 additions & 0 deletions src/sage/combinat/sf/schur.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ def _repeated_bernstein_creation_operator_on_basis(self, la, nu):
return (-1)**m * self([a+b for (a,b) in zip(ga, range(-r,0))])
return self.zero()

def _magma_init_(self, magma):
"""
Used in converting this ring to the corresponding ring in MAGMA.
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraSchur({Bref})"

class Element(classical.SymmetricFunctionAlgebra_classical.Element):
def __pow__(self, n):
"""
Expand Down
27 changes: 27 additions & 0 deletions src/sage/ext_data/magma/sage/basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,33 @@ intrinsic Sage(I::RngOrdIdl) -> MonStgElt, BoolElt
return Sprintf("%o.ideal(%o)", Sage(K),Sage(seq)), true;
end intrinsic;

/* Symmetric functions */

intrinsic Sage(X::AlgSym) -> MonStgElt, BoolElt
{}
if HasSchurBasis(X) then
return Sprintf("SymmetricFunctions(%o).s()", Sage(BaseRing(X))), false;
elif HasHomogeneousBasis(X) then
return Sprintf("SymmetricFunctions(%o).h()", Sage(BaseRing(X))), false;
elif HasElementaryBasis(X) then
return Sprintf("SymmetricFunctions(%o).e()", Sage(BaseRing(X))), false;
elif HasPowerSumBasis(X) then
return Sprintf("SymmetricFunctions(%o).p()", Sage(BaseRing(X))), false;
elif HasMonomialBasis(X) then
return Sprintf("SymmetricFunctions(%o).m()", Sage(BaseRing(X))), false;
end if;
end intrinsic;

intrinsic Sage(X::AlgSymElt) -> MonStgElt, BoolElt
{}
PA := Parent(X);
SF := Sage(PA);
BR := Sage(BaseRing(PA));
parts, coeffs := Support(X);
dict := (&* [ Sprintf("Partition(%o):%o(%o),", Sage(parts[i]), BR, Sage(coeffs[i])) : i in [1..#parts] ]);
return Sprintf("%o._from_dict({%o})", SF, dict), false;
end intrinsic;

/* Elliptic curves */

intrinsic Sage(X::CrvEll) -> MonStgElt, BoolElt
Expand Down
10 changes: 10 additions & 0 deletions src/sage/modules/with_basis/indexed_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,16 @@ cdef class IndexedFreeModuleElement(ModuleElement):
x_inv = B(x) ** -1
return type(self)(F, scal(x_inv, D))

def _magma_init_(self, magma):
r"""
Convert ``self`` to Magma.
"""
# Get a reference to Magma version of parent.
R = magma(self.parent()).name()
# use dict {key: coefficient}.
return '+'.join(f"({c._magma_init_(magma)})*{R}.{m._magma_init_(magma)}"
for m, c in self.monomial_coefficients().items())


def _unpickle_element(C, d):
"""
Expand Down

0 comments on commit 3da3354

Please sign in to comment.