thys/Sulzmann.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 29 Jun 2017 17:57:41 +0100
changeset 256 146b4817aebd
parent 255 222ed43892ea
child 286 804fbb227568
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
148
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
   
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
theory Sulzmann
254
7c89d3f6923e polished
Christian Urban <urbanc@in.tum.de>
parents: 248
diff changeset
     3
  imports "Positions" 
148
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
begin
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
section {* Sulzmann's "Ordering" of Values *}
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
     9
inductive ValOrd :: "val \<Rightarrow> val \<Rightarrow> bool" ("_ \<prec> _" [100, 100] 100)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    10
where
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    11
  MY0: "length (flat v2) < length (flat v1) \<Longrightarrow> v1 \<prec> v2" 
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    12
| C2: "\<lbrakk>v1 \<prec> v1'; flat (Seq v1 v2) = flat (Seq v1' v2')\<rbrakk> \<Longrightarrow> (Seq v1 v2) \<prec> (Seq v1' v2')" 
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    13
| C1: "\<lbrakk>v2 \<prec> v2'; flat v2 = flat v2'\<rbrakk> \<Longrightarrow> (Seq v1 v2) \<prec> (Seq v1 v2')" 
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    14
| A2: "flat v1 = flat v2 \<Longrightarrow> (Left v1) \<prec> (Right v2)"
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    15
| A3: "\<lbrakk>v2 \<prec> v2'; flat v2 = flat v2'\<rbrakk> \<Longrightarrow> (Right v2) \<prec> (Right v2')"
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    16
| A4: "\<lbrakk>v1 \<prec> v1'; flat v1 = flat v1'\<rbrakk> \<Longrightarrow> (Left v1) \<prec> (Left v1')"
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    17
| K1: "flat (Stars (v#vs)) = [] \<Longrightarrow> (Stars []) \<prec> (Stars (v#vs))"
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    18
| K3: "\<lbrakk>v1 \<prec> v2; flat (Stars (v1#vs1)) = flat (Stars (v2#vs2))\<rbrakk> \<Longrightarrow> (Stars (v1#vs1)) \<prec> (Stars (v2#vs2))"
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    19
| K4: "\<lbrakk>(Stars vs1) \<prec> (Stars vs2); flat (Stars vs1) = flat (Stars vs2)\<rbrakk>  \<Longrightarrow> (Stars (v#vs1)) \<prec> (Stars (v#vs2))"
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    20
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    21
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    22
(*
245
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    23
inductive ValOrd :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<preceq>_ _" [100, 100, 100] 100)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    24
where
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    25
  C2: "v1 \<preceq>r1 v1' \<Longrightarrow> (Seq v1 v2) \<preceq>(SEQ r1 r2) (Seq v1' v2')" 
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    26
| C1: "v2 \<preceq>r2 v2' \<Longrightarrow> (Seq v1 v2) \<preceq>(SEQ r1 r2) (Seq v1 v2')" 
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    27
| A1: "length (flat v2) > length (flat v1) \<Longrightarrow> (Right v2) \<preceq>(ALT r1 r2) (Left v1)"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    28
| A2: "length (flat v1) \<ge> length (flat v2) \<Longrightarrow> (Left v1) \<preceq>(ALT r1 r2) (Right v2)"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    29
| A3: "v2 \<preceq>r2 v2' \<Longrightarrow> (Right v2) \<preceq>(ALT r1 r2) (Right v2')"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    30
| A4: "v1 \<preceq>r1 v1' \<Longrightarrow> (Left v1) \<preceq>(ALT r1 r2) (Left v1')"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    31
| K1: "flat (Stars (v # vs)) = [] \<Longrightarrow> (Stars []) \<preceq>(STAR r) (Stars (v # vs))"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    32
| K2: "flat (Stars (v # vs)) \<noteq> [] \<Longrightarrow> (Stars (v # vs)) \<preceq>(STAR r) (Stars [])"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    33
| K3: "v1 \<preceq>r v2 \<Longrightarrow> (Stars (v1 # vs1)) \<preceq>(STAR r) (Stars (v2 # vs2))"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    34
| K4: "(Stars vs1) \<preceq>(STAR r) (Stars vs2) \<Longrightarrow> (Stars (v # vs1)) \<preceq>(STAR r) (Stars (v # vs2))"
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    35
*)
248
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    36
(*| MY1: "Void \<preceq>ONE Void" 
245
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    37
| MY2: "(Char c) \<preceq>(CHAR c) (Char c)" 
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    38
| MY3: "(Stars []) \<preceq>(STAR r) (Stars [])" 
248
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    39
*)
245
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    40
248
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    41
(*
245
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    42
lemma ValOrd_refl: 
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    43
  assumes "\<turnstile> v : r" 
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    44
  shows "v \<preceq>r v"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    45
using assms
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    46
apply(induct r rule: Prf.induct)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    47
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    48
apply(simp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    49
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    50
apply(simp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    51
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    52
apply(simp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    53
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    54
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    55
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    56
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    57
apply(simp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    58
done
248
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    59
*)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    60
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    61
lemma ValOrd_irrefl: 
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    62
  assumes "\<turnstile> v : r"  "v \<prec> v" 
248
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    63
  shows "False"
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    64
using assms
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    65
apply(induct v r rule: Prf.induct)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    66
apply(erule ValOrd.cases)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    67
apply(simp_all)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    68
apply(erule ValOrd.cases)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    69
apply(simp_all)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    70
apply(erule ValOrd.cases)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    71
apply(simp_all)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    72
apply(erule ValOrd.cases)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    73
apply(simp_all)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    74
apply(erule ValOrd.cases)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    75
apply(simp_all)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    76
apply(erule ValOrd.cases)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    77
apply(simp_all)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    78
apply(erule ValOrd.cases)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    79
apply(simp_all)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    80
done
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    81
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    82
lemma prefix_sprefix:
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    83
  shows "xs \<sqsubseteq>pre ys \<longleftrightarrow> (xs = ys \<or> xs \<sqsubset>spre ys)"
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    84
apply(auto simp add: sprefix_list_def prefix_list_def)
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    85
done
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    86
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    87
245
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    88
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    89
lemma Posix_CPT2:
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    90
  assumes "v1 \<prec> v2" 
248
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    91
  shows "v1 :\<sqsubset>val v2" 
245
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    92
using assms
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    93
apply(induct v1 v2 arbitrary: rule: ValOrd.induct)
254
7c89d3f6923e polished
Christian Urban <urbanc@in.tum.de>
parents: 248
diff changeset
    94
apply(rule val_ord_shorterI)
248
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    95
apply(simp)
254
7c89d3f6923e polished
Christian Urban <urbanc@in.tum.de>
parents: 248
diff changeset
    96
apply(rule val_ord_SeqI1)
248
b90ff5abb437 added a proof that Positional ordering is equivalent to direct posix definition
Christian Urban <urbanc@in.tum.de>
parents: 247
diff changeset
    97
apply(simp)
245
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
    98
apply(simp)
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
    99
apply(rule val_ord_SeqI2)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   100
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   101
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   102
apply(simp add: val_ord_ex_def)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   103
apply(rule_tac x="[0]" in exI)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   104
apply(auto simp add: val_ord_def Pos_empty pflat_len_simps)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   105
apply(smt inlen_bigger)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   106
apply(rule val_ord_RightI)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   107
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   108
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   109
apply(rule val_ord_LeftI)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   110
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   111
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   112
defer
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   113
apply(rule val_ord_StarsI)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   114
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   115
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   116
apply(rule val_ord_StarsI2)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   117
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   118
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   119
oops
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   120
256
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   121
lemma QQ: 
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   122
  shows "x \<le> (y::nat) \<longleftrightarrow> x = y \<or> x < y"
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   123
  by auto
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   124
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   125
lemma Posix_CPT2:
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   126
  assumes "v1 :\<sqsubset>val v2" "v1 \<in> CPTpre r s" "v2 \<in> CPTpre r s"
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   127
  shows "v1 \<prec> v2"
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   128
using assms
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   129
apply(induct r arbitrary: v1 v2 s)  
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   130
apply(auto simp add: CPTpre_def)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   131
apply(erule CPrf.cases)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   132
apply(simp_all)[7]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   133
apply(auto simp add: CPTpre_def)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   134
apply(erule CPrf.cases)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   135
apply(simp_all)[7]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   136
apply(auto simp add: CPTpre_def)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   137
apply(erule CPrf.cases)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   138
apply(simp_all)[7]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   139
apply(simp add: val_ord_ex_def)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   140
apply(auto simp add: val_ord_def)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   141
apply(auto simp add: CPTpre_def)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   142
apply(erule CPrf.cases)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   143
apply(simp_all)[7]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   144
apply(erule CPrf.cases)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   145
apply(simp_all)[7]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   146
apply(auto simp add: val_ord_ex_def val_ord_def)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   147
(* SEQ case *)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   148
apply(subst (asm) (5) CPTpre_def)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   149
apply(subst (asm) (5) CPTpre_def)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   150
apply(auto)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   151
apply(erule CPrf.cases)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   152
apply(simp_all)[7]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   153
apply(erule CPrf.cases)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   154
apply(simp_all)[7]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   155
apply(clarify)
256
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   156
apply(frule val_ord_shorterE)
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   157
apply(subst (asm) QQ)
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   158
apply(erule disjE)
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   159
apply(drule val_ord_SeqE)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   160
apply(erule disjE)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   161
apply(drule_tac x="v1a" in meta_spec)
256
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   162
apply(rotate_tac 8)
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   163
apply(drule_tac x="v1b" in meta_spec)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   164
apply(drule_tac x="flat v1a @ flat v2a @ s'" in meta_spec)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   165
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   166
apply(drule meta_mp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   167
apply(auto simp add: CPTpre_def)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   168
apply(drule meta_mp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   169
apply(auto simp add: CPTpre_def)[1]
256
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   170
apply(rule ValOrd.intros(2))
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   171
apply(assumption)
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   172
apply(frule val_ord_shorterE)
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   173
apply(subst (asm) append_eq_append_conv_if)
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   174
apply(simp)
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   175
apply (metis append_assoc append_eq_append_conv_if length_append)
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   176
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   177
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   178
thm le
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   179
apply(clarify)
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   180
apply(rule ValOrd.intros)
256
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   181
apply(simp)
146b4817aebd updated
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
   182
255
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   183
apply(subst (asm) (3) CPTpre_def)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   184
apply(subst (asm) (3) CPTpre_def)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   185
apply(auto)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   186
apply(drule_tac meta_mp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   187
apply(auto simp add: CPTpre_def)[1]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   188
apply(erule CPrf.cases)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   189
apply(simp_all)[7]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   190
apply(erule CPrf.cases)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   191
apply(simp_all)[7]
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   192
apply(clarify)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   193
apply(drule val_ord_SeqE)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   194
apply(erule disjE)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   195
apply(simp add: append_eq_append_conv2)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   196
apply(auto)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   197
prefer 2
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   198
apply(rule  ValOrd.intros(2))
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   199
prefer 2
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   200
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   201
thm ValOrd.intros
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   202
apply(case_tac "flat v1b = flat v1a")
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   203
apply(rule ValOrd.intros)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   204
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   205
apply(simp)
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   206
222ed43892ea updated
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
   207
245
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   208
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   209
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   210
lemma Posix_CPT:
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   211
  assumes "v1 :\<sqsubset>val v2" "v1 \<in> CPT r s" "v2 \<in> CPT r s"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   212
  shows "v1 \<preceq>r v2" 
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   213
using assms
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   214
apply(induct r arbitrary: v1 v2 s rule: rexp.induct)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   215
apply(simp add: CPT_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   216
apply(clarify)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   217
apply(erule CPrf.cases)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   218
apply(simp_all)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   219
apply(simp add: CPT_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   220
apply(clarify)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   221
apply(erule CPrf.cases)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   222
apply(simp_all)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   223
apply(erule CPrf.cases)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   224
apply(simp_all)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   225
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   226
apply(simp add: CPT_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   227
apply(clarify)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   228
apply(erule CPrf.cases)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   229
apply(simp_all)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   230
apply(erule CPrf.cases)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   231
apply(simp_all)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   232
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   233
(*SEQ case *)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   234
apply(simp add: CPT_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   235
apply(clarify)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   236
apply(erule CPrf.cases)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   237
apply(simp_all)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   238
apply(clarify)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   239
apply(erule CPrf.cases)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   240
apply(simp_all)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   241
apply(clarify)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   242
thm val_ord_SEQ
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   243
apply(drule_tac r="r1a" in  val_ord_SEQ)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   244
apply(simp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   245
using Prf_CPrf apply blast
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   246
using Prf_CPrf apply blast
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   247
apply(erule disjE)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   248
apply(rule C2)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   249
prefer 2
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   250
apply(simp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   251
apply(rule C1)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   252
apply blast
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   253
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   254
apply(simp add: append_eq_append_conv2)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   255
apply(clarify)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   256
apply(auto)[1]
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   257
apply(drule_tac x="v1a" in meta_spec)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   258
apply(rotate_tac 8)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   259
apply(drule_tac x="v1b" in meta_spec)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   260
apply(rotate_tac 8)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   261
apply(simp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   262
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   263
(* HERE *)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   264
apply(subst (asm) (3) val_ord_ex_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   265
apply(clarify)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   266
apply(subst (asm) val_ord_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   267
apply(clarify)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   268
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   269
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   270
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   271
apply(simp add: val_ord_ex_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   272
oops
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   273
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   274
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   275
lemma ValOrd_trans:
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   276
  assumes "x \<preceq>r y" "y \<preceq>r z"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   277
  and "x \<in> CPT r s" "y \<in> CPT r s" "z \<in> CPT r s"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   278
  shows "x \<preceq>r z"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   279
using assms
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   280
apply(induct x r y arbitrary: s z rule: ValOrd.induct)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   281
apply(rotate_tac 2)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   282
apply(erule ValOrd.cases)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   283
apply(simp_all)[13]
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   284
apply(rule ValOrd.intros)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   285
apply(drule_tac x="s" in meta_spec)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   286
apply(drule_tac x="v1'a" in meta_spec)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   287
apply(drule_tac meta_mp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   288
apply(simp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   289
apply(drule_tac meta_mp)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   290
apply(simp add: CPT_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   291
oops
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   292
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   293
lemma ValOrd_preorder:
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   294
  "preorder_on (CPT r s) {(v1, v2). v1 \<preceq>r v2 \<and> v1 \<in> (CPT r s) \<and> v2 \<in> (CPT r s)}"
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   295
apply(simp add: preorder_on_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   296
apply(rule conjI)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   297
apply(simp add: refl_on_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   298
apply(auto)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   299
apply(rule ValOrd_refl)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   300
apply(simp add: CPT_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   301
apply(rule Prf_CPrf)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   302
apply(auto)[1]
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   303
apply(simp add: trans_def)
b16702bb6242 updated
Christian Urban <urbanc@in.tum.de>
parents: 204
diff changeset
   304
apply(auto)
148
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
definition ValOrdEq :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<ge>_ _" [100, 100, 100] 100)
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
where 
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
  "v\<^sub>1 \<ge>r v\<^sub>2 \<equiv> v\<^sub>1 = v\<^sub>2 \<or> (v\<^sub>1 >r v\<^sub>2 \<and> flat v\<^sub>1 = flat v\<^sub>2)"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
(*
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
inductive ValOrd :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<succ>_ _" [100, 100, 100] 100)
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
where
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
  "v2 \<succ>r2 v2' \<Longrightarrow> (Seq v1 v2) \<succ>(SEQ r1 r2) (Seq v1 v2')" 
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
| "\<lbrakk>v1 \<succ>r1 v1'; v1 \<noteq> v1'\<rbrakk> \<Longrightarrow> (Seq v1 v2) \<succ>(SEQ r1 r2) (Seq v1' v2')" 
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
| "length (flat v1) \<ge> length (flat v2) \<Longrightarrow> (Left v1) \<succ>(ALT r1 r2) (Right v2)"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
| "length (flat v2) > length (flat v1) \<Longrightarrow> (Right v2) \<succ>(ALT r1 r2) (Left v1)"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
| "v2 \<succ>r2 v2' \<Longrightarrow> (Right v2) \<succ>(ALT r1 r2) (Right v2')"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
| "v1 \<succ>r1 v1' \<Longrightarrow> (Left v1) \<succ>(ALT r1 r2) (Left v1')"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
| "Void \<succ>EMPTY Void"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
| "(Char c) \<succ>(CHAR c) (Char c)"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
| "flat (Stars (v # vs)) = [] \<Longrightarrow> (Stars []) \<succ>(STAR r) (Stars (v # vs))"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
| "flat (Stars (v # vs)) \<noteq> [] \<Longrightarrow> (Stars (v # vs)) \<succ>(STAR r) (Stars [])"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
| "\<lbrakk>v1 \<succ>r v2; v1 \<noteq> v2\<rbrakk> \<Longrightarrow> (Stars (v1 # vs1)) \<succ>(STAR r) (Stars (v2 # vs2))"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
| "(Stars vs1) \<succ>(STAR r) (Stars vs2) \<Longrightarrow> (Stars (v # vs1)) \<succ>(STAR r) (Stars (v # vs2))"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
| "(Stars []) \<succ>(STAR r) (Stars [])"
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
*)
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   331
section {* Bit-Encodings *}
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   332
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   333
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   334
fun 
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   335
  code :: "val \<Rightarrow> rexp \<Rightarrow> bool list"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   336
where
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   337
  "code Void ONE = []"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   338
| "code (Char c) (CHAR d) = []"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   339
| "code (Left v) (ALT r1 r2) = False # (code v r1)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   340
| "code (Right v) (ALT r1 r2) = True # (code v r2)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   341
| "code (Seq v1 v2) (SEQ r1 r2) = (code v1 r1) @ (code v2 r2)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   342
| "code (Stars []) (STAR r) = [True]"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   343
| "code (Stars (v # vs)) (STAR r) =  False # (code v r) @ code (Stars vs) (STAR r)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   344
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   345
fun 
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   346
  Stars_add :: "val \<Rightarrow> val \<Rightarrow> val"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   347
where
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   348
  "Stars_add v (Stars vs) = Stars (v # vs)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   349
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   350
function
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   351
  decode' :: "bool list \<Rightarrow> rexp \<Rightarrow> (val * bool list)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   352
where
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   353
  "decode' ds ZERO = (Void, [])"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   354
| "decode' ds ONE = (Void, ds)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   355
| "decode' ds (CHAR d) = (Char d, ds)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   356
| "decode' [] (ALT r1 r2) = (Void, [])"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   357
| "decode' (False # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r1 in (Left v, ds'))"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   358
| "decode' (True # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r2 in (Right v, ds'))"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   359
| "decode' ds (SEQ r1 r2) = (let (v1, ds') = decode' ds r1 in
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   360
                             let (v2, ds'') = decode' ds' r2 in (Seq v1 v2, ds''))"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   361
| "decode' [] (STAR r) = (Void, [])"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   362
| "decode' (True # ds) (STAR r) = (Stars [], ds)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   363
| "decode' (False # ds) (STAR r) = (let (v, ds') = decode' ds r in
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   364
                                    let (vs, ds'') = decode' ds' (STAR r) 
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   365
                                    in (Stars_add v vs, ds''))"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   366
by pat_completeness auto
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   367
204
cd9e40280784 added paper about size derivatives
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
   368
termination
cd9e40280784 added paper about size derivatives
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
   369
apply(size_change)
cd9e40280784 added paper about size derivatives
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
   370
oops
cd9e40280784 added paper about size derivatives
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
   371
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   372
term "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   373
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   374
lemma decode'_smaller:
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   375
  assumes "decode'_dom (ds, r)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   376
  shows "length (snd (decode' ds r)) \<le> length ds"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   377
using assms
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   378
apply(induct ds r)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   379
apply(auto simp add: decode'.psimps split: prod.split)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   380
using dual_order.trans apply blast
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   381
by (meson dual_order.trans le_SucI)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   382
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   383
termination "decode'"  
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   384
apply(relation "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") 
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   385
apply(auto dest!: decode'_smaller)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   386
by (metis less_Suc_eq_le snd_conv)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   387
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   388
fun 
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   389
  decode :: "bool list \<Rightarrow> rexp \<Rightarrow> val option"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   390
where
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   391
  "decode ds r = (let (v, ds') = decode' ds r 
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   392
                  in (if ds' = [] then Some v else None))"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   393
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   394
lemma decode'_code:
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   395
  assumes "\<turnstile> v : r"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   396
  shows "decode' ((code v r) @ ds) r = (v, ds)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   397
using assms
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   398
by (induct v r arbitrary: ds) (auto)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   399
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   400
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   401
lemma decode_code:
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   402
  assumes "\<turnstile> v : r"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   403
  shows "decode (code v r) r = Some v"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   404
using assms decode'_code[of _ _ "[]"]
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   405
by auto
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
   406
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   407
datatype arexp =
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   408
  AZERO
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   409
| AONE "bool list"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   410
| ACHAR "bool list" char
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   411
| ASEQ "bool list" arexp arexp
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   412
| AALT "bool list" arexp arexp
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   413
| ASTAR "bool list" arexp
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   414
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   415
fun fuse :: "bool list \<Rightarrow> arexp \<Rightarrow> arexp" where
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   416
  "fuse bs AZERO = AZERO"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   417
| "fuse bs (AONE cs) = AONE (bs @ cs)" 
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   418
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   419
| "fuse bs (AALT cs r1 r2) = AALT (bs @ cs) r1 r2"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   420
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   421
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   422
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   423
fun internalise :: "rexp \<Rightarrow> arexp" where
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   424
  "internalise ZERO = AZERO"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   425
| "internalise ONE = AONE []"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   426
| "internalise (CHAR c) = ACHAR [] c"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   427
| "internalise (ALT r1 r2) = AALT [] (fuse [False] (internalise r1)) 
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   428
                                     (fuse [True]  (internalise r2))"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   429
| "internalise (SEQ r1 r2) = ASEQ [] (internalise r1) (internalise r2)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   430
| "internalise (STAR r) = ASTAR [] (internalise r)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   431
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   432
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bool list" where
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   433
  "retrieve (AONE bs) Void = bs"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   434
| "retrieve (ACHAR bs c) (Char d) = bs"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   435
| "retrieve (AALT bs r1 r2) (Left v) = bs @ retrieve r1 v"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   436
| "retrieve (AALT bs r1 r2) (Right v) = bs @ retrieve r2 v"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   437
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   438
| "retrieve (ASTAR bs r) (Stars []) = bs @ [True]"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   439
| "retrieve (ASTAR bs r) (Stars (v#vs)) = 
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   440
     bs @ [False] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   441
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   442
fun
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   443
 anullable :: "arexp \<Rightarrow> bool"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   444
where
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   445
  "anullable (AZERO) = False"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   446
| "anullable (AONE bs) = True"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   447
| "anullable (ACHAR bs c) = False"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   448
| "anullable (AALT bs r1 r2) = (anullable r1 \<or> anullable r2)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   449
| "anullable (ASEQ bs r1 r2) = (anullable r1 \<and> anullable r2)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   450
| "anullable (ASTAR bs r) = True"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   451
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   452
fun 
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   453
  amkeps :: "arexp \<Rightarrow> bool list"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   454
where
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   455
  "amkeps(AONE bs) = bs"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   456
| "amkeps(ASEQ bs r1 r2) = bs @ (amkeps r1) @ (amkeps r2)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   457
| "amkeps(AALT bs r1 r2) = (if anullable(r1) then bs @ (amkeps r1) else bs @ (amkeps r2))"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   458
| "amkeps(ASTAR bs r) = bs @ [True]"
148
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   461
fun
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   462
 ader :: "char \<Rightarrow> arexp \<Rightarrow> arexp"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   463
where
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   464
  "ader c (AZERO) = AZERO"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   465
| "ader c (AONE bs) = AZERO"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   466
| "ader c (ACHAR bs d) = (if c = d then AONE bs else AZERO)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   467
| "ader c (AALT bs r1 r2) = AALT bs (ader c r1) (ader c r2)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   468
| "ader c (ASEQ bs r1 r2) = 
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   469
     (if anullable r1
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   470
      then AALT bs (ASEQ [] (ader c r1) r2) (fuse (amkeps r1) (ader c r2))
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   471
      else ASEQ bs (ader c r1) r2)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   472
| "ader c (ASTAR bs r) = ASEQ bs (fuse [False] (ader c r)) (ASTAR [] r)"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   473
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   474
lemma
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   475
  assumes "\<turnstile> v : der c r"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   476
  shows "Some (injval r c v) = decode (retrieve (ader c (internalise r)) v) r"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   477
using assms
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   478
apply(induct c r arbitrary: v rule: der.induct)
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   479
apply(simp_all)
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   480
apply(erule Prf_elims)
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   481
apply(erule Prf_elims)
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   482
apply(case_tac "c = d")
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   483
apply(simp)
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   484
apply(erule Prf_elims)
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   485
apply(simp)
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   486
apply(simp)
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   487
apply(erule Prf_elims)
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   488
apply(auto split: prod.splits)[1]
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   489
oops
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   490
148
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   491
end