std:Region/Certificate

lib/Region/Certificate.omg

lib/Region/Certificate.omg61 lines
1-- Efficient proposals for exact interval proofs. Subtraction and comparisons
2-- choose witnesses; equality evidence checks them. Soundness uses only the
3-- addition/order theorems, with no NatFacts or hash assumptions.
4let A = std:Arith
5let C = std:Certificate
6let E = std:Equal
7let N = std:Natural
8let R = std:Region
9let before =
10      \(left right : Natural) ->
11        let gap = N.minus right left
12        in  C.make (left + gap) right (\proof -> ((gap, proof) : A.Le left right))
13let fits = \(capacity : Natural) (region : R.Region) -> before (R.end region) capacity
14let emptyDisjoint
15    : forall (a b : R.Region) -> a.size === 0 -> R.Disjoint a b
16    = \a b empty n inside _ ->
17        A.ltIrrefl
18          n
19          (A.ltLeTrans
20             n
21             (R.end a)
22             n
23             inside.upper
24             (A.eqTransLe
25                (R.end a)
26                a.start
27                n
28                (E.cong (\size -> a.start + size) empty)
29                inside.lower))
30let separate =
31      \(a b : R.Region) ->
32        if N.isZero a.size
33        then C.make a.size 0 (emptyDisjoint a b)
34        else if N.isZero b.size
35        then C.make b.size 0 (\proof -> R.disjointSym b a (emptyDisjoint b a proof))
36        else if N.lessThanEqual (R.end a) b.start
37        then C.map (R.separate a b) (before (R.end a) b.start)
38        else C.map (\proof -> R.disjointSym b a (R.separate b a proof)) (before (R.end b) a.start)
39let all
40    : forall (P : R.Region -> Type)
41      -> (forall (r : R.Region) -> C.Certificate @0 (P r))
42      -> forall (rs : List R.Region)
43      -> C.Certificate @0 (R.All P rs)
44    = \P witness ->
45        List/elim
46          (\rs -> C.Certificate @0 (R.All P rs))
47          (C.known {=})
48          (\r rest recurse -> C.both (witness r) recurse)
49let separated
50    : forall (rs : List R.Region) -> C.Certificate @0 (R.Separated rs)
51    = List/elim
52        (\rs -> C.Certificate @0 (R.Separated rs))
53        (C.known {=})
54        (\r rest recurse -> C.both (all (R.Disjoint r) (separate r) rest) recurse)
55let plan =
56      \(capacity : Natural) (regions : List R.Region) ->
57        C.map
58          (\(proof : R.Separated regions * R.All (R.Fits capacity) regions) ->
59             ((regions, { separated = proof.1, fits = proof.2 }) : R.Plan capacity))
60          (C.both (separated regions) (all (R.Fits capacity) (fits capacity) regions))
61in  { before, fits, emptyDisjoint, separate, all, separated, plan }
Your result
Complete file: lib/Region/Certificate.omg · with imports