From 4417ed23303f82b2a872361a26b7defe7ad92bc1 Mon Sep 17 00:00:00 2001 From: "Trevor K. Karn" Date: Sat, 6 Aug 2022 15:02:27 -0700 Subject: [PATCH 1/4] Fix trac 34292 --- src/sage/algebras/group_algebra.py | 10 ++++++++++ src/sage/structure/coerce.pyx | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/sage/algebras/group_algebra.py b/src/sage/algebras/group_algebra.py index 2a903447f3d..2ee63cd6f8a 100644 --- a/src/sage/algebras/group_algebra.py +++ b/src/sage/algebras/group_algebra.py @@ -172,6 +172,14 @@ def _coerce_map_from_(self, S): From: Algebra of Cyclic group of order 3 as a permutation group over Integer Ring To: Algebra of Dihedral group of order 6 as a permutation group over Rational Field + sage: H = PermutationGroup([ [(1,2), (3,4)], [(5,6,7),(12,14,18)] ]) + sage: kH = H.algebra(GF(2)) + sage: [a, b] = kH.gens() + sage: x = kH(a) + kH(b) + kH.one(); print(x) + () + (5,6,7)(12,14,18) + (1,2)(3,4) + sage: x*x #checks :trac:34292 + (5,7,6)(12,18,14) + As expected, there is no coercion when restricting the field:: @@ -184,6 +192,8 @@ def _coerce_map_from_(self, S): sage: ZG = G.algebra(ZZ, category=AdditiveMagmas()) sage: ZG.has_coerce_map_from(G) False + + """ G = self.basis().keys() K = self.base_ring() diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index 6cf8ec78bae..9f12c6b0ec9 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -1326,9 +1326,10 @@ cdef class CoercionModel: return x_elt,y_elt elif x_elt._parent == y_elt._parent: # TODO: Non-uniqueness of parents strikes again! - y_elt = parent(x_elt)(y_elt) + x_elt = parent(y_elt)(x_elt) if x_elt._parent is y_elt._parent: return x_elt,y_elt + self._coercion_error(x, x_map, x_elt, y, y_map, y_elt) cdef bint x_numeric = isinstance(x, (int, long, float, complex)) From e19ec8e7c8ba530e56a49b33c98cc58b54ab9441 Mon Sep 17 00:00:00 2001 From: "Trevor K. Karn" Date: Tue, 9 Aug 2022 15:25:33 -0700 Subject: [PATCH 2/4] Revert changes --- src/sage/structure/coerce.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index 9f12c6b0ec9..417923dad9a 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -1326,7 +1326,7 @@ cdef class CoercionModel: return x_elt,y_elt elif x_elt._parent == y_elt._parent: # TODO: Non-uniqueness of parents strikes again! - x_elt = parent(y_elt)(x_elt) + y_elt = parent(x_elt)(y_elt) if x_elt._parent is y_elt._parent: return x_elt,y_elt From 383d2733753c531d29005ba331548a0fdede4ca3 Mon Sep 17 00:00:00 2001 From: "Trevor K. Karn" Date: Tue, 9 Aug 2022 15:52:16 -0700 Subject: [PATCH 3/4] Change copy and fix _coerce_map_from --- src/sage/algebras/group_algebra.py | 20 +++++++++++++++----- src/sage/groups/perm_gps/permgroup.py | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/sage/algebras/group_algebra.py b/src/sage/algebras/group_algebra.py index 2ee63cd6f8a..6821a64f68f 100644 --- a/src/sage/algebras/group_algebra.py +++ b/src/sage/algebras/group_algebra.py @@ -156,9 +156,16 @@ def _coerce_map_from_(self, S): sage: QG = G.algebra(QQ) sage: ZG = G.algebra(ZZ) sage: ZG.coerce_map_from(H) - Coercion map: + Composite map: From: Cyclic group of order 3 as a permutation group To: Algebra of Dihedral group of order 6 as a permutation group over Integer Ring + Defn: Coercion map: + From: Cyclic group of order 3 as a permutation group + To: Dihedral group of order 6 as a permutation group + then + Coercion map: + From: Dihedral group of order 6 as a permutation group + To: Algebra of Dihedral group of order 6 as a permutation group over Integer Ring sage: QG.coerce_map_from(ZG) Generic morphism: From: Algebra of Dihedral group of order 6 as a permutation group over Integer Ring @@ -192,17 +199,20 @@ def _coerce_map_from_(self, S): sage: ZG = G.algebra(ZZ, category=AdditiveMagmas()) sage: ZG.has_coerce_map_from(G) False - - """ G = self.basis().keys() K = self.base_ring() - if G.has_coerce_map_from(S): + G_coercion = G.coerce_map_from(S) + if G_coercion is not None: from sage.categories.groups import Groups # No coercion for additive groups because of ambiguity of + # being the group action or addition of a new term. - return self.category().is_subcategory(Groups().Algebras(K)) + if not self.category().is_subcategory(Groups().Algebras(K)): + return None + if S is G: + return True + return self.coerce_map_from(G) * G_coercion if S in Sets.Algebras: S_K = S.base_ring() diff --git a/src/sage/groups/perm_gps/permgroup.py b/src/sage/groups/perm_gps/permgroup.py index 49089346995..459129c4ac8 100644 --- a/src/sage/groups/perm_gps/permgroup.py +++ b/src/sage/groups/perm_gps/permgroup.py @@ -532,6 +532,20 @@ def __init__(self, gens=None, gap_group=None, canonicalize=True, _libgap = None + def __copy__(self): + r""" + Return a "copy" of ``self`` by returning ``self``. + + EXAMPLES:: + + sage: G = PermutationGroup(((1,2), (4,5))) + sage: copy(G) is G + True + """ + return self + + __deepcopy__ = __copy__ + def construction(self): """ Return the construction of ``self``. From e6f16a7a60867a855752fe17cde5f2526bd980f2 Mon Sep 17 00:00:00 2001 From: "Trevor K. Karn" Date: Wed, 10 Aug 2022 08:47:38 -0700 Subject: [PATCH 4/4] Remove blankline --- src/sage/structure/coerce.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index 417923dad9a..6cf8ec78bae 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -1329,7 +1329,6 @@ cdef class CoercionModel: y_elt = parent(x_elt)(y_elt) if x_elt._parent is y_elt._parent: return x_elt,y_elt - self._coercion_error(x, x_map, x_elt, y, y_map, y_elt) cdef bint x_numeric = isinstance(x, (int, long, float, complex))