sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.39k stars 472 forks source link

Implement algebraic closures of finite fields #14990

Closed pjbruin closed 10 years ago

pjbruin commented 11 years ago

The goal of this ticket is a basic implementation of algebraic closures of finite fields. Most importantly, it provides the following:

An example using the new functionality is the following analogue of the example from #8335:

sage: Fbar = GF(3).algebraic_closure('z')
sage: Fbar
Algebraic closure of Finite Field of size 3
sage: F2, e2 = Fbar.subfield(2)
sage: F3, e3 = Fbar.subfield(3)
sage: F2
Finite Field in z2 of size 3^2

To add, we first embed into Fbar:

sage: x2 = e2(F2.gen())
sage: x3 = e3(F3.gen())
sage: x = x2 + x3
sage: x
z6^5 + 2*z6^4 + 2*z6^3 + z6^2 + 2*z6 + 1
sage: x.parent() is Fbar
True

One can also do this without explicitly invoking the embeddings; as a shortcut, Fbar has a method gen(n) returning the fixed generator of the subfield of degree n, but as an element of Fbar:

sage: x2 == Fbar.gen(2)
True
sage: x == Fbar.gen(2) + Fbar.gen(3)
True

It is conceivable that there will be different coexisting implementations (deriving from AlgebraicClosureFiniteField_generic). The current implementation uses Conway polynomials and the pseudo-Conway polynomials from #14958, as well as the functionality for finite field homomorphisms provided by #13214.

Depends on #14958 Depends on #13214

CC: @roed314 @jpflori @sagetrac-JCooley @sagetrac-dfesti @defeo @videlec @sagetrac-erousseau

Component: algebra

Keywords: finite field algebraic closure

Author: Peter Bruin

Branch: b0e1539

Reviewer: Vincent Delecroix

Issue created by migration from https://trac.sagemath.org/ticket/14990

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 10 years ago

Changed commit from fdd8837 to b1d4424

videlec commented 10 years ago
comment:85

Dear Peter,

I like very much the documentation in algebraic_closure. Thank you.

For each problem below, I think we need to find a solution which might be: either write specifications in the documentation or provide a fix that change the behaviour.

1) Equality among algebraic closures is not constant over time:

sage: F1 = AlgebraicClosureFiniteField(GF(3), 'z', use_database=False)
sage: F2 = AlgebraicClosureFiniteField(GF(3), 'z', use_database=False)
sage: F1 == F2
True
sage: F1.gen(3)
z3
sage: F1 == F2
False
sage: F2.gen(3)
z3
sage: F1 == F2
True

It becomes really weird when we play with pickling

sage: p = 100003
sage: K = GF(p).algebraic_closure()
sage: K2 = loads(dumps(K))
sage: K.gen(3)
z3
sage: K == K2
False

One fix is to use identity in comparisons of the parent themselves as I suggested in previous comments. The only drawback I see is that K == loads(dumps(K)) will be False. I think it would be safer that way.

2) Get a very strange error from conversions between different algebraic closures that can be fixed introducing more type checking in the methods.

sage: from sage.rings.algebraic_closure_finite_field import AlgebraicClosureFiniteField
sage: F1 = AlgebraicClosureFiniteField(GF(3), 'z')
sage: F2 = AlgebraicClosureFiniteField(GF(3), 'z')
sage: F1(F2.gen(1))
Traceback (most recent call last):
...
TypeError: no canonical coercion from Algebraic closure of Finite Field of size 3 to Finite Field of size 3

3) (minor) The cache in algebraic_closure does not take into account the default arguments.

sage: K1 = GF(5).algebraic_closure(implementation='pseudo_conway', use_database=True)
sage: K2 = GF(5).algebraic_closure(implementation='pseudo_conway')
sage: K4 = GF(5).algebraic_closure()
sage: K1 is K2 or K1 is K3 or K2 is K3
False

One fix is to move the cache at the level of AlgebraicClosureFiniteField, but on the other hand it is good to have the cache at a Cython level.

That's all Vincent

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 10 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

4ac10fbTrac 14990: compare pseudo-Conway algebraic closures by ID
63bc7aaTrac 14990: more informative error message in _element_constructor_()
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 10 years ago

Changed commit from b1d4424 to 63bc7aa

pjbruin commented 10 years ago
comment:87

Thanks for your feedback, Vincent! The two new commits should address your points (1) and (2), respectively. As for (3), I thought about moving the cache to AlgebraicClosureFiniteField, but then we would have to be very careful with weak references to make sure we don't store every algebraic closure forever. Another (ugly) solution would be to duplicate the same default arguments everywhere. I think it is not really worth the trouble, especially because the following does work:

sage: GF(5).algebraic_closure('z') is GF(5).algebraic_closure()
True

I expect it is much more likely that users switch between specifying the 'z' or not than that they switch between specifying keyword arguments or not.

videlec commented 10 years ago
comment:88

Hi Peter,

I agree with your analysis of (3).

All test pass and the documentation builds.

There is a typo which becomes ugly in the compiled documentation. At line 960 of algebraic_closure_finite_field.py you wrote `:meth:~sage.rings.finite_rings.finite_field_base.FiniteField.algebraic_closure` instead of :meth:`~sage.rings.finite_rings.finite_field_base.FiniteField.algebraic_closure`.

Once the change done, you can set to positive review.

Vincent

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 10 years ago

Changed commit from 63bc7aa to b0e1539

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 10 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

b0e1539Trac 14990: fix typo in documentation
pjbruin commented 10 years ago

Reviewer: Vincent Delecroix

pjbruin commented 10 years ago
comment:90

Done. Thanks a lot for your thorough review!

vbraun commented 10 years ago

Changed branch from u/pbruin/14990 to b0e1539

slel commented 10 years ago

Changed commit from b0e1539 to none

slel commented 10 years ago
comment:92

Some change introduced by this ticket is being discussed in this sage-devel thread.

zimmermann6 commented 6 years ago
comment:93

for information, Pari/GP 2.10 implements finite field embeddings. See http://pari.math.u-bordeaux.fr/Events/PARI2018/talks/features.pdf

defeo commented 6 years ago
comment:94

Flint will soon have them too. See https://github.com/wbhart/flint2/pull/351.

Are the embeddings in PARI/GP compatible?

videlec commented 6 years ago
comment:95

Would be nice to have both of them interfaced in Sage together with the version that is already there!

defeo commented 6 years ago
comment:96

Replying to @videlec:

Would be nice to have both of them interfaced in Sage together with the version that is already there!

That's part of our plans. Not immediately, though.