]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/didactic/exercises/duality.ma
- init_cache_and_tables rewritten using the automation_cache
[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
168 DOCEND*)
169
170 (* ATTENZIONE
171    ==========
172    
173    Non modificare quanto segue.
174 *)
175 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.
176 lemma min_bool : ∀n. min n 1 = 0 ∨ min n 1 = 1.  intros; cases n; [left;reflexivity] cases n1; right; reflexivity; qed.  
177 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.
178 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.
179 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.
180 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.
181
182 (* Esercizio 2
183    ===========
184    
185    Definire per ricorsione strutturale la funzione `negate`
186    che presa una formula `F` ne nega gli atomi.
187    
188    Ad esempio la formula `(A ∨ (⊤ → B))` deve diventare
189    `¬A ∨ (⊤ → ¬B)`.
190 *)
191 let rec negate (F: Formula) on F : Formula ≝
192  match F with
193   [ (*BEGIN*)FBot ⇒ FBot
194   | FTop ⇒ FTop
195   | FAtom n ⇒ FNot (FAtom n)
196   | FAnd F1 F2 ⇒ FAnd (negate F1) (negate F2)
197   | FOr F1 F2 ⇒ FOr (negate F1) (negate F2)
198   | FImpl F1 F2 ⇒ FImpl (negate F1) (negate F2)
199   | FNot F ⇒ FNot (negate F)(*END*)
200   ].
201
202 (* Test 2
203    ======
204   
205    Testare la funzione `negate`. Il risultato atteso è:
206    
207        FOr (FNot (FAtom O)) (FImpl FTop (FNot (FAtom 1)))
208        
209    Decommenta ed esegui 
210 *)
211
212 (* eval normalize on (negate (FOr (FAtom 0) (FImpl FTop (FAtom 1)))). *)
213
214 (* ATTENZIONE
215    ==========
216    
217    Non modificare quanto segue
218 *)
219 definition equiv ≝ λF1,F2. ∀v.[[ F1 ]]_v = [[ F2 ]]_v.
220 notation "hvbox(a \nbsp break mstyle color #0000ff (≡) \nbsp b)"  non associative with precedence 45 for @{ 'equivF $a $b }.
221 notation > "a ≡ b" non associative with precedence 50 for @{ equiv $a $b }.
222 interpretation "equivalence for Formulas" 'equivF a b = (equiv a b).
223 lemma equiv_rewrite : ∀F1,F2,F3. F1 ≡ F2 → F1 ≡ F3 → F2 ≡ F3. intros; intro; rewrite < H; rewrite < H1; reflexivity. qed.
224
225 (* Esercizio 3
226    ===========
227    
228    Definire per ricorsione strutturale la funzione di
229    dualizzazione di una formula `F`. Tale funzione:
230    
231    * Scambia FTop con FBot e viceversa
232    
233    * Scambia il connettivo FAnd con FOr e viceversa
234    
235    * Sostituisce il connettivo FImpl con FAnd e nega la
236      prima sottoformula. Il razionale è che `FImpl A B`
237      è semanticamente equivalente a `FOr (FNot A) B` il
238      cui duale è `FAnd (FNot A) B`.
239    
240    Ad esempio la formula `A → (B ∧ ⊥)` viene dualizzata in
241    `¬A ∧ (B ∨ ⊤)`. 
242 *)  
243 let rec dualize (F : Formula) on F : Formula ≝
244   match F with
245   [ (*BEGIN*)FBot ⇒ FTop
246   | FTop ⇒ FBot
247   | FAtom n ⇒ FAtom n
248   | FAnd F1 F2 ⇒ FOr (dualize F1) (dualize F2)
249   | FOr F1 F2 ⇒ FAnd (dualize F1) (dualize F2)
250   | FImpl F1 F2 ⇒ FAnd (FNot (dualize F1)) (dualize F2)
251   | FNot F ⇒ FNot (dualize F)(*END*)
252   ].
253
254 (* Test 3
255    ======
256    
257    Testare la funzione `dualize`. Il risultato atteso è:
258    
259        FAnd (FNot (FAtom O)) (FOr (FAtom 1) FTop) 
260        
261    Decommenta ed esegui.
262 *)
263
264 (* eval normalize on (dualize (FImpl (FAtom 0) (FAnd (FAtom 1) FBot))). *)
265
266 (* Spiegazione
267    ===========
268    
269    La funzione `invert` permette di invertire un mondo `v`.
270    Ovvero, per ogni indice di atomo `i`, se `v i` restituisce
271    `1` allora `(invert v) i` restituisce `0` e viceversa.
272    
273 *)
274 definition invert ≝
275  λv:ℕ → ℕ. λx. if eqb (min (v x) 1) 0 then 1 else 0.
276  
277 interpretation "Inversione del mondo" 'invert v = (invert v).
278  
279 (*DOCBEGIN
280
281 Il linguaggio di dimostrazione di Matita
282 ========================================
283
284 Per dimostrare il lemma `negate_invert` in modo agevole è necessario 
285 utilizzare il seguente comando:
286
287 * by H1, H2 we proved P (H)
288
289   Il comando `by ... we proved` visto nella scorsa esercitazione
290   permette di utilizzare più ipotesi o lemmi alla volta
291   separandoli con una virgola.
292
293 DOCEND*)
294
295 (* Esercizio 4
296    ===========
297    
298    Dimostrare il lemma `negate_invert` che asserisce che
299    la semantica in un mondo `v` associato alla formula
300    negata di `F` e uguale alla semantica associata
301    a `F` in un mondo invertito.
302 *) 
303 lemma negate_invert:
304   ∀F:Formula.∀v:ℕ→ℕ.[[ negate F ]]_v=[[ F ]]_(invert v).
305 assume F:Formula.
306 assume v:(ℕ→ℕ).
307 we proceed by induction on F to prove ([[ negate F ]]_v=[[ F ]]_(invert v)).
308   case FBot.
309     (*BEGIN*)
310     the thesis becomes ([[ negate FBot ]]_v=[[ FBot ]]_(invert v)).
311     (*END*)
312   done.
313   case FTop.
314     (*BEGIN*)
315     the thesis becomes ([[ negate FTop ]]_v=[[ FTop ]]_(invert v)).
316     (*END*)
317   done.
318   case FAtom.
319     assume n : ℕ.
320     the thesis becomes ((*BEGIN*)[[ negate (FAtom n) ]]_v=[[ FAtom n ]]_(invert v)(*END*)).
321     the thesis becomes ((*BEGIN*)1 - (min (v n) 1)= min (invert v n) 1(*END*)).
322     the thesis becomes (1 - (min (v n) 1)= min (if eqb (min (v n) 1) 0 then 1 else 0) 1).
323     by min_bool we proved (min (v n) 1 = 0 ∨ min (v n) 1 = 1) (H1);
324     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).
325       case Left.
326         conclude 
327             (1 - (min (v n) 1)) 
328           = (1 - 0) by H.
329           = 1.
330           = (min 1 1).
331           = (min (if true then 1 else O) 1).
332           = (min (if eqb 0 0 then 1 else O) 1).
333           = (min (if eqb (min (v n) 1) O then 1 else O) 1) by H.
334       done.
335       case Right.
336         (*BEGIN*)
337         conclude 
338             (1 - (min (v n) 1)) 
339           = (1 - 1) by H.
340           = 0.
341           = (min 0 1).
342           = (min (if eqb 1 0 then 1 else O) 1).
343           = (min (if eqb (min (v n) 1) O then 1 else O) 1) by H.
344         (*END*)
345       done.
346   case FAnd.
347     assume f : Formula.
348     by induction hypothesis we know
349       ((*BEGIN*)[[ negate f ]]_v=[[ f ]]_(invert v)(*END*)) (H).
350     assume f1 : Formula.
351     by induction hypothesis we know
352      ((*BEGIN*)[[ negate f1 ]]_v=[[ f1 ]]_(invert v)(*END*)) (H1).
353     the thesis becomes
354      ([[ negate (FAnd f f1) ]]_v=[[ FAnd f f1 ]]_(invert v)).
355     the thesis becomes
356      (min [[ negate f ]]_v [[ negate f1]]_v = [[ FAnd f f1 ]]_(invert v)).
357     conclude 
358         (min [[ negate f ]]_v [[ negate f1]]_v)
359       = (min [[ f ]]_(invert v) [[ negate f1]]_v) by (*BEGIN*)H(*END*).
360       = (min [[ f ]]_(invert v) [[ f1]]_(invert v)) by (*BEGIN*)H1(*END*).
361   done.
362   case FOr.
363     (*BEGIN*)
364     assume f : Formula.
365     by induction hypothesis we know
366       ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
367     assume f1 : Formula.
368     by induction hypothesis we know
369      ([[ negate f1 ]]_v=[[ f1 ]]_(invert v)) (H1).
370     the thesis becomes
371      ([[ negate (FOr f f1) ]]_v=[[ FOr f f1 ]]_(invert v)).
372     the thesis becomes
373      (max [[ negate f ]]_v [[ negate f1]]_v = [[ FOr f f1 ]]_(invert v)).
374     conclude 
375         (max [[ negate f ]]_v [[ negate f1]]_v)
376       = (max [[ f ]]_(invert v) [[ negate f1]]_v) by H.
377       = (max [[ f ]]_(invert v) [[ f1]]_(invert v)) by H1.
378     (*END*)
379   done.
380   case FImpl.
381     (*BEGIN*)
382     assume f : Formula.
383     by induction hypothesis we know
384       ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
385     assume f1 : Formula.
386     by induction hypothesis we know
387      ([[ negate f1 ]]_v=[[ f1 ]]_(invert v)) (H1).
388     the thesis becomes
389      ([[ negate (FImpl f f1) ]]_v=[[ FImpl f f1 ]]_(invert v)).
390     the thesis becomes
391      (max (1 - [[ negate f ]]_v) [[ negate f1]]_v = [[ FImpl f f1 ]]_(invert v)).
392     conclude 
393         (max (1 - [[ negate f ]]_v) [[ negate f1]]_v)
394       = (max (1 - [[ f ]]_(invert v)) [[ negate f1]]_v) by H.
395       = (max (1 - [[ f ]]_(invert v)) [[ f1]]_(invert v)) by H1.
396     (*END*)
397   done.
398   case FNot.
399     (*BEGIN*)
400     assume f : Formula.
401     by induction hypothesis we know
402       ([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
403     the thesis becomes
404       ([[ negate (FNot f) ]]_v=[[ FNot f ]]_(invert v)).
405     the thesis becomes
406       (1 - [[ negate f ]]_v=[[ FNot f ]]_(invert v)).
407     conclude (1 - [[ negate f ]]_v) = (1 - [[f]]_(invert v)) by H.
408     (*END*)
409   done.  
410 qed.   
411
412 (* Esercizio 5
413    ===========
414    
415    Dimostrare che la funzione negate rispetta l'equivalenza.
416 *)
417 lemma negate_fun:
418  ∀F:Formula.∀G:Formula.F ≡ G → negate F ≡ negate G.
419  assume (*BEGIN*)F:Formula(*END*).
420  assume (*BEGIN*)G:Formula(*END*).
421  suppose (*BEGIN*)(F ≡ G) (H)(*END*).
422  the thesis becomes (*BEGIN*)(negate F ≡ negate G)(*END*).
423  the thesis becomes (*BEGIN*)(∀v:ℕ→ℕ.[[ negate F ]]_v=[[ negate G ]]_v)(*END*).
424  assume v:(ℕ→ℕ).
425  conclude 
426      [[ negate F ]]_v
427    = [[ F ]]_(invert v) by (*BEGIN*)negate_invert(*END*).
428    = [[ G ]]_((*BEGIN*)invert v(*BEGIN*)) by (*BEGIN*)H(*BEGIN*).
429    = [[ negate G ]]_(*BEGIN*)v(*BEGIN*) by (*BEGIN*)negate_invert(*END*).
430  done.  
431 qed.
432
433 (* Esercizio 6
434    ===========
435    
436    Dimostrare che per ogni formula `F`, `(negate F)` equivale a 
437    dualizzarla e negarla.
438 *)
439 lemma not_dualize_eq_negate:
440  ∀F:Formula.negate F ≡ FNot (dualize F).
441  (*BEGIN*)
442  assume F:Formula.
443  the thesis becomes (∀v:ℕ→ℕ.[[negate F]]_v=[[FNot (dualize F)]]_v).
444  (*END*)
445  assume v:(ℕ→ℕ).
446  we proceed by induction on F to prove ([[negate F]]_v=[[FNot (dualize F)]]_v).
447  case FBot.
448    (*BEGIN*)
449    the thesis becomes ([[ negate FBot ]]_v=[[ FNot (dualize FBot) ]]_v).
450    (*END*)
451  done.
452  case FTop.
453    (*BEGIN*)
454    the thesis becomes ([[ negate FTop ]]_v=[[ FNot (dualize FTop) ]]_v).
455    (*END*)
456  done.
457  case FAtom.
458    (*BEGIN*)
459    assume n : ℕ.
460    the thesis becomes ([[ negate (FAtom n) ]]_v=[[ FNot (dualize (FAtom n)) ]]_v).
461    (*END*)
462  done.
463  case FAnd.
464    assume f : Formula.
465    by induction hypothesis we know
466      ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
467    assume f1 : Formula.
468    by induction hypothesis we know
469     ([[ negate f1 ]]_v=[[ FNot (dualize f1) ]]_v) (H1).
470    the thesis becomes
471     ([[ negate (FAnd f f1) ]]_v=[[ FNot (dualize (FAnd f f1)) ]]_v).
472    the thesis becomes
473     (min [[ negate f ]]_v [[ negate f1 ]]_v=[[ FNot (dualize (FAnd f f1)) ]]_v).
474    conclude 
475        (min (*BEGIN*)[[ negate f ]]_v(*END*) (*BEGIN*)[[ negate f1 ]]_v(*END*))
476      = (min (*BEGIN*)[[ FNot (dualize f) ]]_v(*END*) (*BEGIN*)[[ negate f1 ]]_v(*END*)) by H.    
477      = (min (*BEGIN*)[[ FNot (dualize f) ]]_v(*END*) (*BEGIN*)[[ FNot (dualize f1) ]]_v(*END*)) by H1.
478      = (min (1 - [[ dualize f ]]_v) (1 - [[ dualize f1 ]]_v)).
479      = (1 - (max [[ dualize f ]]_v [[ dualize f1 ]]_v)) by min_max.
480  done.
481  case FOr.
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 (FOr f f1) ]]_v=[[ FNot (dualize (FOr f f1)) ]]_v).
491    the thesis becomes
492     (max [[ negate f ]]_v [[ negate f1 ]]_v=[[ FNot (dualize (FOr f f1)) ]]_v).
493    conclude 
494        (max [[ negate f ]]_v [[ negate f1 ]]_v)
495      = (max [[ FNot (dualize f) ]]_v [[ negate f1 ]]_v) by H.    
496      = (max [[ FNot (dualize f) ]]_v [[ FNot (dualize f1) ]]_v) by H1.
497      = (max (1 - [[ dualize f ]]_v) (1 - [[ dualize f1 ]]_v)).
498      = (1 - (min [[ dualize f ]]_v [[ dualize f1 ]]_v)) by max_min.
499    (*END*)
500  done.
501  case FImpl.
502    (*BEGIN*)
503    assume f : Formula.
504    by induction hypothesis we know
505      ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
506    assume f1 : Formula.
507    by induction hypothesis we know
508     ([[ negate f1 ]]_v=[[ FNot (dualize f1) ]]_v) (H1).
509    the thesis becomes
510     ([[ negate (FImpl f f1) ]]_v=[[ FNot (dualize (FImpl f f1)) ]]_v).
511    the thesis becomes
512     (max (1 - [[ negate f ]]_v) [[ negate f1 ]]_v=[[ FNot (dualize (FImpl f f1)) ]]_v).
513    conclude 
514        (max (1-[[ negate f ]]_v) [[ negate f1 ]]_v)
515      = (max (1-[[ FNot (dualize f) ]]_v) [[ negate f1 ]]_v) by H.    
516      = (max (1-[[ FNot (dualize f) ]]_v) [[ FNot (dualize f1) ]]_v) by H1.
517      = (max (1 - [[ FNot (dualize f) ]]_v) (1 - [[ dualize f1 ]]_v)).
518      = (1 - (min [[ FNot (dualize f) ]]_v [[ dualize f1 ]]_v)) by max_min.
519    (*END*)
520  done.
521  case FNot.
522    (*BEGIN*) 
523    assume f : Formula.
524    by induction hypothesis we know
525      ([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
526    the thesis becomes
527       ([[ negate (FNot f) ]]_v=[[ FNot (dualize (FNot f)) ]]_v).
528    the thesis becomes
529       (1 - [[ negate f ]]_v=[[ FNot (dualize (FNot f)) ]]_v).
530    conclude (1 - [[ negate f ]]_v) = (1 - [[ FNot (dualize f) ]]_v) by H.
531    (*END*)
532  done.
533 qed.
534
535 (* Esercizio 7
536    ===========
537    
538    Dimostrare che la negazione è iniettiva
539 *)
540 theorem not_inj:
541  ∀F,G:Formula.FNot F ≡ FNot G→F ≡ G.
542  (*BEGIN*)
543  assume F:Formula.
544  assume G:Formula.
545  suppose (FNot F ≡ FNot G) (H).
546  the thesis becomes (F ≡ G).
547  the thesis becomes (∀v:ℕ→ℕ.[[ F ]]_v=[[ G ]]_v).
548  (*END*)
549  assume v:(ℕ→ℕ).
550  by sem_le_1 we proved ([[F]]_v ≤ 1) (H1).
551  by (*BEGIN*)sem_le_1(*END*) we proved ([[G]]_v ≤ 1) (H2).
552  by min_1_1, H1 we proved (1 - (1 - [[F]]_v) = [[F]]_v) (H3).
553  by (*BEGIN*)min_1_1, H2(*END*) we proved ((*BEGIN*)1 - (1 - [[G]]_v)(*END*) = [[G]]_v) (H4).
554  conclude 
555      ([[F]]_v)
556    = (1 - (1 - [[F]]_v)) by (*BEGIN*)H3(*END*).
557    = (1 - [[(*BEGIN*)FNot F(*END*)]]_v).
558    = (1 - [[ FNot G]]_v) by H.
559    = (1 - (*BEGIN*)(1 - [[G]]_v)(*END*)).
560    = [[G]]_v by (*BEGIN*)H4(*END*).
561  done.
562 qed.
563
564 (*DOCBEGIN
565
566 La prova del teorema di dualità
567 ===============================
568
569 Il teorema di dualità accennato a lezione dice che se due formule 
570 `F1` ed `F2` sono equivalenti, allora anche le formule duali lo sono.
571         
572     ∀F1,F2:Formula. F1 ≡ F2 → dualize F1 ≡ dualize F2.
573         
574 Per dimostrare tale teorema è bene suddividere la prova in lemmi intermedi
575
576 1. lemma `negate_invert`, dimostrato per induzione su F, utilizzando
577    `min_bool`
578    
579         ∀F:Formula.∀v:ℕ→ℕ.[[ negate F ]]_v=[[ F ]]_(invert v).
580
581 2. lemma `negate_fun`, conseguenza di `negate_invert`
582
583         ∀F,G:Formula. F ≡ G → negate F ≡ negate G.
584         
585 2. lemma `not_dualize_eq_negate`, dimostrato per induzione su F,
586    utilizzando `max_min` e `min_max`
587
588         ∀F:Formula. negate F ≡ FNot (dualize F)
589         
590 4. lemma `not_inj`, conseguenza di `sem_bool`
591  
592         ∀F,G:Formula. FNot F ≡ FNot G → F ≡ G
593
594 Una volta dimostrati tali lemmi la prova del teorema di dualità 
595 procede come di seguito:
596
597 1. Assume l'ipotesi  
598
599         F1 ≡ F2
600
601 2. Utilizza `negate_fun` per ottenere 
602
603         negate F1 ≡ negate F2
604
605 3. Utilizzando due volte il lemma `not_dualize_eq_negate` e il lemma
606    `equiv_rewrite` ottiene 
607
608         FNot (dualize F1) ≡ FNot (dualize F2)
609
610 4. Conclude utilizzando il lemma `not_inj` per ottenere la tesi 
611
612         dualize F1 ≡ dualize F2
613
614 DOCEND*)
615
616 (* Esercizio 8
617    ===========
618    
619    Dimostrare il teorema di dualità
620 *)
621 theorem duality: ∀F1,F2:Formula.F1 ≡ F2 → dualize F1 ≡ dualize F2.
622  assume F1:Formula.
623  assume F2:Formula.
624  suppose (F1 ≡ F2) (H).
625  the thesis becomes (dualize F1 ≡ dualize F2).
626  by (*BEGIN*)negate_fun(*END*), H we proved (negate F1 ≡ negate F2) (H1).
627  by (*BEGIN*)not_dualize_eq_negate(*END*), (*BEGIN*)equiv_rewrite(*END*), H1 we proved (FNot (dualize F1) ≡ negate F2) (H2).
628  by (*BEGIN*)not_dualize_eq_negate(*END*), (*BEGIN*)equiv_rewrite(*END*), H2 we proved (FNot (dualize F1) ≡ FNot (dualize F2)) (H3).
629  by (*BEGIN*)not_inj(*END*), H3 we proved (dualize F1 ≡ dualize F2) (H4).
630  by H4 done.
631 qed.