288 done |
281 done |
289 |
282 |
290 |
283 |
291 subsection "Proofs for delete" |
284 subsection "Proofs for delete" |
292 |
285 |
293 instantiation upD :: (type)height |
286 fun hD :: "'a upD \<Rightarrow> nat" where |
294 begin |
287 "hD (TD t) = height t" | |
295 |
288 "hD (UF t) = height t + 1" |
296 fun height_upD :: "'a upD \<Rightarrow> nat" where |
|
297 "height (TD t) = height t" | |
|
298 "height (UF t) = height t + 1" |
|
299 |
|
300 instance .. |
|
301 |
|
302 end |
|
303 |
289 |
304 lemma complete_treeD_node21: |
290 lemma complete_treeD_node21: |
305 "\<lbrakk>complete r; complete (treeD l'); height r = height l' \<rbrakk> \<Longrightarrow> complete (treeD (node21 l' a r))" |
291 "\<lbrakk>complete r; complete (treeD l'); height r = hD l' \<rbrakk> \<Longrightarrow> complete (treeD (node21 l' a r))" |
306 by(induct l' a r rule: node21.induct) auto |
292 by(induct l' a r rule: node21.induct) auto |
307 |
293 |
308 lemma complete_treeD_node22: |
294 lemma complete_treeD_node22: |
309 "\<lbrakk>complete(treeD r'); complete l; height r' = height l \<rbrakk> \<Longrightarrow> complete (treeD (node22 l a r'))" |
295 "\<lbrakk>complete(treeD r'); complete l; hD r' = height l \<rbrakk> \<Longrightarrow> complete (treeD (node22 l a r'))" |
310 by(induct l a r' rule: node22.induct) auto |
296 by(induct l a r' rule: node22.induct) auto |
311 |
297 |
312 lemma complete_treeD_node31: |
298 lemma complete_treeD_node31: |
313 "\<lbrakk> complete (treeD l'); complete m; complete r; height l' = height r; height m = height r \<rbrakk> |
299 "\<lbrakk> complete (treeD l'); complete m; complete r; hD l' = height r; height m = height r \<rbrakk> |
314 \<Longrightarrow> complete (treeD (node31 l' a m b r))" |
300 \<Longrightarrow> complete (treeD (node31 l' a m b r))" |
315 by(induct l' a m b r rule: node31.induct) auto |
301 by(induct l' a m b r rule: node31.induct) auto |
316 |
302 |
317 lemma complete_treeD_node32: |
303 lemma complete_treeD_node32: |
318 "\<lbrakk> complete l; complete (treeD m'); complete r; height l = height r; height m' = height r \<rbrakk> |
304 "\<lbrakk> complete l; complete (treeD m'); complete r; height l = height r; hD m' = height r \<rbrakk> |
319 \<Longrightarrow> complete (treeD (node32 l a m' b r))" |
305 \<Longrightarrow> complete (treeD (node32 l a m' b r))" |
320 by(induct l a m' b r rule: node32.induct) auto |
306 by(induct l a m' b r rule: node32.induct) auto |
321 |
307 |
322 lemma complete_treeD_node33: |
308 lemma complete_treeD_node33: |
323 "\<lbrakk> complete l; complete m; complete(treeD r'); height l = height r'; height m = height r' \<rbrakk> |
309 "\<lbrakk> complete l; complete m; complete(treeD r'); height l = hD r'; height m = hD r' \<rbrakk> |
324 \<Longrightarrow> complete (treeD (node33 l a m b r'))" |
310 \<Longrightarrow> complete (treeD (node33 l a m b r'))" |
325 by(induct l a m b r' rule: node33.induct) auto |
311 by(induct l a m b r' rule: node33.induct) auto |
326 |
312 |
327 lemmas completes = complete_treeD_node21 complete_treeD_node22 |
313 lemmas completes = complete_treeD_node21 complete_treeD_node22 |
328 complete_treeD_node31 complete_treeD_node32 complete_treeD_node33 |
314 complete_treeD_node31 complete_treeD_node32 complete_treeD_node33 |
329 |
315 |
330 lemma height'_node21: |
316 lemma height'_node21: |
331 "height r > 0 \<Longrightarrow> height(node21 l' a r) = max (height l') (height r) + 1" |
317 "height r > 0 \<Longrightarrow> hD(node21 l' a r) = max (hD l') (height r) + 1" |
332 by(induct l' a r rule: node21.induct)(simp_all) |
318 by(induct l' a r rule: node21.induct)(simp_all) |
333 |
319 |
334 lemma height'_node22: |
320 lemma height'_node22: |
335 "height l > 0 \<Longrightarrow> height(node22 l a r') = max (height l) (height r') + 1" |
321 "height l > 0 \<Longrightarrow> hD(node22 l a r') = max (height l) (hD r') + 1" |
336 by(induct l a r' rule: node22.induct)(simp_all) |
322 by(induct l a r' rule: node22.induct)(simp_all) |
337 |
323 |
338 lemma height'_node31: |
324 lemma height'_node31: |
339 "height m > 0 \<Longrightarrow> height(node31 l a m b r) = |
325 "height m > 0 \<Longrightarrow> hD(node31 l a m b r) = |
340 max (height l) (max (height m) (height r)) + 1" |
326 max (hD l) (max (height m) (height r)) + 1" |
341 by(induct l a m b r rule: node31.induct)(simp_all add: max_def) |
327 by(induct l a m b r rule: node31.induct)(simp_all add: max_def) |
342 |
328 |
343 lemma height'_node32: |
329 lemma height'_node32: |
344 "height r > 0 \<Longrightarrow> height(node32 l a m b r) = |
330 "height r > 0 \<Longrightarrow> hD(node32 l a m b r) = |
345 max (height l) (max (height m) (height r)) + 1" |
331 max (height l) (max (hD m) (height r)) + 1" |
346 by(induct l a m b r rule: node32.induct)(simp_all add: max_def) |
332 by(induct l a m b r rule: node32.induct)(simp_all add: max_def) |
347 |
333 |
348 lemma height'_node33: |
334 lemma height'_node33: |
349 "height m > 0 \<Longrightarrow> height(node33 l a m b r) = |
335 "height m > 0 \<Longrightarrow> hD(node33 l a m b r) = |
350 max (height l) (max (height m) (height r)) + 1" |
336 max (height l) (max (height m) (hD r)) + 1" |
351 by(induct l a m b r rule: node33.induct)(simp_all add: max_def) |
337 by(induct l a m b r rule: node33.induct)(simp_all add: max_def) |
352 |
338 |
353 lemmas heights = height'_node21 height'_node22 |
339 lemmas heights = height'_node21 height'_node22 |
354 height'_node31 height'_node32 height'_node33 |
340 height'_node31 height'_node32 height'_node33 |
355 |
341 |
356 lemma height_split_min: |
342 lemma height_split_min: |
357 "split_min t = (x, t') \<Longrightarrow> height t > 0 \<Longrightarrow> complete t \<Longrightarrow> height t' = height t" |
343 "split_min t = (x, t') \<Longrightarrow> height t > 0 \<Longrightarrow> complete t \<Longrightarrow> hD t' = height t" |
358 by(induct t arbitrary: x t' rule: split_min.induct) |
344 by(induct t arbitrary: x t' rule: split_min.induct) |
359 (auto simp: heights split: prod.splits) |
345 (auto simp: heights split: prod.splits) |
360 |
346 |
361 lemma height_del: "complete t \<Longrightarrow> height(del x t) = height t" |
347 lemma height_del: "complete t \<Longrightarrow> hD(del x t) = height t" |
362 by(induction x t rule: del.induct) |
348 by(induction x t rule: del.induct) |
363 (auto simp: heights max_def height_split_min split: prod.splits) |
349 (auto simp: heights max_def height_split_min split: prod.splits) |
364 |
350 |
365 lemma complete_split_min: |
351 lemma complete_split_min: |
366 "\<lbrakk> split_min t = (x, t'); complete t; height t > 0 \<rbrakk> \<Longrightarrow> complete (treeD t')" |
352 "\<lbrakk> split_min t = (x, t'); complete t; height t > 0 \<rbrakk> \<Longrightarrow> complete (treeD t')" |