Section SCOTT_FIX.
Context {D : Type}.
Fixpoint iterS (n : nat) (f : D -> D) (x : D) {struct n} : D :=
match n with
| O => x
| S n' => f (iterS n' f x)
end.
Variant IterS (f : D -> D) (x : D) : ensemble D :=
| In_IterS (n : nat) : iterS n f x \in IterS f x.
#[local] Hint Constructors IterS : core.
Context {PROSET : isProset D} {CPO : isCpo D}.
Proof with eauto with *.
assert (claim1 : forall n : nat, iterS n f bottom_cpo =< iterS (S n) f bottom_cpo).
{ induction n as [ | n IH]; [eapply bottom_cpo_spec | simpl]... }
intros n1 n2 n1_le_n2. induction n1_le_n2 as [ | n2 n1_le_n2 IH].
- reflexivity.
- rewrite IH...
Qed.
Proof with eauto with *.
assert (claim1 : forall n1 : nat, forall n2 : nat, n1 <= max n1 n2) by lia.
assert (claim2 : forall n1 : nat, forall n2 : nat, n2 <= max n1 n2) by lia.
pose proof (claim3 := iterS_monotonic).
split.
- exists (iterS 0 f bottom_cpo)...
- ii. inversion x1_IN; subst. rename n into n1. inversion x2_IN; subst. rename n into n2.
exists (iterS (max n1 n2) f bottom_cpo). split...
Qed.
Definition lfp_cpo (f : `[D -> D]) : D :=
supremum_cpo (IterS (proj1_sig f) bottom_cpo) (IterS_f_bottom_isDirected_if_f_isMonotonic (proj1_sig f) (ScottContinuousMap_isMonotonic (proj1_sig f) (proj2_sig f))).

Lemma every_ScottContinuousMap_has_a_fixed_point (f : `[D -> D])
: lfp_cpo f \in fixedpointsOf (proj1_sig f).