Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion of symmetric functions to and from magma #39403

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/sage/combinat/sf/elementary.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@
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.

EXAMPLES::

sage: # optional - magma
sage: E = SymmetricFunctions(QQ).e()
sage: t = 4*E[3,2]+9
sage: mt = magma(t); mt
9 + 4*$.[3,2]
sage: mt.sage()
9*e[] + 4*e[3, 2]
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraElementary({Bref})"

Check warning on line 117 in src/sage/combinat/sf/elementary.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/sf/elementary.py#L115-L117

Added lines #L115 - L117 were not covered by tests

class Element(classical.SymmetricFunctionAlgebra_classical.Element):
def omega(self):
r"""
Expand Down
18 changes: 18 additions & 0 deletions src/sage/combinat/sf/homogeneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@
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.

EXAMPLES::

sage: # optional - magma
sage: H = SymmetricFunctions(QQ).h()
sage: t = 4*H[3,2]+9
sage: mt = magma(t); mt
9 + 4*$.[3,2]
sage: mt.sage()
9*h[] + 4*h[3, 2]
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraHomogeneous({Bref})"

Check warning on line 144 in src/sage/combinat/sf/homogeneous.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/sf/homogeneous.py#L142-L144

Added lines #L142 - L144 were not covered by tests

class Element(classical.SymmetricFunctionAlgebra_classical.Element):
def omega(self):
r"""
Expand Down
18 changes: 18 additions & 0 deletions src/sage/combinat/sf/monomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@
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.

EXAMPLES::

sage: # optional - magma
sage: M = SymmetricFunctions(QQ).m()
sage: t = 4*M[3,2]+9
sage: mt = magma(t); mt
9 + 4*$.[3,2]
sage: mt.sage()
9*m[] + 4*m[3, 2]
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraMonomial({Bref})"

Check warning on line 295 in src/sage/combinat/sf/monomial.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/sf/monomial.py#L293-L295

Added lines #L293 - L295 were not covered by tests

class Element(classical.SymmetricFunctionAlgebra_classical.Element):
def expand(self, n, alphabet='x'):
"""
Expand Down
18 changes: 18 additions & 0 deletions src/sage/combinat/sf/powersum.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,24 @@
"""
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.

EXAMPLES::

sage: # optional - magma
sage: P = SymmetricFunctions(QQ).p()
sage: t = 4*P[3,2]+9
sage: mt = magma(t); mt
9 + 4*$.[3,2]
sage: mt.sage()
9*p[] + 4*p[3, 2]
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraPower({Bref})"

Check warning on line 235 in src/sage/combinat/sf/powersum.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/sf/powersum.py#L233-L235

Added lines #L233 - L235 were not covered by tests

class Element(classical.SymmetricFunctionAlgebra_classical.Element):
def omega(self):
r"""
Expand Down
18 changes: 18 additions & 0 deletions src/sage/combinat/sf/schur.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,24 @@
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.

EXAMPLES::

sage: # optional - magma
sage: S = SymmetricFunctions(QQ).s()
sage: t = 4*S[3,2]+9
sage: mt = magma(t); mt
9 + 4*$.[3,2]
sage: mt.sage()
9*s[] + 4*s[3, 2]
"""
B = magma(self.base_ring())
Bref = B._ref()
return f"SymmetricFunctionAlgebraSchur({Bref})"

Check warning on line 243 in src/sage/combinat/sf/schur.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/sf/schur.py#L241-L243

Added lines #L241 - L243 were not covered by tests

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
Loading