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