]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/didactic/shannon.ma
using the new by foo we proved semantics
[helm.git] / helm / software / matita / contribs / didactic / shannon.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 *)
17
18 (* ATTENZIONE
19    ==========
20    
21    Non modificare quanto segue 
22 *)
23 include "nat/minus.ma".
24 definition if_then_else ≝ λT:Type.λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
25 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 }.
26 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 }.
27 interpretation "Formula if_then_else" 'if_then_else e t f = (if_then_else _ e t f).
28 definition max ≝ λn,m. if eqb (n - m) 0 then m else n. 
29 definition min ≝ λn,m. if eqb (n - m) 0 then n else m. 
30
31 (* Ripasso
32    =======
33    
34    Il linguaggio delle formule, dove gli atomi sono
35    rapperesentati da un numero naturale
36 *)
37 inductive Formula : Type ≝
38 | FBot: Formula
39 | FTop: Formula
40 | FAtom: nat → Formula
41 | FAnd: Formula → Formula → Formula
42 | FOr: Formula → Formula → Formula
43 | FImpl: Formula → Formula → Formula
44 | FNot: Formula → Formula
45 .
46
47 let rec sem (v: nat → nat) (F: Formula) on F : nat ≝
48  match F with
49   [ FBot ⇒ 0
50   | FTop ⇒ 1
51   | FAtom n ⇒ min (v n) 1
52   | FAnd F1 F2 ⇒ min (sem v F1) (sem v F2)
53   | FOr F1 F2 ⇒ max (sem v F1) (sem v F2)
54   | FImpl F1 F2 ⇒ max (1 - sem v F1) (sem v F2)
55   | FNot F1 ⇒ 1 - (sem v F1)
56   ]
57 .
58
59 (* ATTENZIONE
60    ==========
61    
62    Non modificare quanto segue.
63 *)
64 notation < "[[ \nbsp term 19 a \nbsp ]] \nbsp \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }.
65 notation > "[[ term 19 a ]] \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }.
66 notation > "[[ term 19 a ]]_ term 90 v" non associative with precedence 90 for @{ sem $v $a }.
67 interpretation "Semantic of Formula" 'semantics v a = (sem v a).
68
69 (*DOCBEGIN
70
71 La libreria di Matita
72 =====================
73
74 Gli strumenti per la dimostrazione assistita sono corredati da
75 librerie di teoremi già dimostrati. Per portare a termine l'esercitazione
76 sono necessari i seguenti lemmi:
77
78 * lemma `sem_le_1` : `∀F,v. [[ F ]]_v ≤ 1`
79 * lemma `min_1_1` : `∀x. x ≤ 1 → 1 - (1 - x) = x`
80 * lemma `min_bool` : `∀n. min n 1 = 0 ∨ min n 1 = 1`
81 * lemma `min_max` : `∀F,G,v.min (1 - [[F]]_v) (1 - [[G]]_v) = 1 - max [[F]]_v [[G]]_v`
82 * lemma `max_min` : `∀F,G,v.max (1 - [[F]]_v) (1 - [[G]]_v) = 1 - min [[F]]_v [[G]]_v`
83 * lemma `decidable_eq_nat` : `∀x,y.x = y ∨ x ≠ y`
84
85
86 DOCEND*)
87
88 (* ATTENZIONE
89    ==========
90    
91    Non modificare quanto segue.
92 *)
93 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.
94 lemma min_bool : ∀n. min n 1 = 0 ∨ min n 1 = 1.  intros; cases n; [left;reflexivity] cases n1; right; reflexivity; qed.  
95 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.
96 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.
97 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.
98 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.
99 let rec subst (x:nat) (G: Formula) (F: Formula) on F ≝
100  match F with
101   [ FBot ⇒ FBot
102   | FTop ⇒ FTop
103   | FAtom n ⇒ if eqb n x then G else (FAtom n)
104   | FAnd F1 F2 ⇒ FAnd (subst x G F1) (subst x G F2)
105   | FOr F1 F2 ⇒ FOr (subst x G F1) (subst x G F2)
106   | FImpl F1 F2 ⇒ FImpl (subst x G F1) (subst x G F2)
107   | FNot F ⇒ FNot (subst x G F)
108   ].
109   
110 notation < "t [ \nbsp term 19 a / term 19 b \nbsp ]" non associative with precedence 19 for @{ 'substitution $b $a $t }.
111 notation > "t [ term 90 a / term 90 b]" non associative with precedence 19 for @{ 'substitution $b $a $t }.
112 interpretation "Substitution for Formula" 'substitution b a t = (subst b a t).
113 definition equiv ≝ λF1,F2. ∀v.[[ F1 ]]_v = [[ F2 ]]_v.
114 notation "hvbox(a \nbsp break mstyle color #0000ff (≡) \nbsp b)"  non associative with precedence 45 for @{ 'equivF $a $b }.
115 notation > "a ≡ b" non associative with precedence 50 for @{ equiv $a $b }.
116 interpretation "equivalence for Formulas" 'equivF a b = (equiv a b).
117
118 theorem shannon : 
119   ∀F,x,v. [[ if eqb [[FAtom x]]_v 0 then F[FBot/x] else (F[FTop/x]) ]]_v = [[F]]_v.
120 assume F : Formula.
121 assume x : ℕ.
122 assume v : (ℕ → ℕ).
123 we proceed by induction on F to prove ([[ if eqb [[FAtom x]]_v 0 then F[FBot/x] else (F[FTop/x]) ]]_v = [[F]]_v).
124 case FBot.
125   the thesis becomes ([[ if eqb [[FAtom x]]_v 0 then FBot[FBot/x] else (FBot[FTop/x]) ]]_v = [[FBot]]_v). 
126   we proceed by cases on (eqb [[ FAtom x ]]_v 0) 
127     to prove ([[ if eqb [[FAtom x]]_v 0 then FBot[FBot/x] else (FBot[FTop/x]) ]]_v = [[FBot]]_v).
128   case true.
129     the thesis becomes ([[ if true then FBot[FBot/x] else (FBot[FTop/x]) ]]_v = [[FBot]]_v).
130     the thesis becomes ([[ FBot[FBot/x]]]_v = [[FBot]]_v).
131     the thesis becomes ([[ FBot ]]_v = [[FBot]]_v).
132     the thesis becomes (0 = 0).
133     done.
134   case false.
135     done.
136 case FTop.
137   we proceed by cases on (eqb [[ FAtom x ]]_v 0)
138     to prove ([[ if eqb [[FAtom x]]_v 0 then FTop[FBot/x] else (FTop[FTop/x]) ]]_v = [[FTop]]_v).
139   case true.
140     done.
141   case false.
142     done.     
143 case FAtom.
144   assume n : ℕ.
145   the thesis becomes ([[ if eqb [[ FAtom x ]]_v O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v = [[ FAtom n ]]_ v).
146   by decidable_eq_nat we proved (n = x ∨ n ≠ x) (H).
147   by sem_bool we proved ([[ FAtom x ]]_v = 0 ∨ [[ FAtom x ]]_v = 1) (H1).
148   we proceed by cases on H to prove 
149     ([[ if eqb [[ FAtom x ]]_v O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v = [[ FAtom n ]]_ v).
150   case Left. (* H2 : n = x *)
151     we proceed by cases on H1 to prove 
152       ([[ if eqb [[ FAtom x ]]_v O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v = [[ FAtom n ]]_ v).
153     case Left. (* H3 : [[ FAtom x ]]_v = 0 *)
154       conclude 
155           ([[ if eqb [[ FAtom x ]]_v O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v)
156         = ([[ if eqb 0 0 then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v) by H3.
157         = ([[ if true then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v).
158         = ([[ (FAtom n)[ FBot/x ] ]]_v).
159         = ([[ if eqb n x then FBot else (FAtom  n) ]]_v).
160         = ([[ if eqb n n then FBot else (FAtom  n) ]]_v) by H2.
161         = ([[ if true then FBot else (FAtom  n) ]]_v) by eqb_n_n.
162         = ([[ FBot ]]_v).
163         = 0.
164         = [[ FAtom x ]]_v by H3.
165         = [[ FAtom n ]]_v by H2.
166       done.
167     case Right.
168       conclude 
169           ([[ if eqb [[ FAtom x ]]_v O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v)
170         = ([[ if eqb 1 0 then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v) by H3.
171         = ([[ if false then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v).
172         = ([[ (FAtom n)[ FTop/x ] ]]_v).
173         = ([[ if eqb n x then FTop else (FAtom  n) ]]_v).
174         = ([[ if eqb n n then FTop else (FAtom  n) ]]_v) by H2.
175         = ([[ if true then FTop else (FAtom  n) ]]_v) by eqb_n_n.
176         = ([[ FTop ]]_v).
177         = 1.
178         = [[ FAtom x ]]_v by H3.
179         = [[ FAtom n ]]_v by H2.
180       done.
181   case Right.
182     we proceed by cases on H1 to prove 
183       ([[ if eqb [[ FAtom x ]]_v O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v = [[ FAtom n ]]_ v).
184     case Left.
185       conclude 
186           ([[ if eqb [[ FAtom x ]]_v O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v)
187         = ([[ if eqb 0 O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v) by H3.  
188         = [[ (FAtom n)[ FBot/x ] ]]_v.
189         = [[ if eqb n x then FBot else (FAtom n) ]]_v.
190         = [[ if false then FBot else (FAtom n) ]]_v by (not_eq_to_eqb_false ?? H2).
191         = [[ FAtom n ]]_v. 
192       done.
193     case Right.
194       conclude 
195           ([[ if eqb [[ FAtom x ]]_v O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v)
196         = ([[ if eqb 1 O then (FAtom n)[ FBot/x ] else (FAtom n[ FTop/x ]) ]]_v) by H3.  
197         = [[ FAtom n[ FTop/x ] ]]_v.
198         = [[ if eqb n x then FTop else (FAtom n) ]]_v.
199         = [[ if false then FTop else (FAtom n) ]]_v by (not_eq_to_eqb_false ?? H2).
200         = [[ FAtom n ]]_v. 
201       done.
202 case FAnd.
203   assume f : Formula.
204   by induction hypothesis we know ([[ if eqb [[ FAtom x ]]_v O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H).
205   assume f1 : Formula.
206   by induction hypothesis we know ([[ if eqb [[ FAtom x ]]_v O then f1[ FBot/x ] else (f1[ FTop/x ])  ]]_v = [[ f1 ]]_v) (H1).
207   the thesis becomes 
208     ([[ if eqb [[ FAtom x ]]_v O then ((FAnd f f1)[ FBot/x ]) else ((FAnd f f1)[ FTop/x ]) ]]_v = [[ FAnd f f1 ]]_v).
209   by sem_bool we proved ([[ FAtom x ]]_v = 0 ∨ [[ FAtom x ]]_v = 1) (H2).
210   we proceed by cases on H2 to prove 
211     ([[ if eqb [[ FAtom x ]]_v O then ((FAnd f f1)[ FBot/x ]) else ((FAnd f f1)[ FTop/x ]) ]]_v = [[ FAnd f f1 ]]_v).
212   case Left.
213     by H3, H we proved 
214       ([[ if eqb 0 O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H4).
215     by H4 we proved ([[ f[FBot/x ] ]]_v = [[ f ]]_v) (H5).
216     by H3, H1 we proved 
217       ([[ if eqb 0 O then f1[ FBot/x ] else (f1[ FTop/x ])  ]]_v = [[ f1 ]]_v) (H6).
218     by H6 we proved ([[ f1[FBot/x ] ]]_v = [[ f1 ]]_v) (H7).
219     conclude
220         ([[ if eqb [[ FAtom x ]]_v O then ((FAnd f f1)[ FBot/x ]) else ((FAnd f f1)[ FTop/x ]) ]]_v)
221       = ([[ if eqb 0 O then ((FAnd f f1)[ FBot/x ]) else ((FAnd f f1)[ FTop/x ]) ]]_v) by H3.
222       = ([[ if true then ((FAnd f f1)[ FBot/x ]) else ((FAnd f f1)[ FTop/x ]) ]]_v).
223       = ([[ (FAnd f f1)[ FBot/x ] ]]_v).
224       = ([[ FAnd (f[ FBot/x ]) (f1[ FBot/x ]) ]]_v).
225       = (min [[ f[ FBot/x ] ]]_v [[ f1[ FBot/x ] ]]_v).
226       = (min [[ f ]]_v [[ f1[ FBot/x ] ]]_v) by H5.
227       = (min [[ f ]]_v [[ f1 ]]_v) by H6.
228       = ([[ FAnd f f1 ]]_v).
229     done.
230   case Right.
231     by H3, H we proved 
232       ([[ if eqb 1 O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H4).
233     by H4 we proved ([[ f[FTop/x ] ]]_v = [[ f ]]_v) (H5).
234     by H3, H1 we proved 
235       ([[ if eqb 1 O then f1[ FBot/x ] else (f1[ FTop/x ])  ]]_v = [[ f1 ]]_v) (H6).
236     by H6 we proved ([[ f1[FTop/x ] ]]_v = [[ f1 ]]_v) (H7).
237     conclude
238         ([[ if eqb [[ FAtom x ]]_v O then ((FAnd f f1)[ FBot/x ]) else ((FAnd f f1)[ FTop/x ]) ]]_v)
239       = ([[ if eqb 1 O then ((FAnd f f1)[ FBot/x ]) else ((FAnd f f1)[ FTop/x ]) ]]_v) by H3.
240       = ([[ if false then ((FAnd f f1)[ FBot/x ]) else ((FAnd f f1)[ FTop/x ]) ]]_v).
241       = ([[ (FAnd f f1)[ FTop/x ] ]]_v).
242       = ([[ FAnd (f[ FTop/x ]) (f1[ FTop/x ]) ]]_v).
243       = (min [[ f[ FTop/x ] ]]_v [[ f1[ FTop/x ] ]]_v).
244       = (min [[ f ]]_v [[ f1[ FTop/x ] ]]_v) by H5.
245       = (min [[ f ]]_v [[ f1 ]]_v) by H6.
246       = ([[ FAnd f f1 ]]_v).
247     done.
248 case FOr.
249   assume f : Formula.
250   by induction hypothesis we know ([[ if eqb [[ FAtom x ]]_v O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H).
251   assume f1 : Formula.
252   by induction hypothesis we know ([[ if eqb [[ FAtom x ]]_v O then f1[ FBot/x ] else (f1[ FTop/x ])  ]]_v = [[ f1 ]]_v) (H1).
253   the thesis becomes 
254     ([[ if eqb [[ FAtom x ]]_v O then ((FOr f f1)[ FBot/x ]) else ((FOr f f1)[ FTop/x ]) ]]_v = [[ FOr f f1 ]]_v).
255   by sem_bool we proved ([[ FAtom x ]]_v = 0 ∨ [[ FAtom x ]]_v = 1) (H2).
256   we proceed by cases on H2 to prove 
257     ([[ if eqb [[ FAtom x ]]_v O then ((FOr f f1)[ FBot/x ]) else ((FOr f f1)[ FTop/x ]) ]]_v = [[ FOr f f1 ]]_v).
258   case Left.
259     by H3, H we proved 
260       ([[ if eqb 0 O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H4).
261     by H4 we proved ([[ f[FBot/x ] ]]_v = [[ f ]]_v) (H5).
262     by H3, H1 we proved 
263       ([[ if eqb 0 O then f1[ FBot/x ] else (f1[ FTop/x ])  ]]_v = [[ f1 ]]_v) (H6).
264     by H6 we proved ([[ f1[FBot/x ] ]]_v = [[ f1 ]]_v) (H7).
265     conclude
266         ([[ if eqb [[ FAtom x ]]_v O then ((FOr f f1)[ FBot/x ]) else ((FOr f f1)[ FTop/x ]) ]]_v)
267       = ([[ if eqb 0 O then ((FOr f f1)[ FBot/x ]) else ((FOr f f1)[ FTop/x ]) ]]_v) by H3.
268       = ([[ if true then ((FOr f f1)[ FBot/x ]) else ((FOr f f1)[ FTop/x ]) ]]_v).
269       = ([[ (FOr f f1)[ FBot/x ] ]]_v).
270       = ([[ FOr (f[ FBot/x ]) (f1[ FBot/x ]) ]]_v).
271       = (max [[ f[ FBot/x ] ]]_v [[ f1[ FBot/x ] ]]_v).
272       = (max [[ f ]]_v [[ f1[ FBot/x ] ]]_v) by H5.
273       = (max [[ f ]]_v [[ f1 ]]_v) by H6.
274       = ([[ FOr f f1 ]]_v).
275     done.
276   case Right.
277     by H3, H we proved 
278       ([[ if eqb 1 O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H4).
279     by H4 we proved ([[ f[FTop/x ] ]]_v = [[ f ]]_v) (H5).
280     by H3, H1 we proved 
281       ([[ if eqb 1 O then f1[ FBot/x ] else (f1[ FTop/x ])  ]]_v = [[ f1 ]]_v) (H6).
282     by H6 we proved ([[ f1[FTop/x ] ]]_v = [[ f1 ]]_v) (H7).
283     conclude
284         ([[ if eqb [[ FAtom x ]]_v O then ((FOr f f1)[ FBot/x ]) else ((FOr f f1)[ FTop/x ]) ]]_v)
285       = ([[ if eqb 1 O then ((FOr f f1)[ FBot/x ]) else ((FOr f f1)[ FTop/x ]) ]]_v) by H3.
286       = ([[ if false then ((FOr f f1)[ FBot/x ]) else ((FOr f f1)[ FTop/x ]) ]]_v).
287       = ([[ (FOr f f1)[ FTop/x ] ]]_v).
288       = ([[ FOr (f[ FTop/x ]) (f1[ FTop/x ]) ]]_v).
289       = (max [[ f[ FTop/x ] ]]_v [[ f1[ FTop/x ] ]]_v).
290       = (max [[ f ]]_v [[ f1[ FTop/x ] ]]_v) by H5.
291       = (max [[ f ]]_v [[ f1 ]]_v) by H6.
292       = ([[ FOr f f1 ]]_v).
293     done.
294 case FImpl.
295   assume f : Formula.
296   by induction hypothesis we know ([[ if eqb [[ FAtom x ]]_v O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H).
297   assume f1 : Formula.
298   by induction hypothesis we know ([[ if eqb [[ FAtom x ]]_v O then f1[ FBot/x ] else (f1[ FTop/x ])  ]]_v = [[ f1 ]]_v) (H1).
299   the thesis becomes 
300     ([[ if eqb [[ FAtom x ]]_v O then ((FImpl f f1)[ FBot/x ]) else ((FImpl f f1)[ FTop/x ]) ]]_v = [[ FImpl f f1 ]]_v).
301   by sem_bool we proved ([[ FAtom x ]]_v = 0 ∨ [[ FAtom x ]]_v = 1) (H2).
302   we proceed by cases on H2 to prove 
303     ([[ if eqb [[ FAtom x ]]_v O then ((FImpl f f1)[ FBot/x ]) else ((FImpl f f1)[ FTop/x ]) ]]_v = [[ FImpl f f1 ]]_v).
304   case Left.
305     by H3, H we proved 
306       ([[ if eqb 0 O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H4).
307     by H4 we proved ([[ f[FBot/x ] ]]_v = [[ f ]]_v) (H5).
308     by H3, H1 we proved 
309       ([[ if eqb 0 O then f1[ FBot/x ] else (f1[ FTop/x ])  ]]_v = [[ f1 ]]_v) (H6).
310     by H6 we proved ([[ f1[FBot/x ] ]]_v = [[ f1 ]]_v) (H7).
311     conclude
312         ([[ if eqb [[ FAtom x ]]_v O then ((FImpl f f1)[ FBot/x ]) else ((FImpl f f1)[ FTop/x ]) ]]_v)
313       = ([[ if eqb 0 O then ((FImpl f f1)[ FBot/x ]) else ((FImpl f f1)[ FTop/x ]) ]]_v) by H3.
314       = ([[ if true then ((FImpl f f1)[ FBot/x ]) else ((FImpl f f1)[ FTop/x ]) ]]_v).
315       = ([[ (FImpl f f1)[ FBot/x ] ]]_v).
316       = ([[ FImpl (f[ FBot/x ]) (f1[ FBot/x ]) ]]_v).
317       = (max (1 - [[ f[ FBot/x ] ]]_v) [[ f1[ FBot/x ] ]]_v).
318       = (max (1 -  [[ f ]]_v) [[ f1[ FBot/x ] ]]_v) by H5.
319       = (max (1 -  [[ f ]]_v) [[ f1 ]]_v) by H6.
320       = ([[ FImpl f f1 ]]_v).
321     done.
322   case Right.
323     by H3, H we proved 
324       ([[ if eqb 1 O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H4).
325     by H4 we proved ([[ f[FTop/x ] ]]_v = [[ f ]]_v) (H5).
326     by H3, H1 we proved 
327       ([[ if eqb 1 O then f1[ FBot/x ] else (f1[ FTop/x ])  ]]_v = [[ f1 ]]_v) (H6).
328     by H6 we proved ([[ f1[FTop/x ] ]]_v = [[ f1 ]]_v) (H7).
329     conclude
330         ([[ if eqb [[ FAtom x ]]_v O then ((FImpl f f1)[ FBot/x ]) else ((FImpl f f1)[ FTop/x ]) ]]_v)
331       = ([[ if eqb 1 O then ((FImpl f f1)[ FBot/x ]) else ((FImpl f f1)[ FTop/x ]) ]]_v) by H3.
332       = ([[ if false then ((FImpl f f1)[ FBot/x ]) else ((FImpl f f1)[ FTop/x ]) ]]_v).
333       = ([[ (FImpl f f1)[ FTop/x ] ]]_v).
334       = ([[ FImpl (f[ FTop/x ]) (f1[ FTop/x ]) ]]_v).
335       = (max (1 - [[ f[ FTop/x ] ]]_v) [[ f1[ FTop/x ] ]]_v).
336       = (max (1 - [[ f ]]_v) [[ f1[ FTop/x ] ]]_v) by H5.
337       = (max (1 - [[ f ]]_v) [[ f1 ]]_v) by H6.
338       = ([[ FImpl f f1 ]]_v).
339     done.
340 case FNot.
341   assume f : Formula.
342   by induction hypothesis we know ([[ if eqb [[ FAtom x ]]_v O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H).
343   the thesis becomes 
344     ([[ if eqb [[ FAtom x ]]_v O then ((FNot f)[ FBot/x ]) else ((FNot f)[ FTop/x ]) ]]_v = [[ FNot f ]]_v).
345   by sem_bool we proved ([[ FAtom x ]]_v = 0 ∨ [[ FAtom x ]]_v = 1) (H2).
346   we proceed by cases on H2 to prove 
347     ([[ if eqb [[ FAtom x ]]_v O then ((FNot f)[ FBot/x ]) else ((FNot f)[ FTop/x ]) ]]_v = [[ FNot f ]]_v).
348   case Left.
349     by H1, H we proved 
350       ([[ if eqb 0 O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H4).
351     by H4 we proved ([[ f[FBot/x ] ]]_v = [[ f ]]_v) (H5).
352     conclude
353         ([[ if eqb [[ FAtom x ]]_v O then ((FNot f)[ FBot/x ]) else ((FNot f)[ FTop/x ]) ]]_v)
354       = ([[ if eqb 0 O then ((FNot f)[ FBot/x ]) else ((FNot f)[ FTop/x ]) ]]_v) by H1.
355       = ([[ if true then ((FNot f)[ FBot/x ]) else ((FNot f)[ FTop/x ]) ]]_v).
356       = ([[ (FNot f)[ FBot/x ] ]]_v).
357       = ([[ FNot (f[ FBot/x ]) ]]_v).
358       change with (1 - [[ f[ FBot/x ] ]]_v = [[ FNot f ]]_v).
359       = (1 - [[ f ]]_v) by H5.
360       change with ([[ FNot f ]]_v = [[ FNot f ]]_v).
361     done.
362   case Right.
363     by H1, H we proved 
364       ([[ if eqb 1 O then f[ FBot/x ] else (f[ FTop/x ])  ]]_v = [[ f ]]_v) (H4).
365     by H4 we proved ([[ f[FTop/x ] ]]_v = [[ f ]]_v) (H5).
366     conclude
367         ([[ if eqb [[ FAtom x ]]_v O then ((FNot f)[ FBot/x ]) else ((FNot f)[ FTop/x ]) ]]_v)
368       = ([[ if eqb 1 O then ((FNot f)[ FBot/x ]) else ((FNot f)[ FTop/x ]) ]]_v) by H1.
369       = ([[ if false then ((FNot f)[ FBot/x ]) else ((FNot f)[ FTop/x ]) ]]_v).
370       = ([[ (FNot f)[ FTop/x ] ]]_v).
371       = ([[ FNot (f[ FTop/x ]) ]]_v).
372       change with (1 - [[ f[ FTop/x ] ]]_v = [[ FNot f ]]_v) .
373       = (1 - [[ f ]]_v) by H5.
374       change with ([[ FNot f ]]_v = [[ FNot f ]]_v).
375     done.
376 qed.
377
378 let rec maxatom (F : Formula) on F : ℕ ≝
379   match F with
380   [ FTop ⇒ 0
381   | FBot ⇒ 0
382   | FAtom n ⇒ n
383   | FAnd F1 F2 ⇒ max (maxatom F1) (maxatom F2)
384   | FOr F1 F2 ⇒ max (maxatom F1) (maxatom F2)
385   | FImpl F1 F2 ⇒ max (maxatom F1) (maxatom F2)
386   | FNot F1 ⇒ maxatom F1
387   ]
388 .
389
390 let rec expandall (F : Formula) (v : ℕ → ℕ) (n : nat) on n: Formula ≝
391   match n with
392   [ O ⇒ F
393   | S m ⇒ 
394       if eqb [[ FAtom n ]]_v 0 
395       then (expandall F v m)[FBot/n] 
396       else ((expandall F v m)[FTop/n])
397   ]
398 .
399
400 lemma BDD : ∀F,n,v. [[ expandall F v n ]]_v = [[ F ]]_v.
401 intros; elim n; simplify; [reflexivity]
402 cases (sem_bool (FAtom (S n1)) v); simplify in H1; rewrite > H1; simplify;
403 [ lapply (shannon (expandall F v n1) (S n1) v);
404   simplify in Hletin; rewrite > H1 in Hletin; simplify in Hletin;
405   rewrite > Hletin; assumption;
406 | lapply (shannon (expandall F v n1) (S n1) v);
407   simplify in Hletin; rewrite > H1 in Hletin; simplify in Hletin;
408   rewrite > Hletin; assumption;]
409 qed.