301 Some t'' \<Rightarrow> subtract r t'' |
301 Some t'' \<Rightarrow> subtract r t'' |
302 | None \<Rightarrow> None) |
302 | None \<Rightarrow> None) |
303 | None \<Rightarrow> None)" |
303 | None \<Rightarrow> None)" |
304 |
304 |
305 lemma subtract_Some_set_of_res: |
305 lemma subtract_Some_set_of_res: |
306 "subtract t\<^isub>1 t\<^isub>2 = Some t \<Longrightarrow> set_of t \<subseteq> set_of t\<^isub>2" |
306 "subtract t\<^sub>1 t\<^sub>2 = Some t \<Longrightarrow> set_of t \<subseteq> set_of t\<^sub>2" |
307 proof (induct t\<^isub>1 arbitrary: t\<^isub>2 t) |
307 proof (induct t\<^sub>1 arbitrary: t\<^sub>2 t) |
308 case Tip thus ?case by simp |
308 case Tip thus ?case by simp |
309 next |
309 next |
310 case (Node l x b r) |
310 case (Node l x b r) |
311 have sub: "subtract (Node l x b r) t\<^isub>2 = Some t" by fact |
311 have sub: "subtract (Node l x b r) t\<^sub>2 = Some t" by fact |
312 show ?case |
312 show ?case |
313 proof (cases "delete x t\<^isub>2") |
313 proof (cases "delete x t\<^sub>2") |
314 case (Some t\<^isub>2') |
314 case (Some t\<^sub>2') |
315 note del_x_Some = this |
315 note del_x_Some = this |
316 from delete_Some_set_of [OF Some] |
316 from delete_Some_set_of [OF Some] |
317 have t2'_t2: "set_of t\<^isub>2' \<subseteq> set_of t\<^isub>2" . |
317 have t2'_t2: "set_of t\<^sub>2' \<subseteq> set_of t\<^sub>2" . |
318 show ?thesis |
318 show ?thesis |
319 proof (cases "subtract l t\<^isub>2'") |
319 proof (cases "subtract l t\<^sub>2'") |
320 case (Some t\<^isub>2'') |
320 case (Some t\<^sub>2'') |
321 note sub_l_Some = this |
321 note sub_l_Some = this |
322 from Node.hyps (1) [OF Some] |
322 from Node.hyps (1) [OF Some] |
323 have t2''_t2': "set_of t\<^isub>2'' \<subseteq> set_of t\<^isub>2'" . |
323 have t2''_t2': "set_of t\<^sub>2'' \<subseteq> set_of t\<^sub>2'" . |
324 show ?thesis |
324 show ?thesis |
325 proof (cases "subtract r t\<^isub>2''") |
325 proof (cases "subtract r t\<^sub>2''") |
326 case (Some t\<^isub>2''') |
326 case (Some t\<^sub>2''') |
327 from Node.hyps (2) [OF Some ] |
327 from Node.hyps (2) [OF Some ] |
328 have "set_of t\<^isub>2''' \<subseteq> set_of t\<^isub>2''" . |
328 have "set_of t\<^sub>2''' \<subseteq> set_of t\<^sub>2''" . |
329 with Some sub_l_Some del_x_Some sub t2''_t2' t2'_t2 |
329 with Some sub_l_Some del_x_Some sub t2''_t2' t2'_t2 |
330 show ?thesis |
330 show ?thesis |
331 by simp |
331 by simp |
332 next |
332 next |
333 case None |
333 case None |
346 with sub show ?thesis by simp |
346 with sub show ?thesis by simp |
347 qed |
347 qed |
348 qed |
348 qed |
349 |
349 |
350 lemma subtract_Some_set_of: |
350 lemma subtract_Some_set_of: |
351 "subtract t\<^isub>1 t\<^isub>2 = Some t \<Longrightarrow> set_of t\<^isub>1 \<subseteq> set_of t\<^isub>2" |
351 "subtract t\<^sub>1 t\<^sub>2 = Some t \<Longrightarrow> set_of t\<^sub>1 \<subseteq> set_of t\<^sub>2" |
352 proof (induct t\<^isub>1 arbitrary: t\<^isub>2 t) |
352 proof (induct t\<^sub>1 arbitrary: t\<^sub>2 t) |
353 case Tip thus ?case by simp |
353 case Tip thus ?case by simp |
354 next |
354 next |
355 case (Node l x d r) |
355 case (Node l x d r) |
356 have sub: "subtract (Node l x d r) t\<^isub>2 = Some t" by fact |
356 have sub: "subtract (Node l x d r) t\<^sub>2 = Some t" by fact |
357 show ?case |
357 show ?case |
358 proof (cases "delete x t\<^isub>2") |
358 proof (cases "delete x t\<^sub>2") |
359 case (Some t\<^isub>2') |
359 case (Some t\<^sub>2') |
360 note del_x_Some = this |
360 note del_x_Some = this |
361 from delete_Some_set_of [OF Some] |
361 from delete_Some_set_of [OF Some] |
362 have t2'_t2: "set_of t\<^isub>2' \<subseteq> set_of t\<^isub>2" . |
362 have t2'_t2: "set_of t\<^sub>2' \<subseteq> set_of t\<^sub>2" . |
363 from delete_None_set_of_conv [of x t\<^isub>2] Some |
363 from delete_None_set_of_conv [of x t\<^sub>2] Some |
364 have x_t2: "x \<in> set_of t\<^isub>2" |
364 have x_t2: "x \<in> set_of t\<^sub>2" |
365 by simp |
365 by simp |
366 show ?thesis |
366 show ?thesis |
367 proof (cases "subtract l t\<^isub>2'") |
367 proof (cases "subtract l t\<^sub>2'") |
368 case (Some t\<^isub>2'') |
368 case (Some t\<^sub>2'') |
369 note sub_l_Some = this |
369 note sub_l_Some = this |
370 from Node.hyps (1) [OF Some] |
370 from Node.hyps (1) [OF Some] |
371 have l_t2': "set_of l \<subseteq> set_of t\<^isub>2'" . |
371 have l_t2': "set_of l \<subseteq> set_of t\<^sub>2'" . |
372 from subtract_Some_set_of_res [OF Some] |
372 from subtract_Some_set_of_res [OF Some] |
373 have t2''_t2': "set_of t\<^isub>2'' \<subseteq> set_of t\<^isub>2'" . |
373 have t2''_t2': "set_of t\<^sub>2'' \<subseteq> set_of t\<^sub>2'" . |
374 show ?thesis |
374 show ?thesis |
375 proof (cases "subtract r t\<^isub>2''") |
375 proof (cases "subtract r t\<^sub>2''") |
376 case (Some t\<^isub>2''') |
376 case (Some t\<^sub>2''') |
377 from Node.hyps (2) [OF Some ] |
377 from Node.hyps (2) [OF Some ] |
378 have r_t\<^isub>2'': "set_of r \<subseteq> set_of t\<^isub>2''" . |
378 have r_t\<^sub>2'': "set_of r \<subseteq> set_of t\<^sub>2''" . |
379 from Some sub_l_Some del_x_Some sub r_t\<^isub>2'' l_t2' t2'_t2 t2''_t2' x_t2 |
379 from Some sub_l_Some del_x_Some sub r_t\<^sub>2'' l_t2' t2'_t2 t2''_t2' x_t2 |
380 show ?thesis |
380 show ?thesis |
381 by auto |
381 by auto |
382 next |
382 next |
383 case None |
383 case None |
384 with del_x_Some sub_l_Some sub |
384 with del_x_Some sub_l_Some sub |
396 with sub show ?thesis by simp |
396 with sub show ?thesis by simp |
397 qed |
397 qed |
398 qed |
398 qed |
399 |
399 |
400 lemma subtract_Some_all_distinct_res: |
400 lemma subtract_Some_all_distinct_res: |
401 "subtract t\<^isub>1 t\<^isub>2 = Some t \<Longrightarrow> all_distinct t\<^isub>2 \<Longrightarrow> all_distinct t" |
401 "subtract t\<^sub>1 t\<^sub>2 = Some t \<Longrightarrow> all_distinct t\<^sub>2 \<Longrightarrow> all_distinct t" |
402 proof (induct t\<^isub>1 arbitrary: t\<^isub>2 t) |
402 proof (induct t\<^sub>1 arbitrary: t\<^sub>2 t) |
403 case Tip thus ?case by simp |
403 case Tip thus ?case by simp |
404 next |
404 next |
405 case (Node l x d r) |
405 case (Node l x d r) |
406 have sub: "subtract (Node l x d r) t\<^isub>2 = Some t" by fact |
406 have sub: "subtract (Node l x d r) t\<^sub>2 = Some t" by fact |
407 have dist_t2: "all_distinct t\<^isub>2" by fact |
407 have dist_t2: "all_distinct t\<^sub>2" by fact |
408 show ?case |
408 show ?case |
409 proof (cases "delete x t\<^isub>2") |
409 proof (cases "delete x t\<^sub>2") |
410 case (Some t\<^isub>2') |
410 case (Some t\<^sub>2') |
411 note del_x_Some = this |
411 note del_x_Some = this |
412 from delete_Some_all_distinct [OF Some dist_t2] |
412 from delete_Some_all_distinct [OF Some dist_t2] |
413 have dist_t2': "all_distinct t\<^isub>2'" . |
413 have dist_t2': "all_distinct t\<^sub>2'" . |
414 show ?thesis |
414 show ?thesis |
415 proof (cases "subtract l t\<^isub>2'") |
415 proof (cases "subtract l t\<^sub>2'") |
416 case (Some t\<^isub>2'') |
416 case (Some t\<^sub>2'') |
417 note sub_l_Some = this |
417 note sub_l_Some = this |
418 from Node.hyps (1) [OF Some dist_t2'] |
418 from Node.hyps (1) [OF Some dist_t2'] |
419 have dist_t2'': "all_distinct t\<^isub>2''" . |
419 have dist_t2'': "all_distinct t\<^sub>2''" . |
420 show ?thesis |
420 show ?thesis |
421 proof (cases "subtract r t\<^isub>2''") |
421 proof (cases "subtract r t\<^sub>2''") |
422 case (Some t\<^isub>2''') |
422 case (Some t\<^sub>2''') |
423 from Node.hyps (2) [OF Some dist_t2''] |
423 from Node.hyps (2) [OF Some dist_t2''] |
424 have dist_t2''': "all_distinct t\<^isub>2'''" . |
424 have dist_t2''': "all_distinct t\<^sub>2'''" . |
425 from Some sub_l_Some del_x_Some sub |
425 from Some sub_l_Some del_x_Some sub |
426 dist_t2''' |
426 dist_t2''' |
427 show ?thesis |
427 show ?thesis |
428 by simp |
428 by simp |
429 next |
429 next |
444 qed |
444 qed |
445 qed |
445 qed |
446 |
446 |
447 |
447 |
448 lemma subtract_Some_dist_res: |
448 lemma subtract_Some_dist_res: |
449 "subtract t\<^isub>1 t\<^isub>2 = Some t \<Longrightarrow> set_of t\<^isub>1 \<inter> set_of t = {}" |
449 "subtract t\<^sub>1 t\<^sub>2 = Some t \<Longrightarrow> set_of t\<^sub>1 \<inter> set_of t = {}" |
450 proof (induct t\<^isub>1 arbitrary: t\<^isub>2 t) |
450 proof (induct t\<^sub>1 arbitrary: t\<^sub>2 t) |
451 case Tip thus ?case by simp |
451 case Tip thus ?case by simp |
452 next |
452 next |
453 case (Node l x d r) |
453 case (Node l x d r) |
454 have sub: "subtract (Node l x d r) t\<^isub>2 = Some t" by fact |
454 have sub: "subtract (Node l x d r) t\<^sub>2 = Some t" by fact |
455 show ?case |
455 show ?case |
456 proof (cases "delete x t\<^isub>2") |
456 proof (cases "delete x t\<^sub>2") |
457 case (Some t\<^isub>2') |
457 case (Some t\<^sub>2') |
458 note del_x_Some = this |
458 note del_x_Some = this |
459 from delete_Some_x_set_of [OF Some] |
459 from delete_Some_x_set_of [OF Some] |
460 obtain x_t2: "x \<in> set_of t\<^isub>2" and x_not_t2': "x \<notin> set_of t\<^isub>2'" |
460 obtain x_t2: "x \<in> set_of t\<^sub>2" and x_not_t2': "x \<notin> set_of t\<^sub>2'" |
461 by simp |
461 by simp |
462 from delete_Some_set_of [OF Some] |
462 from delete_Some_set_of [OF Some] |
463 have t2'_t2: "set_of t\<^isub>2' \<subseteq> set_of t\<^isub>2" . |
463 have t2'_t2: "set_of t\<^sub>2' \<subseteq> set_of t\<^sub>2" . |
464 show ?thesis |
464 show ?thesis |
465 proof (cases "subtract l t\<^isub>2'") |
465 proof (cases "subtract l t\<^sub>2'") |
466 case (Some t\<^isub>2'') |
466 case (Some t\<^sub>2'') |
467 note sub_l_Some = this |
467 note sub_l_Some = this |
468 from Node.hyps (1) [OF Some ] |
468 from Node.hyps (1) [OF Some ] |
469 have dist_l_t2'': "set_of l \<inter> set_of t\<^isub>2'' = {}". |
469 have dist_l_t2'': "set_of l \<inter> set_of t\<^sub>2'' = {}". |
470 from subtract_Some_set_of_res [OF Some] |
470 from subtract_Some_set_of_res [OF Some] |
471 have t2''_t2': "set_of t\<^isub>2'' \<subseteq> set_of t\<^isub>2'" . |
471 have t2''_t2': "set_of t\<^sub>2'' \<subseteq> set_of t\<^sub>2'" . |
472 show ?thesis |
472 show ?thesis |
473 proof (cases "subtract r t\<^isub>2''") |
473 proof (cases "subtract r t\<^sub>2''") |
474 case (Some t\<^isub>2''') |
474 case (Some t\<^sub>2''') |
475 from Node.hyps (2) [OF Some] |
475 from Node.hyps (2) [OF Some] |
476 have dist_r_t2''': "set_of r \<inter> set_of t\<^isub>2''' = {}" . |
476 have dist_r_t2''': "set_of r \<inter> set_of t\<^sub>2''' = {}" . |
477 from subtract_Some_set_of_res [OF Some] |
477 from subtract_Some_set_of_res [OF Some] |
478 have t2'''_t2'': "set_of t\<^isub>2''' \<subseteq> set_of t\<^isub>2''". |
478 have t2'''_t2'': "set_of t\<^sub>2''' \<subseteq> set_of t\<^sub>2''". |
479 |
479 |
480 from Some sub_l_Some del_x_Some sub t2'''_t2'' dist_l_t2'' dist_r_t2''' |
480 from Some sub_l_Some del_x_Some sub t2'''_t2'' dist_l_t2'' dist_r_t2''' |
481 t2''_t2' t2'_t2 x_not_t2' |
481 t2''_t2' t2'_t2 x_not_t2' |
482 show ?thesis |
482 show ?thesis |
483 by auto |
483 by auto |
498 with sub show ?thesis by simp |
498 with sub show ?thesis by simp |
499 qed |
499 qed |
500 qed |
500 qed |
501 |
501 |
502 lemma subtract_Some_all_distinct: |
502 lemma subtract_Some_all_distinct: |
503 "subtract t\<^isub>1 t\<^isub>2 = Some t \<Longrightarrow> all_distinct t\<^isub>2 \<Longrightarrow> all_distinct t\<^isub>1" |
503 "subtract t\<^sub>1 t\<^sub>2 = Some t \<Longrightarrow> all_distinct t\<^sub>2 \<Longrightarrow> all_distinct t\<^sub>1" |
504 proof (induct t\<^isub>1 arbitrary: t\<^isub>2 t) |
504 proof (induct t\<^sub>1 arbitrary: t\<^sub>2 t) |
505 case Tip thus ?case by simp |
505 case Tip thus ?case by simp |
506 next |
506 next |
507 case (Node l x d r) |
507 case (Node l x d r) |
508 have sub: "subtract (Node l x d r) t\<^isub>2 = Some t" by fact |
508 have sub: "subtract (Node l x d r) t\<^sub>2 = Some t" by fact |
509 have dist_t2: "all_distinct t\<^isub>2" by fact |
509 have dist_t2: "all_distinct t\<^sub>2" by fact |
510 show ?case |
510 show ?case |
511 proof (cases "delete x t\<^isub>2") |
511 proof (cases "delete x t\<^sub>2") |
512 case (Some t\<^isub>2') |
512 case (Some t\<^sub>2') |
513 note del_x_Some = this |
513 note del_x_Some = this |
514 from delete_Some_all_distinct [OF Some dist_t2 ] |
514 from delete_Some_all_distinct [OF Some dist_t2 ] |
515 have dist_t2': "all_distinct t\<^isub>2'" . |
515 have dist_t2': "all_distinct t\<^sub>2'" . |
516 from delete_Some_set_of [OF Some] |
516 from delete_Some_set_of [OF Some] |
517 have t2'_t2: "set_of t\<^isub>2' \<subseteq> set_of t\<^isub>2" . |
517 have t2'_t2: "set_of t\<^sub>2' \<subseteq> set_of t\<^sub>2" . |
518 from delete_Some_x_set_of [OF Some] |
518 from delete_Some_x_set_of [OF Some] |
519 obtain x_t2: "x \<in> set_of t\<^isub>2" and x_not_t2': "x \<notin> set_of t\<^isub>2'" |
519 obtain x_t2: "x \<in> set_of t\<^sub>2" and x_not_t2': "x \<notin> set_of t\<^sub>2'" |
520 by simp |
520 by simp |
521 |
521 |
522 show ?thesis |
522 show ?thesis |
523 proof (cases "subtract l t\<^isub>2'") |
523 proof (cases "subtract l t\<^sub>2'") |
524 case (Some t\<^isub>2'') |
524 case (Some t\<^sub>2'') |
525 note sub_l_Some = this |
525 note sub_l_Some = this |
526 from Node.hyps (1) [OF Some dist_t2' ] |
526 from Node.hyps (1) [OF Some dist_t2' ] |
527 have dist_l: "all_distinct l" . |
527 have dist_l: "all_distinct l" . |
528 from subtract_Some_all_distinct_res [OF Some dist_t2'] |
528 from subtract_Some_all_distinct_res [OF Some dist_t2'] |
529 have dist_t2'': "all_distinct t\<^isub>2''" . |
529 have dist_t2'': "all_distinct t\<^sub>2''" . |
530 from subtract_Some_set_of [OF Some] |
530 from subtract_Some_set_of [OF Some] |
531 have l_t2': "set_of l \<subseteq> set_of t\<^isub>2'" . |
531 have l_t2': "set_of l \<subseteq> set_of t\<^sub>2'" . |
532 from subtract_Some_set_of_res [OF Some] |
532 from subtract_Some_set_of_res [OF Some] |
533 have t2''_t2': "set_of t\<^isub>2'' \<subseteq> set_of t\<^isub>2'" . |
533 have t2''_t2': "set_of t\<^sub>2'' \<subseteq> set_of t\<^sub>2'" . |
534 from subtract_Some_dist_res [OF Some] |
534 from subtract_Some_dist_res [OF Some] |
535 have dist_l_t2'': "set_of l \<inter> set_of t\<^isub>2'' = {}". |
535 have dist_l_t2'': "set_of l \<inter> set_of t\<^sub>2'' = {}". |
536 show ?thesis |
536 show ?thesis |
537 proof (cases "subtract r t\<^isub>2''") |
537 proof (cases "subtract r t\<^sub>2''") |
538 case (Some t\<^isub>2''') |
538 case (Some t\<^sub>2''') |
539 from Node.hyps (2) [OF Some dist_t2''] |
539 from Node.hyps (2) [OF Some dist_t2''] |
540 have dist_r: "all_distinct r" . |
540 have dist_r: "all_distinct r" . |
541 from subtract_Some_set_of [OF Some] |
541 from subtract_Some_set_of [OF Some] |
542 have r_t2'': "set_of r \<subseteq> set_of t\<^isub>2''" . |
542 have r_t2'': "set_of r \<subseteq> set_of t\<^sub>2''" . |
543 from subtract_Some_dist_res [OF Some] |
543 from subtract_Some_dist_res [OF Some] |
544 have dist_r_t2''': "set_of r \<inter> set_of t\<^isub>2''' = {}". |
544 have dist_r_t2''': "set_of r \<inter> set_of t\<^sub>2''' = {}". |
545 |
545 |
546 from dist_l dist_r Some sub_l_Some del_x_Some r_t2'' l_t2' x_t2 x_not_t2' |
546 from dist_l dist_r Some sub_l_Some del_x_Some r_t2'' l_t2' x_t2 x_not_t2' |
547 t2''_t2' dist_l_t2'' dist_r_t2''' |
547 t2''_t2' dist_l_t2'' dist_r_t2''' |
548 show ?thesis |
548 show ?thesis |
549 by auto |
549 by auto |