1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 set "baseuri" "cic:/matita/demo/propositional_sequent_calculus/".
17 include "nat/plus.ma".
18 include "nat/compare.ma".
19 include "list/sort.ma".
20 include "datatypes/constructors.ma".
22 inductive Formula : Type ≝
25 | FAtom: nat → Formula
26 | FAnd: Formula → Formula → Formula
27 | FOr: Formula → Formula → Formula
28 | FNot: Formula → Formula.
30 definition interp ≝ nat → bool.
32 let rec eval (interp:interp) F on F : bool ≝
37 | FAnd f1 f2 ⇒ eval interp f1 ∧ eval interp f2
38 | FOr f1 f2 ⇒ eval interp f1 ∨ eval interp f2
39 | FNot f ⇒ ¬ eval interp f
42 inductive not_nf : Formula → Prop ≝
44 | NFalse: not_nf FFalse
45 | NAtom: ∀n. not_nf (FAtom n)
46 | NAnd: ∀f1,f2. not_nf f1 → not_nf f2 → not_nf (FAnd f1 f2)
47 | NOr: ∀f1,f2. not_nf f1 → not_nf f2 → not_nf (FOr f1 f2)
48 | NNot: ∀n.not_nf (FNot (FAtom n)).
54 | FAtom n ⇒ FNot (FAtom n)
55 | FAnd f1 f2 ⇒ FOr (negate f1) (negate f2)
56 | FOr f1 f2 ⇒ FAnd (negate f1) (negate f2)
57 | FNot f ⇒ elim_not f]
63 | FAnd f1 f2 ⇒ FAnd (elim_not f1) (elim_not f2)
64 | FOr f1 f2 ⇒ FOr (elim_not f1) (elim_not f2)
68 theorem not_nf_elim_not: ∀F.not_nf (elim_not F) ∧ not_nf (negate F).
71 [1,2,3: simplify; autobatch
86 theorem demorgan1: ∀b1,b2:bool. (¬ (b1 ∧ b2)) = ¬ b1 ∨ ¬ b2.
93 theorem demorgan2: ∀b1,b2:bool. (¬ (b1 ∨ b2)) = ¬ b1 ∧ ¬ b2.
100 theorem eq_notb_notb_b_b: ∀b:bool. (¬ ¬ b) = b.
106 theorem eq_eval_elim_not_eval:
107 ∀i,F. eval i (elim_not F) = eval i F ∧ eval i (negate F) = eval i (FNot F).
110 [1,2,3: split; reflexivity
117 |replace with ((eval i (FNot f) ∨ eval i (FNot f1)) = ¬ (eval i f ∧ eval i f1));
122 |replace with ((eval i (FNot f) ∧ eval i (FNot f1)) = ¬ (eval i f ∨ eval i f1));
131 | change with (eval i (elim_not f) = ¬ ¬ eval i f);
137 definition sequent ≝ (list Formula) × (list Formula).
139 inductive derive: sequent → Prop ≝
140 ExchangeL: ∀l,l1,l2,f. derive 〈f::l1@l2,l〉 → derive 〈l1 @ [f] @ l2,l〉
141 | ExchangeR: ∀l,l1,l2,f. derive 〈l,f::l1@l2〉 → derive 〈l,l1 @ [f] @ l2〉
142 | Axiom: ∀l1,l2,f. derive 〈f::l1, f::l2〉
143 | TrueR: ∀l1,l2. derive 〈l1,FTrue::l2〉
144 | FalseL: ∀l1,l2. derive 〈FFalse::l1,l2〉
145 | AndR: ∀l1,l2,f1,f2.
146 derive 〈l1,f1::l2〉 → derive 〈l1,f2::l2〉 →
147 derive 〈l1,FAnd f1 f2::l2〉
148 | AndL: ∀l1,l2,f1,f2.
149 derive 〈f1 :: f2 :: l1,l2〉 → derive 〈FAnd f1 f2 :: l1,l2〉
151 derive 〈f1::l1,l2〉 → derive 〈f2::l1,l2〉 →
152 derive 〈FOr f1 f2 :: l1,l2〉
154 derive 〈l1,f1 :: f2 :: l2〉 → derive 〈l1,FOr f1 f2 :: l2〉
156 derive 〈f::l1,l2〉 → derive 〈l1,FNot f :: l2〉
158 derive 〈l1,f::l2〉 → derive 〈FNot f :: l1,l2〉.
160 let rec and_of_list l ≝
163 | cons F l' ⇒ FAnd F (and_of_list l')
166 let rec or_of_list l ≝
169 | cons F l' ⇒ FOr F (or_of_list l')
172 definition formula_of_sequent ≝
173 λs.match s with [pair l1 l2 ⇒ FOr (FNot (and_of_list l1)) (or_of_list l2)].
175 definition is_tautology ≝
176 λF. ∀i. eval i F = true.
178 axiom assoc_orb: associative ? orb.
179 axiom symm_orb: symmetric ? orb.
180 axiom orb_not_b_b: ∀b:bool. (¬b ∨ b) = true.
181 axiom distributive_orb_andb: distributive ? orb andb.
182 axiom symm_andb: symmetric ? andb.
183 axiom associative_andb: associative ? andb.
184 axiom distributive_andb_orb: distributive ? andb orb.
186 lemma and_of_list_permut:
187 ∀i,f,l1,l2. eval i (and_of_list (l1 @ (f::l2))) = eval i (and_of_list (f :: l1 @ l2)).
194 autobatch paramodulation
198 lemma or_of_list_permut:
199 ∀i,f,l1,l2. eval i (or_of_list (l1 @ (f::l2))) = eval i (or_of_list (f :: l1 @ l2)).
206 autobatch paramodulation
210 theorem soundness: ∀F. derive F → is_tautology (formula_of_sequent F).
213 [ simplify in H2 ⊢ %;
215 lapply (H2 i); clear H2;
216 rewrite > and_of_list_permut;
219 | simplify in H2 ⊢ %;
221 lapply (H2 i); clear H2;
222 rewrite > or_of_list_permut;
229 rewrite > assoc_orb in ⊢ (? ? (? % ?) ?);
230 rewrite > symm_orb in ⊢ (? ? (? (? ? %) ?) ?);
232 rewrite > orb_not_b_b;
241 | simplify in H2 H4 ⊢ %;
243 lapply (H2 i); clear H2;
244 lapply (H4 i); clear H4;
245 rewrite > symm_orb in ⊢ (? ? (? ? %) ?);
246 rewrite > distributive_orb_andb;
247 autobatch paramodulation
248 | simplify in H2 ⊢ %;
250 lapply (H2 i); clear H2;
252 | simplify in H2 H4 ⊢ %;
254 lapply (H2 i); clear H2;
255 lapply (H4 i); clear H4;
257 rewrite > distributive_andb_orb;
260 rewrite > distributive_orb_andb;
261 autobatch paramodulation
262 | simplify in H2 ⊢ %;
264 lapply (H2 i); clear H2;
266 | simplify in H2 ⊢ %;
268 lapply (H2 i); clear H2;
269 autobatch paramodulation
270 | simplify in H2 ⊢ %;
272 lapply (H2 i); clear H2;
273 autobatch paramodulation
277 alias num (instance 0) = "natural number".
283 | FAnd f1 f2 ⇒ S (size f1 + size f2)
284 | FOr f1 f2 ⇒ S (size f1 + size f2)
285 | FNot f ⇒ S (size f)
291 | cons F l' ⇒ size F + sizel l'
294 definition size_of_sequent ≝
295 λS.match S with [ pair l r ⇒ sizel l + sizel r].
298 ∀l1,l2,F. derive 〈l1,l2〉 → derive 〈l1,F::l2〉.
300 definition same_atom : Formula → Formula → bool.
311 definition symmetricb ≝
312 λA:Type.λeq:A → A → bool. ∀x,y. eq x y = eq y x.
314 theorem symmetricb_eqb: symmetricb ? eqb.
324 theorem symmetricb_same_atom: symmetricb ? same_atom.
334 |*: elim y; reflexivity
338 definition transitiveb ≝
339 λA:Type.λeq:A → A → bool.
340 ∀x,y,z. eq x y = true → eq y z = eq x z.
342 theorem transitiveb_same_atom: transitiveb ? same_atom.
351 rewrite > (eqb_true_to_eq ? ? H);
379 theorem eq_to_eq_mem:
380 ∀A.∀eq: A → A → bool.transitiveb ? eq →
381 ∀x,y,l.eq x y = true → mem ? eq x l = mem ? eq y l.
386 rewrite > (H ? ? ? H1);
392 theorem mem_to_exists_l1_l2:
393 ∀A,eq,n,l. (∀x,y. eq x y = true → x = y) → mem A eq n l = true → ∃l1,l2. l = l1 @ (n :: l2).
399 apply (bool_elim ? (eq n t));
401 [ apply (ex_intro ? ? []);
402 apply (ex_intro ? ? l1);
404 rewrite > (H1 ? ? H3);
406 | rewrite > H3 in H2;
411 apply (ex_intro ? ? (t::a));
412 apply (ex_intro ? ? a1);
419 lemma same_atom_to_eq: ∀f1,f2. same_atom f1 f2 = true → f1=f2.
425 | generalize in match H; clear H;
431 rewrite > (eqb_true_to_eq ? ? H);
448 lemma same_atom_to_exists: ∀f1,f2. same_atom f1 f2 = true → ∃n. f1 = FAtom n.
463 lemma mem_same_atom_to_exists:
464 ∀f,l. mem ? same_atom f l = true → ∃n. f = FAtom n.
470 apply (bool_elim ? (same_atom f t));
472 [ elim (same_atom_to_exists ? ? H2);
474 | rewrite > H2 in H1;
482 lemma look_for_axiom:
484 (∃n,ll1,ll2,lr1,lr2. l1 = ll1 @ (FAtom n :: ll2) ∧ l2 = lr1 @ (FAtom n :: lr2))
485 ∨ ∀n1. (mem ? same_atom (FAtom n1) l1 ∧ mem ? same_atom (FAtom n1) l2) = false.
494 generalize in match (refl_eq ? (mem ? same_atom t l2));
495 elim (mem ? same_atom t l2) in ⊢ (? ? ? %→?);
497 elim (mem_to_exists_l1_l2 ? ? ? ? same_atom_to_eq H1);
499 elim (mem_same_atom_to_exists ? ? H1);
501 apply (ex_intro ? ? a2);
503 apply (ex_intro ? ? []);
509 apply (ex_intro ? ? a);
510 apply (ex_intro ? ? (t::a1));
512 apply (ex_intro ? ? a2);
513 apply (ex_intro ? ? a3);
517 apply (bool_elim ? (same_atom t (FAtom n1)));
519 rewrite > (eq_to_eq_mem ? ? transitiveb_same_atom ? ? ? H3) in H1;
523 change in ⊢ (? ? (? % ?) ?) with
524 (match same_atom (FAtom n1) t with
526 |false ⇒ mem ? same_atom (FAtom n1) l
528 rewrite > symmetricb_same_atom;
538 lemma eq_plus_n_m_O_to_eq_m_O: ∀n,m.n+m=0 → m=0.
547 lemma not_eq_nil_append_cons: ∀A.∀l1,l2.∀x:A.¬ [] = l1 @ (x :: l2).
561 [true⇒true|false⇒mem Formula same_atom (FAtom n) l]) (and_of_list l)) =
563 (λn:nat.mem Formula same_atom (FAtom n) l) (and_of_list l)).
567 | simplify in ⊢ (? ? (? (? ? %)) ?);
568 change in ⊢ (? ? (? %) ?) with
570 .match eqb n x in bool return λb:bool.bool with
571 [true⇒true|false⇒mem Formula same_atom (FAtom n) (t::l1)]) t
574 .match eqb n x in bool return λb:bool.bool with
575 [true⇒true|false⇒mem Formula same_atom (FAtom n) (t::l1)])
584 lemma sizel_0_no_axiom_is_tautology:
585 ∀l1,l2. size_of_sequent 〈l1,l2〉 = 0 → is_tautology (formula_of_sequent 〈l1,l2〉) →
586 (∀n. (mem ? same_atom (FAtom n) l1 ∧ mem ? same_atom (FAtom n) l2) = false) →
587 (∃ll1,ll2. l1 = ll1 @ (FFalse :: ll2)) ∨ (∃ll1,ll2. l2 = ll1 @ (FTrue :: ll2)).
589 lapply (H1 (λn.mem ? same_atom (FAtom n) l1)); clear H1;
591 generalize in match Hletin; clear Hletin;
592 generalize in match H2; clear H2;
593 generalize in match H; clear H;
597 generalize in match H2; clear H2;
598 generalize in match H1; clear H1;
599 generalize in match H; clear H;
608 apply (ex_intro ? ? []);
616 elim (not_eq_nil_append_cons ? ? ? ? H6)
619 apply (ex_intro ? ? (FFalse::a));
622 apply (ex_intro ? ? a1);
628 elim (H H1 H2 H3); clear H;
631 elim (not_eq_nil_append_cons ? ? ? ? H5)
634 apply (ex_intro ? ? (FAtom n::a));
651 apply (ex_intro ? ? (FTrue::a));
658 | lapply (H2 n); clear H2;
665 apply (ex_intro ? ? []);
671 apply (ex_intro ? ? (FAtom n::a));
678 | lapply (H2 n1); clear H2;
680 generalize in match Hletin; clear Hletin;
689 lapply (H2 n); clear H2;
690 rewrite > eqb_n_n in Hletin;
693 rewrite > eqb_n_n in H3;
696 generalize in match H3;
697 generalize in match H1; clear H1;
698 generalize in match H; clear H;
712 apply (eq_plus_n_m_O_to_eq_m_O ? ? H2)
717 | generalize in match H4; clear H4;
718 generalize in match H2; clear H2;
744 lemma completeness_base:
745 ∀S. size_of_sequent S = 0 → is_tautology (formula_of_sequent S) → derive S.
748 simplify in ⊢ (?→%→?);
750 elim (look_for_axiom t t1);
752 rewrite > H2; clear H2;
753 rewrite > H4; clear H4;
754 apply (ExchangeL ? a1 a2 (FAtom a));
755 apply (ExchangeR ? a3 a4 (FAtom a));
757 | elim (sizel_0_no_axiom_is_tautology t t1 H H1 H2);
760 apply (ExchangeL ? a a1 FFalse);
764 apply (ExchangeR ? a a1 FTrue);
771 lemma completeness_step:
772 ∀l1,l2,n. size_of_sequent 〈l1,l2〉 = S n →
773 (∃ll1,ll2,f. l1 = ll1 @ (f::ll2) ∧ size f > 0) ∨
774 (∃ll1,ll2,f. l2 = ll1 @ (f::ll2) ∧ size f > 0).
788 apply (ex_intro ? ? (FTrue::a));
797 apply (ex_intro ? ? (FFalse::a));
806 apply (ex_intro ? ? (FAtom n1::a));
811 apply (ex_intro ? ? []);
813 apply (ex_intro ? ? l);
814 apply (ex_intro ? ? (FAnd f f1));
822 apply (ex_intro ? ? []);
824 apply (ex_intro ? ? l);
825 apply (ex_intro ? ? (FOr f f1));
833 apply (ex_intro ? ? []);
835 apply (ex_intro ? ? l);
836 apply (ex_intro ? ? (FNot f));
856 apply (ex_intro ? ? []);
858 apply (ex_intro ? ? l);
859 apply (ex_intro ? ? (FAnd f f1));
864 apply (ex_intro ? ? []);
866 apply (ex_intro ? ? l);
867 apply (ex_intro ? ? (FOr f f1));
872 apply (ex_intro ? ? []);
874 apply (ex_intro ? ? l);
875 apply (ex_intro ? ? (FNot f));
883 theorem completeness: ∀S. is_tautology (formula_of_sequent S) → derive S.
885 generalize in match (refl_eq ? (size_of_sequent S));
886 elim (size_of_sequent S) in ⊢ (? ? ? %→?);
887 [ apply completeness_base;
896 lapply (H (λx.true));
899 lapply (H (λx.false));
904 lapply (H2 i); clear H2;
909 lapply (H2 i); clear H2;