thys4/posix/FBound.thy
author Chengsong
Tue, 25 Jul 2023 17:28:29 +0100
changeset 667 660cf698eb26
parent 618 233cf2b97d1a
permissions -rw-r--r--
added example of how inj and lexer works
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
     1
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
     2
theory FBound
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
     3
  imports "BlexerSimp" "ClosedFormsBounds"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
     4
begin
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
     5
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
     6
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
     7
  where
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
     8
  "distinctBy [] f acc = []"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
     9
| "distinctBy (x#xs) f acc = 
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    10
     (if (f x) \<in> acc then distinctBy xs f acc 
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    11
      else x # (distinctBy xs f ({f x} \<union> acc)))"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    12
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    13
fun rerase :: "arexp \<Rightarrow> rrexp"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    14
where
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    15
  "rerase AZERO = RZERO"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    16
| "rerase (AONE _) = RONE"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    17
| "rerase (ACHAR _ c) = RCHAR c"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    18
| "rerase (AALTs bs rs) = RALTS (map rerase rs)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    19
| "rerase (ASEQ _ r1 r2) = RSEQ (rerase r1) (rerase r2)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    20
| "rerase (ASTAR _ r) = RSTAR (rerase r)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    21
| "rerase (ANTIMES _ r n) = RNTIMES (rerase r) n"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    22
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    23
lemma eq1_rerase:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    24
  shows "x ~1 y \<longleftrightarrow> (rerase x) = (rerase y)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    25
  apply(induct x y rule: eq1.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    26
  apply(auto)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    27
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    28
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    29
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    30
lemma distinctBy_distinctWith:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    31
  shows "distinctBy xs f (f ` acc) = distinctWith xs (\<lambda>x y. f x = f y) acc"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    32
  apply(induct xs arbitrary: acc)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    33
  apply(auto)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    34
  by (metis image_insert)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    35
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    36
lemma distinctBy_distinctWith2:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    37
  shows "distinctBy xs rerase {} = distinctWith xs eq1 {}"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    38
  apply(subst distinctBy_distinctWith[of _ _ "{}", simplified])
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    39
  using eq1_rerase by presburger
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    40
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    41
lemma asize_rsize:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    42
  shows "rsize (rerase r) = asize r"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    43
  apply(induct r rule: rerase.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    44
  apply(auto)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    45
  apply (metis (mono_tags, lifting) comp_apply map_eq_conv)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    46
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    47
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    48
lemma rerase_fuse:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    49
  shows "rerase (fuse bs r) = rerase r"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    50
  apply(induct r)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    51
       apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    52
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    53
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    54
lemma rerase_bsimp_ASEQ:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    55
  shows "rerase (bsimp_ASEQ x1 a1 a2) = rsimp_SEQ (rerase a1) (rerase a2)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    56
  apply(induct x1 a1 a2 rule: bsimp_ASEQ.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    57
  apply(auto)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    58
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    59
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    60
lemma rerase_bsimp_AALTs:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    61
  shows "rerase (bsimp_AALTs bs rs) = rsimp_ALTs (map rerase rs)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    62
  apply(induct bs rs rule: bsimp_AALTs.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    63
  apply(auto simp add: rerase_fuse)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    64
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    65
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    66
fun anonalt :: "arexp \<Rightarrow> bool"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    67
  where
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    68
  "anonalt (AALTs bs2 rs) = False"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    69
| "anonalt r = True"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    70
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    71
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    72
fun agood :: "arexp \<Rightarrow> bool" where
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    73
  "agood AZERO = False"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    74
| "agood (AONE cs) = True" 
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    75
| "agood (ACHAR cs c) = True"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    76
| "agood (AALTs cs []) = False"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    77
| "agood (AALTs cs [r]) = False"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    78
| "agood (AALTs cs (r1#r2#rs)) = (distinct (map rerase (r1 # r2 # rs)) \<and>(\<forall>r' \<in> set (r1#r2#rs). agood r' \<and> anonalt r'))"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    79
| "agood (ASEQ _ AZERO _) = False"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    80
| "agood (ASEQ _ (AONE _) _) = False"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    81
| "agood (ASEQ _ _ AZERO) = False"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    82
| "agood (ASEQ cs r1 r2) = (agood r1 \<and> agood r2)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    83
| "agood (ASTAR cs r) = True"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    84
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    85
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    86
fun anonnested :: "arexp \<Rightarrow> bool"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    87
  where
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    88
  "anonnested (AALTs bs2 []) = True"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    89
| "anonnested (AALTs bs2 ((AALTs bs1 rs1) # rs2)) = False"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    90
| "anonnested (AALTs bs2 (r # rs2)) = anonnested (AALTs bs2 rs2)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    91
| "anonnested r = True"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    92
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    93
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    94
lemma asize0:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    95
  shows "0 < asize r"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    96
  apply(induct  r)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    97
  apply(auto)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    98
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
    99
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   100
lemma rnullable:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   101
  shows "rnullable (rerase r) = bnullable r"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   102
  apply(induct r rule: rerase.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   103
  apply(auto)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   104
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   105
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   106
lemma rder_bder_rerase:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   107
  shows "rder c (rerase r ) = rerase (bder c r)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   108
  apply (induct r)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   109
  apply (auto)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   110
  using rerase_fuse apply presburger
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   111
  using rnullable apply blast
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   112
  using rnullable by blast
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   113
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   114
lemma rerase_map_bsimp:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   115
  assumes "\<And> r. r \<in> set rs \<Longrightarrow> rerase (bsimp r) = (rsimp \<circ> rerase) r"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   116
  shows "map rerase (map bsimp rs) =  map (rsimp \<circ> rerase) rs"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   117
  using assms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   118
  apply(induct rs)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   119
  by simp_all
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   120
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   121
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   122
lemma rerase_flts:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   123
  shows "map rerase (flts rs) = rflts (map rerase rs)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   124
  apply(induct rs rule: flts.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   125
  apply(auto simp add: rerase_fuse)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   126
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   127
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   128
lemma rerase_dB:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   129
  shows "map rerase (distinctBy rs rerase acc) = rdistinct (map rerase rs) acc"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   130
  apply(induct rs arbitrary: acc)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   131
  apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   132
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   133
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   134
lemma rerase_earlier_later_same:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   135
  assumes " \<And>r. r \<in> set rs \<Longrightarrow> rerase (bsimp r) = rsimp (rerase r)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   136
  shows " (map rerase (distinctBy (flts (map bsimp rs)) rerase {})) =
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   137
          (rdistinct (rflts (map (rsimp \<circ> rerase) rs)) {})"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   138
  apply(subst rerase_dB)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   139
  apply(subst rerase_flts)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   140
  apply(subst rerase_map_bsimp)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   141
  apply auto
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   142
  using assms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   143
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   144
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   145
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   146
lemma bsimp_rerase:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   147
  shows "rerase (bsimp a) = rsimp (rerase a)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   148
  apply(induct a rule: bsimp.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   149
  apply(auto)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   150
  using rerase_bsimp_ASEQ apply presburger
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   151
  using distinctBy_distinctWith2 rerase_bsimp_AALTs rerase_earlier_later_same by fastforce
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   152
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   153
lemma rders_simp_size:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   154
  shows "rders_simp (rerase r) s  = rerase (bders_simp r s)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   155
  apply(induct s rule: rev_induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   156
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   157
  by (simp add: bders_simp_append rder_bder_rerase rders_simp_append bsimp_rerase)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   158
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   159
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   160
corollary aders_simp_finiteness:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   161
  assumes "\<exists>N. \<forall>s. rsize (rders_simp (rerase r) s) \<le> N"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   162
  shows " \<exists>N. \<forall>s. asize (bders_simp r s) \<le> N"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   163
proof - 
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   164
  from assms obtain N where "\<forall>s. rsize (rders_simp (rerase r) s) \<le> N"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   165
    by blast
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   166
  then have "\<forall>s. rsize (rerase (bders_simp r s)) \<le> N"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   167
    by (simp add: rders_simp_size) 
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   168
  then have "\<forall>s. asize (bders_simp r s) \<le> N"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   169
    by (simp add: asize_rsize) 
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   170
  then show "\<exists>N. \<forall>s. asize (bders_simp r s) \<le> N" by blast
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   171
qed
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   172
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   173
theorem annotated_size_bound:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   174
  shows "\<exists>N. \<forall>s. asize (bders_simp r s) \<le> N"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   175
  apply(insert aders_simp_finiteness)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   176
  by (simp add: rders_simp_bounded)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   177
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   178
definition bitcode_agnostic :: "(arexp \<Rightarrow> arexp ) \<Rightarrow> bool"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   179
  where " bitcode_agnostic f = (\<forall>a1 a2. rerase a1 = rerase a2 \<longrightarrow> rerase (f a1) = rerase (f a2))  "
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   180
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   181
lemma bitcode_agnostic_bsimp:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   182
  shows  "bitcode_agnostic bsimp"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   183
  by (simp add: bitcode_agnostic_def bsimp_rerase)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   184
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   185
thm bsimp_rerase
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   186
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   187
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   188
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   189
lemma unsure_unchanging:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   190
  assumes "bsimp a = bsimp b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   191
and "a ~1 b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   192
shows "a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   193
  using assms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   194
  apply(induct rule: eq1.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   195
                      apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   196
  oops
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   197
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   198
lemma eq1rerase:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   199
  shows "rerase r1 = rerase r2 \<longleftrightarrow> r1 ~1 r2"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   200
  using eq1_rerase by presburger
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   201
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   202
thm contrapos_pp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   203
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   204
lemma r_part_neq_whole:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   205
  shows "RSEQ r1 r2 \<noteq> r2"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   206
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   207
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   208
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   209
lemma r_part_neq_whole2:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   210
  shows "RSEQ r1 r2 \<noteq> rsimp r2"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   211
  by (metis good.simps(7) good.simps(8) good1 good_SEQ r_part_neq_whole rrexp.distinct(5) rsimp.simps(3) test)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   212
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   213
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   214
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   215
lemma arexpfiniteaux1:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   216
  shows "rerase (bsimp_ASEQ x41 (bsimp x42) (bsimp x43)) = RSEQ (rerase x42) (rerase x43) \<Longrightarrow> \<forall>bs. bsimp x42 \<noteq> AONE bs"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   217
  apply(erule contrapos_pp)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   218
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   219
  apply(erule exE)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   220
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   221
  by (metis bsimp_rerase r_part_neq_whole2 rerase_fuse)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   222
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   223
lemma arexpfiniteaux2:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   224
  shows "rerase (bsimp_ASEQ x41 (bsimp x42) (bsimp x43)) = RSEQ (rerase x42) (rerase x43) \<Longrightarrow> bsimp x42 \<noteq> AZERO "
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   225
  apply(erule contrapos_pp)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   226
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   227
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   228
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   229
lemma arexpfiniteaux3:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   230
  shows "rerase (bsimp_ASEQ x41 (bsimp x42) (bsimp x43)) = RSEQ (rerase x42) (rerase x43) \<Longrightarrow> bsimp x43 \<noteq> AZERO "
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   231
  apply(erule contrapos_pp)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   232
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   233
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   234
588
Chengsong
parents: 587
diff changeset
   235
lemma aux_aux_aux:
Chengsong
parents: 587
diff changeset
   236
  shows "map rerase (flts (map bsimp rs)) = map rerase rs \<Longrightarrow> map rerase (map bsimp rs) = map rerase rs"
Chengsong
parents: 587
diff changeset
   237
  oops
Chengsong
parents: 587
diff changeset
   238
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   239
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   240
  thm asize.simps
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   241
fun s_complexity:: "arexp \<Rightarrow> nat" where
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   242
    "s_complexity AZERO = 1"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   243
  | "s_complexity (AONE _) = 1"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   244
  | "s_complexity (ASTAR bs r) = Suc (s_complexity r)"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   245
  | "s_complexity (AALTs bs rs) = Suc (Suc (sum_list (map s_complexity rs)))"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   246
  | "s_complexity (ASEQ bs r1 r2) = Suc (s_complexity r1 + s_complexity r2)"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   247
  | "s_complexity (ACHAR _ _) = 1"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   248
  | "s_complexity (ANTIMES _ r _) = Suc (s_complexity r)"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   249
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   250
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   251
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   252
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   253
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   254
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   255
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   256
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   257
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   258
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   259
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   260
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   261
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   262
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   263
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   264
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   265
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   266
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   267
588
Chengsong
parents: 587
diff changeset
   268
inductive leq1 ("_ \<le>1 _" [80, 80] 80) where  
Chengsong
parents: 587
diff changeset
   269
  "r1 \<le>1 r1"
Chengsong
parents: 587
diff changeset
   270
| "AZERO \<le>1 ASEQ bs AZERO r" 
Chengsong
parents: 587
diff changeset
   271
| "AZERO \<le>1 ASEQ bs r AZERO"
Chengsong
parents: 587
diff changeset
   272
| "fuse (bs @ bs1) r2 \<le>1 ASEQ bs (AONE bs1) r2"
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   273
| "AALTs bs (rs1 @ rs) \<le>1 AALTs bs (rs1 @( AZERO # rs))"
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   274
| "AALTs bs (rsa @ (map (fuse bs1) rs1) @ rsb) \<le>1 AALTs bs (rsa @ (AALTs bs1 rs1) # rsb)"
588
Chengsong
parents: 587
diff changeset
   275
| "rerase a1 = rerase a2 \<Longrightarrow> AALTs bs (rsa @ [a1] @ rsb @ rsc) \<le>1 AALTs bs (rsa @ [a1] @ rsb @ [a2] @ rsc) "
Chengsong
parents: 587
diff changeset
   276
| "r1 \<le>1 r2 \<Longrightarrow> r1  \<le>1 ASEQ bs (AONE bs1) r2"
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   277
| "r2 \<le>1 r1 \<Longrightarrow> AALTs bs (rs1 @ r2 # rs) \<le>1 AALTs bs (rs1 @ r1 # rs)"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   278
| "r2 \<le>1 r1 \<Longrightarrow> ASEQ bs r  r2 \<le>1 ASEQ bs r r1"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   279
| "r2 \<le>1 r1 \<Longrightarrow> ASEQ bs r2 r  \<le>1 ASEQ bs r1 r"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   280
| "r \<le>1 r' \<Longrightarrow> ASTAR bs r \<le>1 ASTAR bs r'"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   281
| "AZERO \<le>1 AALTs bs []"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   282
| "fuse bs r \<le>1 AALTs bs [r]"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   283
| "\<lbrakk>r1' \<le>1 r1;  r2' \<le>1 r2\<rbrakk> \<Longrightarrow> bsimp_ASEQ bs1 r1' r2' \<le>1 ASEQ bs1 r1 r2"
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   284
| "\<lbrakk>AALTs bs rs1 \<le>1 AALTs bs rs2; r1 \<le>1 r2 \<rbrakk> \<Longrightarrow> AALTs bs (r1 # rs1) \<le>1 AALTs bs (r2 # rs2)"
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   285
| "\<lbrakk>r1 \<le>1 r2; r2 \<le>1 r3 \<rbrakk> \<Longrightarrow> r1 \<le>1 r3"
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   286
| "AALTs bs (rs1 @ distinctWith rs2 eq1 (set rs1)) \<le>1 AALTs bs (rs1 @ rs2)"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   287
| "bsimp_AALTs bs rs \<le>1 AALTs bs rs"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   288
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   289
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   290
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   291
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   292
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   293
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   294
lemma leq1_6_variant1:
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   295
  shows "AALTs bs ( (map (fuse bs1) rs1) @ rsb) \<le>1 AALTs bs ((AALTs bs1 rs1) # rsb)"
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   296
  by (metis leq1.intros(6) self_append_conv2)
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   297
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   298
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   299
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   300
lemma flts_leq1:
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   301
  shows "AALTs bs (flts rs) \<le>1 AALTs bs rs"
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   302
  apply(induct rule: flts.induct)
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   303
         apply (simp add: leq1.intros(1))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   304
        apply simp
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   305
  apply (metis append_Nil leq1.intros(17) leq1.intros(5))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   306
       apply simp
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   307
       apply(subgoal_tac "AALTs bs (map (fuse bsa) rs1 @ flts rs) \<le>1 AALTs bs (AALTs bsa rs1 # flts rs)")
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   308
        apply (meson leq1.intros(1) leq1.intros(16) leq1.intros(17))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   309
  using leq1_6_variant1 apply presburger
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   310
  apply (simp add: leq1.intros(1) leq1.intros(16))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   311
  using leq1.intros(1) leq1.intros(16) apply auto[1]
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   312
  using leq1.intros(1) leq1.intros(16) apply force
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   313
   apply (simp add: leq1.intros(1) leq1.intros(16))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   314
  using leq1.intros(1) leq1.intros(16) by force
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   315
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   316
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   317
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   318
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   319
lemma dB_leq1:
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   320
  shows "AALTs bs (distinctWith rs eq1 {}) \<le>1 AALTs bs rs"
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   321
  by (metis append_Nil empty_set leq1.intros(18))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   322
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   323
lemma leq1_list:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   324
  shows "
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   325
       \<lbrakk>\<And>x2aa. x2aa \<in> set x2a \<Longrightarrow> bsimp x2aa \<le>1 x2aa;
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   326
        bsimp_AALTs x1 (distinctWith (flts (map bsimp x2a)) eq1 {}) \<le>1 AALTs x1 (distinctWith (flts (map bsimp x2a)) eq1 {});
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   327
        AALTs x1 (distinctWith (flts (map bsimp x2a)) eq1 {}) \<le>1 AALTs x1 (flts (map bsimp x2a));
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   328
        AALTs x1 (flts (map bsimp x2a)) \<le>1 AALTs x1 (map bsimp x2a)\<rbrakk>
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   329
       \<Longrightarrow> AALTs x1 (map bsimp x2a) \<le>1 AALTs x1 x2a"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   330
  apply(induct x2a)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   331
   apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   332
  by (simp add: dB_leq1 flts_leq1 leq1.intros(16) leq1.intros(19))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   333
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   334
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   335
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   336
lemma bsimp_leq1:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   337
  shows "bsimp r \<le>1 r"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   338
  apply(induct r)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   339
        apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   340
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   341
  apply (simp add: leq1.intros(1))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   342
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   343
  using leq1.intros(1) apply force
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   344
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   345
  apply (simp add: leq1.intros(1))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   346
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   347
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   348
     apply (simp add: leq1.intros(15))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   349
  prefer 2
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   350
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   351
  apply (simp add: leq1.intros(1))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   352
   prefer 2
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   353
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   354
  apply (simp add: leq1.intros(1))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   355
  apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   356
  apply(subgoal_tac " bsimp_AALTs x1 (distinctWith (flts (map bsimp x2a)) eq1 {}) \<le>1  AALTs x1 (distinctWith (flts (map bsimp x2a)) eq1 {})")
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   357
  apply(subgoal_tac " AALTs x1 (distinctWith (flts (map bsimp x2a)) eq1 {}) \<le>1  AALTs x1 ( (flts (map bsimp x2a)) )")
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   358
    apply(subgoal_tac " AALTs x1 ( (flts (map bsimp x2a)) ) \<le>1  AALTs x1 ( ( (map bsimp x2a)) )")
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   359
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   360
    apply(subgoal_tac " AALTs x1 ( map bsimp x2a ) \<le>1  AALTs x1   x2a ")
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   361
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   362
  apply (meson leq1.intros(17))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   363
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   364
  using leq1_list apply blast
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   365
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   366
  using flts_leq1 apply presburger
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   367
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   368
  using dB_leq1 apply blast
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   369
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   370
  using leq1.intros(19) by blast
591
b2d0de6aee18 more polishing integrated comments chap2
Chengsong
parents: 590
diff changeset
   371
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   372
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   373
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   374
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   375
lemma stupid_leq1_1:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   376
  shows " rerase  r2 \<noteq> RSEQ r (RSEQ RONE (rerase r2))"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   377
  apply(induct r2)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   378
        apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   379
  done
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   380
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   381
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   382
lemma rerase_arexp_additional1:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   383
  shows " asize (AALTs bs (rs1 @ rs2)) = rsize (RALTS (map rerase rs1 @ map rerase rs2))"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   384
  apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   385
  by (metis (mono_tags, lifting) asize_rsize comp_apply map_eq_conv)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   386
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   387
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   388
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   389
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   390
lemma rerase2:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   391
  shows "rsizes (map rerase (distinctWith rs2 eq1 (set rs1))) \<le> rsizes (map rerase rs2)"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   392
  apply(induct rs2 arbitrary: rs1)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   393
   apply simp+
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   394
  by (metis List.set_insert trans_le_add2)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   395
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   396
lemma rerase3:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   397
  shows "rsize (RALTS (map rerase rs1 @ map rerase (distinctWith rs2 eq1 (set rs1)))) \<le> rsize (RALTS (map rerase rs1 @ map rerase rs2))"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   398
  using rerase2 by force
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   399
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   400
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   401
lemma bsimpalts_size:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   402
  shows "asize (bsimp_AALTs bs rs) \<le> asize (AALTs bs rs)"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   403
  apply(case_tac rs)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   404
   apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   405
  apply(case_tac list)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   406
   apply auto
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   407
  by (metis asize_rsize dual_order.refl le_SucI rerase_fuse)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   408
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   409
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   410
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   411
lemma leq1_size:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   412
  shows "r1 \<le>1 r2 \<Longrightarrow> asize r1 \<le> asize r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   413
  apply (induct rule: leq1.induct)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   414
               apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   415
  apply (metis asize_rsize le_SucI le_add2 plus_1_eq_Suc rerase_fuse)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   416
           apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   417
          apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   418
  
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   419
          apply (metis (mono_tags, lifting) asize_rsize comp_apply dual_order.eq_iff le_SucI map_eq_conv rerase_fuse)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   420
  apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   421
  apply (metis Suc_n_not_le_n asize_rsize linorder_le_cases rerase_fuse)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   422
  apply(case_tac "r1' = AZERO")
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   423
   apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   424
  apply(case_tac "\<exists>bs1. r1' = AONE bs1")
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   425
   apply(erule exE)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   426
   apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   427
  apply (metis asize_rsize le_SucI rerase_fuse trans_le_add2)
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   428
  apply (smt (verit, best) Suc_eq_plus1 ab_semigroup_add_class.add_ac(1) add.commute add.right_neutral add_cancel_right_right add_mono_thms_linordered_semiring(1) asize.simps(5) asize_rsize nat_add_left_cancel_le order.trans order_trans plus_1_eq_Suc rSEQ_mono rerase_bsimp_ASEQ rsize.simps(5))
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   429
     apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   430
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   431
  using dual_order.trans apply blast
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   432
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   433
  using rerase3 rerase_arexp_additional1 apply force
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   434
  using bsimpalts_size by blast
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   435
  
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   436
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   437
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   438
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   439
lemma size_deciding_equality:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   440
  shows "asize r1 \<noteq> asize r2 \<Longrightarrow> r1 \<noteq> r2 "
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   441
  apply auto
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   442
  done
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   443
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   444
lemma size_deciding_equality2:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   445
  shows "rerase r1 = rerase r2 \<Longrightarrow> asize r1 = asize r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   446
  by (metis asize_rsize)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   447
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   448
lemma size_deciding_equality3:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   449
  shows "asize r1 \<noteq> asize r2 \<Longrightarrow> rerase r1 \<noteq> rerase r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   450
  by (metis asize_rsize)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   451
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   452
lemma size_deciding_equality4:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   453
  shows "rerase a1 = r2 \<Longrightarrow> asize a1 = rsize r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   454
  by (metis asize_rsize)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   455
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   456
lemma size_deciding_equality5:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   457
  shows "asize a1 \<noteq> rsize r2 \<Longrightarrow>rerase a1 \<noteq> r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   458
  by (metis asize_rsize)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   459
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   460
lemma leq1_trans1:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   461
  shows " r1 \<le>1 r2 \<Longrightarrow>  rerase r1 \<noteq> RSEQ r (rerase r2)"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   462
  apply(induct rule: leq1.induct)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   463
               apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   464
  using rerase_fuse stupid_leq1_1 apply presburger
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   465
           apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   466
        apply(subgoal_tac "asize r1 \<noteq> rsize (RSEQ r (RSEQ RONE (rerase r2)))")
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   467
  using size_deciding_equality5 apply blast
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   468
  using asize_rsize leq1_size apply fastforce
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   469
       apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   470
  apply(subgoal_tac "rsize (rerase (fuse bs ra)) \<noteq> rsize (RSEQ r (RALTS [rerase ra]))")
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   471
  
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   472
  apply force
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   473
  apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   474
  apply(simp add: asize_rsize)
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   475
  apply (simp add: rerase_fuse size_deciding_equality4)
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   476
    apply (metis Suc_n_not_le_n asize_rsize leq1.intros(15) leq1_size rsize.simps(5) trans_le_add2)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   477
  apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   478
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   479
  apply (metis asize_rsize leq1_size lessI nle_le not_add_less2 plus_1_eq_Suc rsize.simps(5) trans_le_add2)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   480
   apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   481
  by (metis Suc_n_not_le_n bsimpalts_size rsize.simps(5) size_deciding_equality5 trans_le_add2)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   482
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   483
lemma leq1_neq:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   484
  shows "\<lbrakk>r1 \<le>1 r2 ; r1 \<noteq> r2\<rbrakk> \<Longrightarrow> asize r1 < asize r2"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   485
  apply(induct rule : leq1.induct)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   486
                    apply simp+
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   487
                 apply (metis asize_rsize lessI less_SucI rerase_fuse)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   488
  apply simp+
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   489
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   490
               apply (metis (mono_tags, lifting) comp_apply less_SucI map_eq_conv not_less_less_Suc_eq rerase_fuse size_deciding_equality3)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   491
  apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   492
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   493
  apply (simp add: asize0)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   494
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   495
  using less_Suc_eq apply auto[1]
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   496
            apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   497
           apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   498
          apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   499
         apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   500
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   501
  oops
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   502
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   503
lemma leq1_leq_case1:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   504
  shows " \<lbrakk>r1 \<le>1 r2; r1 = r2 \<or> rerase r1 \<noteq> rerase r2; r2 \<le>1 r3; r2 = r3 \<or> rerase r2 \<noteq> rerase r3\<rbrakk> \<Longrightarrow> r1 = r3 \<or> rerase r1 \<noteq> rerase r3"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   505
  apply(induct rule: leq1.induct)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   506
                    apply simp+
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   507
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   508
  apply (metis rerase.elims rrexp.distinct(1) rrexp.distinct(11) rrexp.distinct(3) rrexp.distinct(5) rrexp.distinct(7) rrexp.distinct(9))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   509
                  apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   510
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   511
                  apply (metis leq1_trans1 rerase.simps(1) rerase.simps(5))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   512
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   513
                 apply (metis leq1_trans1 rerase.simps(5) rerase_fuse)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   514
                apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   515
                apply auto
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   516
 
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   517
  oops
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   518
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   519
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   520
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   521
lemma scomp_rerase3:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   522
  shows "r1 ~1 r2 \<Longrightarrow> s_complexity r1 = s_complexity r2"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   523
  apply(induct rule: eq1.induct)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   524
                      apply simp+
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   525
  done
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   526
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   527
  
588
Chengsong
parents: 587
diff changeset
   528
Chengsong
parents: 587
diff changeset
   529
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   530
lemma scomp_rerase2:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   531
  shows "rerase r1 = rerase r2 \<Longrightarrow> s_complexity r1 = s_complexity r2"  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   532
  using eq1rerase scomp_rerase3 by blast
588
Chengsong
parents: 587
diff changeset
   533
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   534
588
Chengsong
parents: 587
diff changeset
   535
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   536
588
Chengsong
parents: 587
diff changeset
   537
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   538
lemma scomp_rerase:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   539
  shows "s_complexity r1 < s_complexity r2 \<Longrightarrow>rerase  r1 \<noteq> rerase r2"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   540
  by (metis nat_neq_iff scomp_rerase2)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   541
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   542
thm bsimp_ASEQ.simps
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   543
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   544
lemma scomp_bsimpalts:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   545
  shows "s_complexity (bsimp_ASEQ bs1 r1' r2') \<le> s_complexity (ASEQ bs1 r1' r2')"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   546
  apply(case_tac "r1' = AZERO")
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   547
   apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   548
  apply(case_tac "r2' = AZERO")
588
Chengsong
parents: 587
diff changeset
   549
  apply simp
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   550
  apply(case_tac "\<exists>bs2. r1' = AONE bs2")
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   551
   apply(erule exE)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   552
 
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   553
   apply simp
588
Chengsong
parents: 587
diff changeset
   554
  
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   555
  apply (metis le_SucI le_add2 plus_1_eq_Suc rerase_fuse scomp_rerase2)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   556
  apply(subgoal_tac "bsimp_ASEQ bs1 r1' r2' = ASEQ bs1 r1' r2'")
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   557
   apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   558
  using bsimp_ASEQ1 by presburger
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   559
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   560
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   561
lemma scompsize_aux:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   562
  shows "s_complexity (AALTs bs (rs1 @ distinctWith rs2 eq1 (set rs1))) \<le> s_complexity (AALTs bs (rs1 @ rs2))"
600
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   563
  apply(induct rs2 arbitrary: rs1)
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   564
   apply simp
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   565
  apply simp
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   566
  apply(case_tac "\<exists>x \<in> set rs1. a ~1 x")
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   567
  using trans_le_add2 apply blast
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   568
  apply simp
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   569
  
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   570
  by (metis List.set_insert)
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   571
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   572
  
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   573
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   574
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   575
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   576
lemma scomp_size_reduction:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   577
  shows "r1 \<le>1 r2 \<Longrightarrow> s_complexity r1 \<le> s_complexity r2"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   578
  apply(induct rule: leq1.induct)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   579
                    apply simp+
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   580
                 apply (metis le_SucI le_add2 plus_1_eq_Suc rerase_fuse scomp_rerase2)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   581
  apply simp+
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   582
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   583
  apply (smt (verit) comp_apply dual_order.eq_iff map_eq_conv plus_1_eq_Suc rerase_fuse scomp_rerase2 trans_le_add2)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   584
              apply simp+
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   585
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   586
       apply (metis le_SucI le_add2 plus_1_eq_Suc rerase_fuse scomp_rerase2)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   587
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   588
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   589
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   590
  apply (smt (verit, del_insts) add_mono_thms_linordered_semiring(1) dual_order.trans le_numeral_extra(4) plus_1_eq_Suc s_complexity.simps(5) scomp_bsimpalts)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   591
     apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   592
    apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   593
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   594
  using scompsize_aux apply auto[1]
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   595
  apply(case_tac rs)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   596
   apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   597
  apply(case_tac "list")
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   598
   apply auto
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   599
  by (metis eq_imp_le le_imp_less_Suc less_imp_le_nat rerase_fuse scomp_rerase2)
588
Chengsong
parents: 587
diff changeset
   600
600
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   601
lemma prf22:
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   602
  shows "\<lbrakk>r1 \<le>1 r2; \<not> r1 ~1 r2\<rbrakk> \<Longrightarrow> s_complexity r1 \<noteq> s_complexity r2"
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   603
  apply(induct rule:eq1.induct)
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   604
                      apply simp+
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   605
                      apply auto
588
Chengsong
parents: 587
diff changeset
   606
600
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   607
  sorry
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   608
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   609
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   610
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   611
lemma compl_rrewrite_down1:
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   612
  shows "r1 \<le>1 r2 \<Longrightarrow> r1 ~1 r2 \<or> s_complexity r1 < s_complexity r2"
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   613
    apply(subgoal_tac "s_complexity r1 \<le> s_complexity r2")
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   614
  apply(case_tac "r1 ~1 r2")
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   615
    apply simp
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   616
   apply(subgoal_tac "s_complexity r1 \<noteq> s_complexity r2")
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   617
    apply simp
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   618
  using prf22 apply blast
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   619
  by (simp add: scomp_size_reduction)
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   620
  
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   621
lemma leq1_eq1_equal:
601
Chengsong
parents: 600
diff changeset
   622
  shows "\<lbrakk>r1 \<le>1 r2; bsimp r2 = r1 \<rbrakk> \<Longrightarrow> r1 = r2 \<or> s_complexity r1 < s_complexity r2"
Chengsong
parents: 600
diff changeset
   623
  sorry
588
Chengsong
parents: 587
diff changeset
   624
Chengsong
parents: 587
diff changeset
   625
Chengsong
parents: 587
diff changeset
   626
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   627
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   628
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   629
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   630
lemma compl_rrewrite_down:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   631
  shows "r1 \<le>1 r2 \<Longrightarrow>r1 = r2 \<or> s_complexity r1 < s_complexity r2"
600
fd068f39ac23 chap4 comments done
Chengsong
parents: 597
diff changeset
   632
  apply(subgoal_tac "s_complexity r1 \<le> s_complexity r2")
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   633
  
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   634
  apply(induct rule: leq1.induct)
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   635
                    apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   636
                   apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   637
                  apply simp
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   638
  apply (smt (verit) fuse.elims lessI less_Suc_eq plus_1_eq_Suc s_complexity.simps(2) s_complexity.simps(3) s_complexity.simps(4) s_complexity.simps(5) s_complexity.simps(6) s_complexity.simps(7))
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   639
                apply simp
588
Chengsong
parents: 587
diff changeset
   640
  sorry
Chengsong
parents: 587
diff changeset
   641
Chengsong
parents: 587
diff changeset
   642
618
233cf2b97d1a chapter 5 finished!!
Chengsong
parents: 601
diff changeset
   643
lemma compl_rrewrite_down1_1:
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   644
  shows "\<lbrakk>r1 \<le>1 r2; s_complexity r1 = s_complexity r2 \<rbrakk> \<Longrightarrow> r1 = r2"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   645
  using compl_rrewrite_down nat_less_le by auto
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   646
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   647
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   648
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   649
lemma leq1_less_or_equal: shows
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   650
"r1 \<le>1 r2 \<Longrightarrow> r1 = r2 \<or> rerase r1 \<noteq> rerase r2"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   651
  using compl_rrewrite_down scomp_rerase by blast
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   652
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   653
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   654
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   655
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   656
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   657
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   658
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   659
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   660
588
Chengsong
parents: 587
diff changeset
   661
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   662
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   663
lemma arexp_finite1:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   664
  shows "rerase (bsimp b) = rerase b \<Longrightarrow> bsimp b = b"
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   665
  using bsimp_leq1 leq1_less_or_equal by blast
588
Chengsong
parents: 587
diff changeset
   666
  
597
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   667
lemma bsimp_idem:
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   668
  shows "bsimp (bsimp r ) = bsimp r"
19d304554ae1 more bsimpidem
Chengsong
parents: 591
diff changeset
   669
  using arexp_finite1 bsimp_rerase rsimp_idem by presburger
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   670
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   671
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   672
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   673
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   674
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   675
end