package osdp

  1. Overview
  2. Docs

Module Polynomial.MakeSource

Parameters

module SC : Scalar.S

Signature

Sourcemodule Coeff = SC

Type of coefficients.

Sourcetype t

Type of polynomials.

Conversion functions.

Sourceval 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).

Sourceval 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.

Sourceval zero : t
Sourceval one : t
Sourceval 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.

Sourceval const : Coeff.t -> t

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

Sourceval monomial : Monomial.t -> t

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

Arithmetic operations.

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

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

Sourceexception Dimension_error
Sourceval 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)).

Sourceval 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.

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

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

Various functions.

Sourceval compare : t -> t -> int
Sourceval 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)

Sourceval degree : t -> int

-1 for the null polynomial.

Sourceval 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.

Sourceval is_homogeneous : t -> bool
Sourceval 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.

Sourceval is_const : t -> Coeff.t option

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

Sourceval 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)
Sourceval (??) : int -> t
Sourceval (!) : Coeff.t -> t
Sourceval (*.) : Coeff.t -> t -> t
Sourceval (~-) : t -> t

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

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

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

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

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

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

Printing.

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

See Monomial.pp for details about names.

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

Innovation. Community. Security.