Flint2-0.1.0.5: Haskell bindings for the flint library for number theory

Data.Number.Flint.NF.Elem

Synopsis

# nf_elem.h -- number field elements

data NFElem Source #

Constructors

 NFElem !(ForeignPtr CNFElem)

#### Instances

Instances details
 Source # Instance detailsDefined in Data.Number.Flint.NF.Elem.FFI MethodspokeElemOff :: Ptr CNFElem -> Int -> CNFElem -> IO () #peekByteOff :: Ptr b -> Int -> IO CNFElem #pokeByteOff :: Ptr b -> Int -> CNFElem -> IO () #poke :: Ptr CNFElem -> CNFElem -> IO () #

withNFElem :: NFElem -> (Ptr CNFElem -> IO a) -> IO (NFElem, a) Source #

Use number-field element.

withNewNFElem :: NF -> (Ptr CNFElem -> IO a) -> IO (NFElem, a) Source #

# Initialisation

nf_elem_init a nf

Initialise a number field element to belong to the given number field code{nf}. The element is set to zero.

nf_elem_clear a nf

Clear resources allocated by the given number field element in the given number field.

nf_elem_randtest a state bits nf

Generate a random number field element $$a$$ in the number field code{nf} whose coefficients have up to the given number of bits.

nf_elem_canonicalise a nf

Canonicalise a number field element, i.e. reduce numerator and denominator to lowest terms. If the numerator is $$0$$, set the denominator to $$1$$.

_nf_elem_reduce a nf

Reduce a number field element modulo the defining polynomial. This is used with functions such as code{nf_elem_mul_red} which allow reduction to be delayed. Does not canonicalise.

nf_elem_reduce a nf

Reduce a number field element modulo the defining polynomial. This is used with functions such as code{nf_elem_mul_red} which allow reduction to be delayed.

_nf_elem_invertible_check a nf

Whilst the defining polynomial for a number field should by definition be irreducible, it is not enforced. Thus in test code, it is convenient to be able to check that a given number field element is invertible modulo the defining polynomial of the number field. This function does precisely this.

If $$a$$ is invertible modulo the defining polynomial of code{nf} the value $$1$$ is returned, otherwise $$0$$ is returned.

The function is only intended to be used in test code.

# Conversion

nf_elem_set_fmpz_mat_row b M i den nf

Set $$b$$ to the element specified by row $$i$$ of the matrix $$M$$ and with the given denominator $$d$$. Column $$0$$ of the matrix corresponds to the constant coefficient of the number field element.

nf_elem_get_fmpz_mat_row M i den b nf

Set the row $$i$$ of the matrix $$M$$ to the coefficients of the numerator of the element $$b$$ and $$d$$ to the denominator of $$b$$. Column $$0$$ of the matrix corresponds to the constant coefficient of the number field element.

nf_elem_set_fmpq_poly a pol nf

Set $$a$$ to the element corresponding to the polynomial code{pol}.

nf_elem_get_fmpq_poly pol a nf

Set code{pol} to a polynomial corresponding to $$a$$, reduced modulo the defining polynomial of code{nf}.

nf_elem_get_nmod_poly_den pol a nf den

Set code{pol} to the reduction of the polynomial corresponding to the numerator of $$a$$. If code{den == 1}, the result is multiplied by the inverse of the denominator of $$a$$. In this case it is assumed that the reduction of the denominator of $$a$$ is invertible.

nf_elem_get_nmod_poly pol a nf

Set code{pol} to the reduction of the polynomial corresponding to the numerator of $$a$$. The result is multiplied by the inverse of the denominator of $$a$$. It is assumed that the reduction of the denominator of $$a$$ is invertible.

nf_elem_get_fmpz_mod_poly_den pol a nf den

Set code{pol} to the reduction of the polynomial corresponding to the numerator of $$a$$. If code{den == 1}, the result is multiplied by the inverse of the denominator of $$a$$. In this case it is assumed that the reduction of the denominator of $$a$$ is invertible.

nf_elem_get_fmpz_mod_poly pol a nf

Set code{pol} to the reduction of the polynomial corresponding to the numerator of $$a$$. The result is multiplied by the inverse of the denominator of $$a$$. It is assumed that the reduction of the denominator of $$a$$ is invertible.

# Basic manipulation

nf_elem_set_den b d nf

Set the denominator of the code{nf_elem_t b} to the given integer $$d$$. Assumes $$d > 0$$.

nf_elem_get_den d b nf

Set $$d$$ to the denominator of the code{nf_elem_t b}.

_nf_elem_set_coeff_num_fmpz a i d nf

Set the $$ith coefficient of the denominator of :math:a$$ to the given integer $$d$$.

# Comparison

_nf_elem_equal a b nf

Return $$1$$ if the given number field elements are equal in the given number field code{nf}. This function does emph{not} assume $$a$$ and $$b$$ are canonicalised.

nf_elem_equal a b nf

Return $$1$$ if the given number field elements are equal in the given number field code{nf}. This function assumes $$a$$ and $$b$$ emph{are} canonicalised.

nf_elem_is_zero a nf

Return $$1$$ if the given number field element is equal to zero, otherwise return $$0$$.

nf_elem_is_one a nf

Return $$1$$ if the given number field element is equal to one, otherwise return $$0$$.

# I/O

nf_elem_print_pretty a nf var

Print the given number field element to code{stdout} using the null-terminated string code{var} not equal to code{"0"} as the name of the primitive element. foreign import ccall "nf_elem.h nf_elem_print_pretty"

# Arithmetic

nf_elem_zero a nf

Set the given number field element to zero.

nf_elem_one a nf

Set the given number field element to one.

nf_elem_set a b nf

Set the number field element $$a$$ to equal the number field element $$b$$, i.e. set $$a = b$$.

nf_elem_neg a b nf

Set the number field element $$a$$ to minus the number field element $$b$$, i.e. set $$a = -b$$.

nf_elem_swap a b nf

Efficiently swap the two number field elements $$a$$ and $$b$$.

nf_elem_mul_gen a b nf

Multiply the element $$b$$ with the generator of the number field.

Add two elements of a number field code{nf}, i.e. set $$r = a + b$$. Canonicalisation is not performed.

Add two elements of a number field code{nf}, i.e. set $$r = a + b$$.

_nf_elem_sub r a b nf

Subtract two elements of a number field code{nf}, i.e. set $$r = a - b$$. Canonicalisation is not performed.

nf_elem_sub r a b nf

Subtract two elements of a number field code{nf}, i.e. set $$r = a - b$$.

_nf_elem_mul a b c nf

Multiply two elements of a number field code{nf}, i.e. set $$r = a * b$$. Does not canonicalise. Aliasing of inputs with output is not supported.

_nf_elem_mul_red a b c nf red

As per code{_nf_elem_mul}, but reduction modulo the defining polynomial of the number field is only carried out if code{red == 1}. Assumes both inputs are reduced.

nf_elem_mul a b c nf

Multiply two elements of a number field code{nf}, i.e. set $$r = a * b$$.

nf_elem_mul_red a b c nf red

As per code{nf_elem_mul}, but reduction modulo the defining polynomial of the number field is only carried out if code{red == 1}. Assumes both inputs are reduced.

_nf_elem_inv r a nf

Invert an element of a number field code{nf}, i.e. set $$r = a^{-1}$$. Aliasing of the input with the output is not supported.

nf_elem_inv r a nf

Invert an element of a number field code{nf}, i.e. set $$r = a^{-1}$$.

_nf_elem_div a b c nf

Set $$a$$ to $$b/c$$ in the given number field. Aliasing of $$a$$ and $$b$$ is not permitted.

nf_elem_div a b c nf

Set $$a$$ to $$b/c$$ in the given number field.

_nf_elem_pow res a e nf

Set code{res} to $$a^e$$ using left-to-right binary exponentiation as described in~citep[p.~461]{Knu1997}.

Assumes that $$a \neq 0$$ and $$e > 1$$. Does not support aliasing.

nf_elem_pow res a e nf

Set code{res} = code{a^e} using the binary exponentiation algorithm. If $$e$$ is zero, returns one, so that in particular code{0^0 = 1}.

_nf_elem_norm rnum rden a nf

Set code{{rnum, rden}} to the absolute norm of the given number field element $$a$$.

nf_elem_norm res a nf

Set code{res} to the absolute norm of the given number field element $$a$$.

nf_elem_norm_div res a nf div nbits

Set code{res} to the absolute norm of the given number field element $$a$$, divided by code{div} . Assumes the result to be an integer and having at most code{nbits} bits.

_nf_elem_norm_div rnum rden a nf divisor nbits

Set code{{rnum, rden}} to the absolute norm of the given number field element $$a$$, divided by code{div} . Assumes the result to be an integer and having at most code{nbits} bits.

_nf_elem_trace rnum rden a nf

Set code{{rnum, rden}} to the absolute trace of the given number field element $$a$$.

nf_elem_trace res a nf

Set code{res} to the absolute trace of the given number field element $$a$$.

# Representation matrix

nf_elem_rep_mat res a nf

Set code{res} to the matrix representing the multiplication with $$a$$ with respect to the basis $$1, a, \dotsc, a^{d - 1}$$, where $$a$$ is the generator of the number field of $$d$$ is its degree.

nf_elem_rep_mat_fmpz_mat_den res den a nf

Return a tuple $$M, d$$ such that $$M/d$$ is the matrix representing the multiplication with $$a$$ with respect to the basis $$1, a, \dotsc, a^{d - 1}$$, where $$a$$ is the generator of the number field of $$d$$ is its degree. The integral matrix $$M$$ is primitive.

# Modular reduction

nf_elem_mod_fmpz_den z a mod nf

If code{den == 0}, return an element $$z$$ with denominator $$1$$, such that the coefficients of $$z - da$$ are divisble by code{mod}, where $$d$$ is the denominator of $$a$$. The coefficients of $$z$$ are reduced modulo code{mod}.

If code{den == 1}, return an element $$z$$, such that $$z - a$$ has denominator $$1$$ and the coefficients of $$z - a$$ are divisble by code{mod}. The coefficients of $$z$$ are reduced modulo code{mod * d}, where $$d$$ is the denominator of $$a$$.

Reduction takes place with respect to the positive residue system.

nf_elem_smod_fmpz_den z a mod nf

If code{den == 0}, return an element $$z$$ with denominator $$1$$, such that the coefficients of $$z - da$$ are divisble by code{mod}, where $$d$$ is the denominator of $$a$$. The coefficients of $$z$$ are reduced modulo code{mod}.

If code{den == 1}, return an element $$z$$, such that $$z - a$$ has denominator $$1$$ and the coefficients of $$z - a$$ are divisble by code{mod}. The coefficients of $$z$$ are reduced modulo code{mod * d}, where $$d$$ is the denominator of $$a$$.

Reduction takes place with respect to the symmetric residue system.

nf_elem_mod_fmpz res a mod nf

Return an element $$z$$ such that $$z - a$$ has denominator $$1$$ and the coefficients of $$z - a$$ are divisible by code{mod}. The coefficients of $$z$$ are reduced modulo code{mod * d}, where $$d$$ is the denominator of $$b$$.

Reduction takes place with respect to the positive residue system.

nf_elem_smod_fmpz res a mod nf

Return an element $$z$$ such that $$z - a$$ has denominator $$1$$ and the coefficients of $$z - a$$ are divisible by code{mod}. The coefficients of $$z$$ are reduced modulo code{mod * d}, where $$d$$ is the denominator of $$b$$.

Reduction takes place with respect to the symmetric residue system.

nf_elem_coprime_den res a mod nf

Return an element $$z$$ such that the denominator of $$z - a$$ is coprime to code{mod}.

Reduction takes place with respect to the positive residue system.

nf_elem_coprime_den_signed res a mod nf

Return an element $$z$$ such that the denominator of $$z - a$$ is coprime to code{mod}.

Reduction takes place with respect to the symmetric residue system.