Skip to content

Fix multiplication of number field element * ZZ-vector by handling latex names of number field generators #30360

@kliem

Description

@kliem
sage: 1/2*vector([1,2,3])
(1/2, 1, 3/2)
sage: AA(2).sqrt()*vector([1,2,3])                                                                                                                                                                                                                                                                                                                                         
(1.414213562373095?, 2.828427124746190?, 4.242640687119285?)
sage: K.<sqrt5> = QuadraticField(5, embedding=AA(5).sqrt())                                                                                                                                                                                                                                                                                                                
sage: sqrt5*vector([1,2])                                                                                                                                                                                                                                                                                                                                                  
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-65-1ac790b433d6> in <module>
----> 1 sqrt5*vector([Integer(1),Integer(2)])

~/Applications/sage/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__mul__ (build/cythonized/sage/structure/element.c:12196)()
   1513             return (<Element>left)._mul_(right)
   1514         if BOTH_ARE_ELEMENT(cl):
-> 1515             return coercion_model.bin_op(left, right, mul)
   1516 
   1517         cdef long value

~/Applications/sage/local/lib/python3.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:11304)()
   1246         # We should really include the underlying error.
   1247         # This causes so much headache.
-> 1248         raise bin_op_exception(op, x, y)
   1249 
   1250     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for *: 'Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?' and 'Ambient free module of rank 2 over the principal ideal domain Integer Ring'

It doesn't matter whether you specify the embedding or not.

Depends on #30372

CC: @videlec @tscrim

Component: coercion

Keywords: action, scalar, free module

Author: Matthias Koeppe, Francis Clarke

Branch/Commit: a3c790f

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/30360

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions