(** *Notice: This file is very sketchy at the moment. Read at your own risk.*)
From mathcomp.ssreflect Require Import ssreflect seq ssrbool ssrnat.
(*Require Import VST.concurrency.juicy_machine.  Require Import VST.concurrency.common.HybridMachineSig. Require Import VST.concurrency.common.scheduler.*)
Section cardinality.
(*Here goes cardinality stuff*)
End cardinality.
(**  We will reduce the safety result to a subset of the type satisfign some predicate [Filter]. Given that the relation R presrves the predicate. *)
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)).

(* Specifications: *)
Lemma filtered_to_unfiltered_safe:
forall P,
konig.safe _ RR P ->
konig.safe X R (thing P).
Lemma unfiltered_to_filtered_safeN:
forall n P,
konig.safeN X R n (thing P) ->
konig.safeN _ RR n P.