Opened 13 years ago

Last modified 3 months ago

#4621 needs_info defect

Fix membership in QQbar for number field elements -- canonical embedding of subfields

Reported by: SimonKing Owned by: tbd
Priority: major Milestone: sage-9.5
Component: algebra Keywords: canonical embedding subfield
Cc: gh-kliem, slelievre Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by slelievre)

Reported by Alex Raichev on sage-support.

sage: F.<a> = NumberField(x^2 - 2)
sage: a^2
2
sage: a^2 in QQ
True
sage: a^2 in QQbar
False
sage: 2 in QQbar
True 

or more directly

sage: F(2) in QQbar
False

Perhaps related to this is

sage: F.<a> = NumberField(x^2 - 2)
sage: QQ.is_subring(F)
True
sage: F.is_subring(QQbar)
False 

Robert Bradshow comments that F.is_subring(QQbar) should be False, because QQbar has a canonical embedding into CC, but F has not.

So, from that point of view, it makes sense that a^2 is in F but not in QQbar. However, a^2 is equal to 2 after all, and hence is in a part of F that does have a canonical embedding.

In other words, we have a field element x in F_1 such that there is in fact a subfield F_2 of F_1 with x in F_1. Moreover, we have a field F_3 such that F_2 has a canonical embedding into F_3, but F_1 has no canonical embedding.

Is it possible for Sage to detect that situation?

Idea: Is there a unique maximal subfield F_m of F_1 that has a canonical embedding into F_3? If there is, there could be a method max_subfield_coercing_into(...).

Then, in the original example, we probably have

sage: F.max_subfield_coercing_into(QQbar)
Rational Field

and then x in QQbar would answer True, since

sage: x in F_1.max_subfield_coercing_into(QQbar)
True

Sorry if that idea is not realistic.

Attachments (1)

4621-qqbar-embed.patch (1.1 KB) - added by robertwb 12 years ago.

Download all attachments as: .zip

Change History (24)

Changed 12 years ago by robertwb

comment:1 Changed 12 years ago by robertwb

  • Report Upstream set to N/A

This issue is fixed. Followup about embedding into QQbar at #7960.

comment:2 Changed 12 years ago by robertwb

  • Status changed from new to needs_review

comment:3 Changed 12 years ago by wjp

  • Status changed from needs_review to needs_info

A side effect of this patch is the following because it now tries to explicitly convert its argument to QQ. Is that desirable?

sage: GF(7)(2) in QQbar
True

(Related 'in's:

sage: GF(7)(2) in ZZ
True
sage: GF(7)(2) in QQ
False
sage: GF(7)(2) in QQbar
True

)

comment:4 Changed 12 years ago by robertwb

This exposes a separate but that == for QQbar is not symetric...

sage: GF(7)(2) == QQbar(2)
False
sage: QQbar(2) == GF(7)(2)
True # after the patch, BOOM before, should be False

comment:5 Changed 12 years ago by robertwb

  • Status changed from needs_info to needs_review

See #7984 for a fix for QQbar cmp.

comment:6 Changed 12 years ago by robertwb

  • Status changed from needs_review to needs_info

For this to return True, one would have to change the definition of canonical comparison--not something that should be done lightly.

comment:7 Changed 10 years ago by mhansen

Just a note -- this patch no longer works with #7984.

comment:8 Changed 8 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:9 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:10 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:11 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:12 follow-up: Changed 7 years ago by vdelecroix

The reason why this fails is

sage: F.<a>= NumberField(x^2-2)
sage: two = F(2)
sage: QQbar(two)
Traceback (most recent call last):
...
TypeError: Illegal initializer for algebraic number

One way to fix it is to be more flexible on creation of algebraic number (in AA._element_constructor_ or QQbar._element_constructor_) or to implement a method _algebraic_ to number field elements.

Vincent

comment:13 in reply to: ↑ 12 Changed 5 years ago by vdelecroix

Replying to vdelecroix:

The reason why this fails is

sage: F.<a>= NumberField(x^2-2)
sage: two = F(2)
sage: QQbar(two)
Traceback (most recent call last):
...
TypeError: Illegal initializer for algebraic number

One way to fix it is to be more flexible on creation of algebraic number (in AA._element_constructor_ or QQbar._element_constructor_) or to implement a method _algebraic_ to number field elements.

the above is fixed in #14485 and #20400 but it does not solve the containment test!

comment:14 Changed 15 months ago by mkoeppe

  • Cc gh-kliem added
  • Milestone changed from sage-6.4 to sage-9.2

comment:15 Changed 12 months ago by mkoeppe

  • Milestone changed from sage-9.2 to sage-9.3

comment:16 follow-up: Changed 7 months ago by slelievre

  • Cc slelievre added
  • Description modified (diff)
  • Summary changed from '2' not in QQbar -- canonical embedding of subfields to Fix membership in QQbar for number field elements -- canonical embedding of subfields

To put it another way.

In Sage 9.3.rc0:

sage: root2 = QuadraticField(2).gen()
sage: root2 in QQbar, root2^2 in QQbar  # expected: (True, True)
(False, False)

comment:17 in reply to: ↑ 16 Changed 7 months ago by vdelecroix

Replying to slelievre:

To put it another way.

In Sage 9.3.rc0:

sage: root2 = QuadraticField(2).gen()
sage: root2 in QQbar, root2^2 in QQbar  # expected: (True, True)
(False, False)

The embedding is not set by writing only QuadraticField(2) (see also #30518 comment:10). You can compare with

sage: root2 = QuadraticField(2, embedding=AA(2).sqrt()).gen()
sage: root2 in QQbar, root2^2 in QQbar
(True, True)

Though the following is definitely annoying

sage: QuadraticField(2).one() in QQbar  # would better be true
False

comment:18 Changed 7 months ago by vdelecroix

Note that it will quickly become annoying with extensions

sage: K.<a> = QuadraticField(2, embedding=AA(2).sqrt())
sage: x = polygen(ZZ)
sage: L.<b> = K.extension(x**3 - x**2 - x - 1) 
  • Do you expect QQbar(L(a)) to work?
  • What should be the result of L(a) in QQbar?

comment:19 Changed 7 months ago by vdelecroix

Note also that 1 == 1 does not hold in the following situation

sage: QuadraticField(2).one() == QuadraticField(3).one()
True

Again, with properly set embeddings it compares as a user might expect

sage: K2 = QuadraticField(2, embedding=AA(2).sqrt())
sage: K3 = QuadraticField(3, embedding=AA(3).sqrt())
sage: K2.one() == K3.one()
True

comment:20 Changed 7 months ago by vdelecroix

The only way I can imagine a fix would be to implement intersection of parents as part of the coercion model. It would have at least the following requirements

  • C = A.intersection(B) is a parent with injective coercions in both A and B
  • A.intersection(B) is identical to B.intersection(A)

Given that, we could design a more reasonable sage.structure.element.Element.__richcmp__.

comment:21 Changed 7 months ago by slelievre

Thanks for launching a discussion on sage-devel:

comment:22 Changed 7 months ago by mkoeppe

  • Milestone changed from sage-9.3 to sage-9.4

Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review.

comment:23 Changed 3 months ago by mkoeppe

  • Milestone changed from sage-9.4 to sage-9.5

Setting a new milestone for this ticket based on a cursory review.

Note: See TracTickets for help on using tickets.