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