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.
Proof with eauto with *.
change (forall X : ensemble B, improveFilter X n1 =< improveFilter X n2).
induction n1_le_n2 as [ | n2 n1_le_n2 IH]; intros X...
rewrite IH with (X := X). transitivity (Insertion (improveFilter X n2) n2).
- intros z z_in; left...
- simpl; eapply fact3_of_1_2_8...
Qed.

Lemma lemma1_of_1_2_13_aux1 bs F n
(F_isFilter : isFilter F)
(FINITE_SUBSET : L.is_finsubset_of bs (E.union (improveFilter F n) (insertion (improveFilter F n) n)))
: andsB bs \in improveFilter F n \/ (exists b, L.In b bs /\ b \in insertion (improveFilter F n) n).