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 alias id "Nil" = "cic:/matita/list/list.ind#xpointer(1/1/1)".
161 let rec and_of_list l ≝
164 | Cons F l' ⇒ FAnd F (and_of_list l')
167 let rec or_of_list l ≝
170 | Cons F l' ⇒ FOr F (or_of_list l')
173 definition formula_of_sequent ≝
174 λs.match s with [pair l1 l2 ⇒ FOr (FNot (and_of_list l1)) (or_of_list l2)].
176 definition is_tautology ≝
177 λF. ∀i. eval i F = true.
179 axiom assoc_orb: associative ? orb.
180 axiom symm_orb: symmetric ? orb.
181 axiom orb_not_b_b: ∀b:bool. (¬b ∨ b) = true.
182 axiom distributive_orb_andb: distributive ? orb andb.
183 axiom symm_andb: symmetric ? andb.
184 axiom associative_andb: associative ? andb.
185 axiom distributive_andb_orb: distributive ? andb orb.
187 lemma and_of_list_permut:
188 ∀i,f,l1,l2. eval i (and_of_list (l1 @ (f::l2))) = eval i (and_of_list (f :: l1 @ l2)).
195 autobatch paramodulation
199 lemma or_of_list_permut:
200 ∀i,f,l1,l2. eval i (or_of_list (l1 @ (f::l2))) = eval i (or_of_list (f :: l1 @ l2)).
207 autobatch paramodulation
211 theorem soundness: ∀F. derive F → is_tautology (formula_of_sequent F).
214 [ simplify in H2 ⊢ %;
216 lapply (H2 i); clear H2;
217 rewrite > and_of_list_permut;
220 | simplify in H2 ⊢ %;
222 lapply (H2 i); clear H2;
223 rewrite > or_of_list_permut;
230 rewrite > assoc_orb in ⊢ (? ? (? % ?) ?);
231 rewrite > symm_orb in ⊢ (? ? (? (? ? %) ?) ?);
233 rewrite > orb_not_b_b;
242 | simplify in H2 H4 ⊢ %;
244 lapply (H2 i); clear H2;
245 lapply (H4 i); clear H4;
246 rewrite > symm_orb in ⊢ (? ? (? ? %) ?);
247 rewrite > distributive_orb_andb;
248 autobatch paramodulation
249 | simplify in H2 ⊢ %;
251 lapply (H2 i); clear H2;
253 | simplify in H2 H4 ⊢ %;
255 lapply (H2 i); clear H2;
256 lapply (H4 i); clear H4;
258 rewrite > distributive_andb_orb;
261 rewrite > distributive_orb_andb;
262 autobatch paramodulation
263 | simplify in H2 ⊢ %;
265 lapply (H2 i); clear H2;
267 | simplify in H2 ⊢ %;
269 lapply (H2 i); clear H2;
270 autobatch paramodulation
271 | simplify in H2 ⊢ %;
273 lapply (H2 i); clear H2;
274 autobatch paramodulation
278 alias num (instance 0) = "natural number".
279 alias symbol "plus" = "natural plus".
285 | FAnd f1 f2 ⇒ S (size f1 + size f2)
286 | FOr f1 f2 ⇒ S (size f1 + size f2)
287 | FNot f ⇒ S (size f)
293 | Cons F l' ⇒ size F + sizel l'
296 definition size_of_sequent ≝
297 λS.match S with [ pair l r ⇒ sizel l + sizel r].
300 ∀l1,l2,F. derive 〈l1,l2〉 → derive 〈l1,F::l2〉.
302 definition same_atom : Formula → Formula → bool.
313 definition symmetricb ≝
314 λA:Type.λeq:A → A → bool.
315 ∀x,y. eq x y = eq y x.
317 theorem symmetricb_eqb: symmetricb ? eqb.
327 theorem symmetricb_same_atom: symmetricb ? same_atom.
337 |*: elim y; reflexivity
341 definition transitiveb ≝
342 λA:Type.λeq:A → A → bool.
343 ∀x,y,z. eq x y = true → eq y z = eq x z.
345 theorem transitiveb_same_atom: transitiveb ? same_atom.
354 rewrite > (eqb_true_to_eq ? ? H);
382 theorem eq_to_eq_mem:
383 ∀A.∀eq: A → A → bool.transitiveb ? eq →
384 ∀x,y,l.eq x y = true → mem ? eq x l = mem ? eq y l.
389 rewrite > (H ? ? ? H1);
395 theorem mem_to_exists_l1_l2:
396 ∀A,eq,n,l. (∀x,y. eq x y = true → x = y) → mem A eq n l = true → ∃l1,l2. l = l1 @ (n :: l2).
402 apply (bool_elim ? (eq n t));
404 [ apply (ex_intro ? ? []);
405 apply (ex_intro ? ? l1);
407 rewrite > (H1 ? ? H3);
409 | rewrite > H3 in H2;
414 apply (ex_intro ? ? (t::a));
415 apply (ex_intro ? ? a1);
422 lemma same_atom_to_eq: ∀f1,f2. same_atom f1 f2 = true → f1=f2.
428 | generalize in match H; clear H;
434 rewrite > (eqb_true_to_eq ? ? H);
451 lemma same_atom_to_exists: ∀f1,f2. same_atom f1 f2 = true → ∃n. f1 = FAtom n.
466 lemma mem_same_atom_to_exists:
467 ∀f,l. mem ? same_atom f l = true → ∃n. f = FAtom n.
473 apply (bool_elim ? (same_atom f t));
475 [ elim (same_atom_to_exists ? ? H2);
477 | rewrite > H2 in H1;
485 lemma look_for_axiom:
487 (∃n,ll1,ll2,lr1,lr2. l1 = ll1 @ (FAtom n :: ll2) ∧ l2 = lr1 @ (FAtom n :: lr2))
488 ∨ ∀n1. (mem ? same_atom (FAtom n1) l1 ∧ mem ? same_atom (FAtom n1) l2) = false.
497 generalize in match (refl_eq ? (mem ? same_atom t l2));
498 elim (mem ? same_atom t l2) in ⊢ (? ? ? %→?);
500 elim (mem_to_exists_l1_l2 ? ? ? ? same_atom_to_eq H1);
502 elim (mem_same_atom_to_exists ? ? H1);
504 apply (ex_intro ? ? a2);
506 apply (ex_intro ? ? []);
512 apply (ex_intro ? ? a);
513 apply (ex_intro ? ? (t::a1));
515 apply (ex_intro ? ? a2);
516 apply (ex_intro ? ? a3);
520 apply (bool_elim ? (same_atom t (FAtom n1)));
522 rewrite > (eq_to_eq_mem ? ? transitiveb_same_atom ? ? ? H3) in H1;
526 change in ⊢ (? ? (? % ?) ?) with
527 (match same_atom (FAtom n1) t with
529 |false ⇒ mem ? same_atom (FAtom n1) l
531 rewrite > symmetricb_same_atom;
541 lemma eq_plus_n_m_O_to_eq_m_O: ∀n,m.n+m=0 → m=0.
550 lemma not_eq_nil_append_cons: ∀A.∀l1,l2.∀x:A.¬ [] = l1 @ (x :: l2).
564 [true⇒true|false⇒mem Formula same_atom (FAtom n) l]) (and_of_list l)) =
566 (λn:nat.mem Formula same_atom (FAtom n) l) (and_of_list l)).
570 | simplify in ⊢ (? ? (? (? ? %)) ?);
571 change in ⊢ (? ? (? %) ?) with
573 .match eqb n x in bool return λb:bool.bool with
574 [true⇒true|false⇒mem Formula same_atom (FAtom n) (t::l1)]) t
577 .match eqb n x in bool return λb:bool.bool with
578 [true⇒true|false⇒mem Formula same_atom (FAtom n) (t::l1)])
587 lemma sizel_0_no_axiom_is_tautology:
588 ∀l1,l2. size_of_sequent 〈l1,l2〉 = 0 → is_tautology (formula_of_sequent 〈l1,l2〉) →
589 (∀n. (mem ? same_atom (FAtom n) l1 ∧ mem ? same_atom (FAtom n) l2) = false) →
590 (∃ll1,ll2. l1 = ll1 @ (FFalse :: ll2)) ∨ (∃ll1,ll2. l2 = ll1 @ (FTrue :: ll2)).
592 lapply (H1 (λn.mem ? same_atom (FAtom n) l1)); clear H1;
594 generalize in match Hletin; clear Hletin;
595 generalize in match H2; clear H2;
596 generalize in match H; clear H;
600 generalize in match H2; clear H2;
601 generalize in match H1; clear H1;
602 generalize in match H; clear H;
611 apply (ex_intro ? ? []);
619 elim (not_eq_nil_append_cons ? ? ? ? H6)
622 apply (ex_intro ? ? (FFalse::a));
625 apply (ex_intro ? ? a1);
631 elim (H H1 H2 H3); clear H;
634 elim (not_eq_nil_append_cons ? ? ? ? H5)
637 apply (ex_intro ? ? (FAtom n::a));
654 apply (ex_intro ? ? (FTrue::a));
661 | lapply (H2 n); clear H2;
668 apply (ex_intro ? ? []);
674 apply (ex_intro ? ? (FAtom n::a));
681 | lapply (H2 n1); clear H2;
683 generalize in match Hletin; clear Hletin;
692 lapply (H2 n); clear H2;
693 rewrite > eqb_n_n in Hletin;
696 rewrite > eqb_n_n in H3;
699 generalize in match H3;
700 generalize in match H1; clear H1;
701 generalize in match H; clear H;
715 apply (eq_plus_n_m_O_to_eq_m_O ? ? H2)
720 | generalize in match H4; clear H4;
721 generalize in match H2; clear H2;
747 lemma completeness_base:
748 ∀S. size_of_sequent S = 0 → is_tautology (formula_of_sequent S) → derive S.
751 simplify in ⊢ (?→%→?);
753 elim (look_for_axiom t t1);
755 rewrite > H2; clear H2;
756 rewrite > H4; clear H4;
757 apply (exchangeL ? a1 a2 (FAtom a));
758 apply (exchangeR ? a3 a4 (FAtom a));
760 | elim (sizel_0_no_axiom_is_tautology t t1 H H1 H2);
763 apply (exchangeL ? a a1 FFalse);
767 apply (exchangeR ? a a1 FTrue);
774 lemma completeness_step:
775 ∀l1,l2,n. size_of_sequent 〈l1,l2〉 = S n →
776 (∃ll1,ll2,f. l1 = ll1 @ (f::ll2) ∧ size f > 0) ∨
777 (∃ll1,ll2,f. l2 = ll1 @ (f::ll2) ∧ size f > 0).
791 apply (ex_intro ? ? (FTrue::a));
800 apply (ex_intro ? ? (FFalse::a));
809 apply (ex_intro ? ? (FAtom n1::a));
814 apply (ex_intro ? ? []);
816 apply (ex_intro ? ? l);
817 apply (ex_intro ? ? (FAnd f f1));
825 apply (ex_intro ? ? []);
827 apply (ex_intro ? ? l);
828 apply (ex_intro ? ? (FOr f f1));
836 apply (ex_intro ? ? []);
838 apply (ex_intro ? ? l);
839 apply (ex_intro ? ? (FNot f));
859 apply (ex_intro ? ? []);
861 apply (ex_intro ? ? l);
862 apply (ex_intro ? ? (FAnd f f1));
867 apply (ex_intro ? ? []);
869 apply (ex_intro ? ? l);
870 apply (ex_intro ? ? (FOr f f1));
875 apply (ex_intro ? ? []);
877 apply (ex_intro ? ? l);
878 apply (ex_intro ? ? (FNot f));
886 theorem completeness: ∀S. is_tautology (formula_of_sequent S) → derive S.
888 generalize in match (refl_eq ? (size_of_sequent S));
889 elim (size_of_sequent S) in ⊢ (? ? ? %→?);
890 [ apply completeness_base;
899 lapply (H (λx.true));
902 lapply (H (λx.false));
907 lapply (H2 i); clear H2;
912 lapply (H2 i); clear H2;