2 include "nat/minus.ma".
4 let rec max n m on n ≝ match n - m with [ O => m | _ => n].
5 let rec min n m on n ≝ match n - m with [ O => n | _ => m].
6 definition if_then_else ≝ λT:Type.λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
7 notation > "'if' term 19 e 'then' term 19 t 'else' term 90 f" non associative with precedence 90 for @{ 'if_then_else $e $t $f }.
8 notation < "'if' \nbsp term 19 e \nbsp 'then' \nbsp term 19 t \nbsp 'else' \nbsp term 90 f \nbsp" non associative with precedence 90 for @{ 'if_then_else $e $t $f }.
9 interpretation "Formula if_then_else" 'if_then_else e t f = (if_then_else _ e t f).
12 inductive Formula : Type ≝
15 | FAtom: nat → Formula
16 | FAnd: Formula → Formula → Formula
17 | FOr: Formula → Formula → Formula
18 | FImpl: Formula → Formula → Formula
19 | FNot: Formula → Formula
22 let rec sem (v: nat → nat) (F: Formula) on F ≝
26 | FAtom n ⇒ min (v n) 1
27 | FAnd F1 F2 ⇒ min (sem v F1) (sem v F2)
28 | FOr F1 F2 ⇒ max (sem v F1) (sem v F2)
29 | FImpl F1 F2 ⇒ max (1 - sem v F1) (sem v F2)
30 | FNot F1 ⇒ 1 - (sem v F1)
34 notation < "[[ \nbsp term 19 a \nbsp ]] \nbsp \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }.
35 notation > "[[ term 19 a ]] \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }.
36 notation > "[[ term 19 a ]]_ term 90 v" non associative with precedence 90 for @{ sem $v $a }.
37 interpretation "Semantic of Formula" 'semantics v a = (sem v a).
39 lemma sem_bool : ∀F,v. [[ F ]]_v = 0 ∨ [[ F ]]_v = 1.
40 intros; elim F; simplify;
43 |cases (v n);[left;|cases n1;right;]reflexivity;
44 |4,5,6: cases H; cases H1; rewrite > H2; rewrite > H3; simplify;
45 first [ left;reflexivity | right; reflexivity ].
46 |cases H; rewrite > H1; simplify;[right|left]reflexivity;]
49 lemma min_bool : ∀n. min n 1 = 0 ∨ min n 1 = 1.
50 intros; cases n; [left;reflexivity] cases n1; right; reflexivity;
53 lemma min_max : ∀F,G,v.
54 min (1 - [[F]]_v) (1 - [[G]]_v) = 1 - max [[F]]_v [[G]]_v.
55 intros; cases (sem_bool F v);cases (sem_bool G v); rewrite > H; rewrite >H1;
56 simplify; reflexivity;
59 lemma max_min : ∀F,G,v.
60 max (1 - [[F]]_v) (1 - [[G]]_v) = 1 - min [[F]]_v [[G]]_v.
61 intros; cases (sem_bool F v);cases (sem_bool G v); rewrite > H; rewrite >H1;
62 simplify; reflexivity;
65 let rec negate (F: Formula) on F ≝
69 | FAtom n ⇒ FNot (FAtom n)
70 | FAnd F1 F2 ⇒ FAnd (negate F1) (negate F2)
71 | FOr F1 F2 ⇒ FOr (negate F1) (negate F2)
72 | FImpl F1 F2 ⇒ FImpl (negate F1) (negate F2)
73 | FNot F ⇒ FNot (negate F)
77 definition equiv ≝ λF1,F2. ∀v.[[ F1 ]]_v = [[ F2 ]]_v.
78 notation "hvbox(a \nbsp break mstyle color #0000ff (≡) \nbsp b)" non associative with precedence 45 for @{ 'equivF $a $b }.
79 notation > "a ≡ b" non associative with precedence 50 for @{ equiv $a $b }.
80 interpretation "equivalence for Formulas" 'equivF a b = (equiv a b).
82 lemma equiv_rewrite : ∀F1,F2,F3. F1 ≡ F2 → F1 ≡ F3 → F2 ≡ F3. intros; intro; autobatch. qed.
84 let rec dualize (F : Formula) on F : Formula ≝
89 | FAnd F1 F2 ⇒ FOr (dualize F1) (dualize F2)
90 | FOr F1 F2 ⇒ FAnd (dualize F1) (dualize F2)
91 | FImpl F1 F2 ⇒ FAnd (FNot (dualize F1)) (dualize F2)
92 | FNot F ⇒ FNot (dualize F)
96 λv:ℕ -> ℕ. λx. if eqb (min (v x) 1) 0 then 1 else 0.
100 Il linguaggio di dimostrazione di Matita
101 ========================================
103 Per dimostrare questo teorema in modo agevole è necessario utilizzare il
108 Quando la conclusuine è `a = b` permette di cambiarla in `b = a`.
111 theorem negate_invert:
112 ∀F:Formula.∀v:ℕ→ℕ.[[ negate F ]]_v=[[ F ]]_(invert v).
115 we proceed by induction on F to prove ([[ negate F ]]_v=[[ F ]]_(invert v)).
117 the thesis becomes ([[ negate FBot ]]_v=[[ FBot ]]_(invert v)).
120 the thesis becomes ([[ negate FTop ]]_v=[[ FTop ]]_(invert v)).
124 the thesis becomes ([[ negate (FAtom n) ]]_v=[[ FAtom n ]]_(invert v)).
125 the thesis becomes (1 - (min (v n) 1)= min (invert v n) 1).
126 the thesis becomes (1 - (min (v n) 1)= min (if eqb (min (v n) 1) 0 then 1 else 0) 1).
127 by min_bool we proved (min (v n) 1 = 0 ∨ min (v n) 1 = 1) (H1);
128 we proceed by cases on (H1) to prove (1 - (min (v n) 1)= min (if eqb (min (v n) 1) 0 then 1 else 0) 1).
136 (min (if eqb (min (v n) 1) O then 1 else O) 1)
137 = (min (if eqb 0 0 then 1 else O) 1) by H.
148 (min (if eqb (min (v n) 1) O then 1 else O) 1)
149 = (min (if eqb 1 0 then 1 else O) 1) by H.
155 by induction hypothesis we know
156 ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
158 by induction hypothesis we know
159 ([[ negate f1 ]]_v=[[ f1 ]]_(invert v)) (H1).
161 ([[ negate (FAnd f f1) ]]_v=[[ FAnd f f1 ]]_(invert v)).
163 (min [[ negate f ]]_v [[ negate f1]]_v = [[ FAnd f f1 ]]_(invert v)).
165 (min [[ negate f ]]_v [[ negate f1]]_v)
166 = (min [[ f ]]_(invert v) [[ negate f1]]_v) by H.
167 = (min [[ f ]]_(invert v) [[ f1]]_(invert v)) by H1.
171 by induction hypothesis we know
172 ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
174 by induction hypothesis we know
175 ([[ negate f1 ]]_v=[[ f1 ]]_(invert v)) (H1).
177 ([[ negate (FOr f f1) ]]_v=[[ FOr f f1 ]]_(invert v)).
179 (max [[ negate f ]]_v [[ negate f1]]_v = [[ FOr f f1 ]]_(invert v)).
181 (max [[ negate f ]]_v [[ negate f1]]_v)
182 = (max [[ f ]]_(invert v) [[ negate f1]]_v) by H.
183 = (max [[ f ]]_(invert v) [[ f1]]_(invert v)) by H1.
187 by induction hypothesis we know
188 ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
190 by induction hypothesis we know
191 ([[ negate f1 ]]_v=[[ f1 ]]_(invert v)) (H1).
193 ([[ negate (FImpl f f1) ]]_v=[[ FImpl f f1 ]]_(invert v)).
195 (max (1 - [[ negate f ]]_v) [[ negate f1]]_v = [[ FImpl f f1 ]]_(invert v)).
197 (max (1 - [[ negate f ]]_v) [[ negate f1]]_v)
198 = (max (1 - [[ f ]]_(invert v)) [[ negate f1]]_v) by H.
199 = (max (1 - [[ f ]]_(invert v)) [[ f1]]_(invert v)) by H1.
203 by induction hypothesis we know
204 ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
206 ([[ negate (FNot f) ]]_v=[[ FNot f ]]_(invert v)).
208 (1 - [[ negate f ]]_v=[[ FNot f ]]_(invert v)).
209 conclude (1 - [[ negate f ]]_v) = (1 - [[f]]_(invert v)) by H.
214 lemma negate_fun : ∀F,G. F ≡ G → negate F ≡ negate G.
215 intros; intro v; rewrite > (negate_invert ? v);rewrite > (negate_invert ? v);
221 ∀F:Formula.∀G:Formula.F ≡ G→negate F ≡ negate G.
225 the thesis becomes (negate F ≡ negate G).
226 the thesis becomes (∀v:ℕ→ℕ.[[ negate F ]]_v=[[ negate G ]]_v).
230 = [[ F ]]_(invert v) by negate_invert.
231 = [[ G ]]_(invert v) by H.
232 = [[ negate G ]]_v by negate_invert.
236 lemma not_dualize_eq_negate : ∀F. FNot (dualize F) ≡ negate F.
237 intros; intro; elim F; intros; try reflexivity;
238 [1,2: simplify in ⊢ (? ? ? %); rewrite <(H); rewrite <(H1);
239 [rewrite < (min_max (dualize f) (dualize f1) v); reflexivity;
240 |rewrite < (max_min (dualize f) (dualize f1) v); reflexivity;]
241 |3: change in ⊢ (? ? ? %) with [[FImpl (negate f) (negate f1)]]_v;
242 change in ⊢ (? ? ? %) with (max (1 - [[negate f]]_v) [[negate f1]]_v);
243 rewrite <H1; rewrite <H;
244 rewrite > (max_min (FNot (dualize f)) ((dualize f1)) v);reflexivity;
245 |4: simplify; rewrite < H; reflexivity;]
249 theorem not_dualize_eq_negate:
250 ∀F:Formula.negate F ≡ FNot (dualize F).
252 the thesis becomes (∀v:ℕ→ℕ.[[negate F]]_v=[[FNot (dualize F)]]_v).
254 we proceed by induction on F to prove ([[negate F]]_v=[[FNot (dualize F)]]_v).
256 the thesis becomes ([[ negate FBot ]]_v=[[ FNot (dualize FBot) ]]_v).
259 the thesis becomes ([[ negate FTop ]]_v=[[ FNot (dualize FTop) ]]_v).
263 the thesis becomes ([[ negate (FAtom n) ]]_v=[[ FNot (dualize (FAtom n)) ]]_v).
267 by induction hypothesis we know
268 ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
270 by induction hypothesis we know
271 ([[ negate f1 ]]_v=[[ FNot (dualize f1) ]]_v) (H1).
273 ([[ negate (FAnd f f1) ]]_v=[[ FNot (dualize (FAnd f f1)) ]]_v).
275 (min [[ negate f ]]_v [[ negate f1 ]]_v=[[ FNot (dualize (FAnd f f1)) ]]_v).
277 (min [[ negate f ]]_v [[ negate f1 ]]_v)
278 = (min [[ FNot (dualize f) ]]_v [[ negate f1 ]]_v) by H.
279 = (min [[ FNot (dualize f) ]]_v [[ FNot (dualize f1) ]]_v) by H1.
280 = (min (1 - [[ dualize f ]]_v) (1 - [[ dualize f1 ]]_v)).
281 = (1 - (max [[ dualize f ]]_v [[ dualize f1 ]]_v)) by min_max.
285 by induction hypothesis we know
286 ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
288 by induction hypothesis we know
289 ([[ negate f1 ]]_v=[[ FNot (dualize f1) ]]_v) (H1).
291 ([[ negate (FOr f f1) ]]_v=[[ FNot (dualize (FOr f f1)) ]]_v).
293 (max [[ negate f ]]_v [[ negate f1 ]]_v=[[ FNot (dualize (FOr f f1)) ]]_v).
295 (max [[ negate f ]]_v [[ negate f1 ]]_v)
296 = (max [[ FNot (dualize f) ]]_v [[ negate f1 ]]_v) by H.
297 = (max [[ FNot (dualize f) ]]_v [[ FNot (dualize f1) ]]_v) by H1.
298 = (max (1 - [[ dualize f ]]_v) (1 - [[ dualize f1 ]]_v)).
299 = (1 - (min [[ dualize f ]]_v [[ dualize f1 ]]_v)) by max_min.
303 by induction hypothesis we know
304 ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
306 by induction hypothesis we know
307 ([[ negate f1 ]]_v=[[ FNot (dualize f1) ]]_v) (H1).
309 ([[ negate (FImpl f f1) ]]_v=[[ FNot (dualize (FImpl f f1)) ]]_v).
311 (max (1 - [[ negate f ]]_v) [[ negate f1 ]]_v=[[ FNot (dualize (FImpl f f1)) ]]_v).
313 (max (1-[[ negate f ]]_v) [[ negate f1 ]]_v)
314 = (max (1-[[ FNot (dualize f) ]]_v) [[ negate f1 ]]_v) by H.
315 = (max (1-[[ FNot (dualize f) ]]_v) [[ FNot (dualize f1) ]]_v) by H1.
316 = (max (1 - [[ FNot (dualize f) ]]_v) (1 - [[ dualize f1 ]]_v)).
317 = (1 - (min [[ FNot (dualize f) ]]_v [[ dualize f1 ]]_v)) by max_min.
321 by induction hypothesis we know
322 ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
324 ([[ negate (FNot f) ]]_v=[[ FNot (dualize (FNot f)) ]]_v).
326 (1 - [[ negate f ]]_v=[[ FNot (dualize (FNot f)) ]]_v).
327 conclude (1 - [[ negate f ]]_v) = (1 - [[ FNot (dualize f) ]]_v) by H.
333 lemma not_inj : ∀F,G. FNot F ≡ FNot G → F ≡ G.
334 intros; intro v;lapply (H v) as K;
335 change in K with (1 - [[ F ]]_v = 1 - [[ G ]]_v);
336 cases (sem_bool F v);cases (sem_bool G v); rewrite > H1; rewrite > H2;
337 try reflexivity; rewrite > H1 in K; rewrite > H2 in K; simplify in K;
338 symmetry; assumption;
343 ∀F:Formula.∀G:Formula.FNot F ≡ FNot G→F ≡ G.
346 suppose (FNot F ≡ FNot G) (H).
347 the thesis becomes (F ≡ G).
348 the thesis becomes (∀v:ℕ→ℕ.[[ F ]]_v=[[ G ]]_v).
350 by H we proved ([[ FNot F ]]_v=[[ FNot G ]]_v) (H1).
351 by sem_bool we proved ([[ F ]]_v=O∨[[ F ]]_v=1) (H2).
352 by sem_bool we proved ([[ G ]]_v=O∨[[ G ]]_v=1) (H3).
353 we proceed by cases on H2 to prove ([[ F ]]_v=[[ G ]]_v).
355 we proceed by cases on H3 to prove ([[ F ]]_v=[[ G ]]_v).
363 = (1 - [[G]]_v) by H5.
365 = [[ FNot F ]]_v by H1.
371 we proceed by cases on H3 to prove ([[ F ]]_v=[[ G ]]_v).
377 = (1 - [[G]]_v) by H5.
379 = [[ FNot F ]]_v by H1.
389 theorem duality: ∀F1,F2. F1 ≡ F2 → dualize F1 ≡ dualize F2.
390 intros; apply not_inj; intro v; rewrite > (not_dualize_eq_negate ? v);
391 rewrite > (not_dualize_eq_negate ? v); apply (negate_fun ??? v); apply H;
398 ∀F1:Formula.∀F2:Formula.F1 ≡ F2→dualize F1 ≡ dualize F2.
401 suppose (F1 ≡ F2) (H).
402 the thesis becomes (dualize F1 ≡ dualize F2).
403 by negate_fun we proved (negate F1 ≡ negate F2) (H1).
404 by not_dualize_eq_negate, equiv_rewrite we proved (FNot (dualize F1) ≡ negate F2) (H2).
405 by not_dualize_eq_negate, equiv_rewrite we proved (FNot (dualize F1) ≡ FNot (dualize F2)) (H3).
406 by not_inj we proved (dualize F1 ≡ dualize F2) (H4).