Kripke-Models

Require Import nd forms.
Require Import Coq.Classes.CRelationClasses.
Require Import PslBase.Base.
Require Import PslBase.Lists.BaseLists.

Section Models.
  Context {d : DerivationType}.

Kripke Models


  Class KripkeModel := mkKripkeModel {
                            world : Type;
                            valuation := Prop;
                            cogn : world world Prop;
                            verif : world world Prop;
                            val : world valuation;
                            preorderCogn: PreOrder cogn;
                            monotone: s x y, cogn x y val x s val y s;
                            vericont: subrelation verif cogn;
                            transvalid: x y z, cogn x y verif y z verif x z;
                          }.
  Context {M: (@KripkeModel)}.

  Instance kripke_verif_trans_equiv_Equiv {M': KripkeModel} : Transitive (verif).
  Proof.
    intros u v w H . apply vericont in H. apply transvalid with (y := v); auto.
  Qed.


  Instance cogn_trans {M': KripkeModel} : Transitive (cogn).
  Proof.
    apply preorderCogn.
  Qed.



  Fixpoint evalK {M: KripkeModel} (s: form) : (world) Prop :=
    match s with
    | (K x) ( y r, ((verif y r) evalK x r))
    | Bot ( x False)
    | Var y ( x val x y)
    | x y ( z r', cogn z r' (evalK x r') (evalK y r'))
    | s t ( y evalK s y evalK t y)
    | s t ( y evalK s y evalK t y)
    end.

  Definition evalK' {M: KripkeModel} (Γ: context) :=
     w s, (s Γ) @evalK M s w.

    Definition isIEL (M: KripkeModel) := w, w', verif w w'.

  Definition model_constraint m :=
    if d then True else isIEL m.


  Definition entails Γ φ :=
     (M : KripkeModel), model_constraint M
      (( w,evalK' Γ w @evalK M φ w)).

  Notation "Γ ⊨ φ" := (entails Γ φ) (at level 30).

Evaluation is monotone, that is if φ is true at world w and we can reach world v from w, φ true at v.
  Lemma eval_monotone (s: form) w v:
    cogn w v evalK s w evalK s v.

  Proof.
    intros C H. induction s.
    + intros z . apply H. apply transvalid with (y := v); auto.
    + intros z . apply H. apply transitivity with v; auto. exact .
    + destruct H. split.
      ++ apply . auto.
      ++ apply . auto.
    + destruct H.
      ++ left. auto.
      ++ right. auto.
    + exfalso. apply H.
    + apply monotone with (x := w); auto.
  Qed.


  Lemma monotone_ctx (A:context) :
     w w', cogn w w' evalK' A w evalK' A w'.
  Proof.
    intros. intros t .
    apply eval_monotone with (w := w); auto.
  Qed.


End Models.
  Lemma soundness (Γ: context) (A: form) {D: DerivationType}:
    nd Γ A entails Γ A.
  Proof.
    intro. induction H; try firstorder eauto.
    - unfold entails. intros M' c w . unfold evalK. intros r' . apply IHnd. auto. intros a Ha. destruct Ha; eauto.
      + subst s. apply .
      + apply eval_monotone with w; eauto.
    - unfold entails in . intros M c w . eapply ; auto. apply . apply preorderCogn. apply . auto. auto.
    -
      intros M Mc w .
      intros w' cw Hs. specialize (IHnd M Mc w'). simpl evalK in IHnd.
      intros w'' wc. apply IHnd with w''; auto. apply monotone_ctx with w; auto.
      apply preorderCogn.
    - intros M c w . intros r . apply eval_monotone with w. apply vericont. auto. apply IHnd. auto. auto.
    - intros M c w . specialize ( M c w ). destruct .
      + eapply ; auto. apply . apply preorderCogn.
      + eapply ; eauto. apply preorderCogn.
    - intros M Mc w u c.
      apply monotone_ctx with (w' := u) in . 2: auto.
      unfold isIEL in Mc. destruct (Mc u).
      assert (evalK s x).
      {
        eapply IHnd; auto.
        apply . auto.
      }
      intro.
      apply ( x).
      + apply vericont. auto.
      + apply .
  Qed.