thys2/ClosedForms.thy
author Chengsong
Mon, 10 Jul 2023 19:29:22 +0100
changeset 664 ba44144875b1
parent 492 61eff2abb0b6
permissions -rw-r--r--
introduction Contribution section update
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
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
     5
lemma flts_middle0:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
     6
  shows "rflts (rsa @ RZERO # rsb) = rflts (rsa @ rsb)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
     7
  apply(induct rsa)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
     8
  apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
     9
  by (metis append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    10
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
    11
64183736777a almost there
Chengsong
parents: 489
diff changeset
    12
64183736777a almost there
Chengsong
parents: 489
diff changeset
    13
lemma simp_flatten_aux0:
64183736777a almost there
Chengsong
parents: 489
diff changeset
    14
  shows "rsimp (RALTS rs) = rsimp (RALTS (map rsimp rs))"
64183736777a almost there
Chengsong
parents: 489
diff changeset
    15
  by (metis append_Nil head_one_more_simp identity_wwo0 list.simps(8) rdistinct.simps(1) rflts.simps(1) rsimp.simps(2) rsimp_ALTs.simps(1) rsimp_ALTs.simps(3) simp_flatten spawn_simp_rsimpalts)
64183736777a almost there
Chengsong
parents: 489
diff changeset
    16
64183736777a almost there
Chengsong
parents: 489
diff changeset
    17
64183736777a almost there
Chengsong
parents: 489
diff changeset
    18
64183736777a almost there
Chengsong
parents: 489
diff changeset
    19
64183736777a almost there
Chengsong
parents: 489
diff changeset
    20
64183736777a almost there
Chengsong
parents: 489
diff changeset
    21
64183736777a almost there
Chengsong
parents: 489
diff changeset
    22
64183736777a almost there
Chengsong
parents: 489
diff changeset
    23
64183736777a almost there
Chengsong
parents: 489
diff changeset
    24
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    25
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    26
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    27
inductive 
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    28
  hrewrite:: "rrexp \<Rightarrow> rrexp \<Rightarrow> bool" ("_ h\<leadsto> _" [99, 99] 99)
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    29
where
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    30
  "RSEQ  RZERO r2 h\<leadsto> RZERO"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    31
| "RSEQ  r1 RZERO h\<leadsto> RZERO"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    32
| "RSEQ  RONE r h\<leadsto>  r"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    33
| "r1 h\<leadsto> r2 \<Longrightarrow> RSEQ  r1 r3 h\<leadsto> RSEQ r2 r3"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    34
| "r3 h\<leadsto> r4 \<Longrightarrow> RSEQ r1 r3 h\<leadsto> RSEQ r1 r4"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    35
| "r h\<leadsto> r' \<Longrightarrow> (RALTS (rs1 @ [r] @ rs2)) h\<leadsto> (RALTS  (rs1 @ [r'] @ rs2))"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    36
(*context rule for eliminating 0, alts--corresponds to the recursive call flts r::rs = r::(flts rs)*)
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    37
| "RALTS  (rsa @ [RZERO] @ rsb) h\<leadsto> RALTS  (rsa @ rsb)"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    38
| "RALTS  (rsa @ [RALTS rs1] @ rsb) h\<leadsto> RALTS (rsa @ rs1 @ rsb)"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    39
| "RALTS  [] h\<leadsto> RZERO"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    40
| "RALTS  [r] h\<leadsto> r"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    41
| "a1 = a2 \<Longrightarrow> RALTS (rsa@[a1]@rsb@[a2]@rsc) h\<leadsto> RALTS (rsa @ [a1] @ rsb @ rsc)"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    42
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    43
inductive 
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    44
  hrewrites:: "rrexp \<Rightarrow> rrexp \<Rightarrow> bool" ("_ h\<leadsto>* _" [100, 100] 100)
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    45
where 
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    46
  rs1[intro, simp]:"r h\<leadsto>* r"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    47
| rs2[intro]: "\<lbrakk>r1 h\<leadsto>* r2; r2 h\<leadsto> r3\<rbrakk> \<Longrightarrow> r1 h\<leadsto>* r3"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    48
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    49
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    50
lemma hr_in_rstar : "r1 h\<leadsto> r2 \<Longrightarrow> r1 h\<leadsto>* r2"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    51
  using hrewrites.intros(1) hrewrites.intros(2) by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    52
 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    53
lemma hreal_trans[trans]: 
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    54
  assumes a1: "r1 h\<leadsto>* r2"  and a2: "r2 h\<leadsto>* r3"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    55
  shows "r1 h\<leadsto>* r3"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    56
  using a2 a1
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    57
  apply(induct r2 r3 arbitrary: r1 rule: hrewrites.induct) 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    58
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    59
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    60
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    61
lemma  hmany_steps_later: "\<lbrakk>r1 h\<leadsto> r2; r2 h\<leadsto>* r3 \<rbrakk> \<Longrightarrow> r1 h\<leadsto>* r3"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    62
  by (meson hr_in_rstar hreal_trans)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    63
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    64
lemma hrewrites_seq_context:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    65
  shows "r1 h\<leadsto>* r2 \<Longrightarrow> RSEQ r1 r3 h\<leadsto>* RSEQ r2 r3"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    66
  apply(induct r1 r2 rule: hrewrites.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    67
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    68
  using hrewrite.intros(4) by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    69
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    70
lemma hrewrites_seq_context2:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    71
  shows "r1 h\<leadsto>* r2 \<Longrightarrow> RSEQ r0 r1 h\<leadsto>* RSEQ r0 r2"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    72
  apply(induct r1 r2 rule: hrewrites.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    73
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    74
  using hrewrite.intros(5) by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    75
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    76
lemma hrewrites_seq_context0:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    77
  shows "r1 h\<leadsto>* RZERO \<Longrightarrow> RSEQ r1 r3 h\<leadsto>* RZERO"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    78
  apply(subgoal_tac "RSEQ r1 r3 h\<leadsto>* RSEQ RZERO r3")
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    79
  using hrewrite.intros(1) apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    80
  by (simp add: hrewrites_seq_context)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    81
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    82
lemma hrewrites_seq_contexts:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
    83
  shows "\<lbrakk>r1 h\<leadsto>* r2; r3 h\<leadsto>* r4\<rbrakk> \<Longrightarrow> RSEQ r1 r3 h\<leadsto>* RSEQ r2 r4"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    84
  by (meson hreal_trans hrewrites_seq_context hrewrites_seq_context2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    85
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    86
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
    87
453
Chengsong
parents: 451
diff changeset
    88
lemma map_concat_cons:
Chengsong
parents: 451
diff changeset
    89
  shows "map f rsa @ f a # rs = map f (rsa @ [a]) @ rs"
Chengsong
parents: 451
diff changeset
    90
  by simp
Chengsong
parents: 451
diff changeset
    91
Chengsong
parents: 451
diff changeset
    92
lemma neg_removal_element_of:
Chengsong
parents: 451
diff changeset
    93
  shows " \<not> a \<notin> aset \<Longrightarrow> a \<in> aset"
Chengsong
parents: 451
diff changeset
    94
  by simp
Chengsong
parents: 451
diff changeset
    95
465
Chengsong
parents: 456
diff changeset
    96
Chengsong
parents: 456
diff changeset
    97
Chengsong
parents: 456
diff changeset
    98
Chengsong
parents: 456
diff changeset
    99
478
Chengsong
parents: 476
diff changeset
   100
465
Chengsong
parents: 456
diff changeset
   101
Chengsong
parents: 456
diff changeset
   102
478
Chengsong
parents: 476
diff changeset
   103
465
Chengsong
parents: 456
diff changeset
   104
Chengsong
parents: 456
diff changeset
   105
Chengsong
parents: 456
diff changeset
   106
lemma flts_middle01:
Chengsong
parents: 456
diff changeset
   107
  shows "rflts (rsa @ [RZERO] @ rsb) = rflts (rsa @ rsb)"
Chengsong
parents: 456
diff changeset
   108
  by (simp add: flts_middle0)
Chengsong
parents: 456
diff changeset
   109
Chengsong
parents: 456
diff changeset
   110
lemma flts_append1:
Chengsong
parents: 456
diff changeset
   111
  shows "\<lbrakk>a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1; a \<in> set rs\<rbrakk>  \<Longrightarrow>
Chengsong
parents: 456
diff changeset
   112
         rflts (rsa @ [a] @ rsb) = rflts rsa @ [a] @ (rflts rsb)"
Chengsong
parents: 456
diff changeset
   113
  apply(induct rsa arbitrary: rsb)
Chengsong
parents: 456
diff changeset
   114
   apply simp
Chengsong
parents: 456
diff changeset
   115
  using rflts_def_idiot apply presburger
Chengsong
parents: 456
diff changeset
   116
  apply(case_tac aa)  
Chengsong
parents: 456
diff changeset
   117
       apply simp+
Chengsong
parents: 456
diff changeset
   118
  done
Chengsong
parents: 456
diff changeset
   119
478
Chengsong
parents: 476
diff changeset
   120
465
Chengsong
parents: 456
diff changeset
   121
Chengsong
parents: 456
diff changeset
   122
lemma simp_removes_duplicate1:
Chengsong
parents: 456
diff changeset
   123
  shows  " a \<in> set rsa \<Longrightarrow> rsimp (RALTS (rsa @ [a])) =  rsimp (RALTS (rsa))"
Chengsong
parents: 456
diff changeset
   124
and " rsimp (RALTS (a1 # rsa @ [a1])) = rsimp (RALTS (a1 # rsa))"
Chengsong
parents: 456
diff changeset
   125
  apply(induct rsa arbitrary: a1)
Chengsong
parents: 456
diff changeset
   126
     apply simp
Chengsong
parents: 456
diff changeset
   127
    apply simp
Chengsong
parents: 456
diff changeset
   128
  prefer 2
Chengsong
parents: 456
diff changeset
   129
  apply(case_tac "a = aa")
Chengsong
parents: 456
diff changeset
   130
     apply simp
Chengsong
parents: 456
diff changeset
   131
    apply simp
Chengsong
parents: 456
diff changeset
   132
  apply (metis Cons_eq_appendI Cons_eq_map_conv distinct_removes_duplicate_flts list.set_intros(2))
Chengsong
parents: 456
diff changeset
   133
  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
   134
  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
   135
  
Chengsong
parents: 456
diff changeset
   136
lemma simp_removes_duplicate2:
Chengsong
parents: 456
diff changeset
   137
  shows "a \<in> set rsa \<Longrightarrow> rsimp (RALTS (rsa @ [a] @ rsb)) = rsimp (RALTS (rsa @ rsb))"
Chengsong
parents: 456
diff changeset
   138
  apply(induct rsb arbitrary: rsa)
Chengsong
parents: 456
diff changeset
   139
   apply simp
Chengsong
parents: 456
diff changeset
   140
  using distinct_removes_duplicate_flts apply auto[1]
Chengsong
parents: 456
diff changeset
   141
  by (metis append.assoc head_one_more_simp rsimp.simps(2) simp_flatten simp_removes_duplicate1(1))
Chengsong
parents: 456
diff changeset
   142
Chengsong
parents: 456
diff changeset
   143
lemma simp_removes_duplicate3:
Chengsong
parents: 456
diff changeset
   144
  shows "a \<in> set rsa \<Longrightarrow> rsimp (RALTS (rsa @ a # rsb)) = rsimp (RALTS (rsa @ rsb))"
Chengsong
parents: 456
diff changeset
   145
  using simp_removes_duplicate2 by auto
Chengsong
parents: 456
diff changeset
   146
Chengsong
parents: 456
diff changeset
   147
lemma distinct_removes_middle4:
Chengsong
parents: 456
diff changeset
   148
  shows "a \<in> set rsa \<Longrightarrow> rdistinct (rsa @ [a] @ rsb) rset = rdistinct (rsa @ rsb) rset"
Chengsong
parents: 456
diff changeset
   149
  using distinct_removes_middle(1) by fastforce
Chengsong
parents: 456
diff changeset
   150
Chengsong
parents: 456
diff changeset
   151
lemma distinct_removes_middle_list:
Chengsong
parents: 456
diff changeset
   152
  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
   153
  apply(induct x)
Chengsong
parents: 456
diff changeset
   154
   apply simp
Chengsong
parents: 456
diff changeset
   155
  by (simp add: distinct_removes_middle3)
Chengsong
parents: 456
diff changeset
   156
Chengsong
parents: 456
diff changeset
   157
Chengsong
parents: 456
diff changeset
   158
lemma distinct_removes_duplicate_flts2:
Chengsong
parents: 456
diff changeset
   159
  shows " a \<in> set rsa
Chengsong
parents: 456
diff changeset
   160
       \<Longrightarrow> rdistinct (rflts (rsa @ [a] @ rsb)) {} =
Chengsong
parents: 456
diff changeset
   161
           rdistinct (rflts (rsa @ rsb)) {}"
Chengsong
parents: 456
diff changeset
   162
  apply(induct a arbitrary: rsb)
Chengsong
parents: 456
diff changeset
   163
  using flts_middle01 apply presburger
Chengsong
parents: 456
diff changeset
   164
      apply(subgoal_tac "rflts (rsa @ [RONE] @ rsb) = rflts rsa @ [RONE] @ rflts rsb")
Chengsong
parents: 456
diff changeset
   165
  prefer 2
Chengsong
parents: 456
diff changeset
   166
  using flts_append1 apply blast
Chengsong
parents: 456
diff changeset
   167
      apply simp
Chengsong
parents: 456
diff changeset
   168
      apply(subgoal_tac "RONE \<in> set (rflts rsa)")
Chengsong
parents: 456
diff changeset
   169
  prefer 2
Chengsong
parents: 456
diff changeset
   170
  using rflts_def_idiot2 apply blast
Chengsong
parents: 456
diff changeset
   171
      apply(subst distinct_removes_middle3)
Chengsong
parents: 456
diff changeset
   172
       apply simp
Chengsong
parents: 456
diff changeset
   173
  using flts_append apply presburger
Chengsong
parents: 456
diff changeset
   174
     apply simp
Chengsong
parents: 456
diff changeset
   175
  apply (metis distinct_removes_middle3 flts_append in_set_conv_decomp rflts.simps(5))
Chengsong
parents: 456
diff changeset
   176
  apply (metis distinct_removes_middle(1) flts_append flts_append1 rflts_def_idiot2 rrexp.distinct(25) rrexp.distinct(5))
Chengsong
parents: 456
diff changeset
   177
   apply(subgoal_tac "rflts (rsa @ [RALTS x] @ rsb) = rflts rsa @ x @ rflts rsb")
Chengsong
parents: 456
diff changeset
   178
    prefer 2
Chengsong
parents: 456
diff changeset
   179
  apply (simp add: flts_append)
Chengsong
parents: 456
diff changeset
   180
   apply (simp only:)
Chengsong
parents: 456
diff changeset
   181
Chengsong
parents: 456
diff changeset
   182
   apply(subgoal_tac "\<forall>r1 \<in> set x. r1 \<in> set (rflts rsa)")
Chengsong
parents: 456
diff changeset
   183
    prefer 2
Chengsong
parents: 456
diff changeset
   184
  using spilled_alts_contained apply blast
Chengsong
parents: 456
diff changeset
   185
  apply(subst flts_append)
Chengsong
parents: 456
diff changeset
   186
  using distinct_removes_middle_list apply blast
Chengsong
parents: 456
diff changeset
   187
  using distinct_removes_middle2 flts_append rflts_def_idiot2 by fastforce
Chengsong
parents: 456
diff changeset
   188
Chengsong
parents: 456
diff changeset
   189
Chengsong
parents: 456
diff changeset
   190
lemma simp_removes_duplicate:
Chengsong
parents: 456
diff changeset
   191
  shows "a \<in> set rsa \<Longrightarrow> rsimp (rsimp_ALTs (rsa @ a # rs)) =  rsimp (rsimp_ALTs (rsa @ rs))"
Chengsong
parents: 456
diff changeset
   192
  apply(subgoal_tac "rsimp (rsimp_ALTs (rsa @ a # rs)) = rsimp (RALTS (rsa @ a # rs))")
Chengsong
parents: 456
diff changeset
   193
   prefer 2
Chengsong
parents: 456
diff changeset
   194
  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
   195
  apply(simp only:)
Chengsong
parents: 456
diff changeset
   196
  apply simp
Chengsong
parents: 456
diff changeset
   197
  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
   198
   apply(simp only:)
Chengsong
parents: 456
diff changeset
   199
  prefer 2
Chengsong
parents: 456
diff changeset
   200
   apply(subgoal_tac "rsimp a \<in> set (map rsimp rsa)")
Chengsong
parents: 456
diff changeset
   201
    prefer 2
Chengsong
parents: 456
diff changeset
   202
  apply simp
Chengsong
parents: 456
diff changeset
   203
  using distinct_removes_duplicate_flts2 apply force
Chengsong
parents: 456
diff changeset
   204
  apply(case_tac rsa)
Chengsong
parents: 456
diff changeset
   205
   apply simp
Chengsong
parents: 456
diff changeset
   206
  apply(case_tac rs)
Chengsong
parents: 456
diff changeset
   207
   apply simp
Chengsong
parents: 456
diff changeset
   208
   apply(case_tac list)
Chengsong
parents: 456
diff changeset
   209
    apply simp
Chengsong
parents: 456
diff changeset
   210
  using idem_after_simp1 apply presburger
Chengsong
parents: 456
diff changeset
   211
   apply simp+
Chengsong
parents: 456
diff changeset
   212
  apply(subgoal_tac "rsimp_ALTs (aa # list @ aaa # lista) = RALTS (aa # list @ aaa # lista)")
Chengsong
parents: 456
diff changeset
   213
   apply simp
Chengsong
parents: 456
diff changeset
   214
  using rsimpalts_conscons by presburger
467
Chengsong
parents: 465
diff changeset
   215
Chengsong
parents: 465
diff changeset
   216
Chengsong
parents: 465
diff changeset
   217
Chengsong
parents: 465
diff changeset
   218
468
a0f27e21b42c all texrelated
Chengsong
parents: 467
diff changeset
   219
467
Chengsong
parents: 465
diff changeset
   220
Chengsong
parents: 465
diff changeset
   221
471
Chengsong
parents: 469
diff changeset
   222
Chengsong
parents: 469
diff changeset
   223
inductive frewrite:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>f _" [10, 10] 10)
Chengsong
parents: 469
diff changeset
   224
  where
Chengsong
parents: 469
diff changeset
   225
  "(RZERO # rs) \<leadsto>f rs"
Chengsong
parents: 469
diff changeset
   226
| "((RALTS rs) # rsa) \<leadsto>f (rs @ rsa)"
Chengsong
parents: 469
diff changeset
   227
| "rs1 \<leadsto>f rs2 \<Longrightarrow> (r # rs1) \<leadsto>f (r # rs2)"
Chengsong
parents: 469
diff changeset
   228
Chengsong
parents: 469
diff changeset
   229
Chengsong
parents: 469
diff changeset
   230
inductive 
Chengsong
parents: 469
diff changeset
   231
  frewrites:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>f* _" [10, 10] 10)
Chengsong
parents: 469
diff changeset
   232
where 
473
Chengsong
parents: 472
diff changeset
   233
  [intro, simp]:"rs \<leadsto>f* rs"
Chengsong
parents: 472
diff changeset
   234
| [intro]: "\<lbrakk>rs1 \<leadsto>f* rs2; rs2 \<leadsto>f rs3\<rbrakk> \<Longrightarrow> rs1 \<leadsto>f* rs3"
Chengsong
parents: 472
diff changeset
   235
Chengsong
parents: 472
diff changeset
   236
inductive grewrite:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>g _" [10, 10] 10)
Chengsong
parents: 472
diff changeset
   237
  where
Chengsong
parents: 472
diff changeset
   238
  "(RZERO # rs) \<leadsto>g rs"
Chengsong
parents: 472
diff changeset
   239
| "((RALTS rs) # rsa) \<leadsto>g (rs @ rsa)"
Chengsong
parents: 472
diff changeset
   240
| "rs1 \<leadsto>g rs2 \<Longrightarrow> (r # rs1) \<leadsto>g (r # rs2)"
Chengsong
parents: 472
diff changeset
   241
| "rsa @ [a] @ rsb @ [a] @ rsc \<leadsto>g rsa @ [a] @ rsb @ rsc" 
Chengsong
parents: 472
diff changeset
   242
478
Chengsong
parents: 476
diff changeset
   243
lemma grewrite_variant1:
Chengsong
parents: 476
diff changeset
   244
  shows "a \<in> set rs1 \<Longrightarrow> rs1 @ a # rs \<leadsto>g rs1 @ rs"
Chengsong
parents: 476
diff changeset
   245
  apply (metis append.assoc append_Cons append_Nil grewrite.intros(4) split_list_first)
Chengsong
parents: 476
diff changeset
   246
  done
Chengsong
parents: 476
diff changeset
   247
473
Chengsong
parents: 472
diff changeset
   248
Chengsong
parents: 472
diff changeset
   249
inductive 
Chengsong
parents: 472
diff changeset
   250
  grewrites:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>g* _" [10, 10] 10)
Chengsong
parents: 472
diff changeset
   251
where 
Chengsong
parents: 472
diff changeset
   252
  [intro, simp]:"rs \<leadsto>g* rs"
Chengsong
parents: 472
diff changeset
   253
| [intro]: "\<lbrakk>rs1 \<leadsto>g* rs2; rs2 \<leadsto>g rs3\<rbrakk> \<Longrightarrow> rs1 \<leadsto>g* rs3"
478
Chengsong
parents: 476
diff changeset
   254
Chengsong
parents: 476
diff changeset
   255
Chengsong
parents: 476
diff changeset
   256
473
Chengsong
parents: 472
diff changeset
   257
(*
Chengsong
parents: 472
diff changeset
   258
inductive 
Chengsong
parents: 472
diff changeset
   259
  frewrites2:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ <\<leadsto>f* _" [10, 10] 10)
Chengsong
parents: 472
diff changeset
   260
where 
Chengsong
parents: 472
diff changeset
   261
 [intro]: "\<lbrakk>rs1 \<leadsto>f* rs2; rs2 \<leadsto>f* rs1\<rbrakk> \<Longrightarrow> rs1 <\<leadsto>f* rs2"
Chengsong
parents: 472
diff changeset
   262
*)
471
Chengsong
parents: 469
diff changeset
   263
Chengsong
parents: 469
diff changeset
   264
lemma fr_in_rstar : "r1 \<leadsto>f r2 \<Longrightarrow> r1 \<leadsto>f* r2"
Chengsong
parents: 469
diff changeset
   265
  using frewrites.intros(1) frewrites.intros(2) by blast
Chengsong
parents: 469
diff changeset
   266
 
Chengsong
parents: 469
diff changeset
   267
lemma freal_trans[trans]: 
Chengsong
parents: 469
diff changeset
   268
  assumes a1: "r1 \<leadsto>f* r2"  and a2: "r2 \<leadsto>f* r3"
Chengsong
parents: 469
diff changeset
   269
  shows "r1 \<leadsto>f* r3"
Chengsong
parents: 469
diff changeset
   270
  using a2 a1
Chengsong
parents: 469
diff changeset
   271
  apply(induct r2 r3 arbitrary: r1 rule: frewrites.induct) 
Chengsong
parents: 469
diff changeset
   272
  apply(auto)
Chengsong
parents: 469
diff changeset
   273
  done
Chengsong
parents: 469
diff changeset
   274
Chengsong
parents: 469
diff changeset
   275
Chengsong
parents: 469
diff changeset
   276
lemma  many_steps_later: "\<lbrakk>r1 \<leadsto>f r2; r2 \<leadsto>f* r3 \<rbrakk> \<Longrightarrow> r1 \<leadsto>f* r3"
Chengsong
parents: 469
diff changeset
   277
  by (meson fr_in_rstar freal_trans)
Chengsong
parents: 469
diff changeset
   278
Chengsong
parents: 469
diff changeset
   279
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   280
lemma gr_in_rstar : "r1 \<leadsto>g r2 \<Longrightarrow> r1 \<leadsto>g* r2"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   281
  using grewrites.intros(1) grewrites.intros(2) by blast
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   282
 
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   283
lemma greal_trans[trans]: 
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   284
  assumes a1: "r1 \<leadsto>g* r2"  and a2: "r2 \<leadsto>g* r3"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   285
  shows "r1 \<leadsto>g* r3"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   286
  using a2 a1
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   287
  apply(induct r2 r3 arbitrary: r1 rule: grewrites.induct) 
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   288
  apply(auto)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   289
  done
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   290
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   291
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   292
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
   293
  by (meson gr_in_rstar greal_trans)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   294
478
Chengsong
parents: 476
diff changeset
   295
lemma gstar_rdistinct_general:
Chengsong
parents: 476
diff changeset
   296
  shows "rs1 @  rs \<leadsto>g* rs1 @ (rdistinct rs (set rs1))"
Chengsong
parents: 476
diff changeset
   297
  apply(induct rs arbitrary: rs1)
Chengsong
parents: 476
diff changeset
   298
   apply simp
Chengsong
parents: 476
diff changeset
   299
  apply(case_tac " a \<in> set rs1")
Chengsong
parents: 476
diff changeset
   300
   apply simp
Chengsong
parents: 476
diff changeset
   301
  apply(subgoal_tac "rs1 @ a # rs \<leadsto>g rs1 @ rs")
Chengsong
parents: 476
diff changeset
   302
  using gmany_steps_later apply auto[1]
Chengsong
parents: 476
diff changeset
   303
  apply (metis append.assoc append_Cons append_Nil grewrite.intros(4) split_list_first)
Chengsong
parents: 476
diff changeset
   304
  apply simp
Chengsong
parents: 476
diff changeset
   305
  apply(drule_tac x = "rs1 @ [a]" in meta_spec)
Chengsong
parents: 476
diff changeset
   306
  by simp
Chengsong
parents: 476
diff changeset
   307
Chengsong
parents: 476
diff changeset
   308
Chengsong
parents: 476
diff changeset
   309
lemma gstar_rdistinct:
Chengsong
parents: 476
diff changeset
   310
  shows "rs \<leadsto>g* rdistinct rs {}"
Chengsong
parents: 476
diff changeset
   311
  apply(induct rs)
Chengsong
parents: 476
diff changeset
   312
   apply simp
Chengsong
parents: 476
diff changeset
   313
  by (metis append.left_neutral empty_set gstar_rdistinct_general)
Chengsong
parents: 476
diff changeset
   314
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   315
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   316
471
Chengsong
parents: 469
diff changeset
   317
lemma frewrite_append:
Chengsong
parents: 469
diff changeset
   318
  shows "\<lbrakk> rsa \<leadsto>f rsb \<rbrakk> \<Longrightarrow> rs @ rsa \<leadsto>f rs @ rsb"
Chengsong
parents: 469
diff changeset
   319
  apply(induct rs)
472
Chengsong
parents: 471
diff changeset
   320
   apply simp+
Chengsong
parents: 471
diff changeset
   321
  using frewrite.intros(3) by blast
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   322
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   323
lemma grewrite_append:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   324
  shows "\<lbrakk> rsa \<leadsto>g rsb \<rbrakk> \<Longrightarrow> rs @ rsa \<leadsto>g rs @ rsb"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   325
  apply(induct rs)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   326
   apply simp+
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   327
  using grewrite.intros(3) by blast
472
Chengsong
parents: 471
diff changeset
   328
  
471
Chengsong
parents: 469
diff changeset
   329
Chengsong
parents: 469
diff changeset
   330
Chengsong
parents: 469
diff changeset
   331
lemma frewrites_cons:
Chengsong
parents: 469
diff changeset
   332
  shows "\<lbrakk> rsa \<leadsto>f* rsb \<rbrakk> \<Longrightarrow> r # rsa \<leadsto>f* r # rsb"
472
Chengsong
parents: 471
diff changeset
   333
  apply(induct rsa rsb rule: frewrites.induct)
Chengsong
parents: 471
diff changeset
   334
   apply simp
Chengsong
parents: 471
diff changeset
   335
  using frewrite.intros(3) by blast
471
Chengsong
parents: 469
diff changeset
   336
Chengsong
parents: 469
diff changeset
   337
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   338
lemma grewrites_cons:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   339
  shows "\<lbrakk> rsa \<leadsto>g* rsb \<rbrakk> \<Longrightarrow> r # rsa \<leadsto>g* r # rsb"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   340
  apply(induct rsa rsb rule: grewrites.induct)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   341
   apply simp
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   342
  using grewrite.intros(3) by blast
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   343
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   344
471
Chengsong
parents: 469
diff changeset
   345
lemma frewrites_append:
Chengsong
parents: 469
diff changeset
   346
  shows " \<lbrakk>rsa \<leadsto>f* rsb\<rbrakk> \<Longrightarrow> (rs @ rsa) \<leadsto>f* (rs @ rsb)"
472
Chengsong
parents: 471
diff changeset
   347
  apply(induct rs)
471
Chengsong
parents: 469
diff changeset
   348
   apply simp
472
Chengsong
parents: 471
diff changeset
   349
  by (simp add: frewrites_cons)
471
Chengsong
parents: 469
diff changeset
   350
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   351
lemma grewrites_append:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   352
  shows " \<lbrakk>rsa \<leadsto>g* rsb\<rbrakk> \<Longrightarrow> (rs @ rsa) \<leadsto>g* (rs @ rsb)"
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   353
  apply(induct rs)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   354
   apply simp
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   355
  by (simp add: grewrites_cons)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   356
471
Chengsong
parents: 469
diff changeset
   357
Chengsong
parents: 469
diff changeset
   358
Chengsong
parents: 469
diff changeset
   359
lemma frewrites_concat:
Chengsong
parents: 469
diff changeset
   360
  shows "\<lbrakk>rs1 \<leadsto>f rs2; rsa \<leadsto>f* rsb \<rbrakk> \<Longrightarrow> (rs1 @ rsa) \<leadsto>f* (rs2 @ rsb)"
Chengsong
parents: 469
diff changeset
   361
  apply(induct rs1 rs2 rule: frewrite.induct)
Chengsong
parents: 469
diff changeset
   362
    apply(simp)
Chengsong
parents: 469
diff changeset
   363
  apply(subgoal_tac "(RZERO # rs @ rsa) \<leadsto>f (rs @ rsa)")
Chengsong
parents: 469
diff changeset
   364
  prefer 2
Chengsong
parents: 469
diff changeset
   365
  using frewrite.intros(1) apply blast
Chengsong
parents: 469
diff changeset
   366
    apply(subgoal_tac "(rs @ rsa) \<leadsto>f* (rs @ rsb)")
Chengsong
parents: 469
diff changeset
   367
  using many_steps_later apply blast
472
Chengsong
parents: 471
diff changeset
   368
  apply (simp add: frewrites_append)
Chengsong
parents: 471
diff changeset
   369
  apply (metis append.assoc append_Cons frewrite.intros(2) frewrites_append many_steps_later)
Chengsong
parents: 471
diff changeset
   370
  using frewrites_cons by auto
471
Chengsong
parents: 469
diff changeset
   371
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   372
lemma grewrites_concat:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   373
  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
   374
  apply(induct rs1 rs2 rule: grewrite.induct)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   375
    apply(simp)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   376
  apply(subgoal_tac "(RZERO # rs @ rsa) \<leadsto>g (rs @ rsa)")
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   377
  prefer 2
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   378
  using grewrite.intros(1) apply blast
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   379
    apply(subgoal_tac "(rs @ rsa) \<leadsto>g* (rs @ rsb)")
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   380
  using gmany_steps_later apply blast
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   381
  apply (simp add: grewrites_append)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   382
  apply (metis append.assoc append_Cons grewrite.intros(2) grewrites_append gmany_steps_later)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   383
  using grewrites_cons apply auto
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   384
  apply(subgoal_tac "rsaa @ a # rsba @ a # rsc @ rsa \<leadsto>g* rsaa @ a # rsba @ a # rsc @ rsb")
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   385
  using grewrite.intros(4) grewrites.intros(2) apply force
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   386
  using grewrites_append by auto
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   387
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   388
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   389
lemma grewritess_concat:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   390
  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
   391
  apply(induct rsa rsb rule: grewrites.induct)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   392
   apply(case_tac rs)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   393
    apply simp
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   394
  using grewrites_append apply blast   
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   395
  by (meson greal_trans grewrites.simps grewrites_concat)
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   396
476
Chengsong
parents: 475
diff changeset
   397
fun alt_set:: "rrexp \<Rightarrow> rrexp set"
Chengsong
parents: 475
diff changeset
   398
  where
Chengsong
parents: 475
diff changeset
   399
  "alt_set (RALTS rs) = set rs \<union> \<Union> (alt_set ` (set rs))"
Chengsong
parents: 475
diff changeset
   400
| "alt_set r = {r}"
Chengsong
parents: 475
diff changeset
   401
Chengsong
parents: 475
diff changeset
   402
lemma alt_set_has_all:
Chengsong
parents: 475
diff changeset
   403
  shows "RALTS rs \<in> alt_set rx \<Longrightarrow> set rs \<subseteq> alt_set rx"
Chengsong
parents: 475
diff changeset
   404
  apply(induct rx arbitrary: rs)
Chengsong
parents: 475
diff changeset
   405
       apply simp_all
Chengsong
parents: 475
diff changeset
   406
  apply(rename_tac rSS rss)
Chengsong
parents: 475
diff changeset
   407
  using in_mono by fastforce
Chengsong
parents: 475
diff changeset
   408
Chengsong
parents: 475
diff changeset
   409
Chengsong
parents: 475
diff changeset
   410
Chengsong
parents: 475
diff changeset
   411
Chengsong
parents: 475
diff changeset
   412
478
Chengsong
parents: 476
diff changeset
   413
lemma grewrite_cases_middle:
Chengsong
parents: 476
diff changeset
   414
  shows "rs1 \<leadsto>g rs2 \<Longrightarrow> 
Chengsong
parents: 476
diff changeset
   415
(\<exists>rsa rsb rsc. rs1 =  (rsa @ [RALTS rsb] @ rsc) \<and> rs2 = (rsa @ rsb @ rsc)) \<or>
Chengsong
parents: 476
diff changeset
   416
(\<exists>rsa rsc. rs1 = rsa @ [RZERO] @ rsc \<and> rs2 = rsa @ rsc) \<or>
Chengsong
parents: 476
diff changeset
   417
(\<exists>rsa rsb rsc a. rs1 = rsa @ [a] @ rsb @ [a] @ rsc \<and> rs2 = rsa @ [a] @ rsb @ rsc)"
Chengsong
parents: 476
diff changeset
   418
  apply( induct rs1 rs2 rule: grewrite.induct)
Chengsong
parents: 476
diff changeset
   419
     apply simp
Chengsong
parents: 476
diff changeset
   420
  apply blast
Chengsong
parents: 476
diff changeset
   421
  apply (metis append_Cons append_Nil)
Chengsong
parents: 476
diff changeset
   422
  apply (metis append_Cons)
Chengsong
parents: 476
diff changeset
   423
  by blast
476
Chengsong
parents: 475
diff changeset
   424
Chengsong
parents: 475
diff changeset
   425
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   426
lemma good_singleton:
64183736777a almost there
Chengsong
parents: 489
diff changeset
   427
  shows "good a \<and> nonalt a  \<Longrightarrow> rflts [a] = [a]"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   428
  using good.simps(1) k0b by blast
64183736777a almost there
Chengsong
parents: 489
diff changeset
   429
64183736777a almost there
Chengsong
parents: 489
diff changeset
   430
64183736777a almost there
Chengsong
parents: 489
diff changeset
   431
64183736777a almost there
Chengsong
parents: 489
diff changeset
   432
64183736777a almost there
Chengsong
parents: 489
diff changeset
   433
64183736777a almost there
Chengsong
parents: 489
diff changeset
   434
64183736777a almost there
Chengsong
parents: 489
diff changeset
   435
64183736777a almost there
Chengsong
parents: 489
diff changeset
   436
lemma all_that_same_elem:
64183736777a almost there
Chengsong
parents: 489
diff changeset
   437
  shows "\<lbrakk> a \<in> rset; rdistinct rs {a} = []\<rbrakk>
64183736777a almost there
Chengsong
parents: 489
diff changeset
   438
       \<Longrightarrow> rdistinct (rs @ rsb) rset = rdistinct rsb rset"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   439
  apply(induct rs)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   440
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   441
  apply(subgoal_tac "aa = a")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   442
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   443
  by (metis empty_iff insert_iff list.discI rdistinct.simps(2))
64183736777a almost there
Chengsong
parents: 489
diff changeset
   444
64183736777a almost there
Chengsong
parents: 489
diff changeset
   445
lemma distinct_early_app1:
64183736777a almost there
Chengsong
parents: 489
diff changeset
   446
  shows "rset1 \<subseteq> rset \<Longrightarrow> rdistinct rs rset = rdistinct (rdistinct rs rset1) rset"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   447
  apply(induct rs arbitrary: rset rset1)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   448
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   449
  apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   450
  apply(case_tac "a \<in> rset1")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   451
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   452
   apply(case_tac "a \<in> rset")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   453
    apply simp+
64183736777a almost there
Chengsong
parents: 489
diff changeset
   454
  
64183736777a almost there
Chengsong
parents: 489
diff changeset
   455
   apply blast
64183736777a almost there
Chengsong
parents: 489
diff changeset
   456
  apply(case_tac "a \<in> rset1")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   457
   apply simp+
64183736777a almost there
Chengsong
parents: 489
diff changeset
   458
  apply(case_tac "a \<in> rset")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   459
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   460
   apply (metis insert_subsetI)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   461
  apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   462
  by (meson insert_mono)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   463
64183736777a almost there
Chengsong
parents: 489
diff changeset
   464
64183736777a almost there
Chengsong
parents: 489
diff changeset
   465
lemma distinct_early_app:
64183736777a almost there
Chengsong
parents: 489
diff changeset
   466
  shows " rdistinct (rs @ rsb) rset = rdistinct (rdistinct rs {} @ rsb) rset"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   467
  apply(induct rsb)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   468
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   469
  using distinct_early_app1 apply blast
64183736777a almost there
Chengsong
parents: 489
diff changeset
   470
  by (metis distinct_early_app1 distinct_once_enough empty_subsetI)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   471
64183736777a almost there
Chengsong
parents: 489
diff changeset
   472
64183736777a almost there
Chengsong
parents: 489
diff changeset
   473
lemma distinct_eq_interesting1:
64183736777a almost there
Chengsong
parents: 489
diff changeset
   474
  shows "a \<in> rset \<Longrightarrow> rdistinct (rs @ rsb) rset = rdistinct (rdistinct (a # rs) {} @ rsb) rset"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   475
  apply(subgoal_tac "rdistinct (rdistinct (a # rs) {} @ rsb) rset = rdistinct (rdistinct rs {} @ rsb) rset")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   476
   apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   477
  using distinct_early_app apply blast 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   478
  by (metis append_Cons distinct_early_app rdistinct.simps(2))
64183736777a almost there
Chengsong
parents: 489
diff changeset
   479
64183736777a almost there
Chengsong
parents: 489
diff changeset
   480
64183736777a almost there
Chengsong
parents: 489
diff changeset
   481
64183736777a almost there
Chengsong
parents: 489
diff changeset
   482
lemma good_flatten_aux_aux1:
64183736777a almost there
Chengsong
parents: 489
diff changeset
   483
  shows "\<lbrakk> size rs \<ge>2; 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   484
\<forall>r \<in> set rs. good r \<and> r \<noteq> RZERO \<and> nonalt r; \<forall>r \<in> set rsb. good r \<and> r \<noteq> RZERO \<and> nonalt r \<rbrakk>
64183736777a almost there
Chengsong
parents: 489
diff changeset
   485
       \<Longrightarrow> rdistinct (rs @ rsb) rset =
64183736777a almost there
Chengsong
parents: 489
diff changeset
   486
           rdistinct (rflts [rsimp_ALTs (rdistinct rs {})] @ rsb) rset"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   487
  apply(induct rs arbitrary: rset)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   488
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   489
  apply(case_tac "a \<in> rset")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   490
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   491
   apply(case_tac "rdistinct rs {a}")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   492
    apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   493
    apply(subst good_singleton)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   494
     apply force
64183736777a almost there
Chengsong
parents: 489
diff changeset
   495
  apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   496
    apply (meson all_that_same_elem)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   497
   apply(subgoal_tac "rflts [rsimp_ALTs (a # rdistinct rs {a})] = a # rdistinct rs {a} ")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   498
  prefer 2
64183736777a almost there
Chengsong
parents: 489
diff changeset
   499
  using k0a rsimp_ALTs.simps(3) apply presburger
64183736777a almost there
Chengsong
parents: 489
diff changeset
   500
  apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   501
  apply(subgoal_tac "rdistinct (rs @ rsb) rset = rdistinct ((rdistinct (a # rs) {}) @ rsb) rset ")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   502
    apply (metis insert_absorb insert_is_Un insert_not_empty rdistinct.simps(2))
64183736777a almost there
Chengsong
parents: 489
diff changeset
   503
   apply (meson distinct_eq_interesting1)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   504
  apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   505
  apply(case_tac "rdistinct rs {a}")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   506
  prefer 2
64183736777a almost there
Chengsong
parents: 489
diff changeset
   507
   apply(subgoal_tac "rsimp_ALTs (a # rdistinct rs {a}) = RALTS (a # rdistinct rs {a})")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   508
  apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   509
  apply(subgoal_tac "a # rdistinct (rs @ rsb) (insert a rset) =
64183736777a almost there
Chengsong
parents: 489
diff changeset
   510
           rdistinct (rflts [RALTS (a # rdistinct rs {a})] @ rsb) rset")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   511
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   512
  apply (metis append_Cons distinct_early_app empty_iff insert_is_Un k0a rdistinct.simps(2))
64183736777a almost there
Chengsong
parents: 489
diff changeset
   513
  using rsimp_ALTs.simps(3) apply presburger
64183736777a almost there
Chengsong
parents: 489
diff changeset
   514
  by (metis Un_insert_left append_Cons distinct_early_app empty_iff good_singleton rdistinct.simps(2) rsimp_ALTs.simps(2) sup_bot_left)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   515
64183736777a almost there
Chengsong
parents: 489
diff changeset
   516
64183736777a almost there
Chengsong
parents: 489
diff changeset
   517
64183736777a almost there
Chengsong
parents: 489
diff changeset
   518
  
64183736777a almost there
Chengsong
parents: 489
diff changeset
   519
64183736777a almost there
Chengsong
parents: 489
diff changeset
   520
lemma good_flatten_aux_aux:
64183736777a almost there
Chengsong
parents: 489
diff changeset
   521
  shows "\<lbrakk>\<exists>a aa lista list. rs = a # list \<and> list = aa # lista; 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   522
\<forall>r \<in> set rs. good r \<and> r \<noteq> RZERO \<and> nonalt r; \<forall>r \<in> set rsb. good r \<and> r \<noteq> RZERO \<and> nonalt r \<rbrakk>
64183736777a almost there
Chengsong
parents: 489
diff changeset
   523
       \<Longrightarrow> rdistinct (rs @ rsb) rset =
64183736777a almost there
Chengsong
parents: 489
diff changeset
   524
           rdistinct (rflts [rsimp_ALTs (rdistinct rs {})] @ rsb) rset"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   525
  apply(erule exE)+
64183736777a almost there
Chengsong
parents: 489
diff changeset
   526
  apply(subgoal_tac "size rs \<ge> 2")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   527
   apply (metis good_flatten_aux_aux1)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   528
  by (simp add: Suc_leI length_Cons less_add_Suc1)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   529
64183736777a almost there
Chengsong
parents: 489
diff changeset
   530
64183736777a almost there
Chengsong
parents: 489
diff changeset
   531
64183736777a almost there
Chengsong
parents: 489
diff changeset
   532
lemma good_flatten_aux:
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   533
  shows " \<lbrakk>\<forall>r\<in>set rs. good r \<or> r = RZERO; \<forall>r\<in>set rsa . good r \<or> r = RZERO; 
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   534
           \<forall>r\<in>set rsb. good r \<or> r = RZERO;
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   535
     rsimp (RALTS (rsa @ rs @ rsb)) = rsimp_ALTs (rdistinct (rflts (rsa @ rs @ rsb)) {});
64183736777a almost there
Chengsong
parents: 489
diff changeset
   536
     rsimp (RALTS (rsa @ [RALTS rs] @ rsb)) =
64183736777a almost there
Chengsong
parents: 489
diff changeset
   537
     rsimp_ALTs (rdistinct (rflts (rsa @ [rsimp (RALTS rs)] @ rsb)) {});
64183736777a almost there
Chengsong
parents: 489
diff changeset
   538
     map rsimp rsa = rsa; map rsimp rsb = rsb; map rsimp rs = rs;
64183736777a almost there
Chengsong
parents: 489
diff changeset
   539
     rdistinct (rflts rsa @ rflts rs @ rflts rsb) {} =
64183736777a almost there
Chengsong
parents: 489
diff changeset
   540
     rdistinct (rflts rsa) {} @ rdistinct (rflts rs @ rflts rsb) (set (rflts rsa));
64183736777a almost there
Chengsong
parents: 489
diff changeset
   541
     rdistinct (rflts rsa @ rflts [rsimp (RALTS rs)] @ rflts rsb) {} =
64183736777a almost there
Chengsong
parents: 489
diff changeset
   542
     rdistinct (rflts rsa) {} @ rdistinct (rflts [rsimp (RALTS rs)] @ rflts rsb) (set (rflts rsa))\<rbrakk>
64183736777a almost there
Chengsong
parents: 489
diff changeset
   543
    \<Longrightarrow>    rdistinct (rflts rs @ rflts rsb) rset =
64183736777a almost there
Chengsong
parents: 489
diff changeset
   544
           rdistinct (rflts [rsimp (RALTS rs)] @ rflts rsb) rset"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   545
  apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   546
  apply(case_tac "rflts rs ")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   547
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   548
  apply(case_tac "list")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   549
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   550
   apply(case_tac "a \<in> rset")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   551
    apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   552
  apply (metis append_Cons append_Nil flts_append list.set(1) list.simps(15) nonalt.simps(1) nonalt0_flts_keeps nonalt_flts_rd qqq1 rdistinct.simps(2) rdistinct_set_equality singleton_iff)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   553
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   554
  apply (metis Un_insert_left append_Cons append_Nil ex_in_conv flts_single1 insertI1 list.simps(15) nonalt_flts_rd nonazero.elims(3) qqq1 rdistinct.simps(2) sup_bot_left)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   555
  apply(subgoal_tac "\<forall>r \<in> set (rflts rs). good r \<and> r \<noteq> RZERO \<and> nonalt r")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   556
  prefer 2  
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   557
  apply (metis flts3 nonalt_flts_rd qqq1 rdistinct_set_equality)
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   558
  apply(subgoal_tac "\<forall>r \<in> set (rflts rsb). good r \<and> r \<noteq> RZERO \<and> nonalt r")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   559
  prefer 2  
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   560
  apply (metis flts3 nonalt_flts_rd qqq1 rdistinct_set_equality)
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   561
  by (smt (verit, ccfv_threshold) good_flatten_aux_aux)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   562
64183736777a almost there
Chengsong
parents: 489
diff changeset
   563
  
64183736777a almost there
Chengsong
parents: 489
diff changeset
   564
64183736777a almost there
Chengsong
parents: 489
diff changeset
   565
64183736777a almost there
Chengsong
parents: 489
diff changeset
   566
lemma good_flatten_middle:
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   567
  shows "\<lbrakk>\<forall>r \<in> set rs. good r \<or> r = RZERO; \<forall>r \<in> set rsa. good r \<or> r = RZERO; \<forall>r \<in> set rsb. good r \<or> r = RZERO\<rbrakk> \<Longrightarrow>
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   568
rsimp (RALTS (rsa @ rs @ rsb)) = rsimp (RALTS (rsa @ [RALTS rs] @ rsb))"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   569
  apply(subgoal_tac "rsimp (RALTS (rsa @ rs @ rsb)) = rsimp_ALTs (rdistinct (rflts (map rsimp rsa @ 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   570
map rsimp rs @ map rsimp rsb)) {})")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   571
  prefer 2
64183736777a almost there
Chengsong
parents: 489
diff changeset
   572
  apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   573
  apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   574
    apply(subgoal_tac "rsimp (RALTS (rsa @ [RALTS rs] @ rsb)) = rsimp_ALTs (rdistinct (rflts (map rsimp rsa @ 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   575
[rsimp (RALTS rs)] @ map rsimp rsb)) {})")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   576
  prefer 2
64183736777a almost there
Chengsong
parents: 489
diff changeset
   577
   apply simp
64183736777a almost there
Chengsong
parents: 489
diff changeset
   578
  apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   579
  apply(subgoal_tac "map rsimp rsa = rsa")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   580
  prefer 2
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   581
  apply (metis map_idI rsimp.simps(3) test)
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   582
  apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   583
  apply(subgoal_tac "map rsimp rsb = rsb")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   584
   prefer 2
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   585
  apply (metis map_idI rsimp.simps(3) test)
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   586
  apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   587
  apply(subst k00)+
64183736777a almost there
Chengsong
parents: 489
diff changeset
   588
  apply(subgoal_tac "map rsimp rs = rs")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   589
   apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   590
   prefer 2
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   591
  apply (metis map_idI rsimp.simps(3) test)
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   592
  apply(subgoal_tac "rdistinct (rflts rsa @ rflts rs @ rflts rsb) {} = 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   593
rdistinct (rflts rsa) {} @ rdistinct  (rflts rs @ rflts rsb) (set (rflts rsa))")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   594
   apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   595
  prefer 2
64183736777a almost there
Chengsong
parents: 489
diff changeset
   596
  using rdistinct_concat_general apply blast
64183736777a almost there
Chengsong
parents: 489
diff changeset
   597
  apply(subgoal_tac "rdistinct (rflts rsa @ rflts [rsimp (RALTS rs)] @ rflts rsb) {} = 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   598
rdistinct (rflts rsa) {} @ rdistinct  (rflts [rsimp (RALTS rs)] @ rflts rsb) (set (rflts rsa))")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   599
   apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   600
  prefer 2
64183736777a almost there
Chengsong
parents: 489
diff changeset
   601
  using rdistinct_concat_general apply blast
64183736777a almost there
Chengsong
parents: 489
diff changeset
   602
  apply(subgoal_tac "rdistinct (rflts rs @ rflts rsb) (set (rflts rsa)) = 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   603
                     rdistinct  (rflts [rsimp (RALTS rs)] @ rflts rsb) (set (rflts rsa))")
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   604
   apply presburger
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   605
  using good_flatten_aux by blast
64183736777a almost there
Chengsong
parents: 489
diff changeset
   606
64183736777a almost there
Chengsong
parents: 489
diff changeset
   607
64183736777a almost there
Chengsong
parents: 489
diff changeset
   608
lemma simp_flatten3:
64183736777a almost there
Chengsong
parents: 489
diff changeset
   609
  shows "rsimp (RALTS (rsa @ [RALTS rs] @ rsb)) = rsimp (RALTS (rsa @ rs @ rsb))"
64183736777a almost there
Chengsong
parents: 489
diff changeset
   610
  apply(subgoal_tac "rsimp (RALTS (rsa @ [RALTS rs] @ rsb)) = 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   611
                     rsimp (RALTS (map rsimp rsa @ [rsimp (RALTS rs)] @ map rsimp rsb)) ")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   612
  prefer 2
64183736777a almost there
Chengsong
parents: 489
diff changeset
   613
   apply (metis append.left_neutral append_Cons list.simps(9) map_append simp_flatten_aux0)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   614
  apply (simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   615
  apply(subgoal_tac "rsimp (RALTS (rsa @ rs @ rsb)) = 
64183736777a almost there
Chengsong
parents: 489
diff changeset
   616
rsimp (RALTS (map rsimp rsa @ map rsimp rs @ map rsimp rsb))")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   617
  prefer 2
64183736777a almost there
Chengsong
parents: 489
diff changeset
   618
   apply (metis map_append simp_flatten_aux0)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   619
  apply(simp only:)
64183736777a almost there
Chengsong
parents: 489
diff changeset
   620
  apply(subgoal_tac "rsimp  (RALTS (map rsimp rsa @ map rsimp rs @ map rsimp rsb)) =
64183736777a almost there
Chengsong
parents: 489
diff changeset
   621
 rsimp (RALTS (map rsimp rsa @ [RALTS (map rsimp rs)] @ map rsimp rsb))")
64183736777a almost there
Chengsong
parents: 489
diff changeset
   622
  
64183736777a almost there
Chengsong
parents: 489
diff changeset
   623
   apply (metis (no_types, lifting) head_one_more_simp map_append simp_flatten_aux0)
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   624
  apply(subgoal_tac "\<forall>r \<in> set (map rsimp rsa). good r \<or> r = RZERO")
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   625
   apply(subgoal_tac "\<forall>r \<in> set (map rsimp rs). good r \<or> r = RZERO")
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   626
    apply(subgoal_tac "\<forall>r \<in> set (map rsimp rsb). good r \<or> r = RZERO")
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   627
  
64183736777a almost there
Chengsong
parents: 489
diff changeset
   628
  using good_flatten_middle apply presburger
64183736777a almost there
Chengsong
parents: 489
diff changeset
   629
  
491
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   630
  apply (simp add: good1)
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   631
  apply (simp add: good1)
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   632
  apply (simp add: good1)
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   633
48ce16d61e03 all done!!!!
Chengsong
parents: 490
diff changeset
   634
  done
490
64183736777a almost there
Chengsong
parents: 489
diff changeset
   635
64183736777a almost there
Chengsong
parents: 489
diff changeset
   636
64183736777a almost there
Chengsong
parents: 489
diff changeset
   637
64183736777a almost there
Chengsong
parents: 489
diff changeset
   638
  
64183736777a almost there
Chengsong
parents: 489
diff changeset
   639
476
Chengsong
parents: 475
diff changeset
   640
lemma grewrite_equal_rsimp:
Chengsong
parents: 475
diff changeset
   641
  shows "rs1 \<leadsto>g rs2 \<Longrightarrow> rsimp (RALTS rs1) = rsimp (RALTS rs2)"
478
Chengsong
parents: 476
diff changeset
   642
  apply(frule grewrite_cases_middle)
Chengsong
parents: 476
diff changeset
   643
  apply(case_tac "(\<exists>rsa rsb rsc. rs1 = rsa @ [RALTS rsb] @ rsc \<and> rs2 = rsa @ rsb @ rsc)")  
Chengsong
parents: 476
diff changeset
   644
  using simp_flatten3 apply auto[1]
Chengsong
parents: 476
diff changeset
   645
  apply(case_tac "(\<exists>rsa rsc. rs1 = rsa @ [RZERO] @ rsc \<and> rs2 = rsa @ rsc)")
Chengsong
parents: 476
diff changeset
   646
  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
   647
  by (smt (verit) append.assoc append_Cons append_Nil in_set_conv_decomp simp_removes_duplicate3)
476
Chengsong
parents: 475
diff changeset
   648
Chengsong
parents: 475
diff changeset
   649
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   650
lemma grewrites_equal_rsimp:
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   651
  shows "rs1 \<leadsto>g* rs2 \<Longrightarrow> rsimp (RALTS rs1) = rsimp (RALTS rs2)"
476
Chengsong
parents: 475
diff changeset
   652
  apply (induct rs1 rs2 rule: grewrites.induct)
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   653
  apply simp
476
Chengsong
parents: 475
diff changeset
   654
  using grewrite_equal_rsimp by presburger
Chengsong
parents: 475
diff changeset
   655
  
Chengsong
parents: 475
diff changeset
   656
Chengsong
parents: 475
diff changeset
   657
Chengsong
parents: 475
diff changeset
   658
Chengsong
parents: 475
diff changeset
   659
lemma grewrites_equal_simp_2:
Chengsong
parents: 475
diff changeset
   660
  shows "rsimp (RALTS rs1) = rsimp (RALTS rs2) \<Longrightarrow> rs1 \<leadsto>g* rs2"
478
Chengsong
parents: 476
diff changeset
   661
  oops
Chengsong
parents: 476
diff changeset
   662
Chengsong
parents: 476
diff changeset
   663
Chengsong
parents: 476
diff changeset
   664
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   665
476
Chengsong
parents: 475
diff changeset
   666
lemma grewrites_last:
Chengsong
parents: 475
diff changeset
   667
  shows "r # [RALTS rs] \<leadsto>g*  r # rs"
Chengsong
parents: 475
diff changeset
   668
  by (metis gr_in_rstar grewrite.intros(2) grewrite.intros(3) self_append_conv)
Chengsong
parents: 475
diff changeset
   669
Chengsong
parents: 475
diff changeset
   670
lemma simp_flatten2:
Chengsong
parents: 475
diff changeset
   671
  shows "rsimp (RALTS (r # [RALTS rs])) = rsimp (RALTS (r # rs))"
Chengsong
parents: 475
diff changeset
   672
  using grewrites_equal_rsimp grewrites_last by blast
475
10fd25fba2ba identities
Chengsong
parents: 473
diff changeset
   673
473
Chengsong
parents: 472
diff changeset
   674
lemma frewrites_middle:
Chengsong
parents: 472
diff changeset
   675
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> r # (RALTS rs # rs1) \<leadsto>f* r # (rs @ rs1)"
Chengsong
parents: 472
diff changeset
   676
  by (simp add: fr_in_rstar frewrite.intros(2) frewrite.intros(3))
471
Chengsong
parents: 469
diff changeset
   677
473
Chengsong
parents: 472
diff changeset
   678
lemma frewrites_alt:
Chengsong
parents: 472
diff changeset
   679
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> (RALT r1 r2) # rs1 \<leadsto>f* r1 # r2 # rs2"  
Chengsong
parents: 472
diff changeset
   680
  by (metis Cons_eq_appendI append_self_conv2 frewrite.intros(2) frewrites_cons many_steps_later)
471
Chengsong
parents: 469
diff changeset
   681
Chengsong
parents: 469
diff changeset
   682
lemma early_late_der_frewrites:
Chengsong
parents: 469
diff changeset
   683
  shows "map (rder x) (rflts rs) \<leadsto>f* rflts (map (rder x) rs)"
Chengsong
parents: 469
diff changeset
   684
  apply(induct rs)
Chengsong
parents: 469
diff changeset
   685
   apply simp
Chengsong
parents: 469
diff changeset
   686
  apply(case_tac a)
Chengsong
parents: 469
diff changeset
   687
       apply simp+
Chengsong
parents: 469
diff changeset
   688
  using frewrite.intros(1) many_steps_later apply blast
Chengsong
parents: 469
diff changeset
   689
     apply(case_tac "x = x3")
472
Chengsong
parents: 471
diff changeset
   690
      apply simp
Chengsong
parents: 471
diff changeset
   691
  using frewrites_cons apply presburger
Chengsong
parents: 471
diff changeset
   692
  using frewrite.intros(1) many_steps_later apply fastforce
Chengsong
parents: 471
diff changeset
   693
  apply(case_tac "rnullable x41")
473
Chengsong
parents: 472
diff changeset
   694
     apply simp+
Chengsong
parents: 472
diff changeset
   695
     apply (simp add: frewrites_alt)
Chengsong
parents: 472
diff changeset
   696
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   697
   apply (simp add: frewrites_append)
Chengsong
parents: 472
diff changeset
   698
  by (simp add: frewrites_cons)
471
Chengsong
parents: 469
diff changeset
   699
Chengsong
parents: 469
diff changeset
   700
Chengsong
parents: 469
diff changeset
   701
Chengsong
parents: 469
diff changeset
   702
473
Chengsong
parents: 472
diff changeset
   703
lemma with_wo0_distinct:
Chengsong
parents: 472
diff changeset
   704
  shows "rdistinct rs rset \<leadsto>f* rdistinct rs (insert RZERO rset)"
Chengsong
parents: 472
diff changeset
   705
  apply(induct rs arbitrary: rset)
Chengsong
parents: 472
diff changeset
   706
   apply simp
Chengsong
parents: 472
diff changeset
   707
  apply(case_tac a)
Chengsong
parents: 472
diff changeset
   708
  apply(case_tac "RZERO \<in> rset")
Chengsong
parents: 472
diff changeset
   709
        apply simp+
Chengsong
parents: 472
diff changeset
   710
  using fr_in_rstar frewrite.intros(1) apply presburger
Chengsong
parents: 472
diff changeset
   711
  apply (case_tac "RONE \<in> rset")
Chengsong
parents: 472
diff changeset
   712
       apply simp+
Chengsong
parents: 472
diff changeset
   713
  using frewrites_cons apply presburger
Chengsong
parents: 472
diff changeset
   714
     apply(case_tac "a \<in> rset")
Chengsong
parents: 472
diff changeset
   715
  apply simp
Chengsong
parents: 472
diff changeset
   716
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   717
     apply(case_tac "a \<in> rset")
Chengsong
parents: 472
diff changeset
   718
  apply simp
Chengsong
parents: 472
diff changeset
   719
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   720
       apply(case_tac "a \<in> rset")
Chengsong
parents: 472
diff changeset
   721
  apply simp
Chengsong
parents: 472
diff changeset
   722
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   723
       apply(case_tac "a \<in> rset")
Chengsong
parents: 472
diff changeset
   724
  apply simp
Chengsong
parents: 472
diff changeset
   725
  apply (simp add: frewrites_cons)
Chengsong
parents: 472
diff changeset
   726
  done
Chengsong
parents: 472
diff changeset
   727
476
Chengsong
parents: 475
diff changeset
   728
(*Interesting lemma: not obvious but easily proven by sledgehammer*)
473
Chengsong
parents: 472
diff changeset
   729
476
Chengsong
parents: 475
diff changeset
   730
  
Chengsong
parents: 475
diff changeset
   731
Chengsong
parents: 475
diff changeset
   732
Chengsong
parents: 475
diff changeset
   733
(*lemma induction last rule not go through
Chengsong
parents: 475
diff changeset
   734
 example:
Chengsong
parents: 475
diff changeset
   735
r #
Chengsong
parents: 475
diff changeset
   736
           rdistinct rs1
Chengsong
parents: 475
diff changeset
   737
            (insert RZERO
Chengsong
parents: 475
diff changeset
   738
              (insert r
Chengsong
parents: 475
diff changeset
   739
                (rset \<union>
Chengsong
parents: 475
diff changeset
   740
                 \<Union> (alt_set `
Chengsong
parents: 475
diff changeset
   741
                     rset)))) \<leadsto>g* r #
Chengsong
parents: 475
diff changeset
   742
                                   rdistinct rs2
Chengsong
parents: 475
diff changeset
   743
                                    (insert RZERO (insert r (rset \<union> \<Union> (alt_set ` rset))))
Chengsong
parents: 475
diff changeset
   744
 rs2 = [+rs] rs3 = rs,
Chengsong
parents: 475
diff changeset
   745
r = +rs
Chengsong
parents: 475
diff changeset
   746
[] \<leadsto>g* rs which is wrong
Chengsong
parents: 475
diff changeset
   747
*)
Chengsong
parents: 475
diff changeset
   748
469
e5dd8cc0aa82 all electron pics removed
Chengsong
parents: 468
diff changeset
   749
e5dd8cc0aa82 all electron pics removed
Chengsong
parents: 468
diff changeset
   750
476
Chengsong
parents: 475
diff changeset
   751
Chengsong
parents: 475
diff changeset
   752
Chengsong
parents: 475
diff changeset
   753
Chengsong
parents: 475
diff changeset
   754
Chengsong
parents: 475
diff changeset
   755
lemma frewrite_simpeq:
Chengsong
parents: 475
diff changeset
   756
  shows "rs1 \<leadsto>f rs2 \<Longrightarrow> rsimp (RALTS rs1) = rsimp (RALTS rs2)"
Chengsong
parents: 475
diff changeset
   757
  apply(induct rs1 rs2 rule: frewrite.induct)
Chengsong
parents: 475
diff changeset
   758
    apply simp
Chengsong
parents: 475
diff changeset
   759
  using simp_flatten apply presburger
478
Chengsong
parents: 476
diff changeset
   760
  by (metis (no_types, opaque_lifting) grewrites_equal_rsimp grewrites_last list.simps(9) rsimp.simps(2))
Chengsong
parents: 476
diff changeset
   761
Chengsong
parents: 476
diff changeset
   762
lemma gstar0:
Chengsong
parents: 476
diff changeset
   763
  shows "rsa @ (rdistinct rs (set rsa)) \<leadsto>g* rsa @ (rdistinct rs (insert RZERO (set rsa)))"
Chengsong
parents: 476
diff changeset
   764
  apply(induct rs arbitrary: rsa)
Chengsong
parents: 476
diff changeset
   765
   apply simp
Chengsong
parents: 476
diff changeset
   766
  apply(case_tac "a = RZERO")
Chengsong
parents: 476
diff changeset
   767
   apply simp
Chengsong
parents: 476
diff changeset
   768
  
Chengsong
parents: 476
diff changeset
   769
  using gr_in_rstar grewrite.intros(1) grewrites_append apply presburger
Chengsong
parents: 476
diff changeset
   770
  apply(case_tac "a \<in> set rsa")
Chengsong
parents: 476
diff changeset
   771
   apply simp+
Chengsong
parents: 476
diff changeset
   772
  apply(drule_tac x = "rsa @ [a]" in meta_spec)
Chengsong
parents: 476
diff changeset
   773
  by simp
Chengsong
parents: 476
diff changeset
   774
  
Chengsong
parents: 476
diff changeset
   775
lemma gstar01:
Chengsong
parents: 476
diff changeset
   776
  shows "rdistinct rs {} \<leadsto>g* rdistinct rs {RZERO}"
Chengsong
parents: 476
diff changeset
   777
  by (metis empty_set gstar0 self_append_conv2)
Chengsong
parents: 476
diff changeset
   778
Chengsong
parents: 476
diff changeset
   779
Chengsong
parents: 476
diff changeset
   780
lemma grewrite_rdistinct_aux:
Chengsong
parents: 476
diff changeset
   781
  shows "rs @ rdistinct rsa rset \<leadsto>g* rs @ rdistinct rsa (rset \<union> set rs)"
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   782
  apply(induct rsa arbitrary: rs rset)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   783
   apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   784
  apply(case_tac " a \<in> rset")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   785
   apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   786
  apply(case_tac "a \<in> set rs")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   787
  apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   788
   apply (metis Un_insert_left Un_insert_right gmany_steps_later grewrite_variant1 insert_absorb)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   789
  apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   790
  apply(drule_tac x = "rs @ [a]" in meta_spec)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   791
  by (metis Un_insert_left Un_insert_right append.assoc append.right_neutral append_Cons append_Nil insert_absorb2 list.simps(15) set_append)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   792
  
478
Chengsong
parents: 476
diff changeset
   793
Chengsong
parents: 476
diff changeset
   794
lemma grewrite_rdistinct_worth1:
Chengsong
parents: 476
diff changeset
   795
  shows "(rsb @ [a]) @ rdistinct rs set1 \<leadsto>g* (rsb @ [a]) @ rdistinct rs (insert a set1)"
Chengsong
parents: 476
diff changeset
   796
  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
   797
Chengsong
parents: 476
diff changeset
   798
lemma grewrite_rdisitinct:
Chengsong
parents: 476
diff changeset
   799
  shows "rs @ rdistinct rsa {RALTS rs} \<leadsto>g* rs @ rdistinct rsa (insert (RALTS rs) (set rs))"
Chengsong
parents: 476
diff changeset
   800
  apply(induct rsa arbitrary: rs)
Chengsong
parents: 476
diff changeset
   801
   apply simp
Chengsong
parents: 476
diff changeset
   802
  apply(case_tac "a = RALTS rs")
Chengsong
parents: 476
diff changeset
   803
  apply simp
Chengsong
parents: 476
diff changeset
   804
  apply(case_tac "a \<in> set rs")
Chengsong
parents: 476
diff changeset
   805
   apply simp
Chengsong
parents: 476
diff changeset
   806
  apply(subgoal_tac "rs @
Chengsong
parents: 476
diff changeset
   807
           a # rdistinct rsa {RALTS rs, a} \<leadsto>g rs @ rdistinct rsa {RALTS rs, a}")
Chengsong
parents: 476
diff changeset
   808
    apply(subgoal_tac 
Chengsong
parents: 476
diff changeset
   809
"rs @ rdistinct rsa {RALTS rs, a} \<leadsto>g* rs @ rdistinct rsa (insert (RALTS rs) (set rs))")
Chengsong
parents: 476
diff changeset
   810
  using gmany_steps_later apply blast
Chengsong
parents: 476
diff changeset
   811
    apply(subgoal_tac 
Chengsong
parents: 476
diff changeset
   812
" rs @ rdistinct rsa {RALTS rs, a} \<leadsto>g* rs @ rdistinct rsa ({RALTS rs, a} \<union> set rs)")
Chengsong
parents: 476
diff changeset
   813
     apply (simp add: insert_absorb)
Chengsong
parents: 476
diff changeset
   814
  using grewrite_rdistinct_aux apply blast
Chengsong
parents: 476
diff changeset
   815
  using grewrite_variant1 apply blast
Chengsong
parents: 476
diff changeset
   816
  by (metis grewrite_rdistinct_aux insert_is_Un)
Chengsong
parents: 476
diff changeset
   817
Chengsong
parents: 476
diff changeset
   818
  
Chengsong
parents: 476
diff changeset
   819
lemma frewrite_rd_grewrites_general:
Chengsong
parents: 476
diff changeset
   820
  shows "\<lbrakk>rs1 \<leadsto>f rs2; \<And>rs. \<exists>rs3. 
Chengsong
parents: 476
diff changeset
   821
(rs @ (rdistinct rs1 (set rs)) \<leadsto>g* rs3) \<and> (rs @ (rdistinct rs2 (set rs)) \<leadsto>g* rs3)\<rbrakk>
Chengsong
parents: 476
diff changeset
   822
       \<Longrightarrow> 
Chengsong
parents: 476
diff changeset
   823
\<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
   824
  apply(drule_tac x = "rs @ [r]" in meta_spec )
Chengsong
parents: 476
diff changeset
   825
  by simp
Chengsong
parents: 476
diff changeset
   826
Chengsong
parents: 476
diff changeset
   827
479
Chengsong
parents: 478
diff changeset
   828
lemma alts_g_can_flts:
Chengsong
parents: 478
diff changeset
   829
  shows "RALTS rs \<in> set rsb \<Longrightarrow> \<exists>rs1 rs2.( rflts rsb = rs1 @ rs @ rs2)"
Chengsong
parents: 478
diff changeset
   830
  by (metis flts_append rflts.simps(3) split_list_last)
Chengsong
parents: 478
diff changeset
   831
Chengsong
parents: 478
diff changeset
   832
lemma flts_gstar:
Chengsong
parents: 478
diff changeset
   833
  shows "rs \<leadsto>g* rflts rs"
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   834
  apply(induct rs)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   835
   apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   836
  apply(case_tac "a = RZERO")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   837
   apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   838
  using gmany_steps_later grewrite.intros(1) apply blast
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   839
  apply(case_tac "\<exists>rsa. a = RALTS rsa")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   840
   apply(erule exE)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   841
  apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   842
   apply (meson grewrite.intros(2) grewrites.simps grewrites_cons)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   843
  by (simp add: grewrites_cons rflts_def_idiot)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   844
479
Chengsong
parents: 478
diff changeset
   845
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   846
lemma wrong1:
479
Chengsong
parents: 478
diff changeset
   847
  shows "a \<in> set rs1 \<Longrightarrow> rs1 @ (rdistinct rs (insert a rset)) \<leadsto>g* rs1 @ (rdistinct rs (rset))"
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   848
  
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   849
  oops
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   850
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   851
lemma more_distinct1:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   852
  shows "       \<lbrakk>\<And>rsb rset rset2.
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   853
           rset2 \<subseteq> set rsb \<Longrightarrow> rsb @ rdistinct rs rset \<leadsto>g* rsb @ rdistinct rs (rset \<union> rset2);
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   854
        rset2 \<subseteq> set rsb; a \<notin> rset; a \<in> rset2\<rbrakk>
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   855
       \<Longrightarrow> rsb @ a # rdistinct rs (insert a rset) \<leadsto>g* rsb @ rdistinct rs (rset \<union> rset2)"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   856
  apply(subgoal_tac "rsb @ a # rdistinct rs (insert a rset) \<leadsto>g* rsb @ rdistinct rs (insert a rset)")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   857
   apply(subgoal_tac "rsb @ rdistinct rs (insert a rset) \<leadsto>g* rsb @ rdistinct rs (rset \<union> rset2)")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   858
    apply (meson greal_trans)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   859
   apply (metis Un_iff Un_insert_left insert_absorb)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   860
  by (simp add: gr_in_rstar grewrite_variant1 in_mono)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   861
  
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   862
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   863
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   864
478
Chengsong
parents: 476
diff changeset
   865
479
Chengsong
parents: 478
diff changeset
   866
lemma grewrites_in_distinct0:
Chengsong
parents: 478
diff changeset
   867
  shows "a \<in>  set rs1 \<Longrightarrow> rs1 @ (rdistinct (a # rs) rset) \<leadsto>g* rs1 @ (rdistinct rs rset)"
Chengsong
parents: 478
diff changeset
   868
  apply(case_tac "a \<in> rset")
Chengsong
parents: 478
diff changeset
   869
   apply simp
Chengsong
parents: 478
diff changeset
   870
  apply simp
Chengsong
parents: 478
diff changeset
   871
  oops
Chengsong
parents: 478
diff changeset
   872
Chengsong
parents: 478
diff changeset
   873
 
Chengsong
parents: 478
diff changeset
   874
Chengsong
parents: 478
diff changeset
   875
Chengsong
parents: 478
diff changeset
   876
  
Chengsong
parents: 478
diff changeset
   877
Chengsong
parents: 478
diff changeset
   878
478
Chengsong
parents: 476
diff changeset
   879
Chengsong
parents: 476
diff changeset
   880
Chengsong
parents: 476
diff changeset
   881
lemma frewrite_rd_grewrites_aux:
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   882
  shows     "       RALTS rs \<notin> set rsb \<Longrightarrow>
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   883
       rsb @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   884
       RALTS rs #
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   885
       rdistinct rsa
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   886
        (insert (RALTS rs)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   887
          (set rsb)) \<leadsto>g* rflts rsb @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   888
                          rdistinct rs (set rsb) @ rdistinct rsa (set rs \<union> set rsb \<union> {RALTS rs})"
478
Chengsong
parents: 476
diff changeset
   889
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   890
   apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   891
  apply(subgoal_tac "rsb @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   892
    RALTS rs #
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   893
    rdistinct rsa
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   894
     (insert (RALTS rs)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   895
       (set rsb)) \<leadsto>g* rsb @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   896
    rs @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   897
    rdistinct rsa
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   898
     (insert (RALTS rs)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   899
       (set rsb)) ")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   900
  apply(subgoal_tac " rsb @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   901
    rs @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   902
    rdistinct rsa
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   903
     (insert (RALTS rs)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   904
       (set rsb)) \<leadsto>g*
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   905
                      rsb @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   906
    rdistinct rs (set rsb) @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   907
    rdistinct rsa
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   908
     (insert (RALTS rs)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   909
       (set rsb)) ")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   910
    apply (smt (verit, ccfv_SIG) Un_insert_left flts_gstar greal_trans grewrite_rdistinct_aux grewritess_concat inf_sup_aci(5) rdistinct_concat_general rdistinct_set_equality set_append)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   911
   apply (metis append_assoc grewrites.intros(1) grewritess_concat gstar_rdistinct_general)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
   912
  by (simp add: gr_in_rstar grewrite.intros(2) grewrites_append)
478
Chengsong
parents: 476
diff changeset
   913
  
Chengsong
parents: 476
diff changeset
   914
479
Chengsong
parents: 478
diff changeset
   915
478
Chengsong
parents: 476
diff changeset
   916
Chengsong
parents: 476
diff changeset
   917
lemma list_dlist_union:
Chengsong
parents: 476
diff changeset
   918
  shows "set rs \<subseteq> set rsb \<union> set (rdistinct rs (set rsb))"
Chengsong
parents: 476
diff changeset
   919
  by (metis rdistinct_concat_general rdistinct_set_equality set_append sup_ge2)
Chengsong
parents: 476
diff changeset
   920
Chengsong
parents: 476
diff changeset
   921
lemma subset_distinct_rewrite1:
Chengsong
parents: 476
diff changeset
   922
  shows "set1 \<subseteq> set rsb \<Longrightarrow> rsb @ rs \<leadsto>g* rsb @ (rdistinct rs set1)"
Chengsong
parents: 476
diff changeset
   923
  apply(induct rs arbitrary: rsb)
Chengsong
parents: 476
diff changeset
   924
   apply simp
Chengsong
parents: 476
diff changeset
   925
  apply(case_tac "a \<in> set1")
Chengsong
parents: 476
diff changeset
   926
   apply simp
Chengsong
parents: 476
diff changeset
   927
  
Chengsong
parents: 476
diff changeset
   928
  using gmany_steps_later grewrite_variant1 apply blast
Chengsong
parents: 476
diff changeset
   929
  apply simp
Chengsong
parents: 476
diff changeset
   930
  apply(drule_tac x = "rsb @ [a]" in meta_spec)
Chengsong
parents: 476
diff changeset
   931
  apply(subgoal_tac "set1 \<subseteq> set (rsb @ [a])")
Chengsong
parents: 476
diff changeset
   932
   apply (simp only:)
Chengsong
parents: 476
diff changeset
   933
  apply(subgoal_tac "(rsb @ [a]) @ rdistinct rs set1 \<leadsto>g* (rsb @ [a]) @ rdistinct rs (insert a set1)")
Chengsong
parents: 476
diff changeset
   934
    apply (metis (no_types, opaque_lifting) append.assoc append_Cons append_Nil greal_trans)
Chengsong
parents: 476
diff changeset
   935
  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
   936
  by auto
Chengsong
parents: 476
diff changeset
   937
Chengsong
parents: 476
diff changeset
   938
Chengsong
parents: 476
diff changeset
   939
lemma subset_distinct_rewrite:
Chengsong
parents: 476
diff changeset
   940
  shows "set rsb' \<subseteq> set rsb \<Longrightarrow> rsb @ rs \<leadsto>g* rsb @ (rdistinct rs (set rsb'))"
Chengsong
parents: 476
diff changeset
   941
  by (simp add: subset_distinct_rewrite1)
Chengsong
parents: 476
diff changeset
   942
  
Chengsong
parents: 476
diff changeset
   943
Chengsong
parents: 476
diff changeset
   944
Chengsong
parents: 476
diff changeset
   945
lemma distinct_3list:
Chengsong
parents: 476
diff changeset
   946
  shows "rsb @ (rdistinct rs (set rsb)) @ rsa \<leadsto>g* 
Chengsong
parents: 476
diff changeset
   947
         rsb @ (rdistinct rs (set rsb)) @ (rdistinct rsa (set rs))"
Chengsong
parents: 476
diff changeset
   948
  by (metis append.assoc list_dlist_union set_append subset_distinct_rewrite)
Chengsong
parents: 476
diff changeset
   949
  
Chengsong
parents: 476
diff changeset
   950
Chengsong
parents: 476
diff changeset
   951
Chengsong
parents: 476
diff changeset
   952
Chengsong
parents: 476
diff changeset
   953
lemma grewrites_shape1:
Chengsong
parents: 476
diff changeset
   954
  shows "      RALTS rs \<notin> set rsb \<Longrightarrow>
Chengsong
parents: 476
diff changeset
   955
       rsb @
Chengsong
parents: 476
diff changeset
   956
       RALTS rs #
Chengsong
parents: 476
diff changeset
   957
       rdistinct rsa
Chengsong
parents: 476
diff changeset
   958
        (
Chengsong
parents: 476
diff changeset
   959
          (set rsb)) \<leadsto>g* rsb @
Chengsong
parents: 476
diff changeset
   960
                          rdistinct rs (set rsb) @
Chengsong
parents: 476
diff changeset
   961
                          rdistinct (rflts (rdistinct rsa ( (set rsb \<union> set rs)))) (set rs)"
Chengsong
parents: 476
diff changeset
   962
Chengsong
parents: 476
diff changeset
   963
Chengsong
parents: 476
diff changeset
   964
  apply (subgoal_tac "       rsb @
Chengsong
parents: 476
diff changeset
   965
       RALTS rs #
Chengsong
parents: 476
diff changeset
   966
       rdistinct rsa
Chengsong
parents: 476
diff changeset
   967
        (
Chengsong
parents: 476
diff changeset
   968
          (set rsb))  \<leadsto>g*        rsb @
Chengsong
parents: 476
diff changeset
   969
       rs @
Chengsong
parents: 476
diff changeset
   970
       rdistinct rsa
Chengsong
parents: 476
diff changeset
   971
        (
Chengsong
parents: 476
diff changeset
   972
          (set rsb)) ")
Chengsong
parents: 476
diff changeset
   973
   prefer 2
Chengsong
parents: 476
diff changeset
   974
  using gr_in_rstar grewrite.intros(2) grewrites_append apply presburger
Chengsong
parents: 476
diff changeset
   975
  apply(subgoal_tac "rsb @ rs @ rdistinct rsa (  (set rsb)) \<leadsto>g* rsb @ 
Chengsong
parents: 476
diff changeset
   976
(rdistinct rs (set rsb) @ rdistinct rsa (  (set rsb)))")
Chengsong
parents: 476
diff changeset
   977
  prefer 2
Chengsong
parents: 476
diff changeset
   978
  apply (metis append_assoc grewrites.intros(1) grewritess_concat gstar_rdistinct_general)
Chengsong
parents: 476
diff changeset
   979
  apply(subgoal_tac " rsb @ rdistinct rs (set rsb) @ rdistinct rsa (  (set rsb))
Chengsong
parents: 476
diff changeset
   980
\<leadsto>g*  rsb @ rdistinct rs (set rsb) @ rdistinct rsa (  (set rsb) \<union> (set rs))")
Chengsong
parents: 476
diff changeset
   981
  prefer 2
Chengsong
parents: 476
diff changeset
   982
  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
   983
  apply(subgoal_tac "rdistinct rsa (  (set rsb)  \<union> set rs) \<leadsto>g*
Chengsong
parents: 476
diff changeset
   984
rflts (rdistinct rsa (  (set rsb) \<union> set rs))")
Chengsong
parents: 476
diff changeset
   985
   apply(subgoal_tac "rsb @ (rdistinct rs (set rsb)) @ rflts (rdistinct rsa (  (set rsb) \<union> set rs)) \<leadsto>g* 
Chengsong
parents: 476
diff changeset
   986
rsb @ (rdistinct rs (set rsb)) @ (rdistinct (rflts (rdistinct rsa (  (set rsb) \<union> set rs))) (set rs))")
Chengsong
parents: 476
diff changeset
   987
  apply (smt (verit, ccfv_SIG) Un_insert_left greal_trans grewrites_append)
Chengsong
parents: 476
diff changeset
   988
  using distinct_3list apply presburger
Chengsong
parents: 476
diff changeset
   989
  using flts_gstar apply blast
Chengsong
parents: 476
diff changeset
   990
  done
Chengsong
parents: 476
diff changeset
   991
Chengsong
parents: 476
diff changeset
   992
lemma r_finite1:
Chengsong
parents: 476
diff changeset
   993
  shows "r = RALTS (r # rs) = False"
Chengsong
parents: 476
diff changeset
   994
  apply(induct r)
Chengsong
parents: 476
diff changeset
   995
  apply simp+
Chengsong
parents: 476
diff changeset
   996
   apply (metis list.set_intros(1))
Chengsong
parents: 476
diff changeset
   997
  by blast
Chengsong
parents: 476
diff changeset
   998
  
Chengsong
parents: 476
diff changeset
   999
Chengsong
parents: 476
diff changeset
  1000
Chengsong
parents: 476
diff changeset
  1001
lemma grewrite_singleton:
Chengsong
parents: 476
diff changeset
  1002
  shows "[r] \<leadsto>g r # rs \<Longrightarrow> rs = []"
Chengsong
parents: 476
diff changeset
  1003
  apply (induct "[r]" "r # rs" rule: grewrite.induct)
Chengsong
parents: 476
diff changeset
  1004
    apply simp
Chengsong
parents: 476
diff changeset
  1005
  apply (metis r_finite1)
Chengsong
parents: 476
diff changeset
  1006
  using grewrite.simps apply blast
Chengsong
parents: 476
diff changeset
  1007
  by simp
Chengsong
parents: 476
diff changeset
  1008
Chengsong
parents: 476
diff changeset
  1009
lemma impossible_grewrite1:
Chengsong
parents: 476
diff changeset
  1010
  shows "\<not>( [RONE] \<leadsto>g [])"
Chengsong
parents: 476
diff changeset
  1011
  using grewrite.cases by fastforce
Chengsong
parents: 476
diff changeset
  1012
Chengsong
parents: 476
diff changeset
  1013
Chengsong
parents: 476
diff changeset
  1014
lemma impossible_grewrite2:
Chengsong
parents: 476
diff changeset
  1015
  shows "\<not> ([RALTS rs] \<leadsto>g (RALTS rs) # a # rs)"
Chengsong
parents: 476
diff changeset
  1016
  using grewrite_singleton by blast
Chengsong
parents: 476
diff changeset
  1017
Chengsong
parents: 476
diff changeset
  1018
  
Chengsong
parents: 476
diff changeset
  1019
Chengsong
parents: 476
diff changeset
  1020
479
Chengsong
parents: 478
diff changeset
  1021
lemma wront_sublist_grewrites:
478
Chengsong
parents: 476
diff changeset
  1022
  shows "rs1 @ rs2 \<leadsto>g* rs1 @ rs3 \<Longrightarrow> rs2 \<leadsto>g* rs3"
Chengsong
parents: 476
diff changeset
  1023
  apply(induct rs1 arbitrary: rs2 rs3 rule: rev_induct)
Chengsong
parents: 476
diff changeset
  1024
   apply simp
Chengsong
parents: 476
diff changeset
  1025
  apply(drule_tac x = "[x] @ rs2" in meta_spec)
Chengsong
parents: 476
diff changeset
  1026
  apply(drule_tac x = "[x] @ rs3" in meta_spec)
Chengsong
parents: 476
diff changeset
  1027
  apply(simp)
Chengsong
parents: 476
diff changeset
  1028
Chengsong
parents: 476
diff changeset
  1029
  oops
Chengsong
parents: 476
diff changeset
  1030
Chengsong
parents: 476
diff changeset
  1031
Chengsong
parents: 476
diff changeset
  1032
Chengsong
parents: 476
diff changeset
  1033
479
Chengsong
parents: 478
diff changeset
  1034
lemma concat_rdistinct_equality1:
Chengsong
parents: 478
diff changeset
  1035
  shows "rdistinct (rs @ rsa) rset = rdistinct rs rset @ rdistinct rsa (rset \<union> (set rs))"
Chengsong
parents: 478
diff changeset
  1036
  apply(induct rs arbitrary: rsa rset)
478
Chengsong
parents: 476
diff changeset
  1037
   apply simp
479
Chengsong
parents: 478
diff changeset
  1038
  apply(case_tac "a \<in> rset")
Chengsong
parents: 478
diff changeset
  1039
   apply simp
Chengsong
parents: 478
diff changeset
  1040
  apply (simp add: insert_absorb)
Chengsong
parents: 478
diff changeset
  1041
  by auto
478
Chengsong
parents: 476
diff changeset
  1042
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1043
lemma middle_grewrites: 
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1044
"rs1 \<leadsto>g* rs2 \<Longrightarrow> rsa @ rs1 @ rsb \<leadsto>g* rsa @ rs2 @ rsb "
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1045
  by (simp add: grewritess_concat)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1046
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1047
lemma rdistinct_removes_all:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1048
  shows "set rs \<subseteq> rset \<Longrightarrow> rdistinct rs rset = []"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1049
  
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1050
  by (metis append.right_neutral rdistinct.simps(1) rdistinct_concat)
478
Chengsong
parents: 476
diff changeset
  1051
479
Chengsong
parents: 478
diff changeset
  1052
lemma ends_removal:
Chengsong
parents: 478
diff changeset
  1053
  shows " rsb @ rdistinct rs (set rsb) @ RALTS rs # rsc \<leadsto>g* rsb @ rdistinct rs (set rsb) @ rsc"
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1054
  apply(subgoal_tac "rsb @ rdistinct rs (set rsb) @ RALTS rs # rsc \<leadsto>g* 
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1055
                     rsb @ rdistinct rs (set rsb) @ rs @ rsc")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1056
   apply(subgoal_tac "rsb @ rdistinct rs (set rsb) @ rs @ rsc \<leadsto>g* 
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1057
rsb @ rdistinct rs (set rsb) @ rdistinct rs (set (rsb @ rdistinct rs (set rsb))) @ rsc")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1058
  apply (metis (full_types) append_Nil2 append_eq_appendI greal_trans list_dlist_union rdistinct_removes_all set_append)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1059
   apply (metis append.assoc append_Nil gstar_rdistinct_general middle_grewrites)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1060
  using gr_in_rstar grewrite.intros(2) grewrites_append by presburger
478
Chengsong
parents: 476
diff changeset
  1061
479
Chengsong
parents: 478
diff changeset
  1062
lemma grewrites_rev_append:
Chengsong
parents: 478
diff changeset
  1063
  shows "rs1 \<leadsto>g* rs2 \<Longrightarrow> rs1 @ [x] \<leadsto>g* rs2 @ [x]"
Chengsong
parents: 478
diff changeset
  1064
  using grewritess_concat by auto
478
Chengsong
parents: 476
diff changeset
  1065
479
Chengsong
parents: 478
diff changeset
  1066
lemma grewrites_inclusion:
Chengsong
parents: 478
diff changeset
  1067
  shows "set rs \<subseteq> set rs1 \<Longrightarrow> rs1 @ rs \<leadsto>g* rs1"
Chengsong
parents: 478
diff changeset
  1068
  apply(induct rs arbitrary: rs1)
Chengsong
parents: 478
diff changeset
  1069
  apply simp
Chengsong
parents: 478
diff changeset
  1070
  by (meson gmany_steps_later grewrite_variant1 list.set_intros(1) set_subset_Cons subset_code(1))
478
Chengsong
parents: 476
diff changeset
  1071
479
Chengsong
parents: 478
diff changeset
  1072
lemma distinct_keeps_last:
Chengsong
parents: 478
diff changeset
  1073
  shows "\<lbrakk>x \<notin> rset; x \<notin> set xs \<rbrakk> \<Longrightarrow> rdistinct (xs @ [x]) rset = rdistinct xs rset @ [x]"
Chengsong
parents: 478
diff changeset
  1074
  by (simp add: concat_rdistinct_equality1)
478
Chengsong
parents: 476
diff changeset
  1075
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1076
lemma grewrites_shape2_aux:
478
Chengsong
parents: 476
diff changeset
  1077
  shows "       RALTS rs \<notin> set rsb \<Longrightarrow>
Chengsong
parents: 476
diff changeset
  1078
       rsb @
Chengsong
parents: 476
diff changeset
  1079
       rdistinct (rs @ rsa)
Chengsong
parents: 476
diff changeset
  1080
        (set rsb) \<leadsto>g* rsb @
Chengsong
parents: 476
diff changeset
  1081
                       rdistinct rs (set rsb) @
479
Chengsong
parents: 478
diff changeset
  1082
                       rdistinct rsa (set rs \<union> set rsb \<union> {RALTS rs})"
Chengsong
parents: 478
diff changeset
  1083
  apply(subgoal_tac " rdistinct (rs @ rsa) (set rsb) =  rdistinct rs (set rsb) @ rdistinct rsa (set rs \<union> set rsb)")
Chengsong
parents: 478
diff changeset
  1084
   apply (simp only:)
Chengsong
parents: 478
diff changeset
  1085
  prefer 2
Chengsong
parents: 478
diff changeset
  1086
  apply (simp add: Un_commute concat_rdistinct_equality1)
Chengsong
parents: 478
diff changeset
  1087
  apply(induct rsa arbitrary: rs rsb rule: rev_induct)
Chengsong
parents: 478
diff changeset
  1088
   apply simp
Chengsong
parents: 478
diff changeset
  1089
  apply(case_tac "x \<in> set rs")
Chengsong
parents: 478
diff changeset
  1090
  apply (simp add: distinct_removes_middle3)
Chengsong
parents: 478
diff changeset
  1091
  apply(case_tac "x = RALTS rs")
Chengsong
parents: 478
diff changeset
  1092
   apply simp
Chengsong
parents: 478
diff changeset
  1093
  apply(case_tac "x \<in> set rsb")
Chengsong
parents: 478
diff changeset
  1094
   apply simp
Chengsong
parents: 478
diff changeset
  1095
    apply (simp add: concat_rdistinct_equality1)
Chengsong
parents: 478
diff changeset
  1096
  apply (simp add: concat_rdistinct_equality1)
Chengsong
parents: 478
diff changeset
  1097
  apply simp
Chengsong
parents: 478
diff changeset
  1098
  apply(drule_tac x = "rs " in meta_spec)
Chengsong
parents: 478
diff changeset
  1099
  apply(drule_tac x = rsb in meta_spec)
Chengsong
parents: 478
diff changeset
  1100
  apply simp
Chengsong
parents: 478
diff changeset
  1101
  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
  1102
  prefer 2
Chengsong
parents: 478
diff changeset
  1103
   apply (simp add: concat_rdistinct_equality1)
Chengsong
parents: 478
diff changeset
  1104
  apply(case_tac "x \<in> set xs")
Chengsong
parents: 478
diff changeset
  1105
   apply simp
Chengsong
parents: 478
diff changeset
  1106
   apply (simp add: distinct_removes_last2)
Chengsong
parents: 478
diff changeset
  1107
  apply(case_tac "x \<in> set rsb")
Chengsong
parents: 478
diff changeset
  1108
   apply (smt (verit, ccfv_threshold) Un_iff append.right_neutral concat_rdistinct_equality1 insert_is_Un rdistinct.simps(2))
Chengsong
parents: 478
diff changeset
  1109
  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
  1110
  apply(simp only:)
Chengsong
parents: 478
diff changeset
  1111
  apply(case_tac "x = RALTS rs")
Chengsong
parents: 478
diff changeset
  1112
    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
  1113
  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
  1114
      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
  1115
  apply(subgoal_tac "set rs \<subseteq> set ( rsb @ rdistinct rs (set rsb) @ rdistinct xs (set rs \<union> set rsb))")
Chengsong
parents: 478
diff changeset
  1116
  apply (metis append.assoc grewrites_inclusion)
Chengsong
parents: 478
diff changeset
  1117
     apply (metis Un_upper1 append.assoc dual_order.trans list_dlist_union set_append)
Chengsong
parents: 478
diff changeset
  1118
  apply (metis append_Nil2 gr_in_rstar grewrite.intros(2) grewrite_append)
Chengsong
parents: 478
diff changeset
  1119
   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
  1120
  apply(simp only:)
Chengsong
parents: 478
diff changeset
  1121
  apply (metis append.assoc grewrites_rev_append)
Chengsong
parents: 478
diff changeset
  1122
  apply (simp add: insert_absorb)
Chengsong
parents: 478
diff changeset
  1123
   apply (simp add: distinct_keeps_last)+
Chengsong
parents: 478
diff changeset
  1124
  done
478
Chengsong
parents: 476
diff changeset
  1125
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1126
lemma grewrites_shape2:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1127
  shows "       RALTS rs \<notin> set rsb \<Longrightarrow>
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1128
       rsb @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1129
       rdistinct (rs @ rsa)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1130
        (set rsb) \<leadsto>g* rflts rsb @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1131
                       rdistinct rs (set rsb) @
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1132
                       rdistinct rsa (set rs \<union> set rsb \<union> {RALTS rs})"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1133
  apply (meson flts_gstar greal_trans grewrites.simps grewrites_shape2_aux grewritess_concat)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1134
  done
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1135
479
Chengsong
parents: 478
diff changeset
  1136
lemma rdistinct_add_acc:
Chengsong
parents: 478
diff changeset
  1137
  shows "rset2 \<subseteq> set rsb \<Longrightarrow> rsb @ rdistinct rs rset \<leadsto>g* rsb @ rdistinct rs (rset \<union> rset2)"
Chengsong
parents: 478
diff changeset
  1138
  apply(induct rs arbitrary: rsb rset rset2)
Chengsong
parents: 478
diff changeset
  1139
   apply simp
Chengsong
parents: 478
diff changeset
  1140
  apply (case_tac "a \<in> rset")
Chengsong
parents: 478
diff changeset
  1141
   apply simp
Chengsong
parents: 478
diff changeset
  1142
  apply(case_tac "a \<in> rset2")
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1143
   apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1144
  apply (simp add: more_distinct1)
479
Chengsong
parents: 478
diff changeset
  1145
  apply simp
Chengsong
parents: 478
diff changeset
  1146
  apply(drule_tac x = "rsb @ [a]" in meta_spec)
Chengsong
parents: 478
diff changeset
  1147
  by (metis Un_insert_left append.assoc append_Cons append_Nil set_append sup.coboundedI1)
Chengsong
parents: 478
diff changeset
  1148
  
478
Chengsong
parents: 476
diff changeset
  1149
479
Chengsong
parents: 478
diff changeset
  1150
lemma frewrite_fun1:
Chengsong
parents: 478
diff changeset
  1151
  shows "       RALTS rs \<in> set rsb \<Longrightarrow>
Chengsong
parents: 478
diff changeset
  1152
       rsb @ rdistinct rsa (set rsb) \<leadsto>g* rflts rsb @ rdistinct rsa (set rsb \<union> set rs)"
Chengsong
parents: 478
diff changeset
  1153
  apply(subgoal_tac "rsb @ rdistinct rsa (set rsb) \<leadsto>g* rflts rsb @ rdistinct rsa (set rsb)")
Chengsong
parents: 478
diff changeset
  1154
   apply(subgoal_tac " set rs \<subseteq> set (rflts rsb)")
Chengsong
parents: 478
diff changeset
  1155
  prefer 2
Chengsong
parents: 478
diff changeset
  1156
  using spilled_alts_contained apply blast
Chengsong
parents: 478
diff changeset
  1157
   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
  1158
  using greal_trans apply blast
Chengsong
parents: 478
diff changeset
  1159
  using rdistinct_add_acc apply presburger
Chengsong
parents: 478
diff changeset
  1160
  using flts_gstar grewritess_concat by auto
Chengsong
parents: 478
diff changeset
  1161
  
478
Chengsong
parents: 476
diff changeset
  1162
Chengsong
parents: 476
diff changeset
  1163
Chengsong
parents: 476
diff changeset
  1164
476
Chengsong
parents: 475
diff changeset
  1165
Chengsong
parents: 475
diff changeset
  1166
lemma frewrite_rd_grewrites:
Chengsong
parents: 475
diff changeset
  1167
  shows "rs1 \<leadsto>f rs2 \<Longrightarrow> 
478
Chengsong
parents: 476
diff changeset
  1168
\<exists>rs3. (rs @ (rdistinct rs1 (set rs)) \<leadsto>g* rs3) \<and> (rs @ (rdistinct rs2 (set rs)) \<leadsto>g* rs3) "
Chengsong
parents: 476
diff changeset
  1169
  apply(induct rs1 rs2 arbitrary: rs rule: frewrite.induct)
Chengsong
parents: 476
diff changeset
  1170
    apply(rule_tac x = "rsa @ (rdistinct rs ({RZERO} \<union> set rsa))" in exI)
476
Chengsong
parents: 475
diff changeset
  1171
    apply(rule conjI)
478
Chengsong
parents: 476
diff changeset
  1172
  apply(case_tac "RZERO \<in> set rsa")
Chengsong
parents: 476
diff changeset
  1173
  apply simp+
Chengsong
parents: 476
diff changeset
  1174
  using gstar0 apply fastforce
Chengsong
parents: 476
diff changeset
  1175
     apply (simp add: gr_in_rstar grewrite.intros(1) grewrites_append)
Chengsong
parents: 476
diff changeset
  1176
    apply (simp add: gstar0)
Chengsong
parents: 476
diff changeset
  1177
    prefer 2
Chengsong
parents: 476
diff changeset
  1178
    apply(case_tac "r \<in> set rs")
Chengsong
parents: 476
diff changeset
  1179
  apply simp
Chengsong
parents: 476
diff changeset
  1180
    apply(drule_tac x = "rs @ [r]" in meta_spec)
Chengsong
parents: 476
diff changeset
  1181
    apply(erule exE)
Chengsong
parents: 476
diff changeset
  1182
    apply(rule_tac x = "rs3" in exI)
Chengsong
parents: 476
diff changeset
  1183
   apply simp
Chengsong
parents: 476
diff changeset
  1184
  apply(case_tac "RALTS rs \<in> set rsb")
Chengsong
parents: 476
diff changeset
  1185
   apply simp
479
Chengsong
parents: 478
diff changeset
  1186
   apply(rule_tac x = "rflts rsb @ rdistinct rsa (set rsb \<union> set rs)" in exI)
478
Chengsong
parents: 476
diff changeset
  1187
   apply(rule conjI)
479
Chengsong
parents: 478
diff changeset
  1188
  using frewrite_fun1 apply force
Chengsong
parents: 478
diff changeset
  1189
  apply (metis frewrite_fun1 rdistinct_concat sup_ge2)
478
Chengsong
parents: 476
diff changeset
  1190
  apply(simp)
Chengsong
parents: 476
diff changeset
  1191
  apply(rule_tac x = 
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1192
 "rflts rsb @
479
Chengsong
parents: 478
diff changeset
  1193
                       rdistinct rs (set rsb) @
Chengsong
parents: 478
diff changeset
  1194
                       rdistinct rsa (set rs \<union> set rsb \<union> {RALTS rs})" in exI)
478
Chengsong
parents: 476
diff changeset
  1195
  apply(rule conjI)
Chengsong
parents: 476
diff changeset
  1196
   prefer 2
Chengsong
parents: 476
diff changeset
  1197
  using grewrites_shape2 apply force
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1198
  using frewrite_rd_grewrites_aux by blast
478
Chengsong
parents: 476
diff changeset
  1199
473
Chengsong
parents: 472
diff changeset
  1200
476
Chengsong
parents: 475
diff changeset
  1201
Chengsong
parents: 475
diff changeset
  1202
lemma frewrites_rd_grewrites:
Chengsong
parents: 475
diff changeset
  1203
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow>
478
Chengsong
parents: 476
diff changeset
  1204
rsimp (RALTS rs1) = rsimp (RALTS rs2)"
476
Chengsong
parents: 475
diff changeset
  1205
  apply(induct rs1 rs2 rule: frewrites.induct)
Chengsong
parents: 475
diff changeset
  1206
   apply simp
479
Chengsong
parents: 478
diff changeset
  1207
  using frewrite_simpeq by presburger
476
Chengsong
parents: 475
diff changeset
  1208
Chengsong
parents: 475
diff changeset
  1209
lemma frewrite_simpeq2:
Chengsong
parents: 475
diff changeset
  1210
  shows "rs1 \<leadsto>f rs2 \<Longrightarrow> rsimp (RALTS (rdistinct rs1 {})) = rsimp (RALTS (rdistinct rs2 {}))"
478
Chengsong
parents: 476
diff changeset
  1211
  apply(subgoal_tac "\<exists> rs3. (rdistinct rs1 {} \<leadsto>g* rs3) \<and> (rdistinct rs2 {} \<leadsto>g* rs3)")
Chengsong
parents: 476
diff changeset
  1212
  using grewrites_equal_rsimp apply fastforce
479
Chengsong
parents: 478
diff changeset
  1213
  by (metis append_self_conv2 frewrite_rd_grewrites list.set(1))
Chengsong
parents: 478
diff changeset
  1214
Chengsong
parents: 478
diff changeset
  1215
Chengsong
parents: 478
diff changeset
  1216
478
Chengsong
parents: 476
diff changeset
  1217
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1218
(*a more refined notion of h\<leadsto>* is needed,
473
Chengsong
parents: 472
diff changeset
  1219
this lemma fails when rs1 contains some RALTS rs where elements
Chengsong
parents: 472
diff changeset
  1220
of rs appear in later parts of rs1, which will be picked up by rs2
Chengsong
parents: 472
diff changeset
  1221
and deduplicated*)
476
Chengsong
parents: 475
diff changeset
  1222
lemma frewrites_simpeq:
473
Chengsong
parents: 472
diff changeset
  1223
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow>
476
Chengsong
parents: 475
diff changeset
  1224
 rsimp (RALTS (rdistinct rs1 {})) = rsimp (RALTS ( rdistinct rs2 {})) "
Chengsong
parents: 475
diff changeset
  1225
  apply(induct rs1 rs2 rule: frewrites.induct)
Chengsong
parents: 475
diff changeset
  1226
   apply simp
478
Chengsong
parents: 476
diff changeset
  1227
  using frewrite_simpeq2 by presburger
476
Chengsong
parents: 475
diff changeset
  1228
473
Chengsong
parents: 472
diff changeset
  1229
Chengsong
parents: 472
diff changeset
  1230
lemma frewrite_single_step:
Chengsong
parents: 472
diff changeset
  1231
  shows " rs2 \<leadsto>f rs3 \<Longrightarrow> rsimp (RALTS rs2) = rsimp (RALTS rs3)"
Chengsong
parents: 472
diff changeset
  1232
  apply(induct rs2 rs3 rule: frewrite.induct)
Chengsong
parents: 472
diff changeset
  1233
    apply simp
Chengsong
parents: 472
diff changeset
  1234
  using simp_flatten apply blast
Chengsong
parents: 472
diff changeset
  1235
  by (metis (no_types, opaque_lifting) list.simps(9) rsimp.simps(2) simp_flatten2)
Chengsong
parents: 472
diff changeset
  1236
Chengsong
parents: 472
diff changeset
  1237
lemma frewrites_equivalent_simp:
Chengsong
parents: 472
diff changeset
  1238
  shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> rsimp (RALTS rs1) = rsimp (RALTS rs2)"
Chengsong
parents: 472
diff changeset
  1239
  apply(induct rs1 rs2 rule: frewrites.induct)
Chengsong
parents: 472
diff changeset
  1240
   apply simp
Chengsong
parents: 472
diff changeset
  1241
  using frewrite_single_step by presburger
Chengsong
parents: 472
diff changeset
  1242
476
Chengsong
parents: 475
diff changeset
  1243
lemma grewrite_simpalts:
Chengsong
parents: 475
diff changeset
  1244
  shows " rs2 \<leadsto>g rs3 \<Longrightarrow> rsimp (rsimp_ALTs rs2) = rsimp (rsimp_ALTs rs3)"
Chengsong
parents: 475
diff changeset
  1245
  apply(induct rs2 rs3 rule : grewrite.induct)
Chengsong
parents: 475
diff changeset
  1246
  using identity_wwo0 apply presburger
Chengsong
parents: 475
diff changeset
  1247
  apply (metis frewrite.intros(1) frewrite_single_step identity_wwo0 rsimp_ALTs.simps(3) simp_flatten)
Chengsong
parents: 475
diff changeset
  1248
  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
  1249
  apply simp
Chengsong
parents: 475
diff changeset
  1250
  apply(subst rsimp_alts_equal)
Chengsong
parents: 475
diff changeset
  1251
  apply(case_tac "rsa = [] \<and> rsb = [] \<and> rsc = []")
Chengsong
parents: 475
diff changeset
  1252
   apply(subgoal_tac "rsa @ a # rsb @ rsc = [a]")
Chengsong
parents: 475
diff changeset
  1253
  apply (simp only:)
Chengsong
parents: 475
diff changeset
  1254
  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
  1255
   apply simp
Chengsong
parents: 475
diff changeset
  1256
  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
  1257
Chengsong
parents: 475
diff changeset
  1258
Chengsong
parents: 475
diff changeset
  1259
lemma grewrites_simpalts:
Chengsong
parents: 475
diff changeset
  1260
  shows " rs2 \<leadsto>g* rs3 \<Longrightarrow> rsimp (rsimp_ALTs rs2) = rsimp (rsimp_ALTs rs3)"
Chengsong
parents: 475
diff changeset
  1261
  apply(induct rs2 rs3 rule: grewrites.induct)
Chengsong
parents: 475
diff changeset
  1262
   apply simp
Chengsong
parents: 475
diff changeset
  1263
  using grewrite_simpalts by presburger
473
Chengsong
parents: 472
diff changeset
  1264
476
Chengsong
parents: 475
diff changeset
  1265
473
Chengsong
parents: 472
diff changeset
  1266
Chengsong
parents: 472
diff changeset
  1267
Chengsong
parents: 472
diff changeset
  1268
467
Chengsong
parents: 465
diff changeset
  1269
lemma simp_der_flts:
471
Chengsong
parents: 469
diff changeset
  1270
  shows "rsimp (RALTS (rdistinct (map (rder x) (rflts rs)) {})) = 
Chengsong
parents: 469
diff changeset
  1271
         rsimp (RALTS (rdistinct (rflts (map (rder x) rs)) {}))"
473
Chengsong
parents: 472
diff changeset
  1272
  apply(subgoal_tac "map (rder x) (rflts rs) \<leadsto>f* rflts (map (rder x) rs)")
478
Chengsong
parents: 476
diff changeset
  1273
  using frewrites_simpeq apply presburger
Chengsong
parents: 476
diff changeset
  1274
  using early_late_der_frewrites by auto
Chengsong
parents: 476
diff changeset
  1275
Chengsong
parents: 476
diff changeset
  1276
  
476
Chengsong
parents: 475
diff changeset
  1277
Chengsong
parents: 475
diff changeset
  1278
Chengsong
parents: 475
diff changeset
  1279
Chengsong
parents: 475
diff changeset
  1280
Chengsong
parents: 475
diff changeset
  1281
 
Chengsong
parents: 475
diff changeset
  1282
Chengsong
parents: 475
diff changeset
  1283
Chengsong
parents: 475
diff changeset
  1284
Chengsong
parents: 475
diff changeset
  1285
lemma simp_der_pierce_flts_prelim:
Chengsong
parents: 475
diff changeset
  1286
  shows "rsimp (rsimp_ALTs (rdistinct (map (rder x) (rflts rs)) {})) 
Chengsong
parents: 475
diff changeset
  1287
       = rsimp (rsimp_ALTs (rdistinct (rflts (map (rder x) rs)) {}))"
478
Chengsong
parents: 476
diff changeset
  1288
  by (metis append.right_neutral grewrite.intros(2) grewrite_simpalts rsimp_ALTs.simps(2) simp_der_flts)
467
Chengsong
parents: 465
diff changeset
  1289
Chengsong
parents: 465
diff changeset
  1290
465
Chengsong
parents: 456
diff changeset
  1291
lemma simp_der_pierce_flts:
471
Chengsong
parents: 469
diff changeset
  1292
  shows " rsimp (
Chengsong
parents: 469
diff changeset
  1293
rsimp_ALTs (rdistinct (map (rder x) (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {})
Chengsong
parents: 469
diff changeset
  1294
) =
Chengsong
parents: 469
diff changeset
  1295
          rsimp (
Chengsong
parents: 469
diff changeset
  1296
rsimp_ALTs (rdistinct (rflts (map (rder x) (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {})
Chengsong
parents: 469
diff changeset
  1297
)"
476
Chengsong
parents: 475
diff changeset
  1298
  using simp_der_pierce_flts_prelim by presburger
465
Chengsong
parents: 456
diff changeset
  1299
453
Chengsong
parents: 451
diff changeset
  1300
Chengsong
parents: 451
diff changeset
  1301
Chengsong
parents: 451
diff changeset
  1302
lemma simp_more_distinct:
465
Chengsong
parents: 456
diff changeset
  1303
  shows "rsimp  (rsimp_ALTs (rsa @ rs)) = rsimp (rsimp_ALTs (rsa @ (rdistinct rs (set rsa)))) "
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1304
  oops
465
Chengsong
parents: 456
diff changeset
  1305
453
Chengsong
parents: 451
diff changeset
  1306
Chengsong
parents: 451
diff changeset
  1307
lemma non_empty_list:
Chengsong
parents: 451
diff changeset
  1308
  shows "a \<in> set as \<Longrightarrow> as \<noteq> []"
Chengsong
parents: 451
diff changeset
  1309
  by (metis empty_iff empty_set)
Chengsong
parents: 451
diff changeset
  1310
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1311
lemma distinct_comp:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1312
  shows "rdistinct (rs1@rs2) {} = (rdistinct rs1 {}) @ (rdistinct rs2 (set rs1))"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1313
  apply(induct rs2 arbitrary: rs1)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1314
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1315
  apply(subgoal_tac "rs1 @ a # rs2 = (rs1 @ [a]) @ rs2")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1316
   apply(simp only:)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1317
   apply(case_tac "a \<in> set rs1")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1318
    apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1319
  oops
453
Chengsong
parents: 451
diff changeset
  1320
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1321
lemma instantiate1:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1322
  shows "\<lbrakk>\<And>ab rset1.  rdistinct (ab # as) rset1 = rdistinct (ab # as @ [ab]) rset1\<rbrakk> \<Longrightarrow>  
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1323
rdistinct (aa # as) rset = rdistinct (aa # as @ [aa]) rset"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1324
  apply(drule_tac x = "aa" in meta_spec)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1325
  apply(drule_tac x = "rset" in meta_spec)
453
Chengsong
parents: 451
diff changeset
  1326
  apply simp
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1327
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1328
  
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1329
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1330
lemma not_head_elem:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1331
  shows " \<lbrakk>aa \<in> set (a # as); aa \<notin> (set as)\<rbrakk> \<Longrightarrow> a = aa"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1332
  
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1333
  by fastforce
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1334
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1335
(*
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1336
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1337
  apply (metis append_Cons)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1338
  apply(case_tac "ab \<in> rset1")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1339
  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
  1340
  apply(subgoal_tac "rdistinct (ab # (aa # as) @ [ab]) rset1 = 
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1341
               ab # (rdistinct ((aa # as) @ [ab]) (insert ab rset1))")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1342
   apply(simp only:)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1343
   apply(subgoal_tac "rdistinct (ab # aa # as) rset1 = ab # (rdistinct (aa # as) (insert ab rset1))")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1344
  apply(simp only:)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1345
    apply(subgoal_tac "rdistinct ((aa # as) @ [ab]) (insert ab rset1) = rdistinct (aa # as) (insert ab rset1)")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1346
  apply blast
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1347
*)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1348
  
453
Chengsong
parents: 451
diff changeset
  1349
Chengsong
parents: 451
diff changeset
  1350
lemma flts_identity1:
Chengsong
parents: 451
diff changeset
  1351
  shows  "rflts (rs @ [RONE]) = rflts rs @ [RONE] "
Chengsong
parents: 451
diff changeset
  1352
  apply(induct rs)
Chengsong
parents: 451
diff changeset
  1353
   apply simp+
Chengsong
parents: 451
diff changeset
  1354
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
  1355
       apply simp
Chengsong
parents: 451
diff changeset
  1356
      apply simp+
Chengsong
parents: 451
diff changeset
  1357
  done
Chengsong
parents: 451
diff changeset
  1358
Chengsong
parents: 451
diff changeset
  1359
lemma flts_identity10:
Chengsong
parents: 451
diff changeset
  1360
  shows " rflts (rs @ [RCHAR c]) = rflts rs @ [RCHAR c]"
Chengsong
parents: 451
diff changeset
  1361
  apply(induct rs)
Chengsong
parents: 451
diff changeset
  1362
   apply simp+
Chengsong
parents: 451
diff changeset
  1363
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
  1364
       apply simp+
Chengsong
parents: 451
diff changeset
  1365
  done
Chengsong
parents: 451
diff changeset
  1366
Chengsong
parents: 451
diff changeset
  1367
lemma flts_identity11:
Chengsong
parents: 451
diff changeset
  1368
  shows " rflts (rs @ [RSEQ r1 r2]) = rflts rs @ [RSEQ r1 r2]"
Chengsong
parents: 451
diff changeset
  1369
  apply(induct rs)
Chengsong
parents: 451
diff changeset
  1370
   apply simp+
Chengsong
parents: 451
diff changeset
  1371
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
  1372
       apply simp+
Chengsong
parents: 451
diff changeset
  1373
  done
Chengsong
parents: 451
diff changeset
  1374
Chengsong
parents: 451
diff changeset
  1375
lemma flts_identity12:
Chengsong
parents: 451
diff changeset
  1376
  shows " rflts (rs @ [RSTAR r0]) = rflts rs @ [RSTAR r0]"
Chengsong
parents: 451
diff changeset
  1377
  apply(induct rs)
Chengsong
parents: 451
diff changeset
  1378
   apply simp+
Chengsong
parents: 451
diff changeset
  1379
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
  1380
       apply simp+
Chengsong
parents: 451
diff changeset
  1381
  done
Chengsong
parents: 451
diff changeset
  1382
Chengsong
parents: 451
diff changeset
  1383
lemma flts_identity2:
Chengsong
parents: 451
diff changeset
  1384
  shows "a \<noteq> RZERO \<and> (\<forall>rs. a \<noteq> RALTS rs) \<Longrightarrow>  rflts (rs @ [a]) = rflts rs @ [a]"
Chengsong
parents: 451
diff changeset
  1385
  apply(case_tac a)
Chengsong
parents: 451
diff changeset
  1386
       apply simp
Chengsong
parents: 451
diff changeset
  1387
  using flts_identity1 apply auto[1]
Chengsong
parents: 451
diff changeset
  1388
  using flts_identity10 apply blast
Chengsong
parents: 451
diff changeset
  1389
  using flts_identity11 apply auto[1]
Chengsong
parents: 451
diff changeset
  1390
   apply blast
Chengsong
parents: 451
diff changeset
  1391
  using flts_identity12 by presburger
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1392
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1393
lemma flts_identity3:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1394
  shows "a = RZERO  \<Longrightarrow> rflts (rs @ [a]) = rflts rs"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1395
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1396
  apply(induct rs)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1397
   apply simp+
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1398
  apply(case_tac aa)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1399
       apply simp+
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1400
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1401
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1402
lemma distinct_removes_last3:
465
Chengsong
parents: 456
diff changeset
  1403
  shows "\<lbrakk>a \<in> set as\<rbrakk>
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1404
    \<Longrightarrow> rdistinct as {} = rdistinct (as @ [a]) {}"
465
Chengsong
parents: 456
diff changeset
  1405
  by (simp add: distinct_removes_last2)
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1406
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1407
lemma set_inclusion_with_flts1:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1408
  shows " \<lbrakk>RONE \<in> set rs\<rbrakk> \<Longrightarrow> RONE  \<in> set (rflts rs)"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1409
  apply(induct rs)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1410
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1411
  apply(case_tac " RONE \<in> set rs")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1412
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1413
  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
  1414
  apply(case_tac "RONE = a")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1415
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1416
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1417
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1418
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1419
lemma set_inclusion_with_flts10:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1420
  shows " \<lbrakk>RCHAR x \<in> set rs\<rbrakk> \<Longrightarrow> RCHAR x  \<in> set (rflts rs)"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1421
  apply(induct rs)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1422
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1423
  apply(case_tac " RCHAR x \<in> set rs")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1424
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1425
  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
  1426
  apply(case_tac "RCHAR x = a")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1427
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1428
  apply fastforce
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1429
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1430
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1431
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1432
lemma set_inclusion_with_flts11:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1433
  shows " \<lbrakk>RSEQ r1 r2 \<in> set rs\<rbrakk> \<Longrightarrow> RSEQ r1 r2  \<in> set (rflts rs)"
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1434
  apply(induct rs)
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1435
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1436
  apply(case_tac " RSEQ r1 r2 \<in> set rs")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1437
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1438
  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
  1439
  apply(case_tac "RSEQ r1 r2 = a")
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1440
   apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1441
  apply fastforce
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1442
  apply simp
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1443
  done
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1444
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1445
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1446
lemma set_inclusion_with_flts:
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1447
  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
  1448
  by (simp add: set_inclusion_with_flts1)
453
Chengsong
parents: 451
diff changeset
  1449
  
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1450
lemma can_spill_lst:"\<And>x5. \<lbrakk>a \<in> set as; rsimp a \<in> set (map rsimp as); rsimp a = RALTS x5\<rbrakk>
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1451
          \<Longrightarrow> rsimp_ALTs (rdistinct (rflts (map rsimp as @ [rsimp a])) {}) = 
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1452
rsimp_ALTs (rdistinct (rflts (map rsimp as @ x5)) {})"
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1453
  
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1454
  using flts_append rflts_spills_last rsimp_inner_idem4 by presburger
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1455
  
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1456
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1457
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1458
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1459
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1460
lemma common_rewrites_equal:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1461
  shows "(rs1 \<leadsto>g* rs3) \<and> (rs2 \<leadsto>g* rs3) \<Longrightarrow> rsimp (rsimp_ALTs rs1 ) = rsimp (rsimp_ALTs rs2)"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1462
  using grewrites_simpalts by force
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1463
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1464
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1465
lemma basic_regex_property1:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1466
  shows "rnullable r \<Longrightarrow> rsimp r \<noteq> RZERO"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1467
  apply(induct r rule: rsimp.induct)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1468
  apply(auto)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1469
  apply (metis idiot idiot2 rrexp.distinct(5))
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1470
  by (metis der_simp_nullability rnullable.simps(1) rnullable.simps(4) rsimp.simps(2))
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1471
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1472
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1473
thm rsimp_SEQ.elims
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1474
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1475
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1476
lemma basic_rsimp_SEQ_property2:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1477
  shows "\<lbrakk>r1 \<noteq> RZERO ; r1 \<noteq> RONE; r2 \<noteq> RZERO\<rbrakk> \<Longrightarrow>rsimp_SEQ r1 r2 = RSEQ r1 r2"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1478
  apply(case_tac r1)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1479
       apply simp+
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1480
     apply (simp add: idiot2)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1481
  using idiot2 apply blast
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1482
  using idiot2 apply auto[1]
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1483
  using idiot2 by blast
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1484
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1485
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1486
(*
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1487
lemma rderssimp_same_rewrites_rder_induct1:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1488
  shows "\<lbrakk> ([rder x (rsimp r1)] \<leadsto>g* rs1) \<and> ([rder x r1] \<leadsto>g* rs1) ;
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1489
 ([rder x (rsimp r2)] \<leadsto>g* rs2) \<and> ([rder x r2] \<leadsto>g* rs2) \<rbrakk> \<Longrightarrow> 
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1490
\<exists>rs3. ([rder x (rsimp (RSEQ r1 r2))] \<leadsto>g* rs3) \<and> ([rder x (RSEQ r1 r2)] \<leadsto>g* rs3) "
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1491
  sorry
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1492
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1493
lemma rderssimp_same_rewrites_rder_induct2:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1494
  shows "\<lbrakk> ([rder x (rsimp r1)] \<leadsto>g* rs1) \<and> ([rder x r1] \<leadsto>g* rs1) \<rbrakk> \<Longrightarrow> 
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1495
\<exists>rs3. ([rder x (rsimp (RSTAR r1))] \<leadsto>g* rs3) \<and> ([rder x (RSTAR r1)] \<leadsto>g* rs3) "
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1496
  sorry
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1497
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1498
lemma rderssimp_same_rewrites_rder_induct3:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1499
  shows "\<lbrakk> ([rder x (rsimp r1)] \<leadsto>g* rs1) \<and> ([rder x r1] \<leadsto>g* rs1) ;
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1500
 ([rder x (rsimp r2)] \<leadsto>g* rs2) \<and> ([rder x r2] \<leadsto>g* rs2) \<rbrakk> \<Longrightarrow> 
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1501
\<exists>rs3. ([rder x (rsimp (RALT r1 r2))] \<leadsto>g* rs3) \<and> ([rder x (RALT r1 r2)] \<leadsto>g* rs3) "
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1502
  sorry
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1503
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1504
lemma rderssimp_same_rewrites_rder_induct4:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1505
  shows "\<lbrakk>\<forall>r \<in> set rs. \<exists> rsa. ([rder x (rsimp r)] \<leadsto>g* rsa ) \<and> ([rder x r] \<leadsto>g* rsa) \<rbrakk> \<Longrightarrow> 
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1506
\<exists>rsb. ([rder x (rsimp (RALTS rs))]  \<leadsto>g* rsb) \<and> ([rder x (RALTS rs)] \<leadsto>g* rsb) "
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1507
  sorry
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1508
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1509
lemma rderssimp_same_rewrites_rder_base1:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1510
  shows "([rder x (rsimp RONE)] \<leadsto>g* [] ) \<and> ([rder x RONE] \<leadsto>g* [])"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1511
  by (simp add: gr_in_rstar grewrite.intros(1))
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1512
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1513
lemma rderssimp_same_rewrites_rder_base2:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1514
  shows " ([rder x (rsimp RZERO)] \<leadsto>g* [] ) \<and> ([rder x RZERO] \<leadsto>g* [])"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1515
  using rderssimp_same_rewrites_rder_base1 by auto
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1516
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1517
lemma rderssimp_same_rewrites_rder_base3:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1518
  shows " ([rder x (rsimp (RCHAR c))] \<leadsto>g* [] ) \<and> ([rder x (RCHAR c)] \<leadsto>g* [])"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1519
  sorry
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1520
*)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1521
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1522
lemma inside_simp_seq_nullable:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1523
  shows 
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1524
"\<And>r1 r2.
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1525
       \<lbrakk>rsimp (rder x (rsimp r1)) = rsimp (rder x r1); rsimp (rder x (rsimp r2)) = rsimp (rder x r2);
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1526
        rnullable r1\<rbrakk>
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1527
       \<Longrightarrow> rsimp (rder x (rsimp_SEQ (rsimp r1) (rsimp r2))) =
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1528
           rsimp_ALTs (rdistinct (rflts [rsimp_SEQ (rsimp (rder x r1)) (rsimp r2), rsimp (rder x r2)]) {})"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1529
  apply(case_tac "rsimp r1 = RONE")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1530
   apply(simp)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1531
  apply(subst basic_rsimp_SEQ_property1)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1532
   apply (simp add: idem_after_simp1)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1533
  apply(case_tac "rsimp r1 = RZERO")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1534
  
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1535
  using basic_regex_property1 apply blast
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1536
  apply(case_tac "rsimp r2 = RZERO")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1537
  
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1538
  apply (simp add: basic_rsimp_SEQ_property3)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1539
  apply(subst basic_rsimp_SEQ_property2)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1540
     apply simp+
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1541
  apply(subgoal_tac "rnullable (rsimp r1)")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1542
   apply simp
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1543
  using rsimp_idem apply presburger
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1544
  using der_simp_nullability by presburger
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1545
  
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1546
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1547
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1548
lemma grewrite_ralts:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1549
  shows "rs \<leadsto>g rs' \<Longrightarrow> RALTS rs h\<leadsto>* RALTS rs'"
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1550
  by (smt (verit) grewrite_cases_middle hr_in_rstar hrewrite.intros(11) hrewrite.intros(7) hrewrite.intros(8))
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1551
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1552
lemma grewrites_ralts:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1553
  shows "rs \<leadsto>g* rs' \<Longrightarrow> RALTS rs h\<leadsto>* RALTS rs'"
488
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1554
  apply(induct rule: grewrites.induct)
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1555
  apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1556
  using grewrite_ralts hreal_trans by blast
488
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1557
  
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1558
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1559
lemma distinct_grewrites_subgoal1:
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1560
  shows "  
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1561
       \<lbrakk>rs1 \<leadsto>g* [a]; RALTS rs1 h\<leadsto>* a; [a] \<leadsto>g rs3\<rbrakk> \<Longrightarrow> RALTS rs1 h\<leadsto>* rsimp_ALTs rs3"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1562
  apply(subgoal_tac "RALTS rs1 h\<leadsto>* RALTS rs3")
488
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1563
  apply (metis hrewrite.intros(10) hrewrite.intros(9) rs2 rsimp_ALTs.cases rsimp_ALTs.simps(1) rsimp_ALTs.simps(2) rsimp_ALTs.simps(3))
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1564
  apply(subgoal_tac "rs1 \<leadsto>g* rs3")
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1565
  using grewrites_ralts apply blast
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1566
  using grewrites.intros(2) by presburger
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1567
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1568
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1569
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1570
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1571
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1572
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1573
lemma grewrites_ralts_rsimpalts:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1574
  shows "rs \<leadsto>g* rs' \<Longrightarrow> RALTS rs h\<leadsto>* rsimp_ALTs rs' "
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1575
  apply(induct rs rs' rule: grewrites.induct)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1576
   apply(case_tac rs)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1577
  using hrewrite.intros(9) apply force
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1578
   apply(case_tac list)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1579
  apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1580
  using hr_in_rstar hrewrite.intros(10) rsimp_ALTs.simps(2) apply presburger
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1581
   apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1582
  apply(case_tac rs2)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1583
   apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1584
   apply (metis grewrite.intros(3) grewrite_singleton rsimp_ALTs.simps(1))
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1585
  apply(case_tac list)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1586
   apply(simp)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1587
  using distinct_grewrites_subgoal1 apply blast
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1588
  apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1589
  apply(case_tac rs3)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1590
   apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1591
  using grewrites_ralts hrewrite.intros(9) apply blast
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1592
  by (metis (no_types, opaque_lifting) grewrite_ralts hr_in_rstar hreal_trans hrewrite.intros(10) neq_Nil_conv rsimp_ALTs.simps(2) rsimp_ALTs.simps(3))
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1593
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1594
lemma hrewrites_alts:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1595
  shows " r h\<leadsto>* r' \<Longrightarrow> (RALTS (rs1 @ [r] @ rs2)) h\<leadsto>* (RALTS  (rs1 @ [r'] @ rs2))"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1596
  apply(induct r r' rule: hrewrites.induct)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1597
  apply simp
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1598
  using hrewrite.intros(6) by blast
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1599
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1600
inductive 
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1601
  srewritescf:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" (" _ scf\<leadsto>* _" [100, 100] 100)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1602
where
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1603
  ss1: "[] scf\<leadsto>* []"
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1604
| ss2: "\<lbrakk>r h\<leadsto>* r'; rs scf\<leadsto>* rs'\<rbrakk> \<Longrightarrow> (r#rs) scf\<leadsto>* (r'#rs')"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1605
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1606
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1607
lemma hrewrites_alts_cons:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1608
  shows " RALTS rs h\<leadsto>* RALTS rs' \<Longrightarrow> RALTS (r # rs) h\<leadsto>* RALTS (r # rs')"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1609
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1610
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1611
  oops
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1612
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1613
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1614
lemma srewritescf_alt: "rs1 scf\<leadsto>* rs2 \<Longrightarrow> (RALTS (rs@rs1)) h\<leadsto>* (RALTS (rs@rs2))"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1615
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1616
  apply(induct rs1 rs2 arbitrary: rs rule: srewritescf.induct)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1617
   apply(rule rs1)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1618
  apply(drule_tac x = "rsa@[r']" in meta_spec)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1619
  apply simp
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1620
  apply(rule hreal_trans)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1621
   prefer 2
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1622
   apply(assumption)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1623
  apply(drule hrewrites_alts)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1624
  by auto
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1625
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1626
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1627
corollary srewritescf_alt1: 
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1628
  assumes "rs1 scf\<leadsto>* rs2"
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1629
  shows "RALTS rs1 h\<leadsto>* RALTS rs2"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1630
  using assms
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1631
  by (metis append_Nil srewritescf_alt)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1632
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1633
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1634
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1635
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1636
lemma trivialrsimp_srewrites: 
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1637
  "\<lbrakk>\<And>x. x \<in> set rs \<Longrightarrow> x h\<leadsto>* f x \<rbrakk> \<Longrightarrow> rs scf\<leadsto>* (map f rs)"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1638
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1639
  apply(induction rs)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1640
   apply simp
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1641
   apply(rule ss1)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1642
  by (metis insert_iff list.simps(15) list.simps(9) srewritescf.simps)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1643
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1644
lemma hrewrites_list: 
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1645
  shows
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1646
" (\<And>xa. xa \<in> set x \<Longrightarrow> xa h\<leadsto>* rsimp xa) \<Longrightarrow> RALTS x h\<leadsto>* RALTS (map rsimp x)"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1647
  apply(induct x)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1648
   apply(simp)+
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1649
  by (simp add: srewritescf_alt1 ss2 trivialrsimp_srewrites)
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1650
(*  apply(subgoal_tac "RALTS x h\<leadsto>* RALTS (map rsimp x)")*)
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1651
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1652
  
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1653
lemma hrewrite_simpeq:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1654
  shows "r1 h\<leadsto> r2 \<Longrightarrow> rsimp r1 = rsimp r2"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1655
  apply(induct rule: hrewrite.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1656
            apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1657
  apply (simp add: basic_rsimp_SEQ_property3)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1658
  apply (simp add: basic_rsimp_SEQ_property1)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1659
  using rsimp.simps(1) apply presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1660
        apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1661
  using flts_middle0 apply force
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1662
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1663
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1664
  using simp_flatten3 apply presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1665
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1666
  apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1667
  apply (simp add: idem_after_simp1)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1668
  using grewrite.intros(4) grewrite_equal_rsimp by presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1669
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1670
lemma hrewrites_simpeq:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1671
  shows "r1 h\<leadsto>* r2 \<Longrightarrow> rsimp r1 = rsimp r2"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1672
  apply(induct rule: hrewrites.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1673
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1674
  apply(subgoal_tac "rsimp r2 = rsimp r3")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1675
   apply auto[1]
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1676
  using hrewrite_simpeq by presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1677
  
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1678
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1679
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1680
lemma simp_hrewrites:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1681
  shows "r1 h\<leadsto>* rsimp r1"
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1682
  apply(induct r1)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1683
       apply simp+
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1684
    apply(case_tac "rsimp r11 = RONE")
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1685
     apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1686
     apply(subst basic_rsimp_SEQ_property1)
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1687
  apply(subgoal_tac "RSEQ r11 r12 h\<leadsto>* RSEQ RONE r12")
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1688
  using hreal_trans hrewrite.intros(3) apply blast
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1689
  using hrewrites_seq_context apply presburger
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1690
    apply(case_tac "rsimp r11 = RZERO")
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1691
     apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1692
  using hrewrite.intros(1) hrewrites_seq_context apply blast
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1693
    apply(case_tac "rsimp r12 = RZERO")
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1694
     apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1695
  apply(subst basic_rsimp_SEQ_property3)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1696
  apply (meson hrewrite.intros(2) hrewrites.simps hrewrites_seq_context2)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1697
    apply(subst basic_rsimp_SEQ_property2)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1698
       apply simp+
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1699
  using hrewrites_seq_contexts apply presburger
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1700
   apply simp
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1701
   apply(subgoal_tac "RALTS x h\<leadsto>* RALTS (map rsimp x)")
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1702
  apply(subgoal_tac "RALTS (map rsimp x) h\<leadsto>* rsimp_ALTs (rdistinct (rflts (map rsimp x)) {}) ")
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1703
  using hreal_trans apply blast
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1704
    apply (meson flts_gstar greal_trans grewrites_ralts_rsimpalts gstar_rdistinct)
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1705
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1706
   apply (simp add: grewrites_ralts hrewrites_list)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1707
  by simp
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1708
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1709
lemma interleave_aux1:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1710
  shows " RALT (RSEQ RZERO r1) r h\<leadsto>*  r"
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1711
  apply(subgoal_tac "RSEQ RZERO r1 h\<leadsto>* RZERO")
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1712
  apply(subgoal_tac "RALT (RSEQ RZERO r1) r h\<leadsto>* RALT RZERO r")
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1713
  apply (meson grewrite.intros(1) grewrite_ralts hreal_trans hrewrite.intros(10) hrewrites.simps)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1714
  using rs1 srewritescf_alt1 ss1 ss2 apply presburger
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1715
  by (simp add: hr_in_rstar hrewrite.intros(1))
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1716
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1717
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1718
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1719
lemma rnullable_hrewrite:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1720
  shows "r1 h\<leadsto> r2 \<Longrightarrow> rnullable r1 = rnullable r2"
488
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1721
  apply(induct rule: hrewrite.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1722
            apply simp+
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1723
     apply blast
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1724
    apply simp+
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1725
  done
465
Chengsong
parents: 456
diff changeset
  1726
453
Chengsong
parents: 451
diff changeset
  1727
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1728
lemma interleave1:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1729
  shows "r h\<leadsto> r' \<Longrightarrow> rder c r h\<leadsto>* rder c r'"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1730
  apply(induct r r' rule: hrewrite.induct)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1731
            apply (simp add: hr_in_rstar hrewrite.intros(1))
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1732
  apply (metis (no_types, lifting) basic_rsimp_SEQ_property3 list.simps(8) list.simps(9) rder.simps(1) rder.simps(5) rdistinct.simps(1) rflts.simps(1) rflts.simps(2) rsimp.simps(1) rsimp.simps(2) rsimp.simps(3) rsimp_ALTs.simps(1) simp_hrewrites)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1733
          apply simp
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1734
          apply(subst interleave_aux1)
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1735
          apply simp
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1736
         apply(case_tac "rnullable r1")
488
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1737
          apply simp
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1738
  
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1739
          apply (simp add: hrewrites_seq_context rnullable_hrewrite srewritescf_alt1 ss1 ss2)
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1740
  
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1741
         apply (simp add: hrewrites_seq_context rnullable_hrewrite)
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1742
        apply(case_tac "rnullable r1")
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1743
  apply simp
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1744
  
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1745
  using hr_in_rstar hrewrites_seq_context2 srewritescf_alt1 ss1 ss2 apply presburger
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1746
  apply simp
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1747
  using hr_in_rstar hrewrites_seq_context2 apply blast
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1748
       apply simp
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1749
  
488
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1750
  using hrewrites_alts apply auto[1]
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1751
  apply simp
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1752
  using grewrite.intros(1) grewrite_append grewrite_ralts apply auto[1]
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1753
  apply simp
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1754
  apply (simp add: grewrite.intros(2) grewrite_append grewrite_ralts)
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1755
  apply (simp add: hr_in_rstar hrewrite.intros(9))
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1756
   apply (simp add: hr_in_rstar hrewrite.intros(10))
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1757
  apply simp
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1758
  using hrewrite.intros(11) by auto
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1759
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1760
lemma interleave_star1:
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1761
  shows "r h\<leadsto>* r' \<Longrightarrow> rder c r h\<leadsto>* rder c r'"
488
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1762
  apply(induct rule : hrewrites.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1763
   apply simp
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1764
  by (meson hreal_trans interleave1)
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1765
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1766
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1767
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1768
lemma inside_simp_removal:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1769
  shows " rsimp (rder x (rsimp r)) = rsimp (rder x r)"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1770
  apply(induct r)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1771
       apply simp+
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1772
    apply(case_tac "rnullable r1")
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1773
     apply simp
456
26a5e640cdd7 realPhdThesis
Chengsong
parents: 453
diff changeset
  1774
  
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1775
  using inside_simp_seq_nullable apply blast
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1776
    apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1777
  apply (smt (verit, del_insts) basic_rsimp_SEQ_property2 basic_rsimp_SEQ_property3 der_simp_nullability rder.simps(1) rder.simps(5) rnullable.simps(2) rsimp.simps(1) rsimp_SEQ.simps(1) rsimp_idem)
492
61eff2abb0b6 problem with erase
Chengsong
parents: 491
diff changeset
  1778
   apply(subgoal_tac "rder x (RALTS xa) h\<leadsto>* rder x (rsimp (RALTS xa))")
488
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1779
  using hrewrites_simpeq apply presburger
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1780
  using interleave_star1 simp_hrewrites apply presburger
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  1781
  by simp
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1782
  
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1783
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1784
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1785
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1786
lemma rders_simp_same_simpders:
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1787
  shows "s \<noteq> [] \<Longrightarrow> rders_simp r s = rsimp (rders r s)"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1788
  apply(induct s rule: rev_induct)
453
Chengsong
parents: 451
diff changeset
  1789
   apply simp
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1790
  apply(case_tac "xs = []")
453
Chengsong
parents: 451
diff changeset
  1791
   apply simp
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1792
  apply(simp add: rders_append rders_simp_append)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1793
  using inside_simp_removal by blast
453
Chengsong
parents: 451
diff changeset
  1794
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1795
453
Chengsong
parents: 451
diff changeset
  1796
Chengsong
parents: 451
diff changeset
  1797
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1798
lemma distinct_der:
480
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1799
  shows "rsimp (rsimp_ALTs (map (rder x) (rdistinct rs {}))) = 
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1800
         rsimp (rsimp_ALTs (rdistinct (map (rder x) rs) {}))"
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1801
  by (metis grewrites_simpalts gstar_rdistinct inside_simp_removal rder_rsimp_ALTs_commute)
574749f5190b a few more
Chengsong
parents: 479
diff changeset
  1802
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1803
453
Chengsong
parents: 451
diff changeset
  1804
  
Chengsong
parents: 451
diff changeset
  1805
Chengsong
parents: 451
diff changeset
  1806
Chengsong
parents: 451
diff changeset
  1807
lemma rders_simp_lambda:
Chengsong
parents: 451
diff changeset
  1808
  shows " rsimp \<circ> rder x \<circ> (\<lambda>r. rders_simp r xs) = (\<lambda>r. rders_simp r (xs @ [x]))"
Chengsong
parents: 451
diff changeset
  1809
  using rders_simp_append by auto
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1810
453
Chengsong
parents: 451
diff changeset
  1811
lemma rders_simp_nonempty_simped:
Chengsong
parents: 451
diff changeset
  1812
  shows "xs \<noteq> [] \<Longrightarrow> rsimp \<circ> (\<lambda>r. rders_simp r xs) = (\<lambda>r. rders_simp r xs)"
Chengsong
parents: 451
diff changeset
  1813
  using rders_simp_same_simpders rsimp_idem by auto
Chengsong
parents: 451
diff changeset
  1814
Chengsong
parents: 451
diff changeset
  1815
lemma repeated_altssimp:
Chengsong
parents: 451
diff changeset
  1816
  shows "\<forall>r \<in> set rs. rsimp r = r \<Longrightarrow> rsimp (rsimp_ALTs (rdistinct (rflts rs) {})) =
Chengsong
parents: 451
diff changeset
  1817
           rsimp_ALTs (rdistinct (rflts rs) {})"
Chengsong
parents: 451
diff changeset
  1818
  by (metis map_idI rsimp.simps(2) rsimp_idem)
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1819
465
Chengsong
parents: 456
diff changeset
  1820
Chengsong
parents: 456
diff changeset
  1821
lemma add0_isomorphic:
Chengsong
parents: 456
diff changeset
  1822
  shows "rsimp_ALTs (rdistinct (rflts [rsimp r, RZERO]) {}) = rsimp r"
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1823
  by (metis append.left_neutral append_Cons flts_removes0 idem_after_simp1)
465
Chengsong
parents: 456
diff changeset
  1824
Chengsong
parents: 456
diff changeset
  1825
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  1826
465
Chengsong
parents: 456
diff changeset
  1827
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1828
lemma alts_closed_form: shows 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1829
"rsimp (rders_simp (RALTS rs) s) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1830
rsimp (RALTS (map (\<lambda>r. rders_simp r s) rs))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1831
  apply(induct s rule: rev_induct)
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1832
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1833
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1834
  apply(subst rders_simp_append)
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1835
  apply(subgoal_tac " rsimp (rders_simp (rders_simp (RALTS rs) xs) [x]) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1836
 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
  1837
   prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1838
  apply (metis inside_simp_removal rders_simp_one_char)
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1839
  apply(simp only: )
451
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1840
  apply(subst rders_simp_one_char)
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1841
  apply(subst rsimp_idem)
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1842
  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
  1843
                     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
  1844
  prefer 2
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1845
  using rder_rsimp_ALTs_commute apply presburger
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1846
  apply(simp only:)
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1847
  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
  1848
= 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
  1849
   prefer 2
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1850
  
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1851
  using distinct_der apply presburger
7a016eeb118d finiteness
Chengsong
parents: 445
diff changeset
  1852
  apply(simp only:)
453
Chengsong
parents: 451
diff changeset
  1853
  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
  1854
                      rsimp (rsimp_ALTs (rdistinct ( (rflts (map (rder x) (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs)))) {}))")
Chengsong
parents: 451
diff changeset
  1855
   apply(simp only:)
Chengsong
parents: 451
diff changeset
  1856
  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
  1857
                      rsimp (rsimp_ALTs (rdistinct (rflts ( (map (rsimp \<circ> (rder x) \<circ> (\<lambda>r. rders_simp r xs)) rs))) {}))")
Chengsong
parents: 451
diff changeset
  1858
    apply(simp only:)
Chengsong
parents: 451
diff changeset
  1859
  apply(subst rders_simp_lambda)
Chengsong
parents: 451
diff changeset
  1860
    apply(subst rders_simp_nonempty_simped)
Chengsong
parents: 451
diff changeset
  1861
     apply simp
Chengsong
parents: 451
diff changeset
  1862
    apply(subgoal_tac "\<forall>r \<in> set  (map (\<lambda>r. rders_simp r (xs @ [x])) rs). rsimp r = r")
Chengsong
parents: 451
diff changeset
  1863
  prefer 2
Chengsong
parents: 451
diff changeset
  1864
     apply (simp add: rders_simp_same_simpders rsimp_idem)
Chengsong
parents: 451
diff changeset
  1865
    apply(subst repeated_altssimp)
Chengsong
parents: 451
diff changeset
  1866
     apply simp
Chengsong
parents: 451
diff changeset
  1867
  apply fastforce
465
Chengsong
parents: 456
diff changeset
  1868
   apply (metis inside_simp_removal list.map_comp rder.simps(4) rsimp.simps(2) rsimp_idem)
476
Chengsong
parents: 475
diff changeset
  1869
  using simp_der_pierce_flts by blast
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1870
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1871
lemma alts_closed_form_variant: shows 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1872
"s \<noteq> [] \<Longrightarrow> rders_simp (RALTS rs) s = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  1873
rsimp (RALTS (map (\<lambda>r. rders_simp r s) rs))"
478
Chengsong
parents: 476
diff changeset
  1874
  by (metis alts_closed_form comp_apply rders_simp_nonempty_simped)
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1875
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1876
thm vsuf.simps
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1877
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  1878
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1879
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1880
lemma rsimp_seq_equal1:
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1881
  shows "rsimp_SEQ (rsimp r1) (rsimp r2) = rsimp_ALTs (rdistinct (rflts [rsimp_SEQ (rsimp r1) (rsimp r2)]) {})"
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1882
  by (metis idem_after_simp1 rsimp.simps(1))
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1883
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1884
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1885
483
Chengsong
parents: 482
diff changeset
  1886
Chengsong
parents: 482
diff changeset
  1887
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1888
fun sflat_aux :: "rrexp  \<Rightarrow> rrexp list " where
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1889
  "sflat_aux (RALTS (r # rs)) = sflat_aux r @ rs"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1890
| "sflat_aux (RALTS []) = []"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1891
| "sflat_aux r = [r]"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1892
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1893
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1894
fun sflat :: "rrexp \<Rightarrow> rrexp" where
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1895
  "sflat (RALTS (r # [])) = r"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1896
| "sflat (RALTS (r # rs)) = RALTS (sflat_aux r @ rs)"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1897
| "sflat r = r"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1898
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1899
inductive created_by_seq:: "rrexp \<Rightarrow> bool" where
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1900
  "created_by_seq (RSEQ r1 r2) "
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1901
| "created_by_seq r1 \<Longrightarrow> created_by_seq (RALT r1 r2)"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1902
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1903
(*Why \<and> rnullable case would be provable.....?*)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1904
lemma seq_der_shape:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1905
  shows "\<forall>r1 r2. \<exists>r3 r4. (rder c (RSEQ r1 r2) = RSEQ r3 r4 \<or> rder c (RSEQ r1 r2) = RALT r3 r4)"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1906
  by (meson rder.simps(5))
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1907
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1908
lemma alt_der_shape:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1909
  shows "\<forall>rs. \<exists> rs'. (rder c (RALTS rs)) = RALTS (map (rder c) rs)"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1910
  by force
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1911
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1912
lemma seq_ders_shape1:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1913
  shows "\<forall>r1 r2. \<exists>r3 r4. (rders (RSEQ r1 r2) s) = RSEQ r3 r4 \<or> (rders (RSEQ r1 r2) s) = RALT r3 r4"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1914
  apply(induct s rule: rev_induct)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1915
   apply auto[1]
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1916
  apply(rule allI)+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1917
  apply(subst rders_append)+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1918
  apply(subgoal_tac " \<exists>r3 r4. rders (RSEQ r1 r2) xs = RSEQ r3 r4 \<or> rders (RSEQ r1 r2) xs = RALT r3 r4 ")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1919
   apply(erule exE)+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1920
   apply(erule disjE)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1921
    apply simp+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1922
  done
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1923
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1924
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1925
lemma seq_ders_shape2:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1926
  shows "rders (RSEQ r1 r2) s = RALTS (ra # rb # rs) \<Longrightarrow> rs = []"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1927
  using seq_ders_shape1
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1928
  by (metis list.inject rrexp.distinct(25) rrexp.inject(3))
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1929
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1930
lemma created_by_seq_der:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1931
  shows "created_by_seq r \<Longrightarrow> created_by_seq (rder c r)"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1932
  apply(induct r)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1933
  apply simp+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1934
  
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1935
  using created_by_seq.cases apply blast
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1936
  
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1937
  apply (meson created_by_seq.cases rrexp.distinct(19) rrexp.distinct(21))
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1938
  apply (metis created_by_seq.simps rder.simps(5))
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1939
   apply (smt (verit, ccfv_threshold) created_by_seq.simps list.set_intros(1) list.simps(8) list.simps(9) rder.simps(4) rrexp.distinct(25) rrexp.inject(3))
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1940
  using created_by_seq.intros(1) by force
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1941
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1942
lemma createdbyseq_left_creatable:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1943
  shows "created_by_seq (RALT r1 r2) \<Longrightarrow> created_by_seq r1"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1944
  using created_by_seq.cases by blast
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1945
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1946
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1947
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1948
lemma recursively_derseq:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1949
  shows " created_by_seq (rders (RSEQ r1 r2) s)"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1950
  apply(induct s rule: rev_induct)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1951
   apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1952
  using created_by_seq.intros(1) apply force
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1953
  apply(subgoal_tac "created_by_seq (rders (RSEQ r1 r2) (xs @ [x]))")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1954
  apply blast
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1955
  apply(subst rders_append)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1956
  apply(subgoal_tac "\<exists>r3 r4. rders (RSEQ r1 r2) xs = RSEQ r3 r4 \<or> 
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1957
                    rders (RSEQ r1 r2) xs = RALT r3 r4")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1958
   prefer 2
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1959
  using seq_ders_shape1 apply presburger
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1960
  apply(erule exE)+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1961
  apply(erule disjE)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1962
   apply(subgoal_tac "created_by_seq (rders (RSEQ r3 r4) [x])")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1963
    apply presburger
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1964
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1965
  using created_by_seq.intros(1) created_by_seq.intros(2) apply presburger
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1966
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1967
  apply(subgoal_tac "created_by_seq r3")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1968
  prefer 2
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1969
  using createdbyseq_left_creatable apply blast
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1970
  using created_by_seq.intros(2) created_by_seq_der by blast
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  1971
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1972
  
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1973
lemma recursively_derseq1:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1974
  shows "r = rders (RSEQ r1 r2) s \<Longrightarrow> created_by_seq r"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1975
  using recursively_derseq by blast
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1976
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1977
lemma recursively_derseq2:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1978
  shows "r = rders (RSEQ r1 r2) s \<Longrightarrow> \<exists>r1 r2. r = RSEQ r1 r2 \<or> (r = RALT r1 r2 \<and> created_by_seq r1) "
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1979
  by (meson created_by_seq.cases recursively_derseq)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1980
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1981
lemma recursively_derseq3:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1982
  shows "created_by_seq r \<Longrightarrow> \<exists>r1 r2. r = RSEQ r1 r2 \<or> (r = RALT r1 r2 \<and> created_by_seq r1) "
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1983
  by (meson created_by_seq.cases recursively_derseq)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1984
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1985
lemma createdbyseq_prop1:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1986
  shows "created_by_seq (RALTS xs) \<Longrightarrow> \<exists> ra rb. xs = [ra, rb]"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1987
  by (metis created_by_seq.cases rrexp.inject(3) rrexp.simps(30))
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1988
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1989
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1990
lemma sfau_head:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1991
  shows " created_by_seq r \<Longrightarrow> \<exists>ra rb rs. sflat_aux r = RSEQ ra rb # rs"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1992
  apply(induction r rule: created_by_seq.induct)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1993
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1994
  by fastforce
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1995
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1996
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1997
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1998
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  1999
lemma sfaux_eq10:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2000
  shows "created_by_seq r3 \<Longrightarrow> 
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2001
rs \<noteq> [] \<Longrightarrow> sflat (RALTS ((map (rder c) (sflat_aux r3)) @ (map (rder c) rs))) = 
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2002
RALTS (sflat_aux (rder c r3) @ (map (rder c ) rs) )"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2003
  apply(induction r3 arbitrary: rs rule: created_by_seq.induct)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2004
   apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2005
   apply(case_tac "rnullable r1")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2006
    apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2007
  
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2008
  apply (metis append_Cons list.exhaust map_is_Nil_conv self_append_conv2 sflat.simps(2) sflat_aux.simps(1) sflat_aux.simps(6))
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2009
   apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2010
  
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2011
  apply (metis Nil_is_map_conv append_Cons append_Nil list.exhaust sflat.simps(2) sflat_aux.simps(6))
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2012
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2013
  by force
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  2014
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2015
lemma sfaux_keeps_tail:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2016
  shows "created_by_seq r3 \<Longrightarrow>  
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2017
         sflat_aux (RALTS (map (rder c) (sflat_aux r3) @ xs )) = 
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2018
         sflat_aux (RALTS (map (rder c) (sflat_aux r3))) @ xs  "
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2019
  using sfau_head by fastforce
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2020
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2021
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2022
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  2023
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2024
lemma sfaux_eq00:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2025
  shows "created_by_seq r3 \<Longrightarrow> 
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2026
 sflat_aux (RALTS ((map (rder c) (sflat_aux r3)) @ (map (rder c) rs))) = 
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2027
 (sflat_aux (rder c r3) @ (map (rder c ) rs) )"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2028
  apply(induct rs rule: rev_induct)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2029
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2030
  apply (smt (verit, del_insts) append_Cons created_by_seq.simps list.distinct(1) list.simps(9) map_append rder.simps(4) rrexp.inject(3) self_append_conv self_append_conv2 sfau_head sfaux_eq10 sflat_aux.simps(1) sflat_aux.simps(6))
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2031
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2032
  apply(subst sfaux_keeps_tail)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2033
   apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2034
  apply(subst (asm) sfaux_keeps_tail)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2035
  apply simp+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2036
  done
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2037
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2038
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2039
lemma sfaux_eq1:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2040
  shows "created_by_seq r3 \<Longrightarrow> sflat (RALTS ((map (rder c) (sflat_aux r3)) @ [rder c r4])) = RALTS (sflat_aux (rder c r3) @ [rder c r4] )"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2041
  by (metis (no_types, lifting) list.distinct(1) list.simps(9) map_append map_concat_cons self_append_conv sfaux_eq10)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2042
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2043
lemma sflat_seq_induct:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2044
  shows "sflat (rder c (sflat (rders (RSEQ r1 r2) s) )) = sflat (rders (RSEQ r1 r2) (s @ [c]))"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2045
  apply(subst rders_append)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2046
  apply(case_tac "rders (RSEQ r1 r2) s ")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2047
  prefer 6
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2048
       apply simp+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2049
  apply(subgoal_tac "\<exists>r3 r4. x5 = [r3, r4]")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2050
  apply(erule exE)+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2051
   apply(subgoal_tac "sflat (rder c (sflat (RALT r3 r4))) = sflat (RALTS (map (rder c) [r3, r4]))")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2052
    apply meson
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2053
   apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2054
  
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2055
  apply (metis createdbyseq_left_creatable recursively_derseq sfaux_eq1)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2056
  by (metis created_by_seq.simps recursively_derseq rrexp.distinct(25) rrexp.inject(3))
484
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  2057
15f02ec4d9fe changeto sflat def
Chengsong
parents: 483
diff changeset
  2058
483
Chengsong
parents: 482
diff changeset
  2059
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2060
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2061
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2062
lemma vsuf_prop1:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2063
  shows "vsuf (xs @ [x]) r = (if (rnullable (rders r xs)) 
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2064
                                then [x] # (map (\<lambda>s. s @ [x]) (vsuf xs r) )
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2065
                                else (map (\<lambda>s. s @ [x]) (vsuf xs r)) ) 
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2066
             "
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2067
  apply(induct xs arbitrary: r)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2068
   apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2069
  apply(case_tac "rnullable r")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2070
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2071
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2072
  done
483
Chengsong
parents: 482
diff changeset
  2073
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2074
fun  breakHead :: "rrexp list \<Rightarrow> rrexp list" where
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2075
  "breakHead [] = [] "
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2076
| "breakHead (RALT r1 r2 # rs) = r1 # r2 # rs"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2077
| "breakHead (r # rs) = r # rs"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2078
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2079
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2080
lemma sfau_idem_der:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2081
  shows "created_by_seq r \<Longrightarrow> sflat_aux (rder c r) = breakHead (map (rder c) (sflat_aux r))"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2082
  apply(induct rule: created_by_seq.induct)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2083
   apply simp+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2084
  using sfau_head by fastforce
483
Chengsong
parents: 482
diff changeset
  2085
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2086
lemma vsuf_compose1:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2087
  shows " \<not> rnullable (rders r1 xs)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2088
       \<Longrightarrow> map (rder x \<circ> rders r2) (vsuf xs r1) = map (rders r2) (vsuf (xs @ [x]) r1)"
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2089
  apply(subst vsuf_prop1)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2090
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2091
  by (simp add: rders_append)
483
Chengsong
parents: 482
diff changeset
  2092
  
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2093
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2094
483
Chengsong
parents: 482
diff changeset
  2095
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2096
lemma seq_sfau0:
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2097
  shows  "sflat_aux (rders (RSEQ r1 r2) s) = (RSEQ (rders r1 s) r2) #
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2098
                                       (map (rders r2) (vsuf s r1)) "
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2099
  apply(induct s rule: rev_induct)
483
Chengsong
parents: 482
diff changeset
  2100
   apply simp
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2101
  apply(subst rders_append)+
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2102
  apply(subgoal_tac "created_by_seq (rders (RSEQ r1 r2) xs)")
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2103
  prefer 2
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2104
  using recursively_derseq1 apply blast
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2105
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2106
  apply(subst sfau_idem_der)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2107
  
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2108
   apply blast
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2109
  apply(case_tac "rnullable (rders r1 xs)")
483
Chengsong
parents: 482
diff changeset
  2110
   apply simp
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2111
   apply(subst vsuf_prop1)
483
Chengsong
parents: 482
diff changeset
  2112
  apply simp
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2113
  apply (simp add: rders_append)
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2114
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2115
  using vsuf_compose1 by blast
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2116
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2117
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2118
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2119
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2120
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2121
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2122
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2123
483
Chengsong
parents: 482
diff changeset
  2124
Chengsong
parents: 482
diff changeset
  2125
thm sflat.elims
Chengsong
parents: 482
diff changeset
  2126
Chengsong
parents: 482
diff changeset
  2127
Chengsong
parents: 482
diff changeset
  2128
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2129
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2130
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2131
lemma sflat_rsimpeq:
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2132
  shows "created_by_seq r1 \<Longrightarrow> sflat_aux r1 =  rs \<Longrightarrow> rsimp r1 = rsimp (RALTS rs)"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2133
  apply(induct r1 arbitrary: rs rule:  created_by_seq.induct)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2134
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2135
  using rsimp_seq_equal1 apply force
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2136
  by (metis head_one_more_simp rsimp.simps(2) sflat_aux.simps(1) simp_flatten)
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2137
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2138
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2139
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2140
lemma seq_closed_form_general:
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2141
  shows "rsimp (rders (RSEQ r1 r2) s) = 
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2142
rsimp ( (RALTS ( (RSEQ (rders r1 s) r2 # (map (rders r2) (vsuf s r1))))))"
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2143
  apply(case_tac "s \<noteq> []")
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2144
  apply(subgoal_tac "created_by_seq (rders (RSEQ r1 r2) s)")
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2145
  apply(subgoal_tac "sflat_aux (rders (RSEQ r1 r2) s) = RSEQ (rders r1 s) r2 # (map (rders r2) (vsuf s r1))")
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2146
  using sflat_rsimpeq apply blast
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2147
    apply (simp add: seq_sfau0)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2148
  using recursively_derseq1 apply blast
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2149
  apply simp
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2150
  by (metis idem_after_simp1 rsimp.simps(1))
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2151
  
485
72edbac05c59 central lemma for seqclosedforms
Chengsong
parents: 484
diff changeset
  2152
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2153
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2154
lemma seq_closed_form_aux1:
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2155
  shows "rsimp ( (RALTS ( (RSEQ (rders r1 s) r2 # (map (rders r2) (vsuf s r1)))))) =
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2156
rsimp ( (RALTS ( (RSEQ (rders_simp r1 s) r2 # (map (rders r2) (vsuf s r1))))))"
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2157
  by (smt (verit, best) list.simps(9) rders.simps(1) rders_simp.simps(1) rders_simp_same_simpders rsimp.simps(1) rsimp.simps(2) rsimp_idem)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2158
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2159
lemma add_simp_to_rest:
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2160
  shows "rsimp (RALTS (r # rs)) = rsimp (RALTS (r # map rsimp rs))"
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2161
  by (metis append_Nil2 grewrite.intros(2) grewrite_simpalts head_one_more_simp list.simps(9) rsimp_ALTs.simps(2) spawn_simp_rsimpalts)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2162
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2163
lemma rsimp_compose_der:
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2164
  shows "map rsimp (map (rders r) ss) = map (\<lambda>s. rsimp (rders r s)) ss"
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2165
  apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2166
  done
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2167
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2168
lemma rsimp_compose_der2:
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2169
  shows "\<forall>s \<in> set ss. s \<noteq> [] \<Longrightarrow> map rsimp (map (rders r) ss) = map (\<lambda>s.  (rders_simp r s)) ss"  
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2170
  by (simp add: rders_simp_same_simpders)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2171
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2172
lemma vsuf_nonempty:
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2173
  shows "\<forall>s \<in> set ( vsuf s1 r). s \<noteq> []"
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2174
  apply(induct s1 arbitrary: r)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2175
   apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2176
  apply simp
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2177
  done
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2178
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2179
lemma rsimp_compose_der3:
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2180
  shows " map rsimp (map (rders r) (vsuf s1 r')) = map (\<lambda>s. rsimp  (rders_simp r s)) (vsuf s1 r')"  
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2181
  by (simp add: rders_simp_same_simpders rsimp_idem vsuf_nonempty)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2182
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2183
thm rders_simp_same_simpders
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2184
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2185
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2186
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2187
lemma seq_closed_form_aux2:
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2188
  shows "s \<noteq> [] \<Longrightarrow> rsimp ( (RALTS ( (RSEQ (rders_simp r1 s) r2 # (map (rders r2) (vsuf s r1)))))) = 
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2189
         rsimp ( (RALTS ( (RSEQ (rders_simp r1 s) r2 # (map (rders_simp r2) (vsuf s r1))))))"
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2190
  
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2191
  by (metis add_simp_to_rest rsimp_compose_der2 vsuf_nonempty)
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2192
  
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2193
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  2194
lemma seq_closed_form: shows 
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  2195
"rsimp (rders_simp (RSEQ r1 r2) s) = 
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  2196
rsimp ( RALTS ( (RSEQ (rders_simp r1 s) r2) # 
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2197
                (map (rders_simp r2) (vsuf s r1)) 
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  2198
              )  
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  2199
      )"
482
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2200
  apply(case_tac s )
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2201
   apply simp  
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2202
  apply (metis idem_after_simp1 rsimp.simps(1))
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2203
  apply(subgoal_tac " s \<noteq> []")
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2204
  using rders_simp_same_simpders rsimp_idem seq_closed_form_aux1 seq_closed_form_aux2 seq_closed_form_general apply presburger
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2205
  by fastforce
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2206
  
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2207
4bf2367e6e53 closedformseq
Chengsong
parents: 480
diff changeset
  2208
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  2209
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  2210
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  2211
lemma seq_closed_form_variant: shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  2212
"s \<noteq> [] \<Longrightarrow> (rders_simp (RSEQ r1 r2) s) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  2213
rsimp (RALTS ((RSEQ (rders_simp r1 s) r2) # (map (rders_simp r2) (vsuf s r1))))"
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2214
  apply(induct s rule: rev_induct)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2215
   apply simp
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2216
  apply(subst rders_simp_append)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2217
  apply(subst rders_simp_one_char)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2218
  apply(subst rsimp_idem[symmetric])
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2219
  apply(subst rders_simp_one_char[symmetric])
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2220
  apply(subst rders_simp_append[symmetric])
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2221
  apply(insert seq_closed_form)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2222
  apply(subgoal_tac "rsimp (rders_simp (RSEQ r1 r2) (xs @ [x]))
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2223
 = rsimp (RALTS (RSEQ (rders_simp r1 (xs @ [x])) r2 # map (rders_simp r2) (vsuf (xs @ [x]) r1)))")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2224
   apply force
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
  2225
  by presburger
443
c6351a96bf80 writeupforclosedforms
Chengsong
parents:
diff changeset
  2226
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2227
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2228
lemma star_closed_form_seq1:
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2229
  shows "sflat_aux (rders (RSTAR r0) (c # s)) = 
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2230
   RSEQ (rders (rder c r0) s) (RSTAR r0) #
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2231
                                       map (rders (RSTAR r0)) (vsuf s (rder c r0))"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2232
  apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2233
  using seq_sfau0 by blast
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2234
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2235
fun hflat_aux :: "rrexp \<Rightarrow> rrexp list" where
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2236
  "hflat_aux (RALT r1 r2) = hflat_aux r1 @ hflat_aux r2"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2237
| "hflat_aux r = [r]"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2238
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2239
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2240
fun hflat :: "rrexp \<Rightarrow> rrexp" where
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2241
  "hflat (RALT r1 r2) = RALTS ((hflat_aux r1) @ (hflat_aux r2))"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2242
| "hflat r = r"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2243
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2244
inductive created_by_star :: "rrexp \<Rightarrow> bool" where
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2245
  "created_by_star (RSEQ ra (RSTAR rb))"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2246
| "\<lbrakk>created_by_star r1; created_by_star r2\<rbrakk> \<Longrightarrow> created_by_star (RALT r1 r2)"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2247
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2248
fun hElem :: "rrexp  \<Rightarrow> rrexp list" where
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2249
  "hElem (RALT r1 r2) = (hElem r1 ) @ (hElem r2)"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2250
| "hElem r = [r]"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2251
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2252
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2253
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2254
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2255
lemma cbs_ders_cbs:
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2256
  shows "created_by_star r \<Longrightarrow> created_by_star (rder c r)"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2257
  apply(induct r rule: created_by_star.induct)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2258
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2259
  using created_by_star.intros(1) created_by_star.intros(2) apply auto[1]
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2260
  by (metis (mono_tags, lifting) created_by_star.simps list.simps(8) list.simps(9) rder.simps(4))
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2261
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2262
lemma star_ders_cbs:
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2263
  shows "created_by_star (rders (RSEQ r1 (RSTAR r2)) s)"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2264
  apply(induct s rule: rev_induct)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2265
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2266
   apply (simp add: created_by_star.intros(1))
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2267
  apply(subst rders_append)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2268
  apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2269
  using cbs_ders_cbs by auto
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2270
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2271
lemma created_by_star_cases:
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2272
  shows "created_by_star r \<Longrightarrow> \<exists>ra rb. (r = RALT ra rb \<and> created_by_star ra \<and> created_by_star rb) \<or> r = RSEQ ra rb "
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2273
  by (meson created_by_star.cases)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2274
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2275
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2276
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2277
lemma hfau_pushin: 
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2278
  shows "created_by_star r \<Longrightarrow> hflat_aux (rder c r) = concat (map hElem (map (rder c) (hflat_aux r)))"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2279
  apply(induct r rule: created_by_star.induct)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2280
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2281
  apply(subgoal_tac "created_by_star (rder c r1)")
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2282
  prefer 2
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2283
  apply(subgoal_tac "created_by_star (rder c r2)")
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2284
  using cbs_ders_cbs apply blast
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2285
  using cbs_ders_cbs apply auto[1]
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2286
  apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2287
  done
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2288
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2289
lemma stupdate_induct1:
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2290
  shows " concat (map (hElem \<circ> (rder x \<circ> (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0)))) Ss) =
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2291
          map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0)) (star_update x r0 Ss)"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2292
  apply(induct Ss)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2293
   apply simp+
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2294
  by (simp add: rders_append)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2295
  
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2296
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2297
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2298
lemma stupdates_join_general:
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2299
  shows  "concat (map hElem (map (rder x) (map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0)) (star_updates xs r0 Ss)))) =
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2300
           map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0)) (star_updates (xs @ [x]) r0 Ss)"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2301
  apply(induct xs arbitrary: Ss)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2302
   apply (simp)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2303
  prefer 2
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2304
   apply auto[1]
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2305
  using stupdate_induct1 by blast
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2306
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2307
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2308
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2309
 
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2310
lemma stupdates_join:
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2311
  shows "concat (map hElem (map (rder x) (map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0)) (star_updates xs r0 [[c]])))) =
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2312
           map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0)) (star_updates (xs @ [x]) r0 [[c]])"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2313
  using stupdates_join_general by auto
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2314
  
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2315
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2316
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2317
lemma star_hfau_induct:
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2318
  shows "hflat_aux (rders (RSEQ (rder c r0) (RSTAR r0)) s) =   
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2319
      map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0)) (star_updates s r0 [[c]])"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2320
  apply(induct s rule: rev_induct)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2321
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2322
  apply(subst rders_append)+
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2323
  apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2324
  apply(subst stupdates_append)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2325
  apply(subgoal_tac "created_by_star (rders (RSEQ (rder c r0) (RSTAR r0)) xs)")
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2326
  prefer 2
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2327
  apply (simp add: star_ders_cbs)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2328
  apply(subst hfau_pushin)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2329
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2330
  apply(subgoal_tac "concat (map hElem (map (rder x) (hflat_aux (rders (RSEQ (rder c r0) (RSTAR r0)) xs)))) =
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2331
                     concat (map hElem (map (rder x) ( map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0)) (star_updates xs r0 [[c]])))) ")
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2332
   apply(simp only:)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2333
  prefer 2
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2334
   apply presburger
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2335
  apply(subst stupdates_append[symmetric])
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2336
  using stupdates_join_general by blast
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2337
487
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2338
lemma starders_hfau_also1:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2339
  shows "hflat_aux (rders (RSTAR r) (c # xs)) = map (\<lambda>s1. RSEQ (rders r s1) (RSTAR r)) (star_updates xs r [[c]])"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2340
  using star_hfau_induct by force
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2341
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2342
lemma hflat_aux_grewrites:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2343
  shows "a # rs \<leadsto>g* hflat_aux a @ rs"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2344
  apply(induct a arbitrary: rs)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2345
       apply simp+
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2346
   apply(case_tac x)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2347
    apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2348
  apply(case_tac list)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2349
  
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2350
  apply (metis append.right_neutral append_Cons append_eq_append_conv2 grewrites.simps hflat_aux.simps(7) same_append_eq)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2351
   apply(case_tac lista)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2352
  apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2353
  apply (metis (no_types, lifting) append_Cons append_eq_append_conv2 gmany_steps_later greal_trans grewrite.intros(2) grewrites_append self_append_conv)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2354
  apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2355
  by simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2356
  
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2357
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2358
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2359
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2360
lemma cbs_hfau_rsimpeq1:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2361
  shows "rsimp (RALT a b) = rsimp (RALTS ((hflat_aux a) @ (hflat_aux b)))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2362
  apply(subgoal_tac "[a, b] \<leadsto>g* hflat_aux a @ hflat_aux b")
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2363
  using grewrites_equal_rsimp apply presburger
488
370dae790b30 more sorrys fileld
Chengsong
parents: 487
diff changeset
  2364
  by (metis append.right_neutral greal_trans grewrites_cons hflat_aux_grewrites)
487
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2365
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2366
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2367
lemma hfau_rsimpeq2:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2368
  shows "created_by_star r \<Longrightarrow> rsimp r = rsimp ( (RALTS (hflat_aux r)))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2369
  apply(induct r)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2370
       apply simp+
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2371
  
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2372
    apply (metis rsimp_seq_equal1)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2373
  prefer 2
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2374
   apply simp
487
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2375
  apply(case_tac x)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2376
   apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2377
  apply(case_tac "list")
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2378
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2379
  
487
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2380
  apply (metis idem_after_simp1)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2381
  apply(case_tac "lista")
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2382
  prefer 2
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2383
   apply (metis hflat_aux.simps(8) idem_after_simp1 list.simps(8) list.simps(9) rsimp.simps(2))
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2384
  apply(subgoal_tac "rsimp (RALT a aa) = rsimp (RALTS (hflat_aux (RALT a aa)))")
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2385
  apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2386
  apply(subgoal_tac "rsimp (RALT a aa) = rsimp (RALTS (hflat_aux a @ hflat_aux aa))")
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2387
  using hflat_aux.simps(1) apply presburger
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2388
  apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2389
  using cbs_hfau_rsimpeq1 by fastforce
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2390
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2391
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2392
lemma hfau_rsimpeq1:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2393
  shows "created_by_star r \<Longrightarrow> hflat_aux r = rs \<Longrightarrow> rsimp r = rsimp (RALTS rs)"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2394
  apply(induct r arbitrary: rs rule: created_by_star.induct )
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2395
  apply (metis created_by_seq.intros(1) hflat_aux.simps(5) sflat_aux.simps(6) sflat_rsimpeq)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2396
  apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2397
  oops
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2398
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2399
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2400
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2401
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2402
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2403
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2404
lemma star_closed_form1:
487
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2405
  shows "rsimp (rders (RSTAR r0) (c#s)) = 
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2406
rsimp ( ( RALTS ( (map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0) ) (star_updates s r0 [[c]]) ) )))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2407
  using hfau_rsimpeq2 rder.simps(6) rders.simps(2) star_ders_cbs starders_hfau_also1 by presburger
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2408
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2409
lemma star_closed_form2:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2410
  shows  "rsimp (rders_simp (RSTAR r0) (c#s)) = 
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2411
rsimp ( ( RALTS ( (map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0) ) (star_updates s r0 [[c]]) ) )))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2412
  by (metis list.distinct(1) rders_simp_same_simpders rsimp_idem star_closed_form1)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2413
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2414
lemma star_closed_form3:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2415
  shows  "rsimp (rders_simp (RSTAR r0) (c#s)) =   (rders_simp (RSTAR r0) (c#s))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2416
  by (metis list.distinct(1) rders_simp_same_simpders star_closed_form1 star_closed_form2)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2417
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2418
lemma star_closed_form4:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2419
  shows " (rders_simp (RSTAR r0) (c#s)) = 
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2420
rsimp ( ( RALTS ( (map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0) ) (star_updates s r0 [[c]]) ) )))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2421
  using star_closed_form2 star_closed_form3 by presburger
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2422
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2423
lemma star_closed_form5:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2424
  shows " rsimp ( ( RALTS ( (map (\<lambda>s1. RSEQ (rders r0 s1) (RSTAR r0) ) Ss         )))) = 
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2425
          rsimp ( ( RALTS ( (map (\<lambda>s1. rsimp (RSEQ (rders r0 s1) (RSTAR r0)) ) Ss ))))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2426
  by (metis (mono_tags, lifting) list.map_comp map_eq_conv o_apply rsimp.simps(2) rsimp_idem)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2427
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2428
lemma star_closed_form6_hrewrites:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2429
  shows "  
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2430
 (map (\<lambda>s1.  (RSEQ (rsimp (rders r0 s1)) (RSTAR r0)) ) Ss )
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2431
 scf\<leadsto>*
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2432
(map (\<lambda>s1. rsimp (RSEQ (rders r0 s1) (RSTAR r0)) ) Ss )"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2433
  apply(induct Ss)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2434
  apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2435
  apply (simp add: ss1)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2436
  by (metis (no_types, lifting) list.simps(9) rsimp.simps(1) rsimp_idem simp_hrewrites ss2)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2437
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2438
lemma star_closed_form6:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2439
  shows " rsimp ( ( RALTS ( (map (\<lambda>s1. rsimp (RSEQ (rders r0 s1) (RSTAR r0)) ) Ss )))) = 
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2440
          rsimp ( ( RALTS ( (map (\<lambda>s1.  (RSEQ (rsimp (rders r0 s1)) (RSTAR r0)) ) Ss ))))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2441
  apply(subgoal_tac " map (\<lambda>s1.  (RSEQ (rsimp (rders r0 s1)) (RSTAR r0)) ) Ss  scf\<leadsto>*
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2442
                      map (\<lambda>s1.  rsimp (RSEQ  (rders r0 s1) (RSTAR r0)) ) Ss ")
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2443
  using hrewrites_simpeq srewritescf_alt1 apply fastforce
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2444
  using star_closed_form6_hrewrites by blast
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2445
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2446
lemma star_closed_form7:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2447
  shows  " (rders_simp (RSTAR r0) (c#s)) = 
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2448
rsimp ( ( RALTS ( (map (\<lambda>s1. RSEQ (rsimp (rders r0 s1)) (RSTAR r0) ) (star_updates s r0 [[c]]) ) )))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2449
  using star_closed_form4 star_closed_form5 star_closed_form6 by presburger
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2450
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2451
lemma derssimp_nonempty_list:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2452
  shows "\<forall>s \<in> set Ss. s \<noteq> [] \<Longrightarrow> 
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2453
 rsimp ( ( RALTS ( (map (\<lambda>s1. RSEQ (rsimp (rders r0 s1)) (RSTAR r0) ) Ss)))) =
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2454
 rsimp ( ( RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) ) Ss)))) "
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2455
  
487
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2456
  by (metis (no_types, lifting) map_eq_conv rders_simp_same_simpders)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2457
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2458
lemma stupdate_nonempty:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2459
  shows "\<forall>s \<in> set  Ss. s \<noteq> [] \<Longrightarrow> \<forall>s \<in> set (star_update c r Ss). s \<noteq> []"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2460
  apply(induct Ss)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2461
  apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2462
  apply(case_tac "rnullable (rders r a)")
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2463
   apply simp+
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2464
  done
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2465
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2466
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2467
lemma stupdates_nonempty:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2468
  shows "\<forall>s \<in> set Ss. s\<noteq> [] \<Longrightarrow> \<forall>s \<in> set (star_updates s r Ss). s \<noteq> []"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2469
  apply(induct s arbitrary: Ss)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2470
   apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2471
  apply simp
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2472
  using stupdate_nonempty by presburger
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2473
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2474
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2475
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2476
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2477
lemma star_closed_form8:
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2478
  shows  
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2479
"rsimp ( ( RALTS ( (map (\<lambda>s1. RSEQ (rsimp (rders r0 s1)) (RSTAR r0) ) (star_updates s r0 [[c]]) ) ))) = 
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2480
 rsimp ( ( RALTS ( (map (\<lambda>s1. RSEQ ( (rders_simp r0 s1)) (RSTAR r0) ) (star_updates s r0 [[c]]) ) )))"
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2481
  by (metis derssimp_nonempty_list neq_Nil_conv non_empty_list set_ConsD stupdates_nonempty)
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2482
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2483
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2484
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2485
lemma star_closed_form:
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2486
  shows "rders_simp (RSTAR r0) (c#s) = 
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2487
rsimp ( RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) ) (star_updates s r0 [[c]]) ) ))"
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2488
  apply(induct s)
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2489
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2490
   apply (metis idem_after_simp1 rsimp.simps(1) rsimp.simps(6) rsimp_idem)
487
9f3d6f09b093 again starClosedForms
Chengsong
parents: 486
diff changeset
  2491
  using star_closed_form4 star_closed_form5 star_closed_form6 star_closed_form8 by presburger
486
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2492
f5b96a532c85 starclosed
Chengsong
parents: 485
diff changeset
  2493
476
Chengsong
parents: 475
diff changeset
  2494
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  2495
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 443
diff changeset
  2496
end