thys3/ClosedFormsBounds.thy
author Chengsong
Mon, 10 Jul 2023 01:33:45 +0100
changeset 660 eddc4eaba7c4
parent 642 6c13f76c070b
permissions -rw-r--r--
addresses Gerog "N_r meaning and relation with backtracking?" comment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
theory ClosedFormsBounds
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
  imports "GeneralRegexBound" "ClosedForms"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
begin
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
lemma alts_ders_lambda_shape_ders:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
  shows "\<forall>r \<in> set (map (\<lambda>r. rders_simp r ( s)) rs ). \<exists>r1 \<in> set rs. r = rders_simp r1 s"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
  by (simp add: image_iff)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
lemma rlist_bound:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
  assumes "\<forall>r \<in> set rs. rsize r \<le> N"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
  shows "rsizes rs \<le> N * (length rs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
  apply(induct rs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    14
  apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
  by simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    17
lemma alts_closed_form_bounded: 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    18
  assumes "\<forall>r \<in> set rs. \<forall>s. rsize (rders_simp r s) \<le> N"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    19
  shows "rsize (rders_simp (RALTS rs) s) \<le> max (Suc (N * (length rs))) (rsize (RALTS rs))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    20
proof (cases s)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    21
  case Nil
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    22
  then show "rsize (rders_simp (RALTS rs) s) \<le> max (Suc (N * length rs)) (rsize (RALTS rs))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    23
    by simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    24
next
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    25
  case (Cons a s)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    26
  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    27
  from assms have "\<forall>r \<in> set (map (\<lambda>r. rders_simp r (a # s)) rs ). rsize r \<le> N"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    28
    by (metis alts_ders_lambda_shape_ders)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    29
  then have a: "rsizes (map (\<lambda>r. rders_simp r (a # s)) rs ) \<le> N *  (length rs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    30
    by (metis length_map rlist_bound) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    31
     
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    32
  have "rsize (rders_simp (RALTS rs) (a # s)) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    33
          = rsize (rsimp (RALTS (map (\<lambda>r. rders_simp r (a # s)) rs)))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    34
    by (metis alts_closed_form_variant list.distinct(1)) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    35
  also have "... \<le> rsize (RALTS (map (\<lambda>r. rders_simp r (a # s)) rs))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    36
    using rsimp_mono by blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    37
  also have "... = Suc (rsizes (map (\<lambda>r. rders_simp r (a # s)) rs))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
    by simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
  also have "... \<le> Suc (N * (length rs))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    40
    using a by blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    41
  finally have "rsize (rders_simp (RALTS rs) (a # s)) \<le> max (Suc (N * length rs)) (rsize (RALTS rs))" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
    by auto
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
  then show ?thesis using local.Cons by simp 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    44
qed
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    45
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    46
lemma alts_simp_ineq_unfold:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    47
  shows "rsize (rsimp (RALTS rs)) \<le> Suc (rsizes (rdistinct (rflts (map rsimp rs)) {}))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    48
  using rsimp_aalts_smaller by auto
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    49
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    50
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    51
lemma rdistinct_mono_list:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    52
  shows "rsizes (rdistinct (x5 @ rs) rset) \<le> rsizes x5 + rsizes (rdistinct  rs ((set x5 ) \<union> rset))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    53
  apply(induct x5 arbitrary: rs rset)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    54
   apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    55
  apply(case_tac "a \<in> rset")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    56
   apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    57
   apply (simp add: add.assoc insert_absorb trans_le_add2)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    58
  apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    59
  by (metis Un_insert_right)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    60
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    61
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    62
lemma flts_size_reduction_alts:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    63
  assumes a: "\<And>noalts_set alts_set corr_set.
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    64
           (\<forall>r\<in>noalts_set. \<forall>xs. r \<noteq> RALTS xs) \<and>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    65
           (\<forall>a\<in>alts_set. \<exists>xs. a = RALTS xs \<and> set xs \<subseteq> corr_set) \<Longrightarrow>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    66
           Suc (rsizes (rdistinct (rflts rs) (noalts_set \<union> corr_set)))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    67
           \<le> Suc (rsizes (rdistinct rs (insert RZERO (noalts_set \<union> alts_set))))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    68
 and b: "\<forall>r\<in>noalts_set. \<forall>xs. r \<noteq> RALTS xs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    69
 and c: "\<forall>a\<in>alts_set. \<exists>xs. a = RALTS xs \<and> set xs \<subseteq> corr_set"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    70
 and d: "a = RALTS x5"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    71
 shows "rsizes (rdistinct (rflts (a # rs)) (noalts_set \<union> corr_set))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    72
           \<le> rsizes (rdistinct (a # rs) (insert RZERO (noalts_set \<union> alts_set)))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    73
  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    74
  apply(case_tac "a \<in> alts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    75
  using a b c d
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    76
   apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    77
   apply(subgoal_tac "set x5 \<subseteq> corr_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    78
  apply(subst rdistinct_concat)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    79
  apply auto[1]
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    80
    apply presburger
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    81
   apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    82
  using a b c d
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    83
  apply (subgoal_tac "a \<notin> noalts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    84
  prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    85
  apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    86
  apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    87
  apply(subgoal_tac "rsizes (rdistinct (x5 @ rflts rs) (noalts_set \<union> corr_set)) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    88
                   \<le> rsizes x5 + rsizes (rdistinct (rflts rs) ((set x5) \<union> (noalts_set \<union> corr_set)))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    89
  prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    90
  using rdistinct_mono_list apply presburger
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    91
  apply(subgoal_tac "insert (RALTS x5) (noalts_set \<union> alts_set) = noalts_set \<union> (insert (RALTS x5) alts_set)")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    92
   apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    93
  apply(subgoal_tac "rsizes x5 + rsizes (rdistinct (rflts rs) (noalts_set \<union> (corr_set \<union> (set x5)))) \<le>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    94
           rsizes x5 + rsizes (rdistinct rs (insert RZERO (noalts_set \<union> insert (RALTS x5) alts_set)))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    95
  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    96
  apply (simp add: Un_left_commute inf_sup_aci(5))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    97
   apply(subgoal_tac "rsizes (rdistinct (rflts rs) (noalts_set \<union> (corr_set \<union> set x5))) \<le> 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    98
                    rsizes (rdistinct rs (insert RZERO (noalts_set \<union> insert (RALTS x5) alts_set)))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    99
    apply linarith
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   100
   apply(subgoal_tac "\<forall>r \<in> insert (RALTS x5) alts_set. \<exists>xs1.( r = RALTS xs1 \<and> set xs1 \<subseteq> corr_set \<union> set x5)")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   101
    apply presburger
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   102
   apply (meson insert_iff sup.cobounded2 sup.coboundedI1)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   103
  by blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   104
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   105
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   106
lemma flts_vs_nflts1:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   107
  assumes "\<forall>r \<in> noalts_set. \<forall>xs. r \<noteq> RALTS xs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   108
  and "\<forall>a \<in> alts_set. (\<exists>xs. a = RALTS xs \<and> set xs \<subseteq> corr_set)" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   109
  shows "rsizes (rdistinct (rflts rs) (noalts_set \<union> corr_set))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   110
         \<le> rsizes (rdistinct rs (insert RZERO (noalts_set \<union> alts_set)))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   111
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   112
    apply(induct rs arbitrary: noalts_set alts_set corr_set)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   113
   apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   114
  apply(case_tac a)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   115
       apply(case_tac "RZERO \<in> noalts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   116
        apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   117
       apply(subgoal_tac "RZERO \<notin> alts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   118
        apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   119
       apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   120
      apply(case_tac "RONE \<in> noalts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   121
       apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   122
      apply(subgoal_tac "RONE \<notin> alts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   123
  prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   124
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   125
      apply(case_tac "RONE \<in> corr_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   126
       apply(subgoal_tac "rflts (a # rs) = RONE # rflts rs")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   127
        apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   128
        apply(subgoal_tac "rdistinct (RONE # rflts rs) (noalts_set \<union> corr_set) = 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   129
                           rdistinct (rflts rs) (noalts_set \<union> corr_set)")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   130
         apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   131
  apply(subgoal_tac "rdistinct (RONE # rs) (insert RZERO (noalts_set \<union> alts_set)) =
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   132
                     RONE # (rdistinct rs (insert RONE (insert RZERO (noalts_set \<union> alts_set)))) ")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   133
          apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   134
  apply(subgoal_tac "rdistinct (rflts rs) (noalts_set \<union> corr_set) = 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   135
                     rdistinct (rflts rs) (insert RONE (noalts_set \<union> corr_set))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   136
  apply (simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   137
  apply(subgoal_tac "insert RONE (noalts_set \<union> corr_set) = (insert RONE noalts_set) \<union> corr_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   138
            apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   139
  apply(subgoal_tac "insert RONE (insert RZERO (noalts_set \<union> alts_set)) = 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   140
                     insert RZERO ((insert RONE noalts_set) \<union> alts_set)")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   141
             apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   142
  apply(subgoal_tac "rsizes (rdistinct rs (insert RZERO (insert RONE noalts_set \<union> alts_set)))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   143
                   \<le>  rsizes (RONE # rdistinct rs (insert RZERO (insert RONE noalts_set \<union> alts_set)))")
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   144
  apply (smt (verit, ccfv_threshold) dual_order.trans insertE rrexp.distinct(17))
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   145
  apply (metis (no_types, opaque_lifting)  le_add_same_cancel2 list.simps(9) sum_list.Cons zero_le)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   146
            apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   147
           apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   148
  apply (metis Un_iff insert_absorb)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   149
         apply (metis UnE insertE insert_is_Un rdistinct.simps(2) rrexp.distinct(1))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   150
        apply (meson UnCI rdistinct.simps(2))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   151
  using rflts.simps(4) apply presburger
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   152
      apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   153
      apply(subgoal_tac "insert RONE (noalts_set \<union> corr_set) = (insert RONE noalts_set) \<union> corr_set")
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   154
        apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   155
  apply (metis Un_insert_left insertE rrexp.distinct(17))
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   156
      apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   157
     apply(case_tac "a \<in> noalts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   158
      apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   159
  apply(subgoal_tac "a \<notin> alts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   160
      prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   161
      apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   162
  apply(case_tac "a \<in> corr_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   163
      apply(subgoal_tac "noalts_set \<union> corr_set = insert a ( noalts_set  \<union> corr_set)")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   164
  prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   165
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   166
      apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   167
      apply(subgoal_tac "rsizes (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \<union> alts_set))) \<le>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   168
              rsizes (rdistinct (a # rs) (insert RZERO (noalts_set \<union> alts_set)))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   169
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   170
       apply(subgoal_tac  "rsizes (rdistinct (rflts (a # rs)) ((insert a noalts_set) \<union> corr_set)) \<le>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   171
              rsizes (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \<union> alts_set)))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   172
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   173
       apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   174
  apply(subgoal_tac "(insert a (noalts_set \<union> alts_set)) = (insert a noalts_set) \<union> alts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   175
        apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   176
        apply(subgoal_tac "noalts_set \<union> corr_set = (insert a noalts_set) \<union> corr_set")
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   177
          apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   178
  apply (metis insertE nonalt.simps(1) nonalt.simps(4))
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   179
        apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   180
  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   181
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   182
  apply force
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   183
      apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   184
  apply (metis Un_insert_left insertE nonalt.simps(1) nonalt.simps(4))
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   185
    apply(case_tac "a \<in> noalts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   186
     apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   187
  apply(subgoal_tac "a \<notin> alts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   188
      prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   189
      apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   190
  apply(case_tac "a \<in> corr_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   191
      apply(subgoal_tac "noalts_set \<union> corr_set = insert a ( noalts_set  \<union> corr_set)")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   192
  prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   193
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   194
      apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   195
      apply(subgoal_tac "rsizes (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \<union> alts_set))) \<le>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   196
             rsizes (rdistinct (a # rs) (insert RZERO (noalts_set \<union> alts_set)))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   197
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   198
       apply(subgoal_tac "rsizes (rdistinct (rflts (a # rs)) ((insert a noalts_set) \<union> corr_set)) \<le>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   199
          rsizes (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \<union> alts_set)))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   200
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   201
       apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   202
  apply(subgoal_tac "(insert a (noalts_set \<union> alts_set)) = (insert a noalts_set) \<union> alts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   203
        apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   204
        apply(subgoal_tac "noalts_set \<union> corr_set = (insert a noalts_set) \<union> corr_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   205
  apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   206
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   207
         apply (metis insertE rrexp.distinct(31))
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   208
  apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   209
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   210
  apply force
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   211
     apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   212
  
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   213
    apply (metis Un_insert_left insertE rrexp.distinct(31))
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   214
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   215
  using Suc_le_mono flts_size_reduction_alts apply presburger
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   216
     apply(case_tac "a \<in> noalts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   217
      apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   218
  apply(subgoal_tac "a \<notin> alts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   219
      prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   220
      apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   221
  apply(case_tac "a \<in> corr_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   222
      apply(subgoal_tac "noalts_set \<union> corr_set = insert a ( noalts_set  \<union> corr_set)")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   223
  prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   224
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   225
      apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   226
      apply(subgoal_tac "rsizes (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \<union> alts_set))) \<le>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   227
               rsizes (rdistinct (a # rs) (insert RZERO (noalts_set \<union> alts_set)))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   228
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   229
       apply(subgoal_tac "rsizes (rdistinct (rflts (a # rs)) ((insert a noalts_set) \<union> corr_set)) \<le>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   230
          rsizes (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \<union> alts_set)))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   231
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   232
       apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   233
  apply(subgoal_tac "(insert a (noalts_set \<union> alts_set)) = (insert a noalts_set) \<union> alts_set")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   234
        apply(simp only:)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   235
        apply(subgoal_tac "noalts_set \<union> corr_set = (insert a noalts_set) \<union> corr_set")
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   236
       apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   237
  apply (metis insertE rrexp.distinct(37))
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   238
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   239
        apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   240
  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   241
  apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   242
  apply force
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   243
     apply simp
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   244
   apply (metis Un_insert_left insert_iff rrexp.distinct(37))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   245
  apply(case_tac "a \<in> noalts_set")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   246
      apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   247
  apply(subgoal_tac "a \<notin> alts_set")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   248
     prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   249
      apply blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   250
  apply(case_tac "a \<in> corr_set")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   251
      apply(subgoal_tac "noalts_set \<union> corr_set = insert a ( noalts_set  \<union> corr_set)")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   252
  prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   253
  apply fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   254
   apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   255
   apply(subgoal_tac "rsizes (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \<union> alts_set))) \<le>
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   256
               rsizes (rdistinct (a # rs) (insert RZERO (noalts_set \<union> alts_set)))")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   257
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   258
       apply(subgoal_tac "rsizes (rdistinct (rflts (a # rs)) ((insert a noalts_set) \<union> corr_set)) \<le>
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   259
          rsizes (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \<union> alts_set)))")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   260
  apply fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   261
       apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   262
  apply(subgoal_tac "(insert a (noalts_set \<union> alts_set)) = (insert a noalts_set) \<union> alts_set")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   263
        apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   264
        apply(subgoal_tac "noalts_set \<union> corr_set = (insert a noalts_set) \<union> corr_set")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   265
       apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   266
  apply (metis insertE nonalt.simps(1) nonalt.simps(7))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   267
  apply blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   268
  apply blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   269
  apply force
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   270
  apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   271
  by (metis Un_insert_left insert_iff rrexp.distinct(39))
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   272
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   273
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   274
lemma flts_vs_nflts:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   275
  assumes "\<forall>r \<in> noalts_set. \<forall>xs. r \<noteq> RALTS xs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   276
  and "\<forall>a \<in> alts_set. (\<exists>xs. a = RALTS xs \<and> set xs \<subseteq> corr_set)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   277
  shows "rsizes (rdistinct (rflts rs) (noalts_set \<union> corr_set))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   278
         \<le> rsizes (rdistinct rs (insert RZERO (noalts_set \<union> alts_set)))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   279
  by (simp add: assms flts_vs_nflts1)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   280
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   281
lemma distinct_simp_ineq_general:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   282
  assumes "rsimp ` no_simp = has_simp" "finite no_simp"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   283
  shows "rsizes (rdistinct (map rsimp rs) has_simp) \<le> rsizes (rdistinct rs no_simp)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   284
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   285
  apply(induct rs no_simp arbitrary: has_simp rule: rdistinct.induct)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   286
  apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   287
  apply(auto)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   288
  using add_le_mono rsimp_mono by presburger
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   289
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   290
lemma larger_acc_smaller_distinct_res0:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   291
  assumes "ss \<subseteq> SS"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   292
  shows "rsizes (rdistinct rs SS) \<le> rsizes (rdistinct rs ss)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   293
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   294
  apply(induct rs arbitrary: ss SS)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   295
   apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   296
  by (metis distinct_early_app1 rdistinct_smaller)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   297
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   298
lemma without_flts_ineq:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   299
  shows "rsizes (rdistinct (rflts rs) {}) \<le> rsizes (rdistinct rs {})"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   300
proof -
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   301
  have "rsizes (rdistinct (rflts rs) {}) \<le>  rsizes (rdistinct rs (insert RZERO {}))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   302
    by (metis empty_iff flts_vs_nflts sup_bot_left)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   303
  also have "... \<le>  rsizes (rdistinct rs {})" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   304
    by (simp add: larger_acc_smaller_distinct_res0)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   305
  finally show ?thesis
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   306
    by blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   307
qed
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   308
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   309
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   310
lemma distinct_simp_ineq:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   311
  shows "rsizes (rdistinct (map rsimp rs) {}) \<le> rsizes (rdistinct rs {})"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   312
  using distinct_simp_ineq_general by blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   313
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   314
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   315
lemma alts_simp_control:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   316
  shows "rsize (rsimp (RALTS rs)) \<le> Suc (rsizes (rdistinct rs {}))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   317
proof -
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   318
  have "rsize (rsimp (RALTS rs)) \<le> Suc (rsizes (rdistinct (rflts (map rsimp rs)) {}))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   319
     using alts_simp_ineq_unfold by auto
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   320
   moreover have "\<dots> \<le> Suc (rsizes (rdistinct (map rsimp rs) {}))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   321
    using without_flts_ineq by blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   322
  ultimately show "rsize (rsimp (RALTS rs)) \<le> Suc (rsizes (rdistinct rs {}))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   323
    by (meson Suc_le_mono distinct_simp_ineq le_trans)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   324
qed
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   325
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   326
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   327
lemma larger_acc_smaller_distinct_res:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   328
  shows "rsizes (rdistinct rs (insert a ss)) \<le> rsizes (rdistinct rs ss)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   329
  by (simp add: larger_acc_smaller_distinct_res0 subset_insertI)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   330
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   331
lemma triangle_inequality_distinct:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   332
  shows "rsizes (rdistinct (a # rs) ss) \<le> rsize a + rsizes (rdistinct rs ss)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   333
  apply(case_tac "a \<in> ss")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   334
   apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   335
  by (simp add: larger_acc_smaller_distinct_res)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   336
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   337
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   338
lemma distinct_list_size_len_bounded:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   339
  assumes "\<forall>r \<in> set rs. rsize r \<le> N" "length rs \<le> lrs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   340
  shows "rsizes rs \<le> lrs * N "
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   341
  using assms
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   342
  by (metis rlist_bound dual_order.trans mult.commute mult_le_mono1)
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   343
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   344
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   345
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   346
lemma rdistinct_same_set:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   347
  shows "r \<in> set rs \<longleftrightarrow> r \<in> set (rdistinct rs {})"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   348
  apply(induct rs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   349
   apply simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   350
  by (metis rdistinct_set_equality)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   351
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   352
(* distinct_list_rexp_up_to_certain_size_bouded_by_set_enumerating_up_to_that_size *)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   353
lemma distinct_list_rexp_upto:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   354
  assumes "\<forall>r\<in> set rs. (rsize r) \<le> N"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   355
  shows "rsizes (rdistinct rs {}) \<le> (card (sizeNregex N)) * N"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   356
  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   357
  apply(subgoal_tac "distinct (rdistinct rs {})")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   358
  prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   359
  using rdistinct_does_the_job apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   360
  apply(subgoal_tac "length (rdistinct rs {}) \<le> card (sizeNregex N)")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   361
  apply(rule distinct_list_size_len_bounded)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   362
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   363
  apply (meson rdistinct_same_set)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   364
   apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   365
  apply(subgoal_tac "\<forall>r \<in> set (rdistinct rs {}). rsize r \<le> N")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   366
   prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   367
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   368
   apply (meson rdistinct_same_set)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   369
  apply(subgoal_tac "length (rdistinct rs {}) = card (set (rdistinct rs {}))")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   370
   prefer 2
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   371
  apply (simp add: distinct_card)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   372
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   373
  by (metis card_mono finite_size_n mem_Collect_eq sizeNregex_def subsetI)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   374
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   375
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   376
lemma star_control_bounded:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   377
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   378
  shows "rsizes (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r s1) (RSTAR r)) (star_updates s r [[c]])) {}) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   379
     \<le> (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * (Suc (N + rsize (RSTAR r)))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   380
  by (smt (verit) add_Suc_shift add_mono_thms_linordered_semiring(3) assms distinct_list_rexp_upto image_iff list.set_map plus_nat.simps(2) rsize.simps(5))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   381
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   382
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   383
lemma star_closed_form_bounded:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   384
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   385
  shows "rsize (rders_simp (RSTAR r) s) \<le> 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   386
           max ((Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * (Suc (N + rsize (RSTAR r))))) (rsize (RSTAR r))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   387
proof(cases s)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   388
  case Nil
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   389
  then show "rsize (rders_simp (RSTAR r) s)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   390
    \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * Suc (N + rsize (RSTAR r))) (rsize (RSTAR r))" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   391
    by simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   392
next
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   393
  case (Cons a list)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   394
  then have "rsize (rders_simp (RSTAR r) s) = 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   395
    rsize (rsimp (RALTS ((map (\<lambda>s1. RSEQ (rders_simp r s1) (RSTAR r)) (star_updates list r [[a]])))))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   396
    using star_closed_form by fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   397
  also have "... \<le> Suc (rsizes (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r s1) (RSTAR r)) (star_updates list r [[a]])) {}))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   398
    using alts_simp_control by blast 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   399
  also have "... \<le> Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * (Suc (N + rsize (RSTAR r)))" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   400
    using star_control_bounded[OF assms] by (metis add_mono le_add1 mult_Suc plus_1_eq_Suc)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   401
  also have "... \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * Suc (N + rsize (RSTAR r))) (rsize (RSTAR r))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   402
    by simp    
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   403
  finally show ?thesis by simp  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   404
qed
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   405
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   406
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   407
thm ntimes_closed_form
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   408
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   409
thm rsize.simps
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   410
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   411
lemma nupdates_snoc:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   412
  shows " (nupdates (xs @ [x]) r optlist) = nupdate x r (nupdates xs r optlist)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   413
  by (simp add: nupdates_append)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   414
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   415
lemma nupdate_elems:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   416
  shows "\<forall>opt \<in> set (nupdate c r optlist). opt = None \<or> (\<exists>s n. opt = Some (s, n))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   417
  using nonempty_string.cases by auto
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   418
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   419
lemma nupdates_elems:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   420
  shows "\<forall>opt \<in> set (nupdates s r optlist). opt = None \<or> (\<exists>s n. opt = Some (s, n))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   421
  by (meson nonempty_string.cases)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   422
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   423
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   424
lemma opterm_optlist_result_shape:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   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))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   426
  apply(induct optlist)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   427
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   428
  apply(case_tac a)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   429
  apply simp+
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   430
  by fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   431
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   432
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   433
lemma opterm_optlist_result_shape2:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   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))"  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   435
  using opterm_optlist_result_shape by presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   436
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   437
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   438
lemma nupdate_n_leq_n:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   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)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   440
  apply(case_tac n)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   441
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   442
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   443
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   444
(*
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   445
lemma nupdate_induct_leqn:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   446
  shows "\<lbrakk>\<forall>opt \<in> set optlist. opt = None \<or> (\<exists>s' m. opt = Some(s', m) \<and> m \<le> n) \<rbrakk> \<Longrightarrow> 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   447
       \<forall>opt \<in> set (nupdate c' r optlist). opt = None \<or> (\<exists>s' m. opt = Some (s', m) \<and> m \<le> n)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   448
  apply (case_tac optlist)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   449
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   450
  apply(case_tac a)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   451
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   452
  sledgehammer
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   453
*)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   454
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   455
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   456
lemma nupdates_n_leq_n:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   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)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   458
  apply(induct s rule: rev_induct)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   459
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   460
  apply(subst nupdates_append)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   461
  by (metis nupdates_elems_leqn nupdates_snoc)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   462
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   463
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   464
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   465
lemma ntimes_closed_form_list_elem_shape:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   466
  shows "\<forall>r' \<in> set (map (optermsimp r) (nupdates s r [Some ([c], n)])). 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   467
r' = RZERO \<or> (\<exists>s' m. r' = RSEQ (rders_simp r s') (RNTIMES r m) \<and> m \<le> n)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   468
  apply(insert opterm_optlist_result_shape2)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   469
  apply(case_tac s)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   470
   apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   471
  apply (metis rders_simp_one_char)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   472
  by (metis case_prod_conv nupdates.simps(2) nupdates_n_leq_n option.simps(4) option.simps(5))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   473
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   474
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   475
lemma ntimes_trivial1:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   476
  shows "rsize RZERO \<le> N + rsize (RNTIMES r n)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   477
  by simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   478
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   479
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   480
lemma ntimes_trivial20:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   481
  shows "m \<le> n \<Longrightarrow> rsize (RNTIMES r m) \<le> rsize (RNTIMES r n)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   482
  by simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   483
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   484
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   485
lemma ntimes_trivial2:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   486
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   487
  shows "    r' = RSEQ (rders_simp r s1) (RNTIMES r m) \<and> m \<le> n
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   488
       \<Longrightarrow> rsize r' \<le> Suc (N + rsize (RNTIMES r n))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   489
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   490
  by (simp add: add_mono_thms_linordered_semiring(1) assms)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   491
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   492
lemma ntimes_closed_form_list_elem_bounded:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   493
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   494
  shows "\<forall>r' \<in>  set  (map (optermsimp r) (nupdates s r [Some ([c], n)])). rsize r' \<le> Suc (N + rsize (RNTIMES r n))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   495
  apply(rule ballI)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   496
  apply(subgoal_tac  "r' = RZERO \<or> (\<exists>s' m. r' = RSEQ (rders_simp r s') (RNTIMES r m) \<and> m \<le> n)")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   497
  prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   498
  using ntimes_closed_form_list_elem_shape apply blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   499
  apply(case_tac "r' = RZERO")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   500
  using le_SucI ntimes_trivial1 apply presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   501
  apply(subgoal_tac "\<exists>s1 m. r' = RSEQ (rders_simp r s1) (RNTIMES r m) \<and> m \<le> n")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   502
  apply(erule exE)+
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   503
  using assms ntimes_trivial2 apply presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   504
  by blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   505
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   506
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   507
lemma P_holds_after_distinct:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   508
  assumes "\<forall>r \<in> set rs. P r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   509
  shows "\<forall>r \<in> set (rdistinct rs rset). P r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   510
  by (simp add: assms rdistinct_set_equality1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   511
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   512
lemma ntimes_control_bounded:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   513
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   514
  shows "rsizes (rdistinct (map (optermsimp r) (nupdates s r [Some ([c], n)])) {}) 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   515
     \<le> (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * (Suc (N + rsize (RNTIMES r n)))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   516
  apply(subgoal_tac "\<forall>r' \<in> set (rdistinct (map (optermsimp r) (nupdates s r [Some ([c], n)])) {}).
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   517
          rsize r' \<le> Suc (N + rsize (RNTIMES r n))")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   518
   apply (meson distinct_list_rexp_upto rdistinct_same_set)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   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))")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   520
   apply (simp add: rdistinct_set_equality)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   521
  by (metis assms nat_le_linear not_less_eq_eq ntimes_closed_form_list_elem_bounded)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   522
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   523
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   524
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   525
lemma ntimes_closed_form_bounded0:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   526
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   527
  shows " (rders_simp (RNTIMES r 0) s)  = RZERO \<or> (rders_simp (RNTIMES r 0) s)  = RNTIMES r 0
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   528
           "
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   529
  apply(induct s)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   530
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   531
  by (metis always0 list.simps(3) rder.simps(7) rders.simps(2) rders_simp_same_simpders rsimp.simps(3))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   532
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   533
lemma ntimes_closed_form_bounded1:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   534
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   535
  shows " rsize (rders_simp (RNTIMES r 0) s) \<le> max (rsize  RZERO) (rsize (RNTIMES r 0))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   536
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   537
  by (metis assms max.cobounded1 max.cobounded2 ntimes_closed_form_bounded0)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   538
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   539
lemma self_smaller_than_bound:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   540
  shows "\<forall>s. rsize (rders_simp r s) \<le> N \<Longrightarrow> rsize r \<le> N"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   541
  apply(drule_tac x = "[]" in spec)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   542
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   543
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   544
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   545
lemma ntimes_closed_form_bounded_nil_aux:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   546
  shows "max (rsize  RZERO) (rsize (RNTIMES r 0)) = 1 + rsize r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   547
  by auto
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   548
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   549
lemma ntimes_closed_form_bounded_nil:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   550
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   551
  shows " rsize (rders_simp (RNTIMES r 0) s) \<le> 1 + rsize r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   552
  using assms ntimes_closed_form_bounded1 by auto
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   553
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   554
lemma ntimes_ineq1:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   555
  shows "(rsize (RNTIMES r n)) \<ge> 1 + rsize r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   556
  by simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   557
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   558
lemma ntimes_ineq2:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   559
  shows "1 + rsize r \<le>  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   560
max ((Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * (Suc (N + rsize (RNTIMES r n))))) (rsize (RNTIMES r n))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   561
  by (meson le_max_iff_disj ntimes_ineq1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   562
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   563
lemma ntimes_closed_form_bounded:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   564
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   565
  shows "rsize (rders_simp (RNTIMES r (Suc n)) s) \<le> 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   566
           max ((Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * (Suc (N + rsize (RNTIMES r n))))) (rsize (RNTIMES r n))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   567
proof(cases s)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   568
  case Nil
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   569
  then show "rsize (rders_simp (RNTIMES r (Suc n)) s)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   570
    \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * Suc (N + rsize (RNTIMES r n))) (rsize (RNTIMES r n))" 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   571
    by simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   572
next
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   573
  case (Cons a list)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   574
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   575
  then have "rsize (rders_simp (RNTIMES r (Suc n)) s) = 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   576
             rsize (rsimp (RALTS ((map (optermsimp r)    (nupdates list r [Some ([a], n)])))))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   577
    using ntimes_closed_form by fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   578
  also have "... \<le> Suc (rsizes (rdistinct ((map (optermsimp r) (nupdates list r [Some ([a], n)]))) {}))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   579
    using alts_simp_control by blast 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   580
  also have "... \<le> Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * (Suc (N + rsize (RNTIMES r n)))" 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   581
    using ntimes_control_bounded[OF assms]
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   582
    by (metis add_mono le_add1 mult_Suc plus_1_eq_Suc)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   583
  also have "... \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RNTIMES r n))))) * Suc (N + rsize (RNTIMES r n))) (rsize (RNTIMES r n))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   584
    by simp    
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   585
  finally show ?thesis by simp  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   586
qed
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   587
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   588
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   589
lemma ntimes_closed_form_boundedA:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   590
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   591
  shows "\<exists>N'. \<forall>s. rsize (rders_simp (RNTIMES r n) s) \<le> N'"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   592
  apply(case_tac n)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   593
  using assms ntimes_closed_form_bounded_nil apply blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   594
  using assms ntimes_closed_form_bounded by blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   595
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   596
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   597
lemma star_closed_form_nonempty_bounded:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   598
  assumes "\<forall>s. rsize (rders_simp r s) \<le> N" and "s \<noteq> []"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   599
  shows "rsize (rders_simp (RSTAR r) s) \<le> 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   600
            ((Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * (Suc (N + rsize (RSTAR r))))) "
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   601
proof(cases s)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   602
  case Nil
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   603
  then show ?thesis 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   604
    using local.Nil by fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   605
next
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   606
  case (Cons a list)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   607
  then have "rsize (rders_simp (RSTAR r) s) = 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   608
    rsize (rsimp (RALTS ((map (\<lambda>s1. RSEQ (rders_simp r s1) (RSTAR r)) (star_updates list r [[a]])))))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   609
    using star_closed_form by fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   610
  also have "... \<le> Suc (rsizes (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r s1) (RSTAR r)) (star_updates list r [[a]])) {}))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   611
    using alts_simp_control by blast 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   612
  also have "... \<le> Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * (Suc (N + rsize (RSTAR r)))" 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   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)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   614
  also have "... \<le> max (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r))))) * Suc (N + rsize (RSTAR r))) (rsize (RSTAR r))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   615
    by simp    
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   616
  finally show ?thesis by simp  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   617
qed
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   618
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   619
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   620
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   621
lemma seq_estimate_bounded: 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   622
  assumes "\<forall>s. rsize (rders_simp r1 s) \<le> N1" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   623
      and "\<forall>s. rsize (rders_simp r2 s) \<le> N2"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   624
  shows
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   625
    "rsizes (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {}) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   626
       \<le> (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   627
proof -
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   628
  have a: "rsizes (rdistinct (map (rders_simp r2) (vsuf s r1)) {}) \<le> N2 * card (sizeNregex N2)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   629
    by (metis assms(2) distinct_list_rexp_upto ex_map_conv mult.commute)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   630
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   631
  have "rsizes (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {}) \<le>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   632
          rsize (RSEQ (rders_simp r1 s) r2) + rsizes (rdistinct (map (rders_simp r2) (vsuf s r1)) {})"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   633
    using triangle_inequality_distinct by blast    
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   634
  also have "... \<le> rsize (RSEQ (rders_simp r1 s) r2) + N2 * card (sizeNregex N2)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   635
    by (simp add: a)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   636
  also have "... \<le> Suc (N1 + (rsize r2) + N2 * card (sizeNregex N2))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   637
    by (simp add: assms(1))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   638
  finally show ?thesis
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   639
    by force
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   640
qed    
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   641
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   642
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   643
lemma seq_closed_form_bounded2: 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   644
  assumes "\<forall>s. rsize (rders_simp r1 s) \<le> N1"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   645
  and     "\<forall>s. rsize (rders_simp r2 s) \<le> N2"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   646
shows "rsize (rders_simp (RSEQ r1 r2) s) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   647
          \<le> max (2 + N1 + (rsize r2) + (N2 * card (sizeNregex N2))) (rsize (RSEQ r1 r2))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   648
proof(cases s)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   649
  case Nil
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   650
  then show "rsize (rders_simp (RSEQ r1 r2) s)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   651
     \<le> max (2 + N1 + (rsize r2) + (N2 * card (sizeNregex N2))) (rsize (RSEQ r1 r2))" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   652
    by simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   653
next
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   654
  case (Cons a list)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   655
  then have "rsize (rders_simp (RSEQ r1 r2) s) = 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   656
    rsize (rsimp (RALTS ((RSEQ (rders_simp r1 s) r2) # (map (rders_simp r2) (vsuf s r1)))))" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   657
    using seq_closed_form_variant by (metis list.distinct(1)) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   658
  also have "... \<le> Suc (rsizes (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {}))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   659
    using alts_simp_control by blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   660
  also have "... \<le> 2 + N1 + (rsize r2) + (N2 * card (sizeNregex N2))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   661
  using seq_estimate_bounded[OF assms] by auto
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   662
  ultimately show "rsize (rders_simp (RSEQ r1 r2) s)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   663
       \<le> max (2 + N1 + (rsize r2) + N2 * card (sizeNregex N2)) (rsize (RSEQ r1 r2))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   664
    by auto 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   665
qed
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   666
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   667
lemma rders_simp_bounded: 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   668
  shows "\<exists>N. \<forall>s. rsize (rders_simp r s) \<le> N"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   669
  apply(induct r)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   670
  apply(rule_tac x = "Suc 0 " in exI)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   671
  using three_easy_cases0 apply force
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   672
  using three_easy_cases1 apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   673
  using three_easy_casesC apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   674
  apply(erule exE)+
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   675
  apply(rule exI)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   676
  apply(rule allI)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   677
  apply(rule seq_closed_form_bounded2)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   678
  apply(assumption)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   679
  apply(assumption)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   680
  apply (metis alts_closed_form_bounded size_list_estimation')
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   681
  using star_closed_form_bounded apply blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   682
  using ntimes_closed_form_boundedA by blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   683
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   684
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   685
unused_thms
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 558
diff changeset
   686
export_code rders_simp rsimp rder in Scala module_name Example
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   687
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   688
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   689
end