summaryrefslogtreecommitdiff
path: root/lib/coq/Sail2_state.v
diff options
context:
space:
mode:
authorBrian Campbell2019-07-25 14:56:19 +0100
committerBrian Campbell2019-07-25 14:56:29 +0100
commitdaff10c33218ecd4044c5006ee47686d8d2458de (patch)
treefeaa80c926840787ac78fa3445a64e531678f9b5 /lib/coq/Sail2_state.v
parent3fb4cf236c0d4b15831576faa45c763853632568 (diff)
Basic port of proof machinery to Coq
Diffstat (limited to 'lib/coq/Sail2_state.v')
-rw-r--r--lib/coq/Sail2_state.v44
1 files changed, 34 insertions, 10 deletions
diff --git a/lib/coq/Sail2_state.v b/lib/coq/Sail2_state.v
index b73d5013..6e242caf 100644
--- a/lib/coq/Sail2_state.v
+++ b/lib/coq/Sail2_state.v
@@ -32,7 +32,7 @@ end.
(*val genlistS : forall 'a 'rv 'e. (nat -> monadS 'rv 'a 'e) -> nat -> monadS 'rv (list 'a) 'e*)
Definition genlistS {A RV E} (f : nat -> monadS RV A E) n : monadS RV (list A) E :=
- let indices := genlist (fun n => n) n in
+ let indices := List.seq 0 n in
foreachS indices [] (fun n xs => (f n >>$= (fun x => returnS (xs ++ [x])))).
(*val and_boolS : forall 'rv 'e. monadS 'rv bool 'e -> monadS 'rv bool 'e -> monadS 'rv bool 'e*)
@@ -43,6 +43,31 @@ Definition and_boolS {RV E} (l r : monadS RV bool E) : monadS RV bool E :=
Definition or_boolS {RV E} (l r : monadS RV bool E) : monadS RV bool E :=
l >>$= (fun l => if l then returnS true else r).
+Definition and_boolSP {rv E} {P Q R:bool->Prop} (x : monadS rv {b:bool & ArithFact (P b)} E) (y : monadS rv {b:bool & ArithFact (Q b)} E)
+ `{H:ArithFact (forall l r, P l -> (l = true -> Q r) -> R (andb l r))}
+ : monadS rv {b:bool & ArithFact (R b)} E.
+refine (
+ x >>$= fun '(existT _ x (Build_ArithFact _ p)) => (if x return P x -> _ then
+ fun p => y >>$= fun '(existT _ y _) => returnS (existT _ y _)
+ else fun p => returnS (existT _ false _)) p
+).
+* constructor. destruct H. destruct a0. change y with (andb true y). auto.
+* constructor. destruct H. change false with (andb false false). apply fact.
+ assumption.
+ congruence.
+Defined.
+Definition or_boolSP {rv E} {P Q R:bool -> Prop} (l : monadS rv {b : bool & ArithFact (P b)} E) (r : monadS rv {b : bool & ArithFact (Q b)} E)
+ `{ArithFact (forall l r, P l -> (l = false -> Q r) -> R (orb l r))}
+ : monadS rv {b : bool & ArithFact (R b)} E.
+refine (
+ l >>$= fun '(existT _ l (Build_ArithFact _ p)) =>
+ (if l return P l -> _ then fun p => returnS (existT _ true _)
+ else fun p => r >>$= fun '(existT _ r _) => returnS (existT _ r _)) p
+).
+* constructor. destruct H. change true with (orb true true). apply fact. assumption. congruence.
+* constructor. destruct H. destruct a0. change r with (orb false r). auto.
+Defined.
+
(*val bool_of_bitU_fail : forall 'rv 'e. bitU -> monadS 'rv bool 'e*)
Definition bool_of_bitU_fail {RV E} (b : bitU) : monadS RV bool E :=
match b with
@@ -101,16 +126,15 @@ Definition choose_boolsS {RV E} n : monadS RV (list bool) E :=
genlistS (fun _ => choose_boolS tt) n.
(* TODO: Replace by chooseS and prove equivalence to prompt monad version *)
-(*val internal_pickS : forall 'rv 'a 'e. list 'a -> monadS 'rv 'a 'e
-let internal_pickS xs =
+(*val internal_pickS : forall 'rv 'a 'e. list 'a -> monadS 'rv 'a 'e*)
+Definition internal_pickS {RV A E} (xs : list A) : monadS RV A E :=
(* Use sufficiently many nondeterministically chosen bits and convert into an
index into the list *)
- choose_boolsS (List.length xs) >>$= fun bs ->
- let idx = (natFromNatural (nat_of_bools bs)) mod List.length xs in
- match index xs idx with
- | Just x -> returnS x
- | Nothing -> failS "choose internal_pick"
- end
+ choose_boolsS (List.length xs) >>$= fun bs =>
+ let idx := ((nat_of_bools bs) mod List.length xs)%nat in
+ match List.nth_error xs idx with
+ | Some x => returnS x
+ | None => failS "choose internal_pick"
+ end.
-*)