/-- **Soundness**: every derivable sequent — with or without cut — is valid. By induction on
the derivation. For the cut rule: if neither `A` nor `Aᗮ` is the true formula supplied by the
premises, some formula of `Γ` is true; and `A`, `Aᗮ` cannot both be true. -/
theorem soundness {c : Bool} {Γ : List Fml} (d : Deriv c Γ) : Valid Γ := by
induction d with
| ax n hp hn =>
intro v
by_cases h : v n
· exact ⟨pos n, hp, h⟩
· exact ⟨neg n, hn, h⟩
| and A B _ _ ihA ihB =>
intro v
obtain ⟨C, hC, hCv⟩ := ihA v
obtain ⟨D, hD, hDv⟩ := ihB v
rcases List.mem_cons.mp hC with rfl | hC
· rcases List.mem_cons.mp hD with rfl | hD
· exact ⟨Fml.and C D, by simp, hCv, hDv⟩
· exact ⟨D, List.mem_cons_of_mem _ hD, hDv⟩
· exact ⟨C, List.mem_cons_of_mem _ hC, hCv⟩
| or A B _ ih =>
intro v
obtain ⟨C, hC, hCv⟩ := ih v
rcases List.mem_cons.mp hC with rfl | hC
· exact ⟨Fml.or C B, by simp, Or.inl hCv⟩
rcases List.mem_cons.mp hC with rfl | hC
· exact ⟨Fml.or A C, by simp, Or.inr hCv⟩
· exact ⟨C, List.mem_cons_of_mem _ hC, hCv⟩
| exchange hp _ ih =>
intro v
obtain ⟨C, hC, hCv⟩ := ih v
exact ⟨C, hp.subset hC, hCv⟩
| cut A _ _ ih₁ ih₂ =>
intro v
obtain ⟨C, hC, hCv⟩ := ih₁ v
obtain ⟨D, hD, hDv⟩ := ih₂ v
rcases List.mem_cons.mp hC with rfl | hC
· rcases List.mem_cons.mp hD with rfl | hD
· exact absurd hCv ((eval_dual v C).mp hDv)
· exact ⟨D, hD, hDv⟩
· exact ⟨C, hC, hCv⟩