thys4/posix/FBound.thy
author Chengsong
Thu, 01 Sep 2022 23:47:37 +0100
changeset 591 b2d0de6aee18
parent 590 988e92a70704
child 597 19d304554ae1
permissions -rw-r--r--
more polishing integrated comments chap2
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
Chengsong
parents: 587
diff changeset
   239
inductive leq1 ("_ \<le>1 _" [80, 80] 80) where  
Chengsong
parents: 587
diff changeset
   240
  "r1 \<le>1 r1"
Chengsong
parents: 587
diff changeset
   241
| "AZERO \<le>1 ASEQ bs AZERO r" 
Chengsong
parents: 587
diff changeset
   242
| "AZERO \<le>1 ASEQ bs r AZERO"
Chengsong
parents: 587
diff changeset
   243
| "fuse (bs @ bs1) r2 \<le>1 ASEQ bs (AONE bs1) r2"
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   244
| "AALTs bs (rs1 @ rs) \<le>1 AALTs bs (rs1 @( AZERO # rs))"
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   245
| "AALTs bs (rsa @ (map (fuse bs1) rs1) @ rsb) \<le>1 AALTs bs (rsa @ (AALTs bs1 rs1) # rsb)"
588
Chengsong
parents: 587
diff changeset
   246
| "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
   247
| "r1 \<le>1 r2 \<Longrightarrow> r1  \<le>1 ASEQ bs (AONE bs1) r2"
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   248
| "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
   249
| "r2 \<le>1 r1 \<Longrightarrow> ASEQ bs r  r2 \<le>1 ASEQ bs r r1"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   250
| "r2 \<le>1 r1 \<Longrightarrow> ASEQ bs r2 r  \<le>1 ASEQ bs r1 r"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   251
| "r \<le>1 r' \<Longrightarrow> ASTAR bs r \<le>1 ASTAR bs r'"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   252
| "AZERO \<le>1 AALTs bs []"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   253
| "fuse bs r \<le>1 AALTs bs [r]"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   254
| "\<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
   255
| "\<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
   256
| "\<lbrakk>r1 \<le>1 r2; r2 \<le>1 r3 \<rbrakk> \<Longrightarrow> r1 \<le>1 r3"
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   257
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   258
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   259
lemma leq1_6_variant1:
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   260
  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
   261
  by (metis leq1.intros(6) self_append_conv2)
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   262
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   263
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   264
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   265
lemma flts_leq1:
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   266
  shows "AALTs bs (flts rs) \<le>1 AALTs bs rs"
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   267
  apply(induct rule: flts.induct)
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   268
         apply (simp add: leq1.intros(1))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   269
        apply simp
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   270
  apply (metis append_Nil leq1.intros(17) leq1.intros(5))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   271
       apply simp
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   272
       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
   273
        apply (meson leq1.intros(1) leq1.intros(16) leq1.intros(17))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   274
  using leq1_6_variant1 apply presburger
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   275
  apply (simp add: leq1.intros(1) leq1.intros(16))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   276
  using leq1.intros(1) leq1.intros(16) apply auto[1]
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   277
  using leq1.intros(1) leq1.intros(16) apply force
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   278
   apply (simp add: leq1.intros(1) leq1.intros(16))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   279
  using leq1.intros(1) leq1.intros(16) by force
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   280
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   281
lemma dB_leq12:
591
b2d0de6aee18 more polishing integrated comments chap2
Chengsong
parents: 590
diff changeset
   282
  shows "AALTs bs (rs1 @ (distinctWith rs1 eq1 (set rs2))) \<le>1 AALTs bs (rs1 @ rs2)"
b2d0de6aee18 more polishing integrated comments chap2
Chengsong
parents: 590
diff changeset
   283
  apply(induct rs1 arbitrary: rs2)
b2d0de6aee18 more polishing integrated comments chap2
Chengsong
parents: 590
diff changeset
   284
  apply simp
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   285
  sorry
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   286
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   287
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   288
lemma dB_leq1:
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   289
  shows "AALTs bs (distinctWith rs eq1 {}) \<le>1 AALTs bs rs"
591
b2d0de6aee18 more polishing integrated comments chap2
Chengsong
parents: 590
diff changeset
   290
  sorry
b2d0de6aee18 more polishing integrated comments chap2
Chengsong
parents: 590
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
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   294
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   295
lemma stupid_leq1_1:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   296
  shows " rerase  r2 \<noteq> RSEQ r (RSEQ RONE (rerase r2))"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   297
  apply(induct r2)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   298
        apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   299
  done
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   300
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   301
lemma leq1_size:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   302
  shows "r1 \<le>1 r2 \<Longrightarrow> asize r1 \<le> asize r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   303
  apply (induct rule: leq1.induct)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   304
               apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   305
  apply (metis asize_rsize le_SucI le_add2 plus_1_eq_Suc rerase_fuse)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   306
           apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   307
          apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   308
  
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   309
          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
   310
  apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   311
  apply (metis Suc_n_not_le_n asize_rsize linorder_le_cases rerase_fuse)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   312
  apply(case_tac "r1' = AZERO")
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   313
   apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   314
  apply(case_tac "\<exists>bs1. r1' = AONE bs1")
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   315
   apply(erule exE)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   316
   apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   317
  apply (metis asize_rsize le_SucI rerase_fuse trans_le_add2)
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   318
  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))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   319
  sorry
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   320
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   321
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   322
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   323
lemma size_deciding_equality:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   324
  shows "asize r1 \<noteq> asize r2 \<Longrightarrow> r1 \<noteq> r2 "
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   325
  apply auto
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   326
  done
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   327
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   328
lemma size_deciding_equality2:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   329
  shows "rerase r1 = rerase r2 \<Longrightarrow> asize r1 = asize r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   330
  by (metis asize_rsize)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   331
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   332
lemma size_deciding_equality3:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   333
  shows "asize r1 \<noteq> asize r2 \<Longrightarrow> rerase r1 \<noteq> rerase r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   334
  by (metis asize_rsize)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   335
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   336
lemma size_deciding_equality4:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   337
  shows "rerase a1 = r2 \<Longrightarrow> asize a1 = rsize r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   338
  by (metis asize_rsize)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   339
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   340
lemma size_deciding_equality5:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   341
  shows "asize a1 \<noteq> rsize r2 \<Longrightarrow>rerase a1 \<noteq> r2"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   342
  by (metis asize_rsize)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   343
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   344
lemma leq1_trans1:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   345
  shows " r1 \<le>1 r2 \<Longrightarrow>  rerase r1 \<noteq> RSEQ r (rerase r2)"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   346
  apply(induct rule: leq1.induct)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   347
               apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   348
  using rerase_fuse stupid_leq1_1 apply presburger
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   349
           apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   350
        apply(subgoal_tac "asize r1 \<noteq> rsize (RSEQ r (RSEQ RONE (rerase r2)))")
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   351
  using size_deciding_equality5 apply blast
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   352
  using asize_rsize leq1_size apply fastforce
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   353
       apply simp+
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   354
  apply(subgoal_tac "rsize (rerase (fuse bs ra)) \<noteq> rsize (RSEQ r (RALTS [rerase ra]))")
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   355
  
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   356
  apply force
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   357
  apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   358
  apply(simp add: asize_rsize)
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   359
  apply (simp add: rerase_fuse size_deciding_equality4)
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   360
  apply (metis Suc_n_not_le_n asize_rsize leq1.intros(15) leq1_size rsize.simps(5) trans_le_add2)
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   361
  sorry
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   362
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   363
  
588
Chengsong
parents: 587
diff changeset
   364
Chengsong
parents: 587
diff changeset
   365
lemma leq1_less_or_equal: shows
Chengsong
parents: 587
diff changeset
   366
"r1 \<le>1 r2 \<Longrightarrow> r1 = r2 \<or> rerase r1 \<noteq> rerase r2"
Chengsong
parents: 587
diff changeset
   367
  apply(induct rule: leq1.induct)
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   368
               apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   369
              apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   370
  apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   371
            apply (simp add: rerase_fuse)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   372
           apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   373
  apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   374
  using r_finite1 rerase_fuse apply force
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   375
         apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   376
        apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   377
        apply(case_tac "r1 = r2")
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   378
         apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   379
        apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   380
  
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   381
  using leq1_trans1 apply presburger
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   382
       apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   383
      apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   384
     apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   385
    apply simp
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   386
   apply simp
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   387
   apply simp
588
Chengsong
parents: 587
diff changeset
   388
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   389
  using r_finite1 rerase_fuse apply auto[1]
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   390
  apply (smt (verit, best) BlexerSimp.bsimp_ASEQ0 BlexerSimp.bsimp_ASEQ2 bsimp_ASEQ.simps(1) bsimp_ASEQ1 leq1_trans1 rerase.simps(5) rerase_bsimp_ASEQ rerase_fuse rrexp.inject(2) rsimp_SEQ.simps(22))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   391
  sorry
588
Chengsong
parents: 587
diff changeset
   392
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   393
588
Chengsong
parents: 587
diff changeset
   394
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   395
588
Chengsong
parents: 587
diff changeset
   396
Chengsong
parents: 587
diff changeset
   397
lemma arexpfiniteaux4:
Chengsong
parents: 587
diff changeset
   398
  shows"
Chengsong
parents: 587
diff changeset
   399
       \<lbrakk>\<And>x. \<lbrakk>x \<in> set rs; rerase (bsimp x) = rerase x\<rbrakk> \<Longrightarrow> bsimp x = x;
Chengsong
parents: 587
diff changeset
   400
        rerase (bsimp_AALTs bs1 (distinctWith (flts (map bsimp rs)) eq1 {})) = RALTS (map rerase rs)\<rbrakk>
Chengsong
parents: 587
diff changeset
   401
       \<Longrightarrow> bsimp_AALTs bs1 (distinctWith (flts (map bsimp rs)) eq1 {}) = AALTs bs1 rs"
Chengsong
parents: 587
diff changeset
   402
  apply(induct rs)
Chengsong
parents: 587
diff changeset
   403
  apply simp
Chengsong
parents: 587
diff changeset
   404
  
Chengsong
parents: 587
diff changeset
   405
Chengsong
parents: 587
diff changeset
   406
Chengsong
parents: 587
diff changeset
   407
Chengsong
parents: 587
diff changeset
   408
Chengsong
parents: 587
diff changeset
   409
Chengsong
parents: 587
diff changeset
   410
  sorry
Chengsong
parents: 587
diff changeset
   411
Chengsong
parents: 587
diff changeset
   412
Chengsong
parents: 587
diff changeset
   413
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   414
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   415
lemma arexp_finite1:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   416
  shows "rerase (bsimp b) = rerase b \<Longrightarrow> bsimp b = b"
588
Chengsong
parents: 587
diff changeset
   417
  apply(induct rule: bsimp.induct)
Chengsong
parents: 587
diff changeset
   418
        apply simp
Chengsong
parents: 587
diff changeset
   419
        apply (smt (verit) arexpfiniteaux1 arexpfiniteaux2 arexpfiniteaux3 bsimp_ASEQ1 rerase.simps(5) rrexp.inject(2))
Chengsong
parents: 587
diff changeset
   420
  apply simp
Chengsong
parents: 587
diff changeset
   421
  
Chengsong
parents: 587
diff changeset
   422
  using arexpfiniteaux4 apply blast
Chengsong
parents: 587
diff changeset
   423
      apply simp+
Chengsong
parents: 587
diff changeset
   424
  done
Chengsong
parents: 587
diff changeset
   425
(*
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   426
  apply(induct b)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   427
        apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   428
         apply(case_tac "bsimp b2 = AZERO")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   429
          apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   430
     apply (case_tac "bsimp b1 = AZERO")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   431
      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   432
  apply(case_tac "\<exists>bs. bsimp b1 = AONE bs")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   433
  using arexpfiniteaux1 apply blast
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   434
     apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   435
     apply(subgoal_tac "bsimp_ASEQ x1 (bsimp b1) (bsimp b2) = ASEQ x1 (bsimp b1) (bsimp b2)")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   436
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   437
  using bsimp_ASEQ1 apply presburger
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   438
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   439
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   440
  sorry
588
Chengsong
parents: 587
diff changeset
   441
*)
Chengsong
parents: 587
diff changeset
   442
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   443
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   444
lemma bitcodes_unchanging2:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   445
  assumes "bsimp a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   446
and "a ~1 b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   447
shows "a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   448
  using assms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   449
  apply(induct rule: eq1.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   450
                      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   451
                      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   452
                      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   453
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   454
                      apply auto
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   455
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   456
  sorry
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   457
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   458
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   459
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   460
lemma bsimp_reduces:
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   461
  shows "bsimp r \<le>1 r"
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   462
  apply(induct rule: bsimp.induct)
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   463
        apply simp
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   464
        apply (simp add: leq1.intros(15))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   465
       apply simp
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   466
  apply(case_tac rs)
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   467
        apply simp
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   468
  
590
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   469
  apply (simp add: leq1.intros(13))
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   470
       apply(case_tac list)
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   471
        apply simp
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   472
  
988e92a70704 more chap5 and chap6 bsimp_idem
Chengsong
parents: 589
diff changeset
   473
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   474
  sorry
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   475
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   476
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   477
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   478
lemma bitcodes_unchanging:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   479
  shows "\<lbrakk>bsimp a = b; rerase a = rerase b \<rbrakk> \<Longrightarrow> a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   480
  apply(induction a arbitrary: b)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   481
        apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   482
     apply(case_tac "\<exists>bs. bsimp a1 = AONE bs")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   483
      apply(erule exE)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   484
      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   485
      prefer 2
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   486
      apply(case_tac "bsimp a1 = AZERO")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   487
       apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   488
      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   489
      apply (metis BlexerSimp.bsimp_ASEQ0 bsimp_ASEQ1 rerase.simps(1) rerase.simps(5) rrexp.distinct(5) rrexp.inject(2))
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   490
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   491
  sorry
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   492
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   493
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   494
lemma bagnostic_shows_bsimp_idem:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   495
  assumes "bitcode_agnostic bsimp"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   496
and "rerase (bsimp a) = rsimp (rerase a)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   497
and "rsimp r = rsimp (rsimp r)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   498
shows "bsimp a = bsimp (bsimp a)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   499
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   500
  oops
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   501
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   502
theorem bsimp_idem:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   503
  shows "bsimp (bsimp a) = bsimp a"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   504
  using bitcodes_unchanging bsimp_rerase rsimp_idem by auto
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   505
589
86e0203db2da chap4 finished
Chengsong
parents: 588
diff changeset
   506
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   507
unused_thms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   508
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   509
end