package osdp

  1. Overview
  2. Docs

Monomials of multiple variables (e.g., x^2 y z^3).

type t

Type of monomials.

Conversion functions.

val of_list : int list -> t

of_list l produces the monomial corresponding to list l. For instance, considering the variables x0, x1, x2 and x3, of_list[3; 4; 0; 1] gives the monomial x0^3 x x1^4 x x3. All elements of the list must be non negative.

val to_list : t -> int list

The returned list contains only non negative values and its last element is non zero (or the list is empty).

A few values.

val one : t

Equivalent to of_list [].

val var : ?d:int -> int -> t

var ?d i returns xi^d, this is equivalent to of_list [0;...; O; d] with i zeros. d is 1 by default. i and d must be non negative. var ~d:0 i is equivalent to one.

Arithmetic operations.

val mult : t -> t -> t

mult m1 m2 multiplies the two monomials m1 and m2. If one of them is defined on less variables, the undefined exponents are considered as 0 (for instance mult (of_list [1; 2]) (of_list [3; 4; 5]) returns m such that to_list m = [4; 6; 5]).

val lcm : t -> t -> t

lcm m1 m2 returns the Least Common Multiple of m1 and m2 (i.e., the maximum of degrees for each variable).

val gcd : t -> t -> t

gcd m1 m2 returns the Greatest Common Divisor of m1 and m2 (i.e., the minimum of degrees for each variable).

val divide : t -> t -> bool

divide m1 m2 returns true iff m1 divides m2 (i.e., when lcm m1 m2 = m2 or equivalently gcd m1 m2 = m1). This can be seen as a pointwise less or equal on degrees.

exception Not_divisible
val div : t -> t -> t

div m1 m2 divides m1 by m2.

val derive : t -> int -> int * t

derive m i returns j_i, x_0^{j_0} ... x_i^{j_i - 1} ... x_n^{j_n}) if the degree j_i of variable i is positive in the monomial m and 0, one otherwise. i must be non negative.

Various functions.

val compare : t -> t -> int
val nb_vars : t -> int

nb_vars m returns the largest index (starting from 0) of a variable appearing in m plus one (0 if none). For instance, nb_var m returns 4 if m is the monomial x_0 x_3^2 (even if variables x_1 and x_2 don't actually appear in m)

val degree : t -> int
val is_var : t -> (int * int) option

is_var m returns Some (d, i) if m is the monomial xi^d and None otherwise.

Sets of monomials.

val list_eq : int -> int -> t list

list_eq n d provides the list of all monomials with n variables of degree equal d (for instance, list_eq 3 2 can return [x0^2; x0 x1; x0 x2; x1^2; x1 x2; x2^2]). n and d must be non negative.

val list_le : int -> int -> t list

list_le n d provides the list of all monomials with n variables of degree less or equal d (for instance, list_le 3 2 can return [1; x0; x1; x2; x0^2; x0 x1; x0 x2; x1^2; x1 x2; x2^2]). n and d must be non negative.

Printing.

val pp : Stdlib.Format.formatter -> t -> unit

Pretty printing. Variables will be printed as x0, x1,...

val pp_names : string list -> Stdlib.Format.formatter -> t -> unit

Pretty printing. If names is to short, variables will be printed as x0, x1,... Providing a too short names list is not advisable however, as the generated names may collide with the provided ones.

Sets and maps.

module Set : Stdlib.Set.S with type elt = t
module Map : Stdlib.Map.S with type key = t