Kripke.correspondence

Require Import List.
Export ListNotations.
Require Import PeanoNat.
Require Import Lia.
Require Import Ensembles.

Require Import im_syntax.
Require Import CKH_export.
Require Import kripke_sem.

Axiom LEM : P, P P.

Section Cd.

(* We present strong, sufficient and correspondence conditions on
    frames for the axiom Cd. *)


Definition mupcone (F : frame) (a : nodes Prop) := fun w v, a v mreachable v w.
Definition mdowncone (F : frame) (a : nodes Prop) := fun w v, a v mreachable w v.
Definition iupcone (F : frame) (a : nodes Prop) := fun w v, a v ireachable v w.
Definition idowncone (F : frame) (a : nodes Prop) := fun w v, a v ireachable w v.

(* A sufficient condition to prove the axiom Cd (◊φ ∨ ψ)→  (◊φ) ∨ (◊ψ) is given below. *)

Definition suff_Cd_frame (F : frame) := x, x', ireachable x x'
         y z, ireachable x y mreachable x' z w, mreachable y w ireachable z w.

(* A stronger condition for Cd is the following. *)

Definition strong_Cd_frame (F : frame) := w v u, ireachable w v mreachable w u x, mreachable v x ireachable u x.

Lemma strong_is_suff_Cd : F,
                  strong_Cd_frame F suff_Cd_frame F.
Proof.
intros F HF x. exists x ; repeat split.
- apply ireach_refl.
- intros. destruct (HF _ _ _ H ). exists ; firstorder.
Qed.


(* The axiom Cd corresponds to the following frame property. *)

Definition Cd_frame (F : frame) := x y z, ireachable x y ireachable x z
                                      (mdowncone F (Singleton _ expl) y) (mdowncone F (Singleton _ expl) z)
                     w, ireachable x w
                                  Included _ (mupcone F (Singleton _ w)) (idowncone F (mupcone F (Singleton _ y)))
                                  Included _ (mupcone F (Singleton _ w)) (idowncone F (mupcone F (Singleton _ z))).

Lemma correspond_Cd: F,
                  Cd_frame F φ ψ, fvalid F (Cd φ ψ).
Proof.
intros F ; split ; intro H.
- intros φ ψ M frameEq w v iwv Hv ; subst.
  epose (LEM _). destruct o as [P | NP] ; [exact P | exfalso ].
  assert ( y, ireachable v y s, mreachable y s forces M s φ).
  { epose (LEM _). destruct o as [ | ] ; [exact | exfalso ].
    apply NP. left. intros u ivu. epose (LEM _). destruct o as [ | ] ; [exact | exfalso ].
    apply . exists u. split ; auto. intros. intro. apply . exists s ; split ; auto. }
  destruct as (y & & ).
  assert ( z, ireachable v z s, mreachable z s forces M s ψ).
  { epose (LEM _). destruct o as [ | ] ; [exact | exfalso ].
    apply NP. right. intros u ivu. epose (LEM _). destruct o as [ | ] ; [exact | exfalso ].
    apply . exists u. split ; auto. intros. intro. apply . exists s ; split ; auto. }
  destruct as (z & & ).
  destruct (H _ _ _ ) as ( & & & ).
  1-2: intros K ; destruct K as (u & & ) ; inversion ; subst.
  apply with expl ; auto. apply Expl.
  apply with expl ; auto. apply Expl.
  destruct (Hv _ ) as (u & & [ | ]) ; cbn in .
  assert ((idowncone fra (mupcone fra (Singleton nodes y))) u).
  apply . exists ; split ; auto. apply In_singleton.
  destruct as (t & & ). destruct as (s & & ).
  inversion ; subst. apply with t ; auto. apply Persistence with u ; auto.
  assert ((idowncone fra (mupcone fra (Singleton nodes z))) u).
  apply . exists ; split ; auto. apply In_singleton.
  destruct as (t & & ). destruct as (s & & ).
  inversion ; subst. apply with t ; auto. apply Persistence with u ; auto.
- intros x y z .
  epose (LEM _). destruct o as [P | NP] ; [exact P | exfalso ].
  remember (fun (v : nodes) (p : ) ( (idowncone F (mupcone F (Singleton _ y)) v) p = 0)
                                                               ( (idowncone F (mupcone F (Singleton _ z)) v) p = 1) v = expl) as Val.
  assert (: u v : nodes, ireachable u v p : , Val u p Val v p).
  { intros. subst. destruct as [( & ) | [( & ) | ]] ; subst.
    + left. split ; auto. intro. apply . destruct as ( & ( & & ) & ).
       inversion ; subst. exists . split ; auto. exists ; split ; auto. apply ireach_tran with v ; auto.
    + right ; left. split ; auto. intro. apply . destruct as ( & ( & & ) & ).
       inversion ; subst. exists . split ; auto. exists ; split ; auto. apply ireach_tran with v ; auto.
    + right ; right. apply ireach_expl in ; auto. }
  assert (: p : , Val expl p).
  { intro p. subst. right ; right ; auto. }
  pose (Build_model F Val ).
  assert ( forces m x (( (#0)) ( (#1)))).
  { intro. cbn in . destruct .
    + destruct ( _ ) as ( & & ). rewrite HeqVal in . destruct as [( & ) | [( & ) | ]] ; try lia.
       - apply . exists . split. exists y ; split ; auto. apply In_singleton. apply ireach_refl.
       - subst. apply . exists expl. split ; auto. apply In_singleton.
    + destruct ( _ ) as ( & & ). rewrite HeqVal in . destruct as [( & ) | [( & ) | ]] ; try lia.
       - apply . exists . split. exists z ; split ; auto. apply In_singleton. apply ireach_refl.
       - subst. apply . exists expl. split ; auto. apply In_singleton. }
  assert (forces m x ( ((#0) (#1)))).
  { intros v ixv. epose (LEM _). destruct o as [ | ] ; [exact | exfalso ].
    apply NP. exists v. repeat split ; auto. 1-2: intros s Hs.
    epose (LEM _). destruct o as [ | ] ; [exact | exfalso ].
    apply . exists s. split. destruct Hs as (k & & ) ; inversion ; subst ; auto.
    left. cbn. subst. left ; split ; auto.
    epose (LEM _). destruct o as [ | ] ; [exact | exfalso ].
    apply . exists s. split. destruct Hs as (k & & ) ; inversion ; subst ; auto.
    right. cbn. subst. right ; left ; split ; auto. }
   apply . cbn. pose (H (# 0) (# 1) m (eq_refl) x). apply f. apply ireach_refl.
    apply .
Qed.


(* We show that the strong condition implies the sufficient, which in turn
    implies the correspondence one. *)


Lemma strong_impl_suff_Cd : F, strong_Cd_frame F suff_Cd_frame F.
Proof.
intros F H x. exists x ; split. apply ireach_refl. intros.
destruct (H _ _ _ ) as (u & myu & izu). exists u ; split ; auto.
Qed.


Lemma suff_impl_Cd : F, suff_Cd_frame F Cd_frame F.
Proof.
intros F H x y z ixy ixz Hy Hz.
destruct (H x) as (w & & ). exists w. repeat split ; auto.
- intros v Hv. destruct Hv as (u & & ). inversion ; subst.
  destruct ( _ _ ixy ) as (r & & ). exists r ; split ; auto.
  exists y ; auto. repeat split ; auto.
- intros v Hv. destruct Hv as (u & & ). inversion ; subst.
  destruct ( _ _ ixz ) as (r & & ). exists r ; split ; auto.
  exists z ; auto. repeat split ; auto.
Qed.


Lemma sufficient_Cd : F,
                  suff_Cd_frame F φ ψ, fvalid F (Cd φ ψ).
Proof.
intros F H φ ψ. apply correspond_Cd. apply suff_impl_Cd ; auto.
Qed.


End Cd.

Section Idb.

(* We present sufficient and correspondence conditions on
    frames for the axiom Idb. *)


Definition suff_Idb_frame (F : frame) := x y z, mreachable x y ireachable y z
                     u, ireachable x u
                                  Included _ (iupcone F (Singleton _ u)) (mdowncone F (iupcone F (Singleton _ z)))
                                  mreachable u z.

(* The axiom Idb ((◊φ) → (□ψ)) →  □(φ → ψ) corresponds to the following frame property. *)

Definition Idb_frame (F : frame) := x y z, mreachable x y ireachable y z z expl
                     u w, ireachable x u mreachable u w ireachable w z
                                  Included _ (iupcone F (Singleton _ u)) (Union _ (mdowncone F (iupcone F (Singleton _ z))) (mdowncone F (Singleton _ expl))).

Lemma correspond_Idb: F,
                  Idb_frame F φ ψ, fvalid F (Idb φ ψ).
Proof.
intros F ; split ; intro Hyp.
- intros φ ψ M frameEq x y ixy Hyv ; subst.
  epose (LEM _). destruct o as [P | NP] ; [exact P | exfalso ].
  assert ( u v w, ireachable y u mreachable u v ireachable v w forces M w φ forces M w ψ).
  { epose (LEM _). destruct o as [ | ] ; [exact | ].
    exfalso. apply NP. intros u ivu r mur s irs Hs ; subst. epose (LEM _). destruct o as [ | ] ; [exact | ].
    exfalso. apply . exists u,r,s. repeat split ; auto. }
  destruct H as (u & v & w & iyu & muv & ivw & Hw & NHw).
  destruct (Hyp _ _ _ muv ivw) as ( & & & mu0w0 & iw0w & cones).
  intro. apply NHw. subst ; apply Expl ; auto.
  assert (forces M ( φ)).
  { intros iu0v1.
    assert ((iupcone fra (Singleton nodes )) ). exists . split ; auto.
    apply In_singleton.
    apply cones in H. destruct H.
    - unfold In in H. destruct H. destruct H. exists . split ; auto.
      apply Persistence with w ; auto. destruct H. destruct H. inversion H ; subst ; auto.
    - inversion H. destruct . inversion ; subst. exists expl. split ; auto. apply Expl. }
  assert ( forces M ( ψ)).
  { intro ctr. pose (ctr _ (ireach_refl ) _ mu0w0). apply NHw. apply Persistence with ; auto. }
  apply . intros iu0v1 mv1u1. cbn in Hyv. apply Hyv with ; auto.
  apply ireach_tran with u ; auto.
- intros x y z mxy iyz zexpl.
  remember (fun (v : nodes) (p : ) (iupcone F (Singleton _ z) v p = 0)
                                                               ( idowncone F (Singleton _ z) v p = 1)
                                                               v = expl) as Val.
  assert (: u v : nodes, ireachable u v p : , Val u p Val v p).
  { intros. rewrite HeqVal. rewrite HeqVal in . destruct as [( & ) | [( & ) | ] ] ; subst.
    + left ; split ; auto. inversion . destruct . inversion ; subst. exists .
       split ; auto. apply ireach_tran with u ; auto.
    + right ; left ; split ; auto. intro. apply . destruct . destruct . inversion ; subst.
       exists ; split ; auto. apply ireach_tran with v ; auto.
    + right ; right. apply ireach_expl in H ; auto. }
  assert (: p : , Val expl p).
  { intro p. rewrite HeqVal. right ; right ; auto. }
  pose (Build_model F Val ).
  assert ( forces m x ( ((# 0) (# 1)))).
  { intro. pose (H _ (@ireach_refl _ x) _ mxy _ iyz). cbn in f.
    rewrite HeqVal in f. destruct f.
    + left. split ; auto. exists z ; split. apply In_singleton. apply ireach_refl.
    + destruct ; lia.
    + destruct . destruct . apply ; exists z ; split. apply In_singleton.
       apply ireach_refl. auto. }
  assert ( forces m x (( (# 0)) ( (# 1)))).
  { intro. apply H. pose (Hyp (#0) (#1) m eq_refl x).
    cbn in *. apply f ; auto. apply ireach_refl. }
  assert ( s, ireachable x s forces m s ( # 0) forces m s ( # 1)).
  { epose (LEM _). destruct o as [P | NP] ; [exact P | ].
    exfalso. apply . intros v ixv Hv. epose (LEM _). destruct o as [ | ] ; [exact | ].
    exfalso. apply NP. exists v ; repeat split ; auto. }
  destruct as (s & & & ).
  assert ( v w, ireachable s v mreachable v w forces m w (# 1)).
  { epose (LEM _). destruct o as [P | NP] ; [exact P | exfalso].
     apply . intros v isv w mvw. epose (LEM _). destruct o as [ | ] ; [exact | exfalso].
     apply NP. exists v. exists w. repeat split ; auto. }
  destruct as (v & w & isv & mvw & Hw).
  exists v. exists w. repeat split ; auto.
  + apply ireach_tran with s ; auto.
  + cbn in Hw. subst. epose (LEM _). destruct o as [P | NP] ; [exact P | exfalso].
    apply Hw. right. left. split ; auto. intro. apply NP. destruct as ( & & ).
    inversion ; subst ; auto.
  + intros u Hu. destruct Hu as (t & & ). inversion ; subst. unfold In.
     destruct ( _ (ireach_tran _ _ _ isv )) as (e & & ). destruct . destruct ; left ; exists e ; split ; auto.
     destruct . exfalso ; lia. subst. right. exists expl ; split ; auto. apply In_singleton.
Qed.


(* We also show that the sufficient implies the correspondence condition. *)

Lemma suff_impl_Idb : F, suff_Idb_frame F Idb_frame F.
Proof.
intros F H x y z ixy myz Hz. destruct (H _ _ _ ixy myz) as (u & & & ).
exists u. exists z. repeat split ; auto.
apply ireach_refl.
intros w Hw. left ; auto.
Qed.


Lemma sufficient_Idb : F,
                  suff_Idb_frame F φ ψ, fvalid F (Idb φ ψ).
Proof.
intros F H φ ψ. apply correspond_Idb. apply suff_impl_Idb ; auto.
Qed.


End Idb.

Section Nd.

(* We present sufficient and correspondence conditions on
    frames for the axiom Nd. *)


(* A sufficient condition to prove the axiom Nd (◊⊥) → ⊥ is that only expl can modally reach expl. *)

Definition suff_Nd_frame (F : frame) := w, mreachable w expl w = expl.

(* The axiom Nd corresponds to the following frame property: if all intuitionistic
    successors of a world w are such that the can modally reach expl, then w is expl. *)


Definition Nd_frame (F : frame) := w, ( v, ireachable w v mreachable v expl) w = expl.

Lemma correspond_Nd : F,
                  Nd_frame F fvalid F Nd.
Proof.
intro F ; split ; intro H.
- intros M frameEq w v iwv Hv ; subst ; cbn in *. apply H.
  intros. apply Hv in . destruct as (u & & ) ; subst ; auto.
- intros w Hw.
  assert (: u v : nodes, ireachable u v p : , (fun (_ : nodes) (_ : ) True) u p (fun (_ : nodes) (_ : ) True) v p).
  intros ; auto.
  assert (: p : , (fun (_ : nodes) (_ : ) True) expl p).
  intros ; auto.
  pose (Build_model F (fun v n True) ).
  pose (H m). unfold mvalid in . cbn in . apply with w ; auto.
  apply ireach_refl. intros. exists expl ; split ; auto.
Qed.


(* The sufficient implies the correspondence condition. *)

Lemma suff_impl_Nd : F, suff_Nd_frame F Nd_frame F.
Proof.
intros F H x Hx. apply H. apply Hx. apply ireach_refl.
Qed.


Lemma sufficient_Nd : F,
                  suff_Nd_frame F fvalid F Nd.
Proof.
intros F H. apply correspond_Nd. apply suff_impl_Nd ; auto.
Qed.


End Nd.

Section suff_CdIdb.

(* While we did not present an alternative condition to sufficient and correspondence
    for Idb, we can find one once both Cd and Idb are present. *)


Definition weak_Idb_frame (F : frame) := x y z, mreachable x y ireachable y z w, ireachable x w mreachable w z.

Definition strong_Cd_weak_Idb_frame (F : frame) := strong_Cd_frame F weak_Idb_frame F.

(* Being a strong Cd frame as well as a weak Idb frame implies being 
    a correspondence Cd and Idb frame. *)


Lemma strong_Cd_weak_Idb_Cd_Idb : F, strong_Cd_weak_Idb_frame F (Cd_frame F Idb_frame F).
Proof.
intros F H. destruct H ; split.
- apply correspond_Cd. intros. apply strong_is_suff_Cd in H. apply sufficient_Cd with:=φ) (ψ:=ψ) in H ; auto.
- intros x y z mxy iyz Hz. destruct ( _ _ _ mxy iyz). destruct . exists . exists z.
  repeat split ; auto. apply ireach_refl.
  intros v Hv. destruct Hv as (w & & ). unfold In. inversion ; subst.
  unfold suff_Cd_frame in H. destruct (H _ _ _ ). destruct . left. exists .
  split ; auto. exists z ; split ; auto. apply In_singleton.
Qed.


End suff_CdIdb.

Section Ndb.

(* We present sufficient and correspondence conditions on
    frames for the axiom Ndb. *)


(* A sufficient condition to prove the axiom Nd (◊⊥) → (□ ⊥) is that only expl can modally reach expl. *)

Definition suff_Ndb_frame (F : frame) := w, mreachable w expl ( v, mreachable w v v = expl).

(* The axiom Ndb corresponds to the following frame property. *)

Definition Ndb_frame (F : frame) := w, ( v, ireachable w v mreachable v expl) ( v u, ireachable w v mreachable v u u = expl).

Lemma correspond_Ndb : F,
                  Ndb_frame F fvalid F Ndb.
Proof.
intro F ; split ; intro H.
- intros M frameEq w v iwv Hv u ivu x mux ; subst ; cbn in *.
  assert ( z, ireachable v z mreachable z expl).
  { intros. destruct (Hv _ ) as (y & & ) ; subst ; auto. }
  apply H in . apply with u ; auto.
- intros w Hw v u iwv mvu.
  assert (: u v : nodes, ireachable u v p : , (fun (_ : nodes) (_ : ) True) u p (fun (_ : nodes) (_ : ) True) v p).
  intros ; auto.
  assert (: p : , (fun (_ : nodes) (_ : ) True) expl p).
  intros ; auto.
  pose (Build_model F (fun v n True) ).
  pose (H m). unfold mvalid in . cbn in .
  pose ( eq_refl _ _ iwv). apply e with v ; auto. 2: apply ireach_refl.
  intros. exists expl ; split ; auto. apply Hw. apply ireach_tran with v ; auto.
Qed.


(* The sufficient condition implies the correspondence one. *)

Lemma suff_impl_Ndb : F, suff_Ndb_frame F Ndb_frame F.
Proof.
intros F H w Hw v u iwv mvu. apply Hw in iwv.
pose (H _ iwv). apply e ; auto.
Qed.


Lemma sufficient_Ndb : F,
                  suff_Ndb_frame F fvalid F Ndb.
Proof.
intros F H. apply correspond_Ndb. apply suff_impl_Ndb ; auto.
Qed.


End Ndb.