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