Tarski Semantics

Generalized Theory Extension


Require Export ND.

Section GenCons.
  Context { : Signature}.
  Context {HdF : eq_dec Funcs} {HdP : eq_dec Preds}.
  Context {HeF : enumT Funcs} {HeP : enumT Preds}.

  Context {b : bottom}.
  Variable GBot : form.
  Hypothesis GBot_closed : closed GBot.

  Notation "⊥" := GBot.
  Notation "A ⊢G phi" := (@prv class b A ) (at level 30).
  Notation "T ⊩G phi" := (@tprv class b T ) (at level 30).

  Definition econsistent T T' := T' G T G .

Union


  Section Union.
    Variable f : theory.
    Hypothesis econsistent_f : n, econsistent (f n) (f (S n)).
    Hypothesis f_le : m n, m n f m f n.

    Definition union (f : theory) := fun t n, f n t.

    Lemma union_f :
      union f G n, f n G .
    Proof.
      intros (A & & ). enough ( n, A f n) as [n H] by now exists n, A.
      clear ; induction A.
      - exists 0; firstorder.
      - destruct IHA as [n Hn]; destruct ( a) as [m Hm]; firstorder.
        exists (max n m); intros ? []; subst.
        + eapply f_le; [apply Nat.le_max_r | firstorder].
        + eapply f_le; [apply Nat.le_max_l | firstorder].
    Qed.


    Lemma union_sub n :
      f n union f.
    Proof.
      firstorder.
    Qed.


    Lemma union_econsistent :
      econsistent (f 0) (union f).
    Proof.
      intros [n H] % union_f. induction n; unfold econsistent in *; eauto.
    Qed.


    Lemma union_closed :
      ( n, closed_T (f n)) closed_T (union f).
    Proof.
      intros f_closed ? n [m H]. now apply f_closed with (n := m) ( := ).
    Qed.

  End Union.

Explosion


  Section Explosion.
    Variable T : theory.
    Hypothesis Hclosed : closed_T T.

    Variable e : form.
    Hypothesis He : , n, e n = .

    Definition exp_axiom := --> close .

    Lemma exp_axiom_lift A :
      exp_axiom A exp_axiom (map (subst_form form_shift) A).
    Proof.
      intros H. apply in_map_iff. exists (exp_axiom ). split. 2: assumption.
      apply subst_unused_closed' with ( := form_shift) ( := exp_axiom ).
      intros ?. constructor. apply GBot_closed. apply close_closed.
    Qed.


    Fixpoint exp n :=
      match n with
      | 0 T
      | S n exp n exp_axiom (e n)
      end.
    Definition Exp := union exp.

    Lemma Exp_sub :
      T Exp.
    Proof.
      apply union_sub with (n := 0) (f := exp).
    Qed.


    Lemma Exp_econsistent :
      econsistent T Exp.
    Proof.
      apply union_econsistent.
      - intros n (B & HB & Hprv) % prv_T_impl. use_theory B.
        opeirce (close (e n)). oimport Hprv. oapply 0. ctx.
      - induction 1; intros ?; firstorder.
    Qed.


    Lemma Exp_closed :
      closed_T Exp.
    Proof.
      apply union_closed. induction n; intuition. intros ? ? []; intuition; subst.
      constructor; [apply GBot_closed | apply close_closed].
    Qed.


    Definition exploding T := , ( --> close ) T.

    Lemma Exp_exploding :
      exploding Exp.
    Proof.
      intros . destruct (He ) as [n Hn]. exists (S n). right; now subst.
    Qed.


    Lemma exploding_inherit :
      exploding exploding .
    Proof.
      firstorder.
    Qed.


  End Explosion.

Proving with explosion axioms


  Notation "¬ phi" := ( --> GBot) (at level 20).
  Notation "∃ phi" := (¬ ¬ ) (at level 56, right associativity).

  Ltac ointro_all :=
    match goal with
    | [ |- ?A ?] apply AllI; cbn; asimpl
    end.

  Ltac ointro_impl :=
    match goal with
    | [ |- _ (_ --> _)] apply II
    | [ |- _ (¬ _)] apply II
    end.

  Ltac ointro := ointro_impl + ointro_all + fail "Nothing to intro!".
  Ltac ointros := repeat ointro.

  Lemma GExp A :
    (exp_axiom ) A A G A G .
  Proof.
    intros Hel Hbot. apply close_extract. exact (IE (Ctx Hel) Hbot).
  Qed.


  Ltac oexfalso := apply GExp; [intuition |].

  Lemma GDN A :
    (exp_axiom ) A A G ¬ ) A G .
  Proof.
    intros Hx H.
    oimport (Pc A GBot). oimport H. oapply 1. ointros. oexfalso. oapply 1. ctx.
  Qed.


  Ltac oindirect := apply GDN; [intuition| apply II].
  Ltac clean H := unfold ; rewrite! (subst_unused_closed' _ H).
  Ltac clean_GBot := clean GBot_closed.

  Lemma GExE A :
    exp_axiom A A G ( ) ( :: map (subst_form form_shift) A) G [] A G .
  Proof.
    intros Hx Hex Hinst.
    oindirect. oimport Hex. oapply 0. ointros. clean_GBot. oapply 2. ouse Hinst.
  Qed.


  Ltac odestruct n := eapply GExE; [intuition|ctx_index n|]; cbn; asimpl.

  Lemma GExI A t :
    A G [t .: ids] A G .
  Proof.
    intros Hc. apply II.
    ospecialize 0 t. clean_GBot. oapply 0. ouse Hc.
  Qed.


  Ltac oexists t :=
    eapply (@GExI _ t); cbn; asimpl.

  Lemma GXM A :
    exp_axiom A ( :: A) G (¬ :: A) G A G .
  Proof.
    intros Hx Ht Hf. oindirect.
    oassert (¬ ). ointros. oapply 1. ouse Ht. oapply 1. ouse Hf.
  Qed.


  Ltac oxm form :=
    apply (@GXM _ form); [intuition| |].

  Definition := exp_axiom ( ( --> ( )[])).
  Definition := exp_axiom ( [(var_term O) .: (shift (shift var_term))]).
  Definition := exp_axiom .

  Lemma GDP A :
     A A A A G ( --> ( )[]).
  Proof.
    intros ? . do 2 apply exp_axiom_lift in . do 1 apply exp_axiom_lift in . oxm ( (¬ )).
    - odestruct 0. clean_GBot. oexists (var_term 0). ointros. oexfalso. clean_GBot. oapply 1. ctx.
    - oexists (var_term 0). ointros. oindirect. clean_GBot. oapply 2. oexists (var_term 0). clean_GBot. ctx.
  Qed.


Henkin


  Section Henkin.
    Variable T : theory.
    Hypothesis Hclosed : closed_T T.
    Hypothesis Hexp : exploding T.

    Variable e : form.
    Hypothesis He : , n, e n = .
    Hypothesis Hunused : n m, n m unused m (e n).

    Definition henkin_axiom := ( --> (( )[])).

    Lemma henkin_axiom_unused n :
      unused n ( ) unused (S n) (¬ (henkin_axiom )).
    Proof.
      inversion 1. unfold henkin_axiom. constructor; [| apply GBot_closed].
      capply uf_Impl. capply unused_after_subst. subst. intros x.
      decide (x = n). 1: subst; now left. right; constructor; congruence.
    Qed.


    Fixpoint henkin n :=
      match n with
      | O T
      | S n henkin n subst_form ((var_term n)..) (henkin_axiom (e n))
      end.

    Lemma henkin_unused n :
       m, (henkin n) n m unused m .
    Proof.
      induction n; cbn.
      - intros. now apply Hclosed.
      - intros [| m] . omega.
        assert (unused (S m) (e n)) by (apply Hunused; omega).
        assert (unused (S (S m)) (e n)) by (apply Hunused; omega).
        assert (unused m (e n)) by (apply Hunused; omega).
        destruct . capply IHn. omega. subst. constructor.
        + apply unused_after_subst. intros []; comp. 1: right; constructor; omega.
          decide (S m = ). 1: subst; now left. right; constructor; omega.
        + constructor. asimpl. assumption.
    Qed.


    Lemma henkin_le m n :
      m n henkin m henkin n.
    Proof.
      induction 1; firstorder.
    Qed.


    Definition Henkin := union henkin.

    Lemma Henkin_consistent :
      econsistent T Henkin.
    Proof.
      refine (union_econsistent _ henkin_le). intros n.
      assert (unused n (e n)) by now apply Hunused.
      cbn; intros (A & & ) % prv_T_impl.
      rewrite (subst_unused_closed' ((var_term n)..) GBot_closed) in .
      apply (@nameless_equiv class b A (¬ (henkin_axiom (e n))) n) in .
      - use_theory (exp_axiom GBot :: (e n) :: (e n) :: (e n) :: A). shelve.
        oimport (@GDP (exp_axiom GBot :: (e n) :: (e n) :: (e n) :: A) (e n)).
        odestruct 0. oimport . shelve. clean_GBot. oapply 0. ctx.
      - apply henkin_axiom_unused; constructor; apply Hunused; omega.
      - intros ? H' % . eapply henkin_unused. apply H'. constructor.
      Unshelve.
        + intros ? [ | [ | [ | [ |]]]]. 5: intuition.
          all: apply henkin_le with (m := 0); [omega | apply Hexp].
        + intros ? ?. now do 6 right.
    Qed.


    Definition is_Henkin T := T' , T T' ( t, T' G [t..]) T' G .

    Lemma Henkin_is_Henkin :
      is_Henkin Henkin.
    Proof.
      intros T' HT' Hall. destruct (He ) as [n Hn]. destruct (Hall (var_term n)) as (A & & ).
      use_theory (subst_form ((var_term n)..) (henkin_axiom ) :: A).
      - intros ? [ |]; [| intuition]; subst. apply HT'. exists (S n). now right.
      - oimport . comp. oapply 1. ctx.
    Qed.


    Lemma is_Henkin_inherit :
      is_Henkin is_Henkin .
    Proof.
      firstorder.
    Qed.


    Lemma Henkin_T :
      T Henkin.
    Proof.
      apply union_sub with (f := henkin) (n := 0).
    Qed.

  End Henkin.

Omega


  Section Omega.
    Variable e : form.
    Hypothesis He : , n, e n = .

    Variable T : theory.
    Hypothesis Hexp : exploding T.
    Hypothesis Hhenkin : is_Henkin T.

    Definition maximal T := f, econsistent T (T f) f T.

    Definition econsistent_join T := fun T (econsistent T (T ) = ).
    Infix "∘" := econsistent_join (at level 20).

    Lemma econsistent_join_sub T' :
      (T' ) (T' ).
    Proof.
      firstorder.
    Qed.


    Lemma consistent_join_step T' :
      T' G T' G econsistent T' (T' ).
    Proof.
      intros (A & & ).
      enough (A T' econsistent T' (T' )) as [] by ((left; exists A; intuition) + now right).
      clear ; induction A.
      - firstorder.
      - destruct ( a), IHA; intuition. all: eauto with contains_theory.
    Qed.


    Fixpoint n : theory :=
      match n with
      | 0 T
      | S n n e n
      end.

    Lemma omega_le n m :
      n m n m.
    Proof.
      induction 1; firstorder.
    Qed.


    Definition : theory := union .

    Lemma econsistent_Omega :
      econsistent T .
    Proof.
      refine (union_econsistent _ omega_le). intros n H. destruct (consistent_join_step H).
      all: firstorder.
    Qed.


    Lemma econsistency_inheritance :
      econsistent econsistent .
    Proof.
      firstorder.
    Qed.


    Lemma econsistency_trans :
      econsistent econsistent econsistent .
    Proof.
      firstorder.
    Qed.


    Lemma maximal_Omega :
      maximal .
    Proof.
      intros H. destruct (He ) as [n Hn].
      apply (union_sub (n := S n)); cbn; rewrite Hn. right; split; [| reflexivity].
      eapply econsistency_inheritance.
      + exact (econsistency_trans econsistent_Omega H).
      + apply omega_le with (n := 0). omega.
      + firstorder.
    Qed.


    Lemma econsistent_prv T' T'' :
      econsistent T' T'' T'' G econsistent T' (T'' ).
    Proof.
      intros HT Hphi Hbot. now apply HT, (prv_T_remove Hphi).
    Qed.


    Lemma maximal_prv T' :
      maximal T' T' G T'.
    Proof.
      intros Hin Hprv. now apply Hin, econsistent_prv.
    Qed.


    Lemma Omega_prv :
       G .
    Proof.
      intros Hprv. now apply (maximal_prv maximal_Omega).
    Qed.


    Lemma Omega_T :
      T .
    Proof.
      change T with ( 0). apply (union_sub (n := 0)).
    Qed.


    Lemma Omega_impl :
       --> ( ).
    Proof.
      split.
      - intros Himp Hphi. apply Omega_prv.
        use_theory [ --> ; ]. oapply 0. ctx.
      - intros H. apply maximal_Omega. intros (A & & ) % prv_T_impl.
        apply (prv_T_remove ( := )).
        + apply elem_prv, H, Omega_prv.
          use_theory (exp_axiom :: exp_axiom :: A).
          * intros ? [ | [ | H'']]; [apply Omega_T, Hexp | apply Omega_T, Hexp | now apply ].
          * oindirect. oimport . oapply 0. ointros. oexfalso. oapply 2. ctx.
        + use_theory ( :: A). oimport . oapply 0. ointros. ctx.
    Qed.


    Lemma Omega_all :
       ( t, [t..] ).
    Proof.
      split; intros Hprv.
      - intros t. apply Omega_prv. use_theory [ ]. ospecialize 0 t. ctx.
      - apply Omega_prv, (Hhenkin Omega_T). eauto using elem_prv.
    Qed.

  End Omega.
End GenCons.

Conclusion


Section Composition.
  Context { : Signature}.
  Context {HdF : eq_dec Funcs} {HdP : eq_dec Preds}.
  Context {HeF : enumT Funcs} {HeP : enumT Preds}.

  Structure ConstructionInputs : Type :=
    {
      NBot : form ;
      NBot_closed : closed NBot ;
      
      variant : bottom ;

      In_T : theory ;
      In_T_closed : closed_T In_T ;

      enum : form ;
      enum_enum : , n, enum n = ;
      enum_unused : n m, n m unused m (enum n)
    }.

  Structure ConstructionOutputs (In : ConstructionInputs) :=
    {
      Out_T : theory ;
      Out_T_econsistent : @econsistent (variant In) (NBot In) (In_T In) Out_T ;
      Out_T_sub : In_T In Out_T ;

      Out_T_prv : , @tprv class (variant In) Out_T Out_T ;
      Out_T_all : , Out_T ( t, [t..] Out_T) ;
      Out_T_impl : , --> Out_T ( Out_T Out_T)
    }.

  Lemma construct_construction (In : ConstructionInputs) :
    ConstructionOutputs In.
  Proof.
    destruct In as [NBot NBot_closed system T T_closed e e_enum e_unused].
    eexists ( NBot e (Henkin (Exp NBot T e) e)); cbn.
    + capply econsistency_trans. capply econsistency_trans. capply Exp_econsistent.
      capply Henkin_consistent. capply Exp_closed. capply Exp_exploding. capply econsistent_Omega.
    + transitivity (Henkin (Exp NBot T e) e). transitivity (Exp NBot T e).
      apply Exp_sub. apply Henkin_T. apply Omega_T.
    + capply Omega_prv.
    + capply Omega_all. capply Henkin_is_Henkin.
    + capply Omega_impl. capply exploding_inherit.
      - capply Exp_exploding.
      - capply Henkin_T.
  Qed.

End Composition.