thys4/posix/FBound.thy
author Chengsong
Tue, 30 Aug 2022 12:41:52 +0100
changeset 588 80e1114d6421
parent 587 3198605ac648
child 589 86e0203db2da
permissions -rw-r--r--
data
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
588
Chengsong
parents: 587
diff changeset
   250
lemma aux_aux_aux:
Chengsong
parents: 587
diff changeset
   251
  shows "map rerase (flts (map bsimp rs)) = map rerase rs \<Longrightarrow> map rerase (map bsimp rs) = map rerase rs"
Chengsong
parents: 587
diff changeset
   252
  oops
Chengsong
parents: 587
diff changeset
   253
Chengsong
parents: 587
diff changeset
   254
inductive leq1 ("_ \<le>1 _" [80, 80] 80) where  
Chengsong
parents: 587
diff changeset
   255
  "r1 \<le>1 r1"
Chengsong
parents: 587
diff changeset
   256
| "AZERO \<le>1 ASEQ bs AZERO r" 
Chengsong
parents: 587
diff changeset
   257
| "AZERO \<le>1 ASEQ bs r AZERO"
Chengsong
parents: 587
diff changeset
   258
| "fuse (bs @ bs1) r2 \<le>1 ASEQ bs (AONE bs1) r2"
Chengsong
parents: 587
diff changeset
   259
| " AALTs bs (rs1 @ rs) \<le>1 AALTs bs (rs1 @( AZERO # rs))"
Chengsong
parents: 587
diff changeset
   260
| "r2 \<le>1 r1 \<Longrightarrow> AALTs bs (rs1 @ r2 # rs) \<le>1 AALTs bs (rs1 @ r1 # rs)"
Chengsong
parents: 587
diff changeset
   261
| "AALTs bs1 (rsa @ (map (fuse bs1) rs1) @ rsb) \<le>1 AALTs bs1 (rsa @ (AALTs bs1 rs1) # rsb)"
Chengsong
parents: 587
diff changeset
   262
| "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
   263
| "r1 \<le>1 r2 \<Longrightarrow> r1  \<le>1 ASEQ bs (AONE bs1) r2"
Chengsong
parents: 587
diff changeset
   264
Chengsong
parents: 587
diff changeset
   265
lemma leq1_less_or_equal: shows
Chengsong
parents: 587
diff changeset
   266
"r1 \<le>1 r2 \<Longrightarrow> r1 = r2 \<or> rerase r1 \<noteq> rerase r2"
Chengsong
parents: 587
diff changeset
   267
  apply(induct rule: leq1.induct)
Chengsong
parents: 587
diff changeset
   268
          apply simp+
Chengsong
parents: 587
diff changeset
   269
  sorry
Chengsong
parents: 587
diff changeset
   270
Chengsong
parents: 587
diff changeset
   271
lemma bsimp_leq1:
Chengsong
parents: 587
diff changeset
   272
  shows "bsimp r \<le>1 r"
Chengsong
parents: 587
diff changeset
   273
Chengsong
parents: 587
diff changeset
   274
  sorry
Chengsong
parents: 587
diff changeset
   275
Chengsong
parents: 587
diff changeset
   276
Chengsong
parents: 587
diff changeset
   277
lemma arexpfiniteaux4_aux:
Chengsong
parents: 587
diff changeset
   278
  shows" \<lbrakk>rerase (bsimp_AALTs bs1 (distinctWith (flts (map bsimp rs)) eq1 {})) = RALTS (map rerase rs) \<rbrakk>
Chengsong
parents: 587
diff changeset
   279
       \<Longrightarrow> map rerase (map bsimp rs) = map rerase rs"
Chengsong
parents: 587
diff changeset
   280
  apply(induct rs)
Chengsong
parents: 587
diff changeset
   281
   apply simp
Chengsong
parents: 587
diff changeset
   282
  apply simp
Chengsong
parents: 587
diff changeset
   283
  apply auto
Chengsong
parents: 587
diff changeset
   284
   prefer 2
Chengsong
parents: 587
diff changeset
   285
Chengsong
parents: 587
diff changeset
   286
  sorry
Chengsong
parents: 587
diff changeset
   287
Chengsong
parents: 587
diff changeset
   288
lemma arexpfiniteaux4:
Chengsong
parents: 587
diff changeset
   289
  shows"
Chengsong
parents: 587
diff changeset
   290
       \<lbrakk>\<And>x. \<lbrakk>x \<in> set rs; rerase (bsimp x) = rerase x\<rbrakk> \<Longrightarrow> bsimp x = x;
Chengsong
parents: 587
diff changeset
   291
        rerase (bsimp_AALTs bs1 (distinctWith (flts (map bsimp rs)) eq1 {})) = RALTS (map rerase rs)\<rbrakk>
Chengsong
parents: 587
diff changeset
   292
       \<Longrightarrow> bsimp_AALTs bs1 (distinctWith (flts (map bsimp rs)) eq1 {}) = AALTs bs1 rs"
Chengsong
parents: 587
diff changeset
   293
  apply(induct rs)
Chengsong
parents: 587
diff changeset
   294
  apply simp
Chengsong
parents: 587
diff changeset
   295
  
Chengsong
parents: 587
diff changeset
   296
Chengsong
parents: 587
diff changeset
   297
Chengsong
parents: 587
diff changeset
   298
Chengsong
parents: 587
diff changeset
   299
Chengsong
parents: 587
diff changeset
   300
Chengsong
parents: 587
diff changeset
   301
  sorry
Chengsong
parents: 587
diff changeset
   302
Chengsong
parents: 587
diff changeset
   303
Chengsong
parents: 587
diff changeset
   304
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   305
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   306
lemma arexp_finite1:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   307
  shows "rerase (bsimp b) = rerase b \<Longrightarrow> bsimp b = b"
588
Chengsong
parents: 587
diff changeset
   308
  apply(induct rule: bsimp.induct)
Chengsong
parents: 587
diff changeset
   309
        apply simp
Chengsong
parents: 587
diff changeset
   310
        apply (smt (verit) arexpfiniteaux1 arexpfiniteaux2 arexpfiniteaux3 bsimp_ASEQ1 rerase.simps(5) rrexp.inject(2))
Chengsong
parents: 587
diff changeset
   311
  apply simp
Chengsong
parents: 587
diff changeset
   312
  
Chengsong
parents: 587
diff changeset
   313
  using arexpfiniteaux4 apply blast
Chengsong
parents: 587
diff changeset
   314
      apply simp+
Chengsong
parents: 587
diff changeset
   315
  done
Chengsong
parents: 587
diff changeset
   316
(*
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   317
  apply(induct b)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   318
        apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   319
         apply(case_tac "bsimp b2 = AZERO")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   320
          apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   321
     apply (case_tac "bsimp b1 = AZERO")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   322
      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   323
  apply(case_tac "\<exists>bs. bsimp b1 = AONE bs")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   324
  using arexpfiniteaux1 apply blast
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   325
     apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   326
     apply(subgoal_tac "bsimp_ASEQ x1 (bsimp b1) (bsimp b2) = ASEQ x1 (bsimp b1) (bsimp b2)")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   327
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   328
  using bsimp_ASEQ1 apply presburger
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   329
  apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   330
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   331
  sorry
588
Chengsong
parents: 587
diff changeset
   332
*)
Chengsong
parents: 587
diff changeset
   333
587
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   334
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   335
lemma bitcodes_unchanging2:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   336
  assumes "bsimp a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   337
and "a ~1 b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   338
shows "a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   339
  using assms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   340
  apply(induct rule: eq1.induct)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   341
                      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   342
                      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   343
                      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   344
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   345
                      apply auto
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   346
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   347
  sorry
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   348
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   349
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   350
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   351
lemma bitcodes_unchanging:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   352
  shows "\<lbrakk>bsimp a = b; rerase a = rerase b \<rbrakk> \<Longrightarrow> a = b"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   353
  apply(induction a arbitrary: b)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   354
        apply simp+
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   355
     apply(case_tac "\<exists>bs. bsimp a1 = AONE bs")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   356
      apply(erule exE)
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   357
      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   358
      prefer 2
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   359
      apply(case_tac "bsimp a1 = AZERO")
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   360
       apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   361
      apply simp
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   362
      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
   363
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   364
  sorry
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   365
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   366
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   367
lemma bagnostic_shows_bsimp_idem:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   368
  assumes "bitcode_agnostic bsimp"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   369
and "rerase (bsimp a) = rsimp (rerase a)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   370
and "rsimp r = rsimp (rsimp r)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   371
shows "bsimp a = bsimp (bsimp a)"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   372
  
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   373
  oops
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   374
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   375
theorem bsimp_idem:
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   376
  shows "bsimp (bsimp a) = bsimp a"
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   377
  using bitcodes_unchanging bsimp_rerase rsimp_idem by auto
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   378
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   379
unused_thms
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   380
3198605ac648 bsimp idempotency
Chengsong
parents:
diff changeset
   381
end