doc-isac/mlehnfeld/master/thesis/isabelle_isac.tex
author Walther Neuper <neuper@ist.tugraz.at>
Wed, 23 Jul 2014 14:32:19 +0200
changeset 55476 8e3f73e1e3a3
parent 55466 55c2d2ee3f92
child 60710 21ae85b023bb
permissions -rw-r--r--
final docu of mlehnfeld

copy from https://hg.risc.uni-linz.ac.at/wneuper/mlehnfeld
changeset 97ab9b31c84d: Added tag fixed final for changeset 2faac24320f2
author Mathias Lehnfeld <s1210629013@students.fh-hagenberg.at>
Sun, 20 Jul 2014 16:32:03 +0200 (2 days ago)
changeset 38 97ab9b31c84d
s1210629013@55466
     1
\chapter{\isabelle{} and \isac{}}
s1210629013@55404
     2
\label{cha:isabelle_isac}
s1210629013@55404
     3
s1210629013@55466
     4
The case study described in this chapter was performed as an
s1210629013@55466
     5
invasive development on \isac{}, a prototype of an educational tool for
s1210629013@55466
     6
applied mathematics which is built upon the theorem prover \isabelle{}
s1210629013@55466
     7
in order to ensure the logical correctness of calculations. The development was invasive in that it addressed basic mechanisms of \isabelle{}
s1210629013@55466
     8
which are reused by \isac{}. The motivation for this development was to improve
s1210629013@55466
     9
\isac{}'s integration with \isabelle{} as well as \isac{}'s efficiency and
s1210629013@55466
    10
responsiveness in a multi-user setting. Both improvements are related to
s1210629013@55466
    11
the introduction of parallelism in \isabelle{} during the last years.
s1210629013@55404
    12
s1210629013@55466
    13
Section \ref{sec:isabelle} introduces \isabelle{}, its basic architecture
s1210629013@55466
    14
and the main components it is comprised of. It furthermore discusses \textit{Standard ML} and
s1210629013@55466
    15
the \textit{Poly/ML} compiler it uses (section \ref{ssec:polyml}).
s1210629013@55466
    16
Section \ref{sec:isadevdoc} is about \isabelle{}'s development and documentation
s1210629013@55466
    17
workflow which has mostly been adopted for the work on \isac{}. An overview
s1210629013@55466
    18
of the basics of why parallelism was added to \isabelle{}'s computation model
s1210629013@55466
    19
in section \ref{ssec:isab-parallel} wraps up the main part about \isabelle{}. In order to make the gain from \isac{}'s improvements comprehensible,
s1210629013@55466
    20
section \ref{ssec:isac-design} gives some background information about
s1210629013@55466
    21
\isac's principal design and architecture.
s1210629013@55466
    22
Section \ref{ssec:isac-archi} shows \isac's
s1210629013@55466
    23
architecture, which had to be adhered to by the study's implementation
s1210629013@55466
    24
work.
s1210629013@55466
    25
Since the case study concerns deeply invasive development into \isac,
s1210629013@55466
    26
section \ref{ssec:future-isab} is dedicated to the question,
s1210629013@55466
    27
how \isac's prototype development relates to
s1210629013@55466
    28
\isabelle{}'s ongoing development, which is invasive, too.
s1210629013@55466
    29
The detailed descriptions of the study's implementation
s1210629013@55466
    30
work are section \ref{ssec:parall-thy} on the integration
s1210629013@55466
    31
of \isac's knowledge definitions into \isabelle{}'s parallel theory evaluation
s1210629013@55466
    32
and section \ref{ssec:session-manag} on the introduction of concurrency
s1210629013@55466
    33
to \isac's user session management.
s1210629013@55466
    34
s1210629013@55466
    35
s1210629013@55466
    36
\section{\isabelle{}}
s1210629013@55404
    37
\label{sec:isabelle}
s1210629013@55466
    38
\isabelle{} is one of the leading computer theorem provers as introduced in section \ref{sec:ctp}. It is used in many academic courses, courses on semantics of programming languages, on program verification, on introduction to mathematical proof, etc. But the number of professional users can hardly be estimated. Continuous reading of the mailing list for technical support \cite{pipermail2014clisa} suggests more than a hundred persons worldwide who already did a notable development within a PhD, some academic postdoctoral work or as engineers in industry. \isabelle{} represents more than hundred man years of development, dedicated within the last twenty five years and still ongoing. \isabelle{} was started by Larry Paulson as a ``logical framework'', an answer to the issue of {\em The Next Seven Hundred Theorem Provers} mentioned on page \pageref{par:next-700}. 
s1210629013@55404
    39
s1210629013@55466
    40
Today, development is ongoing at three universities: At the {\em Computer Laboratory of the University of Cambridge}, Larry Paulson develops specific automated provers, formalizes mathematics and security protocols. {\em The Chair for Logic and Verification} at the {\em Technical University of Munich} spawned from the institute of Manfred Broy and is led by Tobias Nipkow. Nipkow is responsible for the core system as well as for general theory development. About ten postdocs and PhDs are employed for these purposes \cite{tum2013team}. The parallelization efforts and development of the \textit{Isabelle/jEdit} front-end (section \ref{ssec:isa-jedit}) are undertaken at {\em Université Paris-Sud} in the {\em Laboratoire de Recherche en Informatique}, supervised by Makarius Wenzel. Confirmed by a wide range of expectations in TP technology as mentioned in section \ref{sec:ctp}, \isabelle{} strives for usability at the workplace of computer scientists, of practitioners in various engineering disciplines and of mathematicians. E.g. at \textit{RISC Linz} there is an initiative for verified computer algebra using \isabelle{}. Usability issues were the driving force to introduce parallelism to \isabelle{}.
s1210629013@55404
    41
s1210629013@55466
    42
\isabelle{} integrates various tools and languages. This section describes the technologies involved in the system, its most important components and how they work together. Also, it discusses the repository, development and documentation workflow and the introduction of parallelism. The distribution for all major platforms can be downloaded from the \isabelle{} website \cite{tum2014isainst}. Whenever files are referenced, ``{\tt \textasciitilde\textasciitilde}'' stands for the distibution's root directory. These references address the \isabelle{} release {\em Isabelle2013-2}.
s1210629013@55466
    43
% "Isabelle as document-oriented proof assistant" paper
s1210629013@55466
    44
% Isabelle was not designed; it evolved. Not everyone likes this idea.
s1210629013@55466
    45
%Specification experts rightly abhor trial-and-error programming. They
s1210629013@55466
    46
%suggest that no one should write a program without first writing a complete formal specification. But university departments are not software
s1210629013@55466
    47
% houses. Programs like Isabelle are not products: when they have served
s1210629013@55466
    48
% their purpose, they are discarded.
s1210629013@55466
    49
% Lawrence C. Paulson, "Isabelle: The Next 700 Theorem Provers"
s1210629013@55404
    50
s1210629013@55466
    51
% intelligent_computer_math_isabelle.pdf p. 484-487
s1210629013@55466
    52
% itp-smp.pdf (survey paper)
s1210629013@55466
    53
% parallel-ml.pdf
s1210629013@55466
    54
% itp-pide.pdf
s1210629013@55466
    55
% isabelle_proof_method_lang.pdf
s1210629013@55466
    56
% polyml_concurrent_sml.pdf
s1210629013@55404
    57
s1210629013@55466
    58
\subsection{\textit{Isabelle/ML}}
s1210629013@55466
    59
\label{sec:bigisaml}
s1210629013@55466
    60
This section presents \textit{Isabelle/ML}, which allows programmers to embed \textit{Standard ML} code into the \isabelle{} environment. The used compiler is called \textit{Poly/ML}. It is fast and efficient, implements the full \textit{ML} standard \cite{milner1997definition} and provides additional features like a foreign language interface and support for POSIX threads based concurrency. \textit{Isabelle/ML} furthermore includes a number of libraries built on top of \textit{Poly/ML} with extra language constructs for concurrency. Before we take a deeper look into these we need to discuss \textit{Standard ML} and the \textit{Poly/ML} compiler.
s1210629013@55404
    61
s1210629013@55466
    62
\subsubsection{\textit{Standard ML}}
s1210629013@55466
    63
\label{sec:isasml}
s1210629013@55466
    64
\textit{ML} stands for {\em meta language}. The language was briefly introduced in section \ref{sec:funhist}. It is a strongly typed, functional programming language, which is not pure as it allows side effects and updatable references. Many people contributed ideas to the language. In order maintain a common ground, a standard was established \cite{milner1997definition}. All the code samples in this document are written in \textit{Standard ML} syntax. Since \textit{Standard ML} is only a language definition which is not dictated by a reference implementation, there are multiple compilers available, most notably {\em Standard ML of New Jersey} ({\em SML/NJ}) \cite{smlnj2013standard}, {\em MLton} \cite{weeks2006whole} and {\em Moscow ML} \cite{romanenko2014moscow}. They differ in their priorities such as optimization, standard library size or platform support. \textit{ML} was originally designed as a command language for the interactive theorem prover \textit{LCF} (section \ref{sssec:lcf}) \cite{milner1978theory}. Because of its history in this area, it was specifically suitable for the development of \isabelle{}. Inference rules can easily be implemented as functions that accept a theorem and return a new one. Complete theorems can be constructed by applying a sequence of rules to other known theorems.
s1210629013@55404
    65
s1210629013@55466
    66
\paragraph{The Hind\-ley-Mil\-ner Type System.}\label{sec:hindleymilner}
neuper@55476
    67
\textit{Standard ML} makes use of {\em Hind\-ley-Mil\-ner type inference} \cite{milner1978theory} based on a type system for the lambda calculus which utilizes parametric polymorphism, i.e. types can be declared using type variables (e.g. \textit{Synchronized} signature on page \pageref{alg:guarded_access_sig}) and the decision on the instantiated types is left to the inference algorithm. This allows for the generic definition of functions while still ensuring static type safety. The type inference method is complete and is able to always deduce the most general type of an expression without requiring type annotations. If it cannot find a suitable type for an expression, its declaration must contain errors. Because type checking in \textit{ML} is secure, deduction of theorems is always sound. Wrong applications of rules lead to exceptions.
s1210629013@55404
    68
s1210629013@55466
    69
\bigskip
s1210629013@55466
    70
s1210629013@55466
    71
Another important feature of \textit{Standard ML} is its design for robust, large scale, modular software. Signatures are part of the type system and describe the interfaces between different modules.
s1210629013@55466
    72
s1210629013@55466
    73
\subsubsection{\textit{Poly/ML}}
s1210629013@55466
    74
\label{ssec:polyml}
s1210629013@55466
    75
In the course of his PhD thesis, David Matthews from the \textit{University of Cambridge} developed and implemented a language called {\em Poly}, which had many ideas in common with \textit{Standard ML}. The compiler was reimplemented in \textit{Poly} itself. Later, Matthews rewrote parts of the compiler to compile \textit{Standard ML} code. The result was {\em Poly/ML} \cite{matthews1995papers} which is now available under an open source license. It implements the full \textit{Standard ML} specification and provides a few extensions. The run-time system was written in \textit{C}. \textit{Poly/ML}'s most notable feature are its concurrency mechanisms. While the \textit{Standard ML} specification \cite{milner1997definition} is limited to sequential programming, \textit{Poly/ML} provides concurrency primitives based on POSIX threads. Its native support for system threads and parallel garbage collection make it unique amongst \textit{Standard ML} compilers. Another related project is {\em Concurrent ML}, an extension of \textit{SML/NJ} \cite{reppy1993concurrent}. The primitives in \textit{Poly/ML} include threads, mutexes and condition variables. An example for forking a thread was shown in the communicating sequential process example on page \pageref{alg:csp}. For details on the operations and their implementation, please refer to \cite{matthews2010efficient}.
s1210629013@55466
    76
% pretty much extendable: garbage collection, memory management, libraries, more details of concurrency, foreign language interface, esp. C interface
s1210629013@55466
    77
s1210629013@55466
    78
\subsubsection{\textit{Isabelle/ML}}
s1210629013@55466
    79
\label{sec:isabelleml}
s1210629013@55466
    80
\textit{Isabelle/ML} is a way of programming in \textit{Standard ML} which is encouraged and enhanced within the \isabelle{} infrastructure. It adds many library modules to plain \textit{Poly/ML}.
s1210629013@55466
    81
neuper@55476
    82
\paragraph{Antiquotations.}\label{sec:antiquot}
s1210629013@55466
    83
A very powerful mechanism for easy access to \isabelle{} system values and logical entities are so called {\em antiquotations} \cite{wenzel2013impl}. Depending on their particular purpose they are resolved at compile, link or run time. They can refer to various datatypes such as {\em theorems} (derived propositions), {\em theories} (containers for global declarations), {\em contexts} (deductive environment states) and many other concepts within the \isabelle{} framework. E.g. {\tt @\{context\}} would refer to the context at compile time at the location where it is used, i.e. a \textit{Standard ML} value of type {\tt context}.
s1210629013@55466
    84
s1210629013@55466
    85
\paragraph{Concurrency.}
s1210629013@55466
    86
\textit{Poly/ML} comes with very general mechanisms for concurrency. Its approach is based on shared resources and synchronized access. While this concurrency model is well established, it is easy for the programmer to overlook some detail in the coordination of threads and deadlocks can occur. In order to ensure correctness by design, \textit{Isabelle/ML} provides higher-order combinators and thereby hides synchronization details.
s1210629013@55466
    87
s1210629013@55466
    88
\subparagraph{Guarded Access.}\label{sec:guarded-access}
s1210629013@55466
    89
Guarded access primitives operate on an abstract type called {\tt var}. They are available from the module {\em Synchronized}\footnote{\label{ftn:syncml}{\tt \textasciitilde\textasciitilde/src/Pure/Concurrent/synchronized.ML}} and the most notable elements of its interface are declared as
s1210629013@55466
    90
\imlcode{\label{alg:guarded_access_sig}
s1210629013@55466
    91
~~\=ty\=pe\=~'\=a \=var\\
s1210629013@55466
    92
\>val var: string -> 'a -> 'a var\\
s1210629013@55466
    93
\>val value: 'a var -> 'a\\
s1210629013@55466
    94
\>val guarded\_access: 'a var -> ('a -> ('b * 'a) option) -> 'b\\
s1210629013@55466
    95
\>val change: 'a var -> ('a -> 'a) -> unit \textrm{.}}
s1210629013@55466
    96
\noindent
s1210629013@55466
    97
This type is merely a wrapper for an ML reference. Please note the type parameters {\tt 'a} and {\tt 'b}. The constructor creates a {\tt var} from such a reference. {\tt value} is the inverse operation and performs a read access. Machine code produced by the \textit{Poly/ML} compiler generally treats memory cells as volatile, i.e. calls to {\tt value} need not be synchronized because read operations always return {\em some} value. The {\tt guarded\_access} combinator is where the magic happens. Besides the {\tt var} element $x$ with value $v$ that the write access will be performed on, it expects a function $f$ that maps $v$ to an option element of the touple type {\em 'a * 'b}. The type {\em option} is \textit{Standard ML}'s equivalent of the {\tt Maybe} monad in \textit{Haskell}: It can either be {\tt NONE} or contain a value, i.e. in our case {\tt SOME ($y$, $v2$)}. $f$ is executed in a critical section of $x$ on its value $v$. As long as it returns {\tt NONE}, the current execution context waits for another thread to change $v$. If $f$ returns {\tt SOME ($y$, $v2$)}, the value of $x$ is set to $v2$ and the call to {\tt guarded\_access} returns with result $y$.
s1210629013@55466
    98
The original definition of {\tt change}\footnote{{\tt \textasciitilde\textasciitilde/src/Pure/Concurrent/synchronized.ML}}, i.e. an unconditional, synchronized update to a {\tt var} element is given by
s1210629013@55466
    99
\imlcode{~~\=fun change\_result var f = guarded\_access var (SOME o f);\\
s1210629013@55466
   100
\>fun change var f = change\_result var (fn x => ((), f x)); \textrm{.}}
s1210629013@55466
   101
\noindent
s1210629013@55466
   102
It is easily possible to implement higher-order mechanisms using these primitives. See \cite{matthews2010efficient} for an example of a message queue.
s1210629013@55466
   103
% EXTEND: exception handling, performance
s1210629013@55466
   104
s1210629013@55466
   105
\subparagraph{Futures.}\label{sec:isafut}
s1210629013@55466
   106
While the last approach allows for process synchronization on a high level, most of the complexity persists and as software gets larger it still gets increasingly hard to coordinate a high number of concurrent computations efficiently. For this reason, \textit{Isabelle/ML} provides {\em futures} (section \ref{sec:futurespro}) and is thereby able to completely hide threads and their synchronization from the programmer.
s1210629013@55466
   107
The goal was to provide a mechanism for parallelism which is both simple to use and performant with a special emphasis on operations typically carried out by a proof engine. {\em Future values} fulfill these requirements. They are value-oriented, i.e. the focus hereby is on parallelism rather than concurrency. Error handling happens synchronously by means of exceptions and asynchronously with interrupts.
s1210629013@55466
   108
The {\em Future} module\footnote{\tt \textasciitilde\textasciitilde/src/Pure/Concurrent/future.ML} has a comprehensive signature. The following declarations are only an excerpt:
s1210629013@55466
   109
\imlcode{~~\=type 'a future\\
s1210629013@55466
   110
\>val fork: (unit -> 'a) -> 'a future\\
s1210629013@55466
   111
\>val cancel: 'a future -> unit\\
s1210629013@55466
   112
\>val is\_finished: 'a future -> bool\\
s1210629013@55466
   113
\>val join: 'a future -> 'a\\
s1210629013@55466
   114
\>val map: ('a -> 'b) -> 'a future -> 'b future\\
s1210629013@55466
   115
\>val value: 'a -> 'a future}
s1210629013@55466
   116
\noindent
neuper@55476
   117
Notice that {\tt 'a} is a placeholder for an arbitrary type which a future can represent. Calls to {\tt Future.join} synchronize the evaluation and wait for the future's result if it is not already available. In case an exception is raised during the evaluation, its propagation will wait until the future is joined. {\tt Future.cancel} stops a future's evaluation if it has not finished, otherwise the function has no effect. The evaluation of futures is managed by means of tasks and worker threads. The number of workers should be related to the number of available processing cores. The exact number, however, is adjusted dynamically because the future scheduler always keeps a limited number of inactive threads in memory, such that they can immediately take over if another thread is temporarily stalled. In practice, the additional functions {\tt Future.map} and {\tt Future.value} have turned out to be useful in reducing the number of tasks and as a consequence the scheduling overhead. {\tt Future.map} can append another operation to an existing future, which will be executed on the originally scheduled function's result. If the original future's evaluation has not started yet, the appended operation will be computed within the same task. {\tt Future.value} produces a dummy future holding the function's argument as a result. Additionally, futures can be assigned priorities in order to influence execution order which by default is based on creation time. Also, futures can be organized in groups and even hierarchies of groups. This allows futures that depend on each other to be canceled whenever one of them raises an exception.
s1210629013@55466
   118
s1210629013@55466
   119
A simple {\em future} example has already been shown on page \pageref{alg:futures}. Internally, the {\em Futures} module is based on the guarded access mechanisms introduced above. Based on futures, \textit{Isabelle/ML} provides more specific parallel combinators such as the parallel list combinators {\tt map} and {\tt find}. The latter makes use of future groups and throws an exception as soon as a match is found, such that other search branches are not evaluated. This example shows how exceptions can be used as a basic means for functional interaction of futures without reintroducing the complexities usually associated with inter-process communication. See \cite{matthews2010efficient} for further details and a discussion of the performance of futures.
s1210629013@55466
   120
s1210629013@55466
   121
\subsection{\textit{Isabelle/Isar}}
s1210629013@55466
   122
\label{sec:isaisar}
neuper@55476
   123
While in older versions of \isabelle{}, theorem proving tasks had to be solved using raw \textit{ML} tactic scripts, theories and proofs can now be developed interactively in an interpreted, structured, formal proof language called {\em Isar} (Intelligible semi-automated reasoning) \cite{wenzel2013isar,wenzel1999isar}. \textit{Isar} was designed to address an issue common to state-of-the-art theorem provers: Despite successfully formalizing a good amount of existing mathematical knowledge, logics and computer science theory, it was still hard to reach potential target groups unfamiliar with the involved computer programming requirements. The primary users of theorem provers should be mathematicians and engineers who utilize them to formulate new proofs and for verification purposes. \textit{Isar} enables these users (``authors'' in fig. \ref{fig:isar-use}) to write proofs and theories in a way that can be understood by machines while being much closer to human language than \textit{ML} code or some logical calculus. As much as possible, it hides operational details thanks to its notion of {\em obvious inferences}. With a little extra care it can therefore also be used for presentation to an audience. The short, well-known proof that the square root of 2 is an irrational number is presented in appendix \ref{app:sqrt2-isar}.
s1210629013@55466
   124
s1210629013@55466
   125
\begin{figure}
s1210629013@55466
   126
\centering
s1210629013@55466
   127
\def\svgwidth{18.5em}
s1210629013@55466
   128
\resizebox{.5\textwidth}{!}{\input{images/isar_use.pdf_tex}}
s1210629013@55466
   129
\caption{\textit{Isar} proof notions \cite{wenzel1999isar}.}
s1210629013@55466
   130
\label{fig:isar-use}
s1210629013@55466
   131
\end{figure}
s1210629013@55466
   132
s1210629013@55466
   133
The {\em Isar virtual machine} interpreter performs proof checking and incorporates an operational semantics for \textit{Isar}. It is provided by the \textit{Isabelle/Isar} framework, which embeds Isar into the \isabelle{} environment. It supplies the \textit{Isar/VM} interpreter with all available proofs and definitions which are implemented in theory documents. These theories are structured in an inheritance hierarchy that forms a directed, acyclic graph. \textit{Isar} proofs operate on the basis of certain object logics. The most established logic is \textit{Isabelle/HOL}, i.e. higher-order logic (simply typed set theory), but a wide range of logics is available through the \textit{Isabelle/Pure} meta logic. Another important element are {\em proof methods}, which are function mappings between proof goals and according proof rules. \textit{Isar}'s lack of mechanisms for the formulation of automated proof procedures turned out to cause an unacceptable amount of duplicate code. Very recent work on a new language called {\em Eisbach}, which is based on \textit{Isar}, has tried to address these issues \cite{matichuk2014isabelle}.
s1210629013@55466
   134
s1210629013@55466
   135
\subsection{\textit{Isabelle/Scala}}
s1210629013@55466
   136
\label{ssec:isa-scala}
s1210629013@55466
   137
The original user interface for the \isabelle{} theorem prover was a project called {\em Proof General}. It is a proof assistant front-end based on \textit{Emacs}, also available for other provers like {\em Coq} \cite{chlipala2011certified}. Its interaction model offers some improvements over a basic TTY model. The user enters a prover command and immediately receives a result, such as information on proof state or goals, before they can issue the next command. But interaction remains sequential and synchronous. There are two main weaknesses to \textit{Proof General} and similar approaches. The underlying editor framework is outdated: \textit{Emacs} offers a very powerful environment, but its graphical user interface can be considered dated. Also \textit{Emacs}' \textit{Lisp} engine does not support multithreading and does therefore not allow the development environment to make full use of the available CPU power. The other main shortcoming is the poor interaction model that is limited to a synchronous input / output sequence. Instead of simple text editing tools, a fully-featured IDE was desirable \cite{wenzel2012asynchronous}. In addition, the IDE should be available on many platforms and as the main development focus of \isabelle{} developers is theorem provers, they wanted to be able to draw on existing IDE frameworks, rather than developing a new one from scratch. They chose to make use of the \textit{Java Virtual Machine} and enable tools written for the \textit{JVM} to communicate with the \isabelle{} prover via simple byte streams. The resulting asynchronous document model utilized for the communication between \textit{ML} and \textit{JVM} allows GUIs, text editors like \textit{jEdit}, IDE frameworks such as \textit{Eclipse} as well as web services to make use of the \isabelle{} prover. The outcome of the efforts to design this {\bf p}rover {\bf IDE} framework is called {\em Isabelle/PIDE}. In order to overcome the differing programming models and datastructures of \textit{Standard ML} and the \textit{JVM}, \textit{Scala} was chosen as the \textit{JVM} communication endpoint because, due to its flexibility and functional features, it allows programmers to imitate a programming style similar to \textit{Isabelle/ML}. \textit{Scala}'s actors (section \ref{sec:actormodel}) were used heavily for asynchronous communication and concurrency until recently. Since the original Actor library was replaced by {\em Akka}, \isabelle{} developers have decided to imitate the \textit{ML} variants of parallelism mechanisms in \textit{Scala} without actors \cite{wenzel2014actors}. All datastructures that are part of the protocol have been implemented in both languages side by side. E.g. the datatype definition of file system path elements is
s1210629013@55466
   138
\imlcode{~~\=da\=tatype elem =\\
s1210629013@55466
   139
\>\>Root of string |\\
s1210629013@55466
   140
\>\>Basic of string |\\
s1210629013@55466
   141
\>\>Variable of string |\\
s1210629013@55466
   142
\>\>Parent;}
s1210629013@55466
   143
\noindent
s1210629013@55466
   144
in \textit{Standard ML}\footnote{\tt \textasciitilde\textasciitilde/src/Pure/General/path.ML}. Here, a value of type \texttt{elem} can be either of the four subtypes, three of which are \texttt{string}s. The equivalent datastructure in \textit{Scala}\footnote{\tt \textasciitilde\textasciitilde/src/Pure/General/path.scala} is given as four concrete classes inheriting from the abstract class \texttt{Elem}:
s1210629013@55466
   145
\imlcode{~~\=sealed abstract class Elem\\
s1210629013@55466
   146
\>private case class Root(val name: String) extends Elem\\
s1210629013@55466
   147
\>private case class Basic(val name: String) extends Elem\\
s1210629013@55466
   148
\>private case class Variable(val name: String) extends Elem\\
s1210629013@55466
   149
\>private case object Parent extends Elem}
s1210629013@55466
   150
\noindent
neuper@55476
   151
The internal protocol utilizes \textit{YXML}, a transfer format based on XML \cite{wenzel2011isabelle}. Instead of keeping a public protocol specification, the details are being kept private. This allows the developers to make substantial changes to protocol and document model to improve robustness and performance without further ado. Instead, both \textit{Isabelle/ML} and \textit{Isabelle/Scala} offer public, static APIs for their communication which are maintained and kept simple and stable.
s1210629013@55466
   152
s1210629013@55466
   153
\begin{figure}
s1210629013@55466
   154
\centering
s1210629013@55466
   155
\def\svgwidth{17.5em}
s1210629013@55466
   156
\resizebox{.6\textwidth}{!}{\bf\input{images/pide_comm.pdf_tex}}
s1210629013@55466
   157
\caption{The \textit{Isabelle/PIDE} communication model \cite{wenzel2014uipide}.}
s1210629013@55466
   158
\label{fig:pide-comm}
s1210629013@55466
   159
\end{figure}
s1210629013@55466
   160
s1210629013@55466
   161
Fig. \ref{fig:pide-comm} outlines the basic communication model between the \textit{JVM} and the prover. Whenever the user edits a file in an editor, a description of this update is sent to the prover which then produces markup to annotate the new contents with proof data and other semantic information. Then the changes on the editor side are reverted and replaced by the new, annotated content. As a consequence, the interaction mechanism adheres to the functional paradigm's philosophy by using strictly immutable document snapshots of versioned file histories.
s1210629013@55466
   162
% scala actors -> email!
s1210629013@55466
   163
%pide_ocaml.pdf
s1210629013@55466
   164
%isabelle_system_manual.pdf
s1210629013@55466
   165
%async_isabelle_scala_jedit.pdf
s1210629013@55466
   166
% itp-pide.pdf
s1210629013@55466
   167
% Walther mail 24.04. "Fwd: [isabelle-dev] scala-2.11.0" (scala actors)
s1210629013@55466
   168
% isabelle-doc.pdf (YXML)
s1210629013@55466
   169
s1210629013@55466
   170
\subsection{\textit{Isabelle/jEdit}}
s1210629013@55466
   171
\label{ssec:isa-jedit}
neuper@55476
   172
Recent \isabelle{} distributions include a complete prover IDE prototype implementation based on the text editor framework {\em jEdit} \cite{wenzel2012isabelle}. \textit{Isabelle/jEdit} features a completely new interaction model that performs continuous, parallel proof checking. It uses GUI functionality such as highlighting, coloring, tooltips, popup windows and hyperlinks to annotate user code written in \textit{Isar} and \textit{ML} incrementally with semantic information from the prover (see fig. \ref{fig:jedit_feedback}). Prover and editor front-end are executed independently and never block each other thanks to the asynchronous protocol. Additionally, \textit{Isabelle/jEdit} includes several plugins and fonts to facilitate entering and rendering of mathematical symbols.
s1210629013@55466
   173
s1210629013@55466
   174
\begin{figure}
s1210629013@55466
   175
\centering
s1210629013@55466
   176
\includegraphics[width=94mm]{jedit_feedback} %width=.95\textwidth
s1210629013@55466
   177
\caption{GUI feedback in \textit{Isabelle/jEdit}.}
s1210629013@55466
   178
\label{fig:jedit_feedback}
s1210629013@55466
   179
\end{figure}
s1210629013@55466
   180
s1210629013@55466
   181
The IDE also manages loaded theory files and the computation of their dependency graph. Changes to theories are automatically propagated appropriately and the user receives immediate feedback on the processing of theories (fig. \ref{fig:jedit_thy}).
s1210629013@55466
   182
\begin{figure}
s1210629013@55466
   183
\centering
s1210629013@55466
   184
\includegraphics[width=80mm]{theories_processing} %width=.95\textwidth 70mm
s1210629013@55466
   185
\caption{Feedback on theory processing \textit{Isabelle/jEdit}.}
s1210629013@55466
   186
\label{fig:jedit_thy}
s1210629013@55466
   187
\end{figure}
s1210629013@55466
   188
%async_isabelle_scala_jedit.pdf
s1210629013@55466
   189
%jedit.pdf
s1210629013@55466
   190
s1210629013@55466
   191
\subsection{The Prover Framework}
s1210629013@55466
   192
\label{sec:isaatp}
s1210629013@55466
   193
% isabelle/pure vs. isabelle/hol and other logics
s1210629013@55466
   194
% proof general
s1210629013@55466
   195
% pure framework
s1210629013@55466
   196
% graphics Isar-slides-TPHOLs99.ps.gz
s1210629013@55466
   197
%hol_springer.pdf:361
s1210629013@55466
   198
%isahol_proofdisproof.pdf
s1210629013@55466
   199
%itp-pide.pdf:5
s1210629013@55466
   200
%isabelle_tutorial.pdf
s1210629013@55466
   201
%isar_sml_antiquot.pdf:6
s1210629013@55466
   202
%Isar-slides-TPHOLs99.ps.gz:2
s1210629013@55466
   203
%isa_pide_educational.pdf:146
s1210629013@55466
   204
s1210629013@55466
   205
% unlimitide undo, document model immutable: previous states are preserved and full history is saved. unreachable states are garbage collected
s1210629013@55466
   206
% cross-link step 2 under "integration with isabelle's par..." annotations
s1210629013@55466
   207
The paragraph titled {\em The Next Seven Hundred Theorem Provers} in section \ref{par:next-700} (page \pageref{par:next-700}) explained that \isabelle{} was initiated and designed as a logical framework for automated theorem provers. Its design is described in \cite{wenzel2009parallel}. The metaprover / collection of external automated provers supporting interactive proofs is called {\em Sledgehammer}. The standard provers are called {\em E}, {\em SPASS}, {\em Vampire} and {\em Z3}. Fig. \ref{fig:sledgehammer} (page \pageref{fig:sledgehammer}) depicts the view on \textit{Sledgehammer} in \textit{Isabelle/jEdit}.
s1210629013@55466
   208
\begin{figure}
s1210629013@55466
   209
\centering
s1210629013@55466
   210
\includegraphics[width=.95\textwidth]{sledgehammer}
s1210629013@55466
   211
\caption{instance of the \textit{Sledgehammer} panel.}
s1210629013@55466
   212
\label{fig:sledgehammer}
s1210629013@55466
   213
\end{figure}
s1210629013@55466
   214
In those cases where theorems are invalid and therefore cannot be proved, two disproof tools called {\em Quickcheck} and {\em Nitpick} can be utilized for producing counterexamples. See \cite{blanchette2011automatic} for a more detailed overview on the integration of these external tools.
s1210629013@55466
   215
% proof planner Isa?
s1210629013@55466
   216
s1210629013@55466
   217
%\begin{figure}
s1210629013@55466
   218
%\centering
s1210629013@55466
   219
%\includegraphics[width=.65\textwidth]{lcf_concepts.png}
s1210629013@55466
   220
%\caption{Main concepts of the LCF approach \cite{brandt2007theorem}}
s1210629013@55466
   221
%\label{fig:lcf-concepts}
s1210629013@55466
   222
%\end{figure}
s1210629013@55466
   223
s1210629013@55466
   224
%\begin{figure}
s1210629013@55466
   225
%\centering
s1210629013@55466
   226
%\includegraphics[width=.65\textwidth]{isaisar_concepts.png}
s1210629013@55466
   227
%\caption{Main concepts of Isabelle/Isar \cite{brandt2007theorem}}
s1210629013@55466
   228
%\label{fig:isaisar-concepts}
s1210629013@55466
   229
%\end{figure}
s1210629013@55466
   230
s1210629013@55466
   231
s1210629013@55466
   232
\subsection{Development and Documentation}
s1210629013@55466
   233
\label{sec:isadevdoc}
s1210629013@55466
   234
Apart from the technologies used in \isabelle{}, also \isabelle{}'s development process and system documentation had an impact on this thesis. The adaption to \isabelle{}'s specifics was quite challenging. \isabelle{}'s development process is much faster and much more radical as compared to commercial software development due to the specific kind of development. This development is led by three persons (see introduction to section \ref{sec:isabelle}, two of them supervising and also writing code themselves) and executed by a small team of about ten postdocs and PhDs, each working under contracts for three years at least. The members grow into the team by doing projects and master theses before entering the team. According to my supervisor, this particular kind of development leads to the following way of system documentation which is given by:
s1210629013@55466
   235
\begin{enumerate}
s1210629013@55466
   236
\item{\bf The code} itself, without any further comments except in few specific cases. This is common to functional programming and very different from what one is used to from e.g. \textit{Javadoc}. The code can be inspected in the repository, see pt. \ref{enum:isa-repos} below.
s1210629013@55466
   237
\item\label{enum:isa-man}{\bf Reference manuals and tutorials}, which can be found online \cite{tum2013isadoc} and are easily accessible from \textit{Isabelle/jEdit} (section \ref{ssec:isa-jedit}). Both, manuals and tutorials are automatically held in sync with the code by specifically developed mechanisms such as antiquotations (section \ref{sec:bigisaml}, page \pageref{sec:antiquot}), e.g. {\tt @\{type \dots\}}, {\tt @\{const \dots\}}, etc. These entries in the documentation raise exceptions in case some type or constant has changed in the code.
s1210629013@55466
   238
\item\label{enum:isa-repos}{\bf The repository}, publicly readable \cite{tum2014repo} is the third pillar for documentation. Commits must follow a {\em minimal changeset} policy which allows for quick queries and documents particular interdependencies across several files. This kind of documentation of complicated connections is very efficient and always up to date even with frequent changes.
s1210629013@55466
   239
\end{enumerate}
s1210629013@55466
   240
\noindent
neuper@55476
   241
This documentation model has evolved during more than two decades and still allows for ongoing rapid development with invasive changes, last but not least parallelization. However, relevant documentation for this thesis is marginal. Parallelization, as already mentioned, has been done by Makarius Wenzel and was preceded by a feasibility study conducted by a master student \cite{haller2006object}. Wenzel's respective papers \cite{matthews2010efficient,wenzel1999isar,wenzel2012asynchronous, wenzel2011isabelle,wenzel2012isabelle} concern fundamental considerations. The most relevant reference manual \cite{wenzel2013impl} contains less than ten pages on parallelization. All the rest had to be found in the code (several hundred thousand LOCs\footnote{{\em lines of code}}). The gap between papers and code was hard to bridge.
s1210629013@55466
   242
s1210629013@55466
   243
\subsection{Reasons for Parallelism in \isabelle{}}
s1210629013@55466
   244
\label{ssec:isab-parallel}
s1210629013@55466
   245
\isabelle{} is the first theorem prover which is able to exploit multi-core hardware. The reasons for introducing parallelism in \isabelle{} are directed towards the future and complement considerations discussed for functional programming. There are three motivations for parallelization mentioned for \isabelle{}. They have all been addressed at once: parallel invocation of multiple automated provers, a responsive prover IDE and efficient theory evaluation envisage better usability in engineering practice. All three development issues are successfully being tackled, an end cannot be foreseen yet.
s1210629013@55466
   246
s1210629013@55466
   247
\subsubsection{Run Automated Provers in Parallel}
s1210629013@55466
   248
\isabelle{}'s collection of automated provers was mentioned in section \ref{sec:isaatp}. It still has a mechanism to connect with remote prover instances and these already featured parallel access to external resources. Since personal computers and laptops have become powerful enough to run \isabelle{}, this hardware has also become powerful enough to run automated provers. But running them in parallel on a local machine required a redesign.
s1210629013@55466
   249
s1210629013@55466
   250
\subsubsection{Provide a Tool Usable in Engineering Practice}
neuper@55476
   251
The paragraph about {\em Continuous Penetration of Computer Science} by formal methods in section \ref{par:invade-cs} (page \pageref{par:invade-cs}) mentioned the increasing demand for theorem provers in the practice of software engineering and related mathematics. In particular, software engineers are used to comprehensive support by integrated development environments (IDEs): interlinked code, various views on relations between code elements, etc. Since TPs have been used by experts only until the presence, specific user interfaces were sufficient. For \isabelle{} this was {\em Proof General} (see section \ref{ssec:isa-jedit}), which is based on \textit{Emacs}. Those who still use this editor which was dominant during the last decades, know how different \textit{Emacs} is: not reasonable for engineering practice of today. So the issue was to meet the usability requirements of contemporary engineering practice. \isabelle{}'s attempt to meet such requirements is the {\em PIDE} project (section \ref{ssec:isa-scala}). \textit{Isabelle/jEdit} (section \ref{ssec:isa-jedit}) is the reference implementation, which is accompanied by development of an \textit{Eclipse} plugin \cite{andriusvelykis2013isaclipse} and a browser-based front-end under construction.
s1210629013@55466
   252
s1210629013@55466
   253
\subsubsection{Accelerate theory evaluation}
s1210629013@55466
   254
My supervisor's first experience with \isabelle{} was about fifteen years ago on a high-end SPARK workstation. The initial evaluation of \textit{Isabelle/HOL} took more than twenty minutes; not to speak of the considerable amount of time an experienced system administrator needed for installation. Since this time \textit{Isabelle/HOL} has become about three times larger, but the initial evaluation of theories takes about two minutes for recent \isabelle{} releases. \textit{Isabelle/jEdit} represents theory evaluation as shown in fig. \ref{fig:jedit_thy} on page \pageref{fig:jedit_thy}. Parallel branches in the dependency graph are evaluated in parallel. Without this kind of speedup, large theory developments involving several dozens of theories would not be manageable. The most recent \isabelle{} releases do not package binaries of evaluated theories any more. Instead, they pack further components into the bundle. The bundle of the current release is more than 400MB for download. Also, all other bandwidth aspects of \isabelle{} are at the limits of present mainstream hardware. \isabelle{} does not run below 4GB main memory and requires a dual-core processor with more than 2GHz per core.
s1210629013@55466
   255
s1210629013@55466
   256
s1210629013@55466
   257
\section{\isac{}}
s1210629013@55404
   258
\label{sec:isac}
s1210629013@55466
   259
\isac{} is a prototype in both, in the mathematics-engine based on \isabelle{} and written in \textit{Standard ML} as well as in the front-end involving rule-based dialogs and written in \textit{Java}. The mathematics-engine heavily reuses technology from \isabelle{} and thus comprises a comparably small portion of code: 25,000 LOCs\footnote{{\em lines of code}} plus 15,000 LOCs of knowledge in theories compiled to \textit{Standard ML} for fast access and 40,000 LOCs for tests. This code features functionality which is radically new for educational mathematics systems. The gain from TP technology is explained in section \ref{ssec:isac-design}. The front-end exploits the mathematics-engine's TP-based functionality for dialogs on a new level of flexibility and user guidance. The gain from rule-based dialog guidance is addressed in section \ref{ssec:isac-archi}. Since \isabelle{} is still under rapid development, the principal question arises, whether \isac's prototype development can persistently adjust to \isabelle{}, an issue addressed in section \ref{ssec:future-isab}. Otherwise the success achieved with the case study on parallelization would be worthless in the long term. The description of the case study is comprised of two parts: the integration with \isabelle{}'s parallel theory evaluation is described in section \ref{ssec:parall-thy} and section \ref{ssec:session-manag} discusses the parallelization of \isac{}'s user session management.
s1210629013@55404
   260
s1210629013@55466
   261
\subsection{Principal Design Decisions}
s1210629013@55466
   262
\label{ssec:isac-design}
s1210629013@55466
   263
\isac{} is still the only educational mathematics system worldwide which adheres to concepts of TP and which is built reusing TP technology, except for a system under construction by the Scandinavian \textit{E-Math} project \cite{emath2013emath}. All the other math tutoring systems are based on computer algebra. Thus, the distinctive design decision to rely on TP deserves an explanation.
s1210629013@55404
   264
s1210629013@55466
   265
\paragraph{TP concepts ensure logical correctness} in stepwise problem solving. When learning independently from a human tutor or supervisor, a student wants to know whether the calculations are done correctly or not. An educational software system supporting this expectation cannot be based on computer algebra systems. These are in no way related to logics (which is an unresolved issue for computer algebra, for instance at \textit{RISC Linz}), so true / false or correct / not correct requires underpinning with logical concepts as is the case e.g. in the {\em Theorema} project at \textit{RISC Linz}. The system under construction in \textit{E-Math} supports so called {\em structured derivations} which are close to calculations written by hand (see fig. \ref{fig:qed-editor}).
s1210629013@55404
   266
s1210629013@55466
   267
\begin{figure}
s1210629013@55466
   268
\centering
s1210629013@55466
   269
\includegraphics[width=.95\textwidth]{QED_Editor}
s1210629013@55466
   270
\caption{Structured derivation editor (source: \cite{back2010structured}).}
s1210629013@55466
   271
\label{fig:qed-editor}
s1210629013@55466
   272
\end{figure}
s1210629013@55404
   273
s1210629013@55466
   274
\noindent
s1210629013@55466
   275
This kind of calculation is proved logically equivalent \cite{back2010structured} to natural deduction, which forms the logical foundation of \isabelle{} and other provers as mentioned in section \ref{sssec:holfam}.
s1210629013@55404
   276
s1210629013@55466
   277
With the decision for \isabelle{}, \isac{} intentionally dissociates itself from the kind of artificial intelligence that tries to imitate human behavior. \isac{} does not intend to mimic a human tutor by modeling the system with respect to human thought, human comprehension or human learning. Rather, \isac{} is designed as a model of mathematics, following the structure of mathematics from the very bottom, from formal logics as implemented in \isabelle{}. However, AI technologies can take profit from the strength, the generality and the flexibility of the mathematics-engine resulting from this design. The principal strengths of \isac's math engine are described in the following paragraphs.
s1210629013@55466
   278
s1210629013@55466
   279
\paragraph{TP technology features new functionality} of \isac's mathematics-engine. The following features arise naturally from TP:
s1210629013@55466
   280
\begin{description}
s1210629013@55466
   281
\sloppy
s1210629013@55466
   282
\item[Check students' input automatically, flexibly and reliably.] Given a problem of applied mathematics by a formal specification (input, output, precondition and postcondition; generally hidden from the student), any formula (or a theorem for application) input by the student establishes a proof situation. Automated provers then derive, if possible, the input from the logical context. This is what computer theorem provers are built for. They represent the technology for accomplishing this task as generally and reliably as possible at the present state of the art in computer mathematics.
s1210629013@55466
   283
\item[Give explanations on request by students.] Provers designed on the basis of the \textit{LCF principle} (section \ref{sssec:lcf}) such as \isabelle{}, derive all knowledge from ``first principles''. For each definition and for each theorem the respective prerequisites can be traced down to the most fundamental axioms. All this knowledge is represented in human readable form \cite{tum2013isahol}. Thus the situation in systems like \isabelle{} is quite different from computer algebra systems. While documentation for the latter requires additional efforts for creation, all documentation is already there in \isabelle{}. Generation of explanations calls for filtering out details, which could distract or overwhelm students. Another nice feature of \textit{Isabelle/Isar}, although not relevant for applied mathematics, are human readable proofs close to mathematical traditions (see section \ref{sec:isaisar} and appendix \ref{app:sqrt2-isar}).
s1210629013@55466
   284
\item[Propose a next step if students get stuck.] This feature seems indispensable for independent learning. However, this exceeds the traditional discipline of TP. E.g., {\it lemma} $\int{1+x+x^2\;{\it dx}} = x + \frac{x^2}{2} + \frac{x^3}{3} + c$ can be proved, but given $\int{1+x+x^2\;{\it dx}}$ there is no direct way to calculate the result $x + \frac{x^2}{2} + \frac{x^3}{3} + c$ in TP. Since indispensable, \isac{} provides this feature by a novel combination of deduction and computation, called {\em Lucas-Interpretation} \cite{neuper2012automated}. \textit{Lucas-Interpretation} works on programs which describe how to solve a problem of applied mathematics in a quite traditional way. In addition to maintaining an environment as usual for interpretation, \textit{Lucas-Interpretation} maintains a logical context, such that automated prov\-ers are provided with all current knowledge required to check user input. \cite{daroczy2013error} gives a brief introduction to \textit{Lucas-Interpretation}.
s1210629013@55466
   285
\end{description}
s1210629013@55466
   286
\noindent
s1210629013@55466
   287
These three features together establish a powerful interface to the mathe\-matics-engine. With these given, interaction can be analogous to learning how to play chess in interaction with a chess program. The player executes a move (the student inputs a formula) and the program checks the correctness of the move (\isac{} checks the input). The program performs a move (\isac{} proposes a next step) and the player accepts or changes it. If the player is in danger of losing the game (the student gets stuck within the steps towards a problem solution), they can go back a few moves and try alternative moves. Or the player can even switch roles with the system and watch how the system copes with the unfortunate configuration. All these choices are available to a student analogously when learning mathematics in interaction with \isac.
s1210629013@55466
   288
neuper@55476
   289
The comparison of interaction in \isac{} with interaction in playing chess makes clear, that learning with a mechanical system does not necessarily lead to drill and practice in operational mechanization. The degree of freedom in interaction allows for fostering of the evaluation of alternatives and thus learning by trial and error, comparing strategies, etc.
s1210629013@55466
   290
s1210629013@55466
   291
\subsection{Architecture Separating Mathematics and Dialogs}
s1210629013@55466
   292
\label{ssec:isac-archi}
s1210629013@55466
   293
The strengths of \isac's mathematics-engine, as described above, provide powerful features for human-machine interaction and thus call for concepts and technology from AI. In order to cope with increasing complexity, a separation of concerns between AI and mathematics is required.
s1210629013@55466
   294
s1210629013@55466
   295
\subsubsection{Separation of Concerns between Dialogs and Mathematics}
s1210629013@55466
   296
This separation is reflected in \isac's architecture shown in fig. \ref{fig:isac-archi}.
s1210629013@55466
   297
\begin{figure}
s1210629013@55466
   298
\centering
s1210629013@55466
   299
\def\svgwidth{32.5em}
s1210629013@55466
   300
\resizebox{\textwidth}{!}{\input{images/isac_arch.pdf_tex}}
s1210629013@55466
   301
\caption{\isac{}'s architecture as seen by users.}
s1210629013@55466
   302
\label{fig:isac-archi}
s1210629013@55466
   303
\end{figure}
s1210629013@55466
   304
The front-end on the left within a \textit{Java} environment comprises {\em GUI 1..n}, an arbitrary number of remote devices for input and output, the \isac{} {\em server} with the {\em dialog} component. The {\em dialog} component comprises a rule-based system as described in \cite{kienleitner2012towards}, not shown in the figure. {\em Dialog authors} are not concerned with mathematics and are free to focus on the complexity of dialog guidance, see \cite{daroczy2013error} and an example from the paper in fig. \ref{fig:interaction}.
s1210629013@55466
   305
\begin{figure}
s1210629013@55466
   306
\centering
s1210629013@55466
   307
\begin{tikzpicture}[
s1210629013@55466
   308
  font=\footnotesize,
s1210629013@55466
   309
  >=latex,
s1210629013@55466
   310
  arr/.style = {<-,shorten <=2.5em, shorten >=2em,color=color1,line width=1.5pt},
s1210629013@55466
   311
  block/.style = {align=center, anchor=north, inner sep=2},
s1210629013@55466
   312
  formula/.style = {font=\large}
s1210629013@55466
   313
]
s1210629013@55466
   314
s1210629013@55466
   315
  \node [rectangle,rounded corners,very thick,draw=color1,block,formula,inner sep=5] (a) {$\frac{6a+3b}{3b} =\;?$};
s1210629013@55466
   316
s1210629013@55466
   317
  \node [anchor=north,minimum width=14em,minimum height=18em,fill=color5] (student) at (-3.3,-1.5) {};
s1210629013@55466
   318
  \node [anchor=north,minimum width=14em,minimum height=18em,fill=color5] (computer) at (3.3,-1.5) {};
s1210629013@55466
   319
s1210629013@55466
   320
  \node [anchor=north west,color=color2,font=\bf] (slabel) at (-5.96,-1.55) {student};
s1210629013@55466
   321
s1210629013@55466
   322
  \node [anchor=north west,color=color2,font=\bf] (clabel) at (0.69,-1.57) {computer};
s1210629013@55466
   323
s1210629013@55466
   324
s1210629013@55466
   325
  \node [block,formula] (b) at (-3.3,-2.4) {$\frac{6a+3b}{3b} = 6a$}
s1210629013@55466
   326
    edge[arr] (a);
s1210629013@55466
   327
s1210629013@55466
   328
  \node [block,text width=13em] (c) at (3.3,-2)
s1210629013@55466
   329
{\begin{center}
s1210629013@55466
   330
``You can't simplify like that.\\
s1210629013@55466
   331
Try to make products out of both,\\
s1210629013@55466
   332
nominator and denominator.\\
s1210629013@55466
   333
\medskip
s1210629013@55466
   334
Here is a link to look up.''
s1210629013@55466
   335
\end{center}}
s1210629013@55466
   336
    edge[arr] (b);
s1210629013@55466
   337
s1210629013@55466
   338
  \node [block,below=2.2em of b] (d) {\includegraphics[width=5.3em]{next_btn}}
s1210629013@55466
   339
    edge[arr] (c);
s1210629013@55466
   340
s1210629013@55466
   341
  \node [block,formula,below=2em of c] (e) {$\frac{6a+3b}{3b} = \frac{..(..+..)}{..}$}
s1210629013@55466
   342
    edge[arr] (d);
s1210629013@55466
   343
s1210629013@55466
   344
  \node [block,below=2.2em of d] (f) {\includegraphics[width=5.3em]{next_btn}}
s1210629013@55466
   345
    edge[arr] (e);
s1210629013@55466
   346
s1210629013@55466
   347
  \node [block,formula,below=2em of e] (g) {$\frac{6a+3b}{3b} = \frac{3(2a+..)}{..}$}
s1210629013@55466
   348
    edge[arr] (f);
s1210629013@55466
   349
s1210629013@55466
   350
  \node [block,formula,below=2.2em of f] (h) {$\frac{6a+3b}{3b} = \frac{2a+b}{b}$}
s1210629013@55466
   351
    edge[arr] (g);
s1210629013@55466
   352
s1210629013@55466
   353
\end{tikzpicture}
s1210629013@55466
   354
\caption{Interaction with \isac{} \cite{daroczy2013error}.}
s1210629013@55466
   355
\label{fig:interaction}
s1210629013@55466
   356
\end{figure}
s1210629013@55466
   357
In fig. \ref{fig:isac-archi}, the server accesses the {\em knowledge} in HTML representation, both in turn administered by a learning management system like {\em moodle}.
s1210629013@55466
   358
Separated from the front-end concerned with dialogs etc. is the \textit{Standard ML} environment, the implementation language of \isabelle{} and \isac{}: the {\em math-engine} together with {\em programs} for \textit{Lucas-Interpretation} and {\em knowledge} in \textit{Standard ML} representation for fast access. The math-engine builds upon {\em Isabelle} by reusing the term structure of simply typed lambda calculus and respective parsing, pretty printing, matching as well as management of {\em knowledge} within theories. The orange color in fig. \ref{fig:isac-archi} indicates parallelization in order to exploit availability of an arbitrary number of cores ({\em core 1..n}). In 2009, \isabelle{} introduced specific mechanisms to cope with multi-core environments. The central \isabelle{} component for parallelization is the {\em Scala bridge} (section \ref{ssec:isa-scala}) supporting asynchronous user interaction \cite{wenzel2012asynchronous} and parallel proof checking \cite{wenzel2009parallel} via the editor {\em jEdit} (section \ref{ssec:isa-jedit}). \isabelle{}'s parallel mechanisms are reused in the case study. The horizontal orange bar above {\em Isabelle} indicates that parallelization of \isabelle{} affected \isac's management of {\em knowledge} in \textit{Standard ML} representation. This part of the case study is described in section \ref{ssec:parall-thy}. The vertical orange bar to the left of the {\em \isac{} math-engine} indicates the concurrent user session management accomplished by the second part of the case study, which is described in section \ref{ssec:session-manag}.
s1210629013@55466
   359
s1210629013@55466
   360
\subsubsection{Modeling the Universe of Mathematics}
s1210629013@55466
   361
This goes beyond \isabelle{}'s way of modeling the deductive dimension of knowledge. Due to a suggestion by Bruno Buchberger in 2001, \isac{} now implements two additional dimensions, together spanning a three-dimensional space:
s1210629013@55466
   362
\begin{enumerate}
s1210629013@55466
   363
\item\label{enum:thy}{\bf Deductive knowledge} is defined and managed in TP. Beginning with the basic axioms (axioms of higher-order logic in \textit{Isabelle/HOL} used by \isac), definitions are given and theorems about these definitions are proved, theory by theory. \isabelle{} provides an elegant mechanism for defining new syntax, which results in a language close to traditional mathematical notation. The subset of \isabelle{} knowledge presently in use by \isac{} can be found online \cite{isac2014knowledge}.
s1210629013@55466
   364
\item\label{enum:pbl}{\bf Application-oriented knowledge} is given by formal specifications of problems in applied mathematics. The specification of all problems, which can be solved automatically by \isac{} (with the help of algorithms, see below), is available online \cite{isac2014pbl}.
s1210629013@55466
   365
This collection is structured as a tree. Given a tree, automated problem refinement is possible, e.g. starting from the specification at the node of {\em univariate equations} \cite{isac2014pblequuniv} a certain equation can be matched with all child nodes until the appropriate type of equation has been identified. In case a match has been found, such a node contains a pointer to a program solving the specific type of equation.
s1210629013@55466
   366
This kind of problem refinement makes transparent, what is done by computer algebra systems as black boxes.
neuper@55476
   367
\item\label{enum:met}{\bf Algorithmic knowledge} is given by programs to undergo \textit{Lucas-Interpretation}. The collection of programs is structured as a tree. However, principal requirements on the structure are still unclear. There are ideas of how to group algorithms in \cite{buchberger1984mathematik} but the ideas are too vague for mechanization. \isac's programs can be found online \cite{isac2014met}.
s1210629013@55466
   368
\end{enumerate}
s1210629013@55466
   369
The structure of the knowledge collections of pt. \ref{enum:pbl} and \ref{enum:met} are different from pt. \ref{enum:thy}. E.g. linear equations in pt. \ref{enum:pbl} are the same for rational numbers and complex numbers, but the definition of rationals is far away from complex numbers in pt. \ref{enum:thy}.
s1210629013@55466
   370
So the implementation of the latter two collections is orthogonal to the first, the collection structured and managed by \isabelle{}. The only way of implementation was by {\tt Unsynchronized.ref}, i.e. by global references. Write access to these references assumed a certain sequence in evaluation of the theories. This assumption broke with the introduction of parallel execution in \isabelle{}. Section \ref{ssec:parall-thy} explains how this issue was resolved.
s1210629013@55466
   371
s1210629013@55466
   372
\subsection{Relation to Ongoing \isabelle{} Development}
s1210629013@55466
   373
\label{ssec:future-isab}
s1210629013@55466
   374
In my Bachelor's project \cite{lehnfeld2011verbindung} I already had the chance to contribute to \isac{}. From my experience with \isac{} I can give the following overview of \isac{}'s development.
s1210629013@55466
   375
s1210629013@55466
   376
Although being active for more than two decades, \isabelle{} development still undergoes invasive reforms concerning localization, parallelization, etc. See the NEWS file \cite{isabelle2013news} for details. These reforms cause significant changes in module signatures and in functionality more or less with each release. Many of these changes enforce considerable updates of \isac{} because \isac{} extracts functionality from \isabelle{} at a rather deep level, apart from public interfaces.
s1210629013@55466
   377
Updating \isac{} in accordance to the regular \isabelle{} releases is crucial: Between 2002 and 2010 \isac{} development focused on the front-end. In 2010, \textit{Lucas-Interpretation} \cite{neuper2012automated} was clarified and \isabelle{}'s contexts appeared indispensable. Contexts appeared in \isabelle{} after 2002, so an update was necessary. However, updating \isac's math-engine from \textit{Isabelle2002} to \textit{Isabelle2009-2} turned out to be very hard and it was done during and after my Bachelor's project.
s1210629013@55466
   378
Ever since this unpleasant experience \isac{} has been updated with each official \isabelle{} release which are published every eight to twelve months. In addition to these regular updates there are major tasks concerning further adoption of \isabelle{}'s mechanisms which are open due to early design decisions of \isac.
s1210629013@55466
   379
s1210629013@55466
   380
\paragraph{Adopt logical contexts from \isabelle{}.} 
s1210629013@55466
   381
\isac's mathematics-engine was developed between 2000 and 2002, long before \isabelle{} introduced logical contexts \cite{wenzel2013impl}. Without these contexts the user needed to explicitly fix the type of variables during input. This was very inconvenient. I implemented my Bachelor's project in time to introduce contexts to \isac{} and gain first experiences with the system.
s1210629013@55466
   382
Experience with contexts also contributed to the theoretical clarification of \textit{Lucas-Interpretation} \cite{neuper2012automated}.
s1210629013@55466
   383
s1210629013@55466
   384
\paragraph{Adapt to \isabelle{}'s parallel theory evaluation.}
s1210629013@55466
   385
Since \isabelle{} traverses its theory dependency graph in parallel, \isac{} can no longer rely on a particular, deterministic execution order. Fixing the problems which arose from this fact and integrating the related datastructures into \isabelle{}'s theory data management model is one of the big achievements of the project work that this thesis is based on. The details of this process are outlined in section \ref{ssec:parall-thy}.
s1210629013@55466
   386
s1210629013@55466
   387
\paragraph{Exploit parallelism for concurrent session management.}
s1210629013@55466
   388
This task addresses the utilization of \isabelle{}'s new mechanisms for parallelism, most notably futures, for \isac{}'s user session management in order to allow for a high number of concurrent, efficiently executed calculations. Section \ref{ssec:session-manag} documents this step in more depth.
s1210629013@55466
   389
s1210629013@55466
   390
\paragraph{Make \isac's programming language usable.} \isac's programming language was implemented between 2000 and 2002, long before \isabelle{}'s function package was available \cite{krauss2013defining}. \textit{Lucas-Interpretation} on programs in this language uses a variety of rulesets for rewriting, too complicated for an average programmer \cite{rocnik2012interactive}.
s1210629013@55466
   391
Considerable simplification of programming can be expected by narrowing \isac's programming language towards \isabelle{}'s function package. In particular, components of \isabelle{}'s code generator \cite{haftmann2010code} promise to greatly improve computational efficiency.
s1210629013@55466
   392
s1210629013@55466
   393
\paragraph{Adopt \isabelle{}'s numeral computation for \isac{}.}
s1210629013@55466
   394
The initial conception of \isac{} emphasized applied mathematics, which is unrealistic without floating point numbers. There were early attempts to implement the latter together with complex numbers. Both, floating point numbers and complex numbers have in the meantime been implemented in \isabelle{}. These shall now be adopted for \isac{}.
s1210629013@55466
   395
s1210629013@55466
   396
\paragraph{Improve the efficiency of \isac{}'s rewrite engine.}
s1210629013@55466
   397
\isac's initial design stressed the importance of computations closely resembling work by paper and pencil. Major parts of computation happen by rewriting, so a large number of rewrite rules need to form groups which as such mimic the step width of human computations.
s1210629013@55466
   398
\isabelle{}'s rewrite engine meets opposite requirements: provide a maximum of automation with large rule sets (``simpsets''). Only recently, frequent user requests motivated projects in the \isabelle{} development to provide readable traces for rewriting.
s1210629013@55466
   399
However, the requirements of \isabelle{} and \isac{} are too different and \isac{} will keep its own rewrite engine. But the mechanism of {\em term nets} \cite{charniak2014artificial} could be adopted to improve \isac's efficiency.
s1210629013@55466
   400
s1210629013@55466
   401
\paragraph{Adopt \textit{Isabelle/jEdit} for \isac{}.}
s1210629013@55466
   402
\isac's initial design also stressed usability of the front-end for students. At this time \isabelle{}'s front-end was {\em Proof General} \cite{aspinall2000proof}. Thus there was no choice but to develop a custom GUI for \isac{}.
neuper@55476
   403
In the meantime \textit{Isabelle/jEdit} has become an appealing prover IDE. However, the requirements are presently quite opposing. \isabelle{} connects one engineer with a multitude of cores while \isac{} connects a multitude of students with one server. \isac's centralized structure has good reasons: groups of students have one lecturer, groups of students are examined together, etc.
s1210629013@55466
   404
During the next years, \isac{}'s front-end will be developed and improved independently from \isabelle{}. Narrowing towards \isabelle{} can start as soon as \textit{Isabelle/jEdit} moves towards collaborative work, implements session management, version management, etc.
s1210629013@55466
   405
s1210629013@55466
   406
\subsubsection{Summary on \isac's Approach to \isabelle{}}
s1210629013@55466
   407
Above, those points are listed, where \isac's math-engine is supposed to approach \isabelle{} in future development, as this thesis already has begun. Development of \isac's math-engine is separated from the development of \isac's front-end. Section \ref{ssec:isac-archi} describes \isac's {\em architecture {\em separating} mathematics and dialogs}.
s1210629013@55466
   408
Development of the front-end addresses the expertise represented by our {\em University of Applied Sciences} in Hagenberg: human-centered computing, interactive media, mobile computing, secure information systems, software engineering, etc. \isac's development efforts in these disciplines can be planned independently from the above list for several years, until \textit{Isabelle/jEdit} is ready to be adopted for \isac{} in a particularly interesting development effort.
s1210629013@55466
   409
s1210629013@55466
   410
s1210629013@55466
   411
\section{Practical Work on \isac{}}
s1210629013@55466
   412
\label{sec:contrib}
s1210629013@55466
   413
This section documents the implementation work that has been carried out as project work in preparation for and along with the writing of this thesis. During the first big step, the breakdown of \isac{}'s theory evaluation caused by an invasive update to \isabelle{}'s mechanisms was fixed (section \ref{ssec:parall-thy}). This made possible the introduction of concurrency to \isac{}'s user session management and thus enabled the parallel computation of independent calculations. This process is described in section \ref{ssec:session-manag}. Section \ref{sec:performance} discusses the effects of this process on \isac{}'s performance. Finally, \isac{}'s project status is summarized in section \ref{sec:proj-stat}.
s1210629013@55466
   414
s1210629013@55466
   415
s1210629013@55466
   416
\subsection{Integration With \isabelle{}'s Parallel Theory Evaluation}
s1210629013@55466
   417
\label{ssec:parall-thy}
s1210629013@55466
   418
In older \isabelle{} versions, it was not possible for programmers to append arbitrary data to the datastructure which holds all the theories. {\em Isabelle2005} \cite{isabelle2013news} then introduced a concept called {\em theory data}, which allowed developers to store user-defined datastructures in a theory's context from \textit{ML} code embedded in that theory.
s1210629013@55466
   419
s1210629013@55466
   420
\paragraph{Data flow.} In order to understand the following paragraphs, we need to know how \isabelle{} computes theories and what the theory data flow looks like. Section \ref{sec:isaisar} already mentioned, that the inheritance structure of \isabelle{}'s theories forms an acyclic, directed graph. Computation begins at the root theories which are determined backwards from the current working theory. The resulting data is then available in all descendant theories. Whenever a theory has more than one ancestor, the derived data is merged.
s1210629013@55466
   421
s1210629013@55466
   422
\bigskip
s1210629013@55466
   423
neuper@55476
   424
The last sections have outlined the conceptual and architectural differences between \isabelle{} and \isac{}. \isac{} needs to manage application-oriented and algorithmic knowledge which originally could not be integrated with the deductive structure of \isabelle{}'s theories. Therefore these data were stored in raw ML references. {\em Isabelle2009} then introduced parallelism. Now the computation order of the theories was not deterministic anymore and \isac{} could not ensure that its \textit{ML} references were accessed and updated in the same order as previously. This caused certain parts of the system to show faulty behavior in some cases. {\em Isabelle2009-1} then added the wrapper structure {\tt Unsynchronized.ref} to denote that these references are not synchronized with the parallel environment managed by \isabelle{}.
s1210629013@55466
   425
While the temporary deactivation of faulty modules and certain work\-arounds fixed most problems, the parallelization of \isac{}'s user session management required that most relevant data be properly managed by \isabelle{}. Therefore the preparatory step for the parallelization was the integration of the unsynchronized references in question with \isabelle{} by means of the functor {\tt Theory\_Data} \cite{wenzel2013impl}.
s1210629013@55466
   426
It is important to mention that the \isabelle{} implementation manual \cite{wenzel2013impl} warns to be careful about using too many datastructures on the basis of {\tt Theory\_Data} because they are newly initialized for every single theory that derives from the respective module that declared the datastructures. Thus, space is reserved which can cause a significantly increased memory footprint. Most of the overhead, however, occurs when theories are loaded dynamically. When working with a compiled \isac{} system the overhead should be reasonable.
s1210629013@55466
   427
s1210629013@55466
   428
The workflow was implemented for several central elements and broken down into five isolated steps to conform with \isabelle{}'s minimal changeset development and documentation model (section \ref{sec:isadevdoc}):
s1210629013@55466
   429
\begin{enumerate}
neuper@55476
   430
  \item\label{enum:isolate} {\bf Isolate access.} In this step, read accesses were centralized by wrapping references in an access function and replacing all occurrences with a call to the function:
neuper@55476
   431
\imlcode{~~\=val foo = Unsynchronized.ref [1,2,3]; (*declaration*)\\
s1210629013@55466
   432
\>fun get\_foo () = !foo; (*new*)\\
s1210629013@55466
   433
\>fun add x y = x + y;\\
s1210629013@55466
   434
\>fun foo\_sum () = fold add (!foo) 0; (*obsolete*)\\
s1210629013@55466
   435
\>fun foo\_sum () = fold add (get\_foo ()) 0; (*new*)}
s1210629013@55466
   436
s1210629013@55466
   437
  \item\label{enum:addthydata} {\bf Add {\tt Theory\_Data} access functions} in parallel to the existing ones. This includes a new version of the getter function ({\tt get\_foo} in pt. \ref{enum:isolate}). But first we need to define a datastructure that \isabelle{} can manage. Thus, we need to implement the functor \texttt{Theory\_Data} for our specific datatype\footnote{see appendix \ref{app:merge-lists} for definitions of {\tt merge\_lists(')}}:
s1210629013@55466
   438
\imlcode{\label{alg:thydata-functor}
s1210629013@55466
   439
~~\=st\=ructure Foo\_Data = Theory\_Data (\\
s1210629013@55466
   440
\>\>type T = int list;\\
s1210629013@55466
   441
\>\>val empty = [];\\
s1210629013@55466
   442
\>\>val extend = I; (*identity*)\\
s1210629013@55466
   443
\>\>val merge = merge\_lists;\\
s1210629013@55466
   444
\>);}
s1210629013@55466
   445
\noindent
s1210629013@55466
   446
{\tt T} is the type of the data. {\tt empty} is the initial value for every theory that does not define this particular data slot content. {\tt extend} is used for reinitialization on import of a theory and can be understood as a unitary {\tt merge}. Finally, {\tt merge} declares, how the data slot contents of two theories are to be joined. Unlike the operations that we are replacing during this process, the two simple access functions
s1210629013@55466
   447
\imlcode{~~\=val get\_foo' = Foo\_Data.get;\\
s1210629013@55466
   448
\>fun put\_foo' xs = Foo\_Data.map (merge\_lists' xs);}
s1210629013@55466
   449
\noindent
s1210629013@55466
   450
additionally require the target theory as input parameter. Because \textit{ML} code is always embedded in \isabelle{} theories, they can operate on any available theory according to the dependency graph. Each theory stores its own version of the data slot. A new version of {\tt get\_foo},
s1210629013@55466
   451
\imlcode{~~fun get\_foo () = get\_foo' @\{theory\}; \textrm{,}}
s1210629013@55466
   452
which is not yet in use during this phase, could replace \texttt{get\_foo} from pt. \ref{enum:isolate}. This definition uses antiquotations (section \ref{sec:antiquot}, page \pageref{sec:antiquot}). This means that {\tt @\{theory\}} always refers to the theory where the function definition is located and is thus resolved at compile time. The alternative approach
s1210629013@55466
   453
\imlcode{~~fun get\_foo () = get\_ref\_thy () |> get\_foo';}
s1210629013@55466
   454
\noindent
s1210629013@55466
   455
is more flexible in that {\tt get\_foo'} operates on a reference theory set by the programmer (details on {\tt get\_ref\_thy} are explained in the subsequent section) and passes it to {\tt get\_foo'} from above. The last aspect of this step is the addition of {\bf setup} blocks \cite{wenzel2013isar} where previously the raw references had been updated. These blocks must contain one \textit{ML} expression which represents a mapping between two {\tt theory}s. As a consequence, \isabelle{} updates the current theory context with the function's result in these locations, e.g.
s1210629013@55466
   456
\imlcode{~~setup \{* put\_foo' [4,5,6] *\} \textit{.}}
s1210629013@55466
   457
neuper@55476
   458
  \item\label{enum:checkdiff} {\bf Check differences.} Now that both, the old unsynchronized reference and the new stored as theory data, are created and updated, we can compare their contents and make sure that the last steps were successful. Due to the nature of the datastructures and the fact that the new method caused a different ordering to some of the elements, the most convenient solution was to compute a string representation from both results, write them into documents and compare the documents using a file comparison utility. If any errors occurred, step \ref{enum:isolate} and \ref{enum:addthydata} required revision.
s1210629013@55466
   459
s1210629013@55466
   460
  \item\label{enum:shiftthydata} {\bf Shift to theory data.} Optimally, this step merely meant exchanging the old definition of {\tt get\_foo} (pt. \ref{enum:isolate}) for the new one (pt. \ref{enum:addthydata}).
s1210629013@55466
   461
s1210629013@55466
   462
  \item\label{enum:removecode} {\bf Cleanup.} Finally, we can remove all code concerned with the unsynchronized reference.
s1210629013@55466
   463
s1210629013@55466
   464
\end{enumerate}
s1210629013@55466
   465
s1210629013@55466
   466
Besides acquiring the necessary knowledge on how to store and access arbitrary datastructures in a theory's context, the biggest challenges included understanding and merging the different kinds of custom datastructures and keeping the solutions simple; optimally simpler than the previous code. Also, I had to adjust the theory hierarchy and add new theories in order to keep a clean structure and ensure that the availability and computation of datastructures was sound and behaved as it had previously. Some of the data dependencies had not been reflected in the dependency graph but had rather been fulfilled by a fortunate execution order.
s1210629013@55466
   467
neuper@55476
   468
As a result of this contribution, most of the stateful components in \isac{}, which had been necessary to circumvent mismatches between \isac{}'s and \isabelle{}'s architectures, were eradicated from the system. Those which are still not synchronized are currently being replaced. However, they are not accessed by theories potentially executed in parallel and therefore do not interfere with \isac{}'s parallel user session management.
s1210629013@55466
   469
s1210629013@55466
   470
% calcelems.sml:839
s1210629013@55466
   471
% merge tree into another tree (not bidirectional!)
s1210629013@55466
   472
%(* this function only works wrt. the way Isabelle evaluates Theories and is not a general merge
s1210629013@55466
   473
%  function for trees / ptyps *)
s1210629013@55466
   474
%fun merge_ptyps ([], pt) = pt
s1210629013@55466
   475
%  | merge_ptyps (pt, []) = pt
s1210629013@55466
   476
%  | merge_ptyps ((x' as Ptyp (k, x, ps)) :: xs, (xs' as Ptyp (k', y, ps') :: ys)) =
s1210629013@55466
   477
%      if k = k'
s1210629013@55466
   478
%      then Ptyp (k, y, merge_ptyps (ps, ps')) :: merge_ptyps (xs, ys)
s1210629013@55466
   479
%      else x' :: merge_ptyps (xs, xs');
s1210629013@55466
   480
s1210629013@55466
   481
%fun merge_tree 
s1210629013@55466
   482
s1210629013@55466
   483
% challenges:
s1210629013@55466
   484
%   ensure that required functions are available wherever used/needed (change inheritance structure, introduce new theories)
s1210629013@55466
   485
%   don't add to complexity
s1210629013@55466
   486
%   datastructures different (lists, trees)
s1210629013@55466
   487
s1210629013@55466
   488
%DONE:
s1210629013@55466
   489
%> Offensichtlich sind die Umstände durch die unterschiedlichen Architekturen und Requirements der beiden Systeme und der ständigen Erweiterung Isabelles entstanden. 
s1210629013@55466
   490
%Probleme sind durch die Weiterentwicklung von Isabelle entstanden, unterschiedliche Architekturen und Requirements spielen hier keine Rolle:
s1210629013@55466
   491
%ISAC's "stateful components" haben aufgrund von Isabelle's Parallelisierung "non-deterministic behaviour" bekommen. In ISAC betraf dies Unsynchronized.ref.
s1210629013@55466
   492
%> Meine momentane Arbeit ist notwendig, um dann ISAC zu parallelisieren, hat aber forschungstechnisch weniger mit der Parallelisierung funktionaler Programme zu tun, sondern mit Software Engineering Prozessen speziell in Standard ML, da es mutable Data erlaubt - oder?
s1210629013@55466
   493
%"mutable data", die "Unsynchronized.ref" waren notwendig, um der "deductive structure of Isabelle theories" zu entkommen und "Application-oriented knowledge" sowie "Algorithmic knowledge" hinzuzufügen.
s1210629013@55466
   494
%Hier ging es also um "Architectural Design", das nur so unschön zu implementieren war.
s1210629013@55466
   495
%Die bisherige Arbeit war notwendig, weil ISAC mit den "stateful components" auf dem parallelsierten Isabelle schlichtweg nicht mehr funktionierte.
s1210629013@55466
   496
%> Bei einer Implementierung mittels einer rein funktionalen Sprache hätte es diese Probleme maximal in anderer Form gegegeben. 
s1210629013@55466
   497
%Genau.
s1210629013@55466
   498
s1210629013@55466
   499
%DONE:
s1210629013@55466
   500
%>> The init operation is supposed to produce a pure value from the given back-
s1210629013@55466
   501
%>> ground theory and should be somehow “immediate”. Whenever a proof con-
s1210629013@55466
   502
%>> text is initialized, which happens frequently, the the system invokes the init
s1210629013@55466
   503
%>> operation of all theory data slots ever declared. This also means that one
s1210629013@55466
   504
%>> needs to be economic about the total number of proof data declarations in
s1210629013@55466
   505
%>> the system, i.e. each ML module should declare at most one, sometimes two
s1210629013@55466
   506
%>> data slots for its internal use. Repeated data declarations to simulate a
s1210629013@55466
   507
%>> record type should be avoided!
s1210629013@55466
   508
%> (S. 46)
s1210629013@55466
   509
%>
s1210629013@55466
   510
%> Ich weiß nicht, ob das eh vernachlässigbar ist.
s1210629013@55466
   511
%Nicht vernachl"ssigen --- sondern in 4.2.4 erkl"aren:
s1210629013@55466
   512
%# ISAC erzeugt eine gewaltige Menge von Theory_Data
s1210629013@55466
   513
%# Theory_Data werden von Theory zu Theory 'vererbt' --- das erzeugt Overhead, wenn Theories dynamisch %geladen werden
s1210629013@55466
   514
%# ISAC braucht aber kein dynamisches Laden von Theories --- alle Theories sind in einer Session zusammengefasst, die 1-mal beim Hochfahren geladen wird. 
s1210629013@55466
   515
s1210629013@55466
   516
s1210629013@55466
   517
\subsection{Introduction of Concurrent User Session Management}
s1210629013@55466
   518
\label{ssec:session-manag}
s1210629013@55466
   519
\isabelle{}'s programming conventions prohibit user programs based on \isabelle{} from forking their own \textit{ML} threads. This is necessary because \isabelle{} has its own managed environment for concurrency which takes care of thread synchronization and shared resources. Accesses from user threads could easily break this well-tested framework. After careful analysis of the \isabelle{} documentation and the code in some concurrency related \textit{Isabelle/ML} modules, our suspicion that parallelizing \isac{}'s user session management required breaking this convention was rendered unfounded. As it turned out, \isabelle{}'s implementation of {\em future}s (section \ref{sec:isafut}) provided everything we needed. As a result, the actual implementation effort was marginal. Since \isac{}'s does not maintain any problematic stateful resources anymore, there was no further effort required for synchronizing shared resources beyond those managed by \isabelle{}, except for the {\tt states} element, which maintains a state for each active calculation. Instead of an {\tt Unsynchronized.ref}, it was replaced by a {\tt Synchronized.var} (see section \ref{sec:guarded-access}, page \pageref{sec:guarded-access}).
s1210629013@55466
   520
s1210629013@55466
   521
The function {\tt appendFormula}, which derives the input formula from a calculation's state, had to be transformed in a way, such that it can be passed to {\tt Future.fork} which then takes care of the parallel execution.
s1210629013@55466
   522
\imlcode{~~fun ap\=pendFormula params =\\
s1210629013@55466
   523
\>Future.fork (fn () => appendFormula' params);}
s1210629013@55466
   524
\noindent
s1210629013@55466
   525
is a simplified version of the key line in this transition, with {\tt appendFormula'} being the original version of the function. The same transformation was applied to {\tt autoCalculate}, which can compute calculations step by step as well as automatically determine the final result. Many of the computations within {\tt autoCalculate} require access to the current proof context datastructure. During the previous part of the project (section \ref{ssec:parall-thy}), this was done using the function {\tt the\_generic\_context} from \isabelle{}'s {\em ML\_Context} module. When I called more than one instance of {\tt autoCalculate} simultaneously, it turned out that functions executed within a future cannot acquire access to the current proof context through this function. In practice, the context data of the theory {\em Isac} is sufficient for all calculations and could be completed and made available at compile time. However, the \isac{} test suite extends the context data, which cannot be modified at run time. In order to overcome this, there is now a {\tt Synchronized.var} at an appropriate location within the dependency graph, which determines the reference theory for all operations accessing the newly introduced {\tt Theory\_Data} elements. The test suite uses a new function {\tt set\_ref\_thy} to override the standard value which is the theory {\em Isac}.
s1210629013@55466
   526
s1210629013@55466
   527
Now that all calls to {\tt the\_generic\_context} have been eliminated, invocations of {\tt autoCalculate} and {\tt appendFormula} return immediately with a future value and thus the respective operations are executed in the background.
s1210629013@55466
   528
s1210629013@55466
   529
s1210629013@55466
   530
\subsection{Performance}
s1210629013@55466
   531
\label{sec:performance}
s1210629013@55466
   532
The main objective of my project was to improve the speed with which calculations are performed by the system when multiple user front-ends invoke the \isac{} mathematics-engine simultaneously.
s1210629013@55466
   533
s1210629013@55466
   534
The change in memory usage is not our foremost concern and it can only increase linearly. The number of concurrent calculations depends on \isabelle{}'s thread pool size. Pending invocations of the mathematics-engine are problem descriptions whose memory footprint is negligible, considering a reasonable number of clients working on the same \isac{} server. One concern is the keeping of state data on a per user basis which could accumulate and pose a challenge to the server's working memory under heavy load.
s1210629013@55466
   535
s1210629013@55466
   536
Temporal gains were measured on a 64-bit {\em Arch Linux} system running on a {\em Lenovo ThinkPad X230} with 4GB RAM and an {\em Intel\textregistered{} Core\texttrademark{} i5-3320M CPU} with two physical 2.60GHz cores and one additional logical core respectively (see {\em simultaneous multithreading} in section \ref{sec:multicoreproc}). The performance test file can be found on the attached DVD (see appendix \ref{app:dvd-proj}). It uses the most CPU-intensive problem instance currently available, whose calculation takes about 1.58 seconds on average. Various numbers of parallel invocations were issued and the time until all of them were finished was measured. Per test there were 20 repetitions and an average taken. All the samples are shown in fig. \ref{fig:autocalc}.
s1210629013@55466
   537
s1210629013@55466
   538
\def\thinkpaddata{data/thinkpad.dat}
s1210629013@55466
   539
\def\thinkpadavg{data/thinkpadavg.dat}
s1210629013@55466
   540
\def\thinkpaddataseq{data/thinkpad_seq.dat}
s1210629013@55466
   541
\def\thinkpadavgseq{data/thinkpadavg_seq.dat}
s1210629013@55466
   542
s1210629013@55466
   543
\pgfplotsset{
s1210629013@55466
   544
    colormap={spectral}{[5pt]
s1210629013@55466
   545
        color(0pt)=(color1);
s1210629013@55466
   546
        color(5pt)=(color2);
s1210629013@55466
   547
    }
s1210629013@55466
   548
}
s1210629013@55466
   549
s1210629013@55466
   550
\begin{figure}
s1210629013@55466
   551
\centering
s1210629013@55466
   552
\begin{tikzpicture}
s1210629013@55466
   553
  \begin{axis}[
s1210629013@55466
   554
    xlabel=number of calculations $n$,
s1210629013@55466
   555
    ylabel=time $t$ in ms,
s1210629013@55466
   556
    ylabel style={at={(-0.23,0.5)}},
s1210629013@55466
   557
    xmin=0,
s1210629013@55466
   558
    xmax=15.5,
s1210629013@55466
   559
    xticklabel style={/pgf/number format/.cd,1000 sep={,}},
s1210629013@55466
   560
    xticklabel=\pgfmathparse{\tick}\pgfmathprintnumber{\pgfmathresult},
s1210629013@55466
   561
    ymin=0,
s1210629013@55466
   562
    ymax=24000,
s1210629013@55466
   563
    scaled y ticks = false,
s1210629013@55466
   564
    yticklabel style={/pgf/number format/.cd,fixed,1000 sep={,}},
s1210629013@55466
   565
    yticklabel=\pgfmathparse{\tick}\pgfmathprintnumber{\pgfmathresult},
s1210629013@55466
   566
    grid=major,
s1210629013@55466
   567
    legend entries={seq. samples, seq. mean, par. samples, par. mean},
s1210629013@55466
   568
    legend style={draw=none,at={(0.49,0.92)}},
s1210629013@55466
   569
    axis lines=left
s1210629013@55466
   570
  ]
s1210629013@55466
   571
    \addplot[scatter, mark=o, only marks, color=color1, point meta=explicit symbolic] table[y=t, x=n,meta index=0] {\thinkpaddataseq};
s1210629013@55466
   572
    \addplot[color=color1] table[y=t, x=n, meta index=0]{\thinkpadavgseq};
s1210629013@55466
   573
    \addplot[scatter, mark=o, only marks, color=color2, point meta=explicit symbolic] table[y=t, x=n,meta index=1] {\thinkpaddata};
s1210629013@55466
   574
    \addplot[color=color2] table[y=t, x=n, meta index=1]{\thinkpadavg};
s1210629013@55466
   575
  \end{axis}
s1210629013@55466
   576
\end{tikzpicture}
s1210629013@55466
   577
s1210629013@55466
   578
\caption{{\tt autoCalculate} performance comparison.}
s1210629013@55466
   579
\label{fig:autocalc}
s1210629013@55466
   580
\end{figure}
s1210629013@55466
   581
s1210629013@55466
   582
\subsubsection{Discussion}
neuper@55476
   583
From these results it is evident, that two parallel calculations can almost fully exploit both physical processing cores. The slight increase of processing time can be explained by a parallelization overhead caused by \isabelle{}'s future management. Another factor are the synchronized accesses to the {\tt states} datastructure. Since simultaneous multithreading cannot completely simulate additional cores, the increase in runtime between two and three parallel calculations is then slightly bigger. The same happens between six and seven parallel {\tt autoCalculate} invocations. As the number of logical cores of the used machine is four, multiples of four show a significant increase in runtime because once all cores are occupied, additional calculations need to wait. Hence, the execution time accurately doubles with the number of calculations according to the number of cores. The measured runtime of the new {\tt autoCalculate} version was only $38.7\%$ of the previous, sequential implementation with eight parallel calculations, $39.8\%$ with ten and $39.7\%$ with twelve. This is a very satisfying outcome and we trust that it will help to significantly improve the end user experience and enable \isac{} servers to deal with a high number of clients simultaneously.
s1210629013@55466
   584
s1210629013@55466
   585
\subsection{Project Status}
s1210629013@55466
   586
\label{sec:proj-stat}
s1210629013@55466
   587
The user session management is now able to utilize several processing cores for independent computations. However, communication between the \textit{ML} and \textit{Java} layers occurs on the basis of plain standard I/O streams, i.e. multiple front-ends using the same math-engine instance need to write to the same input stream on the \textit{ML} side and thus communication is unsynchronized. This means that although the math-engine is now able to deal with calculations for multiple users concurrently in an efficient manner, the communication model does not yet allow for thread-safe communication. Changing this may be subject for a future project. Another area requiring further investigation is the memory footprint of accumulated state data for calculations and how to deal with a very high number of concurrent user sessions in this respect.
s1210629013@55466
   588
s1210629013@55466
   589
% problems with streams, communication between ml and java, no return value of appendFormula