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 include "nat/plus.ma".
16 include "nat/compare.ma".
17 include "list/sort.ma".
18 include "datatypes/constructors.ma".
20 inductive Formula : Type ≝
23 | FAtom: nat → Formula
24 | FAnd: Formula → Formula → Formula
25 | FOr: Formula → Formula → Formula
26 | FNot: Formula → Formula.
28 definition interp ≝ nat → bool.
30 let rec eval (interp:interp) F on F : bool ≝
35 | FAnd f1 f2 ⇒ eval interp f1 ∧ eval interp f2
36 | FOr f1 f2 ⇒ eval interp f1 ∨ eval interp f2
37 | FNot f ⇒ ¬ eval interp f
40 inductive not_nf : Formula → Prop ≝
42 | NFalse: not_nf FFalse
43 | NAtom: ∀n. not_nf (FAtom n)
44 | NAnd: ∀f1,f2. not_nf f1 → not_nf f2 → not_nf (FAnd f1 f2)
45 | NOr: ∀f1,f2. not_nf f1 → not_nf f2 → not_nf (FOr f1 f2)
46 | NNot: ∀n.not_nf (FNot (FAtom n)).
52 | FAtom n ⇒ FNot (FAtom n)
53 | FAnd f1 f2 ⇒ FOr (negate f1) (negate f2)
54 | FOr f1 f2 ⇒ FAnd (negate f1) (negate f2)
55 | FNot f ⇒ elim_not f]
61 | FAnd f1 f2 ⇒ FAnd (elim_not f1) (elim_not f2)
62 | FOr f1 f2 ⇒ FOr (elim_not f1) (elim_not f2)
66 theorem not_nf_elim_not: ∀F.not_nf (elim_not F) ∧ not_nf (negate F).
69 [1,2,3: simplify; autobatch
84 theorem demorgan1: ∀b1,b2:bool. (¬ (b1 ∧ b2)) = ¬ b1 ∨ ¬ b2.
91 theorem demorgan2: ∀b1,b2:bool. (¬ (b1 ∨ b2)) = ¬ b1 ∧ ¬ b2.
98 theorem eq_notb_notb_b_b: ∀b:bool. (¬ ¬ b) = b.
104 theorem eq_eval_elim_not_eval:
105 ∀i,F. eval i (elim_not F) = eval i F ∧ eval i (negate F) = eval i (FNot F).
108 [1,2,3: split; reflexivity
115 |replace with ((eval i (FNot f) ∨ eval i (FNot f1)) = ¬ (eval i f ∧ eval i f1));
120 |replace with ((eval i (FNot f) ∧ eval i (FNot f1)) = ¬ (eval i f ∨ eval i f1));
129 | change with (eval i (elim_not f) = ¬ ¬ eval i f);
135 definition sequent ≝ (list Formula) × (list Formula).
137 inductive derive: sequent → Prop ≝
138 ExchangeL: ∀l,l1,l2,f. derive 〈f::l1@l2,l〉 → derive 〈l1 @ [f] @ l2,l〉
139 | ExchangeR: ∀l,l1,l2,f. derive 〈l,f::l1@l2〉 → derive 〈l,l1 @ [f] @ l2〉
140 | Axiom: ∀l1,l2,f. derive 〈f::l1, f::l2〉
141 | TrueR: ∀l1,l2. derive 〈l1,FTrue::l2〉
142 | FalseL: ∀l1,l2. derive 〈FFalse::l1,l2〉
143 | AndR: ∀l1,l2,f1,f2.
144 derive 〈l1,f1::l2〉 → derive 〈l1,f2::l2〉 →
145 derive 〈l1,FAnd f1 f2::l2〉
146 | AndL: ∀l1,l2,f1,f2.
147 derive 〈f1 :: f2 :: l1,l2〉 → derive 〈FAnd f1 f2 :: l1,l2〉
149 derive 〈f1::l1,l2〉 → derive 〈f2::l1,l2〉 →
150 derive 〈FOr f1 f2 :: l1,l2〉
152 derive 〈l1,f1 :: f2 :: l2〉 → derive 〈l1,FOr f1 f2 :: l2〉
154 derive 〈f::l1,l2〉 → derive 〈l1,FNot f :: l2〉
156 derive 〈l1,f::l2〉 → derive 〈FNot f :: l1,l2〉.
158 let rec and_of_list l ≝
161 | cons F l' ⇒ FAnd F (and_of_list l')
164 let rec or_of_list l ≝
167 | cons F l' ⇒ FOr F (or_of_list l')
170 definition formula_of_sequent ≝
171 λs.match s with [pair l1 l2 ⇒ FOr (FNot (and_of_list l1)) (or_of_list l2)].
173 definition is_tautology ≝
174 λF. ∀i. eval i F = true.
176 axiom assoc_orb: associative ? orb.
177 axiom symm_orb: symmetric ? orb.
178 axiom orb_not_b_b: ∀b:bool. (¬b ∨ b) = true.
179 axiom distributive_orb_andb: distributive ? orb andb.
180 axiom symm_andb: symmetric ? andb.
181 axiom associative_andb: associative ? andb.
182 axiom distributive_andb_orb: distributive ? andb orb.
184 lemma and_of_list_permut:
185 ∀i,f,l1,l2. eval i (and_of_list (l1 @ (f::l2))) = eval i (and_of_list (f :: l1 @ l2)).
192 autobatch paramodulation
196 lemma or_of_list_permut:
197 ∀i,f,l1,l2. eval i (or_of_list (l1 @ (f::l2))) = eval i (or_of_list (f :: l1 @ l2)).
204 autobatch paramodulation
208 theorem soundness: ∀F. derive F → is_tautology (formula_of_sequent F).
211 [ simplify in H2 ⊢ %;
213 lapply (H2 i); clear H2;
214 rewrite > and_of_list_permut;
217 | simplify in H2 ⊢ %;
219 lapply (H2 i); clear H2;
220 rewrite > or_of_list_permut;
227 rewrite > assoc_orb in ⊢ (? ? (? % ?) ?);
228 rewrite > symm_orb in ⊢ (? ? (? (? ? %) ?) ?);
230 rewrite > orb_not_b_b;
239 | simplify in H2 H4 ⊢ %;
241 lapply (H2 i); clear H2;
242 lapply (H4 i); clear H4;
243 rewrite > symm_orb in ⊢ (? ? (? ? %) ?);
244 rewrite > distributive_orb_andb;
245 autobatch paramodulation
246 | simplify in H2 ⊢ %;
248 lapply (H2 i); clear H2;
250 | simplify in H2 H4 ⊢ %;
252 lapply (H2 i); clear H2;
253 lapply (H4 i); clear H4;
255 rewrite > distributive_andb_orb;
258 rewrite > distributive_orb_andb;
259 autobatch paramodulation
260 | simplify in H2 ⊢ %;
262 lapply (H2 i); clear H2;
264 | simplify in H2 ⊢ %;
266 lapply (H2 i); clear H2;
267 autobatch paramodulation
268 | simplify in H2 ⊢ %;
270 lapply (H2 i); clear H2;
271 autobatch paramodulation
275 alias num (instance 0) = "natural number".
281 | FAnd f1 f2 ⇒ S (size f1 + size f2)
282 | FOr f1 f2 ⇒ S (size f1 + size f2)
283 | FNot f ⇒ S (size f)
289 | cons F l' ⇒ size F + sizel l'
292 definition size_of_sequent ≝
293 λS.match S with [ pair l r ⇒ sizel l + sizel r].
296 ∀l1,l2,F. derive 〈l1,l2〉 → derive 〈l1,F::l2〉.
298 definition same_atom : Formula → Formula → bool.
309 definition symmetricb ≝
310 λA:Type.λeq:A → A → bool. ∀x,y. eq x y = eq y x.
312 theorem symmetricb_eqb: symmetricb ? eqb.
322 theorem symmetricb_same_atom: symmetricb ? same_atom.
332 |*: elim y; reflexivity
336 definition transitiveb ≝
337 λA:Type.λeq:A → A → bool.
338 ∀x,y,z. eq x y = true → eq y z = eq x z.
340 theorem transitiveb_same_atom: transitiveb ? same_atom.
349 rewrite > (eqb_true_to_eq ? ? H);
377 theorem eq_to_eq_mem:
378 ∀A.∀eq: A → A → bool.transitiveb ? eq →
379 ∀x,y,l.eq x y = true → mem ? eq x l = mem ? eq y l.
384 rewrite > (H ? ? ? H1);
390 theorem mem_to_exists_l1_l2:
391 ∀A,eq,n,l. (∀x,y. eq x y = true → x = y) → mem A eq n l = true → ∃l1,l2. l = l1 @ (n :: l2).
397 apply (bool_elim ? (eq n a));
399 [ apply (ex_intro ? ? []);
400 apply (ex_intro ? ? l1);
402 rewrite > (H1 ? ? H3);
404 | rewrite > H3 in H2;
409 apply (ex_intro ? ? (a::a1));
410 apply (ex_intro ? ? a2);
417 lemma same_atom_to_eq: ∀f1,f2. same_atom f1 f2 = true → f1=f2.
428 rewrite > (eqb_true_to_eq ? ? H);
445 lemma same_atom_to_exists: ∀f1,f2. same_atom f1 f2 = true → ∃n. f1 = FAtom n.
460 lemma mem_same_atom_to_exists:
461 ∀f,l. mem ? same_atom f l = true → ∃n. f = FAtom n.
467 apply (bool_elim ? (same_atom f a));
469 [ elim (same_atom_to_exists ? ? H2);
471 | rewrite > H2 in H1;
479 lemma look_for_axiom:
481 (∃n,ll1,ll2,lr1,lr2. l1 = ll1 @ (FAtom n :: ll2) ∧ l2 = lr1 @ (FAtom n :: lr2))
482 ∨ ∀n1. (mem ? same_atom (FAtom n1) l1 ∧ mem ? same_atom (FAtom n1) l2) = false.
491 generalize in match (refl_eq ? (mem ? same_atom a l2));
492 elim (mem ? same_atom a l2) in ⊢ (? ? ? %→?);
494 elim (mem_to_exists_l1_l2 ? ? ? ? same_atom_to_eq H1);
496 elim (mem_same_atom_to_exists ? ? H1);
498 apply (ex_intro ? ? a3);
500 apply (ex_intro ? ? []);
506 apply (ex_intro ? ? a1);
507 apply (ex_intro ? ? (a::a2));
509 apply (ex_intro ? ? a3);
510 apply (ex_intro ? ? a4);
514 apply (bool_elim ? (same_atom a (FAtom n1)));
516 rewrite > (eq_to_eq_mem ? ? transitiveb_same_atom ? ? ? H3) in H1;
520 change in ⊢ (? ? (? % ?) ?) with
521 (match same_atom (FAtom n1) a with
523 |false ⇒ mem ? same_atom (FAtom n1) l
525 rewrite > symmetricb_same_atom;
535 lemma eq_plus_n_m_O_to_eq_m_O: ∀n,m.n+m=0 → m=0.
544 lemma not_eq_nil_append_cons: ∀A.∀l1,l2.∀x:A.¬ [] = l1 @ (x :: l2).
558 [true⇒true|false⇒mem Formula same_atom (FAtom n) l]) (and_of_list l)) =
560 (λn:nat.mem Formula same_atom (FAtom n) l) (and_of_list l)).
564 | simplify in ⊢ (? ? (? (? ? %)) ?);
565 change in ⊢ (? ? (? %) ?) with
567 .match eqb n x in bool return λb:bool.bool with
568 [true⇒true|false⇒mem Formula same_atom (FAtom n) (t::l1)]) t
571 .match eqb n x in bool return λb:bool.bool with
572 [true⇒true|false⇒mem Formula same_atom (FAtom n) (t::l1)])
581 lemma sizel_0_no_axiom_is_tautology:
582 ∀l1,l2. size_of_sequent 〈l1,l2〉 = 0 → is_tautology (formula_of_sequent 〈l1,l2〉) →
583 (∀n. (mem ? same_atom (FAtom n) l1 ∧ mem ? same_atom (FAtom n) l2) = false) →
584 (∃ll1,ll2. l1 = ll1 @ (FFalse :: ll2)) ∨ (∃ll1,ll2. l2 = ll1 @ (FTrue :: ll2)).
586 lapply (H1 (λn.mem ? same_atom (FAtom n) l1)); clear H1;
588 elim l1 in Hletin H2 H ⊢ % 0;
591 elim l2 in H2 H1 H ⊢ % 0;
599 apply (ex_intro ? ? []);
607 elim (not_eq_nil_append_cons ? ? ? ? H6)
610 apply (ex_intro ? ? (FFalse::a1));
613 apply (ex_intro ? ? a2);
619 elim (H H1 H2 H3); clear H;
622 elim (not_eq_nil_append_cons ? ? ? ? H5)
625 apply (ex_intro ? ? (FAtom n::a1));
642 apply (ex_intro ? ? (FTrue::a1));
649 | lapply (H2 n); clear H2;
656 apply (ex_intro ? ? []);
662 apply (ex_intro ? ? (FAtom n::a1));
669 | lapply (H2 n1); clear H2;
671 elim (eqb n1 n) in Hletin ⊢ %;
679 lapply (H2 n); clear H2;
680 rewrite > eqb_n_n in Hletin;
683 rewrite > eqb_n_n in H3;
686 elim l in H3 H1 H ⊢ % 0;
699 apply (eq_plus_n_m_O_to_eq_m_O ? ? H2)
704 | elim t1 in H4 H2 ⊢ %;
729 lemma completeness_base:
730 ∀S. size_of_sequent S = 0 → is_tautology (formula_of_sequent S) → derive S.
733 simplify in ⊢ (?→%→?);
735 elim (look_for_axiom a b);
737 rewrite > H2; clear H2;
738 rewrite > H4; clear H4;
739 apply (ExchangeL ? a2 a3 (FAtom a1));
740 apply (ExchangeR ? a4 a5 (FAtom a1));
742 | elim (sizel_0_no_axiom_is_tautology a b H H1 H2);
745 apply (ExchangeL ? a1 a2 FFalse);
749 apply (ExchangeR ? a1 a2 FTrue);
756 lemma completeness_step:
757 ∀l1,l2,n. size_of_sequent 〈l1,l2〉 = S n →
758 (∃ll1,ll2,f. l1 = ll1 @ (f::ll2) ∧ size f > 0) ∨
759 (∃ll1,ll2,f. l2 = ll1 @ (f::ll2) ∧ size f > 0).
773 apply (ex_intro ? ? (FTrue::a));
782 apply (ex_intro ? ? (FFalse::a));
791 apply (ex_intro ? ? (FAtom n1::a));
796 apply (ex_intro ? ? []);
798 apply (ex_intro ? ? l);
799 apply (ex_intro ? ? (FAnd f f1));
807 apply (ex_intro ? ? []);
809 apply (ex_intro ? ? l);
810 apply (ex_intro ? ? (FOr f f1));
818 apply (ex_intro ? ? []);
820 apply (ex_intro ? ? l);
821 apply (ex_intro ? ? (FNot f));
841 apply (ex_intro ? ? []);
843 apply (ex_intro ? ? l);
844 apply (ex_intro ? ? (FAnd f f1));
849 apply (ex_intro ? ? []);
851 apply (ex_intro ? ? l);
852 apply (ex_intro ? ? (FOr f f1));
857 apply (ex_intro ? ? []);
859 apply (ex_intro ? ? l);
860 apply (ex_intro ? ? (FNot f));
868 theorem completeness: ∀S. is_tautology (formula_of_sequent S) → derive S.
870 generalize in match (refl_eq ? (size_of_sequent S));
871 elim (size_of_sequent S) in ⊢ (? ? ? %→?);
872 [ apply completeness_base;
881 lapply (H (λx.true));
884 lapply (H (λx.false));
889 lapply (H2 i); clear H2;
894 lapply (H2 i); clear H2;