Definition contextual_consi {ora: RandomOracle} (d: RandomHistory -> Prop) (h: RandomHistory): Prop :=
forall h', d h' -> conflict_history h h' -> False.
Definition nth_layer_pre_extension {ora: RandomOracle} (n: nat) (d: RandomHistory -> Prop): RandomHistory -> Prop :=
fun h => d h \/ (is_n_history n h /\ contextual_consi d h).
Fixpoint n_layers_pre_extension {ora: RandomOracle} (n: nat) (d: RandomHistory -> Prop): RandomHistory -> Prop :=
match n with
| 0 => d
| S n => nth_layer_pre_extension n (n_layers_pre_extension n d)
end.
Definition finite_layers_pre_extension {ora: RandomOracle} (d: RandomHistory -> Prop): RandomHistory -> Prop :=
fun h => exists n, n_layers_pre_extension n d h.
Definition max_pre_extension {ora: RandomOracle} (d: RandomHistory -> Prop): RandomHistory -> Prop :=
fun h => finite_layers_pre_extension d h \/ (is_inf_history h /\ contextual_consi (finite_layers_pre_extension d) h).
Definition guarded_covered {ora: RandomOracle} (P: RandomHistory -> Prop) (d: RandomHistory -> Prop): Prop :=
forall h, P h -> contextual_consi d h -> d h.
Definition nth_layer_covered {ora: RandomOracle} (n: nat) (d: RandomHistory -> Prop): Prop :=
guarded_covered (is_n_history n) d.

(* Specifications: *)
Lemma contextual_consi_shorten {ora: RandomOracle}: forall (n: nat) (d: RandomHistory -> Prop) (h h0: RandomHistory),
h n <> None ->
h0 n <> None ->
contextual_consi d h ->
contextual_consi d h0 ->
history_coincide n h h0 ->
n_conflict_history n h h0 ->
contextual_consi d (fstn_history n h).
Lemma is_n_history_conflict {ora: RandomOracle}: forall n m h1 h2,
is_n_history n h1 ->
is_n_history n h2 ->
n_conflict_history m h1 h2 ->
m < n.
Lemma is_n_history_Some {ora: RandomOracle}: forall n m h, m < n -> is_n_history n h -> h m <> None.
Lemma nth_layer_pre_extension_spec {ora: RandomOracle}: forall (n: nat) (d: RandomHistory -> Prop),
(history_set_consi d /\ forall n', n' < n -> nth_layer_covered n' d) ->
(history_set_consi (nth_layer_pre_extension n d) /\
forall n', n' < S n -> nth_layer_covered n' (nth_layer_pre_extension n d)).
Lemma n_layers_pre_extension_spec {ora: RandomOracle}: forall (n: nat) (d: RandomHistory -> Prop),
history_set_consi d ->
history_set_consi (n_layers_pre_extension n d) /\
forall n', n' < n -> nth_layer_covered n' (n_layers_pre_extension n d).
Lemma fin_history_n_history {ora: RandomOracle}: forall h,
is_fin_history h ->
exists n, is_n_history n h.
Lemma n_layers_pre_extension_mono {ora: RandomOracle}: forall (n1 n2: nat) (d: RandomHistory -> Prop) h,
n1 <= n2 ->
(n_layers_pre_extension n1 d) h ->
(n_layers_pre_extension n2 d) h.
Lemma n_layers_pre_extension_consi_mono {ora: RandomOracle}: forall (n1 n2: nat) (d: RandomHistory -> Prop) h,
n1 <= n2 ->
contextual_consi (n_layers_pre_extension n2 d) h ->
contextual_consi (n_layers_pre_extension n1 d) h.
Lemma finite_layers_pre_extension_spec {ora: RandomOracle}: forall (d: RandomHistory -> Prop),
history_set_consi d ->
history_set_consi (finite_layers_pre_extension d) /\
guarded_covered is_fin_history (finite_layers_pre_extension d).
Lemma max_pre_extension_spec {ora: RandomOracle}: forall (d: RandomHistory -> Prop),
history_set_consi d ->
history_set_consi (max_pre_extension d) /\
guarded_covered is_inf_history (max_pre_extension d).