Ask Your Question

Norm in UniversalCyclotomicField

asked 2018-12-10 10:22:04 -0600

Assombrance gravatar image

updated 2018-12-11 16:10:15 -0600

tmonteil gravatar image


I'm trying to work with vectors in the UniversalCyclotomicField, But I can't find a way to make the norm work. I'm writing the following code :

sage: a = vector([E(8)])
sage: a.norm()

TypeError                                 Traceback (most recent call last)
<ipython-input-2-5b5ddb3f4c99> in <module>()
----> 1 a.norm()

/home/[name]/SageMath/local/lib/python2.7/site-packages/sage/modules/free_module_element.pyx in sage.modules.free_module_element.FreeModuleElement.norm (build/cythonized/sage/modules/free_module_element.c:12840)()
   1671             sqrt(5)
   1672         """
-> 1673         abs_self = [abs(x) for x in self]
   1674         if p == Infinity:
   1675             return max(abs_self)

TypeError: bad operand type for abs(): 'UniversalCyclotomicField_with_category.element_class'

And having no luck with it. Does any of you know a workaround allowing me to stay in exact calculations ?

Thanks in advance

edit retag flag offensive close merge delete


Maybe using

sage: E(8)*E(8).conjugate()

to make your own norm method for vectors ?

FrédéricC gravatar imageFrédéricC ( 2018-12-11 02:48:49 -0600 )edit

1 answer

Sort by » oldest newest most voted

answered 2018-12-11 02:44:32 -0600

slelievre gravatar image

Thank you for your report, this is indeed a bug. Now tracked at

As a workaround,

  • one could convert a to a vector over the field of algebraic numbers; then the norm is given as an exact algebraic number:

    sage: a = vector([E(8), E(7)])
    sage: b = a.change_ring(QQbar)
    sage: bn = b.norm()
    sage: bn
    sage: bn.parent()
    Algebraic Real Field
  • one could convert a to a vector over a cyclotomic field (not the universal one); sadly the norm is then given as an inexact (floating-point) number:

    sage: a = vector([E(8), E(7)])
    sage: c = a.apply_map(lambda x: x.to_cyclotomic_field())
    sage: cn = c.norm()
    sage: cn
    sage: cn.parent()
    Real Field with 53 bits of precision
  • the square of the norm of the vector a can be obtained directly as a * a.conjugate(), but one then gets it as an element in the universal cyclotomic field, and a similar bug prevents from taking the square root of that directly:

    sage: a = vector([E(8), E(7)])
    sage: ann = a * a.conjugate()
    sage: ann
    sage: ann.parent()
    Universal Cyclotomic Field
    sage: an = sqrt(ann)
    Traceback (most recent call last)
    NotImplementedError: is_square() not implemented for elements of Universal Cyclotomic Field

    and one again has to go through a cyclotomic field other than the universal one, or the field of real algebraic numbers:

    sage: nna = AA(a*a.conjugate())
    sage: nna
    sage: nna.parent()
    Algebraic Real Field
    sage: na = sqrt(nna)
    sage: na
    sage: na.parent()
    Algebraic Real Field
edit flag offensive delete link more


The fix is merged in Sage 8.6.beta0.

slelievre gravatar imageslelievre ( 2018-12-28 03:27:30 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-12-10 10:22:04 -0600

Seen: 23 times

Last updated: Dec 11 '18