Definition key_in_stash_dec k s :
  { v : nat & blk_in_stash k v s } +
  { ~ exists v, blk_in_stash k v s }.Definition key_in_path_dec k s :
  { v : nat & blk_in_path k v s } +
  { ~ exists v, blk_in_path k v s }.Definition def_or_undef k s :
  { v : nat & blk_in_state k v s } +
  { undef k s }.Definition get_state_val k s : option nat :=
  match def_or_undef k s with
  | inleft p => Some (projT1 p)
  | inright _ => None
  end.Definition get_val k s : nat :=
  match get_state_val k s with
  | Some v => v
  | None => 0
  end.

(* Specifications: *)
Lemma blk_in_state_get_state_val : forall k v s, well_formed s -> blk_in_state k v s -> get_state_val k s = Some v.
Lemma get_state_val_blk_in_state : forall k v s, well_formed s -> get_state_val k s = Some v -> blk_in_state k v s.
Lemma kv_rel_get_val : forall k v s, well_formed s -> kv_rel k v s -> get_val k s = v.
Lemma undef_get_state_val : forall k s, well_formed s -> undef k s -> get_state_val k s = None.
Lemma get_state_val_undef : forall k s, well_formed s -> get_state_val k s = None -> undef k s.
Lemma blk_in_state_get_state_val : forall k v s, well_formed s -> blk_in_state k v s -> get_state_val k s = Some v.
Lemma get_state_val_blk_in_state : forall k v s, well_formed s -> get_state_val k s = Some v -> blk_in_state k v s.
Lemma kv_rel_get_val : forall k v s, well_formed s -> kv_rel k v s -> get_val k s = v.
Lemma undef_get_state_val : forall k s, well_formed s -> undef k s -> get_state_val k s = None.
Lemma get_state_val_undef : forall k s, well_formed s -> get_state_val k s = None -> undef k s.