Section section_2_of_chapter_1_PART2. (* Reference: << Constructive Completeness Proofs and Delimited Control >> written by "Danko Ilik" *)
Context {B : Type} {SETOID : isSetoid B} {CBA : isCBA B}.
Variant insertion X n : ensemble B :=
| In_insertion
(EQUICONSISTENT : equiconsistent X (cl (E.insert (enum n) X)))
: enum n \in insertion X n.
#[global]
Add Parametric Morphism :
insertion with signature (eqProp ==> eq ==> eqProp)
as insertion_lifts_eqProp.
Proof with eauto with *.
enough (to_show : forall X, forall X', X == X' -> forall n, insertion X n \subseteq insertion X' n).
{ ii. split; eapply to_show... }
intros X X' X_eq_X' n b b_in.
inversion b_in; subst. econstructor. rewrite <- X_eq_X' at 1.
rewrite EQUICONSISTENT. clear EQUICONSISTENT b_in.
enough (EQUAL : cl (E.insert (enum n) X) == cl (E.insert (enum n) X')).
{ red. now rewrite EQUAL. }
now rewrite X_eq_X'.
Qed.
Definition Insertion X n : ensemble B :=
E.union X (insertion X n).
Fixpoint improveFilter (X : ensemble B) (n : nat) {struct n} : ensemble B :=
match n with
| O => X
| S n' => cl (Insertion (improveFilter X n') n')
end.
Definition completeFilterOf X : ensemble B :=
fun b => exists n, b \in improveFilter X n.

Lemma lemma1_of_1_2_12 (n1 : nat) (n2 : nat)
(n1_le_n2 : n1 <= n2)
: forall X, improveFilter X n1 \subseteq improveFilter X n2.