thys4/posix/FBound.thy
author Chengsong
Mon, 29 Aug 2022 23:16:28 +0100
changeset 587 3198605ac648
child 588 80e1114d6421
permissions -rw-r--r--
bsimp idempotency
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
lemma cant1:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   188
  shows "\<lbrakk> bsimp a = b; rerase a = rerase b; a = ASEQ bs r1 r2 \<rbrakk> \<Longrightarrow>
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   189
        \<exists>bs' r1' r2'. b = ASEQ bs' r1' r2' \<and> rerase r1' = rerase r1 \<and> rerase r2' = rerase r2"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   190
  sorry
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   191
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   192
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   193
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   194
(*"part is less than whole" thm for rrexp, since rrexp is always finite*)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   195
lemma rrexp_finite1:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   196
  shows "\<lbrakk> bsimp_ASEQ bs1 (bsimp ra1) (bsimp ra2) = ASEQ bs2 rb1 rb2; ra1 ~1 rb1; ra2 ~1 rb2 \<rbrakk> \<Longrightarrow> rerase ra1 = rerase (bsimp ra1) "
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   197
  apply(case_tac ra1 )
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   198
        apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   199
     apply(case_tac rb1)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   200
           apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   201
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   202
  sorry
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   203
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   204
lemma unsure_unchanging:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   205
  assumes "bsimp a = bsimp b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   206
and "a ~1 b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   207
shows "a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   208
  using assms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   209
  apply(induct rule: eq1.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   210
                      apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   211
  oops
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   212
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   213
lemma eq1rerase:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   214
  shows "rerase r1 = rerase r2 \<longleftrightarrow> r1 ~1 r2"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   215
  using eq1_rerase by presburger
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   216
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   217
thm contrapos_pp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   218
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   219
lemma r_part_neq_whole:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   220
  shows "RSEQ r1 r2 \<noteq> r2"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   221
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   222
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   223
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   224
lemma r_part_neq_whole2:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   225
  shows "RSEQ r1 r2 \<noteq> rsimp r2"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   226
  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
   227
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   228
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   229
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   230
lemma arexpfiniteaux1:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   231
  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
   232
  apply(erule contrapos_pp)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   233
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   234
  apply(erule exE)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   235
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   236
  by (metis bsimp_rerase r_part_neq_whole2 rerase_fuse)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   237
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   238
lemma arexpfiniteaux2:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   239
  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
   240
  apply(erule contrapos_pp)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   241
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   242
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   243
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   244
lemma arexpfiniteaux3:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   245
  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
   246
  apply(erule contrapos_pp)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   247
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   248
  done
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   249
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   250
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   251
lemma arexp_finite1:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   252
  shows "rerase (bsimp b) = rerase b \<Longrightarrow> bsimp b = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   253
  apply(induct b)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   254
        apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   255
         apply(case_tac "bsimp b2 = AZERO")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   256
          apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   257
     apply (case_tac "bsimp b1 = AZERO")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   258
      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   259
  apply(case_tac "\<exists>bs. bsimp b1 = AONE bs")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   260
  using arexpfiniteaux1 apply blast
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   261
     apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   262
     apply(subgoal_tac "bsimp_ASEQ x1 (bsimp b1) (bsimp b2) = ASEQ x1 (bsimp b1) (bsimp b2)")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   263
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   264
  using bsimp_ASEQ1 apply presburger
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   265
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   266
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   267
  sorry
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   268
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   269
lemma bitcodes_unchanging2:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   270
  assumes "bsimp a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   271
and "a ~1 b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   272
shows "a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   273
  using assms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   274
  apply(induct rule: eq1.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   275
                      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   276
                      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   277
                      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   278
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   279
                      apply auto
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   280
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   281
  sorry
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   282
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   283
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   284
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   285
lemma bitcodes_unchanging:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   286
  shows "\<lbrakk>bsimp a = b; rerase a = rerase b \<rbrakk> \<Longrightarrow> a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   287
  apply(induction a arbitrary: b)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   288
        apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   289
     apply(case_tac "\<exists>bs. bsimp a1 = AONE bs")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   290
      apply(erule exE)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   291
      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   292
      prefer 2
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   293
      apply(case_tac "bsimp a1 = AZERO")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   294
       apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   295
      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   296
      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
   297
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   298
  sorry
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   299
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   300
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   301
lemma bagnostic_shows_bsimp_idem:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   302
  assumes "bitcode_agnostic bsimp"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   303
and "rerase (bsimp a) = rsimp (rerase a)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   304
and "rsimp r = rsimp (rsimp r)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   305
shows "bsimp a = bsimp (bsimp a)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   306
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   307
  oops
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   308
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   309
theorem bsimp_idem:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   310
  shows "bsimp (bsimp a) = bsimp a"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   311
  using bitcodes_unchanging bsimp_rerase rsimp_idem by auto
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   312
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   313
unused_thms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   314
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   315
end