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 alias id "Nil" = "cic:/matita/list/list.ind#xpointer(1/1/1)".
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".
284 | FAnd f1 f2 ⇒ S (size f1 + size f2)
285 | FOr f1 f2 ⇒ S (size f1 + size f2)
286 | FNot f ⇒ S (size f)
292 | cons F l' ⇒ size F + sizel l'
295 definition size_of_sequent ≝
296 λS.match S with [ pair l r ⇒ sizel l + sizel r].
299 ∀l1,l2,F. derive 〈l1,l2〉 → derive 〈l1,F::l2〉.
301 definition same_atom : Formula → Formula → bool.
312 definition symmetricb ≝
313 λA:Type.λeq:A → A → bool. ∀x,y. eq x y = eq y x.
315 theorem symmetricb_eqb: symmetricb ? eqb.
325 theorem symmetricb_same_atom: symmetricb ? same_atom.
335 |*: elim y; reflexivity
339 definition transitiveb ≝
340 λA:Type.λeq:A → A → bool.
341 ∀x,y,z. eq x y = true → eq y z = eq x z.
343 theorem transitiveb_same_atom: transitiveb ? same_atom.
352 rewrite > (eqb_true_to_eq ? ? H);
380 theorem eq_to_eq_mem:
381 ∀A.∀eq: A → A → bool.transitiveb ? eq →
382 ∀x,y,l.eq x y = true → mem ? eq x l = mem ? eq y l.
387 rewrite > (H ? ? ? H1);
393 theorem mem_to_exists_l1_l2:
394 ∀A,eq,n,l. (∀x,y. eq x y = true → x = y) → mem A eq n l = true → ∃l1,l2. l = l1 @ (n :: l2).
400 apply (bool_elim ? (eq n t));
402 [ apply (ex_intro ? ? []);
403 apply (ex_intro ? ? l1);
405 rewrite > (H1 ? ? H3);
407 | rewrite > H3 in H2;
412 apply (ex_intro ? ? (t::a));
413 apply (ex_intro ? ? a1);
420 lemma same_atom_to_eq: ∀f1,f2. same_atom f1 f2 = true → f1=f2.
426 | generalize in match H; clear H;
432 rewrite > (eqb_true_to_eq ? ? H);
449 lemma same_atom_to_exists: ∀f1,f2. same_atom f1 f2 = true → ∃n. f1 = FAtom n.
464 lemma mem_same_atom_to_exists:
465 ∀f,l. mem ? same_atom f l = true → ∃n. f = FAtom n.
471 apply (bool_elim ? (same_atom f t));
473 [ elim (same_atom_to_exists ? ? H2);
475 | rewrite > H2 in H1;
483 lemma look_for_axiom:
485 (∃n,ll1,ll2,lr1,lr2. l1 = ll1 @ (FAtom n :: ll2) ∧ l2 = lr1 @ (FAtom n :: lr2))
486 ∨ ∀n1. (mem ? same_atom (FAtom n1) l1 ∧ mem ? same_atom (FAtom n1) l2) = false.
495 generalize in match (refl_eq ? (mem ? same_atom t l2));
496 elim (mem ? same_atom t l2) in ⊢ (? ? ? %→?);
498 elim (mem_to_exists_l1_l2 ? ? ? ? same_atom_to_eq H1);
500 elim (mem_same_atom_to_exists ? ? H1);
502 apply (ex_intro ? ? a2);
504 apply (ex_intro ? ? []);
510 apply (ex_intro ? ? a);
511 apply (ex_intro ? ? (t::a1));
513 apply (ex_intro ? ? a2);
514 apply (ex_intro ? ? a3);
518 apply (bool_elim ? (same_atom t (FAtom n1)));
520 rewrite > (eq_to_eq_mem ? ? transitiveb_same_atom ? ? ? H3) in H1;
524 change in ⊢ (? ? (? % ?) ?) with
525 (match same_atom (FAtom n1) t with
527 |false ⇒ mem ? same_atom (FAtom n1) l
529 rewrite > symmetricb_same_atom;
539 lemma eq_plus_n_m_O_to_eq_m_O: ∀n,m.n+m=0 → m=0.
548 lemma not_eq_nil_append_cons: ∀A.∀l1,l2.∀x:A.¬ [] = l1 @ (x :: l2).
562 [true⇒true|false⇒mem Formula same_atom (FAtom n) l]) (and_of_list l)) =
564 (λn:nat.mem Formula same_atom (FAtom n) l) (and_of_list l)).
568 | simplify in ⊢ (? ? (? (? ? %)) ?);
569 change in ⊢ (? ? (? %) ?) with
571 .match eqb n x in bool return λb:bool.bool with
572 [true⇒true|false⇒mem Formula same_atom (FAtom n) (t::l1)]) t
575 .match eqb n x in bool return λb:bool.bool with
576 [true⇒true|false⇒mem Formula same_atom (FAtom n) (t::l1)])
585 lemma sizel_0_no_axiom_is_tautology:
586 ∀l1,l2. size_of_sequent 〈l1,l2〉 = 0 → is_tautology (formula_of_sequent 〈l1,l2〉) →
587 (∀n. (mem ? same_atom (FAtom n) l1 ∧ mem ? same_atom (FAtom n) l2) = false) →
588 (∃ll1,ll2. l1 = ll1 @ (FFalse :: ll2)) ∨ (∃ll1,ll2. l2 = ll1 @ (FTrue :: ll2)).
590 lapply (H1 (λn.mem ? same_atom (FAtom n) l1)); clear H1;
592 generalize in match Hletin; clear Hletin;
593 generalize in match H2; clear H2;
594 generalize in match H; clear H;
598 generalize in match H2; clear H2;
599 generalize in match H1; clear H1;
600 generalize in match H; clear H;
609 apply (ex_intro ? ? []);
617 elim (not_eq_nil_append_cons ? ? ? ? H6)
620 apply (ex_intro ? ? (FFalse::a));
623 apply (ex_intro ? ? a1);
629 elim (H H1 H2 H3); clear H;
632 elim (not_eq_nil_append_cons ? ? ? ? H5)
635 apply (ex_intro ? ? (FAtom n::a));
652 apply (ex_intro ? ? (FTrue::a));
659 | lapply (H2 n); clear H2;
666 apply (ex_intro ? ? []);
672 apply (ex_intro ? ? (FAtom n::a));
679 | lapply (H2 n1); clear H2;
681 generalize in match Hletin; clear Hletin;
690 lapply (H2 n); clear H2;
691 rewrite > eqb_n_n in Hletin;
694 rewrite > eqb_n_n in H3;
697 generalize in match H3;
698 generalize in match H1; clear H1;
699 generalize in match H; clear H;
713 apply (eq_plus_n_m_O_to_eq_m_O ? ? H2)
718 | generalize in match H4; clear H4;
719 generalize in match H2; clear H2;
745 lemma completeness_base:
746 ∀S. size_of_sequent S = 0 → is_tautology (formula_of_sequent S) → derive S.
749 simplify in ⊢ (?→%→?);
751 elim (look_for_axiom t t1);
753 rewrite > H2; clear H2;
754 rewrite > H4; clear H4;
755 apply (exchangeL ? a1 a2 (FAtom a));
756 apply (exchangeR ? a3 a4 (FAtom a));
758 | elim (sizel_0_no_axiom_is_tautology t t1 H H1 H2);
761 apply (exchangeL ? a a1 FFalse);
765 apply (exchangeR ? a a1 FTrue);
772 lemma completeness_step:
773 ∀l1,l2,n. size_of_sequent 〈l1,l2〉 = S n →
774 (∃ll1,ll2,f. l1 = ll1 @ (f::ll2) ∧ size f > 0) ∨
775 (∃ll1,ll2,f. l2 = ll1 @ (f::ll2) ∧ size f > 0).
789 apply (ex_intro ? ? (FTrue::a));
798 apply (ex_intro ? ? (FFalse::a));
807 apply (ex_intro ? ? (FAtom n1::a));
812 apply (ex_intro ? ? []);
814 apply (ex_intro ? ? l);
815 apply (ex_intro ? ? (FAnd f f1));
823 apply (ex_intro ? ? []);
825 apply (ex_intro ? ? l);
826 apply (ex_intro ? ? (FOr f f1));
834 apply (ex_intro ? ? []);
836 apply (ex_intro ? ? l);
837 apply (ex_intro ? ? (FNot f));
857 apply (ex_intro ? ? []);
859 apply (ex_intro ? ? l);
860 apply (ex_intro ? ? (FAnd f f1));
865 apply (ex_intro ? ? []);
867 apply (ex_intro ? ? l);
868 apply (ex_intro ? ? (FOr f f1));
873 apply (ex_intro ? ? []);
875 apply (ex_intro ? ? l);
876 apply (ex_intro ? ? (FNot f));
884 theorem completeness: ∀S. is_tautology (formula_of_sequent S) → derive S.
886 generalize in match (refl_eq ? (size_of_sequent S));
887 elim (size_of_sequent S) in ⊢ (? ? ? %→?);
888 [ apply completeness_base;
897 lapply (H (λx.true));
900 lapply (H (λx.false));
905 lapply (H2 i); clear H2;
910 lapply (H2 i); clear H2;