Library strong_ref_complete2

Require Import base.
Require Import prelim.

Require Import seqt_logic.
Require Import strong_ref_complete.

Module SequentCompleteness (OS:OBSERVATION_SYSTEM).
Module X := ELTS_Theory(OS).
Import OS. Import X.
Import SequentLogic.

  Definition definite o := disj (modality (dia o) TT)
                              (modality (box o) FF).

  Inductive SqAX : list formula -> formula -> Prop :=
    | SqAX0 : forall o,
        SqAX
          nil
          (modality (box o) TT)

    | SqAX1 : forall o p q,
        SqAX
          ((modality (box o) p) :: (modality (box o) q) :: nil)
          (modality (box o) (conj p q))

    | SqAX2 : forall o,
        SqAX
          (modality (dia o) FF :: nil)
          FF

    | SqAX3 : forall o p q,
        SqAX
          (modality (dia o) (disj p q) :: nil)
          (disj (modality (dia o) p) (modality (dia o) q))

    | SqAX4 : forall o p q,
        SqAX
          (modality (box o) p :: modality (dia o) q :: nil)
          (modality (dia o) (conj p q))

    | SqAX5 : forall o x y,
        SqAX
          (modality (box o) (disj x y) :: nil)
          (disj (modality (box o) x)
          (disj (modality (box o) y)
             (conj (modality (dia o) x) (modality (dia o) y))
          ))

    | SqD1 : forall o1 o2,
        SqAX
          (modality (box o1) FF :: nil)
          (definite o2)

    | SqD2 : forall o1 o2,
        SqAX
          (modality (dia o1) TT :: nil)
          (definite o2)

    | SqD3 : forall o x,
        SqAX
          (modality (box o) x :: nil)
          (disj x (definite o)).

Let prime_set := prime_set SqAX.

Definition definite_set (G:formula -> Prop) :=
  forall o, G (modality (dia o) TT) \/
            G (modality (box o) FF).

Definition definite_prime_set := { G:prime_set | definite_set (pset _ G) }.

Definition theorem f := sequent SqAX nil f.

Definition set_steps (X:formula -> Prop) (o:O) (X':formula -> Prop) :=
  (forall p, X (modality (box o) p) -> theorem p \/ X' p) /\
  (forall p, theorem p \/ X' p -> X (modality (dia o) p)).

Definition unlift (LG:lift definite_prime_set) (f:formula) : Prop :=
  exists G, contains LG G /\ proj1_sig G f.

Definition primeELTS : X.ELTS :=
  {| X.state := definite_prime_set
   ; X.steps G o G' :=
       set_steps (proj1_sig G)
                 o
                 (unlift G')
   |}.

Theorem prime_definite_definite_set : forall (G:prime_set) o,
  G (definite o) -> definite_set G.

Theorem prime_definite_set {Classic:EM} : forall f (G:prime_set),
  ~theorem f -> G f -> definite_set G.

Theorem prime_theorems_or_definite {Classic:EM} : forall (G:prime_set),
  (forall f, G f -> theorem f) \/ definite_set G.

Definition subset (G G':formula -> Prop) :=
  forall x, G x -> derives_set SqAX G' x.

Definition def_subset (G G':definite_prime_set) :=
  subset (proj1_sig G) (proj1_sig G').

Lemma sequent_list_conj : forall gs gs',
  (forall x, In x gs' -> In x gs) ->
  sequent SqAX gs (list_conj gs').

Lemma sequent_list_conj2 : forall gs gs' x,
  sequent SqAX (gs'++gs) x ->
  sequent SqAX (list_conj gs :: gs') x.

Lemma sqt_reg_box : forall G o x,
  sequent SqAX G x ->
  sequent SqAX (map (modality (box o)) G) (modality (box o) x).

Lemma box_successor {Classic:EM} : forall
  (G:definite_prime_set) f o
  (Hdia:proj1_sig G (modality (dia o) TT))
  (HGf:~ (proj1_sig G) (modality (box o) f)),
  let G'X p := proj1_sig G (modality (box o) p) in
  let G'Y p := p = f \/ (~derives_set SqAX (proj1_sig G) (modality (dia o) p)) in
    ~derives_sets SqAX G'X G'Y.

Lemma dia_successor {Classic:EM} : forall
  (G:definite_prime_set) f o
  (Hdia: (proj1_sig G) (modality (dia o) f)),

  let G'X p := p = f \/ proj1_sig G (modality (box o) p) in
  let G'Y p := ~derives_set SqAX (proj1_sig G) (modality (dia o) p) in
    ~derives_sets SqAX G'X G'Y.

  Lemma axiom_Sq5 {Classic:EM} : forall w o x y,
    interp (modality (box o) (disj x y)) w ->
    interp
      (disj (modality (box o) x)
      (disj (modality (box o) y)
            (conj (modality (dia o) x)
                  (modality (dia o) y)))) w.

Definition valid_sequent (G:list formula) (x:formula) :=
  forall w, (forall x, In x G -> interp x w) -> interp x w.

Lemma axioms_soundness {Classic:EM} : forall G f,
  SqAX G f -> valid_sequent G f.

Theorem sequent_soundness {Classic:EM} : forall G f,
  sequent SqAX G f ->
  valid_sequent G f.

Theorem theorem_soundness {Classic:EM} : forall f, theorem f -> valid f.

Lemma derives_nec : forall o f,
  theorem f ->
  theorem (modality (box o) f).

Lemma cannonical_model {Classic:EM} : forall (f:formula) (LG:lift definite_prime_set),
  (unlift LG f -> interp f (X.Build_world primeELTS LG)) /\
  (interp f (X.Build_world primeELTS LG) -> theorem f \/ unlift LG f).

Theorem theorem_completeness {Classic:EM} :
  forall f, valid f -> theorem f.

Theorem disjunctive_property_of_theorems {Classic:EM} :
  forall p q,
    theorem (disj p q) ->
    theorem p \/ theorem q.

Theorem sequent_completeness {Classic:EM} : forall G x,
  valid_sequent G x ->
  sequent SqAX G x.

Theorem main {Classic:EM} : forall G x,
  valid_sequent G x <-> sequent SqAX G x.

Require Import prop_logic.
Module PL := PropLogic.

Fixpoint toH (f:formula) : PL.formula :=
  match f with
  | TT => PL.TT
  | FF => PL.FF
  | conj x y => PL.conj (toH x) (toH y)
  | disj x y => PL.disj (toH x) (toH y)
  | modality m x => PL.modality m (toH x)
  end.

Lemma toH_impl_free : forall f,
  PL.impl_free (toH f).

Lemma from_impl_free : forall f:PL.formula,
  PL.impl_free f -> exists f', f = toH f'.

Definition Hsequent (G:list formula) (x:formula) :=
  (PL.impl (PL.list_conj (map toH G)) (toH x)).

Lemma Hsequent_rank1 : forall G x,
  X.rank1 (Hsequent G x).

Lemma toH_interp : forall f w,
  interp f w <-> PL.interp (toH f) w.

Theorem adequate {Classic:EM} : forall X Y x y,
    X.image_finite X ->
    X.image_finite Y ->
    (X.refines X Y x y <->
     (forall f,
      interp f (X.Build_world X (into x)) ->
      interp f (X.Build_world Y (into y)))).

Theorem same_sequents {Classic:EM} : forall G x,
  sequent SqAX G x <-> PL.theorem X.AX (Hsequent G x).

End SequentCompleteness.