Library SemiconcreteStates
Inductive chunk := Chunk(p: pred)(vs: list value).
Definition pointsto l v := Chunk pointsto_pred [l, v].
Definition malloc_block l v := Chunk malloc_block_pred [l, v].
Definition heap := chunk -> nat.
Definition state := (store * heap)%type.
Definition empty_heap: heap := fun c => O.
Definition state0 := (store0, empty_heap).
Definition chunk_dec (c1 c2: chunk): {c1 = c2} + {c1 <> c2}.
Defined.
Definition singleton_heap(c: chunk): heap :=
fun c' => if chunk_dec c c' then 1 else 0.
Definition heap_add(h1 h2: heap): heap :=
fun c => h1 c + h2 c.
Lemma singleton_heap_same: forall c, singleton_heap c c = 1.
Lemma singleton_heap_diff: forall c c', c <> c' -> singleton_heap c c' = 0.
Lemma heap_add_assoc: forall h1 h2 h3, heap_add (heap_add h1 h2) h3 = heap_add h1 (heap_add h2 h3).
Lemma heap_add_commut: forall h1 h2, heap_add h1 h2 = heap_add h2 h1.
Lemma heap_add_empty_l: forall h, heap_add empty_heap h = h.
Lemma heap_add_empty_r: forall h, heap_add h empty_heap = h.
Lemma heap_add_singleton0:
forall h1 h2 c h n,
heap_add h1 h2 = heap_add (singleton_heap c) h ->
h2 c = S n ->
(exists h2', h2 = heap_add (singleton_heap c) h2' /\ h = heap_add h1 h2').
Lemma heap_add_singleton:
forall h1 h2 c h,
heap_add h1 h2 = heap_add (singleton_heap c) h ->
(exists h1', h1 = heap_add (singleton_heap c) h1' /\ h = heap_add h1' h2) \/
(exists h2', h2 = heap_add (singleton_heap c) h2' /\ h = heap_add h1 h2').
Lemma singleton_heap_add_singleton:
forall c1 c2 h,
singleton_heap c1 = heap_add (singleton_heap c2) h ->
c1 = c2 /\ h = empty_heap.
Lemma heap_add_eq_empty:
forall h1 h2,
heap_add h1 h2 = empty_heap <->
h1 = empty_heap /\ h2 = empty_heap.
Lemma singleton_heap_add:
forall c h1 h2,
singleton_heap c = heap_add h1 h2 ->
(h1 = singleton_heap c /\ h2 = empty_heap) \/
(h2 = singleton_heap c /\ h1 = empty_heap).
Lemma heap_add_heap_add:
forall h1 h2 ha hb,
heap_add h1 h2 = heap_add ha hb ->
exists h1a, exists h1b, exists h2a, exists h2b,
h1 = heap_add h1a h1b /\
h2 = heap_add h2a h2b /\
ha = heap_add h1a h2a /\
hb = heap_add h1b h2b.
Lemma singleton_neq_empty:
forall c,
singleton_heap c <> empty_heap.