]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/didactic/duality.ma
7fe9082e154ef754a4f01a9a9488df5a4468e7e1
[helm.git] / helm / software / matita / contribs / didactic / duality.ma
1 (* Esercitazione di logica 29/10/2008. *)
2
3 (* Esercizio 0
4    ===========
5
6    Compilare i seguenti campi:
7
8    Nome1: ...
9    Cognome1: ...
10    Matricola1: ...
11    Account1: ...
12
13    Nome2: ...
14    Cognome2: ...
15    Matricola2: ...
16    Account2: ...
17
18    Prima di abbandonare la postazione:
19
20    * salvare il file (menu `File ▹ Save as ...`) nella directory (cartella)
21      /public/ con nome linguaggi_Account1.ma, ad esempio Mario Rossi, il cui
22      account è mrossi, deve salvare il file in /public/linguaggi_mrossi.ma
23
24    * mandatevi via email o stampate il file. Per stampare potete usare
25      usare l'editor gedit che offre la funzionalità di stampa
26 *)
27
28 (*DOCBEGIN
29
30 Il teorema di dualità
31 =====================
32
33 Il teorema di dualizzazione dice che date due formule `F1` ed `F2`,
34 se le due formule sono equivalenti (`F1 ≡ F2`) allora anche le 
35 loro dualizzate lo sono (`dualize F1 ≡ dualize F2`).
36
37 L'ingrediente principale è la funzione di dualizzazione di una formula `F`:
38    
39    * Scambia FTop con FBot e viceversa
40    
41    * Scambia il connettivo FAnd con FOr e viceversa
42    
43    * Sostituisce il connettivo FImpl con FAnd e nega la
44      prima sottoformula.
45    
46    Ad esempio la formula `A → (B ∧ ⊥)` viene dualizzata in
47    `¬A ∧ (B ∨ ⊤)`.
48
49 Per dimostrare il teorema di dualizzazione in modo agevole è necessario
50 definire altre nozioni:
51
52 * La funzione `negate` che presa una formula `F` ne nega gli atomi.
53   Ad esempio la formula `(A ∨ (⊤ → B))` deve diventare `¬A ∨ (⊤ → ¬B)`.
54    
55 * La funzione `invert` permette di invertire un mondo `v`.
56   Ovvero, per ogni indice di atomo `i`, se `v i` restituisce
57   `1` allora `(invert v) i` restituisce `0` e viceversa.
58    
59 DOCEND*)
60
61 (* ATTENZIONE
62    ==========
63    
64    Non modificare quanto segue 
65 *)
66 include "nat/minus.ma".
67 definition if_then_else ≝ λT:Type.λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
68 notation > "'if' term 19 e 'then' term 19 t 'else' term 90 f" non associative with precedence 19 for @{ 'if_then_else $e $t $f }.
69 notation < "'if' \nbsp term 19 e \nbsp 'then' \nbsp term 19 t \nbsp 'else' \nbsp term 90 f \nbsp" non associative with precedence 19 for @{ 'if_then_else $e $t $f }.
70 interpretation "Formula if_then_else" 'if_then_else e t f = (if_then_else _ e t f).
71 definition max ≝ λn,m. if eqb (n - m) 0 then m else n. 
72 definition min ≝ λn,m. if eqb (n - m) 0 then n else m. 
73
74 (* Ripasso
75    =======
76    
77    Il linguaggio delle formule, dove gli atomi sono
78    rapperesentati da un numero naturale
79 *)
80 inductive Formula : Type ≝
81 | FBot: Formula
82 | FTop: Formula
83 | FAtom: nat → Formula
84 | FAnd: Formula → Formula → Formula
85 | FOr: Formula → Formula → Formula
86 | FImpl: Formula → Formula → Formula
87 | FNot: Formula → Formula
88 .
89
90 (* Esercizio 1
91    ===========
92    
93    Modificare la funzione `sem` scritta nella precedente
94    esercitazione in modo che valga solo 0 oppure 1 nel caso degli
95    atomi, anche nel caso il mondo `v` restituisca un numero
96    maggiore di 1.
97    
98    Suggerimento: non è necessario usare il costrutto if_then_else
99    e tantomento il predicato di maggiore o uguale.
100 *) 
101 let rec sem (v: nat → nat) (F: Formula) on F : nat ≝
102  match F with
103   [ FBot ⇒ 0
104   | FTop ⇒ 1
105   | FAtom n ⇒ (*BEGIN*)min (v n) 1(*END*)
106   | FAnd F1 F2 ⇒ min (sem v F1) (sem v F2)
107   | FOr F1 F2 ⇒ max (sem v F1) (sem v F2)
108   | FImpl F1 F2 ⇒ max (1 - sem v F1) (sem v F2)
109   | FNot F1 ⇒ 1 - (sem v F1)
110   ]
111 .
112
113 (* ATTENZIONE
114    ==========
115    
116    Non modificare quanto segue.
117 *)
118 notation < "[[ \nbsp term 19 a \nbsp ]] \nbsp \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }.
119 notation > "[[ term 19 a ]] \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }.
120 notation > "[[ term 19 a ]]_ term 90 v" non associative with precedence 90 for @{ sem $v $a }.
121 interpretation "Semantic of Formula" 'semantics v a = (sem v a).
122
123 definition v20 ≝ λx.
124        if eqb x 0 then 2
125   else if eqb x 1 then 1
126   else                 0.
127   
128 (* Test 1
129    ======
130    
131    La semantica della formula `(A ∨ C)` nel mondo `v20` in cui 
132    `A` vale `2` e `C` vale `0` deve valere `1`.
133    
134 *)    
135 eval normalize on [[For (FAtom 0) (FAtom 2)]]_v20. 
136
137 (*DOCBEGIN
138
139 La libreria di Matita
140 =====================
141
142 Gli strumenti per la dimostrazione assistita sono corredati da
143 librerie di teoremi già dimostrati. Per portare a termine l'esercitazione
144 sono necessari i seguenti lemmi:
145
146 * lemma `sem_bool` : `∀F,v. [[ F ]]_v = 0 ∨ [[ F ]]_v = 1`
147 * lemma `min_bool` : `∀n. min n 1 = 0 ∨ min n 1 = 1`
148 * lemma `min_max` : `∀F,G,v.min (1 - [[F]]_v) (1 - [[G]]_v) = 1 - max [[F]]_v [[G]]_v`
149 * lemma `max_min` : `∀F,G,v.max (1 - [[F]]_v) (1 - [[G]]_v) = 1 - min [[F]]_v [[G]]_v`
150 * lemma `equiv_rewrite` : `∀F1,F2,F3. F1 ≡ F2 → F1 ≡ F3 → F2 ≡ F3`
151
152 DOCEND*)
153
154 (* ATTENZIONE
155    ==========
156    
157    Non modificare quanto segue.
158 *)
159 lemma sem_bool : ∀F,v. [[ F ]]_v = 0 ∨ [[ F ]]_v = 1.  intros; elim F; simplify; [left;reflexivity; |right;reflexivity; |cases (v n);[left;|cases n1;right;]reflexivity; |4,5,6: cases H; cases H1; rewrite > H2; rewrite > H3; simplify; first [ left;reflexivity | right; reflexivity ].  |cases H; rewrite > H1; simplify;[right|left]reflexivity;] qed.
160 lemma min_bool : ∀n. min n 1 = 0 ∨ min n 1 = 1.  intros; cases n; [left;reflexivity] cases n1; right; reflexivity; qed.  
161 lemma min_max : ∀F,G,v.  min (1 - [[F]]_v) (1 - [[G]]_v) = 1 - max [[F]]_v [[G]]_v.  intros; cases (sem_bool F v);cases (sem_bool G v); rewrite > H; rewrite >H1; simplify; reflexivity; qed.
162 lemma max_min : ∀F,G,v.  max (1 - [[F]]_v) (1 - [[G]]_v) = 1 - min [[F]]_v [[G]]_v.  intros; cases (sem_bool F v);cases (sem_bool G v); rewrite > H; rewrite >H1; simplify; reflexivity; qed.
163
164 (* Esercizio 2
165    ===========
166    
167    Definire per ricorsione strutturale la funzione `negate`
168    che presa una formula `F` ne nega gli atomi.
169    
170    Ad esempio la formula `(A ∨ (⊤ → B))` deve diventare
171    `¬A ∨ (⊤ → ¬B)`.
172 *)
173 let rec negate (F: Formula) on F : Formula ≝
174  match F with
175   [ (*BEGIN*)FBot ⇒ FBot
176   | FTop ⇒ FTop
177   | FAtom n ⇒ FNot (FAtom n)
178   | FAnd F1 F2 ⇒ FAnd (negate F1) (negate F2)
179   | FOr F1 F2 ⇒ FOr (negate F1) (negate F2)
180   | FImpl F1 F2 ⇒ FImpl (negate F1) (negate F2)
181   | FNot F ⇒ FNot (negate F)(*END*)
182   ].
183
184 (* Test 2
185    ======
186   
187    Testare la funzione `negate`. Il risultato atteso è:
188    
189        FOr (FNot (FAtom O)) (FImpl FTop (FNot (FAtom 1))) 
190 *)
191
192 eval normalize on (negate (FOr (FAtom 0) (FImpl FTop (FAtom 1)))).
193
194 (* ATTENZIONE
195    ==========
196    
197    Non modificare quanto segue
198 *)
199 definition equiv ≝ λF1,F2. ∀v.[[ F1 ]]_v = [[ F2 ]]_v.
200 notation "hvbox(a \nbsp break mstyle color #0000ff (≡) \nbsp b)"  non associative with precedence 45 for @{ 'equivF $a $b }.
201 notation > "a ≡ b" non associative with precedence 50 for @{ equiv $a $b }.
202 interpretation "equivalence for Formulas" 'equivF a b = (equiv a b).
203 lemma equiv_rewrite : ∀F1,F2,F3. F1 ≡ F2 → F1 ≡ F3 → F2 ≡ F3. intros; intro; autobatch. qed.
204
205 (* Esercizio 3
206    ===========
207    
208    Definire per ricorsione strutturale la funzione di
209    dualizzazione di una formula `F`. Tale funzione:
210    
211    * Scambia FTop con FBot e viceversa
212    
213    * Scambia il connettivo FAnd con FOr e viceversa
214    
215    * Sostituisce il connettivo FImpl con FAnd e nega la
216      prima sottoformula.
217    
218    Ad esempio la formula `A → (B ∧ ⊥)` viene dualizzata in
219    `¬A ∧ (B ∨ ⊤)`. 
220 *)  
221 let rec dualize (F : Formula) on F : Formula ≝
222   match F with
223   [ (*BEGIN*)FBot ⇒ FTop
224   | FTop ⇒ FBot
225   | FAtom n ⇒ FAtom n
226   | FAnd F1 F2 ⇒ FOr (dualize F1) (dualize F2)
227   | FOr F1 F2 ⇒ FAnd (dualize F1) (dualize F2)
228   | FImpl F1 F2 ⇒ FAnd (FNot (dualize F1)) (dualize F2)
229   | FNot F ⇒ FNot (dualize F)(*END*)
230   ].
231
232 (* Test 3
233    ======
234    
235    Testare la funzione `dualize`. Il risultato atteso è:
236    
237        FAnd (FNot (FAtom O)) (FOr (FAtom 1) FTop) 
238 *)
239
240 eval normalize on (dualize (FImpl (FAtom 0) (FAnd (FAtom 1) FBot))).
241
242 (* Spiegazione
243    ===========
244    
245    La funzione `invert` permette di invertire un mondo `v`.
246    Ovvero, per ogni indice di atomo `i`, se `v i` restituisce
247    `1` allora `(invert v) i` restituisce `0` e viceversa.
248    
249 *)
250 definition invert ≝
251  λv:ℕ -> ℕ. λx. if eqb (min (v x) 1) 0 then 1 else 0.
252  
253 interpretation "Inversione del mondo" 'invert v = (invert v).
254  
255 (*DOCBEGIN
256
257 Il linguaggio di dimostrazione di Matita
258 ========================================
259
260 Per dimostrare il lemma `negate_invert` in modo agevole è necessario 
261 utilizzare il seguente comando:
262
263 * `symmetry` 
264
265   Quando la conclusuine è `a = b` permette di cambiarla in `b = a`.
266   
267 * by H1, H2 we proved P (H)
268
269   Il comando `by ... we proved` visto nella scorsa esercitazione
270   permette di utilizzare più ipotesi o lemmi alla volta
271   separandoli con una virgola.
272
273 DOCEND*)
274
275 (* Esercizio 4
276    ===========
277    
278    Dimostrare il lemma `negate_invert` che asserisce che
279    la semantica in un mondo `v` associato alla formula
280    negata di `F` e uguale alla semantica associata
281    a `F` in un mondo invertito.
282 *) 
283 lemma negate_invert:
284   ∀F:Formula.∀v:ℕ→ℕ.[[ negate F ]]_v=[[ F ]]_(invert v).
285 assume F:Formula.
286 assume v:(ℕ→ℕ).
287 we proceed by induction on F to prove ([[ negate F ]]_v=[[ F ]]_(invert v)).
288   case FBot.
289     (*BEGIN*)
290     the thesis becomes ([[ negate FBot ]]_v=[[ FBot ]]_(invert v)).
291     (*END*)
292   done.
293   case FTop.
294     (*BEGIN*)
295     the thesis becomes ([[ negate FTop ]]_v=[[ FTop ]]_(invert v)).
296     (*END*)
297   done.
298   case FAtom.
299     assume n : ℕ.
300     the thesis becomes ([[ negate (FAtom n) ]]_v=[[ FAtom n ]]_(invert v)).
301     the thesis becomes (1 - (min (v n) 1)= min (invert v n) 1).
302     the thesis becomes (1 - (min (v n) 1)= min (if eqb (min (v n) 1) 0 then 1 else 0) 1).
303     by min_bool we proved ((*BEGIN*)min (v n) 1 = 0 ∨ min (v n) 1 = 1(*END*)) (H1);
304     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).
305       case Left.
306         conclude 
307             (1 - (min (v n) 1)) 
308           = (1 - 0) by H.
309           = 1.
310         symmetry.
311         conclude 
312             (min (if eqb (min (v n) 1) O then 1 else O) 1)
313           = (min (if eqb 0 0 then 1 else O) 1) by H.
314           = (min 1 1).
315           = 1.
316       done.
317       case Right.
318         (*BEGIN*)
319         conclude 
320             (1 - (min (v n) 1)) 
321           = (1 - 1) by H.
322           = 0.
323         symmetry.
324         conclude 
325             (min (if eqb (min (v n) 1) O then 1 else O) 1)
326           = (min (if eqb 1 0 then 1 else O) 1) by H.
327           = (min 0 1).
328           = 0.
329         (*END*)
330       done.
331   case FAnd.
332     assume f : Formula.
333     by induction hypothesis we know
334       ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
335     assume f1 : Formula.
336     by induction hypothesis we know
337      ([[ negate f1 ]]_v=[[ f1 ]]_(invert v)) (H1).
338     the thesis becomes
339      ([[ negate (FAnd f f1) ]]_v=[[ FAnd f f1 ]]_(invert v)).
340     the thesis becomes
341      (min [[ negate f ]]_v [[ negate f1]]_v = [[ FAnd f f1 ]]_(invert v)).
342     conclude 
343         (min [[ negate f ]]_v [[ negate f1]]_v)
344       = (min [[ f ]]_(invert v) [[ negate f1]]_v) by H.
345       = (min [[ f ]]_(invert v) [[ f1]]_(invert v)) by (*BEGIN*)H1(*END*).
346   done.
347   case FOr.
348     (*BEGIN*)
349     assume f : Formula.
350     by induction hypothesis we know
351       ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
352     assume f1 : Formula.
353     by induction hypothesis we know
354      ([[ negate f1 ]]_v=[[ f1 ]]_(invert v)) (H1).
355     the thesis becomes
356      ([[ negate (FOr f f1) ]]_v=[[ FOr f f1 ]]_(invert v)).
357     the thesis becomes
358      (max [[ negate f ]]_v [[ negate f1]]_v = [[ FOr f f1 ]]_(invert v)).
359     conclude 
360         (max [[ negate f ]]_v [[ negate f1]]_v)
361       = (max [[ f ]]_(invert v) [[ negate f1]]_v) by H.
362       = (max [[ f ]]_(invert v) [[ f1]]_(invert v)) by H1.
363     (*END*)
364   done.
365   case FImpl.
366     (*BEGIN*)
367     assume f : Formula.
368     by induction hypothesis we know
369       ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
370     assume f1 : Formula.
371     by induction hypothesis we know
372      ([[ negate f1 ]]_v=[[ f1 ]]_(invert v)) (H1).
373     the thesis becomes
374      ([[ negate (FImpl f f1) ]]_v=[[ FImpl f f1 ]]_(invert v)).
375     the thesis becomes
376      (max (1 - [[ negate f ]]_v) [[ negate f1]]_v = [[ FImpl f f1 ]]_(invert v)).
377     conclude 
378         (max (1 - [[ negate f ]]_v) [[ negate f1]]_v)
379       = (max (1 - [[ f ]]_(invert v)) [[ negate f1]]_v) by H.
380       = (max (1 - [[ f ]]_(invert v)) [[ f1]]_(invert v)) by H1.
381     (*END*)
382   done.
383   case FNot.
384     (*BEGIN*)
385     assume f : Formula.
386     by induction hypothesis we know
387       ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
388     the thesis becomes
389       ([[ negate (FNot f) ]]_v=[[ FNot f ]]_(invert v)).
390     the thesis becomes
391       (1 - [[ negate f ]]_v=[[ FNot f ]]_(invert v)).
392     conclude (1 - [[ negate f ]]_v) = (1 - [[f]]_(invert v)) by H.
393     (*END*)
394   done.  
395 qed.   
396
397 (* Esercizio 5
398    ===========
399    
400    Dimostrare che la funzione negate rispetta l'equivalenza.
401 *)
402 lemma negate_fun:
403  ∀F:Formula.∀G:Formula.F ≡ G→negate F ≡ negate G.
404  (*BEGIN*)
405  assume F:Formula.
406  assume G:Formula.
407  suppose (F ≡ G) (H).
408  the thesis becomes (negate F ≡ negate G).
409  the thesis becomes (∀v:ℕ→ℕ.[[ negate F ]]_v=[[ negate G ]]_v).
410  (*END*)
411  assume v:(ℕ→ℕ).
412  conclude 
413      [[ negate F ]]_v
414    = [[ F ]]_(invert v) by negate_invert.
415    = [[ G ]]_((*BEGIN*)invert v(*BEGIN*)) by (*BEGIN*)H(*BEGIN*).
416    = [[ negate G ]]_(*BEGIN*)v(*BEGIN*) by (*BEGIN*)negate_invert(*END*).
417  done.  
418 qed.
419
420 (* Esercizio 6
421    ===========
422    
423    Dimostrare che per ogni formula `F`, `(negae F)` equivale a 
424    dualizzarla e negarla.
425 *)
426 lemma not_dualize_eq_negate:
427  ∀F:Formula.negate F ≡ FNot (dualize F).
428  (*BEGIN*)
429  assume F:Formula.
430  the thesis becomes (∀v:ℕ→ℕ.[[negate F]]_v=[[FNot (dualize F)]]_v).
431  (*END*)
432  assume v:(ℕ→ℕ).
433  we proceed by induction on F to prove ([[negate F]]_v=[[FNot (dualize F)]]_v).
434  case FBot.
435    (*BEGIN*)
436    the thesis becomes ([[ negate FBot ]]_v=[[ FNot (dualize FBot) ]]_v).
437    (*END*)
438  done.
439  case FTop.
440    (*BEGIN*)
441    the thesis becomes ([[ negate FTop ]]_v=[[ FNot (dualize FTop) ]]_v).
442    (*END*)
443  done.
444  case FAtom.
445    (*BEGIN*)
446    assume n : ℕ.
447    the thesis becomes ([[ negate (FAtom n) ]]_v=[[ FNot (dualize (FAtom n)) ]]_v).
448    (*END*)
449  done.
450  case FAnd.
451    assume f : Formula.
452    by induction hypothesis we know
453      ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
454    assume f1 : Formula.
455    by induction hypothesis we know
456     ([[ negate f1 ]]_v=[[ FNot (dualize f1) ]]_v) (H1).
457    the thesis becomes
458     ([[ negate (FAnd f f1) ]]_v=[[ FNot (dualize (FAnd f f1)) ]]_v).
459    the thesis becomes
460     (min [[ negate f ]]_v [[ negate f1 ]]_v=[[ FNot (dualize (FAnd f f1)) ]]_v).
461    conclude 
462        (min [[ negate f ]]_v [[ negate f1 ]]_v)
463      = (min [[ FNot (dualize f) ]]_v [[ negate f1 ]]_v) by H.    
464      = (min [[ FNot (dualize f) ]]_v [[ FNot (dualize f1) ]]_v) by H1.
465      = (min (1 - [[ dualize f ]]_v) (1 - [[ dualize f1 ]]_v)).
466      = (1 - (max [[ dualize f ]]_v [[ dualize f1 ]]_v)) by min_max.
467  done.
468  case FOr.
469    (*BEGIN*)
470    assume f : Formula.
471    by induction hypothesis we know
472      ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
473    assume f1 : Formula.
474    by induction hypothesis we know
475     ([[ negate f1 ]]_v=[[ FNot (dualize f1) ]]_v) (H1).
476    the thesis becomes
477     ([[ negate (FOr f f1) ]]_v=[[ FNot (dualize (FOr f f1)) ]]_v).
478    the thesis becomes
479     (max [[ negate f ]]_v [[ negate f1 ]]_v=[[ FNot (dualize (FOr f f1)) ]]_v).
480    conclude 
481        (max [[ negate f ]]_v [[ negate f1 ]]_v)
482      = (max [[ FNot (dualize f) ]]_v [[ negate f1 ]]_v) by H.    
483      = (max [[ FNot (dualize f) ]]_v [[ FNot (dualize f1) ]]_v) by H1.
484      = (max (1 - [[ dualize f ]]_v) (1 - [[ dualize f1 ]]_v)).
485      = (1 - (min [[ dualize f ]]_v [[ dualize f1 ]]_v)) by max_min.
486    (*END*)
487  done.
488  case FImpl.
489    (*BEGIN*)
490    assume f : Formula.
491    by induction hypothesis we know
492      ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
493    assume f1 : Formula.
494    by induction hypothesis we know
495     ([[ negate f1 ]]_v=[[ FNot (dualize f1) ]]_v) (H1).
496    the thesis becomes
497     ([[ negate (FImpl f f1) ]]_v=[[ FNot (dualize (FImpl f f1)) ]]_v).
498    the thesis becomes
499     (max (1 - [[ negate f ]]_v) [[ negate f1 ]]_v=[[ FNot (dualize (FImpl f f1)) ]]_v).
500    conclude 
501        (max (1-[[ negate f ]]_v) [[ negate f1 ]]_v)
502      = (max (1-[[ FNot (dualize f) ]]_v) [[ negate f1 ]]_v) by H.    
503      = (max (1-[[ FNot (dualize f) ]]_v) [[ FNot (dualize f1) ]]_v) by H1.
504      = (max (1 - [[ FNot (dualize f) ]]_v) (1 - [[ dualize f1 ]]_v)).
505      = (1 - (min [[ FNot (dualize f) ]]_v [[ dualize f1 ]]_v)) by max_min.
506    (*END*)
507  done.
508  case FNot.
509    (*BEGIN*) 
510    assume f : Formula.
511    by induction hypothesis we know
512      ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
513    the thesis becomes
514       ([[ negate (FNot f) ]]_v=[[ FNot (dualize (FNot f)) ]]_v).
515    the thesis becomes
516       (1 - [[ negate f ]]_v=[[ FNot (dualize (FNot f)) ]]_v).
517    conclude (1 - [[ negate f ]]_v) = (1 - [[ FNot (dualize f) ]]_v) by H.
518    (*END*)
519  done.
520 qed.
521
522 (* Esercizio 7
523    ===========
524    
525    Dimostrare che la negazione è iniettiva
526 *)
527 theorem not_inj:
528  ∀F,G:Formula.FNot F ≡ FNot G→F ≡ G.
529  (*BEGIN*)
530  assume F:Formula.
531  assume G:Formula.
532  suppose (FNot F ≡ FNot G) (H).
533  the thesis becomes (F ≡ G).
534  the thesis becomes (∀v:ℕ→ℕ.[[ F ]]_v=[[ G ]]_v).
535  (*END*)
536  assume v:(ℕ→ℕ).
537  by H we proved ([[ FNot F ]]_v=[[ FNot G ]]_v) (H1).
538  by sem_bool we proved ([[ F ]]_v=O ∨ [[ F ]]_v=1) (H2).
539  by (*BEGIN*)sem_bool(*END*) we proved ([[ G ]]_v=(*BEGIN*)O ∨ [[ G ]]_v=1(*END*)) (H3).
540  we proceed by cases on H2 to prove ([[ F ]]_v=[[ G ]]_v).
541  case Left.
542    we proceed by cases on H3 to prove ([[ F ]]_v=[[ G ]]_v).
543    case Left.
544    done.
545    case Right.
546      conclude 
547          ([[ F ]]_v)
548        = 0 by H4;
549        = (1 - 1).
550        = (1 - [[G]]_v) by H5.
551        = [[ FNot G ]]_v.
552        = [[ FNot F ]]_v by H1.
553        = (1 - [[F]]_v).
554        = (1 - 0) by H4.
555        = 1.
556      done.
557  case Right.
558    (*BEGIN*)
559    we proceed by cases on H3 to prove ([[ F ]]_v=[[ G ]]_v).
560    case Left.
561      conclude 
562          ([[ F ]]_v)
563        = 1 by H4;
564        = (1 - 0).
565        = (1 - [[G]]_v) by H5.
566        = [[ FNot G ]]_v.
567        = [[ FNot F ]]_v by H1.
568        = (1 - [[F]]_v).
569        = (1 - 1) by H4.
570        = 0.
571      done.
572    case Right.
573    (*END*)
574      done.
575 qed.
576
577 (*DOCBEGIN
578
579 La prova del teorema di dualità
580 ===============================
581
582 Il teorema di dualità accennato a lezione dice che se due formule 
583 `F1` ed `F2` sono equivalenti, allora anche le formule duali lo sono.
584         
585     ∀F1,F2:Formula. F1 ≡ F2 → dualize F1 ≡ dualize F2.
586         
587 Per dimostrare tale teorema è bene suddividere la prova in lemmi intermedi
588
589 1. lemma `negate_invert`, dimostrato per induzione su F, utilizzando
590    `min_bool`
591    
592         ∀F:Formula.∀v:ℕ→ℕ.[[ negate F ]]_v=[[ F ]]_(invert v).
593
594 2. lemma `negate_fun`, conseguenza di `negate_invert`
595
596         ∀F,G:Formula. F ≡ G → negate F ≡ negate G.
597         
598 2. lemma `not_dualize_eq_negate`, dimostrato per induzione su F,
599    utilizzando `max_min` e `min_max`
600
601         ∀F:Formula. negate F ≡ FNot (dualize F)
602         
603 4. lemma `not_inj`, conseguenza di `sem_bool`
604  
605         ∀F,G:Formula. FNot F ≡ FNot G → F ≡ G
606
607 Una volta dimostrati tali lemmi la prova del teorema di dualità 
608 procede come di seguito:
609
610 1. Assume l'ipotesi  
611
612         F1 ≡ F2
613
614 2. Utilizza `negate_fun` per ottenere 
615
616         negate F1 ≡ negate F2
617
618 3. Utilizzando due volte il lemma `not_dualize_eq_negate` e il lemma
619    `equiv_rewrite` ottiene 
620
621         FNot (dualize F1) ≡ FNot (dualize F2)
622
623 4. Conclude utilizzando il lemma `not_inj` per ottenere la tesi 
624
625         dualize F1 ≡ dualize F2
626
627 DOCEND*)
628
629 (* Esercizio 8
630    ===========
631    
632    Dimostrare il teorema di dualità
633 *)
634 theorem duality: ∀F1,F2:Formula.F1 ≡ F2 → dualize F1 ≡ dualize F2.
635  assume F1:Formula.
636  assume F2:Formula.
637  suppose (F1 ≡ F2) (H).
638  the thesis becomes (dualize F1 ≡ dualize F2).
639  by (*BEGIN*)negate_fun(*END*) we proved (negate F1 ≡ negate F2) (H1).
640  by (*BEGIN*)not_dualize_eq_negate(*END*), (*BEGIN*)equiv_rewrite(*END*), H1 we proved (FNot (dualize F1) ≡ negate F2) (H2).
641  by (*BEGIN*)not_dualize_eq_negate(*END*), (*BEGIN*)equiv_rewrite(*END*), H2 we proved (FNot (dualize F1) ≡ FNot (dualize F2)) (H3).
642  by (*BEGIN*)not_inj(*END*), H3 we proved (dualize F1 ≡ dualize F2) (H4).
643  done.
644 qed.