package osdp

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

Type of coefficients.

type t

Type of affine expressions.

Conversion functions.

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

of_list [(x_1, a_1);..; (x_n, a_n)] c builds the affine expression a_1 x_1 + ... + a_n x_n + c. 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 -> (Ident.t * Coeff.t) list * Coeff.t

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

A few values.

val var : Ident.t -> t

Same as of_list with the list [ident, Coeff.one] and constant Coeff.zero.

val const : Coeff.t -> t

Same as of_list with an empty list.

Arithmetic operations.

val mult_scalar : Coeff.t -> t -> t
val add : t -> t -> t
val sub : t -> t -> t
val replace : t -> (Ident.t * t) list -> t

compose le [v_1, l_1;...; v_n, l_n] replaces each variable v_i by l_i in l. No duplicates are allowed.

val remove : t -> Ident.t -> t

Various operations.

val compare : t -> t -> int
val is_var : t -> (Ident.t * Coeff.t) option
val is_const : t -> Coeff.t option
val choose : t -> (Ident.t * Coeff.t) option

Returns one of the (non zero) coefficients in the linear expression (if any).

Printing.

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