147 apply(subgoal_tac "insert RONE (insert RZERO (noalts_set \<union> alts_set)) = |
139 apply(subgoal_tac "insert RONE (insert RZERO (noalts_set \<union> alts_set)) = |
148 insert RZERO ((insert RONE noalts_set) \<union> alts_set)") |
140 insert RZERO ((insert RONE noalts_set) \<union> alts_set)") |
149 apply(simp only:) |
141 apply(simp only:) |
150 apply(subgoal_tac "rsizes (rdistinct rs (insert RZERO (insert RONE noalts_set \<union> alts_set))) |
142 apply(subgoal_tac "rsizes (rdistinct rs (insert RZERO (insert RONE noalts_set \<union> alts_set))) |
151 \<le> rsizes (RONE # rdistinct rs (insert RZERO (insert RONE noalts_set \<union> alts_set)))") |
143 \<le> rsizes (RONE # rdistinct rs (insert RZERO (insert RONE noalts_set \<union> alts_set)))") |
152 apply (smt (verit, best) dual_order.trans insert_iff rrexp.distinct(15)) |
144 apply (smt (verit, ccfv_threshold) dual_order.trans insertE rrexp.distinct(17)) |
153 apply (metis (no_types, opaque_lifting) le_add_same_cancel2 list.simps(9) sum_list.Cons zero_le) |
145 apply (metis (no_types, opaque_lifting) le_add_same_cancel2 list.simps(9) sum_list.Cons zero_le) |
154 apply fastforce |
146 apply fastforce |
155 apply fastforce |
147 apply fastforce |
156 apply (metis Un_iff insert_absorb) |
148 apply (metis Un_iff insert_absorb) |
157 apply (metis UnE insertE insert_is_Un rdistinct.simps(2) rrexp.distinct(1)) |
149 apply (metis UnE insertE insert_is_Un rdistinct.simps(2) rrexp.distinct(1)) |
158 apply (meson UnCI rdistinct.simps(2)) |
150 apply (meson UnCI rdistinct.simps(2)) |
159 using rflts.simps(4) apply presburger |
151 using rflts.simps(4) apply presburger |
160 apply simp |
152 apply simp |
161 apply(subgoal_tac "insert RONE (noalts_set \<union> corr_set) = (insert RONE noalts_set) \<union> corr_set") |
153 apply(subgoal_tac "insert RONE (noalts_set \<union> corr_set) = (insert RONE noalts_set) \<union> corr_set") |
162 apply(simp only:) |
154 apply(simp only:) |
163 apply (metis Un_insert_left insertE rrexp.distinct(15)) |
155 apply (metis Un_insert_left insertE rrexp.distinct(17)) |
164 apply fastforce |
156 apply fastforce |
165 apply(case_tac "a \<in> noalts_set") |
157 apply(case_tac "a \<in> noalts_set") |
166 apply simp |
158 apply simp |
167 apply(subgoal_tac "a \<notin> alts_set") |
159 apply(subgoal_tac "a \<notin> alts_set") |
168 prefer 2 |
160 prefer 2 |
378 using star_control_bounded[OF assms] by (metis add_mono le_add1 mult_Suc plus_1_eq_Suc) |
400 using star_control_bounded[OF assms] by (metis add_mono le_add1 mult_Suc plus_1_eq_Suc) |
379 also have "... \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * Suc (N + rsize (RSTAR r))) (rsize (RSTAR r))" |
401 also have "... \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * Suc (N + rsize (RSTAR r))) (rsize (RSTAR r))" |
380 by simp |
402 by simp |
381 finally show ?thesis by simp |
403 finally show ?thesis by simp |
382 qed |
404 qed |
|
405 |
|
406 |
|
407 thm ntimes_closed_form |
|
408 |
|
409 thm rsize.simps |
|
410 |
|
411 lemma nupdates_snoc: |
|
412 shows " (nupdates (xs @ [x]) r optlist) = nupdate x r (nupdates xs r optlist)" |
|
413 by (simp add: nupdates_append) |
|
414 |
|
415 lemma nupdate_elems: |
|
416 shows "\<forall>opt \<in> set (nupdate c r optlist). opt = None \<or> (\<exists>s n. opt = Some (s, n))" |
|
417 using nonempty_string.cases by auto |
|
418 |
|
419 lemma nupdates_elems: |
|
420 shows "\<forall>opt \<in> set (nupdates s r optlist). opt = None \<or> (\<exists>s n. opt = Some (s, n))" |
|
421 by (meson nonempty_string.cases) |
|
422 |
|
423 |
|
424 lemma opterm_optlist_result_shape: |
|
425 shows "\<forall>r' \<in> set (map (optermsimp r) optlist). r' = RZERO \<or> (\<exists>s m. r' = RSEQ (rders_simp r s) (RNTIMES r m))" |
|
426 apply(induct optlist) |
|
427 apply simp |
|
428 apply(case_tac a) |
|
429 apply simp+ |
|
430 by fastforce |
|
431 |
|
432 |
|
433 lemma opterm_optlist_result_shape2: |
|
434 shows "\<And>optlist. \<forall>r' \<in> set (map (optermsimp r) optlist). r' = RZERO \<or> (\<exists>s m. r' = RSEQ (rders_simp r s) (RNTIMES r m))" |
|
435 using opterm_optlist_result_shape by presburger |
|
436 |
|
437 |
|
438 lemma nupdate_n_leq_n: |
|
439 shows "\<forall>r \<in> set (nupdate c' r [Some ([c], n)]). r = None \<or>( \<exists>s' m. r = Some (s', m) \<and> m \<le> n)" |
|
440 apply(case_tac n) |
|
441 apply simp |
|
442 apply simp |
|
443 done |
|
444 (* |
|
445 lemma nupdate_induct_leqn: |
|
446 shows "\<lbrakk>\<forall>opt \<in> set optlist. opt = None \<or> (\<exists>s' m. opt = Some(s', m) \<and> m \<le> n) \<rbrakk> \<Longrightarrow> |
|
447 \<forall>opt \<in> set (nupdate c' r optlist). opt = None \<or> (\<exists>s' m. opt = Some (s', m) \<and> m \<le> n)" |
|
448 apply (case_tac optlist) |
|
449 apply simp |
|
450 apply(case_tac a) |
|
451 apply simp |
|
452 sledgehammer |
|
453 *) |
|
454 |
|
455 |
|
456 lemma nupdates_n_leq_n: |
|
457 shows "\<forall>r \<in> set (nupdates s r [Some ([c], n)]). r = None \<or>( \<exists>s' m. r = Some (s', m) \<and> m \<le> n)" |
|
458 apply(induct s rule: rev_induct) |
|
459 apply simp |
|
460 apply(subst nupdates_append) |
|
461 by (metis nupdates_elems_leqn nupdates_snoc) |
|
462 |
|
463 |
|
464 |
|
465 lemma ntimes_closed_form_list_elem_shape: |
|
466 shows "\<forall>r' \<in> set (map (optermsimp r) (nupdates s r [Some ([c], n)])). |
|
467 r' = RZERO \<or> (\<exists>s' m. r' = RSEQ (rders_simp r s') (RNTIMES r m) \<and> m \<le> n)" |
|
468 apply(insert opterm_optlist_result_shape2) |
|
469 apply(case_tac s) |
|
470 apply(auto) |
|
471 apply (metis rders_simp_one_char) |
|
472 by (metis case_prod_conv nupdates.simps(2) nupdates_n_leq_n option.simps(4) option.simps(5)) |
|
473 |
|
474 |
|
475 lemma ntimes_trivial1: |
|
476 shows "rsize RZERO \<le> N + rsize (RNTIMES r n)" |
|
477 by simp |
|
478 |
|
479 |
|
480 lemma ntimes_trivial20: |
|
481 shows "m \<le> n \<Longrightarrow> rsize (RNTIMES r m) \<le> rsize (RNTIMES r n)" |
|
482 by simp |
|
483 |
|
484 |
|
485 lemma ntimes_trivial2: |
|
486 assumes "\<forall>s. rsize (rders_simp r s) \<le> N" |
|
487 shows " r' = RSEQ (rders_simp r s1) (RNTIMES r m) \<and> m \<le> n |
|
488 \<Longrightarrow> rsize r' \<le> Suc (N + rsize (RNTIMES r n))" |
|
489 apply simp |
|
490 by (simp add: add_mono_thms_linordered_semiring(1) assms) |
|
491 |
|
492 lemma ntimes_closed_form_list_elem_bounded: |
|
493 assumes "\<forall>s. rsize (rders_simp r s) \<le> N" |
|
494 shows "\<forall>r' \<in> set (map (optermsimp r) (nupdates s r [Some ([c], n)])). rsize r' \<le> Suc (N + rsize (RNTIMES r n))" |
|
495 apply(rule ballI) |
|
496 apply(subgoal_tac "r' = RZERO \<or> (\<exists>s' m. r' = RSEQ (rders_simp r s') (RNTIMES r m) \<and> m \<le> n)") |
|
497 prefer 2 |
|
498 using ntimes_closed_form_list_elem_shape apply blast |
|
499 apply(case_tac "r' = RZERO") |
|
500 using le_SucI ntimes_trivial1 apply presburger |
|
501 apply(subgoal_tac "\<exists>s1 m. r' = RSEQ (rders_simp r s1) (RNTIMES r m) \<and> m \<le> n") |
|
502 apply(erule exE)+ |
|
503 using assms ntimes_trivial2 apply presburger |
|
504 by blast |
|
505 |
|
506 |
|
507 lemma P_holds_after_distinct: |
|
508 assumes "\<forall>r \<in> set rs. P r" |
|
509 shows "\<forall>r \<in> set (rdistinct rs rset). P r" |
|
510 by (simp add: assms rdistinct_set_equality1) |
|
511 |
|
512 lemma ntimes_control_bounded: |
|
513 assumes "\<forall>s. rsize (rders_simp r s) \<le> N" |
|
514 shows "rsizes (rdistinct (map (optermsimp r) (nupdates s r [Some ([c], n)])) {}) |
|
515 \<le> (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * (Suc (N + rsize (RNTIMES r n)))" |
|
516 apply(subgoal_tac "\<forall>r' \<in> set (rdistinct (map (optermsimp r) (nupdates s r [Some ([c], n)])) {}). |
|
517 rsize r' \<le> Suc (N + rsize (RNTIMES r n))") |
|
518 apply (meson distinct_list_rexp_upto rdistinct_same_set) |
|
519 apply(subgoal_tac "\<forall>r' \<in> set (map (optermsimp r) (nupdates s r [Some ([c], n)])). rsize r' \<le> Suc (N + rsize (RNTIMES r n))") |
|
520 apply (simp add: rdistinct_set_equality) |
|
521 by (metis assms nat_le_linear not_less_eq_eq ntimes_closed_form_list_elem_bounded) |
|
522 |
|
523 |
|
524 |
|
525 lemma ntimes_closed_form_bounded0: |
|
526 assumes "\<forall>s. rsize (rders_simp r s) \<le> N" |
|
527 shows " (rders_simp (RNTIMES r 0) s) = RZERO \<or> (rders_simp (RNTIMES r 0) s) = RNTIMES r 0 |
|
528 " |
|
529 apply(induct s) |
|
530 apply simp |
|
531 by (metis always0 list.simps(3) rder.simps(7) rders.simps(2) rders_simp_same_simpders rsimp.simps(3)) |
|
532 |
|
533 lemma ntimes_closed_form_bounded1: |
|
534 assumes "\<forall>s. rsize (rders_simp r s) \<le> N" |
|
535 shows " rsize (rders_simp (RNTIMES r 0) s) \<le> max (rsize RZERO) (rsize (RNTIMES r 0))" |
|
536 |
|
537 by (metis assms max.cobounded1 max.cobounded2 ntimes_closed_form_bounded0) |
|
538 |
|
539 lemma self_smaller_than_bound: |
|
540 shows "\<forall>s. rsize (rders_simp r s) \<le> N \<Longrightarrow> rsize r \<le> N" |
|
541 apply(drule_tac x = "[]" in spec) |
|
542 apply simp |
|
543 done |
|
544 |
|
545 lemma ntimes_closed_form_bounded_nil_aux: |
|
546 shows "max (rsize RZERO) (rsize (RNTIMES r 0)) = 1 + rsize r" |
|
547 by auto |
|
548 |
|
549 lemma ntimes_closed_form_bounded_nil: |
|
550 assumes "\<forall>s. rsize (rders_simp r s) \<le> N" |
|
551 shows " rsize (rders_simp (RNTIMES r 0) s) \<le> 1 + rsize r" |
|
552 using assms ntimes_closed_form_bounded1 by auto |
|
553 |
|
554 lemma ntimes_ineq1: |
|
555 shows "(rsize (RNTIMES r n)) \<ge> 1 + rsize r" |
|
556 by simp |
|
557 |
|
558 lemma ntimes_ineq2: |
|
559 shows "1 + rsize r \<le> |
|
560 max ((Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * (Suc (N + rsize (RNTIMES r n))))) (rsize (RNTIMES r n))" |
|
561 by (meson le_max_iff_disj ntimes_ineq1) |
|
562 |
|
563 lemma ntimes_closed_form_bounded: |
|
564 assumes "\<forall>s. rsize (rders_simp r s) \<le> N" |
|
565 shows "rsize (rders_simp (RNTIMES r (Suc n)) s) \<le> |
|
566 max ((Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * (Suc (N + rsize (RNTIMES r n))))) (rsize (RNTIMES r n))" |
|
567 proof(cases s) |
|
568 case Nil |
|
569 then show "rsize (rders_simp (RNTIMES r (Suc n)) s) |
|
570 \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * Suc (N + rsize (RNTIMES r n))) (rsize (RNTIMES r n))" |
|
571 by simp |
|
572 next |
|
573 case (Cons a list) |
|
574 |
|
575 then have "rsize (rders_simp (RNTIMES r (Suc n)) s) = |
|
576 rsize (rsimp (RALTS ((map (optermsimp r) (nupdates list r [Some ([a], n)])))))" |
|
577 using ntimes_closed_form by fastforce |
|
578 also have "... \<le> Suc (rsizes (rdistinct ((map (optermsimp r) (nupdates list r [Some ([a], n)]))) {}))" |
|
579 using alts_simp_control by blast |
|
580 also have "... \<le> Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * (Suc (N + rsize (RNTIMES r n)))" |
|
581 using ntimes_control_bounded[OF assms] |
|
582 by (metis add_mono le_add1 mult_Suc plus_1_eq_Suc) |
|
583 also have "... \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * Suc (N + rsize (RNTIMES r n))) (rsize (RNTIMES r n))" |
|
584 by simp |
|
585 finally show ?thesis by simp |
|
586 qed |
|
587 |
|
588 |
|
589 lemma ntimes_closed_form_boundedA: |
|
590 assumes "\<forall>s. rsize (rders_simp r s) \<le> N" |
|
591 shows "\<exists>N'. \<forall>s. rsize (rders_simp (RNTIMES r n) s) \<le> N'" |
|
592 apply(case_tac n) |
|
593 using assms ntimes_closed_form_bounded_nil apply blast |
|
594 using assms ntimes_closed_form_bounded by blast |
|
595 |
|
596 |
|
597 lemma star_closed_form_nonempty_bounded: |
|
598 assumes "\<forall>s. rsize (rders_simp r s) \<le> N" and "s \<noteq> []" |
|
599 shows "rsize (rders_simp (RSTAR r) s) \<le> |
|
600 ((Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * (Suc (N + rsize (RSTAR r))))) " |
|
601 proof(cases s) |
|
602 case Nil |
|
603 then show ?thesis |
|
604 using local.Nil by fastforce |
|
605 next |
|
606 case (Cons a list) |
|
607 then have "rsize (rders_simp (RSTAR r) s) = |
|
608 rsize (rsimp (RALTS ((map (\<lambda>s1. RSEQ (rders_simp r s1) (RSTAR r)) (star_updates list r [[a]])))))" |
|
609 using star_closed_form by fastforce |
|
610 also have "... \<le> Suc (rsizes (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r s1) (RSTAR r)) (star_updates list r [[a]])) {}))" |
|
611 using alts_simp_control by blast |
|
612 also have "... \<le> Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * (Suc (N + rsize (RSTAR r)))" |
|
613 by (smt (z3) add_mono_thms_linordered_semiring(1) assms(1) le_add1 map_eq_conv mult_Suc plus_1_eq_Suc star_control_bounded) |
|
614 also have "... \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * Suc (N + rsize (RSTAR r))) (rsize (RSTAR r))" |
|
615 by simp |
|
616 finally show ?thesis by simp |
|
617 qed |
|
618 |
383 |
619 |
384 |
620 |
385 lemma seq_estimate_bounded: |
621 lemma seq_estimate_bounded: |
386 assumes "\<forall>s. rsize (rders_simp r1 s) \<le> N1" |
622 assumes "\<forall>s. rsize (rders_simp r1 s) \<le> N1" |
387 and "\<forall>s. rsize (rders_simp r2 s) \<le> N2" |
623 and "\<forall>s. rsize (rders_simp r2 s) \<le> N2" |