package lp

  1. Overview
  2. Docs

Module Lp.PolySource

Module for polynomial expression.

Sourcetype t

Type for the polynomial with order up to two (quadratic).

Sourcetype classified = {
  1. const : t;
  2. linear : t;
  3. quad : t;
}

Type for the polynomial classified by orders.

Sourcetype decomposed = {
  1. const : float;
  2. lcs : float list;
  3. lvs : Var.t list;
  4. qcs : float list;
  5. qv0s : Var.t list;
  6. qv1s : Var.t list;
}

Type for the decomposed expression of the polynomial.

Sourceval c : float -> t

Make monomial of a constant value.

Sourceval var : ?integer:bool -> ?lb:float -> ?ub:float -> string -> t

Make monomial of a variable.

Sourceval of_var : Var.t -> t

Make monomial from a Var.t.

Sourceval of_term : Term.t -> t

Make monomial from a Term.t.

Sourceval binary : string -> t

Make monomial of a binary variable.

Sourceval range : ?integer:bool -> ?lb:float -> ?ub:float -> ?start:int -> int -> string -> t array

Make an array of monomials of a variable with uniform bounds.

Sourceval range2 : ?integer:bool -> ?lb:float -> ?ub:float -> ?start0:int -> ?start1:int -> int -> int -> string -> t array array

Make 2D array of monomials of a variable with uniform bounds.

Sourceval range3 : ?integer:bool -> ?lb:float -> ?ub:float -> ?start0:int -> ?start1:int -> ?start2:int -> int -> int -> int -> string -> t array array array

Make 3D array of monomials of a variable with uniform bounds.

Sourceval rangeb : ?start:int -> int -> string -> t array

Make an array of monomials of a binary variable.

Sourceval range2b : ?start0:int -> ?start1:int -> int -> int -> string -> t array array

Make 2D array of monomials of a binary variable.

Sourceval range3b : ?start0:int -> ?start1:int -> ?start2:int -> int -> int -> int -> string -> t array array array

Make 3D array of monomials of a binary variable.

Sourceval rangev : ?integer:bool -> ?lb:float array -> ?ub:float array -> ?start:int -> int -> string -> t array

Make an array of monomials of a variable with different bounds.

Sourceval range2v : ?integer:bool -> ?lb:float array array -> ?ub:float array array -> ?start0:int -> ?start1:int -> int -> int -> string -> t array array

Make 2D array of monomials of a variable with different bounds.

Sourceval range3v : ?integer:bool -> ?lb:float array array array -> ?ub:float array array array -> ?start0:int -> ?start1:int -> ?start2:int -> int -> int -> int -> string -> t array array array

Make 3D array of monomials of a variable with different bounds.

Sourceval concat : t array -> t

Concatenate an array of polynomials into single polynomial.

Sourceval concat_list : t list -> t

Concatenate a list of polynomials into single polynomial.

Sourceval of_float_array : float array -> t

Convert a float array into a polynomial.

Sourceval of_term_list : Term.t list -> t

Convert a list of terms into a polynomial.

Sourceval to_float : t -> float

Convert a Constant monomial to float.

  • raises Failure

    if it's not constant monomial.

Sourceval zero : t

The monomial of constant zero.

Sourceval one : t

The monomial of constant one.

Sourceval sort : t -> t

Sort terms in the polynomial.

Sourceval compare : t -> t -> int

Compare the polynomial.

Sourceval to_string : ?short:bool -> t -> string

Get string expression of the polynomial.

Sourceval partition : t -> t * t

Partition terms into pair of (quad or linear, const) terms.

Sourceval classify : t -> classified

Classify terms into three categories: quad, linear, and const (classified).

Sourceval decompose : t -> decomposed

Decompose the polynomial into decomposed.

Sourceval collision : t -> bool

Check if any variable collision exist in the polynomial.

Sourceval simplify : ?eps:float -> t -> t

Simplify the polynomial. The polynomial is sorted and terms with same variables are accumulated. After that, near-zero terms are dropped. eps specifies the threshold of near-zero, defaulting to 10. *. epsilon_float.

Sourceval degree : t -> int

Get the degree of polynomial.

Sourceval take_vars : t -> Var.t list

List up all the variables in the polynomial.

Sourceval uniq_vars : t -> Var.t list

List up all the unique variables in the polynomial.

Sourceval linear_coeff : t -> Var.t -> float

take linear coefficient of a variable in a polynomial.

Sourceval quad_coeff : t -> Var.t -> Var.t -> float

take quad coefficient of the variables in a polynomial.

Sourceval neg : t -> t

Negate the polynomial (negate all terms in the polynomial).

Sourceval (~--) : t -> t

Negate the polynomial (negate all terms in the polynomial).

Sourceval (++) : t -> t -> t

Add (concatenate) two polynomials.

Sourceval (--) : t -> t -> t

Subtract two polynomials (concatenate left with negated right).

Sourceval expand : t -> t -> t

Multiply two polynomials. Specifically, performs polynomial expansion.

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

Infix equivalent of expand.

Sourceval dot : t -> t -> t

Regard two polynomials as vectors and take dot product.

  • raises Failure

    if the lengths of two polynomials are different.

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

Infix equivalent of dot.

Sourceval equiv : ?eps:float -> t -> t -> bool

Check if two polynomials are equivalent

Sourceval divt : t -> Term.t -> t

Divide polynomial by a term.

Sourceval div : t -> t -> t

Divide polynomial by a univariate polynomial. Be careful as this function raises exception in some cases.

  • raises Failure

    if failed to divide (with zero remainder) or denominator is multivariate polynomial.

Sourceval (/~) : t -> t -> t

Infix equivalent of div.

Sourceval with_bound : string -> float -> float -> t -> t

with_bound name lb ub transforms the bounds of the variable name with lb and ub.

Sourceval to_integer : string -> t -> t

to_integer name transforms the variable name into general integer variable.

Sourceval to_binary : string -> t -> t

to_binary name transforms the variable name into binary variable.

Sourceval double_quad : t -> t

Double the coefficients in all quadratic terms in the polynomial.

Sourceval half_quad : t -> t

Half the coefficients in all quadratic terms in the polynomial.

Sourceval map : (Term.t -> 'a) -> t -> 'a list

Apply a function to all terms in the polynomial and build a list.

Sourceval map_linear : (float -> Var.t -> 'a) -> t -> 'a list

Apply a function only to linear terms in the polynomial and build a list.

  • raises Failure

    if non-linear terms exist.

Sourceval mapi : (int -> Term.t -> 'a) -> t -> 'a list

Apply a function to all terms in the polynomial and build a list.

Sourceval iter : (Term.t -> unit) -> t -> unit

Apply a function to all terms in the polynomial.

Sourceval iteri : (int -> Term.t -> unit) -> t -> unit

Apply a function to all terms in the polynomial.

Sourceval iter_linear : (float -> Var.t -> unit) -> t -> unit

Apply a function only to linear terms in the polynomial. * non-linear terms are just ignored.

Sourceval iter_linear_exn : (float -> Var.t -> unit) -> t -> unit

Apply a function only to linear terms in the polynomial.

  • raises Failure

    if non-linear terms exist.

Sourceval length : t -> int

Get number of terms (length) of a polynomial.

Sourceval take_linear_coeffs : t -> float list

Make list of coefficients in linear terms in a polynomial.

OCaml

Innovation. Community. Security.