Section filtered_konig.
Variable X: Type.
Variable Filter: X -> Prop.
Variable R: X->X->Prop.
Hypothesis em: forall P, P \/ ~ P.
Hypothesis  preservation :  forall P P', Filter P -> R P P' -> Filter P'.
(* From the relation R, we derive a, dependently typed relation RR for all elements satyisfying the predicate Filter*)
Record TT :Type:= mkTT {thing: X; prf: Filter thing}.
Inductive RR: TT->TT->Prop:=
| stepstep: forall P x' (stp: R (thing P) x'), RR P (mkTT x' (preservation _ _ (prf P) stp)).
(* the number of different elements in X is finite *)
Inductive cardinality {X} (P:X->Prop): nat -> Prop:=
|Cardinality n (f:nat-> X): (forall i j, i<n -> j<n -> i<>j -> f(i)<>f(j)) ->
(forall i, i<n -> P (f i)) ->
(forall x, P x -> exists i, i < n /\ f i = x) ->
cardinality P n.
Inductive cardinality' {X} (P:X->Prop): nat -> Prop:=
|Cardinality' n (f:nat-> X): (forall i j, i<n -> j<n -> i<>j  -> f(i)<>f(j)) ->
(forall i, i<n -> P (f i)) ->
cardinality' P n.

(* If every element in the filter, is finitely branching then finite safety safeN implies infinite safetyy safe.*)
Lemma filtered_konigsafe:
forall (x : X),
(forall P : Prop, P \/ ~ P) ->
(forall x0 : X, Filter x0 -> finite (R x0)) ->
Filter x ->
(forall n : nat, safeN X R n x) -> konig.safe X R x.