Library SemiconcreteExecutionFacts

Require Export SemiconcreteExecution.

Facts about specific semiconcrete mutators

with_store, with_store', with_local_store


Definition update_store_ f: scmutatora store :=
  fun st => let (s, h) := st in single (f s, h) s.

Lemma with_store_covers_update_store s A (C: scmutatora A):
  with_store s C ==> s0 <- update_store_ (fun _ => s); C;, update_store_ (fun _ => s0).

Lemma with_store_covers_update_store' s A (C: scmutatora A):
  s0 <- update_store_ (fun _ => s); C;, update_store_ (fun _ => s0) ==> with_store s C.

Lemma with_store'_covers_update_store s (C: scmutator):
  with_store' s C ==> s0 <- update_store_ (fun _ => s); C; s1 <- update_store_ (fun _ => s0); yield s1.

Lemma with_store'_covers_update_store' s (C: scmutator):
  s0 <- update_store_ (fun _ => s); C; s1 <- update_store_ (fun _ => s0); yield s1 ==> with_store' s C.

Lemma with_local_store_covers_update_store A (C: scmutatora A):
  with_local_store C ==> s0 <- update_store_ (fun s => s); C;, update_store_ (fun _ => s0).

Lemma with_local_store_covers_update_store' A (C: scmutatora A):
  s0 <- update_store_ (fun s => s); C;, update_store_ (fun _ => s0) ==> with_local_store C.

Lemma with_store_equiv_update_store s A (C: scmutatora A):
  with_store s C <==> s0 <- update_store_ (fun _ => s); C;, update_store_ (fun _ => s0).

Lemma with_store'_equiv_update_store s (C: scmutator):
  with_store' s C <==> s0 <- update_store_ (fun _ => s); C; s1 <- update_store_ (fun _ => s0); yield s1.

Lemma with_local_store_equiv_update_store A (C: scmutatora A):
  with_local_store C <==> s0 <- update_store_ (fun s => s); C;, update_store_ (fun _ => s0).

Lemma with_store_with_store':
  forall s (C1 C2: scmutator),
  with_store s (C1; C2) ==> s' <- with_store' s C1; with_store s' C2.

Lemma with_store'_with_store:
  forall s s' (C: scmutator) (f: store -> scmutator),
  seqf (with_store' s (with_store s' C)) f ==>
  with_store s' C; f s.

Lemma with_store_with_store'_ s0 s (C: scmutator) B (f: store -> scmutatora B):
  with_store s0 (seqf (with_store' s C) f) ==>
  seqf (with_store' s C) (fun s1 => with_store s0 (f s1)).

Lemma with_store_with_store_ s0 s A (C: scmutatora A) B (f: A -> scmutatora B):
  with_store s0 (seqf (with_store s C) f) ==>
  seqf (with_store s C) (fun a => with_store s0 (f a)).

Lemma with_store_with_store s0 s A (C: scmutatora A):
  with_store s0 (with_store s C) ==> with_store s C.

set_store


Definition set_store s: scmutatora store :=
  fun st => let (s0, h) := st in
  single (s, h) s0.

Lemma set_store_with_store s A (C: scmutatora A):
  s0 <- set_store s; x <- C; set_store s0; yield x ==> with_store s C.

Lemma set_store_with_store' s (C: scmutator):
  s0 <- set_store s; C; set_store s0 ==> with_store' s C.

Definition get_store: scmutatora store :=
  fun st => let (s, h) := st in
  single (s, h) s.

Lemma set_store_with_local_store (C: scmutator):
  s0 <- get_store; C; set_store s0; yield tt ==> with_local_store C.

havoc


Lemma sat_havoc xs s h Q:
  sat (havoc xs (s, h)) Q <->
  forall s', (forall x, ~ In x xs -> s' x = s x) -> Q (s', h) tt.

Lemma sat_havoc_elim xs s h Q:
  sat (havoc xs (s, h)) Q ->
  forall s', (forall x, ~ In x xs -> s' x = s x) -> Q (s', h) tt.

Lemma sat_havoc_intro xs s h (Q: state -> unit -> Prop):
  (forall s', (forall x, ~ In x xs -> s' x = s x) -> Q (s', h) tt)
  ->
  sat (havoc xs (s, h)) Q.

Lemma havoc_covers_noop xs: havoc xs ==> noop.