thys/Journal/Paper.thy
author Chengsong
Tue, 08 Feb 2022 00:38:27 +0000
changeset 421 d9e1df9ae58f
parent 365 ec5e4fe4cc70
permissions -rw-r--r--
size
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
(*<*)
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
theory Paper
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
imports 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
   "../Lexer"
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
   "../Simplifying" 
280
c840a99a3e05 updated
cu
parents: 275
diff changeset
     6
   "../Positions"
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
     7
   "../Sulzmann"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents: 363
diff changeset
     8
(*   "../SizeBound" *)
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 330
diff changeset
     9
   "HOL-Library.LaTeXsugar"
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
begin
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    12
lemma Suc_0_fold:
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    13
  "Suc 0 = 1"
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    14
by simp
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    15
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    16
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    17
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
declare [[show_question_marks = false]]
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    20
syntax (latex output)
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
    21
  "_Collect" :: "pttrn => bool => 'a set"              ("(1{_ \<^latex>\<open>\\mbox{\\boldmath$\\mid$}\<close> _})")
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    22
  "_CollectIn" :: "pttrn => 'a set => bool => 'a set"   ("(1{_ \<in> _ |e _})")
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    23
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
    24
syntax
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
    25
  "_Not_Ex" :: "idts \<Rightarrow> bool \<Rightarrow> bool"  ("(3\<nexists>_.a./ _)" [0, 10] 10)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
    26
  "_Not_Ex1" :: "pttrn \<Rightarrow> bool \<Rightarrow> bool"  ("(3\<nexists>!_.a./ _)" [0, 10] 10)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
    27
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    28
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
abbreviation 
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    30
  "der_syn r c \<equiv> der c r"
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
abbreviation 
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    33
  "ders_syn r s \<equiv> ders s r"
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    34
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    35
  abbreviation 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    36
  "bder_syn r c \<equiv> bder c r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    37
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    38
abbreviation 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    39
  "bders_syn r s \<equiv> bders r s"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    40
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    41
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    42
abbreviation
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    43
  "nprec v1 v2 \<equiv> \<not>(v1 :\<sqsubset>val v2)"
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    44
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    46
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    47
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
notation (latex output)
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
    49
  If  ("(\<^latex>\<open>\\textrm{\<close>if\<^latex>\<open>}\<close> (_)/ \<^latex>\<open>\\textrm{\<close>then\<^latex>\<open>}\<close> (_)/ \<^latex>\<open>\\textrm{\<close>else\<^latex>\<open>}\<close> (_))" 10) and
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
    50
  Cons ("_\<^latex>\<open>\\mbox{$\\,$}\<close>::\<^latex>\<open>\\mbox{$\\,$}\<close>_" [75,73] 73) and  
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
    52
  ZERO ("\<^bold>0" 81) and 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
    53
  ONE ("\<^bold>1" 81) and 
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 330
diff changeset
    54
  CH ("_" [1000] 80) and
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  ALT ("_ + _" [77,77] 78) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  SEQ ("_ \<cdot> _" [77,77] 78) and
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
    57
  STAR ("_\<^sup>\<star>" [79] 78) and
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    59
  val.Void ("Empty" 78) and
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  val.Char ("Char _" [1000] 78) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  val.Left ("Left _" [79] 78) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  val.Right ("Right _" [1000] 78) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  val.Seq ("Seq _ _" [79,79] 78) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  val.Stars ("Stars _" [79] 78) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  L ("L'(_')" [10] 78) and
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
    67
  LV ("LV _ _" [80,73] 78) and
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  der_syn ("_\\_" [79, 1000] 76) and  
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  ders_syn ("_\\_" [79, 1000] 76) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  flat ("|_|" [75] 74) and
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
    71
  flats ("|_|" [72] 74) and
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  Sequ ("_ @ _" [78,77] 63) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  injval ("inj _ _ _" [79,77,79] 76) and 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  mkeps ("mkeps _" [79] 76) and 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  length ("len _" [73] 73) and
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents: 265
diff changeset
    76
  intlen ("len _" [73] 73) and
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    77
  set ("_" [73] 73) and
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
 
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    79
  Prf ("_ : _" [75,75] 75) and
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  Posix ("'(_, _') \<rightarrow> _" [63,75,75] 75) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  lexer ("lexer _ _" [78,78] 77) and 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  F_RIGHT ("F\<^bsub>Right\<^esub> _") and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  F_LEFT ("F\<^bsub>Left\<^esub> _") and  
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  F_ALT ("F\<^bsub>Alt\<^esub> _ _") and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  F_SEQ1 ("F\<^bsub>Seq1\<^esub> _ _") and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  F_SEQ2 ("F\<^bsub>Seq2\<^esub> _ _") and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  F_SEQ ("F\<^bsub>Seq\<^esub> _ _") and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  simp_SEQ ("simp\<^bsub>Seq\<^esub> _ _" [1000, 1000] 1) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  simp_ALT ("simp\<^bsub>Alt\<^esub> _ _" [1000, 1000] 1) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  slexer ("lexer\<^sup>+" 1000) and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
    93
  at ("_\<^latex>\<open>\\mbox{$\\downharpoonleft$}\<close>\<^bsub>_\<^esub>") and
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    94
  lex_list ("_ \<prec>\<^bsub>lex\<^esub> _") and
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    95
  PosOrd ("_ \<prec>\<^bsub>_\<^esub> _" [77,77,77] 77) and
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    96
  PosOrd_ex ("_ \<prec> _" [77,77] 77) and
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
    97
  PosOrd_ex_eq ("_ \<^latex>\<open>\\mbox{$\\preccurlyeq$}\<close> _" [77,77] 77) and
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    98
  pflat_len ("\<parallel>_\<parallel>\<^bsub>_\<^esub>") and
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
    99
  nprec ("_ \<^latex>\<open>\\mbox{$\\not\\prec$}\<close> _" [77,77] 77) and
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
   100
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   101
  bder_syn ("_\<^latex>\<open>\\mbox{$\\bbslash$}\<close>_" [79, 1000] 76) and  
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   102
  bders_syn ("_\<^latex>\<open>\\mbox{$\\bbslash$}\<close>_" [79, 1000] 76) and
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   103
  intern ("_\<^latex>\<open>\\mbox{$^\\uparrow$}\<close>" [900] 80) and
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   104
  erase ("_\<^latex>\<open>\\mbox{$^\\downarrow$}\<close>" [1000] 74) and
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   105
  bnullable ("nullable\<^latex>\<open>\\mbox{$_b$}\<close> _" [1000] 80) and
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   106
  bmkeps ("mkeps\<^latex>\<open>\\mbox{$_b$}\<close> _" [1000] 80) and
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   107
  blexer ("lexer\<^latex>\<open>\\mbox{$_b$}\<close> _ _" [77, 77] 80) and
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   108
  code ("code _" [79] 74) and
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   109
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   110
  DUMMY ("\<^latex>\<open>\\underline{\\hspace{2mm}}\<close>")
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   111
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
definition 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  "match r s \<equiv> nullable (ders s r)"
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   116
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   117
lemma LV_STAR_ONE_empty: 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   118
  shows "LV (STAR ONE) [] = {Stars []}"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   119
by(auto simp add: LV_def elim: Prf.cases intro: Prf.intros)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   120
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   121
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   122
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
(*
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
comments not implemented
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   126
p9. The condition "not exists s3 s4..." appears often enough (in particular in
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
the proof of Lemma 3) to warrant a definition.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
*)
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   131
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
(*>*)
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   134
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   135
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   136
section \<open>Introduction\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   139
text \<open>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
Brzozowski \cite{Brzozowski1964} introduced the notion of the {\em
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   142
derivative} @{term "der c r"} of a regular expression \<open>r\<close> w.r.t.\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   143
a character~\<open>c\<close>, and showed that it gave a simple solution to the
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   144
problem of matching a string @{term s} with a regular expression @{term
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   145
r}: if the derivative of @{term r} w.r.t.\ (in succession) all the
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   146
characters of the string matches the empty string, then @{term r}
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   147
matches @{term s} (and {\em vice versa}). The derivative has the
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   148
property (which may almost be regarded as its specification) that, for
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   149
every string @{term s} and regular expression @{term r} and character
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   150
@{term c}, one has @{term "cs \<in> L(r)"} if and only if \mbox{@{term "s \<in> L(der c r)"}}. 
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   151
The beauty of Brzozowski's derivatives is that
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   152
they are neatly expressible in any functional language, and easily
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   153
definable and reasoned about in theorem provers---the definitions just
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   154
consist of inductive datatypes and simple recursive functions. A
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
mechanised correctness proof of Brzozowski's matcher in for example HOL4
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   156
has been mentioned by Owens and Slind~\cite{Owens2008}. Another one in
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   157
Isabelle/HOL is part of the work by Krauss and Nipkow \cite{Krauss2011}.
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   158
And another one in Coq is given by Coquand and Siles \cite{Coquand2012}.
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   160
If a regular expression matches a string, then in general there is more
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   161
than one way of how the string is matched. There are two commonly used
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   162
disambiguation strategies to generate a unique answer: one is called
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   163
GREEDY matching \cite{Frisch2004} and the other is POSIX
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   164
matching~\cite{POSIX,Kuklewicz,OkuiSuzuki2010,Sulzmann2014,Vansummeren2006}.
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   165
For example consider the string @{term xy} and the regular expression
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   166
\mbox{@{term "STAR (ALT (ALT x y) xy)"}}. Either the string can be
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   167
matched in two `iterations' by the single letter-regular expressions
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   168
@{term x} and @{term y}, or directly in one iteration by @{term xy}. The
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   169
first case corresponds to GREEDY matching, which first matches with the
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   170
left-most symbol and only matches the next symbol in case of a mismatch
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   171
(this is greedy in the sense of preferring instant gratification to
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   172
delayed repletion). The second case is POSIX matching, which prefers the
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   173
longest match.
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   175
In the context of lexing, where an input string needs to be split up
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   176
into a sequence of tokens, POSIX is the more natural disambiguation
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   177
strategy for what programmers consider basic syntactic building blocks
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   178
in their programs.  These building blocks are often specified by some
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   179
regular expressions, say \<open>r\<^bsub>key\<^esub>\<close> and \<open>r\<^bsub>id\<^esub>\<close> for recognising keywords and identifiers,
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   180
respectively. There are a few underlying (informal) rules behind
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   181
tokenising a string in a POSIX \cite{POSIX} fashion:
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
\begin{itemize} 
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
   184
\item[$\bullet$] \emph{The Longest Match Rule} (or \emph{``{M}aximal {M}unch {R}ule''}):
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
The longest initial substring matched by any regular expression is taken as
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
next token.\smallskip
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
\item[$\bullet$] \emph{Priority Rule:}
265
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
   189
For a particular longest initial substring, the first (leftmost) regular expression
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
   190
that can match determines the token.\smallskip
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
   191
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
   192
\item[$\bullet$] \emph{Star Rule:} A subexpression repeated by ${}^\star$ shall 
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
   193
not match an empty string unless this is the only match for the repetition.\smallskip
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
   194
d36be1e356c0 changed definitions of PRF
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
   195
\item[$\bullet$] \emph{Empty String Rule:} An empty string shall be considered to 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   196
be longer than no match at all.
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
\end{itemize}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   199
\noindent Consider for example a regular expression \<open>r\<^bsub>key\<^esub>\<close> for recognising keywords such as \<open>if\<close>,
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   200
\<open>then\<close> and so on; and \<open>r\<^bsub>id\<^esub>\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
recognising identifiers (say, a single character followed by
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
characters or numbers).  Then we can form the regular expression
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   203
\<open>(r\<^bsub>key\<^esub> + r\<^bsub>id\<^esub>)\<^sup>\<star>\<close>
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   204
and use POSIX matching to tokenise strings, say \<open>iffoo\<close> and
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   205
\<open>if\<close>.  For \<open>iffoo\<close> we obtain by the Longest Match Rule
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   206
a single identifier token, not a keyword followed by an
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   207
identifier. For \<open>if\<close> we obtain by the Priority Rule a keyword
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   208
token, not an identifier token---even if \<open>r\<^bsub>id\<^esub>\<close>
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   209
matches also. By the Star Rule we know \<open>(r\<^bsub>key\<^esub> +
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   210
r\<^bsub>id\<^esub>)\<^sup>\<star>\<close> matches \<open>iffoo\<close>,
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   211
respectively \<open>if\<close>, in exactly one `iteration' of the star. The
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   212
Empty String Rule is for cases where, for example, the regular expression 
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   213
\<open>(a\<^sup>\<star>)\<^sup>\<star>\<close> matches against the
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   214
string \<open>bc\<close>. Then the longest initial matched substring is the
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   215
empty string, which is matched by both the whole regular expression
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   216
and the parenthesised subexpression.
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   217
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
One limitation of Brzozowski's matcher is that it only generates a
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
YES/NO answer for whether a string is being matched by a regular
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
expression.  Sulzmann and Lu~\cite{Sulzmann2014} extended this matcher
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
to allow generation not just of a YES/NO answer but of an actual
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   223
matching, called a [lexical] {\em value}. Assuming a regular
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   224
expression matches a string, values encode the information of
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   225
\emph{how} the string is matched by the regular expression---that is,
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   226
which part of the string is matched by which part of the regular
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   227
expression. For this consider again the string \<open>xy\<close> and
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   228
the regular expression \mbox{\<open>(x + (y + xy))\<^sup>\<star>\<close>}
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   229
(this time fully parenthesised). We can view this regular expression
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   230
as tree and if the string \<open>xy\<close> is matched by two Star
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   231
`iterations', then the \<open>x\<close> is matched by the left-most
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   232
alternative in this tree and the \<open>y\<close> by the right-left alternative. This
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   233
suggests to record this matching as
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   234
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   235
\begin{center}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   236
@{term "Stars [Left(Char x), Right(Left(Char y))]"}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   237
\end{center}
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   238
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   239
\noindent where @{const Stars}, \<open>Left\<close>, \<open>Right\<close> and \<open>Char\<close> are constructors for values. \<open>Stars\<close> records how many
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   240
iterations were used; \<open>Left\<close>, respectively \<open>Right\<close>, which
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   241
alternative is used. This `tree view' leads naturally to the idea that
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   242
regular expressions act as types and values as inhabiting those types
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   243
(see, for example, \cite{HosoyaVouillonPierce2005}).  The value for
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   244
matching \<open>xy\<close> in a single `iteration', i.e.~the POSIX value,
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   245
would look as follows
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   246
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   247
\begin{center}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   248
@{term "Stars [Seq (Char x) (Char y)]"}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   249
\end{center}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   250
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   251
\noindent where @{const Stars} has only a single-element list for the
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   252
single iteration and @{const Seq} indicates that @{term xy} is matched 
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   253
by a sequence regular expression.
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   254
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   255
%, which we will in what follows 
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   256
%write more formally as @{term "SEQ x y"}.
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   257
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   259
Sulzmann and Lu give a simple algorithm to calculate a value that
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   260
appears to be the value associated with POSIX matching.  The challenge
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   261
then is to specify that value, in an algorithm-independent fashion,
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   262
and to show that Sulzmann and Lu's derivative-based algorithm does
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   263
indeed calculate a value that is correct according to the
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   264
specification.  The answer given by Sulzmann and Lu
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   265
\cite{Sulzmann2014} is to define a relation (called an ``order
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   266
relation'') on the set of values of @{term r}, and to show that (once
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   267
a string to be matched is chosen) there is a maximum element and that
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   268
it is computed by their derivative-based algorithm. This proof idea is
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   269
inspired by work of Frisch and Cardelli \cite{Frisch2004} on a GREEDY
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   270
regular expression matching algorithm. However, we were not able to
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   271
establish transitivity and totality for the ``order relation'' by
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   272
Sulzmann and Lu.  There are some inherent problems with their approach
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   273
(of which some of the proofs are not published in
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   274
\cite{Sulzmann2014}); perhaps more importantly, we give in this paper
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   275
a simple inductive (and algorithm-independent) definition of what we
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   276
call being a {\em POSIX value} for a regular expression @{term r} and
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   277
a string @{term s}; we show that the algorithm by Sulzmann and Lu
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   278
computes such a value and that such a value is unique. Our proofs are
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   279
both done by hand and checked in Isabelle/HOL.  The experience of
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   280
doing our proofs has been that this mechanical checking was absolutely
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   281
essential: this subject area has hidden snares. This was also noted by
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   282
Kuklewicz \cite{Kuklewicz} who found that nearly all POSIX matching
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   283
implementations are ``buggy'' \cite[Page 203]{Sulzmann2014} and by
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   284
Grathwohl et al \cite[Page 36]{CrashCourse2014} who wrote:
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
\begin{quote}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
\it{}``The POSIX strategy is more complicated than the greedy because of 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
the dependence on information about the length of matched strings in the 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
various subexpressions.''
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
\end{quote}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
\noindent {\bf Contributions:} We have implemented in Isabelle/HOL the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
derivative-based regular expression matching algorithm of
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
Sulzmann and Lu \cite{Sulzmann2014}. We have proved the correctness of this
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
algorithm according to our specification of what a POSIX value is (inspired
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
by work of Vansummeren \cite{Vansummeren2006}). Sulzmann
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
and Lu sketch in \cite{Sulzmann2014} an informal correctness proof: but to
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
us it contains unfillable gaps.\footnote{An extended version of
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
\cite{Sulzmann2014} is available at the website of its first author; this
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
extended version already includes remarks in the appendix that their
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
informal proof contains gaps, and possible fixes are not fully worked out.}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
Our specification of a POSIX value consists of a simple inductive definition
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
that given a string and a regular expression uniquely determines this value.
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   306
We also show that our definition is equivalent to an ordering 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   307
of values based on positions by Okui and Suzuki \cite{OkuiSuzuki2010}.
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   308
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   309
%Derivatives as calculated by Brzozowski's method are usually more complex
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   310
%regular expressions than the initial one; various optimisations are
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   311
%possible. We prove the correctness when simplifications of @{term "ALT ZERO r"}, 
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   312
%@{term "ALT r ZERO"}, @{term "SEQ ONE r"} and @{term "SEQ r ONE"} to
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   313
%@{term r} are applied. 
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 280
diff changeset
   314
288
9ab8609c66c5 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   315
We extend our results to ??? Bitcoded version??
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   317
\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   319
section \<open>Preliminaries\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   321
text \<open>\noindent Strings in Isabelle/HOL are lists of characters with
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   322
the empty string being represented by the empty list, written @{term
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   323
"[]"}, and list-cons being written as @{term "DUMMY # DUMMY"}. Often
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   324
we use the usual bracket notation for lists also for strings; for
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   325
example a string consisting of just a single character @{term c} is
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   326
written @{term "[c]"}. We use the usual definitions for 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   327
\emph{prefixes} and \emph{strict prefixes} of strings.  By using the
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
type @{type char} for characters we have a supply of finitely many
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
characters roughly corresponding to the ASCII character set. Regular
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   330
expressions are defined as usual as the elements of the following
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   331
inductive datatype:
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
  \begin{center}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   334
  \<open>r :=\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
  @{const "ZERO"} $\mid$
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
  @{const "ONE"} $\mid$
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 330
diff changeset
   337
  @{term "CH c"} $\mid$
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
  @{term "ALT r\<^sub>1 r\<^sub>2"} $\mid$
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
  @{term "SEQ r\<^sub>1 r\<^sub>2"} $\mid$
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
  @{term "STAR r"} 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
  \noindent where @{const ZERO} stands for the regular expression that does
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
  not match any string, @{const ONE} for the regular expression that matches
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
  only the empty string and @{term c} for matching a character literal. The
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
  language of a regular expression is also defined as usual by the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
  recursive function @{term L} with the six clauses:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
  \begin{center}
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   350
  \begin{tabular}{l@ {\hspace{4mm}}rcl}
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   351
  \textit{(1)} & @{thm (lhs) L.simps(1)} & $\dn$ & @{thm (rhs) L.simps(1)}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   352
  \textit{(2)} & @{thm (lhs) L.simps(2)} & $\dn$ & @{thm (rhs) L.simps(2)}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   353
  \textit{(3)} & @{thm (lhs) L.simps(3)} & $\dn$ & @{thm (rhs) L.simps(3)}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   354
  \textit{(4)} & @{thm (lhs) L.simps(4)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   355
        @{thm (rhs) L.simps(4)[of "r\<^sub>1" "r\<^sub>2"]}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   356
  \textit{(5)} & @{thm (lhs) L.simps(5)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   357
        @{thm (rhs) L.simps(5)[of "r\<^sub>1" "r\<^sub>2"]}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   358
  \textit{(6)} & @{thm (lhs) L.simps(6)} & $\dn$ & @{thm (rhs) L.simps(6)}\\
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
  
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   362
  \noindent In clause \textit{(4)} we use the operation @{term "DUMMY ;;
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
  DUMMY"} for the concatenation of two languages (it is also list-append for
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
  strings). We use the star-notation for regular expressions and for
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
  languages (in the last clause above). The star for languages is defined
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   366
  inductively by two clauses: \<open>(i)\<close> the empty string being in
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   367
  the star of a language and \<open>(ii)\<close> if @{term "s\<^sub>1"} is in a
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
  language and @{term "s\<^sub>2"} in the star of this language, then also @{term
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
  "s\<^sub>1 @ s\<^sub>2"} is in the star of this language. It will also be convenient
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
  to use the following notion of a \emph{semantic derivative} (or \emph{left
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
  quotient}) of a language defined as
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
  %
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
  @{thm Der_def}\;.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
  \noindent
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
  For semantic derivatives we have the following equations (for example
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
  mechanically proved in \cite{Krauss2011}):
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
  %
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
  \begin{equation}\label{SemDer}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
  \begin{array}{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
  @{thm (lhs) Der_null}  & \dn & @{thm (rhs) Der_null}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
  @{thm (lhs) Der_empty}  & \dn & @{thm (rhs) Der_empty}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
  @{thm (lhs) Der_char}  & \dn & @{thm (rhs) Der_char}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
  @{thm (lhs) Der_union}  & \dn & @{thm (rhs) Der_union}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
  @{thm (lhs) Der_Sequ}  & \dn & @{thm (rhs) Der_Sequ}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
  @{thm (lhs) Der_star}  & \dn & @{thm (rhs) Der_star}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
  \end{array}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
  \end{equation}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
  \noindent \emph{\Brz's derivatives} of regular expressions
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
  \cite{Brzozowski1964} can be easily defined by two recursive functions:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
  the first is from regular expressions to booleans (implementing a test
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
  when a regular expression can match the empty string), and the second
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
  takes a regular expression and a character to a (derivative) regular
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
  expression:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
  \begin{tabular}{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
  @{thm (lhs) nullable.simps(1)} & $\dn$ & @{thm (rhs) nullable.simps(1)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
  @{thm (lhs) nullable.simps(2)} & $\dn$ & @{thm (rhs) nullable.simps(2)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
  @{thm (lhs) nullable.simps(3)} & $\dn$ & @{thm (rhs) nullable.simps(3)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
  @{thm (lhs) nullable.simps(4)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) nullable.simps(4)[of "r\<^sub>1" "r\<^sub>2"]}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
  @{thm (lhs) nullable.simps(5)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) nullable.simps(5)[of "r\<^sub>1" "r\<^sub>2"]}\\
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   407
  @{thm (lhs) nullable.simps(6)} & $\dn$ & @{thm (rhs) nullable.simps(6)}\medskip\\
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   409
%  \end{tabular}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   410
%  \end{center}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   411
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   412
%  \begin{center}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   413
%  \begin{tabular}{lcl}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   414
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
  @{thm (lhs) der.simps(1)} & $\dn$ & @{thm (rhs) der.simps(1)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
  @{thm (lhs) der.simps(2)} & $\dn$ & @{thm (rhs) der.simps(2)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
  @{thm (lhs) der.simps(3)} & $\dn$ & @{thm (rhs) der.simps(3)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
  @{thm (lhs) der.simps(4)[of c "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) der.simps(4)[of c "r\<^sub>1" "r\<^sub>2"]}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
  @{thm (lhs) der.simps(5)[of c "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) der.simps(5)[of c "r\<^sub>1" "r\<^sub>2"]}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
  @{thm (lhs) der.simps(6)} & $\dn$ & @{thm (rhs) der.simps(6)}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
  \noindent
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
  We may extend this definition to give derivatives w.r.t.~strings:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
  \begin{tabular}{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   429
  @{thm (lhs) ders.simps(1)} & $\dn$ & @{thm (rhs) ders.simps(1)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
  @{thm (lhs) ders.simps(2)} & $\dn$ & @{thm (rhs) ders.simps(2)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
  \noindent Given the equations in \eqref{SemDer}, it is a relatively easy
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
  exercise in mechanical reasoning to establish that
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
  \begin{proposition}\label{derprop}\mbox{}\\ 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
  \begin{tabular}{ll}
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   439
  \textit{(1)} & @{thm (lhs) nullable_correctness} if and only if
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
  @{thm (rhs) nullable_correctness}, and \\ 
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   441
  \textit{(2)} & @{thm[mode=IfThen] der_correctness}.
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
  \end{proposition}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
  \noindent With this in place it is also very routine to prove that the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
  regular expression matcher defined as
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
  %
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
  @{thm match_def}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
  \noindent gives a positive answer if and only if @{term "s \<in> L r"}.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
  Consequently, this regular expression matching algorithm satisfies the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
  usual specification for regular expression matching. While the matcher
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
  above calculates a provably correct YES/NO answer for whether a regular
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
  expression matches a string or not, the novel idea of Sulzmann and Lu
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
  \cite{Sulzmann2014} is to append another phase to this algorithm in order
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
  to calculate a [lexical] value. We will explain the details next.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   460
\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   462
section \<open>POSIX Regular Expression Matching\label{posixsec}\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   464
text \<open>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   466
  There have been many previous works that use values for encoding 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   467
  \emph{how} a regular expression matches a string.
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   468
  The clever idea by Sulzmann and Lu \cite{Sulzmann2014} is to 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   469
  define a function on values that mirrors (but inverts) the
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
  construction of the derivative on regular expressions. \emph{Values}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
  are defined as the inductive datatype
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
  \begin{center}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   474
  \<open>v :=\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
  @{const "Void"} $\mid$
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
  @{term "val.Char c"} $\mid$
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
  @{term "Left v"} $\mid$
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
  @{term "Right v"} $\mid$
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
  @{term "Seq v\<^sub>1 v\<^sub>2"} $\mid$ 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
  @{term "Stars vs"} 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
  \end{center}  
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   483
  \noindent where we use @{term vs} to stand for a list of
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
  values. (This is similar to the approach taken by Frisch and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
  Cardelli for GREEDY matching \cite{Frisch2004}, and Sulzmann and Lu
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
  for POSIX matching \cite{Sulzmann2014}). The string underlying a
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
  value can be calculated by the @{const flat} function, written
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
  @{term "flat DUMMY"} and defined as:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
  \begin{tabular}[t]{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
  @{thm (lhs) flat.simps(1)} & $\dn$ & @{thm (rhs) flat.simps(1)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
  @{thm (lhs) flat.simps(2)} & $\dn$ & @{thm (rhs) flat.simps(2)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   494
  @{thm (lhs) flat.simps(3)} & $\dn$ & @{thm (rhs) flat.simps(3)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   495
  @{thm (lhs) flat.simps(4)} & $\dn$ & @{thm (rhs) flat.simps(4)}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
  \end{tabular}\hspace{14mm}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   497
  \begin{tabular}[t]{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
  @{thm (lhs) flat.simps(5)[of "v\<^sub>1" "v\<^sub>2"]} & $\dn$ & @{thm (rhs) flat.simps(5)[of "v\<^sub>1" "v\<^sub>2"]}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
  @{thm (lhs) flat.simps(6)} & $\dn$ & @{thm (rhs) flat.simps(6)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   500
  @{thm (lhs) flat.simps(7)} & $\dn$ & @{thm (rhs) flat.simps(7)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   501
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   502
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   504
  \noindent We will sometimes refer to the underlying string of a
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   505
  value as \emph{flattened value}.  We will also overload our notation and 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   506
  use @{term "flats vs"} for flattening a list of values and concatenating
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   507
  the resulting strings.
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   508
  
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   509
  Sulzmann and Lu define
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   510
  inductively an \emph{inhabitation relation} that associates values to
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   511
  regular expressions. We define this relation as
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   512
  follows:\footnote{Note that the rule for @{term Stars} differs from
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   513
  our earlier paper \cite{AusafDyckhoffUrban2016}. There we used the
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   514
  original definition by Sulzmann and Lu which does not require that
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   515
  the values @{term "v \<in> set vs"} flatten to a non-empty
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   516
  string. The reason for introducing the more restricted version of
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   517
  lexical values is convenience later on when reasoning about an
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   518
  ordering relation for values.}
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
  \begin{center}
280
c840a99a3e05 updated
cu
parents: 275
diff changeset
   521
  \begin{tabular}{c@ {\hspace{12mm}}c}\label{prfintros}
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
  \\[-8mm]
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   523
  @{thm[mode=Axiom] Prf.intros(4)} & 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
  @{thm[mode=Axiom] Prf.intros(5)[of "c"]}\\[4mm]
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   525
  @{thm[mode=Rule] Prf.intros(2)[of "v\<^sub>1" "r\<^sub>1" "r\<^sub>2"]} &
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
  @{thm[mode=Rule] Prf.intros(3)[of "v\<^sub>2" "r\<^sub>1" "r\<^sub>2"]}\\[4mm]
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   527
  @{thm[mode=Rule] Prf.intros(1)[of "v\<^sub>1" "r\<^sub>1" "v\<^sub>2" "r\<^sub>2"]}  &
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents: 265
diff changeset
   528
  @{thm[mode=Rule] Prf.intros(6)[of "vs"]}
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   532
  \noindent where in the clause for @{const "Stars"} we use the
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   533
  notation @{term "v \<in> set vs"} for indicating that \<open>v\<close> is a
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   534
  member in the list \<open>vs\<close>.  We require in this rule that every
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   535
  value in @{term vs} flattens to a non-empty string. The idea is that
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   536
  @{term "Stars"}-values satisfy the informal Star Rule (see Introduction)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   537
  where the $^\star$ does not match the empty string unless this is
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   538
  the only match for the repetition.  Note also that no values are
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   539
  associated with the regular expression @{term ZERO}, and that the
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   540
  only value associated with the regular expression @{term ONE} is
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   541
  @{term Void}.  It is routine to establish how values ``inhabiting''
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   542
  a regular expression correspond to the language of a regular
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   543
  expression, namely
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
269
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   545
  \begin{proposition}\label{inhabs}
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
  @{thm L_flat_Prf}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
  \end{proposition}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   549
  \noindent
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   550
  Given a regular expression \<open>r\<close> and a string \<open>s\<close>, we define the 
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   551
  set of all \emph{Lexical Values} inhabited by \<open>r\<close> with the underlying string 
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   552
  being \<open>s\<close>:\footnote{Okui and Suzuki refer to our lexical values 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   553
  as \emph{canonical values} in \cite{OkuiSuzuki2010}. The notion of \emph{non-problematic
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   554
  values} by Cardelli and Frisch \cite{Frisch2004} is related, but not identical
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   555
  to our lexical values.}
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   556
  
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   557
  \begin{center}
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   558
  @{thm LV_def}
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   559
  \end{center}
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   560
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   561
  \noindent The main property of @{term "LV r s"} is that it is alway finite.
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   562
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   563
  \begin{proposition}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   564
  @{thm LV_finite}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   565
  \end{proposition}
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   566
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   567
  \noindent This finiteness property does not hold in general if we
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   568
  remove the side-condition about @{term "flat v \<noteq> []"} in the
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   569
  @{term Stars}-rule above. For example using Sulzmann and Lu's
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   570
  less restrictive definition, @{term "LV (STAR ONE) []"} would contain
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   571
  infinitely many values, but according to our more restricted
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   572
  definition only a single value, namely @{thm LV_STAR_ONE_empty}.
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   573
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   574
  If a regular expression \<open>r\<close> matches a string \<open>s\<close>, then
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   575
  generally the set @{term "LV r s"} is not just a singleton set.  In
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   576
  case of POSIX matching the problem is to calculate the unique lexical value
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   577
  that satisfies the (informal) POSIX rules from the Introduction.
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   578
  Graphically the POSIX value calculation algorithm by Sulzmann and Lu
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   579
  can be illustrated by the picture in Figure~\ref{Sulz} where the
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   580
  path from the left to the right involving @{term
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   581
  derivatives}/@{const nullable} is the first phase of the algorithm
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   582
  (calculating successive \Brz's derivatives) and @{const
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   583
  mkeps}/\<open>inj\<close>, the path from right to left, the second
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   584
  phase. This picture shows the steps required when a regular
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   585
  expression, say \<open>r\<^sub>1\<close>, matches the string @{term
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   586
  "[a,b,c]"}. We first build the three derivatives (according to
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   587
  @{term a}, @{term b} and @{term c}). We then use @{const nullable}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   588
  to find out whether the resulting derivative regular expression
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   589
  @{term "r\<^sub>4"} can match the empty string. If yes, we call the
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   590
  function @{const mkeps} that produces a value @{term "v\<^sub>4"}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   591
  for how @{term "r\<^sub>4"} can match the empty string (taking into
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   592
  account the POSIX constraints in case there are several ways). This
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   593
  function is defined by the clauses:
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   594
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   595
\begin{figure}[t]
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   596
\begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   597
\begin{tikzpicture}[scale=2,node distance=1.3cm,
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   598
                    every node/.style={minimum size=6mm}]
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   599
\node (r1)  {@{term "r\<^sub>1"}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   600
\node (r2) [right=of r1]{@{term "r\<^sub>2"}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   601
\draw[->,line width=1mm](r1)--(r2) node[above,midway] {@{term "der a DUMMY"}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   602
\node (r3) [right=of r2]{@{term "r\<^sub>3"}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
\draw[->,line width=1mm](r2)--(r3) node[above,midway] {@{term "der b DUMMY"}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
\node (r4) [right=of r3]{@{term "r\<^sub>4"}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
\draw[->,line width=1mm](r3)--(r4) node[above,midway] {@{term "der c DUMMY"}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
\draw (r4) node[anchor=west] {\;\raisebox{3mm}{@{term nullable}}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   607
\node (v4) [below=of r4]{@{term "v\<^sub>4"}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   608
\draw[->,line width=1mm](r4) -- (v4);
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   609
\node (v3) [left=of v4] {@{term "v\<^sub>3"}};
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   610
\draw[->,line width=1mm](v4)--(v3) node[below,midway] {\<open>inj r\<^sub>3 c\<close>};
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   611
\node (v2) [left=of v3]{@{term "v\<^sub>2"}};
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   612
\draw[->,line width=1mm](v3)--(v2) node[below,midway] {\<open>inj r\<^sub>2 b\<close>};
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   613
\node (v1) [left=of v2] {@{term "v\<^sub>1"}};
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   614
\draw[->,line width=1mm](v2)--(v1) node[below,midway] {\<open>inj r\<^sub>1 a\<close>};
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   615
\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{@{term "mkeps"}}};
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   616
\end{tikzpicture}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
\end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
\mbox{}\\[-13mm]
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   620
\caption{The two phases of the algorithm by Sulzmann \& Lu \cite{Sulzmann2014},
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   621
matching the string @{term "[a,b,c]"}. The first phase (the arrows from 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
left to right) is \Brz's matcher building successive derivatives. If the 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   623
last regular expression is @{term nullable}, then the functions of the 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   624
second phase are called (the top-down and right-to-left arrows): first 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   625
@{term mkeps} calculates a value @{term "v\<^sub>4"} witnessing
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   626
how the empty string has been recognised by @{term "r\<^sub>4"}. After
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   627
that the function @{term inj} ``injects back'' the characters of the string into
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   628
the values.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   629
\label{Sulz}}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   630
\end{figure} 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   631
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   632
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   633
  \begin{tabular}{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   634
  @{thm (lhs) mkeps.simps(1)} & $\dn$ & @{thm (rhs) mkeps.simps(1)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   635
  @{thm (lhs) mkeps.simps(2)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) mkeps.simps(2)[of "r\<^sub>1" "r\<^sub>2"]}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
  @{thm (lhs) mkeps.simps(3)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) mkeps.simps(3)[of "r\<^sub>1" "r\<^sub>2"]}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   637
  @{thm (lhs) mkeps.simps(4)} & $\dn$ & @{thm (rhs) mkeps.simps(4)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   638
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   639
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   640
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
  \noindent Note that this function needs only to be partially defined,
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
  namely only for regular expressions that are nullable. In case @{const
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   643
  nullable} fails, the string @{term "[a,b,c]"} cannot be matched by @{term
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
  "r\<^sub>1"} and the null value @{term "None"} is returned. Note also how this function
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
  makes some subtle choices leading to a POSIX value: for example if an
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
  alternative regular expression, say @{term "ALT r\<^sub>1 r\<^sub>2"}, can
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   647
  match the empty string and furthermore @{term "r\<^sub>1"} can match the
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   648
  empty string, then we return a \<open>Left\<close>-value. The \<open>Right\<close>-value will only be returned if @{term "r\<^sub>1"} cannot match the empty
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   649
  string.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   650
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   651
  The most interesting idea from Sulzmann and Lu \cite{Sulzmann2014} is
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   652
  the construction of a value for how @{term "r\<^sub>1"} can match the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   653
  string @{term "[a,b,c]"} from the value how the last derivative, @{term
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   654
  "r\<^sub>4"} in Fig.~\ref{Sulz}, can match the empty string. Sulzmann and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   655
  Lu achieve this by stepwise ``injecting back'' the characters into the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   656
  values thus inverting the operation of building derivatives, but on the level
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   657
  of values. The corresponding function, called @{term inj}, takes three
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   658
  arguments, a regular expression, a character and a value. For example in
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   659
  the first (or right-most) @{term inj}-step in Fig.~\ref{Sulz} the regular
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   660
  expression @{term "r\<^sub>3"}, the character @{term c} from the last
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   661
  derivative step and @{term "v\<^sub>4"}, which is the value corresponding
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   662
  to the derivative regular expression @{term "r\<^sub>4"}. The result is
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   663
  the new value @{term "v\<^sub>3"}. The final result of the algorithm is
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   664
  the value @{term "v\<^sub>1"}. The @{term inj} function is defined by recursion on regular
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
  expressions and by analysing the shape of values (corresponding to 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   666
  the derivative regular expressions).
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   667
  %
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   668
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   669
  \begin{tabular}{l@ {\hspace{5mm}}lcl}
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   670
  \textit{(1)} & @{thm (lhs) injval.simps(1)} & $\dn$ & @{thm (rhs) injval.simps(1)}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   671
  \textit{(2)} & @{thm (lhs) injval.simps(2)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1"]} & $\dn$ & 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   672
      @{thm (rhs) injval.simps(2)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1"]}\\
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   673
  \textit{(3)} & @{thm (lhs) injval.simps(3)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>2"]} & $\dn$ & 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   674
      @{thm (rhs) injval.simps(3)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>2"]}\\
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   675
  \textit{(4)} & @{thm (lhs) injval.simps(4)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1" "v\<^sub>2"]} & $\dn$ 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   676
      & @{thm (rhs) injval.simps(4)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1" "v\<^sub>2"]}\\
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   677
  \textit{(5)} & @{thm (lhs) injval.simps(5)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1" "v\<^sub>2"]} & $\dn$ 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   678
      & @{thm (rhs) injval.simps(5)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1" "v\<^sub>2"]}\\
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   679
  \textit{(6)} & @{thm (lhs) injval.simps(6)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>2"]} & $\dn$ 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   680
      & @{thm (rhs) injval.simps(6)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>2"]}\\
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   681
  \textit{(7)} & @{thm (lhs) injval.simps(7)[of "r" "c" "v" "vs"]} & $\dn$ 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   682
      & @{thm (rhs) injval.simps(7)[of "r" "c" "v" "vs"]}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   683
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   684
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   685
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   686
  \noindent To better understand what is going on in this definition it
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   687
  might be instructive to look first at the three sequence cases (clauses
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   688
  \textit{(4)} -- \textit{(6)}). In each case we need to construct an ``injected value'' for
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   689
  @{term "SEQ r\<^sub>1 r\<^sub>2"}. This must be a value of the form @{term
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   690
  "Seq DUMMY DUMMY"}\,. Recall the clause of the \<open>derivative\<close>-function
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   691
  for sequence regular expressions:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   692
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   693
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   694
  @{thm (lhs) der.simps(5)[of c "r\<^sub>1" "r\<^sub>2"]} $\dn$ @{thm (rhs) der.simps(5)[of c "r\<^sub>1" "r\<^sub>2"]}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   695
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   696
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   697
  \noindent Consider first the \<open>else\<close>-branch where the derivative is @{term
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   698
  "SEQ (der c r\<^sub>1) r\<^sub>2"}. The corresponding value must therefore
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   699
  be of the form @{term "Seq v\<^sub>1 v\<^sub>2"}, which matches the left-hand
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   700
  side in clause~\textit{(4)} of @{term inj}. In the \<open>if\<close>-branch the derivative is an
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   701
  alternative, namely @{term "ALT (SEQ (der c r\<^sub>1) r\<^sub>2) (der c
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   702
  r\<^sub>2)"}. This means we either have to consider a \<open>Left\<close>- or
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   703
  \<open>Right\<close>-value. In case of the \<open>Left\<close>-value we know further it
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   704
  must be a value for a sequence regular expression. Therefore the pattern
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   705
  we match in the clause \textit{(5)} is @{term "Left (Seq v\<^sub>1 v\<^sub>2)"},
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   706
  while in \textit{(6)} it is just @{term "Right v\<^sub>2"}. One more interesting
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   707
  point is in the right-hand side of clause \textit{(6)}: since in this case the
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   708
  regular expression \<open>r\<^sub>1\<close> does not ``contribute'' to
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   709
  matching the string, that means it only matches the empty string, we need to
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   710
  call @{const mkeps} in order to construct a value for how @{term "r\<^sub>1"}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   711
  can match this empty string. A similar argument applies for why we can
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   712
  expect in the left-hand side of clause \textit{(7)} that the value is of the form
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   713
  @{term "Seq v (Stars vs)"}---the derivative of a star is @{term "SEQ (der c r)
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   714
  (STAR r)"}. Finally, the reason for why we can ignore the second argument
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   715
  in clause \textit{(1)} of @{term inj} is that it will only ever be called in cases
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   716
  where @{term "c=d"}, but the usual linearity restrictions in patterns do
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   717
  not allow us to build this constraint explicitly into our function
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   718
  definition.\footnote{Sulzmann and Lu state this clause as @{thm (lhs)
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   719
  injval.simps(1)[of "c" "c"]} $\dn$ @{thm (rhs) injval.simps(1)[of "c"]},
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   720
  but our deviation is harmless.}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   721
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   722
  The idea of the @{term inj}-function to ``inject'' a character, say
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   723
  @{term c}, into a value can be made precise by the first part of the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   724
  following lemma, which shows that the underlying string of an injected
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   725
  value has a prepended character @{term c}; the second part shows that
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   726
  the underlying string of an @{const mkeps}-value is always the empty
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   727
  string (given the regular expression is nullable since otherwise
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   728
  \<open>mkeps\<close> might not be defined).
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   729
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   730
  \begin{lemma}\mbox{}\smallskip\\\label{Prf_injval_flat}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   731
  \begin{tabular}{ll}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   732
  (1) & @{thm[mode=IfThen] Prf_injval_flat}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   733
  (2) & @{thm[mode=IfThen] mkeps_flat}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   734
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   735
  \end{lemma}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   736
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   737
  \begin{proof}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   738
  Both properties are by routine inductions: the first one can, for example,
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   739
  be proved by induction over the definition of @{term derivatives}; the second by
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   740
  an induction on @{term r}. There are no interesting cases.\qed
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   741
  \end{proof}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   742
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   743
  Having defined the @{const mkeps} and \<open>inj\<close> function we can extend
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   744
  \Brz's matcher so that a value is constructed (assuming the
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   745
  regular expression matches the string). The clauses of the Sulzmann and Lu lexer are
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   746
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   747
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   748
  \begin{tabular}{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   749
  @{thm (lhs) lexer.simps(1)} & $\dn$ & @{thm (rhs) lexer.simps(1)}\\
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   750
  @{thm (lhs) lexer.simps(2)} & $\dn$ & \<open>case\<close> @{term "lexer (der c r) s"} \<open>of\<close>\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   751
                     & & \phantom{$|$} @{term "None"}  \<open>\<Rightarrow>\<close> @{term None}\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   752
                     & & $|$ @{term "Some v"} \<open>\<Rightarrow>\<close> @{term "Some (injval r c v)"}                          
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   753
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   754
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   755
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   756
  \noindent If the regular expression does not match the string, @{const None} is
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   757
  returned. If the regular expression \emph{does}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   758
  match the string, then @{const Some} value is returned. One important
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   759
  virtue of this algorithm is that it can be implemented with ease in any
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   760
  functional programming language and also in Isabelle/HOL. In the remaining
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   761
  part of this section we prove that this algorithm is correct.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   762
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   763
  The well-known idea of POSIX matching is informally defined by some
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   764
  rules such as the Longest Match and Priority Rules (see
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   765
  Introduction); as correctly argued in \cite{Sulzmann2014}, this
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   766
  needs formal specification. Sulzmann and Lu define an ``ordering
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   767
  relation'' between values and argue that there is a maximum value,
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   768
  as given by the derivative-based algorithm.  In contrast, we shall
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   769
  introduce a simple inductive definition that specifies directly what
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   770
  a \emph{POSIX value} is, incorporating the POSIX-specific choices
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   771
  into the side-conditions of our rules. Our definition is inspired by
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   772
  the matching relation given by Vansummeren~\cite{Vansummeren2006}. 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   773
  The relation we define is ternary and
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   774
  written as \mbox{@{term "s \<in> r \<rightarrow> v"}}, relating
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   775
  strings, regular expressions and values; the inductive rules are given in 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   776
  Figure~\ref{POSIXrules}.
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   777
  We can prove that given a string @{term s} and regular expression @{term
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   778
   r}, the POSIX value @{term v} is uniquely determined by @{term "s \<in> r \<rightarrow> v"}.
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   779
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   780
  %
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   781
  \begin{figure}[t]
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   782
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   783
  \begin{tabular}{c}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   784
  @{thm[mode=Axiom] Posix.intros(1)}\<open>P\<close>@{term "ONE"} \qquad
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   785
  @{thm[mode=Axiom] Posix.intros(2)}\<open>P\<close>@{term "c"}\medskip\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   786
  @{thm[mode=Rule] Posix.intros(3)[of "s" "r\<^sub>1" "v" "r\<^sub>2"]}\<open>P+L\<close>\qquad
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   787
  @{thm[mode=Rule] Posix.intros(4)[of "s" "r\<^sub>2" "v" "r\<^sub>1"]}\<open>P+R\<close>\medskip\\
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   788
  $\mprset{flushleft}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   789
   \inferrule
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   790
   {@{thm (prem 1) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]} \qquad
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   791
    @{thm (prem 2) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]} \\\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   792
    @{thm (prem 3) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]}}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   793
   {@{thm (concl) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]}}$\<open>PS\<close>\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   794
  @{thm[mode=Axiom] Posix.intros(7)}\<open>P[]\<close>\medskip\\
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   795
  $\mprset{flushleft}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   796
   \inferrule
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   797
   {@{thm (prem 1) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \qquad
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   798
    @{thm (prem 2) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \qquad
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   799
    @{thm (prem 3) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \\\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   800
    @{thm (prem 4) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]}}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   801
   {@{thm (concl) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]}}$\<open>P\<star>\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   802
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   803
  \end{center}
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   804
  \caption{Our inductive definition of POSIX values.}\label{POSIXrules}
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   805
  \end{figure}
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   806
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   807
   
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   808
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   809
  \begin{theorem}\mbox{}\smallskip\\\label{posixdeterm}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   810
  \begin{tabular}{ll}
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   811
  (1) & If @{thm (prem 1) Posix1(1)} then @{thm (concl)
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   812
  Posix1(1)} and @{thm (concl) Posix1(2)}.\\
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   813
  (2) & @{thm[mode=IfThen] Posix_determ(1)[of _ _ "v" "v'"]}
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   814
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   815
  \end{theorem}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   816
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   817
  \begin{proof} Both by induction on the definition of @{term "s \<in> r \<rightarrow> v"}. 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   818
  The second parts follows by a case analysis of @{term "s \<in> r \<rightarrow> v'"} and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   819
  the first part.\qed
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   820
  \end{proof}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   821
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   822
  \noindent
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   823
  We claim that our @{term "s \<in> r \<rightarrow> v"} relation captures the idea behind the four
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   824
  informal POSIX rules shown in the Introduction: Consider for example the
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   825
  rules \<open>P+L\<close> and \<open>P+R\<close> where the POSIX value for a string
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   826
  and an alternative regular expression, that is @{term "(s, ALT r\<^sub>1 r\<^sub>2)"},
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   827
  is specified---it is always a \<open>Left\<close>-value, \emph{except} when the
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   828
  string to be matched is not in the language of @{term "r\<^sub>1"}; only then it
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   829
  is a \<open>Right\<close>-value (see the side-condition in \<open>P+R\<close>).
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   830
  Interesting is also the rule for sequence regular expressions (\<open>PS\<close>). The first two premises state that @{term "v\<^sub>1"} and @{term "v\<^sub>2"}
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   831
  are the POSIX values for @{term "(s\<^sub>1, r\<^sub>1)"} and @{term "(s\<^sub>2, r\<^sub>2)"}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   832
  respectively. Consider now the third premise and note that the POSIX value
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   833
  of this rule should match the string \mbox{@{term "s\<^sub>1 @ s\<^sub>2"}}. According to the
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   834
  Longest Match Rule, we want that the @{term "s\<^sub>1"} is the longest initial
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   835
  split of \mbox{@{term "s\<^sub>1 @ s\<^sub>2"}} such that @{term "s\<^sub>2"} is still recognised
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   836
  by @{term "r\<^sub>2"}. Let us assume, contrary to the third premise, that there
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   837
  \emph{exist} an @{term "s\<^sub>3"} and @{term "s\<^sub>4"} such that @{term "s\<^sub>2"}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   838
  can be split up into a non-empty string @{term "s\<^sub>3"} and a possibly empty
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   839
  string @{term "s\<^sub>4"}. Moreover the longer string @{term "s\<^sub>1 @ s\<^sub>3"} can be
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   840
  matched by \<open>r\<^sub>1\<close> and the shorter @{term "s\<^sub>4"} can still be
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   841
  matched by @{term "r\<^sub>2"}. In this case @{term "s\<^sub>1"} would \emph{not} be the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   842
  longest initial split of \mbox{@{term "s\<^sub>1 @ s\<^sub>2"}} and therefore @{term "Seq v\<^sub>1
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   843
  v\<^sub>2"} cannot be a POSIX value for @{term "(s\<^sub>1 @ s\<^sub>2, SEQ r\<^sub>1 r\<^sub>2)"}. 
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   844
  The main point is that our side-condition ensures the Longest 
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   845
  Match Rule is satisfied.
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   846
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   847
  A similar condition is imposed on the POSIX value in the \<open>P\<star>\<close>-rule. Also there we want that @{term "s\<^sub>1"} is the longest initial
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   848
  split of @{term "s\<^sub>1 @ s\<^sub>2"} and furthermore the corresponding value
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   849
  @{term v} cannot be flattened to the empty string. In effect, we require
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   850
  that in each ``iteration'' of the star, some non-empty substring needs to
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   851
  be ``chipped'' away; only in case of the empty string we accept @{term
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   852
  "Stars []"} as the POSIX value. Indeed we can show that our POSIX values
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   853
  are lexical values which exclude those \<open>Stars\<close> that contain subvalues 
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   854
  that flatten to the empty string.
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   855
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   856
  \begin{lemma}\label{LVposix}
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   857
  @{thm [mode=IfThen] Posix_LV}
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   858
  \end{lemma}
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   859
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   860
  \begin{proof}
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   861
  By routine induction on @{thm (prem 1) Posix_LV}.\qed 
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   862
  \end{proof}
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   863
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   864
  \noindent
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   865
  Next is the lemma that shows the function @{term "mkeps"} calculates
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   866
  the POSIX value for the empty string and a nullable regular expression.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   867
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   868
  \begin{lemma}\label{lemmkeps}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   869
  @{thm[mode=IfThen] Posix_mkeps}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   870
  \end{lemma}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   871
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   872
  \begin{proof}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   873
  By routine induction on @{term r}.\qed 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   874
  \end{proof}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   875
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   876
  \noindent
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   877
  The central lemma for our POSIX relation is that the \<open>inj\<close>-function
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   878
  preserves POSIX values.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   879
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   880
  \begin{lemma}\label{Posix2}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   881
  @{thm[mode=IfThen] Posix_injval}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   882
  \end{lemma}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   883
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   884
  \begin{proof}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   885
  By induction on \<open>r\<close>. We explain two cases.
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   886
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   887
  \begin{itemize}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   888
  \item[$\bullet$] Case @{term "r = ALT r\<^sub>1 r\<^sub>2"}. There are
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   889
  two subcases, namely \<open>(a)\<close> \mbox{@{term "v = Left v'"}} and @{term
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   890
  "s \<in> der c r\<^sub>1 \<rightarrow> v'"}; and \<open>(b)\<close> @{term "v = Right v'"}, @{term
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   891
  "s \<notin> L (der c r\<^sub>1)"} and @{term "s \<in> der c r\<^sub>2 \<rightarrow> v'"}. In \<open>(a)\<close> we
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   892
  know @{term "s \<in> der c r\<^sub>1 \<rightarrow> v'"}, from which we can infer @{term "(c # s)
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   893
  \<in> r\<^sub>1 \<rightarrow> injval r\<^sub>1 c v'"} by induction hypothesis and hence @{term "(c #
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   894
  s) \<in> ALT r\<^sub>1 r\<^sub>2 \<rightarrow> injval (ALT r\<^sub>1 r\<^sub>2) c (Left v')"} as needed. Similarly
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   895
  in subcase \<open>(b)\<close> where, however, in addition we have to use
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   896
  Proposition~\ref{derprop}(2) in order to infer @{term "c # s \<notin> L r\<^sub>1"} from @{term
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   897
  "s \<notin> L (der c r\<^sub>1)"}.\smallskip
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   898
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   899
  \item[$\bullet$] Case @{term "r = SEQ r\<^sub>1 r\<^sub>2"}. There are three subcases:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   900
  
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   901
  \begin{quote}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   902
  \begin{description}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   903
  \item[\<open>(a)\<close>] @{term "v = Left (Seq v\<^sub>1 v\<^sub>2)"} and @{term "nullable r\<^sub>1"} 
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   904
  \item[\<open>(b)\<close>] @{term "v = Right v\<^sub>1"} and @{term "nullable r\<^sub>1"} 
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   905
  \item[\<open>(c)\<close>] @{term "v = Seq v\<^sub>1 v\<^sub>2"} and @{term "\<not> nullable r\<^sub>1"} 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   906
  \end{description}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   907
  \end{quote}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   908
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   909
  \noindent For \<open>(a)\<close> we know @{term "s\<^sub>1 \<in> der c r\<^sub>1 \<rightarrow> v\<^sub>1"} and
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   910
  @{term "s\<^sub>2 \<in> r\<^sub>2 \<rightarrow> v\<^sub>2"} as well as
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   911
  %
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   912
  \[@{term "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s\<^sub>2 \<and> s\<^sub>1 @ s\<^sub>3 \<in> L (der c r\<^sub>1) \<and> s\<^sub>4 \<in> L r\<^sub>2)"}\]
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   913
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   914
  \noindent From the latter we can infer by Proposition~\ref{derprop}(2):
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   915
  %
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   916
  \[@{term "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s\<^sub>2 \<and> (c # s\<^sub>1) @ s\<^sub>3 \<in> L r\<^sub>1 \<and> s\<^sub>4 \<in> L r\<^sub>2)"}\]
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   917
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   918
  \noindent We can use the induction hypothesis for \<open>r\<^sub>1\<close> to obtain
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   919
  @{term "(c # s\<^sub>1) \<in> r\<^sub>1 \<rightarrow> injval r\<^sub>1 c v\<^sub>1"}. Putting this all together allows us to infer
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   920
  @{term "((c # s\<^sub>1) @ s\<^sub>2) \<in> SEQ r\<^sub>1 r\<^sub>2 \<rightarrow> Seq (injval r\<^sub>1 c v\<^sub>1) v\<^sub>2"}. The case \<open>(c)\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   921
  is similar.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   922
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   923
  For \<open>(b)\<close> we know @{term "s \<in> der c r\<^sub>2 \<rightarrow> v\<^sub>1"} and 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   924
  @{term "s\<^sub>1 @ s\<^sub>2 \<notin> L (SEQ (der c r\<^sub>1) r\<^sub>2)"}. From the former
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   925
  we have @{term "(c # s) \<in> r\<^sub>2 \<rightarrow> (injval r\<^sub>2 c v\<^sub>1)"} by induction hypothesis
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   926
  for @{term "r\<^sub>2"}. From the latter we can infer
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   927
  %
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   928
  \[@{term "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = c # s \<and> s\<^sub>3 \<in> L r\<^sub>1 \<and> s\<^sub>4 \<in> L r\<^sub>2)"}\]
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   929
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   930
  \noindent By Lemma~\ref{lemmkeps} we know @{term "[] \<in> r\<^sub>1 \<rightarrow> (mkeps r\<^sub>1)"}
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   931
  holds. Putting this all together, we can conclude with @{term "(c #
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   932
  s) \<in> SEQ r\<^sub>1 r\<^sub>2 \<rightarrow> Seq (mkeps r\<^sub>1) (injval r\<^sub>2 c v\<^sub>1)"}, as required.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   933
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   934
  Finally suppose @{term "r = STAR r\<^sub>1"}. This case is very similar to the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   935
  sequence case, except that we need to also ensure that @{term "flat (injval r\<^sub>1
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   936
  c v\<^sub>1) \<noteq> []"}. This follows from @{term "(c # s\<^sub>1)
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   937
  \<in> r\<^sub>1 \<rightarrow> injval r\<^sub>1 c v\<^sub>1"}  (which in turn follows from @{term "s\<^sub>1 \<in> der c
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   938
  r\<^sub>1 \<rightarrow> v\<^sub>1"} and the induction hypothesis).\qed
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   939
  \end{itemize}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   940
  \end{proof}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   941
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   942
  \noindent
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   943
  With Lemma~\ref{Posix2} in place, it is completely routine to establish
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   944
  that the Sulzmann and Lu lexer satisfies our specification (returning
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   945
  the null value @{term "None"} iff the string is not in the language of the regular expression,
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   946
  and returning a unique POSIX value iff the string \emph{is} in the language):
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   947
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   948
  \begin{theorem}\mbox{}\smallskip\\\label{lexercorrect}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   949
  \begin{tabular}{ll}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   950
  (1) & @{thm (lhs) lexer_correct_None} if and only if @{thm (rhs) lexer_correct_None}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   951
  (2) & @{thm (lhs) lexer_correct_Some} if and only if @{thm (rhs) lexer_correct_Some}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   952
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   953
  \end{theorem}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   954
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   955
  \begin{proof}
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   956
  By induction on @{term s} using Lemma~\ref{lemmkeps} and \ref{Posix2}.\qed  
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   957
  \end{proof}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   958
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   959
  \noindent In \textit{(2)} we further know by Theorem~\ref{posixdeterm} that the
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   960
  value returned by the lexer must be unique.   A simple corollary 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   961
  of our two theorems is:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   962
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   963
  \begin{corollary}\mbox{}\smallskip\\\label{lexercorrectcor}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   964
  \begin{tabular}{ll}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   965
  (1) & @{thm (lhs) lexer_correctness(2)} if and only if @{thm (rhs) lexer_correctness(2)}\\ 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   966
  (2) & @{thm (lhs) lexer_correctness(1)} if and only if @{thm (rhs) lexer_correctness(1)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   967
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   968
  \end{corollary}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   969
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   970
  \noindent This concludes our correctness proof. Note that we have
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   971
  not changed the algorithm of Sulzmann and Lu,\footnote{All
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   972
  deviations we introduced are harmless.} but introduced our own
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   973
  specification for what a correct result---a POSIX value---should be.
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   974
  In the next section we show that our specification coincides with
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
   975
  another one given by Okui and Suzuki using a different technique.
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   976
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   977
\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   978
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   979
section \<open>Ordering of Values according to Okui and Suzuki\<close>
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   980
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
   981
text \<open>
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   982
  
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   983
  While in the previous section we have defined POSIX values directly
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   984
  in terms of a ternary relation (see inference rules in Figure~\ref{POSIXrules}),
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   985
  Sulzmann and Lu took a different approach in \cite{Sulzmann2014}:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   986
  they introduced an ordering for values and identified POSIX values
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   987
  as the maximal elements.  An extended version of \cite{Sulzmann2014}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   988
  is available at the website of its first author; this includes more
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   989
  details of their proofs, but which are evidently not in final form
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   990
  yet. Unfortunately, we were not able to verify claims that their
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   991
  ordering has properties such as being transitive or having maximal
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   992
  elements. 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   993
 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   994
  Okui and Suzuki \cite{OkuiSuzuki2010,OkuiSuzukiTech} described
269
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   995
  another ordering of values, which they use to establish the
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   996
  correctness of their automata-based algorithm for POSIX matching.
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   997
  Their ordering resembles some aspects of the one given by Sulzmann
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   998
  and Lu, but overall is quite different. To begin with, Okui and
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   999
  Suzuki identify POSIX values as minimal, rather than maximal,
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1000
  elements in their ordering. A more substantial difference is that
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1001
  the ordering by Okui and Suzuki uses \emph{positions} in order to
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1002
  identify and compare subvalues. Positions are lists of natural
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1003
  numbers. This allows them to quite naturally formalise the Longest
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1004
  Match and Priority rules of the informal POSIX standard.  Consider
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1005
  for example the value @{term v}
269
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1006
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1007
  \begin{center}
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1008
  @{term "v == Stars [Seq (Char x) (Char y), Char z]"}
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1009
  \end{center}
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1010
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1011
  \noindent
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1012
  At position \<open>[0,1]\<close> of this value is the
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1013
  subvalue \<open>Char y\<close> and at position \<open>[1]\<close> the
269
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1014
  subvalue @{term "Char z"}.  At the `root' position, or empty list
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1015
  @{term "[]"}, is the whole value @{term v}. Positions such as \<open>[0,1,0]\<close> or \<open>[2]\<close> are outside of \<open>v\<close>. If it exists, the subvalue of @{term v} at a position \<open>p\<close>, written @{term "at v p"}, can be recursively defined by
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1016
  
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1017
  \begin{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1018
  \begin{tabular}{r@ {\hspace{0mm}}lcl}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1019
  @{term v} &  \<open>\<downharpoonleft>\<^bsub>[]\<^esub>\<close> & \<open>\<equiv>\<close>& @{thm (rhs) at.simps(1)}\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1020
  @{term "Left v"} & \<open>\<downharpoonleft>\<^bsub>0::ps\<^esub>\<close> & \<open>\<equiv>\<close>& @{thm (rhs) at.simps(2)}\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1021
  @{term "Right v"} & \<open>\<downharpoonleft>\<^bsub>1::ps\<^esub>\<close> & \<open>\<equiv>\<close> & 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1022
  @{thm (rhs) at.simps(3)[simplified Suc_0_fold]}\\
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1023
  @{term "Seq v\<^sub>1 v\<^sub>2"} & \<open>\<downharpoonleft>\<^bsub>0::ps\<^esub>\<close> & \<open>\<equiv>\<close> & 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1024
  @{thm (rhs) at.simps(4)[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]} \\
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1025
  @{term "Seq v\<^sub>1 v\<^sub>2"} & \<open>\<downharpoonleft>\<^bsub>1::ps\<^esub>\<close>
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1026
  & \<open>\<equiv>\<close> & 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1027
  @{thm (rhs) at.simps(5)[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2", simplified Suc_0_fold]} \\
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1028
  @{term "Stars vs"} & \<open>\<downharpoonleft>\<^bsub>n::ps\<^esub>\<close> & \<open>\<equiv>\<close>& @{thm (rhs) at.simps(6)}\\
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1029
  \end{tabular} 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1030
  \end{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1031
269
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1032
  \noindent In the last clause we use Isabelle's notation @{term "vs ! n"} for the
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1033
  \<open>n\<close>th element in a list.  The set of positions inside a value \<open>v\<close>,
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1034
  written @{term "Pos v"}, is given by 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1035
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1036
  \begin{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1037
  \begin{tabular}{lcl}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1038
  @{thm (lhs) Pos.simps(1)} & \<open>\<equiv>\<close> & @{thm (rhs) Pos.simps(1)}\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1039
  @{thm (lhs) Pos.simps(2)} & \<open>\<equiv>\<close> & @{thm (rhs) Pos.simps(2)}\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1040
  @{thm (lhs) Pos.simps(3)} & \<open>\<equiv>\<close> & @{thm (rhs) Pos.simps(3)}\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1041
  @{thm (lhs) Pos.simps(4)} & \<open>\<equiv>\<close> & @{thm (rhs) Pos.simps(4)}\\
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1042
  @{thm (lhs) Pos.simps(5)[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1043
  & \<open>\<equiv>\<close> 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1044
  & @{thm (rhs) Pos.simps(5)[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]}\\
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1045
  @{thm (lhs) Pos_stars} & \<open>\<equiv>\<close> & @{thm (rhs) Pos_stars}\\
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1046
  \end{tabular}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1047
  \end{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1048
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1049
  \noindent 
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1050
  whereby \<open>len\<close> in the last clause stands for the length of a list. Clearly
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1051
  for every position inside a value there exists a subvalue at that position.
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1052
 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1053
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1054
  To help understanding the ordering of Okui and Suzuki, consider again 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1055
  the earlier value
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1056
  \<open>v\<close> and compare it with the following \<open>w\<close>:
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1057
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1058
  \begin{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1059
  \begin{tabular}{l}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1060
  @{term "v == Stars [Seq (Char x) (Char y), Char z]"}\\
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1061
  @{term "w == Stars [Char x, Char y, Char z]"}  
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1062
  \end{tabular}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1063
  \end{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1064
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1065
  \noindent Both values match the string \<open>xyz\<close>, that means if
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1066
  we flatten these values at their respective root position, we obtain
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1067
  \<open>xyz\<close>. However, at position \<open>[0]\<close>, \<open>v\<close> matches
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1068
  \<open>xy\<close> whereas \<open>w\<close> matches only the shorter \<open>x\<close>. So
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1069
  according to the Longest Match Rule, we should prefer \<open>v\<close>,
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1070
  rather than \<open>w\<close> as POSIX value for string \<open>xyz\<close> (and
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1071
  corresponding regular expression). In order to
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1072
  formalise this idea, Okui and Suzuki introduce a measure for
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1073
  subvalues at position \<open>p\<close>, called the \emph{norm} of \<open>v\<close>
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1074
  at position \<open>p\<close>. We can define this measure in Isabelle as an
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1075
  integer as follows
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1076
  
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1077
  \begin{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1078
  @{thm pflat_len_def}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1079
  \end{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1080
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1081
  \noindent where we take the length of the flattened value at
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1082
  position \<open>p\<close>, provided the position is inside \<open>v\<close>; if
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1083
  not, then the norm is \<open>-1\<close>. The default for outside
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1084
  positions is crucial for the POSIX requirement of preferring a
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1085
  \<open>Left\<close>-value over a \<open>Right\<close>-value (if they can match the
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1086
  same string---see the Priority Rule from the Introduction). For this
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1087
  consider
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1088
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1089
  \begin{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1090
  @{term "v == Left (Char x)"} \qquad and \qquad @{term "w == Right (Char x)"}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1091
  \end{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1092
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1093
  \noindent Both values match \<open>x\<close>. At position \<open>[0]\<close>
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1094
  the norm of @{term v} is \<open>1\<close> (the subvalue matches \<open>x\<close>),
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1095
  but the norm of \<open>w\<close> is \<open>-1\<close> (the position is outside
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1096
  \<open>w\<close> according to how we defined the `inside' positions of
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1097
  \<open>Left\<close>- and \<open>Right\<close>-values).  Of course at position
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1098
  \<open>[1]\<close>, the norms @{term "pflat_len v [1]"} and @{term
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1099
  "pflat_len w [1]"} are reversed, but the point is that subvalues
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1100
  will be analysed according to lexicographically ordered
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1101
  positions. According to this ordering, the position \<open>[0]\<close>
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1102
  takes precedence over \<open>[1]\<close> and thus also \<open>v\<close> will be 
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1103
  preferred over \<open>w\<close>.  The lexicographic ordering of positions, written
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1104
  @{term "DUMMY \<sqsubset>lex DUMMY"}, can be conveniently formalised
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1105
  by three inference rules
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1106
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1107
  \begin{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1108
  \begin{tabular}{ccc}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1109
  @{thm [mode=Axiom] lex_list.intros(1)}\hspace{1cm} &
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1110
  @{thm [mode=Rule] lex_list.intros(3)[where ?p1.0="p\<^sub>1" and ?p2.0="p\<^sub>2" and
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1111
                                            ?ps1.0="ps\<^sub>1" and ?ps2.0="ps\<^sub>2"]}\hspace{1cm} &
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1112
  @{thm [mode=Rule] lex_list.intros(2)[where ?ps1.0="ps\<^sub>1" and ?ps2.0="ps\<^sub>2"]}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1113
  \end{tabular}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1114
  \end{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1115
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1116
  With the norm and lexicographic order in place,
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1117
  we can state the key definition of Okui and Suzuki
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1118
  \cite{OkuiSuzuki2010}: a value @{term "v\<^sub>1"} is \emph{smaller at position \<open>p\<close>} than
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1119
  @{term "v\<^sub>2"}, written @{term "v\<^sub>1 \<sqsubset>val p v\<^sub>2"}, 
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1120
  if and only if  $(i)$ the norm at position \<open>p\<close> is
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1121
  greater in @{term "v\<^sub>1"} (that is the string @{term "flat (at v\<^sub>1 p)"} is longer 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1122
  than @{term "flat (at v\<^sub>2 p)"}) and $(ii)$ all subvalues at 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1123
  positions that are inside @{term "v\<^sub>1"} or @{term "v\<^sub>2"} and that are
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1124
  lexicographically smaller than \<open>p\<close>, we have the same norm, namely
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1125
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1126
 \begin{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1127
 \begin{tabular}{c}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1128
 @{thm (lhs) PosOrd_def[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]} 
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1129
 \<open>\<equiv>\<close> 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1130
 $\begin{cases}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1131
 (i) & @{term "pflat_len v\<^sub>1 p > pflat_len v\<^sub>2 p"}   \quad\text{and}\smallskip \\
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1132
 (ii) & @{term "(\<forall>q \<in> Pos v\<^sub>1 \<union> Pos v\<^sub>2. q \<sqsubset>lex p --> pflat_len v\<^sub>1 q = pflat_len v\<^sub>2 q)"}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1133
 \end{cases}$
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1134
 \end{tabular}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1135
 \end{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1136
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1137
 \noindent The position \<open>p\<close> in this definition acts as the
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1138
  \emph{first distinct position} of \<open>v\<^sub>1\<close> and \<open>v\<^sub>2\<close>, where both values match strings of different length
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1139
  \cite{OkuiSuzuki2010}.  Since at \<open>p\<close> the values \<open>v\<^sub>1\<close> and \<open>v\<^sub>2\<close> match different strings, the
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1140
  ordering is irreflexive. Derived from the definition above
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1141
  are the following two orderings:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1142
  
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1143
  \begin{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1144
  \begin{tabular}{l}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1145
  @{thm PosOrd_ex_def[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]}\\
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1146
  @{thm PosOrd_ex_eq_def[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1147
  \end{tabular}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1148
  \end{center}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1149
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1150
 While we encountered a number of obstacles for establishing properties like
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1151
 transitivity for the ordering of Sulzmann and Lu (and which we failed
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1152
 to overcome), it is relatively straightforward to establish this
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1153
 property for the orderings
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1154
 @{term "DUMMY :\<sqsubset>val DUMMY"} and @{term "DUMMY :\<sqsubseteq>val DUMMY"}  
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1155
 by Okui and Suzuki.
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1156
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1157
 \begin{lemma}[Transitivity]\label{transitivity}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1158
 @{thm [mode=IfThen] PosOrd_trans[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2" and ?v3.0="v\<^sub>3"]} 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1159
 \end{lemma}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1160
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1161
 \begin{proof} From the assumption we obtain two positions \<open>p\<close>
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1162
 and \<open>q\<close>, where the values \<open>v\<^sub>1\<close> and \<open>v\<^sub>2\<close> (respectively \<open>v\<^sub>2\<close> and \<open>v\<^sub>3\<close>) are `distinct'.  Since \<open>\<prec>\<^bsub>lex\<^esub>\<close> is trichotomous, we need to consider
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1163
 three cases, namely @{term "p = q"}, @{term "p \<sqsubset>lex q"} and
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1164
 @{term "q \<sqsubset>lex p"}. Let us look at the first case.  Clearly
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1165
 @{term "pflat_len v\<^sub>2 p < pflat_len v\<^sub>1 p"} and @{term
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1166
 "pflat_len v\<^sub>3 p < pflat_len v\<^sub>2 p"} imply @{term
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1167
 "pflat_len v\<^sub>3 p < pflat_len v\<^sub>1 p"}.  It remains to show
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1168
 that for a @{term "p' \<in> Pos v\<^sub>1 \<union> Pos v\<^sub>3"}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1169
 with @{term "p' \<sqsubset>lex p"} that @{term "pflat_len v\<^sub>1
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1170
 p' = pflat_len v\<^sub>3 p'"} holds.  Suppose @{term "p' \<in> Pos
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1171
 v\<^sub>1"}, then we can infer from the first assumption that @{term
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1172
 "pflat_len v\<^sub>1 p' = pflat_len v\<^sub>2 p'"}.  But this means
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1173
 that @{term "p'"} must be in @{term "Pos v\<^sub>2"} too (the norm
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1174
 cannot be \<open>-1\<close> given @{term "p' \<in> Pos v\<^sub>1"}).  
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1175
 Hence we can use the second assumption and
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1176
 infer @{term "pflat_len v\<^sub>2 p' = pflat_len v\<^sub>3 p'"},
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1177
 which concludes this case with @{term "v\<^sub>1 :\<sqsubset>val
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1178
 v\<^sub>3"}.  The reasoning in the other cases is similar.\qed
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1179
 \end{proof}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1180
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1181
 \noindent 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1182
 The proof for $\preccurlyeq$ is similar and omitted.
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1183
 It is also straightforward to show that \<open>\<prec>\<close> and
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1184
 $\preccurlyeq$ are partial orders.  Okui and Suzuki furthermore show that they
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1185
 are linear orderings for lexical values \cite{OkuiSuzuki2010} of a given
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1186
 regular expression and given string, but we have not formalised this in Isabelle. It is
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1187
 not essential for our results. What we are going to show below is
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1188
 that for a given \<open>r\<close> and \<open>s\<close>, the orderings have a unique
269
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1189
 minimal element on the set @{term "LV r s"}, which is the POSIX value
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1190
 we defined in the previous section. We start with two properties that
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1191
 show how the length of a flattened value relates to the \<open>\<prec>\<close>-ordering.
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1192
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1193
 \begin{proposition}\mbox{}\smallskip\\\label{ordlen}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1194
 \begin{tabular}{@ {}ll}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1195
 (1) &
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1196
 @{thm [mode=IfThen] PosOrd_shorterE[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1197
 (2) &
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1198
 @{thm [mode=IfThen] PosOrd_shorterI[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]} 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1199
 \end{tabular} 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1200
 \end{proposition}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1201
 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1202
 \noindent Both properties follow from the definition of the ordering. Note that
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1203
 \textit{(2)} entails that a value, say @{term "v\<^sub>2"}, whose underlying 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1204
 string is a strict prefix of another flattened value, say @{term "v\<^sub>1"}, then
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1205
 @{term "v\<^sub>1"} must be smaller than @{term "v\<^sub>2"}. For our proofs it
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1206
 will be useful to have the following properties---in each case the underlying strings 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1207
 of the compared values are the same: 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1208
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1209
  \begin{proposition}\mbox{}\smallskip\\\label{ordintros}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1210
  \begin{tabular}{ll}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1211
  \textit{(1)} & 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1212
  @{thm [mode=IfThen] PosOrd_Left_Right[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1213
  \textit{(2)} & If
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1214
  @{thm (prem 1) PosOrd_Left_eq[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]} \;then\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1215
  @{thm (lhs) PosOrd_Left_eq[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]} \;iff\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1216
  @{thm (rhs) PosOrd_Left_eq[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1217
  \textit{(3)} & If
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1218
  @{thm (prem 1) PosOrd_Right_eq[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]} \;then\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1219
  @{thm (lhs) PosOrd_Right_eq[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]} \;iff\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1220
  @{thm (rhs) PosOrd_Right_eq[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1221
  \textit{(4)} & If
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1222
  @{thm (prem 1) PosOrd_Seq_eq[where ?v2.0="v\<^sub>2" and ?w2.0="w\<^sub>2"]} \;then\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1223
  @{thm (lhs) PosOrd_Seq_eq[where ?v2.0="v\<^sub>2" and ?w2.0="w\<^sub>2"]} \;iff\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1224
  @{thm (rhs) PosOrd_Seq_eq[where ?v2.0="v\<^sub>2" and ?w2.0="w\<^sub>2"]}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1225
  \textit{(5)} & If
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1226
  @{thm (prem 2) PosOrd_SeqI1[simplified, where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2" and
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1227
                                    ?w1.0="w\<^sub>1" and ?w2.0="w\<^sub>2"]} \;and\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1228
  @{thm (prem 1) PosOrd_SeqI1[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2" and
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1229
                                    ?w1.0="w\<^sub>1" and ?w2.0="w\<^sub>2"]} \;then\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1230
  @{thm (concl) PosOrd_SeqI1[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2" and
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1231
                                   ?w1.0="w\<^sub>1" and ?w2.0="w\<^sub>2"]}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1232
  \textit{(6)} & If
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1233
  @{thm (prem 1) PosOrd_Stars_append_eq[where ?vs1.0="vs\<^sub>1" and ?vs2.0="vs\<^sub>2"]} \;then\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1234
  @{thm (lhs) PosOrd_Stars_append_eq[where ?vs1.0="vs\<^sub>1" and ?vs2.0="vs\<^sub>2"]} \;iff\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1235
  @{thm (rhs) PosOrd_Stars_append_eq[where ?vs1.0="vs\<^sub>1" and ?vs2.0="vs\<^sub>2"]}\\  
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1236
  
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1237
  \textit{(7)} & If
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1238
  @{thm (prem 2) PosOrd_StarsI[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2" and
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1239
                            ?vs1.0="vs\<^sub>1" and ?vs2.0="vs\<^sub>2"]} \;and\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1240
  @{thm (prem 1) PosOrd_StarsI[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2" and
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1241
                            ?vs1.0="vs\<^sub>1" and ?vs2.0="vs\<^sub>2"]} \;then\;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1242
   @{thm (concl) PosOrd_StarsI[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2" and
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1243
                            ?vs1.0="vs\<^sub>1" and ?vs2.0="vs\<^sub>2"]}\\
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1244
  \end{tabular} 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1245
  \end{proposition}
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1246
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1247
  \noindent One might prefer that statements \textit{(4)} and \textit{(5)} 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1248
  (respectively \textit{(6)} and \textit{(7)})
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1249
  are combined into a single \textit{iff}-statement (like the ones for \<open>Left\<close> and \<open>Right\<close>). Unfortunately this cannot be done easily: such
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1250
  a single statement would require an additional assumption about the
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1251
  two values @{term "Seq v\<^sub>1 v\<^sub>2"} and @{term "Seq w\<^sub>1 w\<^sub>2"}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1252
  being inhabited by the same regular expression. The
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1253
  complexity of the proofs involved seems to not justify such a
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1254
  `cleaner' single statement. The statements given are just the properties that
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
  1255
  allow us to establish our theorems without any difficulty. The proofs 
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
  1256
  for Proposition~\ref{ordintros} are routine.
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1257
 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1258
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1259
  Next we establish how Okui and Suzuki's orderings relate to our
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1260
  definition of POSIX values.  Given a \<open>POSIX\<close> value \<open>v\<^sub>1\<close>
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1261
  for \<open>r\<close> and \<open>s\<close>, then any other lexical value \<open>v\<^sub>2\<close> in @{term "LV r s"} is greater or equal than \<open>v\<^sub>1\<close>, namely:
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1262
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1263
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1264
  \begin{theorem}\label{orderone}
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1265
  @{thm [mode=IfThen] Posix_PosOrd[where ?v1.0="v\<^sub>1" and ?v2.0="v\<^sub>2"]}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1266
  \end{theorem}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1267
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1268
  \begin{proof} By induction on our POSIX rules. By
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1269
  Theorem~\ref{posixdeterm} and the definition of @{const LV}, it is clear
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1270
  that \<open>v\<^sub>1\<close> and \<open>v\<^sub>2\<close> have the same
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1271
  underlying string @{term s}.  The three base cases are
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1272
  straightforward: for example for @{term "v\<^sub>1 = Void"}, we have
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1273
  that @{term "v\<^sub>2 \<in> LV ONE []"} must also be of the form
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1274
  \mbox{@{term "v\<^sub>2 = Void"}}. Therefore we have @{term
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1275
  "v\<^sub>1 :\<sqsubseteq>val v\<^sub>2"}.  The inductive cases for
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1276
  \<open>r\<close> being of the form @{term "ALT r\<^sub>1 r\<^sub>2"} and
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1277
  @{term "SEQ r\<^sub>1 r\<^sub>2"} are as follows:
269
12772d537b71 updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
  1278
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1279
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1280
  \begin{itemize} 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1281
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1282
  \item[$\bullet$] Case \<open>P+L\<close> with @{term "s \<in> (ALT r\<^sub>1 r\<^sub>2)
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1283
  \<rightarrow> (Left w\<^sub>1)"}: In this case the value 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1284
  @{term "v\<^sub>2"} is either of the
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1285
  form @{term "Left w\<^sub>2"} or @{term "Right w\<^sub>2"}. In the
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1286
  latter case we can immediately conclude with \mbox{@{term "v\<^sub>1
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1287
  :\<sqsubseteq>val v\<^sub>2"}} since a \<open>Left\<close>-value with the
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1288
  same underlying string \<open>s\<close> is always smaller than a
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1289
  \<open>Right\<close>-value by Proposition~\ref{ordintros}\textit{(1)}.  
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1290
  In the former case we have @{term "w\<^sub>2
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1291
  \<in> LV r\<^sub>1 s"} and can use the induction hypothesis to infer
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1292
  @{term "w\<^sub>1 :\<sqsubseteq>val w\<^sub>2"}. Because @{term
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1293
  "w\<^sub>1"} and @{term "w\<^sub>2"} have the same underlying string
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1294
  \<open>s\<close>, we can conclude with @{term "Left w\<^sub>1
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1295
  :\<sqsubseteq>val Left w\<^sub>2"} using
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1296
  Proposition~\ref{ordintros}\textit{(2)}.\smallskip
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1297
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1298
  \item[$\bullet$] Case \<open>P+R\<close> with @{term "s \<in> (ALT r\<^sub>1 r\<^sub>2)
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1299
  \<rightarrow> (Right w\<^sub>1)"}: This case similar to the previous
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1300
  case, except that we additionally know @{term "s \<notin> L
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1301
  r\<^sub>1"}. This is needed when @{term "v\<^sub>2"} is of the form
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1302
  \mbox{@{term "Left w\<^sub>2"}}. Since \mbox{@{term "flat v\<^sub>2 = flat
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1303
  w\<^sub>2"} \<open>= s\<close>} and @{term "\<Turnstile> w\<^sub>2 :
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1304
  r\<^sub>1"}, we can derive a contradiction for \mbox{@{term "s \<notin> L
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1305
  r\<^sub>1"}} using
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1306
  Proposition~\ref{inhabs}. So also in this case \mbox{@{term "v\<^sub>1
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1307
  :\<sqsubseteq>val v\<^sub>2"}}.\smallskip
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1308
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1309
  \item[$\bullet$] Case \<open>PS\<close> with @{term "(s\<^sub>1 @
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1310
  s\<^sub>2) \<in> (SEQ r\<^sub>1 r\<^sub>2) \<rightarrow> (Seq
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1311
  w\<^sub>1 w\<^sub>2)"}: We can assume @{term "v\<^sub>2 = Seq
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1312
  (u\<^sub>1) (u\<^sub>2)"} with @{term "\<Turnstile> u\<^sub>1 :
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1313
  r\<^sub>1"} and \mbox{@{term "\<Turnstile> u\<^sub>2 :
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1314
  r\<^sub>2"}}. We have @{term "s\<^sub>1 @ s\<^sub>2 = (flat
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1315
  u\<^sub>1) @ (flat u\<^sub>2)"}.  By the side-condition of the
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1316
  \<open>PS\<close>-rule we know that either @{term "s\<^sub>1 = flat
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1317
  u\<^sub>1"} or that @{term "flat u\<^sub>1"} is a strict prefix of
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1318
  @{term "s\<^sub>1"}. In the latter case we can infer @{term
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1319
  "w\<^sub>1 :\<sqsubset>val u\<^sub>1"} by
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1320
  Proposition~\ref{ordlen}\textit{(2)} and from this @{term "v\<^sub>1
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1321
  :\<sqsubseteq>val v\<^sub>2"} by Proposition~\ref{ordintros}\textit{(5)}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1322
  (as noted above @{term "v\<^sub>1"} and @{term "v\<^sub>2"} must have the
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1323
  same underlying string).
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1324
  In the former case we know
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1325
  @{term "u\<^sub>1 \<in> LV r\<^sub>1 s\<^sub>1"} and @{term
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1326
  "u\<^sub>2 \<in> LV r\<^sub>2 s\<^sub>2"}. With this we can use the
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1327
  induction hypotheses to infer @{term "w\<^sub>1 :\<sqsubseteq>val
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1328
  u\<^sub>1"} and @{term "w\<^sub>2 :\<sqsubseteq>val u\<^sub>2"}. By
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1329
  Proposition~\ref{ordintros}\textit{(4,5)} we can again infer 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1330
  @{term "v\<^sub>1 :\<sqsubseteq>val
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1331
  v\<^sub>2"}.
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1332
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1333
  \end{itemize}
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1334
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1335
  \noindent The case for \<open>P\<star>\<close> is similar to the \<open>PS\<close>-case and omitted.\qed
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1336
  \end{proof}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1337
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1338
  \noindent This theorem shows that our \<open>POSIX\<close> value for a
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1339
  regular expression \<open>r\<close> and string @{term s} is in fact a
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1340
  minimal element of the values in \<open>LV r s\<close>. By
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1341
  Proposition~\ref{ordlen}\textit{(2)} we also know that any value in
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1342
  \<open>LV r s'\<close>, with @{term "s'"} being a strict prefix, cannot be
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1343
  smaller than \<open>v\<^sub>1\<close>. The next theorem shows the
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1344
  opposite---namely any minimal element in @{term "LV r s"} must be a
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1345
  \<open>POSIX\<close> value. This can be established by induction on \<open>r\<close>, but the proof can be drastically simplified by using the fact
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1346
  from the previous section about the existence of a \<open>POSIX\<close> value
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1347
  whenever a string @{term "s \<in> L r"}.
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1348
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1349
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1350
  \begin{theorem}
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1351
  @{thm [mode=IfThen] PosOrd_Posix[where ?v1.0="v\<^sub>1"]} 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1352
  \end{theorem}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1353
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1354
  \begin{proof} 
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1355
  If @{thm (prem 1) PosOrd_Posix[where ?v1.0="v\<^sub>1"]} then 
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1356
  @{term "s \<in> L r"} by Proposition~\ref{inhabs}. Hence by Theorem~\ref{lexercorrect}(2) 
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1357
  there exists a
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1358
  \<open>POSIX\<close> value @{term "v\<^sub>P"} with @{term "s \<in> r \<rightarrow> v\<^sub>P"}
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1359
  and by Lemma~\ref{LVposix} we also have \mbox{@{term "v\<^sub>P \<in> LV r s"}}.
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1360
  By Theorem~\ref{orderone} we therefore have 
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1361
  @{term "v\<^sub>P :\<sqsubseteq>val v\<^sub>1"}. If @{term "v\<^sub>P = v\<^sub>1"} then
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1362
  we are done. Otherwise we have @{term "v\<^sub>P :\<sqsubset>val v\<^sub>1"}, which 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1363
  however contradicts the second assumption about @{term "v\<^sub>1"} being the smallest
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1364
  element in @{term "LV r s"}. So we are done in this case too.\qed
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1365
  \end{proof}
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1366
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1367
  \noindent
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1368
  From this we can also show 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1369
  that if @{term "LV r s"} is non-empty (or equivalently @{term "s \<in> L r"}) then 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1370
  it has a unique minimal element:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1371
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1372
  \begin{corollary}
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1373
  @{thm [mode=IfThen] Least_existence1}
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1374
  \end{corollary}
270
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1375
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1376
462d893ecb3d updated
Christian Urban <urbanc@in.tum.de>
parents: 269
diff changeset
  1377
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1378
  \noindent To sum up, we have shown that the (unique) minimal elements 
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1379
  of the ordering by Okui and Suzuki are exactly the \<open>POSIX\<close>
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1380
  values we defined inductively in Section~\ref{posixsec}. This provides
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1381
  an independent confirmation that our ternary relation formalises the
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1382
  informal POSIX rules. 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
  1383
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1384
\<close>
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
  1385
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1386
section \<open>Bitcoded Lexing\<close>
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1387
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1388
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents: 363
diff changeset
  1389
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents: 363
diff changeset
  1390
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1391
text \<open>
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1392
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1393
Incremental calculation of the value. To simplify the proof we first define the function
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1394
@{const flex} which calculates the ``iterated'' injection function. With this we can 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1395
rewrite the lexer as
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1396
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1397
\begin{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1398
@{thm lexer_flex}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1399
\end{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1400
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1401
\begin{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1402
  \begin{tabular}{lcl}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1403
  @{thm (lhs) code.simps(1)} & $\dn$ & @{thm (rhs) code.simps(1)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1404
  @{thm (lhs) code.simps(2)} & $\dn$ & @{thm (rhs) code.simps(2)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1405
  @{thm (lhs) code.simps(3)} & $\dn$ & @{thm (rhs) code.simps(3)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1406
  @{thm (lhs) code.simps(4)} & $\dn$ & @{thm (rhs) code.simps(4)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1407
  @{thm (lhs) code.simps(5)[of "v\<^sub>1" "v\<^sub>2"]} & $\dn$ & @{thm (rhs) code.simps(5)[of "v\<^sub>1" "v\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1408
  @{thm (lhs) code.simps(6)} & $\dn$ & @{thm (rhs) code.simps(6)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1409
  @{thm (lhs) code.simps(7)} & $\dn$ & @{thm (rhs) code.simps(7)}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1410
\end{tabular}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1411
\end{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1412
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1413
\begin{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1414
\begin{tabular}{lcl}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1415
  @{term areg} & $::=$ & @{term "AZERO"}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1416
               & $\mid$ & @{term "AONE bs"}\\
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 330
diff changeset
  1417
               & $\mid$ & @{term "ACH bs c"}\\
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents: 363
diff changeset
  1418
               & $\mid$ & @{term "AALT bs r1 r2"}\\
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1419
               & $\mid$ & @{term "ASEQ bs r\<^sub>1 r\<^sub>2"}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1420
               & $\mid$ & @{term "ASTAR bs r"}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1421
\end{tabular}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1422
\end{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1423
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents: 363
diff changeset
  1424
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1425
\begin{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1426
  \begin{tabular}{lcl}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1427
  @{thm (lhs) intern.simps(1)} & $\dn$ & @{thm (rhs) intern.simps(1)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1428
  @{thm (lhs) intern.simps(2)} & $\dn$ & @{thm (rhs) intern.simps(2)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1429
  @{thm (lhs) intern.simps(3)} & $\dn$ & @{thm (rhs) intern.simps(3)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1430
  @{thm (lhs) intern.simps(4)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) intern.simps(4)[of "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1431
  @{thm (lhs) intern.simps(5)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) intern.simps(5)[of "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1432
  @{thm (lhs) intern.simps(6)} & $\dn$ & @{thm (rhs) intern.simps(6)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1433
\end{tabular}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1434
\end{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1435
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1436
\begin{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1437
  \begin{tabular}{lcl}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1438
  @{thm (lhs) erase.simps(1)} & $\dn$ & @{thm (rhs) erase.simps(1)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1439
  @{thm (lhs) erase.simps(2)[of bs]} & $\dn$ & @{thm (rhs) erase.simps(2)[of bs]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1440
  @{thm (lhs) erase.simps(3)[of bs]} & $\dn$ & @{thm (rhs) erase.simps(3)[of bs]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1441
  @{thm (lhs) erase.simps(4)[of bs "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) erase.simps(4)[of bs "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1442
  @{thm (lhs) erase.simps(5)[of bs "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) erase.simps(5)[of bs "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1443
  @{thm (lhs) erase.simps(6)[of bs]} & $\dn$ & @{thm (rhs) erase.simps(6)[of bs]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1444
\end{tabular}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1445
\end{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1446
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1447
Some simple facts about erase
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1448
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1449
\begin{lemma}\mbox{}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1450
@{thm erase_bder}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1451
@{thm erase_intern}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1452
\end{lemma}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1453
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1454
\begin{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1455
  \begin{tabular}{lcl}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1456
  @{thm (lhs) bnullable.simps(1)} & $\dn$ & @{thm (rhs) bnullable.simps(1)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1457
  @{thm (lhs) bnullable.simps(2)} & $\dn$ & @{thm (rhs) bnullable.simps(2)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1458
  @{thm (lhs) bnullable.simps(3)} & $\dn$ & @{thm (rhs) bnullable.simps(3)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1459
  @{thm (lhs) bnullable.simps(4)[of bs "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) bnullable.simps(4)[of bs "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1460
  @{thm (lhs) bnullable.simps(5)[of bs "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) bnullable.simps(5)[of bs "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1461
  @{thm (lhs) bnullable.simps(6)} & $\dn$ & @{thm (rhs) bnullable.simps(6)}\medskip\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1462
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1463
%  \end{tabular}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1464
%  \end{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1465
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1466
%  \begin{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1467
%  \begin{tabular}{lcl}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1468
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1469
  @{thm (lhs) bder.simps(1)} & $\dn$ & @{thm (rhs) bder.simps(1)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1470
  @{thm (lhs) bder.simps(2)} & $\dn$ & @{thm (rhs) bder.simps(2)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1471
  @{thm (lhs) bder.simps(3)} & $\dn$ & @{thm (rhs) bder.simps(3)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1472
  @{thm (lhs) bder.simps(4)[of bs "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) bder.simps(4)[of bs "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1473
  @{thm (lhs) bder.simps(5)[of bs "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) bder.simps(5)[of bs "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1474
  @{thm (lhs) bder.simps(6)} & $\dn$ & @{thm (rhs) bder.simps(6)}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1475
  \end{tabular}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1476
  \end{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1477
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1478
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1479
\begin{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1480
  \begin{tabular}{lcl}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1481
  @{thm (lhs) bmkeps.simps(1)} & $\dn$ & @{thm (rhs) bmkeps.simps(1)}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1482
  @{thm (lhs) bmkeps.simps(2)[of bs "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) bmkeps.simps(2)[of bs "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1483
  @{thm (lhs) bmkeps.simps(3)[of bs "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) bmkeps.simps(3)[of bs "r\<^sub>1" "r\<^sub>2"]}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1484
  @{thm (lhs) bmkeps.simps(4)} & $\dn$ & @{thm (rhs) bmkeps.simps(4)}\medskip\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1485
\end{tabular}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1486
\end{center}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1487
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1488
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1489
@{thm [mode=IfThen] bder_retrieve}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1490
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1491
By induction on \<open>r\<close>
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1492
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1493
\begin{theorem}[Main Lemma]\mbox{}\\
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1494
@{thm [mode=IfThen] MAIN_decode}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1495
\end{theorem}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1496
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1497
\noindent
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1498
Definition of the bitcoded lexer
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1499
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1500
@{thm blexer_def}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1501
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1502
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1503
\begin{theorem}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1504
@{thm blexer_correctness}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1505
\end{theorem}
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1506
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1507
\<close>
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
  1508
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1509
section \<open>Optimisations\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1510
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1511
text \<open>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1512
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1513
  Derivatives as calculated by \Brz's method are usually more complex
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1514
  regular expressions than the initial one; the result is that the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1515
  derivative-based matching and lexing algorithms are often abysmally slow.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1516
  However, various optimisations are possible, such as the simplifications
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1517
  of @{term "ALT ZERO r"}, @{term "ALT r ZERO"}, @{term "SEQ ONE r"} and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1518
  @{term "SEQ r ONE"} to @{term r}. These simplifications can speed up the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1519
  algorithms considerably, as noted in \cite{Sulzmann2014}. One of the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1520
  advantages of having a simple specification and correctness proof is that
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1521
  the latter can be refined to prove the correctness of such simplification
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1522
  steps. While the simplification of regular expressions according to 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1523
  rules like
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1524
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1525
  \begin{equation}\label{Simpl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1526
  \begin{array}{lcllcllcllcl}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1527
  @{term "ALT ZERO r"} & \<open>\<Rightarrow>\<close> & @{term r} \hspace{8mm}%\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1528
  @{term "ALT r ZERO"} & \<open>\<Rightarrow>\<close> & @{term r} \hspace{8mm}%\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1529
  @{term "SEQ ONE r"}  & \<open>\<Rightarrow>\<close> & @{term r} \hspace{8mm}%\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1530
  @{term "SEQ r ONE"}  & \<open>\<Rightarrow>\<close> & @{term r}
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1531
  \end{array}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1532
  \end{equation}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1533
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1534
  \noindent is well understood, there is an obstacle with the POSIX value
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1535
  calculation algorithm by Sulzmann and Lu: if we build a derivative regular
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1536
  expression and then simplify it, we will calculate a POSIX value for this
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1537
  simplified derivative regular expression, \emph{not} for the original (unsimplified)
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1538
  derivative regular expression. Sulzmann and Lu \cite{Sulzmann2014} overcome this obstacle by
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1539
  not just calculating a simplified regular expression, but also calculating
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1540
  a \emph{rectification function} that ``repairs'' the incorrect value.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1541
  
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1542
  The rectification functions can be (slightly clumsily) implemented  in
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1543
  Isabelle/HOL as follows using some auxiliary functions:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1544
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1545
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1546
  \begin{tabular}{lcl}
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1547
  @{thm (lhs) F_RIGHT.simps(1)} & $\dn$ & \<open>Right (f v)\<close>\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1548
  @{thm (lhs) F_LEFT.simps(1)} & $\dn$ & \<open>Left (f v)\<close>\\
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1549
  
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1550
  @{thm (lhs) F_ALT.simps(1)} & $\dn$ & \<open>Right (f\<^sub>2 v)\<close>\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1551
  @{thm (lhs) F_ALT.simps(2)} & $\dn$ & \<open>Left (f\<^sub>1 v)\<close>\\
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1552
  
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1553
  @{thm (lhs) F_SEQ1.simps(1)} & $\dn$ & \<open>Seq (f\<^sub>1 ()) (f\<^sub>2 v)\<close>\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1554
  @{thm (lhs) F_SEQ2.simps(1)} & $\dn$ & \<open>Seq (f\<^sub>1 v) (f\<^sub>2 ())\<close>\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1555
  @{thm (lhs) F_SEQ.simps(1)} & $\dn$ & \<open>Seq (f\<^sub>1 v\<^sub>1) (f\<^sub>2 v\<^sub>2)\<close>\medskip\\
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1556
  %\end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1557
  %
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1558
  %\begin{tabular}{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1559
  @{term "simp_ALT (ZERO, DUMMY) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(r\<^sub>2, F_RIGHT f\<^sub>2)"}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1560
  @{term "simp_ALT (r\<^sub>1, f\<^sub>1) (ZERO, DUMMY)"} & $\dn$ & @{term "(r\<^sub>1, F_LEFT f\<^sub>1)"}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1561
  @{term "simp_ALT (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(ALT r\<^sub>1 r\<^sub>2, F_ALT f\<^sub>1 f\<^sub>2)"}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1562
  @{term "simp_SEQ (ONE, f\<^sub>1) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(r\<^sub>2, F_SEQ1 f\<^sub>1 f\<^sub>2)"}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1563
  @{term "simp_SEQ (r\<^sub>1, f\<^sub>1) (ONE, f\<^sub>2)"} & $\dn$ & @{term "(r\<^sub>1, F_SEQ2 f\<^sub>1 f\<^sub>2)"}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1564
  @{term "simp_SEQ (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(SEQ r\<^sub>1 r\<^sub>2, F_SEQ f\<^sub>1 f\<^sub>2)"}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1565
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1566
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1567
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1568
  \noindent
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1569
  The functions \<open>simp\<^bsub>Alt\<^esub>\<close> and \<open>simp\<^bsub>Seq\<^esub>\<close> encode the simplification rules
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1570
  in \eqref{Simpl} and compose the rectification functions (simplifications can occur
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1571
  deep inside the regular expression). The main simplification function is then 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1572
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1573
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1574
  \begin{tabular}{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1575
  @{term "simp (ALT r\<^sub>1 r\<^sub>2)"} & $\dn$ & @{term "simp_ALT (simp r\<^sub>1) (simp r\<^sub>2)"}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1576
  @{term "simp (SEQ r\<^sub>1 r\<^sub>2)"} & $\dn$ & @{term "simp_SEQ (simp r\<^sub>1) (simp r\<^sub>2)"}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1577
  @{term "simp r"} & $\dn$ & @{term "(r, id)"}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1578
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1579
  \end{center} 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1580
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1581
  \noindent where @{term "id"} stands for the identity function. The
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1582
  function @{const simp} returns a simplified regular expression and a corresponding
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1583
  rectification function. Note that we do not simplify under stars: this
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1584
  seems to slow down the algorithm, rather than speed it up. The optimised
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1585
  lexer is then given by the clauses:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1586
  
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1587
  \begin{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1588
  \begin{tabular}{lcl}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1589
  @{thm (lhs) slexer.simps(1)} & $\dn$ & @{thm (rhs) slexer.simps(1)}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1590
  @{thm (lhs) slexer.simps(2)} & $\dn$ & 
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1591
                         \<open>let (r\<^sub>s, f\<^sub>r) = simp (r \<close>$\backslash$\<open> c) in\<close>\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1592
                     & & \<open>case\<close> @{term "slexer r\<^sub>s s"} \<open>of\<close>\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1593
                     & & \phantom{$|$} @{term "None"}  \<open>\<Rightarrow>\<close> @{term None}\\
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1594
                     & & $|$ @{term "Some v"} \<open>\<Rightarrow>\<close> \<open>Some (inj r c (f\<^sub>r v))\<close>                          
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1595
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1596
  \end{center}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1597
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1598
  \noindent
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1599
  In the second clause we first calculate the derivative @{term "der c r"}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1600
  and then simplify the result. This gives us a simplified derivative
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1601
  \<open>r\<^sub>s\<close> and a rectification function \<open>f\<^sub>r\<close>. The lexer
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1602
  is then recursively called with the simplified derivative, but before
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1603
  we inject the character @{term c} into the value @{term v}, we need to rectify
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1604
  @{term v} (that is construct @{term "f\<^sub>r v"}). Before we can establish the correctness
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1605
  of @{term "slexer"}, we need to show that simplification preserves the language
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1606
  and simplification preserves our POSIX relation once the value is rectified
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1607
  (recall @{const "simp"} generates a (regular expression, rectification function) pair):
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1608
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1609
  \begin{lemma}\mbox{}\smallskip\\\label{slexeraux}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1610
  \begin{tabular}{ll}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1611
  (1) & @{thm L_fst_simp[symmetric]}\\
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1612
  (2) & @{thm[mode=IfThen] Posix_simp}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1613
  \end{tabular}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1614
  \end{lemma}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1615
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1616
  \begin{proof} Both are by induction on \<open>r\<close>. There is no
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1617
  interesting case for the first statement. For the second statement,
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1618
  of interest are the @{term "r = ALT r\<^sub>1 r\<^sub>2"} and @{term "r = SEQ r\<^sub>1
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1619
  r\<^sub>2"} cases. In each case we have to analyse four subcases whether
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1620
  @{term "fst (simp r\<^sub>1)"} and @{term "fst (simp r\<^sub>2)"} equals @{const
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1621
  ZERO} (respectively @{const ONE}). For example for @{term "r = ALT
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1622
  r\<^sub>1 r\<^sub>2"}, consider the subcase @{term "fst (simp r\<^sub>1) = ZERO"} and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1623
  @{term "fst (simp r\<^sub>2) \<noteq> ZERO"}. By assumption we know @{term "s \<in>
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1624
  fst (simp (ALT r\<^sub>1 r\<^sub>2)) \<rightarrow> v"}. From this we can infer @{term "s \<in> fst (simp r\<^sub>2) \<rightarrow> v"}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1625
  and by IH also (*) @{term "s \<in> r\<^sub>2 \<rightarrow> (snd (simp r\<^sub>2) v)"}. Given @{term "fst (simp r\<^sub>1) = ZERO"}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1626
  we know @{term "L (fst (simp r\<^sub>1)) = {}"}. By the first statement
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1627
  @{term "L r\<^sub>1"} is the empty set, meaning (**) @{term "s \<notin> L r\<^sub>1"}.
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1628
  Taking (*) and (**) together gives by the \mbox{\<open>P+R\<close>}-rule 
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1629
  @{term "s \<in> ALT r\<^sub>1 r\<^sub>2 \<rightarrow> Right (snd (simp r\<^sub>2) v)"}. In turn this
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1630
  gives @{term "s \<in> ALT r\<^sub>1 r\<^sub>2 \<rightarrow> snd (simp (ALT r\<^sub>1 r\<^sub>2)) v"} as we need to show.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1631
  The other cases are similar.\qed
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1632
  \end{proof}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1633
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1634
  \noindent We can now prove relatively straightforwardly that the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1635
  optimised lexer produces the expected result:
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1636
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1637
  \begin{theorem}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1638
  @{thm slexer_correctness}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1639
  \end{theorem}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1640
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1641
  \begin{proof} By induction on @{term s} generalising over @{term
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1642
  r}. The case @{term "[]"} is trivial. For the cons-case suppose the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1643
  string is of the form @{term "c # s"}. By induction hypothesis we
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1644
  know @{term "slexer r s = lexer r s"} holds for all @{term r} (in
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1645
  particular for @{term "r"} being the derivative @{term "der c
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1646
  r"}). Let @{term "r\<^sub>s"} be the simplified derivative regular expression, that is @{term
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1647
  "fst (simp (der c r))"}, and @{term "f\<^sub>r"} be the rectification
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1648
  function, that is @{term "snd (simp (der c r))"}.  We distinguish the cases
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1649
  whether (*) @{term "s \<in> L (der c r)"} or not. In the first case we
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1650
  have by Theorem~\ref{lexercorrect}(2) a value @{term "v"} so that @{term
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1651
  "lexer (der c r) s = Some v"} and @{term "s \<in> der c r \<rightarrow> v"} hold.
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1652
  By Lemma~\ref{slexeraux}(1) we can also infer from~(*) that @{term "s
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1653
  \<in> L r\<^sub>s"} holds.  Hence we know by Theorem~\ref{lexercorrect}(2) that
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1654
  there exists a @{term "v'"} with @{term "lexer r\<^sub>s s = Some v'"} and
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1655
  @{term "s \<in> r\<^sub>s \<rightarrow> v'"}. From the latter we know by
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1656
  Lemma~\ref{slexeraux}(2) that @{term "s \<in> der c r \<rightarrow> (f\<^sub>r v')"} holds.
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1657
  By the uniqueness of the POSIX relation (Theorem~\ref{posixdeterm}) we
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1658
  can infer that @{term v} is equal to @{term "f\<^sub>r v'"}---that is the 
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1659
  rectification function applied to @{term "v'"}
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1660
  produces the original @{term "v"}.  Now the case follows by the
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1661
  definitions of @{const lexer} and @{const slexer}.
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1662
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1663
  In the second case where @{term "s \<notin> L (der c r)"} we have that
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1664
  @{term "lexer (der c r) s = None"} by Theorem~\ref{lexercorrect}(1).  We
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1665
  also know by Lemma~\ref{slexeraux}(1) that @{term "s \<notin> L r\<^sub>s"}. Hence
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1666
  @{term "lexer r\<^sub>s s = None"} by Theorem~\ref{lexercorrect}(1) and
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1667
  by IH then also @{term "slexer r\<^sub>s s = None"}. With this we can
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1668
  conclude in this case too.\qed   
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1669
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1670
  \end{proof} 
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1671
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1672
\<close>
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1673
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 271
diff changeset
  1674
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1675
section \<open>HERE\<close>
318
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1676
330
89e6605c4ca4 updated
Christian Urban <urbanc@in.tum.de>
parents: 318
diff changeset
  1677
text \<open>
318
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1678
  \begin{center}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1679
  \begin{tabular}{llcl}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1680
  1) & @{thm (lhs) erase.simps(1)} & $\dn$ & @{thm (rhs) erase.simps(1)}\\
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1681
  2) & @{thm (lhs) erase.simps(2)[of bs]} & $\dn$ & @{thm (rhs) erase.simps(2)[of bs]}\\
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1682
  3) & @{thm (lhs) erase.simps(3)[of bs]} & $\dn$ & @{thm (rhs) erase.simps(3)[of bs]}\\
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1683
  4a) & @{term "erase (AALTs bs [])"} & $\dn$ & @{term ZERO}\\
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1684
  4b) & @{term "erase (AALTs bs [r])"} & $\dn$ & @{term "erase r"}\\
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1685
  4c) & @{term "erase (AALTs bs (r\<^sub>1#r\<^sub>2#rs))"} & $\dn$ & 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1686
        @{term "ALT (erase r\<^sub>1) (erase (AALTs bs (r\<^sub>2#rs)))"}\\
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1687
  5) & @{thm (lhs) erase.simps(5)[of bs "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) erase.simps(5)[of bs "r\<^sub>1" "r\<^sub>2"]}\\
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1688
  6) & @{thm (lhs) erase.simps(6)[of bs]} & $\dn$ & @{thm (rhs) erase.simps(6)[of bs]}\\
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1689
  \end{tabular}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1690
  \end{center}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1691
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1692
  \begin{lemma}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1693
  @{thm [mode=IfThen] bder_retrieve}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1694
  \end{lemma}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1695
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1696
  \begin{proof}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1697
  By induction on the definition of @{term "erase r"}. The cases for rule 1) and 2) are
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1698
  straightforward as @{term "der c ZERO"} and @{term "der c ONE"} are both equal to 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1699
  @{term ZERO}. This means @{term "\<Turnstile> v : ZERO"} cannot hold. Similarly in case of rule 3)
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 330
diff changeset
  1700
  where @{term r} is of the form @{term "ACH d"} with @{term "c = d"}. Then by assumption
318
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1701
  we know @{term "\<Turnstile> v : ONE"}, which implies @{term "v = Void"}. The equation follows by 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1702
  simplification of left- and right-hand side. In  case @{term "c \<noteq> d"} we have again
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1703
  @{term "\<Turnstile> v : ZERO"}, which cannot  hold. 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1704
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1705
  For rule 4a) we have again @{term "\<Turnstile> v : ZERO"}. The property holds by IH for rule 4b).
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1706
  The  induction hypothesis is 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1707
  \[
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1708
  @{term "retrieve (bder c r) v = retrieve r (injval (erase r) c v)"}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1709
  \]
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1710
  which is what left- and right-hand side simplify to.  The slightly more interesting case
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1711
  is for 4c). By assumption  we have 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1712
  @{term "\<Turnstile> v : ALT (der c (erase r\<^sub>1)) (der c (erase (AALTs bs (r\<^sub>2 # rs))))"}. This means we 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1713
  have either (*) @{term "\<Turnstile> v1 : der c (erase r\<^sub>1)"} with @{term "v = Left v1"} or
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1714
  (**) @{term "\<Turnstile> v2 : der c (erase (AALTs bs (r\<^sub>2 # rs)))"} with @{term "v = Right v2"}.
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1715
  The former  case is straightforward by simplification. The second case is \ldots TBD.
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1716
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1717
  Rule 5) TBD.
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1718
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1719
  Finally for rule 6) the reasoning is as follows:   By assumption we  have
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1720
  @{term "\<Turnstile> v : SEQ (der c (erase r)) (STAR (erase r))"}. This means we also have
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1721
  @{term "v = Seq v1 v2"}, @{term "\<Turnstile> v1 : der c (erase r)"}  and @{term "v2 = Stars vs"}.
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1722
  We want to prove
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1723
  \begin{align}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1724
  & @{term "retrieve (ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)) v"}\\
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1725
  &= @{term "retrieve (ASTAR bs r) (injval (STAR (erase r)) c v)"}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1726
  \end{align}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1727
  The right-hand side @{term inj}-expression is equal to 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1728
  @{term "Stars (injval (erase r) c v1 # vs)"}, which means the @{term  retrieve}-expression
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1729
  simplifies to 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1730
  \[
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1731
  @{term "bs @ [Z] @ retrieve r (injval (erase r) c v1) @ retrieve (ASTAR [] r) (Stars vs)"}
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1732
  \]
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1733
  The left-hand side (3) above simplifies to 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1734
  \[
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1735
  @{term "bs @ retrieve (fuse [Z] (bder c r)) v1 @ retrieve (ASTAR [] r) (Stars vs)"} 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1736
  \]
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1737
  We can move out the @{term "fuse  [Z]"} and then use the IH to show that left-hand side
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1738
  and right-hand side are equal. This completes the proof. 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1739
  \end{proof}   
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 292
diff changeset
  1740
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1741
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1742
363
fc346faada4e updated for Isabelle 2021
Christian Urban <christian.urban@kcl.ac.uk>
parents: 362
diff changeset
  1743
  \bibliographystyle{plain}
fc346faada4e updated for Isabelle 2021
Christian Urban <christian.urban@kcl.ac.uk>
parents: 362
diff changeset
  1744
  \bibliography{root}
fc346faada4e updated for Isabelle 2021
Christian Urban <christian.urban@kcl.ac.uk>
parents: 362
diff changeset
  1745
fc346faada4e updated for Isabelle 2021
Christian Urban <christian.urban@kcl.ac.uk>
parents: 362
diff changeset
  1746
\<close>
218
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1747
(*<*)
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1748
end
16af5b8bd285 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1749
(*>*)