Skip to content

Commit 76671e9

Browse files
committed
Enhance documentation of algebraic closure
- make it agnostic to the encapsulating documentation (Nemo or Oscar) - collapse docstrings to make it not stand out in the Oscar documentation - make all docstrings self contained (with collapsed docstrings this should be fine)
1 parent fcfa3d0 commit 76671e9

File tree

1 file changed

+76
-56
lines changed

1 file changed

+76
-56
lines changed

docs/src/algebraic.md

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,27 @@
11
```@meta
22
CurrentModule = Nemo
3+
CollapsedDocStrings = true
34
DocTestSetup = quote
45
using Nemo
56
end
67
```
78

8-
# Algebraic numbers
9+
# Algebraic closure of the rational numbers
910

10-
Nemo allows working with exact real and complex algebraic numbers.
11+
An implementation of the field of all algebraic numbers, that is, an algebraic closure of the field of rational numbers, is provided through the type `QQBarField` and the corresponding element type `QQBarFieldElem`.
1112

12-
The default algebraic number type in Nemo is provided by Calcium. The
13-
associated field of algebraic numbers can be constructed using
14-
`QQBar = algebraic_closure(QQ)`. We will leave out this line from
15-
all code blocks on this page for brevity.
13+
Note that the field of algebraic closure is implemented as an ordered field,
14+
see [Comparing algebraic numbers]
1615

17-
Library | Element type | Parent type
18-
----------------|------------------|--------------------
19-
Calcium | `QQBarFieldElem` | `QQBarField`
16+
## Constructing the field of algebraic numbers
2017

21-
**Important note on performance**
22-
23-
The default algebraic number type represents algebraic numbers
24-
in canonical form using minimal polynomials. This works well for representing
25-
individual algebraic numbers, but it does not provide the best
26-
performance for field arithmetic.
27-
For fast calculation in $\overline{\mathbb{Q}}$,
28-
`CalciumField` should typically be used instead (see the section
29-
on *Exact real and complex numbers*).
30-
Alternatively, to compute in a fixed subfield of $\overline{\mathbb{Q}}$,
31-
you may fix a generator $a$ and construct a number field to represent $\mathbb{Q}(a)$.
18+
```jldoctest
19+
julia> algebraic_closure(QQ)
20+
Algebraic closure of rational field
21+
```
3222

3323
## Algebraic number functionality
3424

35-
### Constructing algebraic numbers
36-
3725
Methods to construct algebraic numbers include:
3826

3927
* Conversion from other numbers and through arithmetic operations
@@ -47,24 +35,28 @@ Methods to construct algebraic numbers include:
4735

4836
Arithmetic:
4937

50-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
51-
julia> ZZRingElem(QQBar(3))
38+
```jldoctest
39+
julia> Qb = algebraic_closure(QQ);
40+
41+
julia> ZZRingElem(Qb(3))
5242
3
5343
54-
julia> QQFieldElem(QQBar(3) // 2)
44+
julia> QQFieldElem(Qb(3) // 2)
5545
3//2
5646
57-
julia> QQBar(-1) ^ (QQBar(1) // 3)
47+
julia> Qb(-1) ^ (Qb(1) // 3)
5848
Root 0.500000 + 0.866025*im of x^2 - x + 1
5949
```
6050

6151
Solving the quintic equation:
6252

63-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
53+
```jldoctest
54+
julia> Qb = algebraic_closure(QQ);
55+
6456
julia> R, x = polynomial_ring(QQ, "x")
6557
(Univariate polynomial ring in x over QQ, x)
6658
67-
julia> v = roots(QQBar, x^5-x-1)
59+
julia> v = roots(Qb, x^5-x-1)
6860
5-element Vector{QQBarFieldElem}:
6961
Root 1.16730 of x^5 - x - 1
7062
Root 0.181232 + 1.08395*im of x^5 - x - 1
@@ -78,8 +70,10 @@ true
7870

7971
Computing exact eigenvalues of a matrix:
8072

81-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
82-
julia> eigenvalues(QQBar, ZZ[1 1 0; 0 1 1; 1 0 1])
73+
```jldoctest
74+
julia> Qb = algebraic_closure(QQ);
75+
76+
julia> eigenvalues(Qb, ZZ[1 1 0; 0 1 1; 1 0 1])
8377
3-element Vector{QQBarFieldElem}:
8478
Root 2.00000 of x - 2
8579
Root 0.500000 + 0.866025*im of x^2 - x + 1
@@ -106,11 +100,13 @@ Algebraic numbers can be evaluated
106100
numerically to arbitrary precision by converting
107101
to real or complex Arb fields:
108102

109-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
110-
julia> RR = ArbField(64); RR(sqrt(QQBar(2)))
103+
```jldoctest
104+
julia> Qb = algebraic_closure(QQ);
105+
106+
julia> RR = ArbField(64); RR(sqrt(Qb(2)))
111107
[1.414213562373095049 +/- 3.45e-19]
112108
113-
julia> CC = AcbField(32); CC(QQBar(-1) ^ (QQBar(1) // 4))
109+
julia> CC = AcbField(32); CC(Qb(-1) ^ (Qb(1) // 4))
114110
[0.707106781 +/- 2.74e-10] + [0.707106781 +/- 2.74e-10]*im
115111
```
116112

@@ -121,11 +117,13 @@ julia> CC = AcbField(32); CC(QQBar(-1) ^ (QQBar(1) // 4))
121117
Retrieving the minimal polynomial and algebraic conjugates
122118
of a given algebraic number:
123119

124-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
125-
julia> minpoly(polynomial_ring(ZZ, "x")[1], QQBar(1+2im))
120+
```jldoctest
121+
julia> Qb = algebraic_closure(QQ);
122+
123+
julia> minpoly(polynomial_ring(ZZ, "x")[1], Qb(1+2im))
126124
x^2 - 2*x + 5
127125
128-
julia> conjugates(QQBar(1+2im))
126+
julia> conjugates(Qb(1+2im))
129127
2-element Vector{QQBarFieldElem}:
130128
Root 1.00000 + 2.00000*im of x^2 - 2x + 5
131129
Root 1.00000 - 2.00000*im of x^2 - 2x + 5
@@ -154,17 +152,19 @@ height_bits(x::QQBarFieldElem)
154152

155153
**Examples**
156154

157-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
158-
julia> real(sqrt(QQBar(1im)))
155+
```jldoctest
156+
julia> Qb = algebraic_closure(QQ);
157+
158+
julia> real(sqrt(Qb(1im)))
159159
Root 0.707107 of 2x^2 - 1
160160
161-
julia> abs(sqrt(QQBar(1im)))
161+
julia> abs(sqrt(Qb(1im)))
162162
Root 1.00000 of x - 1
163163
164-
julia> floor(sqrt(QQBar(1000)))
164+
julia> floor(sqrt(Qb(1000)))
165165
Root 31.0000 of x - 31
166166
167-
julia> sign(QQBar(-10-20im))
167+
julia> sign(Qb(-10-20im))
168168
Root -0.447214 - 0.894427*im of 5x^4 + 6x^2 + 5
169169
```
170170

@@ -212,11 +212,13 @@ first.
212212

213213
**Examples**
214214

215-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
216-
julia> 1 < sqrt(QQBar(2)) < QQBar(3)//2
215+
```jldoctest
216+
julia> Qb = algebraic_closure(QQ);
217+
218+
julia> 1 < sqrt(Qb(2)) < Qb(3)//2
217219
true
218220
219-
julia> x = QQBar(3+4im)
221+
julia> x = Qb(3+4im)
220222
Root 3.00000 + 4.00000*im of x^2 - 6x + 25
221223
222224
julia> is_equal_abs(x, -x)
@@ -249,23 +251,25 @@ is_less_root_order(a::QQBarFieldElem, b::QQBarFieldElem)
249251

250252
**Examples**
251253

252-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
253-
julia> root(QQBar(2), 5)
254+
```jldoctest
255+
julia> Qb = algebraic_closure(QQ);
256+
257+
julia> root(Qb(2), 5)
254258
Root 1.14870 of x^5 - 2
255259
256-
julia> sinpi(QQBar(7) // 13)
260+
julia> sinpi(Qb(7) // 13)
257261
Root 0.992709 of 4096x^12 - 13312x^10 + 16640x^8 - 9984x^6 + 2912x^4 - 364x^2 + 13
258262
259-
julia> tanpi(atanpi(sqrt(QQBar(2)) + 1))
263+
julia> tanpi(atanpi(sqrt(Qb(2)) + 1))
260264
Root 2.41421 of x^2 - 2x - 1
261265
262-
julia> root_of_unity(QQBar, 5)
266+
julia> root_of_unity(Qb, 5)
263267
Root 0.309017 + 0.951057*im of x^4 + x^3 + x^2 + x + 1
264268
265-
julia> root_of_unity(QQBar, 5, 4)
269+
julia> root_of_unity(Qb, 5, 4)
266270
Root 0.309017 - 0.951057*im of x^4 + x^3 + x^2 + x + 1
267271
268-
julia> w = (1 - sqrt(QQBar(-3)))//2
272+
julia> w = (1 - sqrt(Qb(-3)))//2
269273
Root 0.500000 - 0.866025*im of x^2 - x + 1
270274
271275
julia> is_root_of_unity(w)
@@ -304,8 +308,10 @@ atanpi(a::QQBarFieldElem)
304308

305309
An algebraic number can be recovered from a numerical value:
306310

307-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
308-
julia> RR = RealField(); guess(QQBar, RR("1.41421356 +/- 1e-6"), 2)
311+
```jldoctest
312+
julia> Qb = algebraic_closure(QQ);
313+
314+
julia> RR = RealField(); guess(Qb, RR("1.41421356 +/- 1e-6"), 2)
309315
Root 1.41421 of x^2 - 2
310316
```
311317

@@ -314,16 +320,18 @@ approximation, you should add an error estimate; otherwise, at best the only
314320
algebraic number that can be guessed is the binary floating-point number
315321
itself, at worst no guess is possible.
316322

317-
```jldoctest; setup = :(QQBar = algebraic_closure(QQ))
323+
```jldoctest
324+
julia> Qb = algebraic_closure(QQ);
325+
318326
julia> RR = RealField();
319327
320328
julia> x = RR(0.1) # note: 53-bit binary approximation of 1//10 without radius
321329
[0.10000000000000000555 +/- 1.12e-21]
322330
323-
julia> guess(QQBar, x, 1)
331+
julia> guess(Qb, x, 1)
324332
ERROR: No suitable algebraic number found
325333
326-
julia> guess(QQBar, x + RR("+/- 1e-10"), 1)
334+
julia> guess(Qb, x + RR("+/- 1e-10"), 1)
327335
Root 0.100000 of 10x - 1
328336
```
329337

@@ -333,3 +341,15 @@ Root 0.100000 of 10x - 1
333341
guess
334342
```
335343

344+
# Important note on performance
345+
346+
The default algebraic number type represents algebraic numbers
347+
in canonical form using minimal polynomials. This works well for representing
348+
individual algebraic numbers, but it does not provide the best
349+
performance for field arithmetic.
350+
For fast calculation in $\overline{\mathbb{Q}}$,
351+
`CalciumField` should typically be used instead (see the section
352+
on *Exact real and complex numbers*).
353+
Alternatively, to compute in a fixed subfield of $\overline{\mathbb{Q}}$,
354+
you may fix a generator $a$ and construct a number field to represent $\mathbb{Q}(a)$.
355+

0 commit comments

Comments
 (0)