Skip to content

Latest commit

 

History

History
172 lines (123 loc) · 3.88 KB

fraction.md

File metadata and controls

172 lines (123 loc) · 3.88 KB
CurrentModule = Nemo
DocTestSetup = quote
    using Nemo
end

Fraction fields

Nemo allows the creation of fraction fields over any ring $R$. We don't require $R$ to be an integral domain, however no attempt is made to deal with the general case. Two fractions $a/b$ and $c/d$ are equal in Nemo iff $ad = bc$. Thus, in practice, a greatest common divisor function is currently required for the ring $R$.

In order to make the representation $a/b$ unique for printing, we have a notion of canonical unit for elements of a ring $R$. When canonicalising $a/b$, each of the elements $a$ and $b$ is first divided by the canonical unit of $b$.

The canonical_unit function is defined for elements of every Nemo ring. It must have the properties

canonical_unit(u) == u
canonical_unit(a*b) == canonical_unit(a)*canonical_unit(b)

for any unit $u$ of the ring in question, and $a$ and $b$ arbitrary elements of the ring.

For example, the canonical unit of an integer is its sign. Thus a fraction of integers always has positive denominator after canonicalisation.

The canonical unit of a polynomial is the canonical unit of its leading coefficient, etc.

There are two different kinds of implementation of fraction fields in Nemo: a generic one for the case where no specific implementation exists (provided by AbstractAlgebra.jl), and efficient implementations of fractions over specific rings, usually provided by C/C++ libraries.

The following table shows each of the fraction types available in Nemo, the base ring $R$, and the Julia/Nemo types for that kind of fraction (the type information is mainly of concern to developers).

Base ring Library Element type Parent type
Generic ring $R$ AbstractAlgebra.jl Generic.FracFieldElem{T} Generic.FracField{T}
$\mathbb{Z}$ Flint QQFieldElem QQField

All fraction element types belong to the abstract type FracElem and all of the fraction field types belong to the abstract type FracField. This enables one to write generic functions that can accept any Nemo fraction type.

Fraction functionality

All fraction types in Nemo provide functionality for fields described in AbstractAlgebra.jl:

https://nemocas.github.io/AbstractAlgebra.jl/stable/field

In addition all the fraction field functionality of AbstractAlgebra.jl is provided, along with generic fractions fields as described here:

https://nemocas.github.io/AbstractAlgebra.jl/stable/fraction

Basic manipulation

sign(::QQFieldElem)
height(::QQFieldElem)
height_bits(::QQFieldElem)
<<(::QQFieldElem, ::Int)
>>(::QQFieldElem, ::Int)
floor(::QQFieldElem)
ceil(::QQFieldElem)

Examples

julia> d = abs(ZZ(11)//3)
11//3

julia> 4 <= ZZ(7)//ZZ(3)
false

Modular arithmetic

The following functions are available for rationals.

mod(a::QQFieldElem, b::ZZRingElem)

Rational Reconstruction

Rational reconstruction is available for rational numbers.

reconstruct(::ZZRingElem, ::ZZRingElem)
reconstruct(::ZZRingElem, ::ZZRingElem, ::ZZRingElem, ::ZZRingElem)

Rational enumeration

Various methods exist to enumerate rationals.

next_minimal(::QQFieldElem)
next_signed_minimal(::QQFieldElem)
next_calkin_wilf(::QQFieldElem)
next_signed_calkin_wilf(::QQFieldElem)

Random generation

rand_bits(::QQField, b::Int)

Special functions

The following special functions are available for specific rings in Nemo.

harmonic(::Int)
bernoulli(::Int)
bernoulli_cache(::Int)
dedekind_sum(::ZZRingElem, ::ZZRingElem)
simplest_between(::QQFieldElem, ::QQFieldElem)