4 1. Leggere ATTENTAMENTE, e magari stampare, la documentazione reperibile
7 http://mowgli.cs.unibo.it/~tassi/exercise-shannon.ma.html
9 2. Questa volta si fa sul serio:
10 l'esercizio proposto è molto difficile, occorre la vostra massima
11 concentrazione (leggi: niente cut&paste selvaggio, cercate di capire!)
19 Compilare i seguenti campi:
36 Non modificare quanto segue
38 include "nat/minus.ma".
39 definition if_then_else ≝ λT:Type.λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
40 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 }.
41 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 }.
42 interpretation "Formula if_then_else" 'if_then_else e t f = (if_then_else _ e t f).
43 definition max ≝ λn,m. if eqb (n - m) 0 then m else n.
44 definition min ≝ λn,m. if eqb (n - m) 0 then n else m.
49 Il linguaggio delle formule, dove gli atomi sono
50 rapperesentati da un numero naturale
52 inductive Formula : Type ≝
55 | FAtom: nat → Formula
56 | FAnd: Formula → Formula → Formula
57 | FOr: Formula → Formula → Formula
58 | FImpl: Formula → Formula → Formula
59 | FNot: Formula → Formula
65 La semantica di una formula `F` in un mondo `v`: `[[ F ]]_v`
67 let rec sem (v: nat → nat) (F: Formula) on F : nat ≝
71 | FAtom n ⇒ min (v n) 1
72 | FAnd F1 F2 ⇒ min (sem v F1) (sem v F2)
73 | FOr F1 F2 ⇒ max (sem v F1) (sem v F2)
74 | FImpl F1 F2 ⇒ max (1 - sem v F1) (sem v F2)
75 | FNot F1 ⇒ 1 - (sem v F1)
82 Non modificare quanto segue.
84 notation < "[[ \nbsp term 19 a \nbsp ]] \nbsp \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }.
85 notation > "[[ term 19 a ]] \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }.
86 notation > "[[ term 19 a ]]_ term 90 v" non associative with precedence 90 for @{ sem $v $a }.
87 interpretation "Semantic of Formula" 'semantics v a = (sem v a).
88 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.
93 L'operazione di sostituzione di una formula `G` al posto dell'atomo
94 `x` in una formula `F`: `F[G/x]`
97 let rec subst (x:nat) (G: Formula) (F: Formula) on F ≝
101 | FAtom n ⇒ if eqb n x then G else (FAtom n)
102 | FAnd F1 F2 ⇒ FAnd (subst x G F1) (subst x G F2)
103 | FOr F1 F2 ⇒ FOr (subst x G F1) (subst x G F2)
104 | FImpl F1 F2 ⇒ FImpl (subst x G F1) (subst x G F2)
105 | FNot F ⇒ FNot (subst x G F)
111 Non modificare quanto segue.
113 notation < "t [ \nbsp term 19 a / term 19 b \nbsp ]" non associative with precedence 19 for @{ 'substitution $b $a $t }.
114 notation > "t [ term 90 a / term 90 b]" non associative with precedence 19 for @{ 'substitution $b $a $t }.
115 interpretation "Substitution for Formula" 'substitution b a t = (subst b a t).
116 definition equiv ≝ λF1,F2. ∀v.[[ F1 ]]_v = [[ F2 ]]_v.
117 notation "hvbox(a \nbsp break mstyle color #0000ff (≡) \nbsp b)" non associative with precedence 45 for @{ 'equivF $a $b }.
118 notation > "a ≡ b" non associative with precedence 50 for @{ equiv $a $b }.
119 interpretation "equivalence for Formulas" 'equivF a b = (equiv a b).
120 lemma min_1_sem: ∀F,v.min 1 [[ F ]]_v = [[ F ]]_v. intros; cases (sem_bool F v); rewrite > H; reflexivity; qed.
121 lemma max_0_sem: ∀F,v.max [[ F ]]_v 0 = [[ F ]]_v. intros; cases (sem_bool F v); rewrite > H; reflexivity; qed.
122 definition IFTE := λA,B,C:Formula. FOr (FAnd A B) (FAnd (FNot A) C).
126 La libreria di Matita
127 =====================
129 Per portare a termine l'esercitazione sono necessari i seguenti lemmi:
131 * lemma `decidable_eq_nat` : `∀x,y.x = y ∨ x ≠ y`
132 * lemma `not_eq_to_eqb_false` : `∀x,y.x ≠ y → eqb x y = false`
133 * lemma `eq_to_eqb_true` : `∀x,y.x = y → eqb x y = true`
134 * lemma `min_1_sem` : `∀F,v.min 1 [[ F ]]_v = [[ F ]]_v`
135 * lemma `max_0_sem` : `∀F,v.max [[ F ]]_v 0 = [[ F ]]_v`
137 Il teorema di espansione di Shannon
138 ===================================
140 Si definisce un connettivo logico `IFTE A B C` come `FOr (FAnd A B) (FAnd (FNot A) C)`.
142 Il teorema dice che data una formula `F`, e preso un atomo `x`, la seguente
143 formula è equivalente a `F`:
145 IFTE (FAtom x) (F[FTop/x]) (F[FBot/x])
147 Ovvero, sostituisco l'atomo `x` con `FBot` se tale atomo è falso
148 in un mondo mondo `v`, altrimenti lo sostituisco con `FTop`.
150 La dimostrazione è composta da due lemmi, `shannon_false` e `shannon_true`.
152 Vediamo la dimostrazione del primo, che asserisce
154 ∀F,x,v. [[ FAtom x ]]_v = 0 → [[ F[FBot/x] ]]_v = [[ F ]]_v
156 Una volta assunte la formula `F`, l'atomo `x`, il mondo `v` e aver supposto
157 che `[[ FAtom x ]]_v = 0` si procede per induzione su `F`.
158 I casi `FTop` e `FBot` sono banali. Nei casi `FAnd/FOr/FImpl/FNot`,
159 una volta assunte le sottofrmule e le ipotesi induttive, si conclude
160 con una catena di uguaglianze.
162 Il caso `FAtom` richiede maggiore cura. Assunto l'indice dell'atomo,
163 occorre utilizzare il lemma `decidable_eq_nat` per ottenere l'ipotesi
164 aggiuntiva `n = x ∨ n ≠ x` su cui si procede poi per casi.
165 In entrambi i casi, usanto i lemmi `eq_to_eqb_true` e `not_eq_to_eqb_false`
166 si ottengolo le ipotesi aggiuntive `(eqb n x = true)` e `(eqb n x = false)`.
167 Entrambi i casi si concludono con una catena di uguaglianze.
169 Il teorema principale si dimostra utilizzando il lemma `sem_bool` per
170 ottenre l'ipotesi `[[ FAtom x ]]_v = 0 ∨ [[ FAtom x ]]_v = 1` su cui
171 si procede poi per casi. Entrambi i casi si cncludono con
172 una catena di uguaglianze che utilizza i lemmi dimostrati in precedenza
173 e i lemmi `min_1_sem` e `max_0_sem`.
178 ∀F,x,v. [[ FAtom x ]]_v = 0 → [[ F[FBot/x] ]]_v = [[ F ]]_v.
183 suppose ([[ FAtom x ]]_v = 0) (H).
184 we proceed by induction on F to prove ([[ F[FBot/x] ]]_v = [[ F ]]_v).
186 the thesis becomes ([[ FBot[FBot/x] ]]_v = [[ FBot ]]_v).
187 the thesis becomes ([[ FBot ]]_v = [[ FBot ]]_v).
190 the thesis becomes ([[ FTop[FBot/x] ]]_v = [[ FTop ]]_v).
191 the thesis becomes ([[ FTop ]]_v = [[ FTop ]]_v).
195 the thesis becomes ([[ (FAtom n)[FBot/x] ]]_v = [[ FAtom n ]]_v).
196 the thesis becomes ([[ if eqb n x then FBot else (FAtom n) ]]_v = [[ FAtom n ]]_v).
197 by decidable_eq_nat we proved (n = x ∨ n ≠ x) (H1).
198 we proceed by cases on H1 to prove ([[ if eqb n x then FBot else (FAtom n) ]]_v = [[ FAtom n ]]_v).
200 by H2, eq_to_eqb_true we proved (eqb n x = true) (H3).
202 ([[ if eqb n x then FBot else (FAtom n) ]]_v)
203 = ([[ if true then FBot else (FAtom n) ]]_v) by H3.
206 = ([[ FAtom x ]]_v) by H.
207 = ([[ FAtom n ]]_v) by H2.
210 by H2, not_eq_to_eqb_false we proved (eqb n x = false) (H3).
212 ([[ if eqb n x then FBot else (FAtom n) ]]_v)
213 = ([[ if false then FBot else (FAtom n) ]]_v) by H3.
218 by induction hypothesis we know ([[ f1[FBot/x] ]]_v = [[ f1 ]]_v) (H1).
220 by induction hypothesis we know ([[ f2[FBot/x] ]]_v = [[ f2 ]]_v) (H2).
221 the thesis becomes ([[ (FAnd f1 f2)[FBot/x] ]]_v = [[ FAnd f1 f2 ]]_v).
223 ([[ (FAnd f1 f2)[FBot/x] ]]_v)
224 = ([[ FAnd (f1[FBot/x]) (f2[FBot/x]) ]]_v).
225 = (min [[ f1[FBot/x] ]]_v [[ f2[FBot/x] ]]_v).
226 = (min [[ f1 ]]_v [[ f2[FBot/x] ]]_v) by H1.
227 = (min [[ f1 ]]_v [[ f2 ]]_v) by H2.
228 = ([[ FAnd f1 f2 ]]_v).
232 by induction hypothesis we know ([[ f1[FBot/x] ]]_v = [[ f1 ]]_v) (H1).
234 by induction hypothesis we know ([[ f2[FBot/x] ]]_v = [[ f2 ]]_v) (H2).
235 the thesis becomes ([[ (FOr f1 f2)[FBot/x] ]]_v = [[ FOr f1 f2 ]]_v).
237 ([[ (FOr f1 f2)[FBot/x] ]]_v)
238 = ([[ FOr (f1[FBot/x]) (f2[FBot/x]) ]]_v).
239 = (max [[ f1[FBot/x] ]]_v [[ f2[FBot/x] ]]_v).
240 = (max [[ f1 ]]_v [[ f2[FBot/x] ]]_v) by H1.
241 = (max [[ f1 ]]_v [[ f2 ]]_v) by H2.
242 = ([[ FOr f1 f2 ]]_v).
246 by induction hypothesis we know ([[ f1[FBot/x] ]]_v = [[ f1 ]]_v) (H1).
248 by induction hypothesis we know ([[ f2[FBot/x] ]]_v = [[ f2 ]]_v) (H2).
249 the thesis becomes ([[ (FImpl f1 f2)[FBot/x] ]]_v = [[ FImpl f1 f2 ]]_v).
251 ([[ (FImpl f1 f2)[FBot/x] ]]_v)
252 = ([[ FImpl (f1[FBot/x]) (f2[FBot/x]) ]]_v).
253 = (max (1 - [[ f1[FBot/x] ]]_v) [[ f2[FBot/x] ]]_v).
254 = (max (1 - [[ f1 ]]_v) [[ f2[FBot/x] ]]_v) by H1.
255 = (max (1 - [[ f1 ]]_v) [[ f2 ]]_v) by H2.
256 = ([[ FImpl f1 f2 ]]_v).
260 by induction hypothesis we know ([[ f[FBot/x] ]]_v = [[ f ]]_v) (H1).
261 the thesis becomes ([[ (FNot f)[FBot/x] ]]_v = [[ FNot f ]]_v).
263 ([[ (FNot f)[FBot/x] ]]_v)
264 = ([[ FNot (f[FBot/x]) ]]_v).
265 = (1 - [[ f[FBot/x] ]]_v).
266 = (1 - [[ f ]]_v) by H1.
273 ∀F,x,v. [[ FAtom x ]]_v = 1 → [[ F[FTop/x] ]]_v = [[ F ]]_v.
278 suppose ([[ FAtom x ]]_v = 1) (H).
279 we proceed by induction on F to prove ([[ F[FTop/x] ]]_v = [[ F ]]_v).
281 the thesis becomes ([[ FBot[FTop/x] ]]_v = [[ FBot ]]_v).
282 the thesis becomes ([[ FBot ]]_v = [[ FBot ]]_v).
285 the thesis becomes ([[ FTop[FTop/x] ]]_v = [[ FTop ]]_v).
286 the thesis becomes ([[ FTop ]]_v = [[ FTop ]]_v).
290 the thesis becomes ([[ (FAtom n)[FTop/x] ]]_v = [[ FAtom n ]]_v).
291 the thesis becomes ([[ if eqb n x then FTop else (FAtom n) ]]_v = [[ FAtom n ]]_v).
292 by decidable_eq_nat we proved (n = x ∨ n ≠ x) (H1).
293 we proceed by cases on H1 to prove ([[ if eqb n x then FTop else (FAtom n) ]]_v = [[ FAtom n ]]_v).
295 by H2, eq_to_eqb_true we proved (eqb n x = true) (H3).
297 ([[ if eqb n x then FTop else (FAtom n) ]]_v)
298 = ([[ if true then FTop else (FAtom n) ]]_v) by H3.
301 = ([[ FAtom x ]]_v) by H.
302 = ([[ FAtom n ]]_v) by H2.
305 by H2, not_eq_to_eqb_false we proved (eqb n x = false) (H3).
307 ([[ if eqb n x then FTop else (FAtom n) ]]_v)
308 = ([[ if false then FTop else (FAtom n) ]]_v) by H3.
313 by induction hypothesis we know ([[ f1[FTop/x] ]]_v = [[ f1 ]]_v) (H1).
315 by induction hypothesis we know ([[ f2[FTop/x] ]]_v = [[ f2 ]]_v) (H2).
316 the thesis becomes ([[ (FAnd f1 f2)[FTop/x] ]]_v = [[ FAnd f1 f2 ]]_v).
318 ([[ (FAnd f1 f2)[FTop/x] ]]_v)
319 = ([[ FAnd (f1[FTop/x]) (f2[FTop/x]) ]]_v).
320 = (min [[ f1[FTop/x] ]]_v [[ f2[FTop/x] ]]_v).
321 = (min [[ f1 ]]_v [[ f2[FTop/x] ]]_v) by H1.
322 = (min [[ f1 ]]_v [[ f2 ]]_v) by H2.
323 = ([[ FAnd f1 f2 ]]_v).
327 by induction hypothesis we know ([[ f1[FTop/x] ]]_v = [[ f1 ]]_v) (H1).
329 by induction hypothesis we know ([[ f2[FTop/x] ]]_v = [[ f2 ]]_v) (H2).
330 the thesis becomes ([[ (FOr f1 f2)[FTop/x] ]]_v = [[ FOr f1 f2 ]]_v).
332 ([[ (FOr f1 f2)[FTop/x] ]]_v)
333 = ([[ FOr (f1[FTop/x]) (f2[FTop/x]) ]]_v).
334 = (max [[ f1[FTop/x] ]]_v [[ f2[FTop/x] ]]_v).
335 = (max [[ f1 ]]_v [[ f2[FTop/x] ]]_v) by H1.
336 = (max [[ f1 ]]_v [[ f2 ]]_v) by H2.
337 = ([[ FOr f1 f2 ]]_v).
341 by induction hypothesis we know ([[ f1[FTop/x] ]]_v = [[ f1 ]]_v) (H1).
343 by induction hypothesis we know ([[ f2[FTop/x] ]]_v = [[ f2 ]]_v) (H2).
344 the thesis becomes ([[ (FImpl f1 f2)[FTop/x] ]]_v = [[ FImpl f1 f2 ]]_v).
346 ([[ (FImpl f1 f2)[FTop/x] ]]_v)
347 = ([[ FImpl (f1[FTop/x]) (f2[FTop/x]) ]]_v).
348 = (max (1 - [[ f1[FTop/x] ]]_v) [[ f2[FTop/x] ]]_v).
349 = (max (1 - [[ f1 ]]_v) [[ f2[FTop/x] ]]_v) by H1.
350 = (max (1 - [[ f1 ]]_v) [[ f2 ]]_v) by H2.
351 = ([[ FImpl f1 f2 ]]_v).
355 by induction hypothesis we know ([[ f[FTop/x] ]]_v = [[ f ]]_v) (H1).
356 the thesis becomes ([[ (FNot f)[FTop/x] ]]_v = [[ FNot f ]]_v).
358 ([[ (FNot f)[FTop/x] ]]_v)
359 = ([[ FNot (f[FTop/x]) ]]_v).
360 = (1 - [[ f[FTop/x] ]]_v).
361 = (1 - [[ f ]]_v) by H1.
368 ∀F,x. IFTE (FAtom x) (F[FTop/x]) (F[FBot/x]) ≡ F.
373 the thesis becomes ([[ IFTE (FAtom x) (F[FTop/x]) (F[FBot/x])]]_v = [[ F ]]_v).
374 by sem_bool we proved ([[ FAtom x]]_v = 0 ∨ [[ FAtom x]]_v = 1) (H).
375 we proceed by cases on H to prove ([[ IFTE (FAtom x) (F[FTop/x]) (F[FBot/x])]]_v = [[ F ]]_v).
378 ([[ IFTE (FAtom x) (F[FTop/x]) (F[FBot/x])]]_v)
379 = ([[ FOr (FAnd (FAtom x) (F[FTop/x])) (FAnd (FNot (FAtom x)) (F[FBot/x]))]]_v).
380 = (max [[ (FAnd (FAtom x) (F[FTop/x])) ]]_v [[ (FAnd (FNot (FAtom x)) (F[FBot/x]))]]_v).
381 = (max (min [[ FAtom x ]]_v [[ F[FTop/x] ]]_v) (min (1 - [[ FAtom x ]]_v) [[ F[FBot/x] ]]_v)).
382 = (max (min 0 [[ F[FTop/x] ]]_v) (min (1 - 0) [[ F[FBot/x] ]]_v)) by H.
383 = (max 0 (min 1 [[ F[FBot/x] ]]_v)).
384 = (max 0 [[ F[FBot/x] ]]_v) by min_1_sem.
385 = ([[ F[FBot/x] ]]_v).
386 = ([[ F ]]_v) by H1, shannon_false.
390 ([[ IFTE (FAtom x) (F[FTop/x]) (F[FBot/x])]]_v)
391 = ([[ FOr (FAnd (FAtom x) (F[FTop/x])) (FAnd (FNot (FAtom x)) (F[FBot/x]))]]_v).
392 = (max [[ (FAnd (FAtom x) (F[FTop/x])) ]]_v [[ (FAnd (FNot (FAtom x)) (F[FBot/x]))]]_v).
393 = (max (min [[ FAtom x ]]_v [[ F[FTop/x] ]]_v) (min (1 - [[ FAtom x ]]_v) [[ F[FBot/x] ]]_v)).
394 = (max (min 1 [[ F[FTop/x] ]]_v) (min (1 - 1) [[ F[FBot/x] ]]_v)) by H.
395 = (max (min 1 [[ F[FTop/x] ]]_v) (min 0 [[ F[FBot/x] ]]_v)).
396 = (max [[ F[FTop/x] ]]_v (min 0 [[ F[FBot/x] ]]_v)) by min_1_sem.
397 = (max [[ F[FTop/x] ]]_v 0).
398 = ([[ F[FTop/x] ]]_v) by max_0_sem.
399 = ([[ F ]]_v) by H1, shannon_true.
411 1. Ogni volta che nella finestra di destra compare un simbolo `∀` oppure un
412 simbolo `→` è opportuno usare il comando `assume` oppure `suppose` (che
413 vengono nuovamente spiegati in seguito).
415 2. Ogni caso (o sotto caso) della dimostrazione:
417 1. Inizia con una sequenza di comandi `assume` o `suppose` oppure
418 `by induction hypothesis we know`. Tale sequenza di comandi può anche
421 2. Continua poi con almeno un comando `the thesis becomes`.
423 3. Eventualmente seguono vari comandi `by ... we proved` per combinare le
424 ipotesi tra loro o utilizzare i teoremi già disponibili per generare nuove
427 4. Eventualmente uno o più comandi `we proceed by cases on (...) to prove (...)`.
429 5. Se necessario un comando `conclude` seguito da un numero anche
430 molto lungo di passi `= (...) by ... .` per rendere la parte
431 sinistra della vostra tesi uguale alla parte destra.
433 6. Ogni caso termina con `done`.
435 3. Ogni caso corrispondente a un nodo con sottoformule (FAnd/For/FNot)
436 avrà tante ipotesi induttive quante sono le sue sottoformule e tali
437 ipotesi sono necessarie per portare a termine la dimostrazione.
439 I comandi da utilizzare
440 =======================
442 * `the thesis becomes (...).`
444 Afferma quale sia la tesi da dimostrare. Se ripetuto
445 permette di espandere le definizioni.
447 * `we proceed by cases on (...) to prove (...).`
449 Permette di andare per casi su una ipotesi (quando essa è della forma
452 Esempio: `we proceed by cases on H to prove Q.`
456 Nelle dimostrazioni per casi o per induzioni si utulizza tale comando
457 per inizia la sotto prova relativa a un caso. Esempio: `case Fbot.`
461 Ogni caso di una dimostrazione deve essere terminato con il comando
464 * `assume ... : (...) .`
466 Assume una formula o un numero, ad esempio `assume n : (ℕ).` assume
467 un numero naturale `n`.
469 * `by ..., ..., ..., we proved (...) (...).`
471 Permette di comporre lemmi e ipotesi per ottenere nuove ipotesi.
472 Ad esempio `by H, H1 we prove (F ≡ G) (H2).` ottiene una nuova ipotesi
473 `H2` che dice che `F ≡ G` componendo insieme `H` e `H1`.
475 * `conclude (...) = (...) by ... .`
477 Il comando conclude lavora SOLO sulla parte sinistra della tesi. È il comando
478 con cui si inizia una catena di uguaglianze. La prima formula che si
479 scrive deve essere esattamente uguale alla parte sinistra della conclusione
480 originale. Esempio `conclude ([[ FAtom x ]]_v) = ([[ FAtom n ]]_v) by H.`
481 Se la giustificazione non è un lemma o una ipotesi ma la semplice espansione
482 di una definizione, la parte `by ...` deve essere omessa.
486 Continua un comando `conclude`, lavorando sempre sulla parte sinistra della