File DeductionTheorem

From MatchingLogic Require Export Definedness_ProofSystem.
Import MatchingLogic.Logic.Notations
       MatchingLogic.Theories.Definedness_Syntax.Notations.


Open Scope list_scope.

(* TODO: These 3 lemmas are used only here as is, but maybe it should be somewhere else? *)
Local Lemma impl_ctx_impl {Σ : Signature} Γ ctx ϕ ψ i :
  well_formed ϕ
  well_formed ψ →
  well_formed (pcPattern ctx) →
  ProofInfoLe AnyReasoning i
  Γi ϕ ---> ψ using i
  (is_positive_context ctx
  Γi (emplace ctx ϕ) ---> (emplace ctx ψ) using i)
  ×
  (is_negative_context ctx
  Γi (emplace ctx ψ) ---> (emplace ctx ϕ) using i).
Lemma impl_ctx_impl_pos {Σ : Signature} Γ ctx ϕ ψ i :
  well_formed ϕ
  well_formed ψ →
  well_formed (pcPattern ctx) →
  is_positive_context ctx
  ProofInfoLe AnyReasoning i
  Γi ϕ ---> ψ using i
  Γi (emplace ctx ϕ) ---> (emplace ctx ψ) using i.

Lemma impl_ctx_impl_neg {Σ : Signature} Γ ctx ϕ ψ i :
  well_formed ϕ
  well_formed ψ →
  well_formed (pcPattern ctx) →
  is_negative_context ctx
  ProofInfoLe AnyReasoning i
  Γi ϕ ---> ψ using i
  Γi (emplace ctx ψ) ---> (emplace ctx ϕ) using i.

(* Lemma 88 in in the matching mu logic paper.*)
Lemma pred_and_ctx_and {Σ : Signature} {syntax : Syntax} Γ ctx ϕ ψ:
  Definedness_Syntax.theoryΓ
  well_formed ϕ
  well_formed ψ →
  well_formed (pcPattern ctx) →
  mu_in_evar_path (pcEvar ctx) (pcPattern ctx) 0 = false
  Γis_predicate_pattern ψ →
  Γ ⊢ ψ and (emplace ctx ϕ) <---> ψ and (emplace ctxand ϕ)).

(* Lemma 89 *)
(* TODO: it is worth splitting this theorem, since the ---> direction requires
         fewer side conditions *)

Lemma mu_and_predicate_propagation {Σ : Signature} {syntax : Syntax} Γ ϕ ψ :
  Definedness_Syntax.theoryΓ
  well_formed (mu, ϕ) →
  well_formed ψ →
  (* "Let X be a set variable that does not occur under any µ-binder in ϕ" *)
  bound_svar_is_banned_under_mus ϕ 0 0 →
  Γis_predicate_pattern ψ →
  Γ ⊢ (mu, (ψ and ϕ)) <---> (ψ and (mu, ϕ)).

Theorem deduction_theorem {Σ : Signature} {syntax : Syntax} Γ ϕ ψ
  (gpi : ProofInfo)
  (pf : Γ ∪ {[ ψ ]} ⊢i ϕ using gpi) :
  well_formed ϕ
  well_formed ψ →
  theoryΓ
  pi_generalized_evars gpi ## (gset_to_coGset (free_evars ψ)) →
  pi_substituted_svars gpi ## (gset_to_coGset (free_svars ψ)) →
  pi_uses_advanced_kt gpi = false
  Γi ⌊ ψ ⌋ ---> ϕ
  using AnyReasoning.

Lemma MLGoal_deduct'
  {Σ : Signature}
  {syntax : Syntax}
  (Γ : Theory)
  (l : hypotheses)
  name
  (ψ g : Pattern)
  (C : PatternCtx)
  (i : ProofInfo)
  :
  theoryΓ
  pi_generalized_evars i ## gset_to_coGset (free_evars ψ) →
  pi_substituted_svars i ## gset_to_coGset (free_svars ψ) →
  pi_uses_advanced_kt i = false
  mkMLGoal Σ (Γ ∪ {[ψ]}) l g i
  mkMLGoal Σ Γ ((mkNH _ name ⌊ ψ ⌋) :: l) g AnyReasoning .
Lemma MLGoal_deduct
  {Σ : Signature}
  {syntax : Syntax}
  (Γ : Theory)
  (l₁ l₂ : hypotheses)
  name
  (ψ g : Pattern)
  :
  theoryΓ
  mkMLGoal Σ (Γ ∪ {[ψ]}) (l₁ ++ l₂) g
    ((ExGen := ⊤ ∖ gset_to_coGset (free_evars ψ), SVSubst := ⊤ ∖ gset_to_coGset (free_svars ψ), KT := true, AKT := false)) →
  mkMLGoal Σ Γ (l₁ ++ (mkNH _ name ⌊ ψ ⌋) :: l₂) g AnyReasoning .

Tactic Notation "mlDeduct" constr(name) :=
  _ensureProofMode;
  _mlReshapeHypsByName name;
  apply MLGoal_deduct;
  [try assumption|_mlReshapeHypsBack]
.

#[local]
Example ex_deduct
  {Σ : Signature} {syntax : Syntax} (Γ : Theory) (ϕ₁ ϕ₂ ϕ₃ : Pattern)
  :
  well_formed ϕ₁
  well_formed ϕ₂
  well_formed ϕ₃
  theoryΓ
  Γϕ₁ ---> ⌊ ϕ₂ ⌋ ---> ϕ₃ ---> ϕ₂
.
Lemma equality_elimination
  {Σ : Signature}
  {sy : Definedness_Syntax.Syntax}
  Γ φ1 φ2 C
  ( : theoryΓ)
  (WF1 : well_formed φ1)
  (WF2 : well_formed φ2)
  (WFC : PC_wf C)
  (Hmu : pattern_kt_well_formed (pcPattern C))
  
:
  Γi (φ1 =ml φ2) --->
    (emplace C φ1) ---> (emplace C φ2)
  using AnyReasoning.
C is the context pattern, and y is the context variable from now on
size-based induction on the context
C = x
C = □ (the context's hole)
C = x ≠ □
C = X
C is a bound element variable --- C is not well-formed
C is a bound set variable --- C is not well-formed
C = σ
C = C₁ ⋅ C₂
side conditions
side conditions
solving the side conditions from above
C = ⊥
C = C₁ ---> C₂
C = ∃x.C
-s are side conditions
swapping substitutions
C = μX.C
Γ ⊢ φ1 = φ2 ∧ (μX.Cy↦φ1) ↔ μX.φ1 = φ2 ∧ Cy↦φ1
This theorem uses Ex-Gen for some fresh x, y, z for which we generate concrete variables above
Γ ⊢ φ1 → φ2
Γ ⊢ (μX.φ1) → μX.φ2
Proof of the premise of monotonicity of μ
Substiutions do not affect the equality, since they do not contain μ's bound variable
Swapping the substitutions
size-based induction is needed to make this `apply`

Lemma pattern_kt_well_formed_free_evar_subst {Σ : Signature}:
   φ ψ x,
    pattern_kt_well_formed φ →
    pattern_kt_well_formed ψ →
    well_formed ψ →
    pattern_kt_well_formed (free_evar_subst ψ x φ).

Corollary equality_elimination_eq
  {Σ : Signature}
  {sy : Definedness_Syntax.Syntax}
  Γ φ1 φ2 C
  ( : theoryΓ)
  (WF1 : well_formed φ1)
  (WF2 : well_formed φ2)
  (WFC : PC_wf C)
  (Hmu : pattern_kt_well_formed (pcPattern C))
  (Htechnical : pattern_kt_well_formed φ1) :
  Γi (φ1 =ml φ2) --->
    (emplace C φ1) =ml (emplace C φ2)
  using AnyReasoning.

Lemma exists_elim {Σ : Signature} {syntax : Definedness_Syntax.Syntax} Γ φ x :
  theoryΓ
  well_formed (ex , φ) →
  pattern_kt_well_formed φ →
  Γ ⊢ (ex , b0 and φ) ---> patt_free_evar x ---> φ^{evar:0↦x}.

Lemma forall_intro {Σ : Signature} {syntax : Definedness_Syntax.Syntax} Γ φ x :
  theoryΓ
  well_formed (ex , φ) →
  pattern_kt_well_formed φ →
  Γpatt_free_evar x ---> φ^{evar:0↦x} ---> (all , b0 ---> φ).

Lemma exists_singleton {Σ : Signature} {syntax : Definedness_Syntax.Syntax} Γ φ :
  theoryΓ
  well_formed (ex, φ) →
  pattern_kt_well_formed φ →
  Γ ⊢ (ex , b0 and φ) ---> (all, (b0 ---> φ)).

This page has been generated by coqdoc