Ask Your Question
1

Norm in UniversalCyclotomicField

asked 2018-12-10 17:22:04 +0100

Assombrance gravatar image

updated 2023-01-09 23:59:48 +0100

tmonteil gravatar image

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 ?

Thanks in advance

edit retag flag offensive close merge delete

Comments

Maybe using

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

to make your own norm method for vectors ?

FrédéricC gravatar imageFrédéricC ( 2018-12-11 09:48:49 +0100 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2018-12-11 09:44:32 +0100

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
    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
    
edit flag offensive delete link more

Comments

The fix is merged in Sage 8.6.beta0.

slelievre gravatar imageslelievre ( 2018-12-28 10:27:30 +0100 )edit
0

answered 2019-02-01 13:53:39 +0100

Assombrance gravatar image

Hi again, this bug was marked as fixed in version 8.6, but I still encounter it in this same version :

Forcing sage-location, probably because a new package was installed.
Cleaning up, do not interrupt this.
Done cleaning.
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.6, Release Date: 2019-01-15                     │
│ Using Python 2.7.15. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: a = vector([E(8)])
sage: a.norm()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-5b5ddb3f4c99> in <module>()
----> 1 a.norm()

/home/henri/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:12190)()
   1672             sqrt(5)
   1673         """
-> 1674         abs_self = [abs(x) for x in self]
   1675         if p == Infinity:
   1676             return max(abs_self)

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

Am I doing something wrong ?

edit flag offensive delete link more

Comments

Sorry, there was a mistake in the fix. The method should have been called __abs__ for it to fix the problem, but there was an oversight and the missing method was introduced under the name abs.

I opened a follow-up ticket at

to give it the proper name.

slelievre gravatar imageslelievre ( 2019-02-01 23:52:49 +0100 )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

Stats

Asked: 2018-12-10 17:22:04 +0100

Seen: 688 times

Last updated: Feb 01 '19