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