library colibrilib.ring — module ExportThe total versions, for the extraction: well formedness is the invariant of the type t
module Export597use int.Int598use real.RealInfix599use list.List600use Atom601use Mono602use colibrilib.stda.StdA as A603use Poly as P604use colibrilib.spec.Eval605Valid (23ms) (colibri2)606type t = { p: P.poly } invariant { P.wf p } by { p = Nil }607608function eval (env: Atom.t -> real) (x:t) : real = P.eval env x.p609
eval with the arguments in the order of the shapes of spec.Eval
function value (x:t) (env: Atom.t -> real) : real = eval env x612Valid (28ms) (colibri2)613let zero () : t614ensures { denotes0 value (fun _ -> 0.0) result }615= { p = P.zero () }616Valid (32ms) (colibri2)617let cst (c:A.t) : t618ensures { denotes0 value (fun _ -> A.real c) result }619= { p = P.cst c }620Valid (26ms) (colibri2)621let var (a:Atom.t) : t622ensures { denotes0 value (fun env -> env a) result }623= { p = P.var a }624Valid (26ms) (colibri2)625let add (x y:t) : t626ensures { denotes2 value (+.) x y result }627= { p = P.add x.p y.p }628Valid (35ms) (colibri2)629let sub (x y:t) : t630ensures { denotes2 value (-.) x y result }631= { p = P.sub x.p y.p }632Valid (29ms) (colibri2)633let neg (x:t) : t634ensures { denotes1 value (fun v -> -. v) x result }635= { p = P.neg x.p }636Valid (26ms) (colibri2)637let mul (x y:t) : t638ensures { denotes2 value (*.) x y result }639= { p = P.mul x.p y.p }640Valid (38ms) (colibri2)641let scale (k:A.t) (x:t) : t642ensures { denotes1 value (fun v -> A.real k *. v) x result }643= if A.equal k (A.of_int 0) then { p = Nil } else { p = P.scale k x.p }644645let function get (x:t) : P.poly = x.p646Valid (328ms) (colibri2 4) (split_vc) (depth 1)647let compose (f: Atom.t -> t) (x:t) : t648ensures { denotes_compose value f x result }649= { p = P.compose (fun a -> get (f a)) x.p }650651type solved =652| Zero653| Contra654| Solved Atom.t t655| NotSolved656Valid (48ms) (colibri2)657let solve [@spec:none "solver: Zero, Contra, Solved a q (x = 0 iff a = q) or NotSolved"] (x:t) : solved658ensures { match result with659| Zero -> x.p = Nil660| Contra -> P.is_cst x.p /\ (forall env. eval env x <> 0.0)661| Solved a q ->662P.has (Cons a Nil) x.p /\ P.occ a x.p = 1 /\ not (P.occurs a q.p)663/\ (forall env. eval env x = 0.0 <-> env a = eval env q)664| NotSolved ->665x.p <> Nil /\ not (P.is_cst x.p)666/\ (forall a. P.has (Cons a Nil) x.p -> P.occ a x.p <> 1)667end }668= match P.solve x.p with669| P.Zero -> Zero670| P.Contra -> Contra671| P.Solved a q -> Solved a { p = q }672| P.NotSolved -> NotSolved673end674
The factorization x = k * g * q, see Poly.factor
Valid (30ms) (colibri2)let factor [@spec:none "factorization: x = k * g * q"] (x:t) : (A.t, mono, t)677returns { (k, g, q) -> A.real k <> 0.0 /\ sorted g678/\ (forall env. eval env x = A.real k *. evalm env g *. eval env q) }679= let k, g, q = P.factor x.p in680(k, g, { p = q })681end682