coursework/cw05.tex
author Christian Urban <urbanc@in.tum.de>
Tue, 04 Dec 2018 00:33:26 +0000
changeset 616 24bbe4e4b37b
parent 567 4573d36d0b2f
child 630 9b1c15c3eb6f
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
253
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\documentclass{article}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\usepackage{../style}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
\usepackage{../langs}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
\begin{document}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
     7
\section*{Coursework (Strand 2)}
253
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
556
40e22ad45744 updated
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
     9
\noindent This coursework is worth 20\% and is due on 14 December at
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    10
18:00. You are asked to prove the correctness of the regular
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
    11
expression matcher from the lectures using the Isabelle theorem
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
    12
prover. You need to submit a theory file containing this proof. The
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
    13
Isabelle theorem prover is available from
253
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
\begin{center}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
\url{http://isabelle.in.tum.de}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
\end{center}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    19
\noindent This is an interactive theorem prover, meaning that
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    20
you can make definitions and state properties, and then help
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    21
the system with proving these properties. Sometimes the proofs
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    22
are also completely automatic. There is a shortish user guide for
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    23
Isabelle, called ``Programming and Proving in Isabelle/HOL''
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    24
at
253
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
\begin{center}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
\url{http://isabelle.in.tum.de/documentation.html}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
\end{center}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
\noindent
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
and also a longer (free) book at
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
\begin{center}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
\url{http://www.concrete-semantics.org}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
\end{center}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    37
\noindent The Isabelle theorem prover is operated through the
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    38
jEdit IDE, which might not be an editor that is widely known.
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    39
JEdit is documented in
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    40
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    41
\begin{center}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    42
\url{http://isabelle.in.tum.de/dist/Isabelle2014/doc/jedit.pdf}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    43
\end{center}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    44
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    45
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    46
\noindent If you need more help or you are stuck somewhere,
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    47
please feel free to contact me (christian.urban at kcl.ac.uk). I
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
    48
am one of the main developers of Isabelle and have used it for
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    49
approximately 16 years. One of the success stories of
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    50
Isabelle is the recent verification of a microkernel operating
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    51
system by an Australian group, see \url{http://sel4.systems}.
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    52
Their operating system is the only one that has been proved
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    53
correct according to its specification and is used for
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    54
application where high assurance, security and reliability is
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    55
needed (like in helicopters which fly over enemy territory).
253
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    58
\subsection*{The Task}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    59
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    60
In this coursework you are asked to prove the correctness of the
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    61
regular expression matcher from the lectures in Isabelle.  The matcher
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    62
should be able to deal with the usual (basic) regular expressions
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    63
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    64
\[
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    65
\ZERO,\; \ONE,\; c,\; r_1 + r_2,\; r_1 \cdot r_2,\; r^*
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    66
\]
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    67
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    68
\noindent
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    69
but also with the following extended regular expressions:
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    70
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    71
\begin{center}
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    72
\begin{tabular}{ll}
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    73
  $r^{\{n\}}$ & exactly $n$-times\\
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    74
  $r^{\{..m\}}$ & zero or more times $r$ but no more than $m$-times\\
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    75
  $r^{\{n..\}}$ & at least $n$-times $r$\\
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    76
  $r^{\{n..m\}}$ & at least $n$-times $r$ but no more than $m$-times\\
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    77
  $\sim{}r$ & not-regular-expression of $r$\\
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    78
\end{tabular}
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    79
\end{center}
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    80
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    81
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    82
\noindent
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    83
You need to first specify what the matcher is
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    84
supposed to do and then to implement the algorithm. Finally you need
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    85
to prove that the algorithm meets the specification.  The first two
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    86
parts are relatively easy, because the definitions in Isabelle will
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    87
look very similar to the mathematical definitions from the lectures or
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    88
the Scala code that is supplied at KEATS. For example very similar to
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    89
Scala, regular expressions are defined in Isabelle as an inductive
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    90
datatype:
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    91
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    92
\begin{lstlisting}[language={},numbers=none]
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    93
datatype rexp =
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
    94
  ZERO
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
    95
| ONE
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    96
| CHAR char
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    97
| SEQ rexp rexp
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    98
| ALT rexp rexp
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    99
| STAR rexp
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   100
\end{lstlisting}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   101
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   102
\noindent The meaning of regular expressions is given as 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   103
usual:
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   104
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   105
\begin{center}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   106
\begin{tabular}{rcl@{\hspace{10mm}}l}
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   107
$L(\ZERO)$  & $\dn$ & $\varnothing$   & \pcode{ZERO}\\
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   108
$L(\ONE)$     & $\dn$ & $\{[]\}$        & \pcode{ONE}\\ 
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   109
$L(c)$            & $\dn$ & $\{[c]\}$       & \pcode{CHAR}\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   110
$L(r_1 + r_2)$     & $\dn$ & $L(r_1) \cup L(r_2)$ & \pcode{ALT}\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   111
$L(r_1 \cdot r_2)$ & $\dn$ & $L(r_1) \,@\, L(r_2)$ & \pcode{SEQ}\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   112
$L(r^*)$           & $\dn$ & $(L(r))^*$ & \pcode{STAR}\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   113
\end{tabular}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   114
\end{center}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   115
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   116
\noindent You would need to implement this function in order
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   117
to state the theorem about the correctness of the algorithm.
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   118
The function $L$ should in Isabelle take a \pcode{rexp} as
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   119
input and return a set of strings. Its type is
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   120
therefore 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   121
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   122
\begin{center}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   123
\pcode{L} \pcode{::} \pcode{rexp} $\Rightarrow$ \pcode{string set}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   124
\end{center}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   125
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   126
\noindent Isabelle treats strings as an abbreviation for lists
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   127
of characters. This means you can pattern-match strings like
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   128
lists. The union operation on sets (for the \pcode{ALT}-case)
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   129
is a standard definition in Isabelle, but not the
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   130
concatenation operation on sets and also not the
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   131
star-operation. You would have to supply these definitions.
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   132
The concatenation operation can be defined in terms of the
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   133
append function, written \code{_ @ _} in Isabelle, for lists.
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   134
The star-operation can be defined as a ``big-union'' of 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   135
powers, like in the lectures, or directly as an inductive set.
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   136
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   137
The functions for the matcher are shown in
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   138
Figure~\ref{matcher}. The theorem that needs to be proved is
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   139
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   140
\begin{lstlisting}[numbers=none,language={},keywordstyle=\color{black}\ttfamily,mathescape]
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   141
theorem 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   142
  "matches r s $\longleftrightarrow$ s $\in$ L r"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   143
\end{lstlisting}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   144
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   145
\noindent which states that the function \emph{matches} is
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   146
true if and only if the string is in the language of the
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   147
regular expression. A proof for this lemma will need
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   148
side-lemmas about \pcode{nullable} and \pcode{der}. An example
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   149
proof in Isabelle that will not be relevant for the theorem
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   150
above is given in Figure~\ref{proof}.
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   151
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   152
\begin{figure}[p]
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   153
\begin{lstlisting}[language={},keywordstyle=\color{black}\ttfamily,mathescape]
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   154
fun 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   155
  nullable :: "rexp $\Rightarrow$ bool"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   156
where
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   157
  "nullable ZERO = False"
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   158
| "nullable ONE = True"
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   159
| "nullable (CHAR _) = False"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   160
| "nullable (ALT r1 r2) = (nullable(r1) $\vee$ nullable(r2))"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   161
| "nullable (SEQ r1 r2) = (nullable(r1) $\wedge$ nullable(r2))"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   162
| "nullable (STAR _) = True"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   163
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   164
fun 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   165
  der :: "char $\Rightarrow$ rexp $\Rightarrow$ rexp"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   166
where
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   167
  "der c ZERO = ZERO"
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   168
| "der c ONE = ZERO"
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   169
| "der c (CHAR d) = (if c = d then ONE else ZERO)"
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   170
| "der c (ALT r1 r2) = ALT (der c r1) (der c r2)"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   171
| "der c (SEQ r1 r2) = 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   172
     (if (nullable r1) then ALT (SEQ (der c r1) r2) (der c r2)
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   173
                       else SEQ (der c r1) r2)"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   174
| "der c (STAR r) = SEQ (der c r) (STAR r)"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   175
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   176
fun 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   177
  ders :: "rexp $\Rightarrow$ string $\Rightarrow$ rexp"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   178
where
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   179
  "ders r [] = r"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   180
| "ders r (c # s) = ders (der c r) s"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   181
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   182
fun 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   183
  matches :: "rexp $\Rightarrow$ string $\Rightarrow$ bool"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   184
where
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   185
  "matches r s = nullable (ders r s)" 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   186
\end{lstlisting}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   187
\caption{The definition of the matcher algorithm in 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   188
Isabelle.\label{matcher}}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   189
\end{figure}
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   190
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   191
\begin{figure}[p]
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   192
\begin{lstlisting}[language={},keywordstyle=\color{black}\ttfamily,mathescape]
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   193
fun 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   194
  zeroable :: "rexp $\Rightarrow$ bool"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   195
where
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   196
  "zeroable ZERO = True"
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   197
| "zeroable ONE = False"
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   198
| "zeroable (CHAR _) = False"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   199
| "zeroable (ALT r1 r2) = (zeroable(r1) $\wedge$ zeroable(r2))"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   200
| "zeroable (SEQ r1 r2) = (zeroable(r1) $\vee$ zeroable(r2))"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   201
| "zeroable (STAR _) = False"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   202
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   203
lemma
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   204
  "zeroable r $\longleftrightarrow$ L r = {}"
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   205
proof (induct)
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   206
  case (ZERO)
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   207
  have "zeroable ZERO" "L ZERO = {}" by simp_all
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   208
  then show "zeroable ZERO $\longleftrightarrow$ (L ZERO = {})" by simp
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   209
next
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   210
  case (ONE)
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   211
  have "$\neg$ zeroable ONE" "L ONE = {[]}" by simp_all
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
   212
  then show "zeroable ONE $\longleftrightarrow$ (L ONE = {})" by simp
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   213
next
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   214
  case (CHAR c)
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   215
  have "$\neg$ zeroable (CHAR c)" "L (CHAR c) = {[c]}" by simp_all
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   216
  then show "zeroable (CHAR c) $\longleftrightarrow$ (L (CHAR c) = {})" by simp
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   217
next 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   218
  case (ALT r1 r2)
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   219
  have ih1: "zeroable r1 $\longleftrightarrow$ L r1 = {}" by fact
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   220
  have ih2: "zeroable r2 $\longleftrightarrow$ L r2 = {}" by fact
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   221
  show "zeroable (ALT r1 r2) $\longleftrightarrow$ (L (ALT r1 r2) = {})" 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   222
    using ih1 ih2 by simp
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   223
next
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   224
  case (SEQ r1 r2)
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   225
  have ih1: "zeroable r1 $\longleftrightarrow$ L r1 = {}" by fact
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   226
  have ih2: "zeroable r2 $\longleftrightarrow$ L r2 = {}" by fact
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   227
  show "zeroable (SEQ r1 r2) $\longleftrightarrow$ (L (SEQ r1 r2) = {})" 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   228
    using ih1 ih2 by (auto simp add: Conc_def)
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   229
next
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   230
  case (STAR r)
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   231
  have "$\neg$ zeroable (STAR r)" "[] $\in$ L (r) ^ 0" by simp_all
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   232
  then show "zeroable (STAR r) $\longleftrightarrow$ (L (STAR r) = {})" 
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   233
    by (simp (no_asm) add: Star_def) blast
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   234
qed
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   235
\end{lstlisting}
317
a61b50c5d57f updated all
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 298
diff changeset
   236
\caption{An Isabelle proof about the function \texttt{zeroable}.\label{proof}}
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   237
\end{figure}
253
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
\end{document}
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
%%% Local Variables: 
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
%%% mode: latex
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
%%% TeX-master: t
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
%%% End: