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