# Norm in UniversalCyclotomicField

Hi,

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 ?

edit retag close merge delete

Maybe using

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


to make your own norm method for vectors ?

( 2018-12-11 02:48:49 -0600 )edit

Sort by » oldest newest most voted

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
1.414213562373095?
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
1.41421356237310
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
2
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
2
sage: nna.parent()
Algebraic Real Field
sage: na = sqrt(nna)
sage: na
1.414213562373095?
sage: na.parent()
Algebraic Real Field

more

The fix is merged in Sage 8.6.beta0.

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

## Stats

Seen: 23 times

Last updated: Dec 11 '18