package octez-libs
include Polynomial.Polynomial_sig
with type t =
Octez_bls12_381_polynomial__Carray.Make(Octez_bls12_381_polynomial__.Fr_carray.Elt).t
with type scalar = scalar
type scalar = scalar
init n f
returns a fresh polynomial of length n
, with element number i
initialized to the result of f i
.
val allocate : int -> t
allocate len
creates a zero polynomial of size len
val erase : t -> unit
erase p
overwrites a polynomial p
with a zero polynomial of the same size as the polynomial p
val generate_biased_random_polynomial : int -> t
generate_biased_random_polynomial n
generates a random polynomial of degree strictly lower than n
, the distribution is NOT uniform, it is biased towards sparse polynomials and particularly towards the zero polynomial
val random : int -> t
random n
generates a uniformly sampled polynomial among the set of all polynomials of degree strictly lower than n
val degree : t -> int
degree p
returns the degree of a polynomial p
. Returns -1
for the zero polynomial
get p i
returns the i
-th element of a given array p
, a coefficient of X^i
in p
val to_string : t -> string
to_string p
returns the string representation of a polynomial p
truncate ~len p
returns a new polynomial made of the first len
coefficients of p
. If degree p + 1
is less than len
then copy p
is returned.
to_dense_coefficients p
returns the dense representation of a polynomial p
, i.e., it converts a C array to an OCaml array
of_dense p
creates a value of type t
from the dense representation of a polynomial p
, i.e., it converts an OCaml array to a C array
of_coefficients p
creates a value of type t
from the sparse representation of a polynomial p
, i.e., it converts an OCaml array to a C array
val is_zero : t -> bool
is_zero p
checks whether a polynomial p
is the zero polynomial
val zero : t
zero
is the zero polynomial, the neutral element for polynomial addition
val one : t
one
is the constant polynomial one, the neutral element for polynomial multiplication
add_inplace res a b
computes polynomial addition of a
and b
and writes the result in res
Note: res
can be equal to either a
or b
sub_inplace res a b
computes polynomial subtraction of a
and b
and writes the result in res
Note: res
can be equal to either a
or b
mul
computes polynomial multiplication
Note: naive quadratic algorithm, result's size is the sum of arguments' size
mul_by_scalar
computes multiplication of a polynomial by a blst_fr element
mul_by_scalar_inplace res s p
computes multiplication of a polynomial p
by a blst_fr element s
and stores it in res
linear_with_powers p s
computes ∑ᵢ sⁱ·p.(i)
. This function is more efficient than linear
+ powers
val opposite_inplace : t -> unit
opposite_inplace p
computes polynomial negation
Note: The argument p
is overwritten
division_xn p n c
returns the quotient and remainder of the division of p
by (X^n + c)
blind ~nb_blinds n p
adds to polynomial p
a random multiple of polynomial (X^n - 1)
, chosen by uniformly sampling a polynomial b
of degree strictly lower than nb_blinds
and multiplying it by (X^n - 1)
, b
is returned as the second argument
val to_carray :
t ->
Octez_bls12_381_polynomial__Carray.Make(Octez_bls12_381_polynomial__.Fr_carray.Elt).t
to_carray p
converts p
from type t
to type Fr_carray.t
Note: to_carray p
doesn't create a copy of p
val of_carray :
Octez_bls12_381_polynomial__Carray.Make(Octez_bls12_381_polynomial__.Fr_carray.Elt).t ->
t
of_carray p
converts p
from type Fr_carray.t
to type t
Note: of_carray p
doesn't create a copy of p
copy_carray ?offset ?len p
returns a polynomial made of len
contiguous coefficients starting from the coefficient of index offset
. By default, offset = 0
and len = length p - offset
.
val length : t -> int
length p
returns the length of the underlying Fr_carray.t
.