]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/demo/natural_deduction.ma
e0c6897208d3d9723f8720be432fcd4c26420e5b
[helm.git] / helm / software / matita / library / demo / natural_deduction.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 definition cast ≝ λA:CProp.λa:A.a.
16
17 notation < "\infrule (t\atop ⋮) a ?" with precedence 19 for @{ 'cast $a $t }.
18 interpretation "cast" 'cast a t = (cast a t).
19
20 definition assumpt ≝ λA:CProp.λa:A.a.
21
22 notation < "[ a ] \sup H" with precedence 19 for @{ 'ass $a $H }.
23 interpretation "assumption" 'ass a H = (cast _ (assumpt a H)).
24
25 inductive Imply (A,B:CProp) : CProp ≝
26  Imply_intro: (A → B) → Imply A B.
27  
28 notation "hbox(a break ⇒ b)" right associative with precedence 20 for @{ 'Imply $a $b }.
29 interpretation "Imply" 'Imply a b = (Imply a b).
30
31 notation < "\infrule hbox(\emsp b \emsp) ab (⇒\sub\i) " with precedence 19 for @{ 'Imply_intro $ab (λ${ident H}:$p.$b) }.
32 interpretation "Imply_intro" 'Imply_intro ab \eta.b = (cast ab (Imply_intro _ _ b)).
33
34 definition Imply_elim ≝ λA,B.λf:Imply A B.λa:A.match f with [ Imply_intro g ⇒ g a].
35
36 notation < "\infrule hbox(\emsp ab \emsp\emsp\emsp a\emsp) b (⇒\sub\e) " with precedence 19 for @{ 'Imply_elim $ab $a $b }.
37 interpretation "Imply_elim" 'Imply_elim ab a b = (cast b (Imply_elim _ _ ab a)).
38
39 inductive And (A,B:CProp) : CProp ≝
40  And_intro: A → B → And A B.
41
42 interpretation "constructive and" 'and x y = (And x y).
43
44 notation < "\infrule hbox(\emsp a \emsp\emsp\emsp b \emsp) ab (∧\sub\i)" with precedence 19 for @{ 'And_intro $a $b $ab }.
45 interpretation "And_intro" 'And_intro a b ab = (cast ab (And_intro _ _ a b)).
46
47 definition And_elim_l ≝
48  λA,B.λc:A∧B.match c with [ And_intro a b ⇒ a ].
49
50 notation < "\infrule hbox(\emsp ab \emsp) a (∧\sub\e\sup\l)" with precedence 19 for @{ 'And_elim_l $ab $a }.
51 interpretation "And_elim_l" 'And_elim_l ab a = (cast a (And_elim_l _ _ ab)).
52
53 definition And_elim_r ≝
54  λA,B.λc:A∧B.match c with [ And_intro a b ⇒ b ].
55
56 notation < "\infrule hbox(\emsp ab \emsp) b (∧\sub\e\sup\r)" with precedence 19 for @{ 'And_elim_r $ab $b }.
57 interpretation "And_elim_r" 'And_elim_r ab b = (cast b (And_elim_r _ _ ab)).
58
59 inductive Or (A,B:CProp) : CProp ≝
60  | Or_intro_l: A → Or A B
61  | Or_intro_r: B → Or A B. 
62  
63 interpretation "constructive or" 'or x y = (Or x y).
64
65 notation < "\infrule hbox(\emsp a \emsp) ab (∨\sub\i\sup\l)" with precedence 19 for @{ 'Or_intro_l $a $ab }.
66 interpretation "Or_intro_l" 'Or_intro_l a ab = (cast ab (Or_intro_l _ _ a)).
67
68 notation < "\infrule hbox(\emsp b \emsp) ab (∨\sub\i\sup\l)" with precedence 19 for @{ 'Or_intro_r $b $ab }.
69 interpretation "Or_intro_l" 'Or_intro_r b ab = (cast ab (Or_intro_r _ _ b)).
70
71 definition Or_elim ≝
72  λA,B,C:CProp.λc:A∨B.λfa: A → C.λfb: B → C.
73   match c with [ Or_intro_l a ⇒ fa a | Or_intro_r b ⇒ fb b].
74
75 notation < "\infrule hbox(\emsp ab \emsp\emsp\emsp ac \emsp\emsp\emsp bc \emsp) c (∨\sub\e)" with precedence 19 for @{ 'Or_elim $ab (λ${ident Ha}:$ta.$ac) (λ${ident Hb}:$tb.$bc) $c }.
76 interpretation "Or_elim" 'Or_elim ab ac bc c = (cast c (Or_elim _ _ _ ab ac bc)).
77
78 inductive Exists (A:Type) (P:A→CProp) : CProp ≝
79   Exists_intro: ∀w:A. P w → Exists A P.
80
81 interpretation "constructive ex" 'exists \eta.x = (Exists _ x).
82
83 notation < "\infrule hbox(\emsp Pn \emsp) Px (∃\sub\i)" with precedence 19 for @{ 'Exists_intro $Pn $Px }.
84 interpretation "Exists_intro" 'Exists_intro Pn Px = (cast Px (Exists_intro _ _ _ Pn)).
85
86 definition Exists_elim ≝
87   λA:Type.λP:A→CProp.λC:CProp.λc:∃x:A.P x.λH:(∀x.P x → C).
88    match c with [ Exists_intro w p ⇒ H w p ].
89
90 notation < "\infrule hbox(\emsp ExPx \emsp\emsp\emsp Pc \emsp) c (∃\sub\e)" with precedence 19 for @{ 'Exists_elim $ExPx (λ${ident n}:$tn.λ${ident HPn}:$Pn.$Pc) $c }.
91 interpretation "Exists_elim" 'Exists_elim ExPx Pc c = (cast c (Exists_elim _ _ _ ExPx Pc)).
92
93 inductive Forall (A:Type) (P:A→CProp) : CProp ≝
94  Forall_intro: (∀n:A. P n) → Forall A P.
95
96 notation "\forall ident x:A.break term 19 Px" with precedence 20 for @{ 'Forall (λ${ident x}:$A.$Px) }.
97 interpretation "Forall" 'Forall \eta.Px = (Forall _ Px).
98
99 notation < "\infrule hbox(\emsp Px \emsp) Pn (∀\sub\i)" with precedence 19 for @{ 'Forall_intro (λ${ident x}:$tx.$Px) $Pn }.
100 interpretation "Forall_intro" 'Forall_intro Px Pn = (cast Pn (Forall_intro _ _ Px)).
101
102 definition Forall_elim ≝
103  λA:Type.λP:A→CProp.λn:A.λf:∀x:A.P x.match f with [ Forall_intro g ⇒ g n ].
104
105 notation < "\infrule hbox(\emsp Px \emsp) Pn (∀\sub\i)" with precedence 19 for @{ 'Forall_elim $Px $Pn }.
106 interpretation "Forall_elim" 'Forall_elim Px Pn = (cast Pn (Forall_elim _ _ _ Px)).
107
108 axiom A: CProp.
109 axiom B: CProp.
110 axiom C: CProp.
111 axiom D: CProp.
112 axiom E: CProp.
113
114
115 notation > "[H]" with precedence 90
116 for @{ assumpt ? $H}.
117 notation > "⇒\sub\i [ident H] term 90 b" with precedence 19
118 for @{ Imply_intro ?? (λ${ident H}.cast $b ?) }.
119 notation > "⇒\sub\e term 90 ab term 90 a" with precedence 19
120 for @{ Imply_elim ?? (cast $ab ?) (cast $a ?) }.
121 notation > "∧\sub\i term 90 a term 90 b" with precedence 19
122 for @{ And_intro ?? (cast $a ?) (cast $b ?) }.
123 notation > "∧\sub\e\sup\l term 90 ab" with precedence 19
124 for @{ And_elim_l ?? (cast $ab ?) }.
125 notation > "∧\sub\e\sup\r term 90 ab" with precedence 19
126 for @{ And_elim_r ?? (cast $ab ?) }.
127 notation > "∨\sub\i\sup\l term 90 a" with precedence 19
128 for @{ Or_intro_l ?? (cast $a ?) }.
129 notation > "∨\sub\i\sup\r term 90 a" with precedence 19
130 for @{ Or_intro_r ?? (cast $a ?) }.
131 notation > "∨\sub\e term 90 ab [ident Ha] term 90 c1 [ident Hb] term 90 c2" with precedence 19
132 for @{ Or_elim ??? (cast $ab ?) (λ${ident Ha}.cast $c1 ?) (λ${ident Hb}.cast $c2 ?) }.
133
134
135 lemma ex1 : (A ⇒ E) ∨ B ⇒ A ∧ C ⇒ (E ∧ C) ∨ B.
136  apply cast;
137  apply (⇒\sub\i [H] (A∧C⇒E∧C∨B));
138  apply (⇒\sub\i [K] (E∧C∨B));
139  apply (∨\sub\e ((A⇒E)∨B) [C1] (E∧C∨B) [C2] (E∧C∨B));
140 [ apply [H];
141 | apply (∨\sub\i\sup\l (E∧C));
142   apply (∧\sub\i E C);
143   [ apply (⇒\sub\e (A⇒E) A);
144     [ apply [C1];
145     | apply (∧\sub\e\sup\l (A∧C));
146       apply [K];
147     ]
148   | apply (∧\sub\e\sup\r (A∧C));
149     apply [K];
150   ]
151 | apply (∨\sub\i\sup\r B);
152   apply [C2];
153 ]
154 qed.
155
156 axiom N: Type.
157 axiom R: N → N → CProp.
158
159 lemma ex2: (∀a:N.∀b:N.R a b ⇒ R b a) ⇒ ∀z:N.(∃x.R x z) ⇒ ∃y. R z y.
160  apply cast; apply Imply_intro; intro;
161  apply cast; apply Forall_intro; intro z;
162  apply cast; apply Imply_intro; intro;
163  apply cast; apply (Exists_elim N (λy.R y z)); try intros (n);
164   [ apply cast; assumption
165   | apply cast; apply (Exists_intro ? ? n);
166     apply cast; apply (Imply_elim (R n z) (R z n));
167      [ apply cast; apply (Forall_elim N (λb:N.R n b ⇒ R b n) z);
168        apply cast; apply (Forall_elim N (λa:N.∀b:N.R a b ⇒ R b a) n);
169        apply cast; assumption
170      | apply cast; assumption
171      ]
172   ]
173 qed.