thys2/ClosedForms.thy
author Chengsong
Mon, 04 Apr 2022 23:56:40 +0100
changeset 479 b2a8610cf110
parent 478 51af5f882350
child 480 574749f5190b
permissions -rw-r--r--
hello
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
     1
theory ClosedForms imports
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
     2
"BasicIdentities"
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
     3
begin
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
     4
453
Chengsong
parents: 451
diff changeset
     5
lemma map_concat_cons:
Chengsong
parents: 451
diff changeset
     6
  shows "map f rsa @ f a # rs = map f (rsa @ [a]) @ rs"
Chengsong
parents: 451
diff changeset
     7
  by simp
Chengsong
parents: 451
diff changeset
     8
Chengsong
parents: 451
diff changeset
     9
lemma neg_removal_element_of:
Chengsong
parents: 451
diff changeset
    10
  shows " \<not> a \<notin> aset \<Longrightarrow> a \<in> aset"
Chengsong
parents: 451
diff changeset
    11
  by simp
Chengsong
parents: 451
diff changeset
    12
465
Chengsong
parents: 456
diff changeset
    13
Chengsong
parents: 456
diff changeset
    14
Chengsong
parents: 456
diff changeset
    15
Chengsong
parents: 456
diff changeset
    16
478
Chengsong
parents: 476
diff changeset
    17
465
Chengsong
parents: 456
diff changeset
    18
Chengsong
parents: 456
diff changeset
    19
478
Chengsong
parents: 476
diff changeset
    20
465
Chengsong
parents: 456
diff changeset
    21
Chengsong
parents: 456
diff changeset
    22
lemma flts_middle0:
Chengsong
parents: 456
diff changeset
    23
  shows "rflts (rsa @ RZERO # rsb) = rflts (rsa @ rsb)"
Chengsong
parents: 456
diff changeset
    24
  apply(induct rsa)
Chengsong
parents: 456
diff changeset
    25
  apply simp
Chengsong
parents: 456
diff changeset
    26
  by (metis append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 456
diff changeset
    27
Chengsong
parents: 456
diff changeset
    28
lemma flts_middle01:
Chengsong
parents: 456
diff changeset
    29
  shows "rflts (rsa @ [RZERO] @ rsb) = rflts (rsa @ rsb)"
Chengsong
parents: 456
diff changeset
    30
  by (simp add: flts_middle0)
Chengsong
parents: 456
diff changeset
    31
Chengsong
parents: 456
diff changeset
    32
lemma flts_append1:
Chengsong
parents: 456
diff changeset
    33
  shows "\<lbrakk>a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1; a \<in> set rs\<rbrakk>  \<Longrightarrow>
Chengsong
parents: 456
diff changeset
    34
         rflts (rsa @ [a] @ rsb) = rflts rsa @ [a] @ (rflts rsb)"
Chengsong
parents: 456
diff changeset
    35
  apply(induct rsa arbitrary: rsb)
Chengsong
parents: 456
diff changeset
    36
   apply simp
Chengsong
parents: 456
diff changeset
    37
  using rflts_def_idiot apply presburger
Chengsong
parents: 456
diff changeset
    38
  apply(case_tac aa)  
Chengsong
parents: 456
diff changeset
    39
       apply simp+
Chengsong
parents: 456
diff changeset
    40
  done
Chengsong
parents: 456
diff changeset
    41
478
Chengsong
parents: 476
diff changeset
    42
465
Chengsong
parents: 456
diff changeset
    43
Chengsong
parents: 456
diff changeset
    44
lemma simp_removes_duplicate1:
Chengsong
parents: 456
diff changeset
    45
  shows  " a \<in> set rsa \<Longrightarrow> rsimp (RALTS (rsa @ [a])) =  rsimp (RALTS (rsa))"
Chengsong
parents: 456
diff changeset
    46
and " rsimp (RALTS (a1 # rsa @ [a1])) = rsimp (RALTS (a1 # rsa))"
Chengsong
parents: 456
diff changeset
    47
  apply(induct rsa arbitrary: a1)
Chengsong
parents: 456
diff changeset
    48
     apply simp
Chengsong
parents: 456
diff changeset
    49
    apply simp
Chengsong
parents: 456
diff changeset
    50
  prefer 2
Chengsong
parents: 456
diff changeset
    51
  apply(case_tac "a = aa")
Chengsong
parents: 456
diff changeset
    52
     apply simp
Chengsong
parents: 456
diff changeset
    53
    apply simp
Chengsong
parents: 456
diff changeset
    54
  apply (metis Cons_eq_appendI Cons_eq_map_conv distinct_removes_duplicate_flts list.set_intros(2))
Chengsong
parents: 456
diff changeset
    55
  apply (metis append_Cons append_Nil distinct_removes_duplicate_flts list.set_intros(1) list.simps(8) list.simps(9))
Chengsong
parents: 456
diff changeset
    56
  by (metis (mono_tags, lifting) append_Cons distinct_removes_duplicate_flts list.set_intros(1) list.simps(8) list.simps(9) map_append rsimp.simps(2))
Chengsong
parents: 456
diff changeset
    57
  
Chengsong
parents: 456
diff changeset
    58
lemma simp_removes_duplicate2:
Chengsong
parents: 456
diff changeset
    59
  shows "a \<in> set rsa \<Longrightarrow> rsimp (RALTS (rsa @ [a] @ rsb)) = rsimp (RALTS (rsa @ rsb))"
Chengsong
parents: 456
diff changeset
    60
  apply(induct rsb arbitrary: rsa)
Chengsong
parents: 456
diff changeset
    61
   apply simp
Chengsong
parents: 456
diff changeset
    62
  using distinct_removes_duplicate_flts apply auto[1]
Chengsong
parents: 456
diff changeset
    63
  by (metis append.assoc head_one_more_simp rsimp.simps(2) simp_flatten simp_removes_duplicate1(1))
Chengsong
parents: 456
diff changeset
    64
Chengsong
parents: 456
diff changeset
    65
lemma simp_removes_duplicate3:
Chengsong
parents: 456
diff changeset
    66
  shows "a \<in> set rsa \<Longrightarrow> rsimp (RALTS (rsa @ a # rsb)) = rsimp (RALTS (rsa @ rsb))"
Chengsong
parents: 456
diff changeset
    67
  using simp_removes_duplicate2 by auto
Chengsong
parents: 456
diff changeset
    68
Chengsong
parents: 456
diff changeset
    69
lemma distinct_removes_middle4:
Chengsong
parents: 456
diff changeset
    70
  shows "a \<in> set rsa \<Longrightarrow> rdistinct (rsa @ [a] @ rsb) rset = rdistinct (rsa @ rsb) rset"
Chengsong
parents: 456
diff changeset
    71
  using distinct_removes_middle(1) by fastforce
Chengsong
parents: 456
diff changeset
    72
Chengsong
parents: 456
diff changeset
    73
lemma distinct_removes_middle_list:
Chengsong
parents: 456
diff changeset
    74
  shows "\<forall>a \<in> set x. a \<in> set rsa \<Longrightarrow> rdistinct (rsa @ x @ rsb) rset = rdistinct (rsa @ rsb) rset"
Chengsong
parents: 456
diff changeset
    75
  apply(induct x)
Chengsong
parents: 456
diff changeset
    76
   apply simp
Chengsong
parents: 456
diff changeset
    77
  by (simp add: distinct_removes_middle3)
Chengsong
parents: 456
diff changeset
    78
Chengsong
parents: 456
diff changeset
    79
Chengsong
parents: 456
diff changeset
    80
lemma distinct_removes_duplicate_flts2:
Chengsong
parents: 456
diff changeset
    81
  shows " a \<in> set rsa
Chengsong
parents: 456
diff changeset
    82
       \<Longrightarrow> rdistinct (rflts (rsa @ [a] @ rsb)) {} =
Chengsong
parents: 456
diff changeset
    83
           rdistinct (rflts (rsa @ rsb)) {}"
Chengsong
parents: 456
diff changeset
    84
  apply(induct a arbitrary: rsb)
Chengsong
parents: 456
diff changeset
    85
  using flts_middle01 apply presburger
Chengsong
parents: 456
diff changeset
    86
      apply(subgoal_tac "rflts (rsa @ [RONE] @ rsb) = rflts rsa @ [RONE] @ rflts rsb")
Chengsong
parents: 456
diff changeset
    87
  prefer 2
Chengsong
parents: 456
diff changeset
    88
  using flts_append1 apply blast
Chengsong
parents: 456
diff changeset
    89
      apply simp
Chengsong
parents: 456
diff changeset
    90
      apply(subgoal_tac "RONE \<in> set (rflts rsa)")
Chengsong
parents: 456
diff changeset
    91
  prefer 2
Chengsong
parents: 456
diff changeset
    92
  using rflts_def_idiot2 apply blast
Chengsong
parents: 456
diff changeset
    93
      apply(subst distinct_removes_middle3)
Chengsong
parents: 456
diff changeset
    94
       apply simp
Chengsong
parents: 456
diff changeset
    95
  using flts_append apply presburger
Chengsong
parents: 456
diff changeset
    96
     apply simp
Chengsong
parents: 456
diff changeset
    97
  apply (metis distinct_removes_middle3 flts_append in_set_conv_decomp rflts.simps(5))
Chengsong
parents: 456
diff changeset
    98
  apply (metis distinct_removes_middle(1) flts_append flts_append1 rflts_def_idiot2 rrexp.distinct(25) rrexp.distinct(5))
Chengsong
parents: 456
diff changeset
    99
   apply(subgoal_tac "rflts (rsa @ [RALTS x] @ rsb) = rflts rsa @ x @ rflts rsb")
Chengsong
parents: 456
diff changeset
   100
    prefer 2
Chengsong
parents: 456
diff changeset
   101
  apply (simp add: flts_append)
Chengsong
parents: 456
diff changeset
   102
   apply (simp only:)
Chengsong
parents: 456
diff changeset
   103
Chengsong
parents: 456
diff changeset
   104
   apply(subgoal_tac "\<forall>r1 \<in> set x. r1 \<in> set (rflts rsa)")
Chengsong
parents: 456
diff changeset
   105
    prefer 2
Chengsong
parents: 456
diff changeset
   106
  using spilled_alts_contained apply blast
Chengsong
parents: 456
diff changeset
   107
  apply(subst flts_append)
Chengsong
parents: 456
diff changeset
   108
  using distinct_removes_middle_list apply blast
Chengsong
parents: 456
diff changeset
   109
  using distinct_removes_middle2 flts_append rflts_def_idiot2 by fastforce
Chengsong
parents: 456
diff changeset
   110
Chengsong
parents: 456
diff changeset
   111
Chengsong
parents: 456
diff changeset
   112
lemma simp_removes_duplicate:
Chengsong
parents: 456
diff changeset
   113
  shows "a \<in> set rsa \<Longrightarrow> rsimp (rsimp_ALTs (rsa @ a # rs)) =  rsimp (rsimp_ALTs (rsa @ rs))"
Chengsong
parents: 456
diff changeset
   114
  apply(subgoal_tac "rsimp (rsimp_ALTs (rsa @ a # rs)) = rsimp (RALTS (rsa @ a # rs))")
Chengsong
parents: 456
diff changeset
   115
   prefer 2
Chengsong
parents: 456
diff changeset
   116
  apply (smt (verit, best) Cons_eq_append_conv append_is_Nil_conv empty_set equals0D list.distinct(1) rsimp_ALTs.elims)
Chengsong
parents: 456
diff changeset
   117
  apply(simp only:)
Chengsong
parents: 456
diff changeset
   118
  apply simp
Chengsong
parents: 456
diff changeset
   119
  apply(subgoal_tac "(rdistinct (rflts (map rsimp rsa @ rsimp a # map rsimp rs)) {}) = (rdistinct (rflts (map rsimp rsa @  map rsimp rs)) {})")
Chengsong
parents: 456
diff changeset
   120
   apply(simp only:)
Chengsong
parents: 456
diff changeset
   121
  prefer 2
Chengsong
parents: 456
diff changeset
   122
   apply(subgoal_tac "rsimp a \<in> set (map rsimp rsa)")
Chengsong
parents: 456
diff changeset
   123
    prefer 2
Chengsong
parents: 456
diff changeset
   124
  apply simp
Chengsong
parents: 456
diff changeset
   125
  using distinct_removes_duplicate_flts2 apply force
Chengsong
parents: 456
diff changeset
   126
  apply(case_tac rsa)
Chengsong
parents: 456
diff changeset
   127
   apply simp
Chengsong
parents: 456
diff changeset
   128
  apply(case_tac rs)
Chengsong
parents: 456
diff changeset
   129
   apply simp
Chengsong
parents: 456
diff changeset
   130
   apply(case_tac list)
Chengsong
parents: 456
diff changeset
   131
    apply simp
Chengsong
parents: 456
diff changeset
   132
  using idem_after_simp1 apply presburger
Chengsong
parents: 456
diff changeset
   133
   apply simp+
Chengsong
parents: 456
diff changeset
   134
  apply(subgoal_tac "rsimp_ALTs (aa # list @ aaa # lista) = RALTS (aa # list @ aaa # lista)")
Chengsong
parents: 456
diff changeset
   135
   apply simp
Chengsong
parents: 456
diff changeset
   136
  using rsimpalts_conscons by presburger
467
Chengsong
parents: 465
diff changeset
   137
Chengsong
parents: 465
diff changeset
   138
Chengsong
parents: 465
diff changeset
   139
Chengsong
parents: 465
diff changeset
   140
468
a0f27e21b42c all texrelated
Chengsong
parents: 467
diff changeset
   141
467
Chengsong
parents: 465
diff changeset
   142
Chengsong
parents: 465
diff changeset
   143
471
Chengsong
parents: 469
diff changeset
   144
Chengsong
parents: 469
diff changeset
   145
inductive frewrite:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>f _" [10, 10] 10)
Chengsong
parents: 469
diff changeset
   146
  where
Chengsong
parents: 469
diff changeset
   147
  "(RZERO # rs) \<leadsto>f rs"
Chengsong
parents: 469
diff changeset
   148
| "((RALTS rs) # rsa) \<leadsto>f (rs @ rsa)"
Chengsong
parents: 469
diff changeset
   149
| "rs1 \<leadsto>f rs2 \<Longrightarrow> (r # rs1) \<leadsto>f (r # rs2)"
Chengsong
parents: 469
diff changeset
   150
Chengsong
parents: 469
diff changeset
   151
Chengsong
parents: 469
diff changeset
   152
inductive 
Chengsong
parents: 469
diff changeset
   153
  frewrites:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>f* _" [10, 10] 10)
Chengsong
parents: 469
diff changeset
   154
where 
473
Chengsong
parents: 472
diff changeset
   155
  [intro, simp]:"rs \<leadsto>f* rs"
Chengsong
parents: 472
diff changeset
   156
| [intro]: "\<lbrakk>rs1 \<leadsto>f* rs2; rs2 \<leadsto>f rs3\<rbrakk> \<Longrightarrow> rs1 \<leadsto>f* rs3"
Chengsong
parents: 472
diff changeset
   157
Chengsong
parents: 472
diff changeset
   158
inductive grewrite:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>g _" [10, 10] 10)
Chengsong
parents: 472
diff changeset
   159
  where
Chengsong
parents: 472
diff changeset
   160
  "(RZERO # rs) \<leadsto>g rs"
Chengsong
parents: 472
diff changeset
   161
| "((RALTS rs) # rsa) \<leadsto>g (rs @ rsa)"
Chengsong
parents: 472
diff changeset
   162
| "rs1 \<leadsto>g rs2 \<Longrightarrow> (r # rs1) \<leadsto>g (r # rs2)"
Chengsong
parents: 472
diff changeset
   163
| "rsa @ [a] @ rsb @ [a] @ rsc \<leadsto>g rsa @ [a] @ rsb @ rsc" 
Chengsong
parents: 472
diff changeset
   164
478
Chengsong
parents: 476
diff changeset
   165
lemma grewrite_variant1:
Chengsong
parents: 476
diff changeset
   166
  shows "a \<in> set rs1 \<Longrightarrow> rs1 @ a # rs \<leadsto>g rs1 @ rs"
Chengsong
parents: 476
diff changeset
   167
  apply (metis append.assoc append_Cons append_Nil grewrite.intros(4) split_list_first)
Chengsong
parents: 476
diff changeset
   168
  done
Chengsong
parents: 476
diff changeset
   169
473
Chengsong
parents: 472
diff changeset
   170
Chengsong
parents: 472
diff changeset
   171
inductive 
Chengsong
parents: 472
diff changeset
   172
  grewrites:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>g* _" [10, 10] 10)
Chengsong
parents: 472
diff changeset
   173
where 
Chengsong
parents: 472
diff changeset
   174
  [intro, simp]:"rs \<leadsto>g* rs"
Chengsong
parents: 472
diff changeset
   175
| [intro]: "\<lbrakk>rs1 \<leadsto>g* rs2; rs2 \<leadsto>g rs3\<rbrakk> \<Longrightarrow> rs1 \<leadsto>g* rs3"
478
Chengsong
parents: 476
diff changeset
   176
Chengsong
parents: 476
diff changeset
   177
Chengsong
parents: 476
diff changeset
   178
473
Chengsong
parents: 472
diff changeset
   179
(*
Chengsong
parents: 472
diff changeset
   180
inductive 
Chengsong
parents: 472
diff changeset
   181
  frewrites2:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ <\<leadsto>f* _" [10, 10] 10)
Chengsong
parents: 472
diff changeset
   182
where 
Chengsong
parents: 472
diff changeset
   183
 [intro]: "\<lbrakk>rs1 \<leadsto>f* rs2; rs2 \<leadsto>f* rs1\<rbrakk> \<Longrightarrow> rs1 <\<leadsto>f* rs2"
Chengsong
parents: 472
diff changeset
   184
*)
471
Chengsong
parents: 469
diff changeset
   185
Chengsong
parents: 469
diff changeset
   186
lemma fr_in_rstar : "r1 \<leadsto>f r2 \<Longrightarrow> r1 \<leadsto>f* r2"
Chengsong
parents: 469
diff changeset
   187
  using frewrites.intros(1) frewrites.intros(2) by blast
Chengsong
parents: 469
diff changeset
   188
 
Chengsong
parents: 469
diff changeset
   189
lemma freal_trans[trans]: 
Chengsong
parents: 469
diff changeset
   190
  assumes a1: "r1 \<leadsto>f* r2"  and a2: "r2 \<leadsto>f* r3"
Chengsong
parents: 469
diff changeset
   191
  shows "r1 \<leadsto>f* r3"
Chengsong
parents: 469
diff changeset
   192
  using a2 a1
Chengsong
parents: 469
diff changeset
   193
  apply(induct r2 r3 arbitrary: r1 rule: frewrites.induct) 
Chengsong
parents: 469
diff changeset
   194
  apply(auto)
Chengsong
parents: 469
diff changeset
   195
  done
Chengsong
parents: 469
diff changeset
   196
Chengsong
parents: 469
diff changeset
   197
Chengsong
parents: 469
diff changeset
   198
lemma  many_steps_later: "\<lbrakk>r1 \<leadsto>f r2; r2 \<leadsto>f* r3 \<rbrakk> \<Longrightarrow> r1 \<leadsto>f* r3"
Chengsong
parents: 469
diff changeset
   199
  by (meson fr_in_rstar freal_trans)
Chengsong
parents: 469
diff changeset
   200
Chengsong
parents: 469
diff changeset
   201
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   202
lemma gr_in_rstar : "r1 \<leadsto>g r2 \<Longrightarrow> r1 \<leadsto>g* r2"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   203
  using grewrites.intros(1) grewrites.intros(2) by blast
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   204
 
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   205
lemma greal_trans[trans]: 
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   206
  assumes a1: "r1 \<leadsto>g* r2"  and a2: "r2 \<leadsto>g* r3"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   207
  shows "r1 \<leadsto>g* r3"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   208
  using a2 a1
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   209
  apply(induct r2 r3 arbitrary: r1 rule: grewrites.induct) 
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   210
  apply(auto)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   211
  done
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   212
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   213
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   214
lemma  gmany_steps_later: "\<lbrakk>r1 \<leadsto>g r2; r2 \<leadsto>g* r3 \<rbrakk> \<Longrightarrow> r1 \<leadsto>g* r3"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   215
  by (meson gr_in_rstar greal_trans)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   216
478
Chengsong
parents: 476
diff changeset
   217
lemma gstar_rdistinct_general:
Chengsong
parents: 476
diff changeset
   218
  shows "rs1 @  rs \<leadsto>g* rs1 @ (rdistinct rs (set rs1))"
Chengsong
parents: 476
diff changeset
   219
  apply(induct rs arbitrary: rs1)
Chengsong
parents: 476
diff changeset
   220
   apply simp
Chengsong
parents: 476
diff changeset
   221
  apply(case_tac " a \<in> set rs1")
Chengsong
parents: 476
diff changeset
   222
   apply simp
Chengsong
parents: 476
diff changeset
   223
  apply(subgoal_tac "rs1 @ a # rs \<leadsto>g rs1 @ rs")
Chengsong
parents: 476
diff changeset
   224
  using gmany_steps_later apply auto[1]
Chengsong
parents: 476
diff changeset
   225
  apply (metis append.assoc append_Cons append_Nil grewrite.intros(4) split_list_first)
Chengsong
parents: 476
diff changeset
   226
  apply simp
Chengsong
parents: 476
diff changeset
   227
  apply(drule_tac x = "rs1 @ [a]" in meta_spec)
Chengsong
parents: 476
diff changeset
   228
  by simp
Chengsong
parents: 476
diff changeset
   229
Chengsong
parents: 476
diff changeset
   230
Chengsong
parents: 476
diff changeset
   231
lemma gstar_rdistinct:
Chengsong
parents: 476
diff changeset
   232
  shows "rs \<leadsto>g* rdistinct rs {}"
Chengsong
parents: 476
diff changeset
   233
  apply(induct rs)
Chengsong
parents: 476
diff changeset
   234
   apply simp
Chengsong
parents: 476
diff changeset
   235
  by (metis append.left_neutral empty_set gstar_rdistinct_general)
Chengsong
parents: 476
diff changeset
   236
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   237
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   238
471
Chengsong
parents: 469
diff changeset
   239
lemma frewrite_append:
Chengsong
parents: 469
diff changeset
   240
  shows "\<lbrakk> rsa \<leadsto>f rsb \<rbrakk> \<Longrightarrow> rs @ rsa \<leadsto>f rs @ rsb"
Chengsong
parents: 469
diff changeset
   241
  apply(induct rs)
472
Chengsong
parents: 471
diff changeset
   242
   apply simp+
Chengsong
parents: 471
diff changeset
   243
  using frewrite.intros(3) by blast
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   244
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   245
lemma grewrite_append:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   246
  shows "\<lbrakk> rsa \<leadsto>g rsb \<rbrakk> \<Longrightarrow> rs @ rsa \<leadsto>g rs @ rsb"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   247
  apply(induct rs)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   248
   apply simp+
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   249
  using grewrite.intros(3) by blast
472
Chengsong
parents: 471
diff changeset
   250
  
471
Chengsong
parents: 469
diff changeset
   251
Chengsong
parents: 469
diff changeset
   252
Chengsong
parents: 469
diff changeset
   253
lemma frewrites_cons:
Chengsong
parents: 469
diff changeset
   254
  shows "\<lbrakk> rsa \<leadsto>f* rsb \<rbrakk> \<Longrightarrow> r # rsa \<leadsto>f* r # rsb"
472
Chengsong
parents: 471
diff changeset
   255
  apply(induct rsa rsb rule: frewrites.induct)
Chengsong
parents: 471
diff changeset
   256
   apply simp
Chengsong
parents: 471
diff changeset
   257
  using frewrite.intros(3) by blast
471
Chengsong
parents: 469
diff changeset
   258
Chengsong
parents: 469
diff changeset
   259
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   260
lemma grewrites_cons:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   261
  shows "\<lbrakk> rsa \<leadsto>g* rsb \<rbrakk> \<Longrightarrow> r # rsa \<leadsto>g* r # rsb"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   262
  apply(induct rsa rsb rule: grewrites.induct)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   263
   apply simp
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   264
  using grewrite.intros(3) by blast
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   265
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   266
471
Chengsong
parents: 469
diff changeset
   267
lemma frewrites_append:
Chengsong
parents: 469
diff changeset
   268
  shows " \<lbrakk>rsa \<leadsto>f* rsb\<rbrakk> \<Longrightarrow> (rs @ rsa) \<leadsto>f* (rs @ rsb)"
472
Chengsong
parents: 471
diff changeset
   269
  apply(induct rs)
471
Chengsong
parents: 469
diff changeset
   270
   apply simp
472
Chengsong
parents: 471
diff changeset
   271
  by (simp add: frewrites_cons)
471
Chengsong
parents: 469
diff changeset
   272
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   273
lemma grewrites_append:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   274
  shows " \<lbrakk>rsa \<leadsto>g* rsb\<rbrakk> \<Longrightarrow> (rs @ rsa) \<leadsto>g* (rs @ rsb)"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   275
  apply(induct rs)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   276
   apply simp
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   277
  by (simp add: grewrites_cons)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   278
471
Chengsong
parents: 469
diff changeset
   279
Chengsong
parents: 469
diff changeset
   280
Chengsong
parents: 469
diff changeset
   281
lemma frewrites_concat:
Chengsong
parents: 469
diff changeset
   282
  shows "\<lbrakk>rs1 \<leadsto>f rs2; rsa \<leadsto>f* rsb \<rbrakk> \<Longrightarrow> (rs1 @ rsa) \<leadsto>f* (rs2 @ rsb)"
Chengsong
parents: 469
diff changeset
   283
  apply(induct rs1 rs2 rule: frewrite.induct)
Chengsong
parents: 469
diff changeset
   284
    apply(simp)
Chengsong
parents: 469
diff changeset
   285
  apply(subgoal_tac "(RZERO # rs @ rsa) \<leadsto>f (rs @ rsa)")
Chengsong
parents: 469
diff changeset
   286
  prefer 2
Chengsong
parents: 469
diff changeset
   287
  using frewrite.intros(1) apply blast
Chengsong
parents: 469
diff changeset
   288
    apply(subgoal_tac "(rs @ rsa) \<leadsto>f* (rs @ rsb)")
Chengsong
parents: 469
diff changeset
   289
  using many_steps_later apply blast
472
Chengsong
parents: 471
diff changeset
   290
  apply (simp add: frewrites_append)
Chengsong
parents: 471
diff changeset
   291
  apply (metis append.assoc append_Cons frewrite.intros(2) frewrites_append many_steps_later)
Chengsong
parents: 471
diff changeset
   292
  using frewrites_cons by auto
471
Chengsong
parents: 469
diff changeset
   293
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   294
lemma grewrites_concat:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   295
  shows "\<lbrakk>rs1 \<leadsto>g rs2; rsa \<leadsto>g* rsb \<rbrakk> \<Longrightarrow> (rs1 @ rsa) \<leadsto>g* (rs2 @ rsb)"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   296
  apply(induct rs1 rs2 rule: grewrite.induct)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   297
    apply(simp)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   298
  apply(subgoal_tac "(RZERO # rs @ rsa) \<leadsto>g (rs @ rsa)")
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   299
  prefer 2
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   300
  using grewrite.intros(1) apply blast
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   301
    apply(subgoal_tac "(rs @ rsa) \<leadsto>g* (rs @ rsb)")
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   302
  using gmany_steps_later apply blast
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   303
  apply (simp add: grewrites_append)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   304
  apply (metis append.assoc append_Cons grewrite.intros(2) grewrites_append gmany_steps_later)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   305
  using grewrites_cons apply auto
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   306
  apply(subgoal_tac "rsaa @ a # rsba @ a # rsc @ rsa \<leadsto>g* rsaa @ a # rsba @ a # rsc @ rsb")
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   307
  using grewrite.intros(4) grewrites.intros(2) apply force
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   308
  using grewrites_append by auto
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   309
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   310
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   311
lemma grewritess_concat:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   312
  shows "\<lbrakk>rsa \<leadsto>g* rsb; rsc \<leadsto>g* rsd \<rbrakk> \<Longrightarrow> (rsa @ rsc) \<leadsto>g* (rsb @ rsd)"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   313
  apply(induct rsa rsb rule: grewrites.induct)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   314
   apply(case_tac rs)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   315
    apply simp
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   316
  using grewrites_append apply blast   
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   317
  by (meson greal_trans grewrites.simps grewrites_concat)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   318
476
Chengsong
parents: 475
diff changeset
   319
fun alt_set:: "rrexp \<Rightarrow> rrexp set"
Chengsong
parents: 475
diff changeset
   320
  where
Chengsong
parents: 475
diff changeset
   321
  "alt_set (RALTS rs) = set rs \<union> \<Union> (alt_set ` (set rs))"
Chengsong
parents: 475
diff changeset
   322
| "alt_set r = {r}"
Chengsong
parents: 475
diff changeset
   323
Chengsong
parents: 475
diff changeset
   324
lemma alt_set_has_all:
Chengsong
parents: 475
diff changeset
   325
  shows "RALTS rs \<in> alt_set rx \<Longrightarrow> set rs \<subseteq> alt_set rx"
Chengsong
parents: 475
diff changeset
   326
  apply(induct rx arbitrary: rs)
Chengsong
parents: 475
diff changeset
   327
       apply simp_all
Chengsong
parents: 475
diff changeset
   328
  apply(rename_tac rSS rss)
Chengsong
parents: 475
diff changeset
   329
  using in_mono by fastforce
Chengsong
parents: 475
diff changeset
   330
Chengsong
parents: 475
diff changeset
   331
Chengsong
parents: 475
diff changeset
   332
Chengsong
parents: 475
diff changeset
   333
Chengsong
parents: 475
diff changeset
   334
lemma grewrite_equal_rsimp:
Chengsong
parents: 475
diff changeset
   335
  shows "\<lbrakk>rs1 \<leadsto>g rs2; rsimp_ALTs (rdistinct (rflts (map rsimp rs1)) (rset \<union> \<Union>(alt_set ` rset))) =
Chengsong
parents: 475
diff changeset
   336
          rsimp_ALTs (rdistinct (rflts (map rsimp rs2)) (rset \<union> \<Union>(alt_set ` rset)))\<rbrakk>
Chengsong
parents: 475
diff changeset
   337
       \<Longrightarrow> rsimp_ALTs (rdistinct (rflts (rsimp r # map rsimp rs1))  (rset \<union> \<Union>(alt_set ` rset))) =
Chengsong
parents: 475
diff changeset
   338
           rsimp_ALTs (rdistinct (rflts (rsimp r # map rsimp rs2))  (rset \<union> \<Union>(alt_set ` rset)))"
Chengsong
parents: 475
diff changeset
   339
  apply(induct rs1 rs2 arbitrary:rset rule: grewrite.induct)
Chengsong
parents: 475
diff changeset
   340
     apply simp
Chengsong
parents: 475
diff changeset
   341
  apply (metis append_Cons append_Nil flts_middle0)
Chengsong
parents: 475
diff changeset
   342
    apply(case_tac "rsimp r \<in> rset")
Chengsong
parents: 475
diff changeset
   343
     apply simp
Chengsong
parents: 475
diff changeset
   344
  oops
Chengsong
parents: 475
diff changeset
   345
478
Chengsong
parents: 476
diff changeset
   346
lemma grewrite_cases_middle:
Chengsong
parents: 476
diff changeset
   347
  shows "rs1 \<leadsto>g rs2 \<Longrightarrow> 
Chengsong
parents: 476
diff changeset
   348
(\<exists>rsa rsb rsc. rs1 =  (rsa @ [RALTS rsb] @ rsc) \<and> rs2 = (rsa @ rsb @ rsc)) \<or>
Chengsong
parents: 476
diff changeset
   349
(\<exists>rsa rsc. rs1 = rsa @ [RZERO] @ rsc \<and> rs2 = rsa @ rsc) \<or>
Chengsong
parents: 476
diff changeset
   350
(\<exists>rsa rsb rsc a. rs1 = rsa @ [a] @ rsb @ [a] @ rsc \<and> rs2 = rsa @ [a] @ rsb @ rsc)"
Chengsong
parents: 476
diff changeset
   351
  apply( induct rs1 rs2 rule: grewrite.induct)
Chengsong
parents: 476
diff changeset
   352
     apply simp
Chengsong
parents: 476
diff changeset
   353
  apply blast
Chengsong
parents: 476
diff changeset
   354
  apply (metis append_Cons append_Nil)
Chengsong
parents: 476
diff changeset
   355
  apply (metis append_Cons)
Chengsong
parents: 476
diff changeset
   356
  by blast
476
Chengsong
parents: 475
diff changeset
   357
Chengsong
parents: 475
diff changeset
   358
Chengsong
parents: 475
diff changeset
   359
lemma grewrite_equal_rsimp:
Chengsong
parents: 475
diff changeset
   360
  shows "rs1 \<leadsto>g rs2 \<Longrightarrow> rsimp (RALTS rs1) = rsimp (RALTS rs2)"
478
Chengsong
parents: 476
diff changeset
   361
  apply(frule grewrite_cases_middle)
Chengsong
parents: 476
diff changeset
   362
  apply(case_tac "(\<exists>rsa rsb rsc. rs1 = rsa @ [RALTS rsb] @ rsc \<and> rs2 = rsa @ rsb @ rsc)")  
Chengsong
parents: 476
diff changeset
   363
  using simp_flatten3 apply auto[1]
Chengsong
parents: 476
diff changeset
   364
  apply(case_tac "(\<exists>rsa rsc. rs1 = rsa @ [RZERO] @ rsc \<and> rs2 = rsa @ rsc)")
Chengsong
parents: 476
diff changeset
   365
  apply (metis (mono_tags, opaque_lifting) append_Cons append_Nil list.set_intros(1) list.simps(9) rflts.simps(2) rsimp.simps(2) rsimp.simps(3) simp_removes_duplicate3)
Chengsong
parents: 476
diff changeset
   366
  by (smt (verit) append.assoc append_Cons append_Nil in_set_conv_decomp simp_removes_duplicate3)
476
Chengsong
parents: 475
diff changeset
   367
Chengsong
parents: 475
diff changeset
   368
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   369
lemma grewrites_equal_rsimp:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   370
  shows "rs1 \<leadsto>g* rs2 \<Longrightarrow> rsimp (RALTS rs1) = rsimp (RALTS rs2)"
476
Chengsong
parents: 475
diff changeset
   371
  apply (induct rs1 rs2 rule: grewrites.induct)
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   372
  apply simp
476
Chengsong
parents: 475
diff changeset
   373
  using grewrite_equal_rsimp by presburger
Chengsong
parents: 475
diff changeset
   374
  
Chengsong
parents: 475
diff changeset
   375
Chengsong
parents: 475
diff changeset
   376
Chengsong
parents: 475
diff changeset
   377
Chengsong
parents: 475
diff changeset
   378
lemma grewrites_equal_simp_2:
Chengsong
parents: 475
diff changeset
   379
  shows "rsimp (RALTS rs1) = rsimp (RALTS rs2) \<Longrightarrow> rs1 \<leadsto>g* rs2"
478
Chengsong
parents: 476
diff changeset
   380
  oops
Chengsong
parents: 476
diff changeset
   381
Chengsong
parents: 476
diff changeset
   382
Chengsong
parents: 476
diff changeset
   383
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   384
476
Chengsong
parents: 475
diff changeset
   385
lemma grewrites_last:
Chengsong
parents: 475
diff changeset
   386
  shows "r # [RALTS rs] \<leadsto>g*  r # rs"
Chengsong
parents: 475
diff changeset
   387
  by (metis gr_in_rstar grewrite.intros(2) grewrite.intros(3) self_append_conv)
Chengsong
parents: 475
diff changeset
   388
Chengsong
parents: 475
diff changeset
   389
lemma simp_flatten2:
Chengsong
parents: 475
diff changeset
   390
  shows "rsimp (RALTS (r # [RALTS rs])) = rsimp (RALTS (r # rs))"
Chengsong
parents: 475
diff changeset
   391
  using grewrites_equal_rsimp grewrites_last by blast
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   392
473
Chengsong
parents: 472
diff changeset
   393
lemma frewrites_middle:
Chengsong
parents: 472
diff changeset
   394
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> r # (RALTS rs # rs1) \<leadsto>f* r # (rs @ rs1)"
Chengsong
parents: 472
diff changeset
   395
  by (simp add: fr_in_rstar frewrite.intros(2) frewrite.intros(3))
471
Chengsong
parents: 469
diff changeset
   396
473
Chengsong
parents: 472
diff changeset
   397
lemma frewrites_alt:
Chengsong
parents: 472
diff changeset
   398
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> (RALT r1 r2) # rs1 \<leadsto>f* r1 # r2 # rs2"  
Chengsong
parents: 472
diff changeset
   399
  by (metis Cons_eq_appendI append_self_conv2 frewrite.intros(2) frewrites_cons many_steps_later)
471
Chengsong
parents: 469
diff changeset
   400
Chengsong
parents: 469
diff changeset
   401
lemma early_late_der_frewrites:
Chengsong
parents: 469
diff changeset
   402
  shows "map (rder x) (rflts rs) \<leadsto>f* rflts (map (rder x) rs)"
Chengsong
parents: 469
diff changeset
   403
  apply(induct rs)
Chengsong
parents: 469
diff changeset
   404
   apply simp
Chengsong
parents: 469
diff changeset
   405
  apply(case_tac a)
Chengsong
parents: 469
diff changeset
   406
       apply simp+
Chengsong
parents: 469
diff changeset
   407
  using frewrite.intros(1) many_steps_later apply blast
Chengsong
parents: 469
diff changeset
   408
     apply(case_tac "x = x3")
472
Chengsong
parents: 471
diff changeset
   409
      apply simp
Chengsong
parents: 471
diff changeset
   410
  using frewrites_cons apply presburger
Chengsong
parents: 471
diff changeset
   411
  using frewrite.intros(1) many_steps_later apply fastforce
Chengsong
parents: 471
diff changeset
   412
  apply(case_tac "rnullable x41")
473
Chengsong
parents: 472
diff changeset
   413
     apply simp+
Chengsong
parents: 472
diff changeset
   414
     apply (simp add: frewrites_alt)
Chengsong
parents: 472
diff changeset
   415
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   416
   apply (simp add: frewrites_append)
Chengsong
parents: 472
diff changeset
   417
  by (simp add: frewrites_cons)
471
Chengsong
parents: 469
diff changeset
   418
Chengsong
parents: 469
diff changeset
   419
Chengsong
parents: 469
diff changeset
   420
Chengsong
parents: 469
diff changeset
   421
473
Chengsong
parents: 472
diff changeset
   422
lemma with_wo0_distinct:
Chengsong
parents: 472
diff changeset
   423
  shows "rdistinct rs rset \<leadsto>f* rdistinct rs (insert RZERO rset)"
Chengsong
parents: 472
diff changeset
   424
  apply(induct rs arbitrary: rset)
Chengsong
parents: 472
diff changeset
   425
   apply simp
Chengsong
parents: 472
diff changeset
   426
  apply(case_tac a)
Chengsong
parents: 472
diff changeset
   427
  apply(case_tac "RZERO \<in> rset")
Chengsong
parents: 472
diff changeset
   428
        apply simp+
Chengsong
parents: 472
diff changeset
   429
  using fr_in_rstar frewrite.intros(1) apply presburger
Chengsong
parents: 472
diff changeset
   430
  apply (case_tac "RONE \<in> rset")
Chengsong
parents: 472
diff changeset
   431
       apply simp+
Chengsong
parents: 472
diff changeset
   432
  using frewrites_cons apply presburger
Chengsong
parents: 472
diff changeset
   433
     apply(case_tac "a \<in> rset")
Chengsong
parents: 472
diff changeset
   434
  apply simp
Chengsong
parents: 472
diff changeset
   435
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   436
     apply(case_tac "a \<in> rset")
Chengsong
parents: 472
diff changeset
   437
  apply simp
Chengsong
parents: 472
diff changeset
   438
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   439
       apply(case_tac "a \<in> rset")
Chengsong
parents: 472
diff changeset
   440
  apply simp
Chengsong
parents: 472
diff changeset
   441
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   442
       apply(case_tac "a \<in> rset")
Chengsong
parents: 472
diff changeset
   443
  apply simp
Chengsong
parents: 472
diff changeset
   444
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   445
  done
Chengsong
parents: 472
diff changeset
   446
476
Chengsong
parents: 475
diff changeset
   447
(*Interesting lemma: not obvious but easily proven by sledgehammer*)
473
Chengsong
parents: 472
diff changeset
   448
476
Chengsong
parents: 475
diff changeset
   449
  
Chengsong
parents: 475
diff changeset
   450
Chengsong
parents: 475
diff changeset
   451
Chengsong
parents: 475
diff changeset
   452
(*lemma induction last rule not go through
Chengsong
parents: 475
diff changeset
   453
 example:
Chengsong
parents: 475
diff changeset
   454
r #
Chengsong
parents: 475
diff changeset
   455
           rdistinct rs1
Chengsong
parents: 475
diff changeset
   456
            (insert RZERO
Chengsong
parents: 475
diff changeset
   457
              (insert r
Chengsong
parents: 475
diff changeset
   458
                (rset \<union>
Chengsong
parents: 475
diff changeset
   459
                 \<Union> (alt_set `
Chengsong
parents: 475
diff changeset
   460
                     rset)))) \<leadsto>g* r #
Chengsong
parents: 475
diff changeset
   461
                                   rdistinct rs2
Chengsong
parents: 475
diff changeset
   462
                                    (insert RZERO (insert r (rset \<union> \<Union> (alt_set ` rset))))
Chengsong
parents: 475
diff changeset
   463
 rs2 = [+rs] rs3 = rs,
Chengsong
parents: 475
diff changeset
   464
r = +rs
Chengsong
parents: 475
diff changeset
   465
[] \<leadsto>g* rs which is wrong
Chengsong
parents: 475
diff changeset
   466
*)
Chengsong
parents: 475
diff changeset
   467
469
e5dd8cc0aa82 all electron pics removed
Chengsong
parents: 468
diff changeset
   468
e5dd8cc0aa82 all electron pics removed
Chengsong
parents: 468
diff changeset
   469
476
Chengsong
parents: 475
diff changeset
   470
Chengsong
parents: 475
diff changeset
   471
Chengsong
parents: 475
diff changeset
   472
Chengsong
parents: 475
diff changeset
   473
Chengsong
parents: 475
diff changeset
   474
lemma frewrite_simpeq:
Chengsong
parents: 475
diff changeset
   475
  shows "rs1 \<leadsto>f rs2 \<Longrightarrow> rsimp (RALTS rs1) = rsimp (RALTS rs2)"
Chengsong
parents: 475
diff changeset
   476
  apply(induct rs1 rs2 rule: frewrite.induct)
Chengsong
parents: 475
diff changeset
   477
    apply simp
Chengsong
parents: 475
diff changeset
   478
  using simp_flatten apply presburger
478
Chengsong
parents: 476
diff changeset
   479
  by (metis (no_types, opaque_lifting) grewrites_equal_rsimp grewrites_last list.simps(9) rsimp.simps(2))
Chengsong
parents: 476
diff changeset
   480
Chengsong
parents: 476
diff changeset
   481
lemma gstar0:
Chengsong
parents: 476
diff changeset
   482
  shows "rsa @ (rdistinct rs (set rsa)) \<leadsto>g* rsa @ (rdistinct rs (insert RZERO (set rsa)))"
Chengsong
parents: 476
diff changeset
   483
  apply(induct rs arbitrary: rsa)
Chengsong
parents: 476
diff changeset
   484
   apply simp
Chengsong
parents: 476
diff changeset
   485
  apply(case_tac "a = RZERO")
Chengsong
parents: 476
diff changeset
   486
   apply simp
Chengsong
parents: 476
diff changeset
   487
  
Chengsong
parents: 476
diff changeset
   488
  using gr_in_rstar grewrite.intros(1) grewrites_append apply presburger
Chengsong
parents: 476
diff changeset
   489
  apply(case_tac "a \<in> set rsa")
Chengsong
parents: 476
diff changeset
   490
   apply simp+
Chengsong
parents: 476
diff changeset
   491
  apply(drule_tac x = "rsa @ [a]" in meta_spec)
Chengsong
parents: 476
diff changeset
   492
  by simp
Chengsong
parents: 476
diff changeset
   493
  
Chengsong
parents: 476
diff changeset
   494
lemma gstar01:
Chengsong
parents: 476
diff changeset
   495
  shows "rdistinct rs {} \<leadsto>g* rdistinct rs {RZERO}"
Chengsong
parents: 476
diff changeset
   496
  by (metis empty_set gstar0 self_append_conv2)
Chengsong
parents: 476
diff changeset
   497
Chengsong
parents: 476
diff changeset
   498
Chengsong
parents: 476
diff changeset
   499
lemma grewrite_rdistinct_aux:
Chengsong
parents: 476
diff changeset
   500
  shows "rs @ rdistinct rsa rset \<leadsto>g* rs @ rdistinct rsa (rset \<union> set rs)"
Chengsong
parents: 476
diff changeset
   501
  sorry
Chengsong
parents: 476
diff changeset
   502
Chengsong
parents: 476
diff changeset
   503
lemma grewrite_rdistinct_worth1:
Chengsong
parents: 476
diff changeset
   504
  shows "(rsb @ [a]) @ rdistinct rs set1 \<leadsto>g* (rsb @ [a]) @ rdistinct rs (insert a set1)"
Chengsong
parents: 476
diff changeset
   505
  by (metis append.assoc empty_set grewrite_rdistinct_aux grewrites_append inf_sup_aci(5) insert_is_Un list.simps(15))
Chengsong
parents: 476
diff changeset
   506
Chengsong
parents: 476
diff changeset
   507
lemma grewrite_rdisitinct:
Chengsong
parents: 476
diff changeset
   508
  shows "rs @ rdistinct rsa {RALTS rs} \<leadsto>g* rs @ rdistinct rsa (insert (RALTS rs) (set rs))"
Chengsong
parents: 476
diff changeset
   509
  apply(induct rsa arbitrary: rs)
Chengsong
parents: 476
diff changeset
   510
   apply simp
Chengsong
parents: 476
diff changeset
   511
  apply(case_tac "a = RALTS rs")
Chengsong
parents: 476
diff changeset
   512
  apply simp
Chengsong
parents: 476
diff changeset
   513
  apply(case_tac "a \<in> set rs")
Chengsong
parents: 476
diff changeset
   514
   apply simp
Chengsong
parents: 476
diff changeset
   515
  apply(subgoal_tac "rs @
Chengsong
parents: 476
diff changeset
   516
           a # rdistinct rsa {RALTS rs, a} \<leadsto>g rs @ rdistinct rsa {RALTS rs, a}")
Chengsong
parents: 476
diff changeset
   517
    apply(subgoal_tac 
Chengsong
parents: 476
diff changeset
   518
"rs @ rdistinct rsa {RALTS rs, a} \<leadsto>g* rs @ rdistinct rsa (insert (RALTS rs) (set rs))")
Chengsong
parents: 476
diff changeset
   519
  using gmany_steps_later apply blast
Chengsong
parents: 476
diff changeset
   520
    apply(subgoal_tac 
Chengsong
parents: 476
diff changeset
   521
" rs @ rdistinct rsa {RALTS rs, a} \<leadsto>g* rs @ rdistinct rsa ({RALTS rs, a} \<union> set rs)")
Chengsong
parents: 476
diff changeset
   522
     apply (simp add: insert_absorb)
Chengsong
parents: 476
diff changeset
   523
  using grewrite_rdistinct_aux apply blast
Chengsong
parents: 476
diff changeset
   524
  using grewrite_variant1 apply blast
Chengsong
parents: 476
diff changeset
   525
  by (metis grewrite_rdistinct_aux insert_is_Un)
Chengsong
parents: 476
diff changeset
   526
Chengsong
parents: 476
diff changeset
   527
  
Chengsong
parents: 476
diff changeset
   528
lemma frewrite_rd_grewrites_general:
Chengsong
parents: 476
diff changeset
   529
  shows "\<lbrakk>rs1 \<leadsto>f rs2; \<And>rs. \<exists>rs3. 
Chengsong
parents: 476
diff changeset
   530
(rs @ (rdistinct rs1 (set rs)) \<leadsto>g* rs3) \<and> (rs @ (rdistinct rs2 (set rs)) \<leadsto>g* rs3)\<rbrakk>
Chengsong
parents: 476
diff changeset
   531
       \<Longrightarrow> 
Chengsong
parents: 476
diff changeset
   532
\<exists>rs3. (rs @ (r # rdistinct rs1 (set rs \<union> {r})) \<leadsto>g* rs3) \<and> (rs @ (r # rdistinct rs2 (set rs \<union> {r})) \<leadsto>g* rs3)"
Chengsong
parents: 476
diff changeset
   533
  apply(drule_tac x = "rs @ [r]" in meta_spec )
Chengsong
parents: 476
diff changeset
   534
  by simp
Chengsong
parents: 476
diff changeset
   535
Chengsong
parents: 476
diff changeset
   536
479
Chengsong
parents: 478
diff changeset
   537
lemma alts_g_can_flts:
Chengsong
parents: 478
diff changeset
   538
  shows "RALTS rs \<in> set rsb \<Longrightarrow> \<exists>rs1 rs2.( rflts rsb = rs1 @ rs @ rs2)"
Chengsong
parents: 478
diff changeset
   539
  by (metis flts_append rflts.simps(3) split_list_last)
Chengsong
parents: 478
diff changeset
   540
Chengsong
parents: 478
diff changeset
   541
lemma flts_gstar:
Chengsong
parents: 478
diff changeset
   542
  shows "rs \<leadsto>g* rflts rs"
Chengsong
parents: 478
diff changeset
   543
  sorry
Chengsong
parents: 478
diff changeset
   544
Chengsong
parents: 478
diff changeset
   545
lemma create_nonexistent_distinct_set:
Chengsong
parents: 478
diff changeset
   546
  shows "a \<in> set rs1 \<Longrightarrow> rs1 @ (rdistinct rs (insert a rset)) \<leadsto>g* rs1 @ (rdistinct rs (rset))"
478
Chengsong
parents: 476
diff changeset
   547
  sorry
Chengsong
parents: 476
diff changeset
   548
479
Chengsong
parents: 478
diff changeset
   549
lemma grewrites_in_distinct0:
Chengsong
parents: 478
diff changeset
   550
  shows "a \<in>  set rs1 \<Longrightarrow> rs1 @ (rdistinct (a # rs) rset) \<leadsto>g* rs1 @ (rdistinct rs rset)"
Chengsong
parents: 478
diff changeset
   551
  apply(case_tac "a \<in> rset")
Chengsong
parents: 478
diff changeset
   552
   apply simp
Chengsong
parents: 478
diff changeset
   553
  apply simp
Chengsong
parents: 478
diff changeset
   554
  oops
Chengsong
parents: 478
diff changeset
   555
Chengsong
parents: 478
diff changeset
   556
 
Chengsong
parents: 478
diff changeset
   557
Chengsong
parents: 478
diff changeset
   558
Chengsong
parents: 478
diff changeset
   559
  
Chengsong
parents: 478
diff changeset
   560
Chengsong
parents: 478
diff changeset
   561
478
Chengsong
parents: 476
diff changeset
   562
Chengsong
parents: 476
diff changeset
   563
Chengsong
parents: 476
diff changeset
   564
lemma frewrite_rd_grewrites_aux:
Chengsong
parents: 476
diff changeset
   565
  shows     "  rsb @
Chengsong
parents: 476
diff changeset
   566
       rdistinct (RALTS rs # rsa)
Chengsong
parents: 476
diff changeset
   567
        (set rsb) \<leadsto>g* rsb @
Chengsong
parents: 476
diff changeset
   568
                       rdistinct rs (set rsb) @ rdistinct rsa (insert (RALTS rs) (set rs) \<union> set rsb)"
Chengsong
parents: 476
diff changeset
   569
Chengsong
parents: 476
diff changeset
   570
  
Chengsong
parents: 476
diff changeset
   571
  sorry
Chengsong
parents: 476
diff changeset
   572
479
Chengsong
parents: 478
diff changeset
   573
478
Chengsong
parents: 476
diff changeset
   574
Chengsong
parents: 476
diff changeset
   575
lemma list_dlist_union:
Chengsong
parents: 476
diff changeset
   576
  shows "set rs \<subseteq> set rsb \<union> set (rdistinct rs (set rsb))"
Chengsong
parents: 476
diff changeset
   577
  by (metis rdistinct_concat_general rdistinct_set_equality set_append sup_ge2)
Chengsong
parents: 476
diff changeset
   578
Chengsong
parents: 476
diff changeset
   579
lemma subset_distinct_rewrite1:
Chengsong
parents: 476
diff changeset
   580
  shows "set1 \<subseteq> set rsb \<Longrightarrow> rsb @ rs \<leadsto>g* rsb @ (rdistinct rs set1)"
Chengsong
parents: 476
diff changeset
   581
  apply(induct rs arbitrary: rsb)
Chengsong
parents: 476
diff changeset
   582
   apply simp
Chengsong
parents: 476
diff changeset
   583
  apply(case_tac "a \<in> set1")
Chengsong
parents: 476
diff changeset
   584
   apply simp
Chengsong
parents: 476
diff changeset
   585
  
Chengsong
parents: 476
diff changeset
   586
  using gmany_steps_later grewrite_variant1 apply blast
Chengsong
parents: 476
diff changeset
   587
  apply simp
Chengsong
parents: 476
diff changeset
   588
  apply(drule_tac x = "rsb @ [a]" in meta_spec)
Chengsong
parents: 476
diff changeset
   589
  apply(subgoal_tac "set1 \<subseteq> set (rsb @ [a])")
Chengsong
parents: 476
diff changeset
   590
   apply (simp only:)
Chengsong
parents: 476
diff changeset
   591
  apply(subgoal_tac "(rsb @ [a]) @ rdistinct rs set1 \<leadsto>g* (rsb @ [a]) @ rdistinct rs (insert a set1)")
Chengsong
parents: 476
diff changeset
   592
    apply (metis (no_types, opaque_lifting) append.assoc append_Cons append_Nil greal_trans)
Chengsong
parents: 476
diff changeset
   593
  apply (metis append.assoc empty_set grewrite_rdistinct_aux grewrites_append inf_sup_aci(5) insert_is_Un list.simps(15))
Chengsong
parents: 476
diff changeset
   594
  by auto
Chengsong
parents: 476
diff changeset
   595
Chengsong
parents: 476
diff changeset
   596
Chengsong
parents: 476
diff changeset
   597
lemma subset_distinct_rewrite:
Chengsong
parents: 476
diff changeset
   598
  shows "set rsb' \<subseteq> set rsb \<Longrightarrow> rsb @ rs \<leadsto>g* rsb @ (rdistinct rs (set rsb'))"
Chengsong
parents: 476
diff changeset
   599
  by (simp add: subset_distinct_rewrite1)
Chengsong
parents: 476
diff changeset
   600
  
Chengsong
parents: 476
diff changeset
   601
Chengsong
parents: 476
diff changeset
   602
Chengsong
parents: 476
diff changeset
   603
lemma distinct_3list:
Chengsong
parents: 476
diff changeset
   604
  shows "rsb @ (rdistinct rs (set rsb)) @ rsa \<leadsto>g* 
Chengsong
parents: 476
diff changeset
   605
         rsb @ (rdistinct rs (set rsb)) @ (rdistinct rsa (set rs))"
Chengsong
parents: 476
diff changeset
   606
  by (metis append.assoc list_dlist_union set_append subset_distinct_rewrite)
Chengsong
parents: 476
diff changeset
   607
  
Chengsong
parents: 476
diff changeset
   608
Chengsong
parents: 476
diff changeset
   609
Chengsong
parents: 476
diff changeset
   610
Chengsong
parents: 476
diff changeset
   611
lemma grewrites_shape1:
Chengsong
parents: 476
diff changeset
   612
  shows "      RALTS rs \<notin> set rsb \<Longrightarrow>
Chengsong
parents: 476
diff changeset
   613
       rsb @
Chengsong
parents: 476
diff changeset
   614
       RALTS rs #
Chengsong
parents: 476
diff changeset
   615
       rdistinct rsa
Chengsong
parents: 476
diff changeset
   616
        (
Chengsong
parents: 476
diff changeset
   617
          (set rsb)) \<leadsto>g* rsb @
Chengsong
parents: 476
diff changeset
   618
                          rdistinct rs (set rsb) @
Chengsong
parents: 476
diff changeset
   619
                          rdistinct (rflts (rdistinct rsa ( (set rsb \<union> set rs)))) (set rs)"
Chengsong
parents: 476
diff changeset
   620
Chengsong
parents: 476
diff changeset
   621
Chengsong
parents: 476
diff changeset
   622
  apply (subgoal_tac "       rsb @
Chengsong
parents: 476
diff changeset
   623
       RALTS rs #
Chengsong
parents: 476
diff changeset
   624
       rdistinct rsa
Chengsong
parents: 476
diff changeset
   625
        (
Chengsong
parents: 476
diff changeset
   626
          (set rsb))  \<leadsto>g*        rsb @
Chengsong
parents: 476
diff changeset
   627
       rs @
Chengsong
parents: 476
diff changeset
   628
       rdistinct rsa
Chengsong
parents: 476
diff changeset
   629
        (
Chengsong
parents: 476
diff changeset
   630
          (set rsb)) ")
Chengsong
parents: 476
diff changeset
   631
   prefer 2
Chengsong
parents: 476
diff changeset
   632
  using gr_in_rstar grewrite.intros(2) grewrites_append apply presburger
Chengsong
parents: 476
diff changeset
   633
  apply(subgoal_tac "rsb @ rs @ rdistinct rsa (  (set rsb)) \<leadsto>g* rsb @ 
Chengsong
parents: 476
diff changeset
   634
(rdistinct rs (set rsb) @ rdistinct rsa (  (set rsb)))")
Chengsong
parents: 476
diff changeset
   635
  prefer 2
Chengsong
parents: 476
diff changeset
   636
  apply (metis append_assoc grewrites.intros(1) grewritess_concat gstar_rdistinct_general)
Chengsong
parents: 476
diff changeset
   637
  apply(subgoal_tac " rsb @ rdistinct rs (set rsb) @ rdistinct rsa (  (set rsb))
Chengsong
parents: 476
diff changeset
   638
\<leadsto>g*  rsb @ rdistinct rs (set rsb) @ rdistinct rsa (  (set rsb) \<union> (set rs))")
Chengsong
parents: 476
diff changeset
   639
  prefer 2
Chengsong
parents: 476
diff changeset
   640
  apply (smt (verit, best) append.assoc append_assoc boolean_algebra_cancel.sup2 grewrite_rdistinct_aux inf_sup_aci(5) insert_is_Un rdistinct_concat_general rdistinct_set_equality set_append sup.commute sup.right_idem sup_commute)
Chengsong
parents: 476
diff changeset
   641
  apply(subgoal_tac "rdistinct rsa (  (set rsb)  \<union> set rs) \<leadsto>g*
Chengsong
parents: 476
diff changeset
   642
rflts (rdistinct rsa (  (set rsb) \<union> set rs))")
Chengsong
parents: 476
diff changeset
   643
   apply(subgoal_tac "rsb @ (rdistinct rs (set rsb)) @ rflts (rdistinct rsa (  (set rsb) \<union> set rs)) \<leadsto>g* 
Chengsong
parents: 476
diff changeset
   644
rsb @ (rdistinct rs (set rsb)) @ (rdistinct (rflts (rdistinct rsa (  (set rsb) \<union> set rs))) (set rs))")
Chengsong
parents: 476
diff changeset
   645
  apply (smt (verit, ccfv_SIG) Un_insert_left greal_trans grewrites_append)
Chengsong
parents: 476
diff changeset
   646
  using distinct_3list apply presburger
Chengsong
parents: 476
diff changeset
   647
  using flts_gstar apply blast
Chengsong
parents: 476
diff changeset
   648
  done
Chengsong
parents: 476
diff changeset
   649
Chengsong
parents: 476
diff changeset
   650
lemma r_finite1:
Chengsong
parents: 476
diff changeset
   651
  shows "r = RALTS (r # rs) = False"
Chengsong
parents: 476
diff changeset
   652
  apply(induct r)
Chengsong
parents: 476
diff changeset
   653
  apply simp+
Chengsong
parents: 476
diff changeset
   654
   apply (metis list.set_intros(1))
Chengsong
parents: 476
diff changeset
   655
  by blast
Chengsong
parents: 476
diff changeset
   656
  
Chengsong
parents: 476
diff changeset
   657
Chengsong
parents: 476
diff changeset
   658
Chengsong
parents: 476
diff changeset
   659
lemma grewrite_singleton:
Chengsong
parents: 476
diff changeset
   660
  shows "[r] \<leadsto>g r # rs \<Longrightarrow> rs = []"
Chengsong
parents: 476
diff changeset
   661
  apply (induct "[r]" "r # rs" rule: grewrite.induct)
Chengsong
parents: 476
diff changeset
   662
    apply simp
Chengsong
parents: 476
diff changeset
   663
  apply (metis r_finite1)
Chengsong
parents: 476
diff changeset
   664
  using grewrite.simps apply blast
Chengsong
parents: 476
diff changeset
   665
  by simp
Chengsong
parents: 476
diff changeset
   666
Chengsong
parents: 476
diff changeset
   667
lemma impossible_grewrite1:
Chengsong
parents: 476
diff changeset
   668
  shows "\<not>( [RONE] \<leadsto>g [])"
Chengsong
parents: 476
diff changeset
   669
  using grewrite.cases by fastforce
Chengsong
parents: 476
diff changeset
   670
Chengsong
parents: 476
diff changeset
   671
Chengsong
parents: 476
diff changeset
   672
lemma impossible_grewrite2:
Chengsong
parents: 476
diff changeset
   673
  shows "\<not> ([RALTS rs] \<leadsto>g (RALTS rs) # a # rs)"
Chengsong
parents: 476
diff changeset
   674
  using grewrite_singleton by blast
Chengsong
parents: 476
diff changeset
   675
Chengsong
parents: 476
diff changeset
   676
  
Chengsong
parents: 476
diff changeset
   677
Chengsong
parents: 476
diff changeset
   678
479
Chengsong
parents: 478
diff changeset
   679
lemma wront_sublist_grewrites:
478
Chengsong
parents: 476
diff changeset
   680
  shows "rs1 @ rs2 \<leadsto>g* rs1 @ rs3 \<Longrightarrow> rs2 \<leadsto>g* rs3"
Chengsong
parents: 476
diff changeset
   681
  apply(induct rs1 arbitrary: rs2 rs3 rule: rev_induct)
Chengsong
parents: 476
diff changeset
   682
   apply simp
Chengsong
parents: 476
diff changeset
   683
  apply(drule_tac x = "[x] @ rs2" in meta_spec)
Chengsong
parents: 476
diff changeset
   684
  apply(drule_tac x = "[x] @ rs3" in meta_spec)
Chengsong
parents: 476
diff changeset
   685
  apply(simp)
Chengsong
parents: 476
diff changeset
   686
Chengsong
parents: 476
diff changeset
   687
  oops
Chengsong
parents: 476
diff changeset
   688
Chengsong
parents: 476
diff changeset
   689
Chengsong
parents: 476
diff changeset
   690
Chengsong
parents: 476
diff changeset
   691
479
Chengsong
parents: 478
diff changeset
   692
lemma concat_rdistinct_equality1:
Chengsong
parents: 478
diff changeset
   693
  shows "rdistinct (rs @ rsa) rset = rdistinct rs rset @ rdistinct rsa (rset \<union> (set rs))"
Chengsong
parents: 478
diff changeset
   694
  apply(induct rs arbitrary: rsa rset)
478
Chengsong
parents: 476
diff changeset
   695
   apply simp
479
Chengsong
parents: 478
diff changeset
   696
  apply(case_tac "a \<in> rset")
Chengsong
parents: 478
diff changeset
   697
   apply simp
Chengsong
parents: 478
diff changeset
   698
  apply (simp add: insert_absorb)
Chengsong
parents: 478
diff changeset
   699
  by auto
478
Chengsong
parents: 476
diff changeset
   700
Chengsong
parents: 476
diff changeset
   701
479
Chengsong
parents: 478
diff changeset
   702
lemma ends_removal:
Chengsong
parents: 478
diff changeset
   703
  shows " rsb @ rdistinct rs (set rsb) @ RALTS rs # rsc \<leadsto>g* rsb @ rdistinct rs (set rsb) @ rsc"
478
Chengsong
parents: 476
diff changeset
   704
  sorry
Chengsong
parents: 476
diff changeset
   705
479
Chengsong
parents: 478
diff changeset
   706
lemma grewrites_rev_append:
Chengsong
parents: 478
diff changeset
   707
  shows "rs1 \<leadsto>g* rs2 \<Longrightarrow> rs1 @ [x] \<leadsto>g* rs2 @ [x]"
Chengsong
parents: 478
diff changeset
   708
  using grewritess_concat by auto
478
Chengsong
parents: 476
diff changeset
   709
479
Chengsong
parents: 478
diff changeset
   710
lemma grewrites_inclusion:
Chengsong
parents: 478
diff changeset
   711
  shows "set rs \<subseteq> set rs1 \<Longrightarrow> rs1 @ rs \<leadsto>g* rs1"
Chengsong
parents: 478
diff changeset
   712
  apply(induct rs arbitrary: rs1)
Chengsong
parents: 478
diff changeset
   713
  apply simp
Chengsong
parents: 478
diff changeset
   714
  by (meson gmany_steps_later grewrite_variant1 list.set_intros(1) set_subset_Cons subset_code(1))
478
Chengsong
parents: 476
diff changeset
   715
479
Chengsong
parents: 478
diff changeset
   716
lemma distinct_keeps_last:
Chengsong
parents: 478
diff changeset
   717
  shows "\<lbrakk>x \<notin> rset; x \<notin> set xs \<rbrakk> \<Longrightarrow> rdistinct (xs @ [x]) rset = rdistinct xs rset @ [x]"
Chengsong
parents: 478
diff changeset
   718
  by (simp add: concat_rdistinct_equality1)
478
Chengsong
parents: 476
diff changeset
   719
Chengsong
parents: 476
diff changeset
   720
lemma grewrites_shape2:
Chengsong
parents: 476
diff changeset
   721
  shows "       RALTS rs \<notin> set rsb \<Longrightarrow>
Chengsong
parents: 476
diff changeset
   722
       rsb @
Chengsong
parents: 476
diff changeset
   723
       rdistinct (rs @ rsa)
Chengsong
parents: 476
diff changeset
   724
        (set rsb) \<leadsto>g* rsb @
Chengsong
parents: 476
diff changeset
   725
                       rdistinct rs (set rsb) @
479
Chengsong
parents: 478
diff changeset
   726
                       rdistinct rsa (set rs \<union> set rsb \<union> {RALTS rs})"
Chengsong
parents: 478
diff changeset
   727
  apply(subgoal_tac " rdistinct (rs @ rsa) (set rsb) =  rdistinct rs (set rsb) @ rdistinct rsa (set rs \<union> set rsb)")
Chengsong
parents: 478
diff changeset
   728
   apply (simp only:)
Chengsong
parents: 478
diff changeset
   729
  prefer 2
Chengsong
parents: 478
diff changeset
   730
  apply (simp add: Un_commute concat_rdistinct_equality1)
Chengsong
parents: 478
diff changeset
   731
  apply(induct rsa arbitrary: rs rsb rule: rev_induct)
Chengsong
parents: 478
diff changeset
   732
   apply simp
Chengsong
parents: 478
diff changeset
   733
  apply(case_tac "x \<in> set rs")
Chengsong
parents: 478
diff changeset
   734
  apply (simp add: distinct_removes_middle3)
Chengsong
parents: 478
diff changeset
   735
  apply(case_tac "x = RALTS rs")
Chengsong
parents: 478
diff changeset
   736
   apply simp
Chengsong
parents: 478
diff changeset
   737
  apply(case_tac "x \<in> set rsb")
Chengsong
parents: 478
diff changeset
   738
   apply simp
Chengsong
parents: 478
diff changeset
   739
    apply (simp add: concat_rdistinct_equality1)
Chengsong
parents: 478
diff changeset
   740
  apply (simp add: concat_rdistinct_equality1)
Chengsong
parents: 478
diff changeset
   741
  apply simp
Chengsong
parents: 478
diff changeset
   742
  apply(drule_tac x = "rs " in meta_spec)
Chengsong
parents: 478
diff changeset
   743
  apply(drule_tac x = rsb in meta_spec)
Chengsong
parents: 478
diff changeset
   744
  apply simp
Chengsong
parents: 478
diff changeset
   745
  apply(subgoal_tac " rsb @ rdistinct rs (set rsb) @ rdistinct xs (set rs \<union> set rsb) \<leadsto>g* rsb @ rdistinct rs (set rsb) @ rdistinct xs (insert (RALTS rs) (set rs \<union> set rsb))")
Chengsong
parents: 478
diff changeset
   746
  prefer 2
Chengsong
parents: 478
diff changeset
   747
   apply (simp add: concat_rdistinct_equality1)
Chengsong
parents: 478
diff changeset
   748
  apply(case_tac "x \<in> set xs")
Chengsong
parents: 478
diff changeset
   749
   apply simp
Chengsong
parents: 478
diff changeset
   750
   apply (simp add: distinct_removes_last2)
Chengsong
parents: 478
diff changeset
   751
  apply(case_tac "x \<in> set rsb")
Chengsong
parents: 478
diff changeset
   752
   apply (smt (verit, ccfv_threshold) Un_iff append.right_neutral concat_rdistinct_equality1 insert_is_Un rdistinct.simps(2))
Chengsong
parents: 478
diff changeset
   753
  apply(subgoal_tac "rsb @ rdistinct rs (set rsb) @ rdistinct (xs @ [x]) (set rs \<union> set rsb) = rsb @ rdistinct rs (set rsb) @ rdistinct xs (set rs \<union> set rsb) @ [x]")
Chengsong
parents: 478
diff changeset
   754
  apply(simp only:)
Chengsong
parents: 478
diff changeset
   755
  apply(case_tac "x = RALTS rs")
Chengsong
parents: 478
diff changeset
   756
    apply(subgoal_tac "rsb @ rdistinct rs (set rsb) @ rdistinct xs (set rs \<union> set rsb) @ [x] \<leadsto>g* rsb @ rdistinct rs (set rsb) @ rdistinct xs (set rs \<union> set rsb) @ rs")
Chengsong
parents: 478
diff changeset
   757
  apply(subgoal_tac "rsb @ rdistinct rs (set rsb) @ rdistinct xs (set rs \<union> set rsb) @ rs \<leadsto>g* rsb @ rdistinct rs (set rsb) @ rdistinct xs (set rs \<union> set rsb) ")
Chengsong
parents: 478
diff changeset
   758
      apply (smt (verit, ccfv_SIG) Un_insert_left append.right_neutral concat_rdistinct_equality1 greal_trans insert_iff rdistinct.simps(2))
Chengsong
parents: 478
diff changeset
   759
  apply(subgoal_tac "set rs \<subseteq> set ( rsb @ rdistinct rs (set rsb) @ rdistinct xs (set rs \<union> set rsb))")
Chengsong
parents: 478
diff changeset
   760
  apply (metis append.assoc grewrites_inclusion)
Chengsong
parents: 478
diff changeset
   761
     apply (metis Un_upper1 append.assoc dual_order.trans list_dlist_union set_append)
Chengsong
parents: 478
diff changeset
   762
  apply (metis append_Nil2 gr_in_rstar grewrite.intros(2) grewrite_append)
Chengsong
parents: 478
diff changeset
   763
   apply(subgoal_tac " rsb @ rdistinct rs (set rsb) @ rdistinct (xs @ [x]) (insert (RALTS rs) (set rs \<union> set rsb)) =  rsb @ rdistinct rs (set rsb) @ rdistinct (xs) (insert (RALTS rs) (set rs \<union> set rsb)) @ [x]")
Chengsong
parents: 478
diff changeset
   764
  apply(simp only:)
Chengsong
parents: 478
diff changeset
   765
  apply (metis append.assoc grewrites_rev_append)
Chengsong
parents: 478
diff changeset
   766
  apply (simp add: insert_absorb)
Chengsong
parents: 478
diff changeset
   767
   apply (simp add: distinct_keeps_last)+
Chengsong
parents: 478
diff changeset
   768
  done
478
Chengsong
parents: 476
diff changeset
   769
479
Chengsong
parents: 478
diff changeset
   770
lemma rdistinct_add_acc:
Chengsong
parents: 478
diff changeset
   771
  shows "rset2 \<subseteq> set rsb \<Longrightarrow> rsb @ rdistinct rs rset \<leadsto>g* rsb @ rdistinct rs (rset \<union> rset2)"
Chengsong
parents: 478
diff changeset
   772
  apply(induct rs arbitrary: rsb rset rset2)
Chengsong
parents: 478
diff changeset
   773
   apply simp
Chengsong
parents: 478
diff changeset
   774
  apply (case_tac "a \<in> rset")
Chengsong
parents: 478
diff changeset
   775
   apply simp
Chengsong
parents: 478
diff changeset
   776
  apply(case_tac "a \<in> rset2")
Chengsong
parents: 478
diff changeset
   777
  apply simp
Chengsong
parents: 478
diff changeset
   778
   apply (meson create_nonexistent_distinct_set gr_in_rstar greal_trans grewrite_variant1 in_mono)
Chengsong
parents: 478
diff changeset
   779
  apply simp
Chengsong
parents: 478
diff changeset
   780
  apply(drule_tac x = "rsb @ [a]" in meta_spec)
Chengsong
parents: 478
diff changeset
   781
  by (metis Un_insert_left append.assoc append_Cons append_Nil set_append sup.coboundedI1)
Chengsong
parents: 478
diff changeset
   782
  
478
Chengsong
parents: 476
diff changeset
   783
479
Chengsong
parents: 478
diff changeset
   784
lemma frewrite_fun1:
Chengsong
parents: 478
diff changeset
   785
  shows "       RALTS rs \<in> set rsb \<Longrightarrow>
Chengsong
parents: 478
diff changeset
   786
       rsb @ rdistinct rsa (set rsb) \<leadsto>g* rflts rsb @ rdistinct rsa (set rsb \<union> set rs)"
Chengsong
parents: 478
diff changeset
   787
  apply(subgoal_tac "rsb @ rdistinct rsa (set rsb) \<leadsto>g* rflts rsb @ rdistinct rsa (set rsb)")
Chengsong
parents: 478
diff changeset
   788
   apply(subgoal_tac " set rs \<subseteq> set (rflts rsb)")
Chengsong
parents: 478
diff changeset
   789
  prefer 2
Chengsong
parents: 478
diff changeset
   790
  using spilled_alts_contained apply blast
Chengsong
parents: 478
diff changeset
   791
   apply(subgoal_tac "rflts rsb @ rdistinct rsa (set rsb) \<leadsto>g* rflts rsb @ rdistinct rsa (set rsb \<union> set rs)")
Chengsong
parents: 478
diff changeset
   792
  using greal_trans apply blast
Chengsong
parents: 478
diff changeset
   793
  using rdistinct_add_acc apply presburger
Chengsong
parents: 478
diff changeset
   794
  using flts_gstar grewritess_concat by auto
Chengsong
parents: 478
diff changeset
   795
  
478
Chengsong
parents: 476
diff changeset
   796
Chengsong
parents: 476
diff changeset
   797
Chengsong
parents: 476
diff changeset
   798
476
Chengsong
parents: 475
diff changeset
   799
Chengsong
parents: 475
diff changeset
   800
lemma frewrite_rd_grewrites:
Chengsong
parents: 475
diff changeset
   801
  shows "rs1 \<leadsto>f rs2 \<Longrightarrow> 
478
Chengsong
parents: 476
diff changeset
   802
\<exists>rs3. (rs @ (rdistinct rs1 (set rs)) \<leadsto>g* rs3) \<and> (rs @ (rdistinct rs2 (set rs)) \<leadsto>g* rs3) "
Chengsong
parents: 476
diff changeset
   803
  apply(induct rs1 rs2 arbitrary: rs rule: frewrite.induct)
Chengsong
parents: 476
diff changeset
   804
    apply(rule_tac x = "rsa @ (rdistinct rs ({RZERO} \<union> set rsa))" in exI)
476
Chengsong
parents: 475
diff changeset
   805
    apply(rule conjI)
478
Chengsong
parents: 476
diff changeset
   806
  apply(case_tac "RZERO \<in> set rsa")
Chengsong
parents: 476
diff changeset
   807
  apply simp+
Chengsong
parents: 476
diff changeset
   808
  using gstar0 apply fastforce
Chengsong
parents: 476
diff changeset
   809
     apply (simp add: gr_in_rstar grewrite.intros(1) grewrites_append)
Chengsong
parents: 476
diff changeset
   810
    apply (simp add: gstar0)
Chengsong
parents: 476
diff changeset
   811
    prefer 2
Chengsong
parents: 476
diff changeset
   812
    apply(case_tac "r \<in> set rs")
Chengsong
parents: 476
diff changeset
   813
  apply simp
Chengsong
parents: 476
diff changeset
   814
    apply(drule_tac x = "rs @ [r]" in meta_spec)
Chengsong
parents: 476
diff changeset
   815
    apply(erule exE)
Chengsong
parents: 476
diff changeset
   816
    apply(rule_tac x = "rs3" in exI)
Chengsong
parents: 476
diff changeset
   817
   apply simp
Chengsong
parents: 476
diff changeset
   818
  apply(case_tac "RALTS rs \<in> set rsb")
Chengsong
parents: 476
diff changeset
   819
   apply simp
479
Chengsong
parents: 478
diff changeset
   820
   apply(rule_tac x = "rflts rsb @ rdistinct rsa (set rsb \<union> set rs)" in exI)
478
Chengsong
parents: 476
diff changeset
   821
   apply(rule conjI)
479
Chengsong
parents: 478
diff changeset
   822
  using frewrite_fun1 apply force
Chengsong
parents: 478
diff changeset
   823
  apply (metis frewrite_fun1 rdistinct_concat sup_ge2)
478
Chengsong
parents: 476
diff changeset
   824
  apply(simp)
Chengsong
parents: 476
diff changeset
   825
  apply(rule_tac x = 
479
Chengsong
parents: 478
diff changeset
   826
 "rsb @
Chengsong
parents: 478
diff changeset
   827
                       rdistinct rs (set rsb) @
Chengsong
parents: 478
diff changeset
   828
                       rdistinct rsa (set rs \<union> set rsb \<union> {RALTS rs})" in exI)
478
Chengsong
parents: 476
diff changeset
   829
  apply(rule conjI)
Chengsong
parents: 476
diff changeset
   830
   prefer 2
Chengsong
parents: 476
diff changeset
   831
  using grewrites_shape2 apply force
479
Chengsong
parents: 478
diff changeset
   832
  by (metis Un_insert_left frewrite_rd_grewrites_aux inf_sup_aci(5) insert_is_Un rdistinct.simps(2))
478
Chengsong
parents: 476
diff changeset
   833
Chengsong
parents: 476
diff changeset
   834
473
Chengsong
parents: 472
diff changeset
   835
476
Chengsong
parents: 475
diff changeset
   836
Chengsong
parents: 475
diff changeset
   837
lemma frewrites_rd_grewrites:
Chengsong
parents: 475
diff changeset
   838
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow>
478
Chengsong
parents: 476
diff changeset
   839
rsimp (RALTS rs1) = rsimp (RALTS rs2)"
476
Chengsong
parents: 475
diff changeset
   840
  apply(induct rs1 rs2 rule: frewrites.induct)
Chengsong
parents: 475
diff changeset
   841
   apply simp
479
Chengsong
parents: 478
diff changeset
   842
  using frewrite_simpeq by presburger
476
Chengsong
parents: 475
diff changeset
   843
Chengsong
parents: 475
diff changeset
   844
lemma frewrite_simpeq2:
Chengsong
parents: 475
diff changeset
   845
  shows "rs1 \<leadsto>f rs2 \<Longrightarrow> rsimp (RALTS (rdistinct rs1 {})) = rsimp (RALTS (rdistinct rs2 {}))"
478
Chengsong
parents: 476
diff changeset
   846
  apply(subgoal_tac "\<exists> rs3. (rdistinct rs1 {} \<leadsto>g* rs3) \<and> (rdistinct rs2 {} \<leadsto>g* rs3)")
Chengsong
parents: 476
diff changeset
   847
  using grewrites_equal_rsimp apply fastforce
479
Chengsong
parents: 478
diff changeset
   848
  by (metis append_self_conv2 frewrite_rd_grewrites list.set(1))
Chengsong
parents: 478
diff changeset
   849
Chengsong
parents: 478
diff changeset
   850
Chengsong
parents: 478
diff changeset
   851
478
Chengsong
parents: 476
diff changeset
   852
473
Chengsong
parents: 472
diff changeset
   853
(*a more refined notion of \<leadsto>* is needed,
Chengsong
parents: 472
diff changeset
   854
this lemma fails when rs1 contains some RALTS rs where elements
Chengsong
parents: 472
diff changeset
   855
of rs appear in later parts of rs1, which will be picked up by rs2
Chengsong
parents: 472
diff changeset
   856
and deduplicated*)
476
Chengsong
parents: 475
diff changeset
   857
lemma frewrites_simpeq:
473
Chengsong
parents: 472
diff changeset
   858
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow>
476
Chengsong
parents: 475
diff changeset
   859
 rsimp (RALTS (rdistinct rs1 {})) = rsimp (RALTS ( rdistinct rs2 {})) "
Chengsong
parents: 475
diff changeset
   860
  apply(induct rs1 rs2 rule: frewrites.induct)
Chengsong
parents: 475
diff changeset
   861
   apply simp
478
Chengsong
parents: 476
diff changeset
   862
  using frewrite_simpeq2 by presburger
476
Chengsong
parents: 475
diff changeset
   863
473
Chengsong
parents: 472
diff changeset
   864
Chengsong
parents: 472
diff changeset
   865
lemma frewrite_single_step:
Chengsong
parents: 472
diff changeset
   866
  shows " rs2 \<leadsto>f rs3 \<Longrightarrow> rsimp (RALTS rs2) = rsimp (RALTS rs3)"
Chengsong
parents: 472
diff changeset
   867
  apply(induct rs2 rs3 rule: frewrite.induct)
Chengsong
parents: 472
diff changeset
   868
    apply simp
Chengsong
parents: 472
diff changeset
   869
  using simp_flatten apply blast
Chengsong
parents: 472
diff changeset
   870
  by (metis (no_types, opaque_lifting) list.simps(9) rsimp.simps(2) simp_flatten2)
Chengsong
parents: 472
diff changeset
   871
Chengsong
parents: 472
diff changeset
   872
lemma frewrites_equivalent_simp:
Chengsong
parents: 472
diff changeset
   873
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> rsimp (RALTS rs1) = rsimp (RALTS rs2)"
Chengsong
parents: 472
diff changeset
   874
  apply(induct rs1 rs2 rule: frewrites.induct)
Chengsong
parents: 472
diff changeset
   875
   apply simp
Chengsong
parents: 472
diff changeset
   876
  using frewrite_single_step by presburger
Chengsong
parents: 472
diff changeset
   877
476
Chengsong
parents: 475
diff changeset
   878
lemma grewrite_simpalts:
Chengsong
parents: 475
diff changeset
   879
  shows " rs2 \<leadsto>g rs3 \<Longrightarrow> rsimp (rsimp_ALTs rs2) = rsimp (rsimp_ALTs rs3)"
Chengsong
parents: 475
diff changeset
   880
  apply(induct rs2 rs3 rule : grewrite.induct)
Chengsong
parents: 475
diff changeset
   881
  using identity_wwo0 apply presburger
Chengsong
parents: 475
diff changeset
   882
  apply (metis frewrite.intros(1) frewrite_single_step identity_wwo0 rsimp_ALTs.simps(3) simp_flatten)
Chengsong
parents: 475
diff changeset
   883
  apply (smt (verit, ccfv_SIG) gmany_steps_later grewrites.intros(1) grewrites_cons grewrites_equal_rsimp identity_wwo0 rsimp_ALTs.simps(3))
Chengsong
parents: 475
diff changeset
   884
  apply simp
Chengsong
parents: 475
diff changeset
   885
  apply(subst rsimp_alts_equal)
Chengsong
parents: 475
diff changeset
   886
  apply(case_tac "rsa = [] \<and> rsb = [] \<and> rsc = []")
Chengsong
parents: 475
diff changeset
   887
   apply(subgoal_tac "rsa @ a # rsb @ rsc = [a]")
Chengsong
parents: 475
diff changeset
   888
  apply (simp only:)
Chengsong
parents: 475
diff changeset
   889
  apply (metis append_Nil frewrite.intros(1) frewrite_single_step identity_wwo0 rsimp_ALTs.simps(3) simp_removes_duplicate1(2))
Chengsong
parents: 475
diff changeset
   890
   apply simp
Chengsong
parents: 475
diff changeset
   891
  by (smt (verit, best) append.assoc append_Cons frewrite.intros(1) frewrite_single_step identity_wwo0 in_set_conv_decomp rsimp_ALTs.simps(3) simp_removes_duplicate3)
Chengsong
parents: 475
diff changeset
   892
Chengsong
parents: 475
diff changeset
   893
Chengsong
parents: 475
diff changeset
   894
lemma grewrites_simpalts:
Chengsong
parents: 475
diff changeset
   895
  shows " rs2 \<leadsto>g* rs3 \<Longrightarrow> rsimp (rsimp_ALTs rs2) = rsimp (rsimp_ALTs rs3)"
Chengsong
parents: 475
diff changeset
   896
  apply(induct rs2 rs3 rule: grewrites.induct)
Chengsong
parents: 475
diff changeset
   897
   apply simp
Chengsong
parents: 475
diff changeset
   898
  using grewrite_simpalts by presburger
Chengsong
parents: 475
diff changeset
   899
(*
473
Chengsong
parents: 472
diff changeset
   900
lemma frewrites_dB_wwo0_simp:
Chengsong
parents: 472
diff changeset
   901
  shows "rdistinct rs1 {RZERO} \<leadsto>f* rdistinct rs2 {RZERO} 
Chengsong
parents: 472
diff changeset
   902
         \<Longrightarrow> rsimp (RALTS (rdistinct rs1 {})) = rsimp (RALTS (rdistinct rs2 {}))"
Chengsong
parents: 472
diff changeset
   903
Chengsong
parents: 472
diff changeset
   904
  sorry
476
Chengsong
parents: 475
diff changeset
   905
*)
Chengsong
parents: 475
diff changeset
   906
473
Chengsong
parents: 472
diff changeset
   907
Chengsong
parents: 472
diff changeset
   908
Chengsong
parents: 472
diff changeset
   909
467
Chengsong
parents: 465
diff changeset
   910
lemma simp_der_flts:
471
Chengsong
parents: 469
diff changeset
   911
  shows "rsimp (RALTS (rdistinct (map (rder x) (rflts rs)) {})) = 
Chengsong
parents: 469
diff changeset
   912
         rsimp (RALTS (rdistinct (rflts (map (rder x) rs)) {}))"
473
Chengsong
parents: 472
diff changeset
   913
  apply(subgoal_tac "map (rder x) (rflts rs) \<leadsto>f* rflts (map (rder x) rs)")
478
Chengsong
parents: 476
diff changeset
   914
  using frewrites_simpeq apply presburger
Chengsong
parents: 476
diff changeset
   915
  using early_late_der_frewrites by auto
Chengsong
parents: 476
diff changeset
   916
Chengsong
parents: 476
diff changeset
   917
  
476
Chengsong
parents: 475
diff changeset
   918
Chengsong
parents: 475
diff changeset
   919
Chengsong
parents: 475
diff changeset
   920
Chengsong
parents: 475
diff changeset
   921
Chengsong
parents: 475
diff changeset
   922
 
Chengsong
parents: 475
diff changeset
   923
Chengsong
parents: 475
diff changeset
   924
Chengsong
parents: 475
diff changeset
   925
Chengsong
parents: 475
diff changeset
   926
lemma simp_der_pierce_flts_prelim:
Chengsong
parents: 475
diff changeset
   927
  shows "rsimp (rsimp_ALTs (rdistinct (map (rder x) (rflts rs)) {})) 
Chengsong
parents: 475
diff changeset
   928
       = rsimp (rsimp_ALTs (rdistinct (rflts (map (rder x) rs)) {}))"
478
Chengsong
parents: 476
diff changeset
   929
  by (metis append.right_neutral grewrite.intros(2) grewrite_simpalts rsimp_ALTs.simps(2) simp_der_flts)
467
Chengsong
parents: 465
diff changeset
   930
Chengsong
parents: 465
diff changeset
   931
465
Chengsong
parents: 456
diff changeset
   932
lemma simp_der_pierce_flts:
471
Chengsong
parents: 469
diff changeset
   933
  shows " rsimp (
Chengsong
parents: 469
diff changeset
   934
rsimp_ALTs (rdistinct (map (rder x) (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {})
Chengsong
parents: 469
diff changeset
   935
) =
Chengsong
parents: 469
diff changeset
   936
          rsimp (
Chengsong
parents: 469
diff changeset
   937
rsimp_ALTs (rdistinct (rflts (map (rder x) (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {})
Chengsong
parents: 469
diff changeset
   938
)"
476
Chengsong
parents: 475
diff changeset
   939
  using simp_der_pierce_flts_prelim by presburger
465
Chengsong
parents: 456
diff changeset
   940
453
Chengsong
parents: 451
diff changeset
   941
Chengsong
parents: 451
diff changeset
   942
Chengsong
parents: 451
diff changeset
   943
lemma simp_more_distinct:
465
Chengsong
parents: 456
diff changeset
   944
  shows "rsimp  (rsimp_ALTs (rsa @ rs)) = rsimp (rsimp_ALTs (rsa @ (rdistinct rs (set rsa)))) "
467
Chengsong
parents: 465
diff changeset
   945
  
Chengsong
parents: 465
diff changeset
   946
465
Chengsong
parents: 456
diff changeset
   947
453
Chengsong
parents: 451
diff changeset
   948
Chengsong
parents: 451
diff changeset
   949
  sorry
Chengsong
parents: 451
diff changeset
   950
Chengsong
parents: 451
diff changeset
   951
lemma non_empty_list:
Chengsong
parents: 451
diff changeset
   952
  shows "a \<in> set as \<Longrightarrow> as \<noteq> []"
Chengsong
parents: 451
diff changeset
   953
  by (metis empty_iff empty_set)
Chengsong
parents: 451
diff changeset
   954
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   955
lemma distinct_comp:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   956
  shows "rdistinct (rs1@rs2) {} = (rdistinct rs1 {}) @ (rdistinct rs2 (set rs1))"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   957
  apply(induct rs2 arbitrary: rs1)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   958
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   959
  apply(subgoal_tac "rs1 @ a # rs2 = (rs1 @ [a]) @ rs2")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   960
   apply(simp only:)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   961
   apply(case_tac "a \<in> set rs1")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   962
    apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   963
  oops
453
Chengsong
parents: 451
diff changeset
   964
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   965
lemma instantiate1:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   966
  shows "\<lbrakk>\<And>ab rset1.  rdistinct (ab # as) rset1 = rdistinct (ab # as @ [ab]) rset1\<rbrakk> \<Longrightarrow>  
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   967
rdistinct (aa # as) rset = rdistinct (aa # as @ [aa]) rset"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   968
  apply(drule_tac x = "aa" in meta_spec)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   969
  apply(drule_tac x = "rset" in meta_spec)
453
Chengsong
parents: 451
diff changeset
   970
  apply simp
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   971
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   972
  
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   973
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   974
lemma not_head_elem:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   975
  shows " \<lbrakk>aa \<in> set (a # as); aa \<notin> (set as)\<rbrakk> \<Longrightarrow> a = aa"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   976
  
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   977
  by fastforce
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   978
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   979
(*
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   980
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   981
  apply (metis append_Cons)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   982
  apply(case_tac "ab \<in> rset1")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   983
  apply (metis (no_types, opaque_lifting) Un_insert_left append_Cons insert_iff rdistinct.simps(2) sup_bot_left)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   984
  apply(subgoal_tac "rdistinct (ab # (aa # as) @ [ab]) rset1 = 
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   985
               ab # (rdistinct ((aa # as) @ [ab]) (insert ab rset1))")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   986
   apply(simp only:)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   987
   apply(subgoal_tac "rdistinct (ab # aa # as) rset1 = ab # (rdistinct (aa # as) (insert ab rset1))")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   988
  apply(simp only:)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   989
    apply(subgoal_tac "rdistinct ((aa # as) @ [ab]) (insert ab rset1) = rdistinct (aa # as) (insert ab rset1)")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   990
  apply blast
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   991
*)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
   992
  
453
Chengsong
parents: 451
diff changeset
   993
Chengsong
parents: 451
diff changeset
   994
lemma flts_identity1:
Chengsong
parents: 451
diff changeset
   995
  shows  "rflts (rs @ [RONE]) = rflts rs @ [RONE] "
Chengsong
parents: 451
diff changeset
   996
  apply(induct rs)
Chengsong
parents: 451
diff changeset
   997
   apply simp+
Chengsong
parents: 451
diff changeset
   998
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
   999
       apply simp
Chengsong
parents: 451
diff changeset
  1000
      apply simp+
Chengsong
parents: 451
diff changeset
  1001
  done
Chengsong
parents: 451
diff changeset
  1002
Chengsong
parents: 451
diff changeset
  1003
lemma flts_identity10:
Chengsong
parents: 451
diff changeset
  1004
  shows " rflts (rs @ [RCHAR c]) = rflts rs @ [RCHAR c]"
Chengsong
parents: 451
diff changeset
  1005
  apply(induct rs)
Chengsong
parents: 451
diff changeset
  1006
   apply simp+
Chengsong
parents: 451
diff changeset
  1007
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
  1008
       apply simp+
Chengsong
parents: 451
diff changeset
  1009
  done
Chengsong
parents: 451
diff changeset
  1010
Chengsong
parents: 451
diff changeset
  1011
lemma flts_identity11:
Chengsong
parents: 451
diff changeset
  1012
  shows " rflts (rs @ [RSEQ r1 r2]) = rflts rs @ [RSEQ r1 r2]"
Chengsong
parents: 451
diff changeset
  1013
  apply(induct rs)
Chengsong
parents: 451
diff changeset
  1014
   apply simp+
Chengsong
parents: 451
diff changeset
  1015
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
  1016
       apply simp+
Chengsong
parents: 451
diff changeset
  1017
  done
Chengsong
parents: 451
diff changeset
  1018
Chengsong
parents: 451
diff changeset
  1019
lemma flts_identity12:
Chengsong
parents: 451
diff changeset
  1020
  shows " rflts (rs @ [RSTAR r0]) = rflts rs @ [RSTAR r0]"
Chengsong
parents: 451
diff changeset
  1021
  apply(induct rs)
Chengsong
parents: 451
diff changeset
  1022
   apply simp+
Chengsong
parents: 451
diff changeset
  1023
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
  1024
       apply simp+
Chengsong
parents: 451
diff changeset
  1025
  done
Chengsong
parents: 451
diff changeset
  1026
Chengsong
parents: 451
diff changeset
  1027
lemma flts_identity2:
Chengsong
parents: 451
diff changeset
  1028
  shows "a \<noteq> RZERO \<and> (\<forall>rs. a \<noteq> RALTS rs) \<Longrightarrow>  rflts (rs @ [a]) = rflts rs @ [a]"
Chengsong
parents: 451
diff changeset
  1029
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
  1030
       apply simp
Chengsong
parents: 451
diff changeset
  1031
  using flts_identity1 apply auto[1]
Chengsong
parents: 451
diff changeset
  1032
  using flts_identity10 apply blast
Chengsong
parents: 451
diff changeset
  1033
  using flts_identity11 apply auto[1]
Chengsong
parents: 451
diff changeset
  1034
   apply blast
Chengsong
parents: 451
diff changeset
  1035
  using flts_identity12 by presburger
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1036
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1037
lemma flts_identity3:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1038
  shows "a = RZERO  \<Longrightarrow> rflts (rs @ [a]) = rflts rs"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1039
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1040
  apply(induct rs)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1041
   apply simp+
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1042
  apply(case_tac aa)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1043
       apply simp+
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1044
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1045
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1046
lemma distinct_removes_last3:
465
Chengsong
parents: 456
diff changeset
  1047
  shows "\<lbrakk>a \<in> set as\<rbrakk>
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1048
    \<Longrightarrow> rdistinct as {} = rdistinct (as @ [a]) {}"
465
Chengsong
parents: 456
diff changeset
  1049
  by (simp add: distinct_removes_last2)
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1050
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1051
lemma set_inclusion_with_flts1:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1052
  shows " \<lbrakk>RONE \<in> set rs\<rbrakk> \<Longrightarrow> RONE  \<in> set (rflts rs)"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1053
  apply(induct rs)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1054
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1055
  apply(case_tac " RONE \<in> set rs")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1056
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1057
  apply (metis Un_upper2 insert_absorb insert_subset list.set_intros(2) rflts.simps(2) rflts.simps(3) rflts_def_idiot set_append)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1058
  apply(case_tac "RONE = a")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1059
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1060
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1061
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1062
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1063
lemma set_inclusion_with_flts10:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1064
  shows " \<lbrakk>RCHAR x \<in> set rs\<rbrakk> \<Longrightarrow> RCHAR x  \<in> set (rflts rs)"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1065
  apply(induct rs)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1066
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1067
  apply(case_tac " RCHAR x \<in> set rs")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1068
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1069
  apply (metis Un_upper2 insert_absorb insert_subset rflts.simps(2) rflts.simps(3) rflts_def_idiot set_append set_subset_Cons)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1070
  apply(case_tac "RCHAR x = a")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1071
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1072
  apply fastforce
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1073
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1074
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1075
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1076
lemma set_inclusion_with_flts11:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1077
  shows " \<lbrakk>RSEQ r1 r2 \<in> set rs\<rbrakk> \<Longrightarrow> RSEQ r1 r2  \<in> set (rflts rs)"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1078
  apply(induct rs)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1079
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1080
  apply(case_tac " RSEQ r1 r2 \<in> set rs")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1081
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1082
  apply (metis Un_upper2 insert_absorb insert_subset rflts.simps(2) rflts.simps(3) rflts_def_idiot set_append set_subset_Cons)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1083
  apply(case_tac "RSEQ r1 r2 = a")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1084
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1085
  apply fastforce
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1086
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1087
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1088
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1089
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1090
lemma set_inclusion_with_flts:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1091
  shows " \<lbrakk>a \<in> set as; rsimp a \<in> set (map rsimp as); rsimp a = RONE\<rbrakk> \<Longrightarrow> rsimp a \<in> set (rflts (map rsimp as))"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1092
  by (simp add: set_inclusion_with_flts1)
453
Chengsong
parents: 451
diff changeset
  1093
  
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1094
lemma "\<And>x5. \<lbrakk>a \<in> set as; rsimp a \<in> set (map rsimp as); rsimp a = RALTS x5\<rbrakk>
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1095
          \<Longrightarrow> rsimp_ALTs (rdistinct (rflts (map rsimp as @ [rsimp a])) {}) = 
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1096
rsimp_ALTs (rdistinct (rflts (map rsimp as @ x5)) {})"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1097
465
Chengsong
parents: 456
diff changeset
  1098
  sorry
Chengsong
parents: 456
diff changeset
  1099
453
Chengsong
parents: 451
diff changeset
  1100
Chengsong
parents: 451
diff changeset
  1101
lemma last_elem_dup1:
Chengsong
parents: 451
diff changeset
  1102
  shows " a \<in> set as \<Longrightarrow> rsimp (RALTS (as @ [a] )) = rsimp (RALTS (as ))"
Chengsong
parents: 451
diff changeset
  1103
  apply simp
Chengsong
parents: 451
diff changeset
  1104
  apply(subgoal_tac "rsimp a \<in> set (map rsimp as)")
Chengsong
parents: 451
diff changeset
  1105
  prefer 2
Chengsong
parents: 451
diff changeset
  1106
   apply simp
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1107
  apply(case_tac "rsimp a")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1108
       apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1109
  
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1110
  using flts_identity3 apply presburger
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1111
      apply(subst flts_identity2)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1112
  using rrexp.distinct(1) rrexp.distinct(15) apply presburger
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1113
      apply(subst distinct_removes_last3[symmetric])
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1114
  using set_inclusion_with_flts apply blast
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1115
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1116
  apply (metis distinct_removes_last3 flts_identity10 set_inclusion_with_flts10)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1117
  apply (metis distinct_removes_last3 flts_identity11 set_inclusion_with_flts11)
453
Chengsong
parents: 451
diff changeset
  1118
  sorry
Chengsong
parents: 451
diff changeset
  1119
Chengsong
parents: 451
diff changeset
  1120
lemma last_elem_dup:
Chengsong
parents: 451
diff changeset
  1121
  shows " a \<in> set as \<Longrightarrow> rsimp (rsimp_ALTs (as @ [a] )) = rsimp (rsimp_ALTs (as ))"
Chengsong
parents: 451
diff changeset
  1122
  apply(induct as rule: rev_induct)
Chengsong
parents: 451
diff changeset
  1123
   apply simp
Chengsong
parents: 451
diff changeset
  1124
  apply simp
Chengsong
parents: 451
diff changeset
  1125
  apply(subgoal_tac "xs \<noteq> []")
Chengsong
parents: 451
diff changeset
  1126
  prefer 2
Chengsong
parents: 451
diff changeset
  1127
  
Chengsong
parents: 451
diff changeset
  1128
Chengsong
parents: 451
diff changeset
  1129
  
Chengsong
parents: 451
diff changeset
  1130
Chengsong
parents: 451
diff changeset
  1131
  sorry
Chengsong
parents: 451
diff changeset
  1132
Chengsong
parents: 451
diff changeset
  1133
lemma appeared_before_remove_later:
Chengsong
parents: 451
diff changeset
  1134
  shows "a \<in>  set as \<Longrightarrow> rsimp (rsimp_ALTs ( as @ a # rs)) = rsimp (rsimp_ALTs (as @ rs))"
Chengsong
parents: 451
diff changeset
  1135
and "a \<in> set as \<Longrightarrow> rsimp (rsimp_ALTs as ) = rsimp (rsimp_ALTs (as @ [a]))"
Chengsong
parents: 451
diff changeset
  1136
  apply(induct rs arbitrary: as)
Chengsong
parents: 451
diff changeset
  1137
   apply simp
Chengsong
parents: 451
diff changeset
  1138
  
Chengsong
parents: 451
diff changeset
  1139
Chengsong
parents: 451
diff changeset
  1140
  sorry
Chengsong
parents: 451
diff changeset
  1141
Chengsong
parents: 451
diff changeset
  1142
lemma distinct_remove_later:
Chengsong
parents: 451
diff changeset
  1143
  shows "\<lbrakk>rder x a \<in> rder x ` set rsa\<rbrakk>
Chengsong
parents: 451
diff changeset
  1144
       \<Longrightarrow> rsimp (rsimp_ALTs (map (rder x) rsa @ rder x a # map (rder x) (rdistinct rs (insert a (set rsa))))) =
Chengsong
parents: 451
diff changeset
  1145
           rsimp (rsimp_ALTs (map (rder x) rsa @ map (rder x) (rdistinct rs (set rsa))))"
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1146
  
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1147
  sorry
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1148
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1149
453
Chengsong
parents: 451
diff changeset
  1150
lemma distinct_der_general:
Chengsong
parents: 451
diff changeset
  1151
  shows "rsimp (rsimp_ALTs (map (rder x) (rsa @ (rdistinct rs (set rsa))))) =
Chengsong
parents: 451
diff changeset
  1152
 rsimp ( rsimp_ALTs ((map (rder x) rsa)@(rdistinct (map (rder x) rs) (set (map (rder x) rsa)))) )"
Chengsong
parents: 451
diff changeset
  1153
  apply(induct rs arbitrary: rsa)
Chengsong
parents: 451
diff changeset
  1154
   apply simp
Chengsong
parents: 451
diff changeset
  1155
  apply(case_tac "a \<in> set rsa")
Chengsong
parents: 451
diff changeset
  1156
   apply(subgoal_tac "rder x a \<in> set (map (rder x) rsa)")
Chengsong
parents: 451
diff changeset
  1157
  apply simp
Chengsong
parents: 451
diff changeset
  1158
   apply simp
Chengsong
parents: 451
diff changeset
  1159
  apply(case_tac "rder x a \<notin> set (map (rder x) rsa)")
Chengsong
parents: 451
diff changeset
  1160
   apply(simp)
Chengsong
parents: 451
diff changeset
  1161
  apply(subst map_concat_cons)+
Chengsong
parents: 451
diff changeset
  1162
  apply(drule_tac x = "rsa @ [a]" in meta_spec)
Chengsong
parents: 451
diff changeset
  1163
   apply simp
Chengsong
parents: 451
diff changeset
  1164
  apply(drule neg_removal_element_of)
Chengsong
parents: 451
diff changeset
  1165
  apply simp
Chengsong
parents: 451
diff changeset
  1166
  apply(subst distinct_remove_later)
Chengsong
parents: 451
diff changeset
  1167
   apply simp
Chengsong
parents: 451
diff changeset
  1168
  apply(drule_tac x = "rsa" in meta_spec)
Chengsong
parents: 451
diff changeset
  1169
  by blast
Chengsong
parents: 451
diff changeset
  1170
Chengsong
parents: 451
diff changeset
  1171
  
Chengsong
parents: 451
diff changeset
  1172
Chengsong
parents: 451
diff changeset
  1173
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1174
lemma distinct_der:
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1175
  shows "rsimp (rsimp_ALTs (map (rder x) (rdistinct rs {}))) = rsimp ( rsimp_ALTs (rdistinct (map (rder x) rs) {}))"
453
Chengsong
parents: 451
diff changeset
  1176
  by (metis distinct_der_general list.simps(8) self_append_conv2 set_empty)
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1177
453
Chengsong
parents: 451
diff changeset
  1178
  
Chengsong
parents: 451
diff changeset
  1179
Chengsong
parents: 451
diff changeset
  1180
Chengsong
parents: 451
diff changeset
  1181
lemma rders_simp_lambda:
Chengsong
parents: 451
diff changeset
  1182
  shows " rsimp \<circ> rder x \<circ> (\<lambda>r. rders_simp r xs) = (\<lambda>r. rders_simp r (xs @ [x]))"
Chengsong
parents: 451
diff changeset
  1183
  using rders_simp_append by auto
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1184
453
Chengsong
parents: 451
diff changeset
  1185
lemma rders_simp_nonempty_simped:
Chengsong
parents: 451
diff changeset
  1186
  shows "xs \<noteq> [] \<Longrightarrow> rsimp \<circ> (\<lambda>r. rders_simp r xs) = (\<lambda>r. rders_simp r xs)"
Chengsong
parents: 451
diff changeset
  1187
  using rders_simp_same_simpders rsimp_idem by auto
Chengsong
parents: 451
diff changeset
  1188
Chengsong
parents: 451
diff changeset
  1189
lemma repeated_altssimp:
Chengsong
parents: 451
diff changeset
  1190
  shows "\<forall>r \<in> set rs. rsimp r = r \<Longrightarrow> rsimp (rsimp_ALTs (rdistinct (rflts rs) {})) =
Chengsong
parents: 451
diff changeset
  1191
           rsimp_ALTs (rdistinct (rflts rs) {})"
Chengsong
parents: 451
diff changeset
  1192
  by (metis map_idI rsimp.simps(2) rsimp_idem)
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1193
465
Chengsong
parents: 456
diff changeset
  1194
Chengsong
parents: 456
diff changeset
  1195
lemma add0_isomorphic:
Chengsong
parents: 456
diff changeset
  1196
  shows "rsimp_ALTs (rdistinct (rflts [rsimp r, RZERO]) {}) = rsimp r"
Chengsong
parents: 456
diff changeset
  1197
  sorry
Chengsong
parents: 456
diff changeset
  1198
Chengsong
parents: 456
diff changeset
  1199
Chengsong
parents: 456
diff changeset
  1200
lemma distinct_append_simp:
Chengsong
parents: 456
diff changeset
  1201
  shows " rsimp (rsimp_ALTs rs1) = rsimp (rsimp_ALTs rs2) \<Longrightarrow>
Chengsong
parents: 456
diff changeset
  1202
           rsimp (rsimp_ALTs (f a # rs1)) =
Chengsong
parents: 456
diff changeset
  1203
           rsimp (rsimp_ALTs (f a # rs2))"
Chengsong
parents: 456
diff changeset
  1204
  apply(case_tac rs1)
Chengsong
parents: 456
diff changeset
  1205
   apply simp
Chengsong
parents: 456
diff changeset
  1206
   apply(case_tac rs2)
Chengsong
parents: 456
diff changeset
  1207
    apply simp
Chengsong
parents: 456
diff changeset
  1208
   apply simp
Chengsong
parents: 456
diff changeset
  1209
   prefer 2
Chengsong
parents: 456
diff changeset
  1210
   apply(case_tac list)
Chengsong
parents: 456
diff changeset
  1211
    apply(case_tac rs2)
Chengsong
parents: 456
diff changeset
  1212
     apply simp
Chengsong
parents: 456
diff changeset
  1213
  using add0_isomorphic apply blast 
Chengsong
parents: 456
diff changeset
  1214
    apply simp
467
Chengsong
parents: 465
diff changeset
  1215
  oops
465
Chengsong
parents: 456
diff changeset
  1216
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1217
lemma alts_closed_form: shows 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1218
"rsimp (rders_simp (RALTS rs) s) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1219
rsimp (RALTS (map (\<lambda>r. rders_simp r s) rs))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1220
  apply(induct s rule: rev_induct)
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1221
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1222
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1223
  apply(subst rders_simp_append)
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1224
  apply(subgoal_tac " rsimp (rders_simp (rders_simp (RALTS rs) xs) [x]) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1225
 rsimp(rders_simp (rsimp_ALTs (rdistinct (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs)) {})) [x])")
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1226
   prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1227
  apply (metis inside_simp_removal rders_simp_one_char)
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1228
  apply(simp only: )
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1229
  apply(subst rders_simp_one_char)
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1230
  apply(subst rsimp_idem)
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1231
  apply(subgoal_tac "rsimp (rder x (rsimp_ALTs (rdistinct (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs)) {}))) =
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1232
                     rsimp ((rsimp_ALTs (map (rder x) (rdistinct (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs)) {})))) ")
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1233
  prefer 2
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1234
  using rder_rsimp_ALTs_commute apply presburger
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1235
  apply(simp only:)
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1236
  apply(subgoal_tac "rsimp (rsimp_ALTs (map (rder x) (rdistinct (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs)) {})))
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1237
= rsimp (rsimp_ALTs (rdistinct (map (rder x) (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {}))")
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1238
   prefer 2
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1239
  
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1240
  using distinct_der apply presburger
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1241
  apply(simp only:)
453
Chengsong
parents: 451
diff changeset
  1242
  apply(subgoal_tac " rsimp (rsimp_ALTs (rdistinct (map (rder x) (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {})) =
Chengsong
parents: 451
diff changeset
  1243
                      rsimp (rsimp_ALTs (rdistinct ( (rflts (map (rder x) (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs)))) {}))")
Chengsong
parents: 451
diff changeset
  1244
   apply(simp only:)
Chengsong
parents: 451
diff changeset
  1245
  apply(subgoal_tac " rsimp (rsimp_ALTs (rdistinct (rflts (map (rder x) (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {})) = 
Chengsong
parents: 451
diff changeset
  1246
                      rsimp (rsimp_ALTs (rdistinct (rflts ( (map (rsimp \<circ> (rder x) \<circ> (\<lambda>r. rders_simp r xs)) rs))) {}))")
Chengsong
parents: 451
diff changeset
  1247
    apply(simp only:)
Chengsong
parents: 451
diff changeset
  1248
  apply(subst rders_simp_lambda)
Chengsong
parents: 451
diff changeset
  1249
    apply(subst rders_simp_nonempty_simped)
Chengsong
parents: 451
diff changeset
  1250
     apply simp
Chengsong
parents: 451
diff changeset
  1251
    apply(subgoal_tac "\<forall>r \<in> set  (map (\<lambda>r. rders_simp r (xs @ [x])) rs). rsimp r = r")
Chengsong
parents: 451
diff changeset
  1252
  prefer 2
Chengsong
parents: 451
diff changeset
  1253
     apply (simp add: rders_simp_same_simpders rsimp_idem)
Chengsong
parents: 451
diff changeset
  1254
    apply(subst repeated_altssimp)
Chengsong
parents: 451
diff changeset
  1255
     apply simp
Chengsong
parents: 451
diff changeset
  1256
  apply fastforce
465
Chengsong
parents: 456
diff changeset
  1257
   apply (metis inside_simp_removal list.map_comp rder.simps(4) rsimp.simps(2) rsimp_idem)
476
Chengsong
parents: 475
diff changeset
  1258
  using simp_der_pierce_flts by blast
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1259
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1260
lemma alts_closed_form_variant: shows 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1261
"s \<noteq> [] \<Longrightarrow> rders_simp (RALTS rs) s = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1262
rsimp (RALTS (map (\<lambda>r. rders_simp r s) rs))"
478
Chengsong
parents: 476
diff changeset
  1263
  by (metis alts_closed_form comp_apply rders_simp_nonempty_simped)
Chengsong
parents: 476
diff changeset
  1264
  
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1265
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1266
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1267
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1268
lemma star_closed_form:
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1269
  shows "rders_simp (RSTAR r0) (c#s) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1270
rsimp ( RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) ) (star_updates s r0 [[c]]) ) ))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1271
  apply(induct s)
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1272
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1273
  sorry
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1274
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1275
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1276
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1277
lemma seq_closed_form: shows 
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1278
"rsimp (rders_simp (RSEQ r1 r2) s) = 
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1279
rsimp ( RALTS ( (RSEQ (rders_simp r1 s) r2) # 
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1280
                (map (rders_simp r2) (vsuf s r1)) 
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1281
              )  
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1282
      )"
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1283
  apply(induct s)
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1284
  apply simp
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1285
  sorry
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1286
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1287
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1288
lemma seq_closed_form_variant: shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1289
"s \<noteq> [] \<Longrightarrow> (rders_simp (RSEQ r1 r2) s) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1290
rsimp (RALTS ((RSEQ (rders_simp r1 s) r2) # (map (rders_simp r2) (vsuf s r1))))"
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1291
  apply(induct s rule: rev_induct)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1292
   apply simp
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1293
  apply(subst rders_simp_append)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1294
  apply(subst rders_simp_one_char)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1295
  apply(subst rsimp_idem[symmetric])
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1296
  apply(subst rders_simp_one_char[symmetric])
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1297
  apply(subst rders_simp_append[symmetric])
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1298
  apply(insert seq_closed_form)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1299
  apply(subgoal_tac "rsimp (rders_simp (RSEQ r1 r2) (xs @ [x]))
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1300
 = rsimp (RALTS (RSEQ (rders_simp r1 (xs @ [x])) r2 # map (rders_simp r2) (vsuf (xs @ [x]) r1)))")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1301
   apply force
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  1302
  by presburger
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1303
476
Chengsong
parents: 475
diff changeset
  1304
lemma simp_helps_der_pierce:
Chengsong
parents: 475
diff changeset
  1305
  shows " rsimp
Chengsong
parents: 475
diff changeset
  1306
            (rder x
Chengsong
parents: 475
diff changeset
  1307
              (rsimp_ALTs rs)) = 
Chengsong
parents: 475
diff changeset
  1308
          rsimp 
Chengsong
parents: 475
diff changeset
  1309
            (rsimp_ALTs 
Chengsong
parents: 475
diff changeset
  1310
              (map (rder x )
Chengsong
parents: 475
diff changeset
  1311
                rs
Chengsong
parents: 475
diff changeset
  1312
              )
Chengsong
parents: 475
diff changeset
  1313
            )"
Chengsong
parents: 475
diff changeset
  1314
  sorry
Chengsong
parents: 475
diff changeset
  1315
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1316
end