Common — library colibrilib.ring — module Export

The total versions, for the extraction: well formedness is the invariant of the type t

597
module Export
598
use int.Int
599
use real.RealInfix
600
use list.List
601
use Atom
602
use Mono
603
use colibrilib.stda.StdA as A
604
use Poly as P
605
use colibrilib.spec.Eval
606
Valid (23ms) (colibri2)
607
type
t
= {
p
: P.poly } invariant { P.wf p } by { p = Nil }
608
609
function
eval
(env: Atom.t -> real) (x:t) : real = P.eval env x.p

eval with the arguments in the order of the shapes of spec.Eval

612
function
value
(x:t) (env: Atom.t -> real) : real = eval env x
613
Valid (28ms) (colibri2)
614
let
zero
() : t
615
ensures { denotes0 value (fun _ -> 0.0) result }
616
= { p = P.zero () }
617
Valid (32ms) (colibri2)
618
let
cst
(c:A.t) : t
619
ensures { denotes0 value (fun _ -> A.real c) result }
620
= { p = P.cst c }
621
Valid (26ms) (colibri2)
622
let
var
(a:Atom.t) : t
623
ensures { denotes0 value (fun env -> env a) result }
624
= { p = P.var a }
625
Valid (26ms) (colibri2)
626
let
add
(x y:t) : t
627
ensures { denotes2 value (+.) x y result }
628
= { p = P.add x.p y.p }
629
Valid (35ms) (colibri2)
630
let
sub
(x y:t) : t
631
ensures { denotes2 value (-.) x y result }
632
= { p = P.sub x.p y.p }
633
Valid (29ms) (colibri2)
634
let
neg
(x:t) : t
635
ensures { denotes1 value (fun v -> -. v) x result }
636
= { p = P.neg x.p }
637
Valid (26ms) (colibri2)
638
let
mul
(x y:t) : t
639
ensures { denotes2 value (*.) x y result }
640
= { p = P.mul x.p y.p }
641
Valid (38ms) (colibri2)
642
let
scale
(k:A.t) (x:t) : t
643
ensures { denotes1 value (fun v -> A.real k *. v) x result }
644
= if A.equal k (A.of_int 0) then { p = Nil } else { p = P.scale k x.p }
645
646
let function
get
(x:t) : P.poly = x.p
647
Valid (328ms) (colibri2 4) (split_vc) (depth 1)
648
let
compose
(f: Atom.t -> t) (x:t) : t
649
ensures { denotes_compose value f x result }
650
= { p = P.compose (fun a -> get (f a)) x.p }
651
652
type
solved
=
653
|
Zero
654
|
Contra
655
|
Solved
Atom.t t
656
|
NotSolved
657
Valid (48ms) (colibri2)
658
let
solve
[@spec:none "solver: Zero, Contra, Solved a q (x = 0 iff a = q) or NotSolved"] (x:t) : solved
659
ensures { match result with
660
| Zero -> x.p = Nil
661
| Contra -> P.is_cst x.p /\ (forall env. eval env x <> 0.0)
662
| Solved a q ->
663
P.has (Cons a Nil) x.p /\ P.occ a x.p = 1 /\ not (P.occurs a q.p)
664
/\ (forall env. eval env x = 0.0 <-> env a = eval env q)
665
| NotSolved ->
666
x.p <> Nil /\ not (P.is_cst x.p)
667
/\ (forall a. P.has (Cons a Nil) x.p -> P.occ a x.p <> 1)
668
end }
669
= match P.solve x.p with
670
| P.Zero -> Zero
671
| P.Contra -> Contra
672
| P.Solved a q -> Solved a { p = q }
673
| P.NotSolved -> NotSolved
674
end

The factorization x = k * g * q, see Poly.factor

  Valid (30ms) (colibri2)
677
let
factor
[@spec:none "factorization: x = k * g * q"] (x:t) : (A.t, mono, t)
678
returns { (k, g, q) -> A.real k <> 0.0 /\ sorted g
679
/\ (forall env. eval env x = A.real k *. evalm env g *. eval env q) }
680
= let k, g, q = P.factor x.p in
681
(k, g, { p = q })
682
end