package osdp

  1. Overview
  2. Docs
module Coeff = Scalar.Q

Type of coefficients.

type t

Type of polynomials.

Conversion functions.

val of_list : (Monomial.t * Coeff.t) list -> t

of_list [(m_1, a_1);..; (m_n, a_n)] builds the polynomial a_1 m_1 + ... + a_n m_n. Duplicates or zeros coefficients are accepted (for instance 2 x_0 + 0 x_1 + 3 x_0 is a valid input for 5 x_0).

val to_list : t -> (Monomial.t * Coeff.t) list

Returns a list sorted in increasing order of Monomial.compare without duplicates nor zeros.

A few values.

val zero : t
val one : t
val var : ?c:Coeff.t -> ?d:int -> int -> t

var ?c ?d i returns c xi^d, this is equivalent to of_list [c, Monomial.var ~d i]. c is Coeff.one and d is 1 by default. i and d must be non negative.

val const : Coeff.t -> t

const c is equivalent to var ~c ~d:0 0.

val monomial : Monomial.t -> t

monomial m is equivalent to of_list [m, Coeff.one].

Arithmetic operations.

val mult_scalar : Coeff.t -> t -> t
val add : t -> t -> t
val sub : t -> t -> t
val mult : t -> t -> t
val power : t -> int -> t

power p n computes p^n, n must be non negative.

exception Dimension_error
val compose : t -> t list -> t

compose p [q_1;...; q_n] returns the polynomial p' such that p'(x_1,..., x_m) = p(q_1(x_1,..., x_m),..., q_n(x_1,..., x_m)).

val derive : t -> int -> t

derive p i returns the derivative of the polynomial p with respect to variable i (indices starting from 0). i must be non negative.

val eval : t -> Coeff.t list -> Coeff.t

eval p [x_1;...; x_n] returns p(x_1,..., x_n).

  • raises Invalid_argument

    "Polynomial.eval" if n is less than nb_vars p.

Various functions.

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

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

val degree : t -> int

-1 for the null polynomial.

val degree_list : t -> int list

degree_list p returns a list of length nb_vars p with the maximal degree for each variable in p.

val is_homogeneous : t -> bool
val is_var : t -> (Coeff.t * int * int) option

is_var p returns Some (c, d, i) if p is a polynomial of the form c xi^d and None otherwise.

val is_const : t -> Coeff.t option

is_const p returns Some c if p is the constant polynomial c and None otherwise.

val is_monomial : t -> Monomial.t option

is_monomial p returns Some m if p is a monmial x_0^i_0 ... x_n^i_n and None otherwise.

Prefix and infix operators.

To use this operators, it's convenient to use local opens. For instance to write the polynomial 2.3 x0^3 x2^2 + x1 + 0.5:

let module P = Osdp.Polynomial.Float in
P.(2.3 *. ??0**3 * ??2**2 + ??1 + !0.5)
val (??) : int -> t
val (!) : Coeff.t -> t
val (*.) : Coeff.t -> t -> t
val (~-) : t -> t

Unary minus, ~- p is syntactic sugar for sub zero p.

val (+) : t -> t -> t
val (-) : t -> t -> t
val (*) : t -> t -> t
val (/) : t -> Coeff.t -> t

p / c is equivaent to mult_scalar (Coeff.div Coeff.one c) p.

val (/.) : Coeff.t -> Coeff.t -> t

c1 /. c2 is equivaent to !c1 / c2.

val (**) : t -> int -> t

Printing.

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

See Monomial.pp for details about names.

val merge : (Monomial.t -> Coeff.t option -> Coeff.t option -> Coeff.t option) -> t -> t -> t
val fold : (Monomial.t -> Coeff.t -> 'a -> 'a) -> t -> 'a -> 'a