Opened 11 years ago

Closed 3 years ago

#7589 closed defect (fixed)

bug in coercion and cyclotomic fields

Reported by: AlexGhitza Owned by: robertwb
Priority: major Milestone: sage-8.3
Component: coercion Keywords: coercion, cyclotomic, coxeter
Cc: vripoll, stumpc5, tscrim Merged in:
Authors: Frédéric Chapoton Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 0a00b44 (Commits, GitHub, GitLab) Commit: 0a00b44d43002eaf650a418b516a838cb32f334f
Dependencies: Stopgaps:

Status badges

Description

This should work automagically:

----------------------------------------------------------------------
| Sage Version 4.2.1, Release Date: 2009-11-14                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: a = CyclotomicField(3).random_element()
sage: b = CyclotomicField(4).random_element()
sage: a + b
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/ghitza/.sage/temp/artin/9098/_home_ghitza__sage_init_sage_0.py in <module>()

/home/ghitza/sage-devel/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.ModuleElement.__add__ (sage/structure/element.c:6989)()

/home/ghitza/sage-devel/local/lib/python2.6/site-packages/sage/structure/coerce.so in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:7021)()

TypeError: unsupported operand parent(s) for '+': 'Cyclotomic Field of order 3 and degree 2' and 'Cyclotomic Field of order 4 and degree 2'
sage: a * b
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/ghitza/.sage/temp/artin/9098/_home_ghitza__sage_init_sage_0.py in <module>()

/home/ghitza/sage-devel/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.RingElement.__mul__ (sage/structure/element.c:10248)()

/home/ghitza/sage-devel/local/lib/python2.6/site-packages/sage/structure/coerce.so in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:7021)()

TypeError: unsupported operand parent(s) for '*': 'Cyclotomic Field of order 3 and degree 2' and 'Cyclotomic Field of order 4 and degree 2'

I think it's a coercion problem. If someone knows better, please change the trac component accordingly.

Change History (13)

comment:1 Changed 8 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:2 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:3 Changed 7 years ago by vripoll

Has anyone looked at this ticket? I ran into this today and discover that the issue has been reported 4 years ago... This bug is particularly confusing for the user, especially when you read the doc that says "Due to their default embedding into CC, cyclotomic number fields are all compatible", and goes on to show the following example:

      sage: cf30 = CyclotomicField(30)
      sage: cf5 = CyclotomicField(5)
      sage: cf3 = CyclotomicField(3)
      sage: cf30.gen() + cf5.gen() + cf3.gen()
      zeta30^6 + zeta30^5 + zeta30 - 1

It turns out Sage is able to compute that only because the first field contains the next two! Note the following test:

      ┌────────────────────────────────────────────────────────────────────┐
      │ Sage Version 6.2.beta7, Release Date: 2014-04-08                   │
      │ Type "notebook()" for the browser-based notebook interface.        │
      │ Type "help()" for help.                                            │
      └────────────────────────────────────────────────────────────────────┘
      sage: cf15=CyclotomicField(15)
      sage: cf5=CyclotomicField(5)
      sage: cf3=CyclotomicField(3)
      
      sage: cf15.gen()+cf5.gen()+cf3.gen()
      zeta15^5 + zeta15^3 + zeta15
      
      sage: cf5.gen()+cf3.gen()+cf15.gen()
      Traceback (most recent call last)
      ...
      TypeError: unsupported operand parent(s) for '+': 'Cyclotomic Field of order 5 and degree 4'   and 'Cyclotomic Field of order 3 and degree 2'
      
      sage: cf5.gen()+cf3.gen()
      Traceback (most recent call last)
      ...
      TypeError: unsupported operand parent(s) for '+': 'Cyclotomic Field of order 5 and degree 4' and 'Cyclotomic Field of order 3 and degree 2'
      
      sage: 0*cf15.gen()+cf5.gen()+cf3.gen()
      zeta15^5 + zeta15^3

comment:4 Changed 7 years ago by vripoll

  • Keywords coercion cyclotomic added

comment:5 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:6 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:7 Changed 6 years ago by vripoll

  • Cc vripoll added

comment:8 Changed 5 years ago by vdelecroix

  • Milestone changed from sage-6.4 to sage-7.4

see also the somehow related #20746

comment:9 Changed 3 years ago by chapoton

  • Authors set to Frédéric Chapoton
  • Branch set to u/chapoton/7589
  • Cc stumpc5 added
  • Commit set to 0a00b44d43002eaf650a418b516a838cb32f334f
  • Keywords coxeter added
  • Milestone changed from sage-7.4 to sage-8.3
  • Status changed from new to needs_review

first tentative, let us see what patchbot says


New commits:

0a00b44pushout for cyclotomic fields

comment:10 Changed 3 years ago by vdelecroix

You should take care of embeddings. The map add: CF(p) x CF(q) -> CF(lcm(p,q)) is not uniquely defined.

comment:11 Changed 3 years ago by chapoton

  • Cc tscrim added

Well. What we just add here is the information that we need to go through CF(lcm). No responsability is taken on the existence of a canonical coercion from CF(p) to CF(lcm). I guess that this already an existing thing..

comment:12 Changed 3 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

As Frederic said, this does not change the (canonical) coercions between cyclotomic fields but allows the analogous computation to

sage: R.<x,y> = ZZ[]
sage: S.<y> = QQ[]
sage: R.an_element() + S.an_element()
x + y
sage: _.parent()
Multivariate Polynomial Ring in x, y over Rational Field

comment:13 Changed 3 years ago by vbraun

  • Branch changed from u/chapoton/7589 to 0a00b44d43002eaf650a418b516a838cb32f334f
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.