]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/demo/natural_deduction.ma
234b99af759e159aa110f32b6d89e46229ba0884
[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,B:CProp.λa:A.a.*)
16 axiom cast: ∀A,B:CProp.B → A.
17
18 (*notation < "\infrule (t\atop ⋮) (b \ALPOSTODI a) (? \ERROR)" with precedence 19
19 for @{ 'caste $a $b $t }.
20 interpretation "cast" 'caste a b t = (cast a b t).*)
21 notation < "\infrule (t\atop ⋮) mstyle color #ff0000 (b) (? \ERROR)" with precedence 19
22 for @{ 'caste $a $b $t }.
23 interpretation "cast" 'caste a b t = (cast a b t).
24
25 notation < "\infrule (t\atop ⋮) a ?" with precedence 19 for @{ 'cast $a $t }.
26 interpretation "cast" 'cast a t = (cast a a t).
27
28 definition assumpt ≝ λA:CProp.λa:A.a.
29
30 notation < "[ a ] \sup mstyle color #ff0000 (H)" with precedence 19 for @{ 'asse $a $H }.
31 interpretation "assumption" 'asse a H = (cast _ _ (assumpt a (cast _ _ H))).
32
33 notation < "[ a ] \sup H" with precedence 19 for @{ 'ass $a $H }.
34 interpretation "assumption" 'ass a H = (cast a a  (assumpt a (cast a a H))).
35
36 inductive Imply (A,B:CProp) : CProp ≝
37  Imply_intro: (A → B) → Imply A B.
38  
39 notation "hbox(a break ⇒ b)" right associative with precedence 20 for @{ 'Imply $a $b }.
40 interpretation "Imply" 'Imply a b = (Imply a b).
41
42 notation < "\infrule hbox(\emsp b \emsp) mstyle color #ff0000(ab) (⇒\sub\i \emsp ident H \ERROR) " with precedence 19
43 for @{ 'Imply_introe $xxx $ab (λ${ident H}:$p.$b) }.
44 interpretation "Imply_intro" 'Imply_introe xxx ab \eta.b = (cast xxx ab (Imply_intro _ _ b)).
45
46 notation < "\infrule hbox(\emsp b \emsp) ab (⇒\sub\i \emsp ident H) " with precedence 19
47 for @{ 'Imply_intro $ab (λ${ident H}:$p.$b) }.
48 interpretation "Imply_intro" 'Imply_intro ab \eta.b = (cast ab ab (Imply_intro _ _ b)).
49
50 definition Imply_elim ≝ λA,B.λf:Imply A B.λa:A.match f with [ Imply_intro g ⇒ g a].
51
52 notation < "\infrule hbox(\emsp ab \emsp\emsp\emsp a\emsp) b (⇒\sub\e) " with precedence 19 for @{ 'Imply_elim $ab $a $b }.
53 interpretation "Imply_elim" 'Imply_elim ab a b = (cast _ b (Imply_elim _ _ ab a)).
54
55 inductive And (A,B:CProp) : CProp ≝
56  And_intro: A → B → And A B.
57
58 interpretation "constructive and" 'and x y = (And x y).
59
60 notation < "\infrule hbox(\emsp a \emsp\emsp\emsp b \emsp) ab (∧\sub\i)" with precedence 19 for @{ 'And_intro $a $b $ab }.
61 interpretation "And_intro" 'And_intro a b ab = (cast _ ab (And_intro _ _ a b)).
62
63 definition And_elim_l ≝
64  λA,B.λc:A∧B.match c with [ And_intro a b ⇒ a ].
65
66 notation < "\infrule hbox(\emsp ab \emsp) a (∧\sub\e\sup\l)" with precedence 19 for @{ 'And_elim_l $ab $a }.
67 interpretation "And_elim_l" 'And_elim_l ab a = (cast _ a (And_elim_l _ _ ab)).
68
69 definition And_elim_r ≝
70  λA,B.λc:A∧B.match c with [ And_intro a b ⇒ b ].
71
72 notation < "\infrule hbox(\emsp ab \emsp) b (∧\sub\e\sup\r)" with precedence 19 for @{ 'And_elim_r $ab $b }.
73 interpretation "And_elim_r" 'And_elim_r ab b = (cast _ b (And_elim_r _ _ ab)).
74
75 inductive Or (A,B:CProp) : CProp ≝
76  | Or_intro_l: A → Or A B
77  | Or_intro_r: B → Or A B. 
78  
79 interpretation "constructive or" 'or x y = (Or x y).
80
81 notation < "\infrule hbox(\emsp a \emsp) ab (∨\sub\i\sup\l)" with precedence 19 for @{ 'Or_intro_l $a $ab }.
82 interpretation "Or_intro_l" 'Or_intro_l a ab = (cast _ ab (Or_intro_l _ _ a)).
83
84 notation < "\infrule hbox(\emsp b \emsp) ab (∨\sub\i\sup\l)" with precedence 19 for @{ 'Or_intro_r $b $ab }.
85 interpretation "Or_intro_l" 'Or_intro_r b ab = (cast _ ab (Or_intro_r _ _ b)).
86
87 definition Or_elim ≝
88  λA,B,C:CProp.λc:A∨B.λfa: A → C.λfb: B → C.
89   match c with [ Or_intro_l a ⇒ fa a | Or_intro_r b ⇒ fb b].
90
91 notation < "\infrule hbox(\emsp ab \emsp\emsp\emsp ac \emsp\emsp\emsp bc \emsp) c (∨\sub\e \emsp ident Ha \emsp ident Hb)" with precedence 19
92 for @{ 'Or_elim $ab (λ${ident Ha}:$ta.$ac) (λ${ident Hb}:$tb.$bc) $c }.
93 interpretation "Or_elim" 'Or_elim ab \eta.ac \eta.bc c = (cast _ c (Or_elim _ _ _ ab ac bc)).
94
95 inductive Exists (A:Type) (P:A→CProp) : CProp ≝
96   Exists_intro: ∀w:A. P w → Exists A P.
97
98 interpretation "constructive ex" 'exists \eta.x = (Exists _ x).
99
100 notation < "\infrule hbox(\emsp Pn \emsp) Px (∃\sub\i)" with precedence 19
101 for @{ 'Exists_intro $Pn $Px }.
102 interpretation "Exists_intro" 'Exists_intro Pn Px = (cast _ Px (Exists_intro _ _ _ Pn)).
103
104 definition Exists_elim ≝
105   λA:Type.λP:A→CProp.λC:CProp.λc:∃x:A.P x.λH:(∀x.P x → C).
106    match c with [ Exists_intro w p ⇒ H w p ].
107
108 notation < "\infrule hbox(\emsp ExPx \emsp\emsp\emsp Pc \emsp) c (∃\sub\e \emsp ident n \emsp ident HPn)" with precedence 19
109 for @{ 'Exists_elim $ExPx (λ${ident n}:$tn.λ${ident HPn}:$Pn.$Pc) $c }.
110 interpretation "Exists_elim" 'Exists_elim ExPx Pc c = (cast _ c (Exists_elim _ _ _ ExPx Pc)).
111
112 inductive Forall (A:Type) (P:A→CProp) : CProp ≝
113  Forall_intro: (∀n:A. P n) → Forall A P.
114
115 notation "\forall ident x:A.break term 19 Px" with precedence 20
116 for @{ 'Forall (λ${ident x}:$A.$Px) }.
117 interpretation "Forall" 'Forall \eta.Px = (Forall _ Px).
118
119 notation < "\infrule hbox(\emsp Px \emsp) Pn (∀\sub\i \emsp ident x)" with precedence 19
120 for @{ 'Forall_intro (λ${ident x}:$tx.$Px) $Pn }.
121 interpretation "Forall_intro" 'Forall_intro Px Pn = (cast _ Pn (Forall_intro _ _ Px)).
122
123 definition Forall_elim ≝
124  λA:Type.λP:A→CProp.λn:A.λf:∀x:A.P x.match f with [ Forall_intro g ⇒ g n ].
125
126 notation < "\infrule hbox(\emsp Px \emsp) Pn (∀\sub\i)" with precedence 19 for @{ 'Forall_elim $Px $Pn }.
127 interpretation "Forall_elim" 'Forall_elim Px Pn = (cast _ Pn (Forall_elim _ _ _ Px)).
128
129 axiom A: CProp.
130 axiom B: CProp.
131 axiom C: CProp.
132 axiom D: CProp.
133 axiom E: CProp.
134
135
136 notation > "[H]" with precedence 90
137 for @{ assumpt ? (cast ? ? $H)}.
138 notation > "⇒\sub\i [ident H] term 90 b" with precedence 19
139 for @{ Imply_intro ?? (λ${ident H}.cast ? $b ?) }.
140 notation > "⇒\sub\e term 90 ab term 90 a" with precedence 19
141 for @{ Imply_elim ?? (cast ? $ab ?) (cast $a $a ?) }.
142 notation > "∧\sub\i term 90 a term 90 b" with precedence 19
143 for @{ And_intro ?? (cast ? $a ?) (cast ? $b ?) }.
144 (*notation > "∧\sub\e\sup\l term 90 ab" with precedence 19
145 for @{ And_elim_l ?? (cast (? ∧ False) $ab ?) }.
146 notation > "∧\sub\e\sup\l term 90 a ∧ term 90 b" with precedence 19
147 for @{ And_elim_l ?? (cast (? ∧ $b) ($a ∧ $b) ?) }. *)
148 notation > "∧\sub\e\sup\l term 90 ab" with precedence 19
149 for @{ And_elim_l ?? (cast $ab $ab ?) }. (* CSC: WRONG *)
150 notation > "∧\sub\e\sup\r term 90 ab" with precedence 19
151 for @{ And_elim_r ?? (cast $ab $ab ?) }. (* CSC: WRONG *)
152 notation > "∨\sub\i\sup\l term 90 a" with precedence 19
153 for @{ Or_intro_l ?? (cast ? $a ?) }.
154 notation > "∨\sub\i\sup\r term 90 a" with precedence 19
155 for @{ Or_intro_r ?? (cast ? $a ?) }.
156 notation > "∨\sub\e term 90 ab [ident Ha] term 90 c1 [ident Hb] term 90 c2" with precedence 19
157 for @{ Or_elim ??? (cast $ab $ab ?) (λ${ident Ha}.cast ? $c1 ?) (λ${ident Hb}.cast ? $c2 ?) }.
158 notation > "∀\sub\i [ident z] term 90 a" with precedence 19
159 for @{ Forall_intro ?? (λ${ident z}.cast ? $a ?) }.
160 notation > "∀\sub\e term 90 ab" with precedence 19
161 for @{ Forall_elim ?? ? (cast $ab $ab ?) }. (* CSC: WRONG *)
162 notation > "∃\sub\e term 90 enpn [ident z] [ident pz] term 90 c" with precedence 19
163 for @{ Exists_elim ??? (cast $enpn $enpn ?) (λ${ident z}.λ${ident pz}.cast ? $c ?) }.
164 notation > "∃\sub\i term 90 n term 90 pn" with precedence 19
165 for @{ Exists_intro ? (λ_.?) $n (cast ? $pn ?) }.
166
167 lemma ex1 : (A ⇒ E) ∨ B ⇒ A ∧ C ⇒ (E ∧ C) ∨ B.
168  apply (cast ? ((A⇒E)∨B⇒A∧C⇒E∧C∨B));
169  (*NICE: TRY THIS ERROR!
170  apply (⇒\sub\i [H] (A∧C⇒E∧E∧C∨B));
171  apply (⇒\sub\i [K] (E∧E∧C∨B));
172   OR DO THE RIGHT THING *)
173  apply (⇒\sub\i [H] (A∧C⇒E∧C∨B));
174  apply (⇒\sub\i [K] (E∧C∨B));
175  
176  apply (∨\sub\e ((A⇒E)∨B) [C1] (E∧C∨B) [C2] (E∧C∨B));
177 [ apply [H];
178 | apply (∨\sub\i\sup\l (E∧C));
179   apply (∧\sub\i E C);
180   [ apply (⇒\sub\e (A⇒E) A);
181     [ apply [C1];
182     | apply (∧\sub\e\sup\l (A∧C));
183       apply [K];
184     ]
185   | apply (∧\sub\e\sup\r (A∧C));
186     apply [K];
187   ]
188 | apply (∨\sub\i\sup\r B);
189   apply [C2];
190 ]
191 qed.
192
193 axiom N: Type.
194 axiom R: N → N → CProp.
195
196 lemma ex2: (∀a:N.∀b:N.R a b ⇒ R b a) ⇒ ∀z:N.(∃x.R x z) ⇒ ∃y. R z y.
197  apply (cast ? ((∀a:N.∀b:N.R a b ⇒ R b a) ⇒ ∀z:N.(∃x.R x z) ⇒ ∃y. R z y));
198  apply (⇒\sub\i [H] (∀z:N.(∃x:N.R x z)⇒∃y:N.R z y));
199  apply (∀\sub\i [z] ((∃x:N.R x z)⇒∃y:N.R z y));
200  apply (⇒\sub\i [H2] (∃y:N.R z y));
201  apply (∃\sub\e (∃x:N.R x z) [n] [H3] (∃y:N.R z y));
202   [ apply [H2]
203   | apply (∃\sub\i n (R z n));
204     apply (⇒\sub\e (R n z ⇒ R z n) (R n z));
205      [ apply (∀\sub\e (∀b:N.R n b ⇒ R b n));
206        apply (∀\sub\e (∀a:N.∀b:N.R a b ⇒ R b a));
207        apply [H]
208      | apply [H3]
209      ]
210   ]
211 qed.