Module Micromega_plugin.Vect
type tThe type of vectors or equivalently linear expressions. The current implementation is using association lists. A list
(0,c),(x1,ai),...,(xn,an)represents the linear expression c + a1.xn + ... an.xn where ai are rational constants and xi are variables.Note that the variable 0 has a special meaning and represent a constant. Moreover, the representation is spare and variables with a zero coefficient are not represented.
Generic functions
Basic accessors and utility functions
val pp_gen : (Stdlib.out_channel -> var -> unit) -> Stdlib.out_channel -> t -> unitpp_gen pp_var o vprints the representation of the vectorvover the channelo
val pp : Stdlib.out_channel -> t -> unitpp o vprints the representation of the vectorvover the channelo
val pp_smt : Stdlib.out_channel -> t -> unitpp_smt o vprints the representation of the vectorvover the channelousing SMTLIB conventions
val variables : t -> Micromega_plugin.Mutils.ISet.tvariables vreturns the set of variables with non-zero coefficients
val get_cst : t -> Num.numget_cst vreturns c i.e. the coefficient of the variable zero
val decomp_fst : t -> (var * Num.num) * tval cst : Num.num -> tcst creturns the vector v=c+0.x1+...+0.xn
val is_constant : t -> boolis_constant vholds ifvis a constant vector i.e. v=c+0.x1+...+0.xn
val null : tnullis the empty vector i.e. 0+0.x1+...+0.xn
val is_null : t -> boolis_null vreturns whethervis thenullvector i.eequal v null
val get : var -> t -> Num.numget xi vreturns the coefficient ai of the variablexi.getis also defined for the variable 0
val set : var -> Num.num -> t -> tset xi ai' vreturns the vector c+a1.x1+...ai'.xi+...+an.xn i.e. the coefficient of the variable xi is set to ai'
val update : var -> (Num.num -> Num.num) -> t -> tupdate xi f vreturns c+a1.x1+...+f(ai).xi+...+an.xn
val fresh : t -> intfresh vreturn the fresh variable with index 1+ max (variables v)
val choose : t -> (var * Num.num * t) optionchoose vdecomposes a vectorvdepending on whether it isnullor not.- returns
None if v is
null
- returns
Some(x,n,r) where v = r + n.x x is the smallest variable with non-zero coefficient n <> 0.
val from_list : Num.num list -> tfrom_list lreturns the vector c+a1.x1...an.xn from the list of coefficientl=c;a1;...;an
val to_list : t -> Num.num listto_list vreturns the list of all coefficient of the vector v i.e.c;a1;...;anThe list representation is (obviously) not sparsed and therefore certain ai may be 0
val decr_var : int -> t -> tdecr_var i vdecrements the variables of the vectorvby the amounti. Beware, it is only defined if all the variables of v are greater than i
val gcd : t -> Big_int.big_intgcd vreturns gcd(num(c),num(a1),...,num(an)) where num extracts the numerator of a rational value.
Linear arithmetics
val add : t -> t -> tadd v1 v2is vector addition.- parameter v1
is of the form c +a1.x1 +...+an.xn
- parameter v2
is of the form c'+a1'.x1 +...+an'.xn
- returns
c1+c1'+ (a1+a1').x1 + ... + (an+an').xn
val mul : Num.num -> t -> tmul a vis vector multiplication of vectorvby a scalara.- returns
a.v = a.c+a.a1.x1+...+a.an.xn
Iterators
val fold : ('acc -> var -> Num.num -> 'acc) -> 'acc -> t -> 'accfold f acc vreturns f (f (f acc 0 c ) x1 a1 ) ... xn an
val fold_error : ('acc -> var -> Num.num -> 'acc option) -> 'acc -> t -> 'acc optionfold_error f acc vis the same asfold (fun acc x i -> match acc with None -> None | Some acc' -> f acc' x i) (Some acc) vbut with early exit...
val find : (var -> Num.num -> 'c option) -> t -> 'c optionfind f vreturns the firstf xi aisuch thatf xi ai <> None. If no such xi ai exists, it returns None