Introduction

Arbitrary precision real ball arithmetic is supplied by Arb which provides a ball representation which tracks error bounds rigorously. Real numbers are represented in mid-rad interval form .

The Arb real field is constructed using the ArbField constructor. This constructs the parent object for the Arb real field.

However, we define

RealField = ArbField

so that one can construct the Arb real field parent object using RealField instead of ArbField.

The types of real balls in Nemo are given in the following table, along with the libraries that provide them and the associated types of the parent objects.

LibraryFieldElement typeParent type
Arb (balls)arbArbField

All the real field types belong to the Field abstract type and the types of elements in this field, i.e. balls in this case, belong to the FieldElem abstract type.

Real field constructors

In order to construct real balls in Nemo, one must first construct the Arb real field itself. This is accomplished with the following constructor.

ArbField(prec::Int)

Return the Arb field with precision in bits prec used for operations on interval midpoints. The precision used for interval radii is a fixed implementation-defined constant (30 bits).

We define

RealField = ArbField

so that one can use RealField in place of ArbField.

Here is an example of creating an Arb real field and using the resulting parent object to coerce values into the resulting field.

RR = RealField(64)

a = RR("0.25")
b = RR("0.1")
c = RR(0.5)
d = RR(12)

Note that whilst one can coerce double precision floating point values into an Arb real field, unless those values can be represented exactly in double precision, the resulting ball can't be any more precise than the double precision supplied.

If instead, values can be represented precisely using decimal arithmetic then one can supply them to Arb using a string. In this case, Arb will store them to the precision specified when creating the Arb field.

If the values can be stored precisely as a binary floating point number, Arb will store the values exactly. See the function isexact below for more information.

Real ball constructors

Once an Arb real field is constructed, there are various ways to construct balls in that field.

Apart from coercing elements into the Arb real field as above, we offer the following functions.

#Base.zeroMethod.

zero(R::ArbField)

Return exact zero in the given Arb field.

source

#Base.oneMethod.

one(R::ArbField)

Return exact one in the given Arb field.

source

#Nemo.ballMethod.

ball(mid::arb, rad::arb)

Constructs an arb enclosing the range , given the pair .

source

Here are some examples of constructing balls.

RR = RealField(64)

a = zero(RR)
b = one(RR)
c = ball(RR(3), RR("0.0001"))

Basic functionality

The following basic functionality is provided by the default Arb real field implementation in Nemo, to support construction of generic rings over real fields. Any custom real field implementation in Nemo should provide analogues of these functions along with the usual arithmetic operations.

parent_type(::Type{arb})

Gives the type of the parent object of an Arb real field element.

elem_type(R::ArbField)

Given the parent object for a Arb field, return the type of elements of the field.

mul!(c::arb, a::arb, b::arb)

Multiply by and set the existing Arb field element to the result. This function is provided for performance reasons as it saves allocating a new object for the result and eliminates associated garbage collection.

addeq!(c::arb, a::arb)

In-place addition. Adds to and sets to the result. This function is provided for performance reasons as it saves allocating a new object for the result and eliminates associated garbage collection.

deepcopy(a::arb)

Return a copy of the Arb field element , recursively copying the internal data. Arb field elements are mutable in Nemo so a shallow copy is not sufficient.

Given the parent object R for an Arb real field, the following coercion functions are provided to coerce various elements into the Arb field. Developers provide these by overloading the call operator for the real field parent objects.

R()

Coerce zero into the Arb field.

R(n::Integer)
R(f::fmpz)
R(q::fmpq)

Coerce an integer or rational value into the Arb field.

R(f::Float64)
R(f::BigFloat)

Coerce the given floating point number into the Arb field.

R(f::AbstractString)

Coerce the decimal number, given as a string, into the Arb field.

R(f::arb)

Take an Arb field element that is already in the Arb field and simply return it. A copy of the original is not made.

Here are some examples of coercing elements into the Arb field.

RR = RealField(64)

a = RR(3)
b = RR(QQ(2,3))
c = ball(RR(3), RR("0.0001"))
d = RR("3 +/- 0.0001")
f = RR("-1.24e+12345")
g = RR("nan +/- inf")

In addition to the above, developers of custom real field types must ensure that they provide the equivalent of the function base_ring(R::ArbField) which should return Union{}. In addition to this they should ensure that each real field element contains a field parent specifying the parent object of the real field element, or at least supply the equivalent of the function parent(a::arb) to return the parent object of a real field element.

Conversions

#Base.convertMethod.

convert(::Type{Float64}, x::arb)

Return the midpoint of rounded down to a machine double.

source

Basic manipulation

Numerous functions are provided to manipulate Arb field elements. Also see the section on basic functionality above.

#Nemo.base_ringMethod.

base_ring(R::ArbField)

Returns Union{} since an Arb field does not depend on any other ring.

source

#Nemo.base_ringMethod.

base_ring(x::arb)

Returns Union{} since an Arb field does not depend on any other ring.

source

#Base.parentMethod.

parent(x::arb)

Return the parent of the given Arb field element.

source

#Nemo.iszeroMethod.

iszero(x::arb)

Return true if is certainly zero, otherwise return false.

source

#Nemo.isnonzeroMethod.

isnonzero(x::arb)

Return true if is certainly not equal to zero, otherwise return false.

source

#Nemo.isoneMethod.

isone(x::arb)

Return true if is certainly not equal to oneo, otherwise return false.

source

#Base.isfiniteMethod.

isfinite(x::arb)

Return true if is finite, i.e. having finite midpoint and radius, otherwise return false.

source

#Nemo.isexactMethod.

isexact(x::arb)

Return true if is exact, i.e. has zero radius, otherwise return false.

source

#Nemo.isintMethod.

isint(x::arb)

Return true if is an exact integer, otherwise return false.

source

#Nemo.ispositiveMethod.

ispositive(x::arb)

Return true if is certainly positive, otherwise return false.

source

#Nemo.isnonnegativeMethod.

isnonnegative(x::arb)

Return true if is certainly nonnegative, otherwise return false.

source

#Nemo.isnegativeMethod.

isnegative(x::arb)

Return true if is certainly negative, otherwise return false.

source

#Nemo.isnonpositiveMethod.

isnonpositive(x::arb)

Return true if is certainly nonpositive, otherwise return false.

source

#Nemo.midpointMethod.

midpoint(x::arb)

Return the midpoint of the ball as an Arb ball.

source

#Nemo.radiusMethod.

radius(x::arb)

Return the radius of the ball as an Arb ball.

source

#Nemo.accuracy_bitsMethod.

accuracy_bits(x::arb)

Return the relative accuracy of measured in bits, capped between typemax(Int) and -typemax(Int).

source

Here are some examples of basic manipulation of Arb balls.

RR = RealField(64)

a = RR("1.2 +/- 0.001")
b = RR(3)

iszero(a)
isone(b)
ispositive(a)
isfinite(b)
isint(b)
isnegative(a)
c = radius(a)
d = midpoint(b)
f = accuracy_bits(a)
S = parent(a)
T = base_ring(RR)

Arithmetic operations

Nemo provides all the standard field operations for Arb field elements, as follows. Note that division is represented by // since a field is its own fraction field and since exact division is not generally possible in an inexact field.

FunctionOperation
-(a::arb)unary minus
+(a::arb, b::arb)addition
-(a::arb, b::arb)subtraction
*(a::arb, b::arb)multiplication
//(a::arb, b::arb)division
^(a::arb, b::arb)powering

In addition, the following ad hoc field operations are defined.

FunctionOperation
+(a::arb, b::Integer)addition
+(a::Integer, b::arb)addition
+(a::arb, b::fmpz)addition
+(a::fmpz, b::arb)addition
-(a::arb, b::Integer)subtraction
-(a::Integer, b::arb)subtraction
-(a::arb, b::fmpz)subtraction
-(a::fmpz, b::arb)subtraction
*(a::arb, b::Integer)multiplication
*(a::Integer, b::arb)multiplication
*(a::arb, b::fmpz)multiplication
*(a::fmpz, b::arb)multiplication
//(a::arb, b::Integer)division
//(a::arb, b::fmpz)division
//(a::Integer, b::arb)division
//(a::fmpz, b::arb)division
^(a::arb, b::Integer)powering
^(a::arb, b::fmpz)powering
^(a::arb, b::fmpq)powering

Here are some examples of arithmetic operations on Arb balls.

RR = RealField(64)

x = RR(3)
y = RR(QQ(2,3))

a = x + y
b = x*y
d = 1//y - x
d = 3x + ZZ(100)//y
f = (x^2 + y^2) ^ QQ(1,2)

Containment

It is often necessary to determine whether a given exact value or ball is contained in a given real ball or whether two balls overlap. The following functions are provided for this purpose.

#Nemo.overlapsMethod.

overlaps(x::arb, y::arb)

Returns true if any part of the ball overlaps any part of the ball , otherwise return false.

source

#Base.containsMethod.

contains(x::arb, y::arb)

Returns true if the ball contains the ball , otherwise return false.

source

#Base.containsMethod.

contains(x::arb, y::Integer)

Returns true if the ball contains the given integer value, otherwise return false.

source

#Base.containsMethod.

contains(x::arb, y::fmpz)

Returns true if the ball contains the given integer value, otherwise return false.

source

#Base.containsMethod.

contains(x::arb, y::fmpq)

Returns true if the ball contains the given rational value, otherwise return false.

source

#Base.containsMethod.

contains(x::arb, y::Rational{Integer})

Returns true if the ball contains the given rational value, otherwise return false.

source

#Base.containsMethod.

contains(x::arb, y::BigFloat)

Returns true if the ball contains the given floating point value, otherwise return false.

source

The following functions are also provided for determining if a ball intersects a certain part of the real number line.

#Nemo.contains_zeroMethod.

contains_zero(x::arb)

Returns true if the ball contains zero, otherwise return false.

source

#Nemo.contains_negativeMethod.

contains_negative(x::arb)

Returns true if the ball contains any negative value, otherwise return false.

source

#Nemo.contains_positiveMethod.

contains_positive(x::arb)

Returns true if the ball contains any positive value, otherwise return false.

source

#Nemo.contains_nonnegativeMethod.

contains_nonnegative(x::arb)

Returns true if the ball contains any nonnegative value, otherwise return false.

source

#Nemo.contains_nonpositiveMethod.

contains_nonpositive(x::arb)

Returns true if the ball contains any nonpositive value, otherwise return false.

source

Here are some examples of testing containment.

RR = RealField(64)
x = RR("1 +/- 0.001")
y = RR("3")

overlaps(x, y)
contains(x, y)
contains(y, 3)
contains(x, ZZ(1)//2)
contains_zero(x)
contains_positive(y)

Comparison

Nemo provides a full range of comparison operations for Arb balls. Note that a ball is considered less than another ball if every value in the first ball is less than every value in the second ball, etc.

Firstly, we introduce an exact equality which is distinct from arithmetic equality. This is distinct from arithmetic equality implemented by ==, which merely compares up to the minimum of the precisions of its operands.

#Base.isequalMethod.

isequal(x::arb, y::arb)

Return true if the balls and are precisely equal, i.e. have the same midpoints and radii.

source

A full range of functions is available for comparing balls, i.e. ==, !=, <, <=, >=, >. In fact, all these are implemented directly in C. In the table below we document these as though only == and isless had been provided to Julia.

Function

isless(x::arb, y::arb)==(x::arb, y::arb)

As well as these, we provide a full range of ad hoc comparison operators. Again, these are implemented directly in Julia, but we document them as though isless and == were provided.

Function

==(x::arb, y::Integer)==(x::Integer, y::arb)==(x::arb, y::fmpz)==(x::fmpz, y::arb)==(x::arb, y::Float64)==(x::Float64, y::arb)isless(x::arb, y::Integer)isless(x::Integer, y::arb)isless(x::arb, y::fmpz)isless(x::fmpz, y::arb)isless(x::arb, y::Float64)isless(x::Float64, y::arb)isless(x::arb, y::BigFloat)isless(x::BigFloat, y::arb)isless(x::arb, y::fmpq)isless(x::fmpq, y::arb)

Here are some examples of comparison.

RR = RealField(64)
x = RR("1 +/- 0.001")
y = RR("3")
z = RR("4")

isequal(y, z)
x <= z
x == 3
ZZ(3) < z
x != 1.23

Absolute value

#Base.absMethod.

abs(x::arb)

Return the absolute value of .

source

Here are some examples of taking the absolute value.

RR = RealField(64)
x = RR("-1 +/- 0.001")

a = abs(x)

Inverse

#Base.invMethod.

inv(x::arb)

Return the multiplicative inverse of , i.e. .

source

Here are some examples of taking the inverse.

RR = RealField(64)
x = RR("-3 +/- 0.001")

a = inv(x)

Shifting

#Base.Math.ldexpMethod.

ldexp(x::arb, y::Int)

Return . Note that can be positive, zero or negative.

source

#Base.Math.ldexpMethod.

ldexp(x::arb, y::fmpz)

Return . Note that can be positive, zero or negative.

source

Here are some examples of shifting.

RR = RealField(64)
x = RR("-3 +/- 0.001")

a = ldexp(x, 23)
b = ldexp(x, -ZZ(15))

Miscellaneous operations

#Nemo.trimMethod.

trim(x::arb)

Return an arb interval containing but which may be more economical, by rounding off insignificant bits from the midpoint.

source

#Nemo.unique_integerMethod.

unique_integer(x::arb)

Return a pair where the first value is a boolean and the second is an fmpz integer. The boolean indicates whether the interval contains a unique integer. If this is the case, the second return value is set to this unique integer.

source

#Nemo.setunionMethod.

setunion(x::arb, y::arb)

Return an arb containing the union of the intervals represented by and .

source

Here are some examples of miscellaneous operations.

RR = RealField(64)
x = RR("-3 +/- 0.001")
y = RR("2 +/- 0.5")

a = trim(x)
b, c = unique_integer(x)
d = setunion(x, y)

Constants

#Nemo.const_piMethod.

const_pi(r::ArbField)

Return as an element of .

source

#Nemo.const_eMethod.

const_e(r::ArbField)

Return as an element of .

source

#Nemo.const_log2Method.

const_log2(r::ArbField)

Return as an element of .

source

#Nemo.const_log10Method.

const_log10(r::ArbField)

Return as an element of .

source

#Nemo.const_eulerMethod.

const_euler(r::ArbField)

Return Euler's constant as an element of .

source

#Nemo.const_catalanMethod.

const_catalan(r::ArbField)

Return Catalan's constant as an element of .

source

#Nemo.const_khinchinMethod.

const_khinchin(r::ArbField)

Return Khinchin's constant as an element of .

source

#Nemo.const_glaisherMethod.

const_glaisher(r::ArbField)

Return Glaisher's constant as an element of .

source

Here are some examples of computing real constants.

RR = RealField(200)

a = const_pi(RR)
b = const_e(RR)
c = const_euler(RR)
d = const_glaisher(RR)

Mathematical functions

#Base.floorMethod.

floor(x::arb)

Compute the floor of , i.e. the greatest integer not exceeding , as an Arb.

source

#Base.ceilMethod.

ceil(x::arb)

Return the ceiling of , i.e. the least integer not less than , as an Arb.

source

#Base.sqrtMethod.

sqrt(x::arb)

Return the square root of .

source

#Nemo.rsqrtMethod.

rsqrt(x::arb)

Return the reciprocal of the square root of , i.e. .

source

#Nemo.sqrt1pm1Method.

sqrt1pm1(x::arb)

Return , evaluated accurately for small .

source

#Base.logMethod.

log(x::arb)

Return the principal branch of the logarithm of .

source

#Base.log1pMethod.

log1p(x::arb)

Return , evaluated accurately for small .

source

#Base.expMethod.

exp(x::arb)

Return the exponential of .

source

#Base.expm1Method.

expm1(x::arb)

Return , evaluated accurately for small .

source

#Base.sinMethod.

sin(x::arb)

Return the sine of .

source

#Base.cosMethod.

cos(x::arb)

Return the cosine of .

source

#Base.Math.sinpiMethod.

sinpi(x::arb)

Return the sine of .

source

#Base.Math.cospiMethod.

cospi(x::arb)

Return the cosine of .

source

#Base.tanMethod.

tan(x::arb)

Return the tangent of .

source

#Base.Math.cotMethod.

cot(x::arb)

Return the cotangent of .

source

#Nemo.tanpiMethod.

tanpi(x::arb)

Return the tangent of .

source

#Nemo.cotpiMethod.

cotpi(x::arb)

Return the cotangent of .

source

#Base.sinhMethod.

sinh(x::arb)

Return the hyperbolic sine of .

source

#Base.coshMethod.

cosh(x::arb)

Return the hyperbolic cosine of .

source

#Base.tanhMethod.

tanh(x::arb)

Return the hyperbolic tangent of .

source

#Base.Math.cothMethod.

coth(x::arb)

Return the hyperbolic cotangent of .

source

#Base.atanMethod.

atan(x::arb)

Return the arctangent of .

source

#Base.asinMethod.

asin(x::arb)

Return the arcsine of .

source

#Base.acosMethod.

acos(x::arb)

Return the arccosine of .

source

#Base.atanhMethod.

atanh(x::arb)

Return the hyperbolic arctangent of .

source

#Base.asinhMethod.

asinh(x::arb)

Return the hyperbolic arcsine of .

source

#Base.acoshMethod.

acosh(x::arb)

Return the hyperbolic arccosine of .

source

#Base.Math.gammaMethod.

gamma(x::arb)

Return the Gamma function evaluated at .

source

#Base.Math.lgammaMethod.

lgamma(x::arb)

Return the logarithm of the Gamma function evaluated at .

source

#Nemo.rgammaMethod.

rgamma(x::arb)

Return the reciprocal of the Gamma function evaluated at .

source

#Base.Math.digammaMethod.

digamma(x::arb)

Return the logarithmic derivative of the gamma function evaluated at , i.e. .

source

#Base.Math.zetaMethod.

zeta(x::arb)

Return the Riemann zeta function evaluated at .

source

#Nemo.sincosMethod.

sincos(x::arb)

Return a tuple consisting of the sine and cosine of .

source

#Nemo.sincospiMethod.

sincospi(x::arb)

Return a tuple consisting of the sine and cosine of .

source

#Base.Math.sinpiMethod.

sinpi(x::fmpq, r::ArbField)

Return the sine of in the given Arb field.

source

#Base.Math.cospiMethod.

cospi(x::fmpq, r::ArbField)

Return the cosine of in the given Arb field.

source

#Nemo.sincospiMethod.

sincospi(x::fmpq, r::ArbField)

Return a tuple consisting of the sine and cosine of in the given Arb field.

source

#Nemo.sinhcoshMethod.

sinhcosh(x::arb)

Return a tuple consisting of the hyperbolic sine and cosine of .

source

#Base.Math.atan2Method.

atan2(x::arb, y::arb)

Return atan2.

source

#Nemo.agmMethod.

agm(x::arb, y::arb)

Return the arithmetic-geometric mean of and

source

#Base.Math.zetaMethod.

zeta(s::arb, a::arb)

Return the Hurwitz zeta function .

source

#Base.Math.hypotMethod.

hypot(x::arb, y::arb)

Return .

source

#Nemo.rootMethod.

root(x::arb, n::Int)

Return the -th root of . We require .

source

#Nemo.facMethod.

fac(x::arb)

Return the factorial of .

source

#Nemo.facMethod.

fac(n::Int, r::ArbField)

Return the factorial of in the given Arb field.

source

#Nemo.binomMethod.

binom(x::arb, n::UInt)

Return the binomial coefficient .

source

#Nemo.binomMethod.

binom(n::UInt, k::UInt, r::ArbField)

Return the binomial coefficient in the given Arb field.

source

#Nemo.fibMethod.

fib(n::fmpz, r::ArbField)

Return the -th Fibonacci number in the given Arb field.

source

#Nemo.fibMethod.

fib(n::Int, r::ArbField)

Return the -th Fibonacci number in the given Arb field.

source

#Base.Math.gammaMethod.

gamma(x::fmpz, r::ArbField)

Return the Gamma function evaluated at in the given Arb field.

source

#Base.Math.gammaMethod.

gamma(x::fmpq, r::ArbField)

Return the Gamma function evaluated at in the given Arb field.

source

#Base.Math.zetaMethod.

zeta(n::Int, r::ArbField)

Return the Riemann zeta function as an element of the given Arb field.

source

#Nemo.bernoulliMethod.

bernoulli(n::Int, r::ArbField)

Return the -th Bernoulli number as an element of the given Arb field.

source

#Nemo.risingfacMethod.

risingfac(x::arb, n::Int)

Return the rising factorial as an Arb.

source

#Nemo.risingfacMethod.

risingfac(x::fmpq, n::Int, r::ArbField)

Return the rising factorial as an element of the given Arb field.

source

#Nemo.risingfac2Method.

risingfac2(x::arb, n::Int)

Return a tuple containing the rising factorial and its derivative.

source

#Nemo.polylogMethod.

polylog(s::arb, a::arb)

Return the polylogarithm Li.

source

#Nemo.polylogMethod.

polylog(s::Int, a::arb)

Return the polylogarithm Li.

source

#Nemo.chebyshev_tMethod.

chebyshev_t(n::Int, x::arb)

Return the value of the Chebyshev polynomial .

source

#Nemo.chebyshev_uMethod.

chebyshev_u(n::Int, x::arb)

Return the value of the Chebyshev polynomial .

source

#Nemo.chebyshev_t2Method.

chebyshev_t2(n::Int, x::arb)

Return the tuple .

source

#Nemo.chebyshev_u2Method.

chebyshev_u2(n::Int, x::arb)

Return the tuple

source

#Nemo.bellMethod.

bell(n::fmpz, r::ArbField)

Return the Bell number as an element of .

source

#Nemo.bellMethod.

bell(n::Int, r::ArbField)

Return the Bell number as an element of .

source

#Nemo.numpartMethod.

numpart(n::fmpz, r::ArbField)

Return the number of partitions as an element of .

source

#Nemo.numpartMethod.

numpart(n::fmpz, r::ArbField)

Return the number of partitions as an element of .

source

Here are some examples of real valued mathematical functions.

RR = RealField(64)

a = floor(exp(RR(1)))
b = sinpi(QQ(5,6), RR)
c = gamma(QQ(1,3), RealField(256))
d = bernoulli(1000, RealField(53))
f = polylog(3, RR(-10))