This code:


























*H = PermutationGroup([ [(1,2), (3,4)], [(5,6,7),(12,14,18)] ])kH = 
H.algebra(GF(2))[a, b] = H.gens()# Produces no coercion errorprint((kH(a) + 
kH(b) + H.one())^2)# Produces a coercion error in all cases belowtry:    
print((kH(a) + kH(b) + kH(kH.one()))^2)except:    print("Fail 1")    
passtry:    print((kH(a) + kH(b) + kH.one())^2)except:    print("Fail 2")  
  passtry:    print((kH(a) + kH(b) + kH.group().one())^2)except:    
print("Fail 3")    passtry:    print((kH(a) + kH(b) + 
kH(kH.group().one()))^2)except:    print("Fail 4")    pass*

produces the output:

*(5,7,6)(12,18,14)*
*Fail 1*
*Fail 2*
*Fail 3*
*Fail 4*

The thing that's irritating is that using H.one() in the sum is fine; using 
kH.group().one() is not. But I fully admit that I may just not understand 
what the right behavior should be.
On Saturday, August 6, 2022 at 11:40:03 PM UTC-4 trevor...@gmail.com wrote:

> Is the x you give in these examples the same x as above? I’m worried 
> (maybe needlessly) about if the x you give includes a summand of kH.one(). 
> If the x you give does not include a summand of one, then the behavior you 
> described is consistent with what I think the problem is. If the x in the 
> new example doesn’t have a summand of kH.one() then I’m misunderstanding 
> something.
>
> On Sat, Aug 6, 2022 at 6:00 PM keirh...@gmail.com <keirh...@gmail.com> 
> wrote:
>
>> Thanks for this workaround. I was passing the group algebra to a function 
>> and then accessing the base group like so:
>>
>> kH.group()
>>
>> Both of the following cause the coercion error:
>>
>> kH.one() * x
>> kH.group().one() * x
>>
>> But this works fine:
>>
>> H.one()*x
>>
>> I will just have to pass the original group along as well.
>>
>> --Keir
>>
>> On Saturday, August 6, 2022 at 2:06:51 PM UTC-4 trevor...@gmail.com 
>> wrote:
>>
>>> I can reproduce this on 9.7.beta7.
>>>
>>> The problem is that the parent is not understood to be the same (even 
>>> though it clearly is). A workaround is:
>>>
>>> sage: x = kH(a) + kH(b) + kH(H.one()); x
>>>
>>> () + (5,6,7)(12,14,18) + (1,2)(3,4)
>>>
>>> sage: x*x
>>>
>>> (5,7,6)(12,18,14)
>>>
>>>
>>> Here H.one() puts the one in the right parent for the coercion 
>>> framework, but this definitely looks like a bug to me, because
>>>
>>> sage: kH(a).parent()
>>>
>>> Algebra of Permutation Group with generators [(5,6,7)(12,14,18), 
>>> (1,2)(3,4)] over Finite Field of size 2
>>>
>>> sage: kH.one().parent()
>>>
>>> Algebra of Permutation Group with generators [(5,6,7)(12,14,18), 
>>> (1,2)(3,4)] over Finite Field of size 2
>>>
>>> sage: kH(a).parent() is kH.one().parent()
>>>
>>> True
>>>
>>>
>>> Reproducing the bug with messages on 9.7.beta7:
>>>
>>> sage: H = PermutationGroup([[(*1*,*2*), (*3*,*4*)], [(*5*,*6*,*7*),(*12*
>>> ,*14*,*18*)]])
>>>
>>> sage: kH = H.algebra(GF(*2*))
>>>
>>> sage: H.gens()
>>>
>>> ((5,6,7)(12,14,18), (1,2)(3,4))
>>>
>>> sage: a, b = H.gens()
>>>
>>> sage: x = kH(a) + kH(b) + kH.one(); x
>>>
>>> (5,6,7)(12,14,18) + (1,2)(3,4) + ()
>>>
>>> sage: x*x
>>>
>>>
>>> ---------------------------------------------------------------------------
>>>
>>> RuntimeError                              Traceback (most recent call 
>>> last)
>>>
>>> Input In [7], in <cell line: 1>()
>>>
>>> ----> 1 x*x
>>>
>>>
>>> File ~/Applications/sage/src/sage/structure/element.pyx:1514, in 
>>> sage.structure.element.Element.__mul__()
>>>
>>> *   1512* cdef int cl = classify_elements(left, right)
>>>
>>> *   1513* if HAVE_SAME_PARENT(cl):
>>>
>>> -> 1514     return (<Element>left)._mul_(right)
>>>
>>> *   1515* if BOTH_ARE_ELEMENT(cl):
>>>
>>> *   1516*     return coercion_model.bin_op(left, right, mul)
>>>
>>>
>>> File ~/Applications/sage/src/sage/structure/element.pyx:1560, in 
>>> sage.structure.element.Element._mul_()
>>>
>>> *   1558*         raise bin_op_exception('*', self, other)
>>>
>>> *   1559*     else:
>>>
>>> -> 1560         return python_op(other)
>>>
>>> *   1561* 
>>>
>>> *   1562* cdef _mul_long(self, long n):
>>>
>>>
>>> File ~/Applications/sage/src/sage/categories/coercion_methods.pyx:53, in 
>>> sage.categories.coercion_methods._mul_parent()
>>>
>>> *     51*     True
>>>
>>> *     52* """
>>>
>>> ---> 53 return (<Element>self)._parent.product(self, other)
>>>
>>>
>>> File ~/Applications/sage/src/sage/categories/magmatic_algebras.py:215, 
>>> in 
>>> MagmaticAlgebras.WithBasis.ParentMethods._product_from_product_on_basis_multiply(self,
>>>  
>>> left, right)
>>>
>>> *    201* *def* _product_from_product_on_basis_multiply( self, left, 
>>> right ):
>>>
>>> *    202*     r*"""*
>>>
>>> *    203* *    Compute the product of two elements by extending*
>>>
>>> *    204* *    bilinearly the method :meth:`product_on_basis`.*
>>>
>>>    (...)
>>>
>>> *    213* 
>>>
>>> *    214* *    """*
>>>
>>> --> 215     *return* 
>>> self.linear_combination((self.product_on_basis(mon_left, mon_right), 
>>> coeff_left * coeff_right )
>>>
>>> *    216*                                     *for* (mon_left, 
>>> coeff_left) *in* left.monomial_coefficients().items()
>>>
>>> *    217*                                     *for* (mon_right, 
>>> coeff_right) *in* right.monomial_coefficients().items() )
>>>
>>>
>>> File ~/Applications/sage/src/sage/combinat/free_module.py:969, in 
>>> CombinatorialFreeModule.linear_combination(self, iter_of_elements_coeff, 
>>> factor_on_left)
>>>
>>> *    945* *def* linear_combination(self, iter_of_elements_coeff, 
>>> factor_on_left=*True*):
>>>
>>> *    946*     r*"""*
>>>
>>> *    947* *    Return the linear combination `\lambda_1 v_1 + \cdots +*
>>>
>>> *    948* *    \lambda_k v_k` (resp.  the linear combination `v_1 
>>> \lambda_1 +*
>>>
>>>    (...)
>>>
>>> *    967* *        20*B[1] + 20*B[2]*
>>>
>>> *    968* *    """*
>>>
>>> --> 969     *return* 
>>> self._from_dict(blas.linear_combination(((element._monomial_coefficients, 
>>> coeff)
>>>
>>> *    970*                                                     *for* 
>>> element, coeff *in* iter_of_elements_coeff),
>>>
>>> *    971*                                                    
>>> factor_on_left=factor_on_left),
>>>
>>> *    972*                            remove_zeros=*False*)
>>>
>>>
>>> File ~/Applications/sage/src/sage/data_structures/blas_dict.pyx:313, in 
>>> sage.data_structures.blas_dict.linear_combination()
>>>
>>> *    311*     return remove_zeros(result)
>>>
>>> *    312* 
>>>
>>> --> 313 cpdef dict linear_combination(dict_factor_iter, bint 
>>> factor_on_left=True):
>>>
>>> *    314*     r"""
>>>
>>> *    315*     Return the pointwise addition of dictionaries with 
>>> coefficients.
>>>
>>>
>>> File ~/Applications/sage/src/sage/data_structures/blas_dict.pyx:348, in 
>>> sage.data_structures.blas_dict.linear_combination()
>>>
>>> *    346* cdef dict D
>>>
>>> *    347* 
>>>
>>> --> 348 for D, a in dict_factor_iter:
>>>
>>> *    349*     if not a: # We multiply by 0, so nothing to do
>>>
>>> *    350*         continue
>>>
>>>
>>> File ~/Applications/sage/src/sage/combinat/free_module.py:969, in 
>>> <genexpr>(.0)
>>>
>>> *    945* *def* linear_combination(self, iter_of_elements_coeff, 
>>> factor_on_left=*True*):
>>>
>>> *    946*     r*"""*
>>>
>>> *    947* *    Return the linear combination `\lambda_1 v_1 + \cdots +*
>>>
>>> *    948* *    \lambda_k v_k` (resp.  the linear combination `v_1 
>>> \lambda_1 +*
>>>
>>>    (...)
>>>
>>> *    967* *        20*B[1] + 20*B[2]*
>>>
>>> *    968* *    """*
>>>
>>> --> 969     *return* 
>>> self._from_dict(blas.linear_combination(((element._monomial_coefficients, 
>>> coeff)
>>>
>>> *    970*                                                     *for* 
>>> element, coeff *in* iter_of_elements_coeff),
>>>
>>> *    971*                                                    
>>> factor_on_left=factor_on_left),
>>>
>>> *    972*                            remove_zeros=*False*)
>>>
>>>
>>> File ~/Applications/sage/src/sage/categories/magmatic_algebras.py:215, 
>>> in <genexpr>(.0)
>>>
>>> *    201* *def* _product_from_product_on_basis_multiply( self, left, 
>>> right ):
>>>
>>> *    202*     r*"""*
>>>
>>> *    203* *    Compute the product of two elements by extending*
>>>
>>> *    204* *    bilinearly the method :meth:`product_on_basis`.*
>>>
>>>    (...)
>>>
>>> *    213* 
>>>
>>> *    214* *    """*
>>>
>>> --> 215     *return* 
>>> self.linear_combination((self.product_on_basis(mon_left, mon_right), 
>>> coeff_left * coeff_right )
>>>
>>> *    216*                                     *for* (mon_left, 
>>> coeff_left) *in* left.monomial_coefficients().items()
>>>
>>> *    217*                                     *for* (mon_right, 
>>> coeff_right) *in* right.monomial_coefficients().items() )
>>>
>>>
>>> File ~/Applications/sage/src/sage/categories/semigroups.py:957, in 
>>> Semigroups.Algebras.ParentMethods.product_on_basis(self, g1, g2)
>>>
>>> *    939* *def* product_on_basis(self, g1, g2):
>>>
>>> *    940*     r*"""*
>>>
>>> *    941* *    Product, on basis elements, as per*
>>>
>>> *    942* *    
>>> :meth:`MagmaticAlgebras.WithBasis.ParentMethods.product_on_basis()*
>>>
>>>    (...)
>>>
>>> *    955* *        B['ab'] + B['bdc']*
>>>
>>> *    956* *    """*
>>>
>>> --> 957     *return* self.monomial(g1 * g2)
>>>
>>>
>>> File 
>>> ~/Applications/sage/src/sage/groups/perm_gps/permgroup_element.pyx:1295, in 
>>> sage.groups.perm_gps.permgroup_element.PermutationGroupElement.__mul__()
>>>
>>> *   1293*             return prod
>>>
>>> *   1294* 
>>>
>>> -> 1295     return coercion_model.bin_op(left, right, operator.mul)
>>>
>>> *   1296* 
>>>
>>> *   1297* cpdef _mul_(left, _right):
>>>
>>>
>>> File ~/Applications/sage/src/sage/structure/coerce.pyx:1200, in 
>>> sage.structure.coerce.CoercionModel.bin_op()
>>>
>>> *   1198* # Now coerce to a common parent and do the operation there
>>>
>>> *   1199* try:
>>>
>>> -> 1200     xy = self.canonical_coercion(x, y)
>>>
>>> *   1201* except TypeError:
>>>
>>> *   1202*     self._record_exception()
>>>
>>>
>>> File ~/Applications/sage/src/sage/structure/coerce.pyx:1332, in 
>>> sage.structure.coerce.CoercionModel.canonical_coercion()
>>>
>>> *   1330*         if x_elt._parent is y_elt._parent:
>>>
>>> *   1331*             return x_elt,y_elt
>>>
>>> -> 1332     self._coercion_error(x, x_map, x_elt, y, y_map, y_elt)
>>>
>>> *   1333* 
>>>
>>> *   1334* cdef bint x_numeric = isinstance(x, (int, long, float, 
>>> complex))
>>>
>>>
>>> File ~/Applications/sage/src/sage/structure/coerce.pyx:2031, in 
>>> sage.structure.coerce.CoercionModel._coercion_error()
>>>
>>> *   2029*             <class 'str'> 'g'
>>>
>>> *   2030*         """
>>>
>>> -> 2031         raise RuntimeError("""There is a bug in the coercion 
>>> code in Sage.
>>>
>>> *   2032* Both x (=%r) and y (=%r) are supposed to have identical 
>>> parents but they don't.
>>>
>>> *   2033* In fact, x has parent '%s'
>>>
>>>
>>> RuntimeError: There is a bug in the coercion code in Sage.
>>>
>>> Both x (=()) and y (=(5,6,7)(12,14,18)) are supposed to have identical 
>>> parents but they don't.
>>>
>>> In fact, x has parent 'Permutation Group with generators 
>>> [(5,6,7)(12,14,18), (1,2)(3,4)]'
>>>
>>> whereas y has parent 'Permutation Group with generators 
>>> [(5,6,7)(12,14,18), (1,2)(3,4)]'
>>>
>>> Original elements () (parent Permutation Group with generators 
>>> [(5,6,7)(12,14,18), (1,2)(3,4)]) and (5,6,7)(12,14,18) (parent Permutation 
>>> Group with generators [(5,6,7)(12,14,18), (1,2)(3,4)]) and maps
>>>
>>> <class 'NoneType'> None
>>>
>>> <class 'sage.structure.coerce_maps.DefaultConvertMap_unique'> (map 
>>> internal to coercion system -- copy before use)
>>>
>>> Coercion map:
>>>
>>>   From: Permutation Group with generators [(5,6,7)(12,14,18), (1,2)(3,4)]
>>>
>>>   To:   Permutation Group with generators [(5,6,7)(12,14,18), (1,2)(3,4)]
>>> On Friday, August 5, 2022 at 4:21:09 PM UTC-7 keirh...@gmail.com wrote:
>>>
>>>> The Sage version I was using is 9.6.
>>>>
>>>> On Friday, August 5, 2022 at 7:19:48 PM UTC-4 keirh...@gmail.com wrote:
>>>>
>>>>> When I do this:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> *H = PermutationGroup([ [(1,2), (3,4)], [(5,6,7),(12,14,18)] ])kH = 
>>>>> H.algebra(GF(2))[a, b] = H.gens()x = kH(a) + kH(b) + kH.one(); 
>>>>> print(x)x*x*
>>>>>
>>>>> I get an error caused by the last computation: "RuntimeError: There is 
>>>>> a bug in the coercion code in Sage." (I was working in Cocalc, but you 
>>>>> can 
>>>>> cut and paste the code above into a SageMathCell and reproduce the error.)
>>>>>
>>>>> Is this really a bug, or should I be doing this differently? (I found 
>>>>> the problem working with a larger group, but this simpler example above 
>>>>> has 
>>>>> the same issue.)
>>>>>
>>>>> Thanks --
>>>>>
>>>>> Keir
>>>>>
>>>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "sage-support" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/sage-support/WVMuik1TICg/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> sage-support...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sage-support/d7fbbb32-5ea3-45d8-8ca6-6c5da0088bban%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/sage-support/d7fbbb32-5ea3-45d8-8ca6-6c5da0088bban%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> -- 
> Best,
>
> Trevor
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/780e2cc2-7126-4f78-850d-cffb7e555470n%40googlegroups.com.

Reply via email to