package lp

  1. Overview
  2. Docs

Module Lp.PolySource

Module for polynomial expression type

Sourcetype t = Term.t list

Type for the polynomial with order up to two (quadratic). Internal representation (Term.t list) is intentionally exposed for now.

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

Type for the polynomial classified by orders

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 binary : string -> t

Make monomial of a binary variable

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

Make array of monomials of a variable

Sourceval zero : t

Constant zero

Sourceval sort : t -> t

Sort terms in the polynomial

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

Get string expression of the polynomial

Sourceval partition : t -> t * t

Partition terms into pair ( quad or linear, const )

Sourceval classify : t -> classified

Classify terms into three categories quad, linear, const

Sourceval collision : t -> bool

Check if any variable collision exist in the polynomial

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

Simplify the polynomial. The polynomial is sorted and terms with same variables are accumulated. After that, near-zero terms are dropped. epsilon 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 neg : t -> t

Negate the whole polynomial

Sourceval (~-) : t -> t

Negate the whole 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

Multiply two polynomials. specifically, performs polynomial expansion.

Sourceval dot : t -> t -> t

Regard two polynomials as vectors and take dot product.

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

Regard two polynomials as vectors and take dot product.

Sourceval equiv : 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 following cases.

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

    equivalent to div

    Sourceval trans_bound : string -> float -> float -> t -> t

    trans_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_integer name transforms the variable name into binary variable