From 8299232181d813cefab81a257792cd711dc4d84a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 5 Apr 2024 16:19:28 +0200 Subject: [PATCH 1/9] Convert some examples to doctests --- docs/src/exact.md | 54 +++---- docs/src/fraction.md | 2 +- docs/src/gfp.md | 10 +- docs/src/matrix.md | 317 ++++++++++++++++++++++++++++------------ docs/src/numberfield.md | 65 +++++--- src/flint/fmpz_mat.jl | 11 ++ 6 files changed, 315 insertions(+), 144 deletions(-) diff --git a/docs/src/exact.md b/docs/src/exact.md index bb864f546c..f48e75dee1 100644 --- a/docs/src/exact.md +++ b/docs/src/exact.md @@ -119,9 +119,9 @@ in the Calcium documentation: ## Basic examples -```julia +```jldoctest julia> C = CalciumField() -Exact Complex Field +Exact complex field julia> exp(C(pi) * C(1im)) + 1 0 @@ -139,13 +139,13 @@ julia> 4*atan(C(1)//5) - atan(C(1)//239) == C(pi)//4 true julia> Cx, x = polynomial_ring(C, "x") -(Univariate Polynomial Ring in x over Exact Complex Field, x) +(Univariate polynomial ring in x over exact complex field, x) julia> (a, b) = (sqrt(C(2)), sqrt(C(3))) (1.41421 {a where a = 1.41421 [a^2-2=0]}, 1.73205 {a where a = 1.73205 [a^2-3=0]}) julia> (x-a-b)*(x-a+b)*(x+a-b)*(x+a+b) -x^4 + (-10)*x^2 + 1 +x^4 + -10*x^2 + 1 ``` ## Conversions and numerical evaluation @@ -161,7 +161,7 @@ if Calcium is unable to prove that the value belongs to the target domain, or if Calcium is unable to compute the explicit value because of evaluation limits. -```julia +```jldoctest; setup = :(C = CalciumField()) julia> QQ(C(1)) 1 @@ -170,16 +170,19 @@ Root 0.707107 of 2x^2 - 1 julia> QQ(C(pi)) ERROR: unable to convert to a rational number +[...] julia> QQ(C(10) ^ C(10^9)) ERROR: unable to convert to a rational number +[...] ``` To compute arbitrary-precision numerical enclosures, convert to `ArbField` or `AcbField`: -```julia -julia> CC = AcbField(64); +```jldoctest +julia> CC = AcbField(64) +Complex Field with 64 bits of precision and error bounds julia> CC(exp(C(1im))) [0.54030230586813971740 +/- 9.37e-22] + [0.84147098480789650665 +/- 2.51e-21]*im @@ -202,7 +205,7 @@ more expensive if one part is smaller than the other, or if the number is nontrivially purely real or purely imaginary (in which case an exact proof attempt is made). -```julia +```jldoctest; setup = :(C = CalciumField()) julia> x = sin(C(1), form=:exponential) 0.841471 + 0e-24*I {(-a^2*b+b)/(2*a) where a = 0.540302 + 0.841471*I [Exp(1.00000*I {b})], b = I [b^2+1=0]} @@ -235,7 +238,7 @@ results in different internal representations ($x \in \mathbb{Q}(\sqrt{3}, \sqrt and $y \in \mathbb{Q}(\sqrt{6})$), the numbers compare as equal: -```julia +```jldoctest; setup = :(C = CalciumField()) julia> x = sqrt(C(2)) * sqrt(C(3)) 2.44949 {a*b where a = 1.73205 [a^2-3=0], b = 1.41421 [b^2-2=0]} @@ -259,7 +262,7 @@ For example, with default settings, Calcium is currently able to prove that $e^{e^{-1000}} \ne 1$, but it fails to prove $e^{e^{-3000}} \ne 1$: -```julia +```jldoctest; setup = :(C = CalciumField()) julia> x = exp(exp(C(-1000))) 1.00000 {a where a = 1.00000 [Exp(5.07596e-435 {b})], b = 5.07596e-435 [Exp(-1000)]} @@ -271,12 +274,12 @@ julia> x = exp(exp(C(-3000))) julia> x == 1 ERROR: Unable to perform operation (failed deciding truth of a predicate): isequal -... +[...] ``` In this case, we can get an answer by allowing a higher working precision: -```julia +```jldoctest julia> C2 = CalciumField(options=Dict(:prec_limit => 10^5)); julia> exp(exp(C2(-3000))) == 1 @@ -286,7 +289,7 @@ false Real numbers can be ordered and sorted the usual way. We illustrate finding square roots that are well-approximated by integers: -```julia +```jldoctest; setup = :(C = CalciumField()) julia> sort([sqrt(C(n)) for n=0:10], by=x -> abs(x - floor(x + C(1)//2))) 11-element Vector{CalciumFieldElem}: 0 @@ -306,7 +309,7 @@ As currently implemented, order comparisons involving nonreal numbers yield *false* (in both directions) rather than throwing an exception: -```julia +```jldoctest; setup = :(C = CalciumField()) julia> C(1im) < C(1im) false @@ -338,17 +341,17 @@ This also applies to the special value Unknown, used in situations where Calcium is unable to prove that a value is a number. To enable special values, use `extended=true`. -```julia +```jldoctest julia> C = CalciumField() -Exact Complex Field +Exact complex field julia> 1 // C(0) ERROR: DomainError with UnsignedInfinity: Non-number result -... +[...] julia> Cext = CalciumField(extended=true) -Exact Complex Field (Extended) +Exact complex field (extended) julia> 1 // Cext(0) UnsignedInfinity @@ -378,7 +381,7 @@ Functions for computing components of real and complex numbers will perform automatic symbolic simplifications in special cases. In general, such operations will introduce new extension numbers. -```julia +```jldoctest; setup = :(C = CalciumField()) julia> real(C(2+3im)) 2 @@ -423,7 +426,7 @@ ceil(a::CalciumFieldElem) Elementary and special functions generally create new extension numbers. In special cases, simplifications occur automatically. -```julia +```jldoctest; setup = :(C = CalciumField()) julia> exp(C(1)) 2.71828 {a where a = 2.71828 [Exp(1)]} @@ -454,15 +457,15 @@ julia> erf(C(1)) + erfc(C(1)) Some functions allow representing the result in different forms: -```julia +```jldoctest; setup = :(C = CalciumField()) julia> s1 = sin(C(1)) -0.841471 - 0e-24*I {(-a^2*b+b)/(2*a) where a = 0.540302 + 0.841471*I [Exp(1.00000*I {b})], b = I [b^2+1=0]} +0.841471 + 0e-24*I {(-a^2*b+b)/(2*a) where a = 0.540302 + 0.841471*I [Exp(1.00000*I {b})], b = I [b^2+1=0]} julia> s2 = sin(C(1), form=:direct) 0.841471 {a where a = 0.841471 [Sin(1)]} julia> s3 = sin(C(1), form=:exponential) -0.841471 - 0e-24*I {(-a^2*b+b)/(2*a) where a = 0.540302 + 0.841471*I [Exp(1.00000*I {b})], b = I [b^2+1=0]} +0.841471 + 0e-24*I {(-a^2*b+b)/(2*a) where a = 0.540302 + 0.841471*I [Exp(1.00000*I {b})], b = I [b^2+1=0]} julia> s4 = sin(C(1), form=:tangent) 0.841471 {(2*a)/(a^2+1) where a = 0.546302 [Tan(0.500000 {1/2})]} @@ -485,7 +488,7 @@ problem in general. Calcium will sometimes fail even in elementary cases. Here is an example of two constant trigonometric identities where the first succeeds and the second fails: -```julia +```jldoctest; setup = :(C = CalciumField()) julia> a = sqrt(C(2)) + 1; julia> cos(a) + cos(2*a) + cos(3*a) == sin(7*a//2)//(2*sin(a//2)) - C(1)//2 @@ -493,11 +496,12 @@ true julia> sin(3*a) == 4 * sin(a) * sin(C(pi)//3 - a) * sin(C(pi)//3 + a) ERROR: Unable to perform operation (failed deciding truth of a predicate): isequal +[...] ``` A possible workaround is to fall back on a numerical comparison: -```julia +```jldoctest; setup = :(C = CalciumField(); a = sqrt(C(2)) + 1;) julia> abs(cos(a) + cos(2*a) + cos(3*a) - (sin(7*a//2)//(2*sin(a//2)) - C(1)//2)) <= C(10)^-100 true ``` diff --git a/docs/src/fraction.md b/docs/src/fraction.md index bf29eea5b2..414e428c9b 100644 --- a/docs/src/fraction.md +++ b/docs/src/fraction.md @@ -93,7 +93,7 @@ ceil(::QQFieldElem) **Examples** -```julia +```jldoctest julia> d = abs(ZZ(11)//3) 11//3 diff --git a/docs/src/gfp.md b/docs/src/gfp.md index bdb57bc214..b1f45e4c13 100644 --- a/docs/src/gfp.md +++ b/docs/src/gfp.md @@ -21,14 +21,16 @@ GF(n::ZZRingElem) For example, one can create the Galois field of characteristic $7$ as follows. -```julia -R = GF(7) +```jldoctest +julia> R = GF(7) +Prime field of characteristic 7 ``` Elements of the field are then created in the usual way. -```julia -a = R(3) +```jldoctest; setup = :(R = GF(7)) +julia> a = R(3) +3 ``` Elements of Galois fields have type `fpFieldElem` when $p$ is given to the diff --git a/docs/src/matrix.md b/docs/src/matrix.md index 5a8f95d465..f3fc714d56 100644 --- a/docs/src/matrix.md +++ b/docs/src/matrix.md @@ -78,11 +78,20 @@ In addition we have the following ad hoc comparison operators. **Examples** -```julia -C = RR[1 2; 3 4] -D = RR["1 +/- 0.1" "2 +/- 0.1"; "3 +/- 0.1" "4 +/- 0.1"] -overlaps(C, D) -contains(D, C) +```jldoctest; setup = :(RR = RealField()) +julia> C = RR[1 2; 3 4] +[1.0000000000000000000 2.0000000000000000000] +[3.0000000000000000000 4.0000000000000000000] + +julia> D = RR["1 +/- 0.1" "2 +/- 0.1"; "3 +/- 0.1" "4 +/- 0.1"] +[[1e+0 +/- 0.101] [2e+0 +/- 0.101]] +[[3e+0 +/- 0.101] [4e+0 +/- 0.101]] + +julia> overlaps(C, D) +true + +julia> contains(D, C) +true ``` ### Scaling @@ -97,13 +106,21 @@ contains(D, C) **Examples** -```julia -S = matrix_space(ZZ, 3, 3) +```jldoctest +julia> A = ZZ[2 3 5; 1 4 7; 9 6 3] +[2 3 5] +[1 4 7] +[9 6 3] -A = S([ZZ(2) 3 5; 1 4 7; 9 6 3]) +julia> B = A<<5 +[ 64 96 160] +[ 32 128 224] +[288 192 96] -B = A<<5 -C = B>>2 +julia> C = B>>2 +[16 24 40] +[ 8 32 56] +[72 48 24] ``` ### Determinant @@ -119,13 +136,17 @@ det_given_divisor(::ZZMatrix, ::ZZRingElem, ::Bool) **Examples** -```julia -S = matrix_space(ZZ, 3, 3) +```jldoctest +julia> A = ZZ[2 3 5; 1 4 7; 9 6 3] +[2 3 5] +[1 4 7] +[9 6 3] -A = S([ZZ(2) 3 5; 1 4 7; 9 6 3]) +julia> c = det_divisor(A) +3 -c = det_divisor(A) -d = det_given_divisor(A, c) +julia> d = det_given_divisor(A, c) +-30 ``` ### Pseudo inverse @@ -134,15 +155,6 @@ d = det_given_divisor(A, c) pseudo_inv(::ZZMatrix) ``` -**Examples** - -```julia -S = matrix_space(ZZ, 3, 3) - -A = S([1 0 1; 2 3 1; 5 6 7]) - -B, d = pseudo_inv(A) -``` ### Nullspace @@ -159,13 +171,21 @@ reduce_mod(::ZZMatrix, ::ZZRingElem) **Examples** -```julia -S = matrix_space(ZZ, 3, 3) +```jldoctest +julia> A = ZZ[2 3 5; 1 4 7; 9 2 2] +[2 3 5] +[1 4 7] +[9 2 2] -A = S([ZZ(2) 3 5; 1 4 7; 9 2 2]) +julia> reduce_mod(A, ZZ(5)) +[2 3 0] +[1 4 2] +[4 2 2] -reduce_mod(A, ZZ(5)) -reduce_mod(A, 2) +julia> reduce_mod(A, 2) +[0 1 1] +[1 0 1] +[1 0 0] ``` ### Lifting @@ -177,13 +197,19 @@ lift(::fpMatrix) **Examples** -```julia -R, = residue_ring(ZZ, 7) -S = matrix_space(R, 3, 3) +```jldoctest +julia> R, = residue_ring(ZZ, 7) +(Integers modulo 7, Map: ZZ -> ZZ/(7)) -a = S([4 5 6; 7 3 2; 1 4 5]) +julia> a = R[4 5 6; 7 3 2; 1 4 5] +[4 5 6] +[0 3 2] +[1 4 5] - b = lift(a) +julia> b = lift(a) +[-3 -2 -1] +[ 0 3 2] +[ 1 -3 -2] ``` ### Special matrices @@ -202,13 +228,24 @@ hilbert(::QQMatrixSpace) **Examples** -```julia -R = matrix_space(ZZ, 3, 3) -S = matrix_space(QQ, 3, 3) +```jldoctest +julia> hadamard(matrix_space(ZZ, 3, 3)) +ERROR: Unable to create Hadamard matrix +[...] + +julia> A = hadamard(matrix_space(ZZ, 4, 4)) +[1 1 1 1] +[1 -1 1 -1] +[1 1 -1 -1] +[1 -1 -1 1] -A = hadamard(R) -is_hadamard(A) -B = hilbert(R) +julia> is_hadamard(A) +true + +julia> B = hilbert(matrix_space(QQ, 3, 3)) +[ 1 1//2 1//3] +[1//2 1//3 1//4] +[1//3 1//4 1//5] ``` ### Hermite Normal Form @@ -235,16 +272,32 @@ is_hnf(::ZZMatrix) **Examples** -```julia -S = matrix_space(ZZ, 3, 3) +```jldoctest +julia> A = ZZ[2 3 5; 1 4 7; 19 3 7] +[ 2 3 5] +[ 1 4 7] +[19 3 7] -A = S([ZZ(2) 3 5; 1 4 7; 19 3 7]) +julia> B = hnf(A) +[1 0 16] +[0 1 18] +[0 0 27] -B = hnf(A) -H, T = hnf_with_transform(A) -M = hnf_modular(A, ZZ(27)) -N = hnf_modular_eldiv(A, ZZ(27)) -is_hnf(M) +julia> H, T = hnf_with_transform(A) +([1 0 16; 0 1 18; 0 0 27], [-43 30 3; -44 31 3; -73 51 5]) + +julia> M = hnf_modular(A, ZZ(27)) +[1 0 16] +[0 1 18] +[0 0 27] + +julia> N = hnf_modular_eldiv(A, ZZ(27)) +[1 0 16] +[0 1 18] +[0 0 27] + +julia> is_hnf(M) +true ``` ### Lattice basis reduction @@ -294,19 +347,33 @@ lll_gram!(::ZZMatrix, ::LLLContext) **Examples** -```julia -S = matrix_space(ZZ, 3, 3) +```jldoctest +julia> A = ZZ[2 3 5; 1 4 7; 19 3 7] +[ 2 3 5] +[ 1 4 7] +[19 3 7] + +julia> L = lll(A, LLLContext(0.95, 0.55, :zbasis, :approx)) +[-1 1 2] +[-1 -2 2] +[ 4 1 1] -A = S([ZZ(2) 3 5; 1 4 7; 19 3 7]) +julia> L, T = lll_with_transform(A) +([-1 1 2; -1 -2 2; 4 1 1], [-1 1 0; -15 10 1; 3 -2 0]) -L = lll(A, LLLContext(0.95, 0.55, :zbasis, :approx) -L, T = lll_with_transform(A) +julia> G = lll_gram(gram(A)) +[ 6 3 -1] +[ 3 9 -4] +[-1 -4 18] -G == lll_gram(gram(A)) -G, T = lll_gram_with_transform(gram(A)) +julia> G, T = lll_gram_with_transform(gram(A)) +([6 3 -1; 3 9 -4; -1 -4 18], [-1 1 0; -15 10 1; 3 -2 0]) -r, L = lll_with_removal(A, ZZ(100)) -r, L, T = lll_with_removal_transform(A, ZZ(100)) +julia> r, L = lll_with_removal(A, ZZ(100)) +(3, [-1 1 2; -1 -2 2; 4 1 1]) + +julia> r, L, T = lll_with_removal_transform(A, ZZ(100)) +(3, [-1 1 2; -1 -2 2; 4 1 1], [-1 1 0; -15 10 1; 3 -2 0]) ``` ### Smith Normal Form @@ -325,17 +392,29 @@ is_snf(::ZZMatrix) **Examples** -```julia -S = matrix_space(ZZ, 3, 3) +```jldoctest +julia> A = ZZ[2 3 5; 1 4 7; 19 3 7] +[ 2 3 5] +[ 1 4 7] +[19 3 7] -A = S([ZZ(2) 3 5; 1 4 7; 19 3 7]) +julia> B = snf(A) +[1 0 0] +[0 1 0] +[0 0 27] -B = snf(A) -is_snf(B) == true +julia> is_snf(B) == true +true -B = S([ZZ(2) 0 0; 0 4 0; 0 0 7]) +julia> B = ZZ[2 0 0; 0 4 0; 0 0 7] +[2 0 0] +[0 4 0] +[0 0 7] -C = snf_diagonal(B) +julia> C = snf_diagonal(B) +[1 0 0] +[0 2 0] +[0 0 28] ``` ### Strong Echelon Form @@ -347,13 +426,18 @@ strong_echelon_form(::fpMatrix) **Examples** -```julia -R, = residue_ring(ZZ, 12) -S = matrix_space(R, 3, 3) +```jldoctest +julia> R, = residue_ring(ZZ, 12); -A = S([4 1 0; 0 0 5; 0 0 0 ]) +julia> A = R[4 1 0; 0 0 5; 0 0 0 ] +[4 1 0] +[0 0 5] +[0 0 0] -B = strong_echelon_form(A) +julia> B = strong_echelon_form(A) +[4 1 0] +[0 3 0] +[0 0 1] ``` ### Howell Form @@ -365,13 +449,18 @@ howell_form(::fpMatrix) **Examples** -```julia -R, = residue_ring(ZZ, 12) -S = matrix_space(R, 3, 3) +```jldoctest +julia> R, = residue_ring(ZZ, 12); -A = S([4 1 0; 0 0 5; 0 0 0 ]) +julia> A = R[4 1 0; 0 0 5; 0 0 0 ] +[4 1 0] +[0 0 5] +[0 0 0] -B = howell_form(A) +julia> B = howell_form(A) +[4 1 0] +[0 3 0] +[0 0 1] ``` ### Gram-Schmidt Orthogonalisation @@ -384,10 +473,16 @@ gram_schmidt_orthogonalisation(::QQMatrix) **Examples** -```julia -A = RR[2 0 0; 0 3 0; 0 0 1] +```jldoctest; setup = :(RR = RealField()) +julia> A = RR[2 0 0; 0 3 0; 0 0 1] +[2.0000000000000000000 0 0] +[ 0 3.0000000000000000000 0] +[ 0 0 1.0000000000000000000] -B = exp(A) +julia> B = exp(A) +[[7.389056098930650227 +/- 4.72e-19] 0 0] +[ 0 [20.08553692318766774 +/- 1.94e-18] 0] +[ 0 0 [2.718281828459045235 +/- 4.30e-19]] ``` ### Norm @@ -402,34 +497,50 @@ bound_inf_norm(::ComplexMat) **Examples** -```julia -A = RR[1 2 3; 4 5 6; 7 8 9] +```jldoctest; setup = :(RR = RealField()) +julia> A = RR[1 2 3; 4 5 6; 7 8 9] +[1.0000000000000000000 2.0000000000000000000 3.0000000000000000000] +[4.0000000000000000000 5.0000000000000000000 6.0000000000000000000] +[7.0000000000000000000 8.0000000000000000000 9.0000000000000000000] -d = bound_inf_norm(A) +julia> d = bound_inf_norm(A) +[24.000000059604644775 +/- 3.91e-19] ``` ### Shifting **Examples** -```julia -A = RR[1 2 3; 4 5 6; 7 8 9] +```jldoctest; setup = :(RR = RealField()) +julia> A = RR[1 2 3; 4 5 6; 7 8 9] +[1.0000000000000000000 2.0000000000000000000 3.0000000000000000000] +[4.0000000000000000000 5.0000000000000000000 6.0000000000000000000] +[7.0000000000000000000 8.0000000000000000000 9.0000000000000000000] -B = ldexp(A, 4) +julia> B = ldexp(A, 4) +[16.000000000000000000 32.000000000000000000 48.000000000000000000] +[64.000000000000000000 80.000000000000000000 96.000000000000000000] +[112.00000000000000000 128.00000000000000000 144.00000000000000000] -overlaps(16*A, B) +julia> overlaps(16*A, B) +true ``` ### Predicates **Examples** -```julia -A = CC[1 2 3; 4 5 6; 7 8 9] +```jldoctest; setup = :(CC = ComplexField()) +julia> A = CC[1 2 3; 4 5 6; 7 8 9] +[1.0000000000000000000 2.0000000000000000000 3.0000000000000000000] +[4.0000000000000000000 5.0000000000000000000 6.0000000000000000000] +[7.0000000000000000000 8.0000000000000000000 9.0000000000000000000] -isreal(A) +julia> isreal(A) +true -isreal(onei(CC)*A) +julia> isreal(onei(CC)*A) +false ``` ### Conversion to Julia matrices @@ -453,10 +564,28 @@ eigenvalues_with_multiplicities(::ComplexMat) eigenvalues_simple(a::ComplexMat) ``` -```julia -A = CC[1 2 3; 0 4 5; 0 0 6] -eigenvalues_simple(A) -A = CC[2 2 3; 0 2 5; 0 0 2]) -eigenvalues(A) -eigenvalues_with_multiplicities(A) +```jldoctest; setup = :(CC = ComplexField()) +julia> A = CC[1 2 3; 0 4 5; 0 0 6] +[1.0000000000000000000 2.0000000000000000000 3.0000000000000000000] +[ 0 4.0000000000000000000 5.0000000000000000000] +[ 0 0 6.0000000000000000000] + +julia> eigenvalues_simple(A) +3-element Vector{AcbFieldElem}: + 1.0000000000000000000 + 4.0000000000000000000 + 6.0000000000000000000 + +julia> A = CC[2 2 3; 0 2 5; 0 0 2] +[2.0000000000000000000 2.0000000000000000000 3.0000000000000000000] +[ 0 2.0000000000000000000 5.0000000000000000000] +[ 0 0 2.0000000000000000000] + +julia> eigenvalues(A) +1-element Vector{AcbFieldElem}: + 2.0000000000000000000 + +julia> eigenvalues_with_multiplicities(A) +1-element Vector{Tuple{AcbFieldElem, Int64}}: + (2.0000000000000000000, 3) ``` diff --git a/docs/src/numberfield.md b/docs/src/numberfield.md index 0361a30ad1..290ac450b6 100644 --- a/docs/src/numberfield.md +++ b/docs/src/numberfield.md @@ -56,17 +56,33 @@ resulting parent objects to coerce various elements into those fields. **Examples** -```julia -R, x = polynomial_ring(QQ, "x") -K, a = number_field(x^3 + 3x + 1, "a") -L, b = cyclotomic_field(5, "b") -M, c = CyclotomicRealField(5, "c") +```jldoctest +julia> R, x = polynomial_ring(QQ, "x") +(Univariate polynomial ring in x over QQ, x) + +julia> K, a = number_field(x^3 + 3x + 1, "a") +(Number field of degree 3 over QQ, a) + +julia> L, b = cyclotomic_field(5, "b") +(Cyclotomic field of order 5, b) + +julia> M, c = cyclotomic_real_subfield(5, "c") +(Maximal real subfield of cyclotomic field of order 5, c) + +julia> d = K(3) +3 + +julia> f = L(b) +b + +julia> g = L(ZZ(11)) +11 -d = K(3) -f = L(b) -g = L(ZZ(11)) -h = L(ZZ(11)//3) -k = M(x) +julia> h = L(ZZ(11)//3) +11//3 + +julia> k = M(x) +c ``` ### Number field element constructors @@ -153,18 +169,27 @@ degree(::AbsSimpleNumField) **Examples** -```julia -R, x = polynomial_ring(QQ, "x") -K, a = number_field(x^3 + 3x + 1, "a") +```jldoctest +julia> R, x = polynomial_ring(QQ, "x") +(Univariate polynomial ring in x over QQ, x) + +julia> K, a = number_field(x^3 + 3x + 1, "a") +(Number field of degree 3 over QQ, a) + +julia> d = a^2 + 2a - 7 +a^2 + 2*a - 7 + +julia> m = gen(K) +a + +julia> c = coeff(d, 1) +2 -d = a^2 + 2a - 7 -m = gen(K) +julia> is_gen(m) +true -c = coeff(d, 1) -is_gen(m) -q = degree(K) -r, s = signature(K) -v = var(R) +julia> q = degree(K) +3 ``` ### Norm and trace diff --git a/src/flint/fmpz_mat.jl b/src/flint/fmpz_mat.jl index 78c9d2e514..3bf7b2c0f6 100644 --- a/src/flint/fmpz_mat.jl +++ b/src/flint/fmpz_mat.jl @@ -532,6 +532,17 @@ end Return a tuple $(z, d)$ consisting of a matrix $z$ and denominator $d$ such that $z/d$ is the inverse of $x$. + +# Examples +```jldoctest +julia> A = S[1 0 1; 2 3 1; 5 6 7] +[1 0 1] +[2 3 1] +[5 6 7] + +julia> B, d = pseudo_inv(A) +([15 6 -3; -9 2 1; -3 -6 3], 12) +``` """ function pseudo_inv(x::ZZMatrix) z = similar(x) From 803ed483ff74561947ef7cdc0657dbd95441f980 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 5 Apr 2024 17:42:40 +0200 Subject: [PATCH 2/9] Apply suggestions from code review --- docs/src/exact.md | 2 +- docs/src/matrix.md | 4 ++-- src/flint/fmpz_mat.jl | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/exact.md b/docs/src/exact.md index f48e75dee1..66e4c5ce9d 100644 --- a/docs/src/exact.md +++ b/docs/src/exact.md @@ -180,7 +180,7 @@ ERROR: unable to convert to a rational number To compute arbitrary-precision numerical enclosures, convert to `ArbField` or `AcbField`: -```jldoctest +```jldoctest; setup = :(C = CalciumField()) julia> CC = AcbField(64) Complex Field with 64 bits of precision and error bounds diff --git a/docs/src/matrix.md b/docs/src/matrix.md index f3fc714d56..145710a836 100644 --- a/docs/src/matrix.md +++ b/docs/src/matrix.md @@ -571,7 +571,7 @@ julia> A = CC[1 2 3; 0 4 5; 0 0 6] [ 0 0 6.0000000000000000000] julia> eigenvalues_simple(A) -3-element Vector{AcbFieldElem}: +3-element Vector{ComplexFieldElem}: 1.0000000000000000000 4.0000000000000000000 6.0000000000000000000 @@ -586,6 +586,6 @@ julia> eigenvalues(A) 2.0000000000000000000 julia> eigenvalues_with_multiplicities(A) -1-element Vector{Tuple{AcbFieldElem, Int64}}: +1-element Vector{Tuple{ComplexFieldElem, Int64}}: (2.0000000000000000000, 3) ``` diff --git a/src/flint/fmpz_mat.jl b/src/flint/fmpz_mat.jl index 3bf7b2c0f6..f9358b0402 100644 --- a/src/flint/fmpz_mat.jl +++ b/src/flint/fmpz_mat.jl @@ -535,7 +535,7 @@ that $z/d$ is the inverse of $x$. # Examples ```jldoctest -julia> A = S[1 0 1; 2 3 1; 5 6 7] +julia> A = ZZ[1 0 1; 2 3 1; 5 6 7] [1 0 1] [2 3 1] [5 6 7] From 31e1c00439a6cfdf8bf0df133c737b104936951b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 5 Apr 2024 19:18:37 +0200 Subject: [PATCH 3/9] Convert more examples --- docs/src/matrix.md | 2 +- docs/src/padic.md | 152 ++++++++++++++++++++--------- docs/src/polynomial.md | 213 +++++++++++++++++++++++++++++------------ docs/src/real.md | 86 ++++++----------- 4 files changed, 293 insertions(+), 160 deletions(-) diff --git a/docs/src/matrix.md b/docs/src/matrix.md index 145710a836..8b14115678 100644 --- a/docs/src/matrix.md +++ b/docs/src/matrix.md @@ -582,7 +582,7 @@ julia> A = CC[2 2 3; 0 2 5; 0 0 2] [ 0 0 2.0000000000000000000] julia> eigenvalues(A) -1-element Vector{AcbFieldElem}: +1-element Vector{ComplexFieldElem}: 2.0000000000000000000 julia> eigenvalues_with_multiplicities(A) diff --git a/docs/src/padic.md b/docs/src/padic.md index d6473397e0..37109deeee 100644 --- a/docs/src/padic.md +++ b/docs/src/padic.md @@ -57,14 +57,24 @@ resulting parent objects to coerce various elements into those fields. **Examples** -```julia -R = PadicField(7, 30) -S = PadicField(ZZ(65537), 30) +```jldoctest +julia> R = PadicField(7, 30) +Field of 7-adic numbers -a = R() -b = S(1) -c = S(ZZ(123)) -d = R(ZZ(1)//7^2) +julia> S = PadicField(ZZ(65537), 30) +Field of 65537-adic numbers + +julia> a = R() +O(7^30) + +julia> b = S(1) +65537^0 + O(65537^30) + +julia> c = S(ZZ(123)) +123*65537^0 + O(65537^30) + +julia> d = R(ZZ(1)//7^2) +7^-2 + O(7^28) ``` ### Big-oh notation @@ -84,18 +94,26 @@ $p^n$ as in the examples. **Examples** -```julia -R = PadicField(7, 30) -S = PadicField(ZZ(65537), 30) +```jldoctest +julia> R = PadicField(7, 30) +Field of 7-adic numbers + +julia> S = PadicField(ZZ(65537), 30) +Field of 65537-adic numbers + +julia> c = 1 + 2*7 + 4*7^2 + O(R, 7^3) +7^0 + 2*7^1 + 4*7^2 + O(7^3) + +julia> d = 13 + 357*ZZ(65537) + O(S, ZZ(65537)^12) +13*65537^0 + 357*65537^1 + O(65537^12) -c = 1 + 2*7 + 4*7^2 + O(R, 7^3) -d = 13 + 357*ZZ(65537) + O(S, ZZ(65537)^12) -f = ZZ(1)//7^2 + ZZ(2)//7 + 3 + 4*7 + O(R, 7^2) +julia> f = ZZ(1)//7^2 + ZZ(2)//7 + 3 + 4*7 + O(R, 7^2) +7^-2 + 2*7^-1 + 3*7^0 + 4*7^1 + O(7^2) ``` Beware that the expression `1 + 2*p + 3*p^2 + O(R, p^n)` is actually computed -as a normal Julia expression. Therefore if `{Int}` values are used instead -of Flint integers or Julia bignums, overflow may result in evaluating the +as a normal Julia expression. Therefore if `Int` values are used instead +of `ZZRingElem`s or Julia `BigInt`s, overflow may result in evaluating the value. ### Basic manipulation @@ -119,18 +137,33 @@ lift(::QQField, ::PadicFieldElem) **Examples** -```julia -R = PadicField(7, 30) +```jldoctest +julia> R = PadicField(7, 30) +Field of 7-adic numbers + +julia> a = 1 + 2*7 + 4*7^2 + O(R, 7^3) +7^0 + 2*7^1 + 4*7^2 + O(7^3) + +julia> b = 7^2 + 3*7^3 + O(R, 7^5) +7^2 + 3*7^3 + O(7^5) + +julia> c = R(2) +2*7^0 + O(7^30) + +julia> k = precision(a) +3 + +julia> m = prime(R) +7 + +julia> n = valuation(b) +2 -a = 1 + 2*7 + 4*7^2 + O(R, 7^3) -b = 7^2 + 3*7^3 + O(R, 7^5) -c = R(2) +julia> p = lift(ZZ, a) +211 -k = precision(a) -m = prime(R) -n = valuation(b) -p = lift(FlintZZ, a) -q = lift(FlintQQ, divexact(a, b)) +julia> q = lift(QQ, divexact(a, b)) +337//49 ``` ### Square root @@ -141,17 +174,33 @@ Base.sqrt(::PadicFieldElem) **Examples** -```julia -R = PadicField(7, 30) +```jldoctest +julia> R = PadicField(7, 30) +Field of 7-adic numbers -a = 1 + 7 + 2*7^2 + O(R, 7^3) -b = 2 + 3*7 + O(R, 7^5) -c = 7^2 + 2*7^3 + O(R, 7^4) +julia> a = 1 + 7 + 2*7^2 + O(R, 7^3) +7^0 + 7^1 + 2*7^2 + O(7^3) -d = sqrt(a) -f = sqrt(b) -f = sqrt(c) -g = sqrt(R(121)) +julia> b = 2 + 3*7 + O(R, 7^5) +2*7^0 + 3*7^1 + O(7^5) + +julia> c = 7^2 + 2*7^3 + O(R, 7^4) +7^2 + 2*7^3 + O(7^4) + +julia> d = sqrt(a) +7^0 + 4*7^1 + 3*7^2 + O(7^3) + +julia> f = sqrt(b) +3*7^0 + 5*7^1 + 7^2 + 7^3 + O(7^5) + +julia> f = sqrt(c) +7^1 + 7^2 + O(7^3) + +julia> g = sqrt(R(121)) +3*7^0 + 5*7^1 + 6*7^2 + 6*7^3 + 6*7^4 + 6*7^5 + 6*7^6 + 6*7^7 + 6*7^8 + 6*7^9 + 6*7^10 + 6*7^11 + 6*7^12 + 6*7^13 + 6*7^14 + 6*7^15 + 6*7^16 + 6*7^17 + 6*7^18 + 6*7^19 + 6*7^20 + 6*7^21 + 6*7^22 + 6*7^23 + 6*7^24 + 6*7^25 + 6*7^26 + 6*7^27 + 6*7^28 + 6*7^29 + O(7^30) + +julia> g^2 == R(121) +true ``` ### Special functions @@ -170,16 +219,31 @@ teichmuller(::PadicFieldElem) **Examples** -```julia -R = PadicField(7, 30) +```jldoctest +julia> R = PadicField(7, 30) +Field of 7-adic numbers + +julia> a = 1 + 7 + 2*7^2 + O(R, 7^3) +7^0 + 7^1 + 2*7^2 + O(7^3) + +julia> b = 2 + 5*7 + 3*7^2 + O(R, 7^3) +2*7^0 + 5*7^1 + 3*7^2 + O(7^3) + +julia> c = 3*7 + 2*7^2 + O(R, 7^5) +3*7^1 + 2*7^2 + O(7^5) + +julia> c = exp(c) +7^0 + 3*7^1 + 3*7^2 + 4*7^3 + 4*7^4 + O(7^5) + +julia> d = log(a) +7^1 + 5*7^2 + O(7^3) + +julia> c = exp(R(0)) +7^0 + O(7^30) -a = 1 + 7 + 2*7^2 + O(R, 7^3) -b = 2 + 5*7 + 3*7^2 + O(R, 7^3) -c = 3*7 + 2*7^2 + O(R, 7^5) +julia> d = log(R(1)) +O(7^30) -c = exp(c) -d = log(a) -c = exp(R(0)) -d = log(R(1)) -f = teichmuller(b) +julia> f = teichmuller(b) +2*7^0 + 4*7^1 + 6*7^2 + O(7^3) ``` diff --git a/docs/src/polynomial.md b/docs/src/polynomial.md index 7170b829ce..a6822d03e8 100644 --- a/docs/src/polynomial.md +++ b/docs/src/polynomial.md @@ -66,13 +66,18 @@ evaluate2(::ComplexPoly, ::ComplexFieldElem) **Examples** -```julia -RR = RealField() -T, z = polynomial_ring(RR, "z") - -h = z^2 + 2z + 1 +```jldoctest +julia> RR = RealField() +Real field -s, t = evaluate2(h, RR("2.0 +/- 0.1")) +julia> T, z = polynomial_ring(RR, "z") +(Univariate polynomial ring in z over RR, z) + +julia> h = z^2 + 2z + 1 +z^2 + 2.0000000000000000000*z + 1 + +julia> s, t = evaluate2(h, RR("2.0 +/- 0.1")) +([9e+0 +/- 0.611], [6e+0 +/- 0.201]) ``` ### Signature @@ -90,18 +95,31 @@ roots(::ComplexPoly) **Examples** -```julia -CC = ComplexField() -C, y = polynomial_ring(CC, "y") +```jldoctest +julia> CC = ComplexField() +Complex field + +julia> C, y = polynomial_ring(CC, "y") +(Univariate polynomial ring in y over CC, y) -m = y^2 + 2y + 3 -n = m + CC("0 +/- 0.0001", "0 +/- 0.0001") +julia> m = y^2 + 2y + 3 +y^2 + 2.0000000000000000000*y + 3.0000000000000000000 -r = roots(n) +julia> n = m + CC("0 +/- 0.0001", "0 +/- 0.0001") +y^2 + 2.0000000000000000000*y + [3.000 +/- 1.01e-4] + [+/- 1.01e-4]*im -p = y^7 - 1 +julia> r = roots(n) +2-element Vector{ComplexFieldElem}: + [-1.00 +/- 1.01e-4] + [-1.414 +/- 3.14e-4]*im + [-1.00 +/- 1.01e-4] + [1.414 +/- 3.14e-4]*im -r = roots(n, isolate_real = true) +julia> p = y^7 - 1 +y^7 - 1.0000000000000000000 + +julia> r = roots(n, isolate_real = true) +2-element Vector{ComplexFieldElem}: + [-1.00 +/- 1.01e-4] + [-1.414 +/- 3.14e-4]*im + [-1.00 +/- 1.01e-4] + [1.414 +/- 3.14e-4]*im ``` ### Construction from roots @@ -113,12 +131,26 @@ from_roots(::AcbPolyRing, ::Vector{AcbFieldElem}) **Examples** -```julia -RR = RealField() -R, x = polynomial_ring(RR, "x") +```jldoctest +julia> RR = RealField() +Real field + +julia> R, x = polynomial_ring(RR, "x") +(Univariate polynomial ring in x over RR, x) -xs = ArbFieldElem[inv(RR(i)) for i=1:5] -f = from_roots(R, xs) +julia> xs = [inv(RR(i)) for i=1:5] +5-element Vector{RealFieldElem}: + 1.0000000000000000000 + 0.50000000000000000000 + [0.3333333333333333333 +/- 4.24e-20] + 0.25000000000000000000 + [0.2000000000000000000 +/- 2.44e-20] + +julia> f = from_roots(R, xs) +x^5 + [-2.283333333333333333 +/- 4.54e-19]*x^4 + [1.875000000000000000 +/- 5.10e-19]*x^3 + [-0.708333333333333333 +/- 3.99e-19]*x^2 + [0.1250000000000000000 +/- 3.69e-20]*x + [-0.00833333333333333333 +/- 4.13e-21] + +julia> all(x -> contains_zero(evaluate(f, x)), xs) +true ``` ### Bounding absolute values of roots @@ -142,14 +174,21 @@ lift(::ZZPolyRing, ::FpPolyRingElem) **Examples** -```julia -R, = residue_ring(ZZ, 123456789012345678949) -S, x = polynomial_ring(R, "x") -T, y = polynomial_ring(ZZ, "y") +```jldoctest +julia> R, = residue_ring(ZZ, 123456789012345678949) +(Integers modulo 123456789012345678949, Map: ZZ -> ZZ/(123456789012345678949)) + +julia> S, x = polynomial_ring(R, "x") +(Univariate polynomial ring in x over ZZ/(123456789012345678949), x) + +julia> T, y = polynomial_ring(ZZ, "y") +(Univariate polynomial ring in y over ZZ, y) -f = x^2 + 2x + 1 +julia> f = x^2 + 2x + 1 +x^2 + 2*x + 1 -a = lift(T, f) +julia> a = lift(T, f) +y^2 + 2*y + 1 ``` ### Overlapping and containment @@ -185,26 +224,55 @@ unique_integer(::ComplexPoly) **Examples** -```julia -RR = RealField() -CC = ComplexField() -R, x = polynomial_ring(RR, "x") -C, y = polynomial_ring(CC, "y") -Zx, zx = polynomial_ring(ZZ, "x") -Qx, qx = polynomial_ring(QQ, "x") - -f = x^2 + 2x + 1 -h = f + RR("0 +/- 0.0001") -k = f + RR("0 +/- 0.0001") * x^4 -m = y^2 + 2y + 1 -n = m + CC("0 +/- 0.0001", "0 +/- 0.0001") - -contains(h, f) -overlaps(f, k) -contains(n, m) -t, z = unique_integer(k) -isreal(n) +```jldoctest +julia> RR = RealField() +Real field + +julia> R, x = polynomial_ring(RR, "x") +(Univariate polynomial ring in x over RR, x) + +julia> f = x^2 + 2x + 1 +x^2 + 2.0000000000000000000*x + 1 + +julia> h = f + RR("0 +/- 0.0001") +x^2 + 2.0000000000000000000*x + [1.000 +/- 1.01e-4] + +julia> k = f + RR("0 +/- 0.0001") * x^4 +[+/- 1.01e-4]*x^4 + x^2 + 2.0000000000000000000*x + 1 + +julia> contains(h, f) +true + +julia> overlaps(f, k) +true + +julia> t, z = unique_integer(k) +(true, x^2 + 2*x + 1) +``` + +```jldoctest +julia> CC = ComplexField() +Complex field + +julia> C, y = polynomial_ring(CC, "y") +(Univariate polynomial ring in y over CC, y) + +julia> m = y^2 + 2y + 1 +y^2 + 2.0000000000000000000*y + 1 + +julia> n = m + CC("0 +/- 0.0001", "0 +/- 0.0001") +y^2 + 2.0000000000000000000*y + [1.000 +/- 1.01e-4] + [+/- 1.01e-4]*im + +julia> contains(n, m) +true + +julia> isreal(n) +false + +julia> isreal(m) +true ``` + ### Factorisation Certain polynomials can be factored (`ZZPolyRingElem', `zzModPolyRingElem`, `fpPolyRingElem`, @@ -224,15 +292,29 @@ factor_distinct_deg(::fqPolyRepPolyRingElem) **Examples** ``` -R, = residue_ring(ZZ, 23) -S, x = polynomial_ring(R, "x") +julia> R, = residue_ring(ZZ, 23) +(Integers modulo 23, Map: ZZ -> ZZ/(23)) + +julia> S, x = polynomial_ring(R, "x") +(Univariate polynomial ring in x over ZZ/(23), x) -f = x^2 + 2x + 1 -g = x^3 + 3x + 1 +julia> f = x^2 + 2x + 1 +x^2 + 2*x + 1 -R = factor(f*g) -S = factor_squarefree(f*g) -T = factor_distinct_deg((x + 1)*g*(x^5+x^3+x+1)) +julia> g = x^3 + 3x + 1 +x^3 + 3*x + 1 + +julia> R = factor(f*g) +1 * (x + 1)^2 * (x^3 + 3*x + 1) + +julia> S = factor_squarefree(f*g) +1 * (x + 1)^2 * (x^3 + 3*x + 1) + +julia> T = factor_distinct_deg((x + 1)*g*(x^5+x^3+x+1)) +Dict{Int64, zzModPolyRingElem} with 3 entries: + 4 => x^4 + 7*x^3 + 4*x^2 + 5*x + 13 + 3 => x^3 + 3*x + 1 + 1 => x^2 + 17*x + 16 ``` ### Special functions @@ -259,14 +341,25 @@ eta_qexp(::Int, ::Int, ::ZZPolyRingElem) **Examples** -```julia -R, x = polynomial_ring(ZZ, "x") -S, y = polynomial_ring(R, "y") +```jldoctest +julia> R, x = polynomial_ring(ZZ, "x") +(Univariate polynomial ring in x over ZZ, x) + +julia> h = cyclotomic(120, x) +x^32 + x^28 - x^20 - x^16 - x^12 + x^4 + 1 + +julia> j = swinnerton_dyer(5, x) +x^32 - 448*x^30 + 84864*x^28 - 9028096*x^26 + 602397952*x^24 - 26625650688*x^22 + 801918722048*x^20 - 16665641517056*x^18 + 239210760462336*x^16 - 2349014746136576*x^14 + 15459151516270592*x^12 - 65892492886671360*x^10 + 172580952324702208*x^8 - 255690851718529024*x^6 + 183876928237731840*x^4 - 44660812492570624*x^2 + 2000989041197056 + +julia> k = cos_minpoly(30, x) +x^4 + x^3 - 4*x^2 - 4*x + 1 + +julia> l = theta_qexp(3, 30, x) +72*x^29 + 32*x^27 + 72*x^26 + 30*x^25 + 24*x^24 + 24*x^22 + 48*x^21 + 24*x^20 + 24*x^19 + 36*x^18 + 48*x^17 + 6*x^16 + 48*x^14 + 24*x^13 + 8*x^12 + 24*x^11 + 24*x^10 + 30*x^9 + 12*x^8 + 24*x^6 + 24*x^5 + 6*x^4 + 8*x^3 + 12*x^2 + 6*x + 1 + +julia> m = eta_qexp(24, 30, x) +-29211840*x^29 + 128406630*x^28 + 24647168*x^27 - 73279080*x^26 + 13865712*x^25 - 25499225*x^24 + 21288960*x^23 + 18643272*x^22 - 12830688*x^21 - 4219488*x^20 - 7109760*x^19 + 10661420*x^18 + 2727432*x^17 - 6905934*x^16 + 987136*x^15 + 1217160*x^14 + 401856*x^13 - 577738*x^12 - 370944*x^11 + 534612*x^10 - 115920*x^9 - 113643*x^8 + 84480*x^7 - 16744*x^6 - 6048*x^5 + 4830*x^4 - 1472*x^3 + 252*x^2 - 24*x + 1 -h = cyclotomic(120, x) -j = swinnerton_dyer(5, x) -k = cos_minpoly(30, x) -l = theta_qexp(3, 30, x) -m = eta_qexp(24, 30, x) -o = cyclotomic(10, 1 + x + x^2) +julia> o = cyclotomic(10, 1 + x + x^2) +x^8 + 4*x^7 + 9*x^6 + 13*x^5 + 14*x^4 + 11*x^3 + 6*x^2 + 2*x + 1 ``` diff --git a/docs/src/real.md b/docs/src/real.md index 403ec32205..9ef1d0c294 100644 --- a/docs/src/real.md +++ b/docs/src/real.md @@ -94,10 +94,7 @@ Using coercion into the real field, new elements can be created. **Examples** -```jldoctest -julia> RR = RealField() -Real field - +```jldoctest; setup = :(RR = RealField()) julia> c = RR(1) 1.0000000000000000000 @@ -107,19 +104,17 @@ julia> d = RR(1//2) Note that for the construction, also the precision can be supplied: -```julia -RR = RealField() +```jldoctest; setup = :(RR = RealField()) +julia> c = RR(1//3, 100) +[0.33333333333333333333 +/- 3.34e-21] -c = RR(1, precision = 100) -d = RR(1//2, precision = 4) +julia> d = RR(1//3, 4) +[0.3 +/- 0.0438] ``` ### Conversions -```jldoctest -julia> RR = RealField() -Real field - +```jldoctest; setup = :(RR = RealField()) julia> convert(Float64, RR(1//3)) 0.3333333333333333 ``` @@ -209,25 +204,29 @@ julia> f = accuracy_bits(a) Printing real balls can at first sight be confusing. Lets look at the following example: -```julia -RR = RealField() +```jldoctest; setup = :(RR = RealField()) +julia> a = RR(1) +1.0000000000000000000 -a = RR(1) -b = RR(2) -c = RR(12) +julia> b = RR(2) +2.0000000000000000000 -x = ball(a, b) -y = ball(c, b) +julia> c = RR(12) +12.000000000000000000 -mid = midpoint(x) -rad = radius(x) +julia> x = ball(a, b) +[+/- 3.01] -print(x, "\n", y, "\n", mid, "\n", rad) -``` +julia> y = ball(c, b) +[1e+1 +/- 4.01] -which generates +julia> mid = midpoint(x) +1.0000000000000000000 -``` +julia> rad = radius(x) +[2.0000000037252902985 +/- 3.81e-20] + +julia> print(x, "\n", y, "\n", mid, "\n", rad) [+/- 3.01] [1e+1 +/- 4.01] 1.0000000000000000000 @@ -290,10 +289,7 @@ contains_nonpositive(::RealFieldElem) **Examples** -```jldoctest -julia> RR = RealField() -Real field - +```jldoctest; setup = :(RR = RealField()) julia> x = RR("1 +/- 0.001") [1.00 +/- 1.01e-3] @@ -357,10 +353,7 @@ Function | **Examples** -```jldoctest -julia> RR = RealField() -Real field - +```jldoctest; setup = :(RR = RealField()) julia> x = RR("1 +/- 0.001") [1.00 +/- 1.01e-3] @@ -387,10 +380,7 @@ true **Examples** -```jldoctest -julia> RR = RealField() -Real field - +```jldoctest; setup = :(RR = RealField()) julia> x = RR("-1 +/- 0.001") [-1.00 +/- 1.01e-3] @@ -402,10 +392,7 @@ julia> a = abs(x) **Examples** -```jldoctest -julia> RR = RealField() -Real field - +```jldoctest; setup = :(RR = RealField()) julia> x = RR("-3 +/- 0.001") [-3.00 +/- 1.01e-3] @@ -436,10 +423,7 @@ setunion(::RealFieldElem, ::RealFieldElem) **Examples** -```jldoctest -julia> RR = RealField() -Real field - +```jldoctest; setup = :(RR = RealField()) julia> x = RR("-3 +/- 0.001") [-3.00 +/- 1.01e-3] @@ -492,10 +476,7 @@ const_glaisher(::RealField) **Examples** -```jldoctest -julia> RR = RealField() -Real field - +```jldoctest; setup = :(RR = RealField()) julia> a = const_pi(RR) [3.141592653589793239 +/- 5.96e-19] @@ -681,10 +662,7 @@ airy_bi_prime(::RealFieldElem) **Examples** -```jldoctest -julia> RR = RealField() -Real field - +```jldoctest; setup = :(RR = RealField()) julia> a = floor(exp(RR(1))) 2.0000000000000000000 @@ -720,8 +698,6 @@ rand(::RealField) **Examples** ```julia -RR = RealField() - a = rand(RR) b = rand(RR; randtype = :null_exact) c = rand(RR; randtype = :exact) From c76d281fb55ad0e9876bdc55c7d9b6d9cc2875af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 9 Apr 2024 16:05:39 +0200 Subject: [PATCH 4/9] Sort roots to make printing consistent --- docs/src/polynomial.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/src/polynomial.md b/docs/src/polynomial.md index a6822d03e8..3b3d032b1e 100644 --- a/docs/src/polynomial.md +++ b/docs/src/polynomial.md @@ -108,7 +108,9 @@ y^2 + 2.0000000000000000000*y + 3.0000000000000000000 julia> n = m + CC("0 +/- 0.0001", "0 +/- 0.0001") y^2 + 2.0000000000000000000*y + [3.000 +/- 1.01e-4] + [+/- 1.01e-4]*im -julia> r = roots(n) +julia> r = roots(n); + +julia> sort(r; by=x->(real(x), imag(x))) # sort roots to make printing consistent 2-element Vector{ComplexFieldElem}: [-1.00 +/- 1.01e-4] + [-1.414 +/- 3.14e-4]*im [-1.00 +/- 1.01e-4] + [1.414 +/- 3.14e-4]*im @@ -116,7 +118,9 @@ julia> r = roots(n) julia> p = y^7 - 1 y^7 - 1.0000000000000000000 -julia> r = roots(n, isolate_real = true) +julia> r = roots(n, isolate_real = true); + +julia> sort(r; by=x->(real(x), imag(x))) # sort roots to make printing consistent 2-element Vector{ComplexFieldElem}: [-1.00 +/- 1.01e-4] + [-1.414 +/- 3.14e-4]*im [-1.00 +/- 1.01e-4] + [1.414 +/- 3.14e-4]*im From 1af23368e6db130e9f1431b002ba47ac931bb55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 9 Apr 2024 16:19:26 +0200 Subject: [PATCH 5/9] Convert all examples with just ``` (no `julia`) --- docs/src/arb.md | 33 ++++++++++++++++++++------------- docs/src/complex.md | 32 +++++++++++++++++++++++--------- docs/src/constructors.md | 28 ++++++++++++++++++---------- docs/src/numberfield.md | 32 ++++++++++++++++++++++---------- docs/src/polynomial.md | 2 +- 5 files changed, 84 insertions(+), 43 deletions(-) diff --git a/docs/src/arb.md b/docs/src/arb.md index a823307a44..6710044f8f 100644 --- a/docs/src/arb.md +++ b/docs/src/arb.md @@ -163,25 +163,32 @@ f = accuracy_bits(a) Printing real balls can at first sight be confusing. Lets look at the following example: -```julia -RR = ArbField(64) +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds -a = RR(1) -b = RR(2) -c = RR(12) +julia> a = RR(1) +1.0000000000000000000 -x = ball(a, b) -y = ball(c, b) +julia> b = RR(2) +2.0000000000000000000 -mid = midpoint(x) -rad = radius(x) +julia> c = RR(12) +12.000000000000000000 -print(x, "\n", y, "\n", mid, "\n", rad) -``` +julia> x = ball(a, b) +[+/- 3.01] -which generates +julia> y = ball(c, b) +[1e+1 +/- 4.01] -``` +julia> mid = midpoint(x) +1.0000000000000000000 + +julia> rad = radius(x) +[2.0000000037252902985 +/- 3.81e-20] + +julia> print(x, "\n", y, "\n", mid, "\n", rad) [+/- 3.01] [1e+1 +/- 4.01] 1.0000000000000000000 diff --git a/docs/src/complex.md b/docs/src/complex.md index e9be131bd6..f656cbb160 100644 --- a/docs/src/complex.md +++ b/docs/src/complex.md @@ -181,16 +181,30 @@ return it. A copy of the original is not made. Here are some examples of coercing elements into the Arb complex field. -``` -RR = RealField() -CC = ComplexField() +```jldoctest +julia> RR = RealField() +Real field + +julia> CC = ComplexField() +Complex field + +julia> a = CC(3) +3.0000000000000000000 + +julia> b = CC(QQ(2,3)) +[0.6666666666666666666 +/- 8.48e-20] + +julia> c = CC("3 +/- 0.0001") +[3.000 +/- 1.01e-4] + +julia> d = CC("-1.24e+12345") +[-1.240000000000000000e+12345 +/- 1.16e+12326] + +julia> f = CC("nan +/- inf") +nan -a = CC(3) -b = CC(QQ(2,3)) -c = CC("3 +/- 0.0001") -d = CC("-1.24e+12345") -f = CC("nan +/- inf") -g = CC(RR(3)) +julia> g = CC(RR(3)) +3.0000000000000000000 ``` In addition to the above, developers of custom complex field types must ensure diff --git a/docs/src/constructors.md b/docs/src/constructors.md index c4262c1add..7ddcefc1a2 100644 --- a/docs/src/constructors.md +++ b/docs/src/constructors.md @@ -6,14 +6,16 @@ In Julia, one constructs objects of a given type by calling a type constructor. with the same name as the type itself. For example, to construct a `BigInt` object in Julia, we simply call the `BigInt` constructor: -``` -n = BigInt("1234567898765434567898765434567876543456787654567890") +```jldoctest +julia> n = parse(BigInt, "1234567898765434567898765434567876543456787654567890") +1234567898765434567898765434567876543456787654567890 ``` Julia also uses constructors to convert between types. For example, to convert an `Int` to a `BigInt`: -``` -m = BigInt(123) +```jldoctest +julia> m = BigInt(123) +123 ``` ## How we construct objects in Nemo @@ -27,8 +29,9 @@ refer to as parent objects. They behave a lot like Julia types. Consider the following simple example, to create a Flint multiprecision integer: -``` -n = ZZ("12345678765456787654567890987654567898765678909876567890") +```jldoctest +julia> n = ZZ("12345678765456787654567890987654567898765678909876567890") +12345678765456787654567890987654567898765678909876567890 ``` Here `ZZ` is not a Julia type, but a callable object. However, for most purposes one can think of such @@ -42,10 +45,15 @@ one can use it to construct element objects. Nemo provides a set of functions for constructing such parent objects. For example, to create a parent object for polynomials over the integers, we use the `polynomial_ring` parent object constructor. -``` -R, x = polynomial_ring(ZZ, "x") -f = x^3 + 3x + 1 -g = R(12) +```jldoctest +julia> R, x = polynomial_ring(ZZ, "x") +(Univariate polynomial ring in x over ZZ, x) + +julia> f = x^3 + 3x + 1 +x^3 + 3*x + 1 + +julia> g = R(12) +12 ``` In this example, $R$ is the parent object and we use it to convert the `Int` value $12$ to an element diff --git a/docs/src/numberfield.md b/docs/src/numberfield.md index 290ac450b6..7bdf8cb23b 100644 --- a/docs/src/numberfield.md +++ b/docs/src/numberfield.md @@ -97,12 +97,18 @@ representation as a polynomial. See the following examples for how to do this. **Examples** -``` -R, x = polynomial_ring(QQ, "x") -K, a = number_field(x^3 + 3x + 1, "a") +```jldoctest +julia> R, x = polynomial_ring(QQ, "x") +(Univariate polynomial ring in x over QQ, x) + +julia> K, a = number_field(x^3 + 3x + 1, "a") +(Number field of degree 3 over QQ, a) + +julia> d = gen(K) +a -d = gen(K) -f = a^2 + 2a - 7 +julia> f = a^2 + 2a - 7 +a^2 + 2*a - 7 ``` ### Basic functionality @@ -137,12 +143,18 @@ number field is a quotient. **Examples** -``` -R, x = polynomial_ring(QQ, "x") -K, a = number_field(x^3 + 3x + 1, "a") +```jldoctest +julia> R, x = polynomial_ring(QQ, "x") +(Univariate polynomial ring in x over QQ, x) + +julia> K, a = number_field(x^3 + 3x + 1, "a") +(Number field of degree 3 over QQ, a) + +julia> f = R(a^2 + 2a + 3) +x^2 + 2*x + 3 -f = R(a^2 + 2a + 3) -g = K(x^2 + 2x + 1) +julia> g = K(x^2 + 2x + 1) +a^2 + 2*a + 1 ``` ### Basic manipulation diff --git a/docs/src/polynomial.md b/docs/src/polynomial.md index 3b3d032b1e..33a1f1ff9e 100644 --- a/docs/src/polynomial.md +++ b/docs/src/polynomial.md @@ -295,7 +295,7 @@ factor_distinct_deg(::fqPolyRepPolyRingElem) **Examples** -``` +```jldoctest julia> R, = residue_ring(ZZ, 23) (Integers modulo 23, Map: ZZ -> ZZ/(23)) From 53dd0c0e198113682bda377e72fb9d81349e2a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 9 Apr 2024 17:04:50 +0200 Subject: [PATCH 6/9] Convert even more examples --- docs/src/acb.md | 53 ++++++--- docs/src/arb.md | 276 +++++++++++++++++++++++++++++++------------- docs/src/complex.md | 234 +++++++++++++++++++++++++------------ 3 files changed, 388 insertions(+), 175 deletions(-) diff --git a/docs/src/acb.md b/docs/src/acb.md index e6857e182e..a6e63b0215 100644 --- a/docs/src/acb.md +++ b/docs/src/acb.md @@ -726,19 +726,42 @@ lindep(A::Matrix{AcbFieldElem}, bits::Int) **Examples** -```julia -CC = AcbField(128) - -# These are two of the roots of x^5 + 3x + 1 -a = CC(1.0050669478588622428791051888364775253, - 0.93725915669289182697903585868761513585) -b = CC(-0.33198902958450931620250069492231652319) - -# We recover the polynomial from one root.... -V1 = [CC(1), a, a^2, a^3, a^4, a^5]; -W = lindep(V1, 20) - -# ...or from two -V2 = [CC(1), b, b^2, b^3, b^4, b^5]; -Vs = [V1 V2] -X = lindep(Vs, 20) +```jldoctest +julia> CC = AcbField(128) +Complex Field with 128 bits of precision and error bounds + +julia> # These are two of the roots of x^5 + 3x + 1 + +julia> a = CC(1.0050669478588622428791051888364775253, -0.93725915669289182697903585868761513585) +[1.00506694785886230292248910700436681509 +/- 1.80e-40] - [0.937259156692891837181491609953809529543 +/- 7.71e-41]*im + +julia> b = CC(-0.33198902958450931620250069492231652319) +-[0.331989029584509320880414406929048709571 +/- 3.62e-40] + +julia> V1 = [CC(1), a, a^2, a^3, a^4, a^5]; # We recover the polynomial from one root.... + +julia> W = lindep(V1, 20) +6-element Vector{ZZRingElem}: + 1 + 3 + 0 + 0 + 0 + 1 + +julia> V2 = [CC(1), b, b^2, b^3, b^4, b^5]; # ...or from two + +julia> Vs = [V1 V2] +6×2 Matrix{AcbFieldElem}: + 1.00000000000000000000000000000000000000 … 1.00000000000000000000000000000000000000 + [1.00506694785886230292248910700436681509 +/- 1.80e-40] - [0.937259156692891837181491609953809529543 +/- 7.71e-41]*im -[0.331989029584509320880414406929048709571 +/- 3.62e-40] + [0.131704842873658261608907475851071865533 +/- 2.43e-40] - [1.88401639994019194629934002026077386471 +/- 2.35e-39]*im [0.110216715764464205102727554344054759368 +/- 3.32e-40] + [-1.63343943775826359832802955077858762779 +/- 7.18e-39] + [-2.0170041827680651335098567246278775869 +/- 5.08e-38]*im [-0.0365907405106361618384680031506015710184 +/- 8.30e-41] + [-3.5321716296072262805776584101060548180 +/- 5.08e-38] + [-0.49626816785103656510289466486482917885 +/- 2.35e-39]*im [0.0121477244339046924274232580429164920524 +/- 8.57e-41] + [-4.01520084357658781437077178965706076158 +/- 5.97e-39] + [2.81177747007867551213313071756269751169 +/- 3.99e-39]*im … [-0.00403291124647205167662794872826031818905 +/- 7.87e-42] + +julia> X = lindep(Vs, 20) +2-element Vector{ZZRingElem}: + 0 + 1 ``` diff --git a/docs/src/arb.md b/docs/src/arb.md index 6710044f8f..458533377e 100644 --- a/docs/src/arb.md +++ b/docs/src/arb.md @@ -51,13 +51,21 @@ parent object to coerce values into the resulting field. **Examples** -```julia -RR = ArbField(64) +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds + +julia> a = RR("0.25") +0.25000000000000000000 + +julia> b = RR("0.1 +/- 0.001") +[0.1 +/- 1.01e-3] -a = RR("0.25") -b = RR("0.1 +/- 0.001") -c = RR(0.5) -d = RR(12) +julia> c = RR(0.5) +0.50000000000000000000 + +julia> d = RR(12) +12.000000000000000000 ``` Note that whilst one can coerce double precision floating point values into an @@ -81,18 +89,22 @@ ball(::ArbFieldElem, ::ArbFieldElem) **Examples** -```julia -RR = ArbField(64) +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds -c = ball(RR(3), RR("0.0001")) +julia> c = ball(RR(3), RR("0.0001")) +[3.000 +/- 1.01e-4] ``` ### Conversions -```julia -RR = ArbField(64) +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds -convert(Float64, RR(1//3)) +julia> convert(Float64, RR(1//3)) +0.3333333333333333 ``` ### Basic manipulation @@ -143,19 +155,36 @@ accuracy_bits(::ArbFieldElem) **Examples** -```julia -RR = ArbField(64) +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds + +julia> a = RR("1.2 +/- 0.001") +[1.20 +/- 1.01e-3] + +julia> b = RR(3) +3.0000000000000000000 + +julia> is_positive(a) +true -a = RR("1.2 +/- 0.001") -b = RR(3) +julia> isfinite(b) +true -is_positive(a) -isfinite(b) -isinteger(b) -is_negative(a) -c = radius(a) -d = midpoint(b) -f = accuracy_bits(a) +julia> isinteger(b) +true + +julia> is_negative(a) +false + +julia> c = radius(a) +[0.0010000000038417056203 +/- 1.12e-23] + +julia> d = midpoint(b) +3.0000000000000000000 + +julia> f = accuracy_bits(a) +9 ``` ### Printing @@ -251,17 +280,33 @@ contains_nonpositive(::ArbFieldElem) **Examples** -```julia -RR = ArbField(64) -x = RR("1 +/- 0.001") -y = RR("3") +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds + +julia> x = RR("1 +/- 0.001") +[1.00 +/- 1.01e-3] + +julia> y = RR("3") +3.0000000000000000000 + +julia> overlaps(x, y) +false + +julia> contains(x, y) +false -overlaps(x, y) -contains(x, y) -contains(y, 3) -contains(x, ZZ(1)//2) -contains_zero(x) -contains_positive(y) +julia> contains(y, 3) +true + +julia> contains(x, ZZ(1)//2) +false + +julia> contains_zero(x) +false + +julia> contains_positive(y) +true ``` ### Comparison @@ -302,39 +347,66 @@ Function | **Examples** -```julia -RR = ArbField(64) -x = RR("1 +/- 0.001") -y = RR("3") -z = RR("4") +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds + +julia> x = RR("1 +/- 0.001") +[1.00 +/- 1.01e-3] + +julia> y = RR("3") +3.0000000000000000000 + +julia> z = RR("4") +4.0000000000000000000 + +julia> isequal(x, deepcopy(x)) +true -isequal(x, deepcopy(x)) -x == 3 -ZZ(3) < z -x != 1.23 +julia> x == 3 +false + +julia> ZZ(3) < z +true + +julia> x != 1.23 +true + +julia> 3 == y +true ``` ### Absolute value **Examples** -```julia -RR = ArbField(64) -x = RR("-1 +/- 0.001") +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds + +julia> x = RR("-1 +/- 0.001") +[-1.00 +/- 1.01e-3] -a = abs(x) +julia> a = abs(x) +[1.00 +/- 1.01e-3] ``` ### Shifting **Examples** -```julia -RR = ArbField(64) -x = RR("-3 +/- 0.001") +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds -a = ldexp(x, 23) -b = ldexp(x, -ZZ(15)) +julia> x = RR("-3 +/- 0.001") +[-3.00 +/- 1.01e-3] + +julia> a = ldexp(x, 23) +[-2.52e+7 +/- 4.26e+4] + +julia> b = ldexp(x, -ZZ(15)) +[-9.16e-5 +/- 7.78e-8] ``` ### Miscellaneous operations @@ -357,14 +429,24 @@ setunion(::ArbFieldElem, ::ArbFieldElem) **Examples** -```julia -RR = ArbField(64) -x = RR("-3 +/- 0.001") -y = RR("2 +/- 0.5") +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds -a = trim(x) -b, c = unique_integer(x) -d = setunion(x, y) +julia> x = RR("-3 +/- 0.001") +[-3.00 +/- 1.01e-3] + +julia> y = RR("2 +/- 0.5") +[2e+0 +/- 0.501] + +julia> a = trim(x) +[-3.00 +/- 1.01e-3] + +julia> b, c = unique_integer(x) +(true, -3) + +julia> d = setunion(x, y) +[+/- 3.01] ``` ### Constants @@ -403,13 +485,21 @@ const_glaisher(::ArbField) **Examples** -```julia -RR = ArbField(200) +```jldoctest +julia> RR = ArbField(200) +Real Field with 200 bits of precision and error bounds + +julia> a = const_pi(RR) +[3.14159265358979323846264338327950288419716939937510582097494 +/- 5.73e-60] -a = const_pi(RR) -b = const_e(RR) -c = const_euler(RR) -d = const_glaisher(RR) +julia> b = const_e(RR) +[2.71828182845904523536028747135266249775724709369995957496697 +/- 7.06e-60] + +julia> c = const_euler(RR) +[0.577215664901532860606512090082402431042159335939923598805767 +/- 5.37e-61] + +julia> d = const_glaisher(RR) +[1.28242712910062263687534256886979172776768892732500119206374 +/- 2.18e-60] ``` ### Mathematical and special functions @@ -584,14 +674,24 @@ airy_bi_prime(::ArbFieldElem) **Examples** -```julia -RR = ArbField(64) +```jldoctest +julia> RR = ArbField(64) +Real Field with 64 bits of precision and error bounds + +julia> a = floor(exp(RR(1))) +2.0000000000000000000 -a = floor(exp(RR(1))) -b = sinpi(QQ(5,6), RR) -c = gamma(QQ(1,3), ArbField(256)) -d = bernoulli(1000, ArbField(53)) -f = polylog(3, RR(-10)) +julia> b = sinpi(QQ(5,6), RR) +0.50000000000000000000 + +julia> c = gamma(QQ(1,3), ArbField(256)) +[2.6789385347077476336556929409746776441286893779573011009504283275904176101677 +/- 6.71e-77] + +julia> d = bernoulli(1000, ArbField(53)) +[-5.318704469415522e+1769 +/- 8.20e+1753] + +julia> f = polylog(3, RR(-10)) +[-5.92106480375697 +/- 6.68e-15] ``` ### Linear dependence @@ -602,26 +702,36 @@ lindep(::Vector{ArbFieldElem}, n::Int) **Examples** -```julia -RR = ArbField(128) +```jldoctest +julia> RR = ArbField(128) +Real Field with 128 bits of precision and error bounds + +julia> a = RR(-0.33198902958450931620250069492231652319) # real root of x^5 + 3x + 1 +[-0.331989029584509320880414406929048709571 +/- 3.62e-40] -a = RR(-0.33198902958450931620250069492231652319) +julia> V = [RR(1), a, a^2, a^3, a^4, a^5] +6-element Vector{ArbFieldElem}: + 1.00000000000000000000000000000000000000 + [-0.331989029584509320880414406929048709571 +/- 3.62e-40] + [0.110216715764464205102727554344054759368 +/- 3.32e-40] + [-0.0365907405106361618384680031506015710184 +/- 8.30e-41] + [0.0121477244339046924274232580429164920524 +/- 2.83e-41] + [-0.00403291124647205167662794872826031818905 +/- 7.87e-42] -V = [RR(1), a, a^2, a^3, a^4, a^5] -W = lindep(V, 20) +julia> W = lindep(V, 20) +6-element Vector{ZZRingElem}: + 1 + 3 + 0 + 0 + 0 + 1 ``` ```@docs simplest_rational_inside(::ArbFieldElem) ``` -**Examples** - -```julia -RR = ArbField(64) -simplest_rational_inside(const_pi(RR)) -``` - ### Random generation ```@docs diff --git a/docs/src/complex.md b/docs/src/complex.md index f656cbb160..9dfb18e5bd 100644 --- a/docs/src/complex.md +++ b/docs/src/complex.md @@ -51,13 +51,21 @@ parent object to coerce values into the resulting field. **Examples** -```julia -CC = ComplexField() +```jldoctest +julia> CC = ComplexField() +Complex field + +julia> a = CC("0.25") +0.25000000000000000000 + +julia> b = CC("0.1") +[0.100000000000000000 +/- 1.22e-20] -a = CC("0.25") -b = CC("0.1") -c = CC(0.5) -d = CC(12) +julia> c = CC(0.5) +0.50000000000000000000 + +julia> d = CC(12) +12.000000000000000000 ``` Note that whilst one can coerce double precision floating point values into an @@ -81,10 +89,9 @@ onei(::ComplexField) **Examples** -```julia -CC = ComplexField() - -c = onei(CC) +```jldoctest; setup = :(CC = ComplexField()) +julia> c = onei(CC) +1.0000000000000000000*im ``` ## Basic functionality @@ -235,18 +242,30 @@ accuracy_bits(::ComplexFieldElem) **Examples** -```julia -CC = ComplexField() +```jldoctest; setup = :(CC = ComplexField()) +julia> a = CC("1.2 +/- 0.001") +[1.20 +/- 1.01e-3] + +julia> b = CC(3) +3.0000000000000000000 + +julia> isreal(a) +true + +julia> isfinite(b) +true + +julia> isinteger(b) +true -a = CC("1.2 +/- 0.001") -b = CC(3) +julia> c = real(a) +[1.20 +/- 1.01e-3] -isreal(a) -isfinite(b) -isinteger(b) -c = real(a) -d = imag(b) -f = accuracy_bits(a) +julia> d = imag(b) +0 + +julia> f = accuracy_bits(a) +9 ``` ### Containment @@ -278,16 +297,27 @@ contains_zero(::ComplexFieldElem) **Examples** -```julia -CC = ComplexField() -x = CC("1 +/- 0.001") -y = CC("3") +```jldoctest; setup = :(CC = ComplexField()) +julia> x = CC("1 +/- 0.001") +[1.00 +/- 1.01e-3] -overlaps(x, y) -contains(x, y) -contains(y, 3) -contains(x, ZZ(1)//2) -contains_zero(x) +julia> y = CC("3") +3.0000000000000000000 + +julia> overlaps(x, y) +false + +julia> contains(x, y) +false + +julia> contains(y, 3) +true + +julia> contains(x, ZZ(1)//2) +false + +julia> contains_zero(x) +false ``` ### Comparison @@ -318,39 +348,54 @@ Function | **Examples** -```julia -CC = ComplexField() -x = CC("1 +/- 0.001") -y = CC("3") -z = CC("4") +```jldoctest; setup = :(CC = ComplexField()) +julia> x = CC("1 +/- 0.001") +[1.00 +/- 1.01e-3] + +julia> y = CC("3") +3.0000000000000000000 + +julia> z = CC("4") +4.0000000000000000000 + +julia> isequal(x, deepcopy(x)) +true + +julia> x == 3 +false + +julia> ZZ(3) == y +true -isequal(x, deepcopy(x)) -x == 3 -ZZ(3) == z -x != 1.23 +julia> z != 1.23 +true ``` ### Absolute value **Examples** -```julia -CC = ComplexField() -x = CC("-1 +/- 0.001") +```jldoctest; setup = :(CC = ComplexField()) +julia> x = CC("-1 +/- 0.001") +[-1.00 +/- 1.01e-3] -a = abs(x) +julia> a = abs(x) +[1.00 +/- 1.01e-3] ``` ### Shifting **Examples** -```julia -CC = ComplexField() -x = CC("-3 +/- 0.001") +```jldoctest; setup = :(CC = ComplexField()) +julia> x = CC("-3 +/- 0.001") +[-3.00 +/- 1.01e-3] -a = ldexp(x, 23) -b = ldexp(x, -ZZ(15)) +julia> a = ldexp(x, 23) +[-2.52e+7 +/- 4.26e+4] + +julia> b = ldexp(x, -ZZ(15)) +[-9.16e-5 +/- 7.78e-8] ``` ### Miscellaneous operations @@ -365,14 +410,21 @@ unique_integer(::ComplexFieldElem) **Examples** -```julia -CC = ComplexField() -x = CC("-3 +/- 0.001", "0.1") +```jldoctest; setup = :(CC = ComplexField()) +julia> x = CC("-3 +/- 0.001", "0.1") +[-3.00 +/- 1.01e-3] + [0.100000000000000000 +/- 1.22e-20]*im -a = trim(x) -b, c = unique_integer(x) -d = conj(x) -f = angle(x) +julia> a = trim(x) +[-3.00 +/- 1.01e-3] + [0.100000000000000000 +/- 1.22e-20]*im + +julia> b, c = unique_integer(x) +(false, 0) + +julia> d = conj(x) +[-3.00 +/- 1.01e-3] + [-0.100000000000000000 +/- 1.22e-20]*im + +julia> f = angle(x) +[3.1083 +/- 3.95e-5] ``` ### Constants @@ -620,16 +672,24 @@ weierstrass_p(::ComplexFieldElem, ::ComplexFieldElem) **Examples** -```julia -CC = ComplexField() +```jldoctest; setup = :(CC = ComplexField()) +julia> s = CC(1, 2) +1.0000000000000000000 + 2.0000000000000000000*im + +julia> z = CC("1.23", "3.45") +[1.230000000000000000 +/- 2.00e-19] + [3.450000000000000000 +/- 3.91e-19]*im + +julia> a = sin(z)^2 + cos(z)^2 +[1.000000000000000 +/- 4.92e-16] + [+/- 4.12e-16]*im -s = CC(1, 2) -z = CC("1.23", "3.45") +julia> b = zeta(z) +[0.685803329024164062 +/- 6.30e-19] + [-0.038574782404586856 +/- 7.54e-19]*im -a = sin(z)^2 + cos(z)^2 -b = zeta(z) -c = bessel_j(s, z) -d = hypergeometric_1f1(s, s+1, z) +julia> c = bessel_j(s, z) +[0.63189634741402481 +/- 4.85e-18] + [0.00970090757446076 +/- 4.66e-18]*im + +julia> d = hypergeometric_1f1(s, s+1, z) +[-1.3355297330012291 +/- 5.83e-17] + [-0.1715020340928697 +/- 4.97e-17]*im ``` ### Linear dependence @@ -644,20 +704,40 @@ lindep(A::Matrix{ComplexFieldElem}, bits::Int) **Examples** -```julia -CC = ComplexField() - -# These are two of the roots of x^5 + 3x + 1 -a = CC(1.0050669478588622428791051888364775253, - 0.93725915669289182697903585868761513585) -b = CC(-0.33198902958450931620250069492231652319) - -# We recover the polynomial from one root.... -V1 = [CC(1), a, a^2, a^3, a^4, a^5]; -W = lindep(V1, 20) - -# ...or from two -V2 = [CC(1), b, b^2, b^3, b^4, b^5]; -Vs = [V1 V2] -X = lindep(Vs, 20) +```jldoctest; setup = :(CC = ComplexField()) +julia> # These are two of the roots of x^5 + 3x + 1 + +julia> a = CC(1.0050669478588622428791051888364775253, -0.93725915669289182697903585868761513585) +[1.0050669478588623029 +/- 2.25e-20] - [0.93725915669289183718 +/- 1.50e-21]*im + +julia> b = CC(-0.33198902958450931620250069492231652319) +-[0.33198902958450932088 +/- 4.15e-22] + +julia> V1 = [CC(1), a, a^2, a^3, a^4, a^5]; # We recover the polynomial from one root.... + +julia> W = lindep(V1, 20) +6-element Vector{ZZRingElem}: + 1 + 3 + 0 + 0 + 0 + 1 + +julia> V2 = [CC(1), b, b^2, b^3, b^4, b^5]; # ...or from two + +julia> Vs = [V1 V2] +6×2 Matrix{ComplexFieldElem}: + 1.0000000000000000000 … 1.0000000000000000000 + [1.0050669478588623029 +/- 2.25e-20] - [0.93725915669289183718 +/- 1.50e-21]*im -[0.33198902958450932088 +/- 4.15e-22] + [0.1317048428736582616 +/- 2.21e-20] + [-1.884016399940191946 +/- 3.53e-19]*im [0.11021671576446420510 +/- 7.87e-21] + [-1.633439437758263598 +/- 4.96e-19] + [-2.01700418276806513 +/- 4.04e-18]*im [-0.03659074051063616184 +/- 4.17e-21] + [-3.53217162960722628 +/- 9.36e-19] + [-0.496268167851036565 +/- 1.73e-19]*im [0.01214772443390469243 +/- 5.99e-21] + [-4.015200843576587814 +/- 4.39e-19] + [2.811777470078675512 +/- 2.01e-19]*im … [-0.004032911246472051677 +/- 6.25e-22] + +julia> X = lindep(Vs, 20) +2-element Vector{ZZRingElem}: + 0 + 1 ``` From f610086f7d932e07b14d246281854c26e42b0b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 9 Apr 2024 17:38:28 +0200 Subject: [PATCH 7/9] Add missing meta --- docs/src/constructors.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/src/constructors.md b/docs/src/constructors.md index 7ddcefc1a2..8066210077 100644 --- a/docs/src/constructors.md +++ b/docs/src/constructors.md @@ -1,3 +1,10 @@ +```@meta +CurrentModule = Nemo +DocTestSetup = quote + using Nemo +end +``` + # Constructing mathematical objects in Nemo ## Constructing objects in Julia From 60c7660b599f555114987afd4d3b6ae77b2446b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 11:14:11 +0200 Subject: [PATCH 8/9] Update docs/src/acb.md Co-authored-by: Max Horn --- docs/src/acb.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/docs/src/acb.md b/docs/src/acb.md index a6e63b0215..3bd1a59296 100644 --- a/docs/src/acb.md +++ b/docs/src/acb.md @@ -751,14 +751,7 @@ julia> W = lindep(V1, 20) julia> V2 = [CC(1), b, b^2, b^3, b^4, b^5]; # ...or from two -julia> Vs = [V1 V2] -6×2 Matrix{AcbFieldElem}: - 1.00000000000000000000000000000000000000 … 1.00000000000000000000000000000000000000 - [1.00506694785886230292248910700436681509 +/- 1.80e-40] - [0.937259156692891837181491609953809529543 +/- 7.71e-41]*im -[0.331989029584509320880414406929048709571 +/- 3.62e-40] - [0.131704842873658261608907475851071865533 +/- 2.43e-40] - [1.88401639994019194629934002026077386471 +/- 2.35e-39]*im [0.110216715764464205102727554344054759368 +/- 3.32e-40] - [-1.63343943775826359832802955077858762779 +/- 7.18e-39] + [-2.0170041827680651335098567246278775869 +/- 5.08e-38]*im [-0.0365907405106361618384680031506015710184 +/- 8.30e-41] - [-3.5321716296072262805776584101060548180 +/- 5.08e-38] + [-0.49626816785103656510289466486482917885 +/- 2.35e-39]*im [0.0121477244339046924274232580429164920524 +/- 8.57e-41] - [-4.01520084357658781437077178965706076158 +/- 5.97e-39] + [2.81177747007867551213313071756269751169 +/- 3.99e-39]*im … [-0.00403291124647205167662794872826031818905 +/- 7.87e-42] +julia> Vs = [V1 V2]; julia> X = lindep(Vs, 20) 2-element Vector{ZZRingElem}: From 265cbe0f517ba7f9e289ba379457dd431d8c01de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 12:13:28 +0200 Subject: [PATCH 9/9] Address comments --- docs/src/acb.md | 8 ++++++-- docs/src/complex.md | 15 ++++++--------- docs/src/constructors.md | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/docs/src/acb.md b/docs/src/acb.md index 3bd1a59296..3e5d57ec2e 100644 --- a/docs/src/acb.md +++ b/docs/src/acb.md @@ -751,10 +751,14 @@ julia> W = lindep(V1, 20) julia> V2 = [CC(1), b, b^2, b^3, b^4, b^5]; # ...or from two -julia> Vs = [V1 V2]; +julia> Vs = [transpose(V1); transpose(V2)]; julia> X = lindep(Vs, 20) -2-element Vector{ZZRingElem}: +6-element Vector{ZZRingElem}: + 1 + 3 + 0 + 0 0 1 ``` diff --git a/docs/src/complex.md b/docs/src/complex.md index 9dfb18e5bd..205b5f77df 100644 --- a/docs/src/complex.md +++ b/docs/src/complex.md @@ -726,17 +726,14 @@ julia> W = lindep(V1, 20) julia> V2 = [CC(1), b, b^2, b^3, b^4, b^5]; # ...or from two -julia> Vs = [V1 V2] -6×2 Matrix{ComplexFieldElem}: - 1.0000000000000000000 … 1.0000000000000000000 - [1.0050669478588623029 +/- 2.25e-20] - [0.93725915669289183718 +/- 1.50e-21]*im -[0.33198902958450932088 +/- 4.15e-22] - [0.1317048428736582616 +/- 2.21e-20] + [-1.884016399940191946 +/- 3.53e-19]*im [0.11021671576446420510 +/- 7.87e-21] - [-1.633439437758263598 +/- 4.96e-19] + [-2.01700418276806513 +/- 4.04e-18]*im [-0.03659074051063616184 +/- 4.17e-21] - [-3.53217162960722628 +/- 9.36e-19] + [-0.496268167851036565 +/- 1.73e-19]*im [0.01214772443390469243 +/- 5.99e-21] - [-4.015200843576587814 +/- 4.39e-19] + [2.811777470078675512 +/- 2.01e-19]*im … [-0.004032911246472051677 +/- 6.25e-22] +julia> Vs = [transpose(V1); transpose(V2)]; julia> X = lindep(Vs, 20) -2-element Vector{ZZRingElem}: +6-element Vector{ZZRingElem}: + 1 + 3 + 0 + 0 0 1 ``` diff --git a/docs/src/constructors.md b/docs/src/constructors.md index 8066210077..d7e26a49e7 100644 --- a/docs/src/constructors.md +++ b/docs/src/constructors.md @@ -14,7 +14,7 @@ with the same name as the type itself. For example, to construct a `BigInt` obje call the `BigInt` constructor: ```jldoctest -julia> n = parse(BigInt, "1234567898765434567898765434567876543456787654567890") +julia> BigInt(1234567898765434567898765434567876543456787654567890) 1234567898765434567898765434567876543456787654567890 ``` @@ -37,7 +37,7 @@ refer to as parent objects. They behave a lot like Julia types. Consider the following simple example, to create a Flint multiprecision integer: ```jldoctest -julia> n = ZZ("12345678765456787654567890987654567898765678909876567890") +julia> n = ZZ(12345678765456787654567890987654567898765678909876567890) 12345678765456787654567890987654567898765678909876567890 ```