src/HOL/Imperative_HOL/Overview.thy
author paulson
Thu, 14 Jun 2018 14:23:48 +0100
changeset 68446 92ddca1edc43
parent 66453 cc19f7ca2ed6
child 69597 ff784d5a5bfb
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Imperative_HOL/Overview.thy
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
     2
    Author:     Florian Haftmann, TU Muenchen
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
     3
*)
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
     4
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
     5
(*<*)
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
     6
theory Overview
66453
cc19f7ca2ed6 session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents: 63167
diff changeset
     7
imports Imperative_HOL "HOL-Library.LaTeXsugar"
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
     8
begin
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
     9
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    10
(* type constraints with spacing *)
61143
5f898411ce87 eliminated \<Colon> from syntax of constraints;
wenzelm
parents: 58622
diff changeset
    11
no_syntax (output)
5f898411ce87 eliminated \<Colon> from syntax of constraints;
wenzelm
parents: 58622
diff changeset
    12
  "_constrain" :: "logic => type => logic"  ("_::_" [4, 0] 3)
5f898411ce87 eliminated \<Colon> from syntax of constraints;
wenzelm
parents: 58622
diff changeset
    13
  "_constrain" :: "prop' => type => prop'"  ("_::_" [4, 0] 3)
5f898411ce87 eliminated \<Colon> from syntax of constraints;
wenzelm
parents: 58622
diff changeset
    14
5f898411ce87 eliminated \<Colon> from syntax of constraints;
wenzelm
parents: 58622
diff changeset
    15
syntax (output)
5f898411ce87 eliminated \<Colon> from syntax of constraints;
wenzelm
parents: 58622
diff changeset
    16
  "_constrain" :: "logic => type => logic"  ("_ :: _" [4, 0] 3)
5f898411ce87 eliminated \<Colon> from syntax of constraints;
wenzelm
parents: 58622
diff changeset
    17
  "_constrain" :: "prop' => type => prop'"  ("_ :: _" [4, 0] 3)
5f898411ce87 eliminated \<Colon> from syntax of constraints;
wenzelm
parents: 58622
diff changeset
    18
(*>*)
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    19
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    20
text \<open>
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    21
  \<open>Imperative HOL\<close> is a leightweight framework for reasoning
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    22
  about imperative data structures in \<open>Isabelle/HOL\<close>
58622
aa99568f56de more antiquotations;
wenzelm
parents: 56240
diff changeset
    23
  @{cite "Nipkow-et-al:2002:tutorial"}.  Its basic ideas are described in
aa99568f56de more antiquotations;
wenzelm
parents: 56240
diff changeset
    24
  @{cite "Bulwahn-et-al:2008:imp_HOL"}.  However their concrete
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    25
  realisation has changed since, due to both extensions and
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    26
  refinements.  Therefore this overview wants to present the framework
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    27
  \qt{as it is} by now.  It focusses on the user-view, less on matters
40358
b6ed3364753d added note on countable types
haftmann
parents: 39717
diff changeset
    28
  of construction.  For details study of the theory sources is
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    29
  encouraged.
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    30
\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    31
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    32
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    33
section \<open>A polymorphic heap inside a monad\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    34
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    35
text \<open>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    36
  Heaps (@{type heap}) can be populated by values of class @{class
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    37
  heap}; HOL's default types are already instantiated to class @{class
40358
b6ed3364753d added note on countable types
haftmann
parents: 39717
diff changeset
    38
  heap}.  Class @{class heap} is a subclass of @{class countable};  see
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    39
  theory \<open>Countable\<close> for ways to instantiate types as @{class countable}.
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    40
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    41
  The heap is wrapped up in a monad @{typ "'a Heap"} by means of the
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    42
  following specification:
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    43
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    44
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    45
    @{datatype Heap}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    46
  \end{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    47
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    48
  Unwrapping of this monad type happens through
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    49
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    50
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    51
    @{term_type execute} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    52
    @{thm execute.simps [no_vars]}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    53
  \end{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    54
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    55
  This allows for equational reasoning about monadic expressions; the
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    56
  fact collection \<open>execute_simps\<close> contains appropriate rewrites
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    57
  for all fundamental operations.
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    58
39610
23bdf736d84f tuned text
haftmann
parents: 39307
diff changeset
    59
  Primitive fine-granular control over heaps is available through rule
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    60
  \<open>Heap_cases\<close>:
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    61
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    62
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    63
    @{thm [break] Heap_cases [no_vars]}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    64
  \end{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    65
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    66
  Monadic expression involve the usual combinators:
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    67
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    68
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    69
    @{term_type return} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    70
    @{term_type bind} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    71
    @{term_type raise}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    72
  \end{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    73
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    74
  This is also associated with nice monad do-syntax.  The @{typ
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    75
  string} argument to @{const raise} is just a codified comment.
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    76
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    77
  Among a couple of generic combinators the following is helpful for
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    78
  establishing invariants:
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    79
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    80
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    81
    @{term_type assert} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    82
    @{thm assert_def [no_vars]}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    83
  \end{quote}
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    84
\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    85
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    86
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    87
section \<open>Relational reasoning about @{type Heap} expressions\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    88
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    89
text \<open>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    90
  To establish correctness of imperative programs, predicate
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    91
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    92
  \begin{quote}
40671
5e46057ba8e0 renamed slightly ambivalent crel to effect
haftmann
parents: 40358
diff changeset
    93
    @{term_type effect}
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    94
  \end{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    95
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    96
  provides a simple relational calculus.  Primitive rules are \<open>effectI\<close> and \<open>effectE\<close>, rules appropriate for reasoning about
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    97
  imperative operations are available in the \<open>effect_intros\<close> and
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
    98
  \<open>effect_elims\<close> fact collections.
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
    99
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   100
  Often non-failure of imperative computations does not depend
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   101
  on the heap at all;  reasoning then can be easier using predicate
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   102
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   103
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   104
    @{term_type success}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   105
  \end{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   106
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   107
  Introduction rules for @{const success} are available in the
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   108
  \<open>success_intro\<close> fact collection.
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   109
40671
5e46057ba8e0 renamed slightly ambivalent crel to effect
haftmann
parents: 40358
diff changeset
   110
  @{const execute}, @{const effect}, @{const success} and @{const bind}
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   111
  are related by rules \<open>execute_bind_success\<close>, \<open>success_bind_executeI\<close>, \<open>success_bind_effectI\<close>, \<open>effect_bindI\<close>, \<open>effect_bindE\<close> and \<open>execute_bind_eq_SomeI\<close>.
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   112
\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   113
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   114
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   115
section \<open>Monadic data structures\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   116
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   117
text \<open>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   118
  The operations for monadic data structures (arrays and references)
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   119
  come in two flavours:
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   120
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   121
  \begin{itemize}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   122
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   123
     \item Operations on the bare heap; their number is kept minimal
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   124
       to facilitate proving.
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   125
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   126
     \item Operations on the heap wrapped up in a monad; these are designed
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   127
       for executing.
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   128
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   129
  \end{itemize}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   130
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   131
  Provided proof rules are such that they reduce monad operations to
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   132
  operations on bare heaps.
39717
e9bec0b43449 added hint on reference equality
haftmann
parents: 39610
diff changeset
   133
e9bec0b43449 added hint on reference equality
haftmann
parents: 39610
diff changeset
   134
  Note that HOL equality coincides with reference equality and may be
e9bec0b43449 added hint on reference equality
haftmann
parents: 39610
diff changeset
   135
  used as primitive executable operation.
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   136
\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   137
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   138
subsection \<open>Arrays\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   139
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   140
text \<open>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   141
  Heap operations:
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   142
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   143
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   144
    @{term_type Array.alloc} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   145
    @{term_type Array.present} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   146
    @{term_type Array.get} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   147
    @{term_type Array.set} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   148
    @{term_type Array.length} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   149
    @{term_type Array.update} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   150
    @{term_type Array.noteq}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   151
  \end{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   152
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   153
  Monad operations:
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   154
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   155
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   156
    @{term_type Array.new} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   157
    @{term_type Array.of_list} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   158
    @{term_type Array.make} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   159
    @{term_type Array.len} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   160
    @{term_type Array.nth} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   161
    @{term_type Array.upd} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   162
    @{term_type Array.map_entry} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   163
    @{term_type Array.swap} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   164
    @{term_type Array.freeze}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   165
  \end{quote}
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   166
\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   167
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   168
subsection \<open>References\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   169
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   170
text \<open>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   171
  Heap operations:
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   172
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   173
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   174
    @{term_type Ref.alloc} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   175
    @{term_type Ref.present} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   176
    @{term_type Ref.get} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   177
    @{term_type Ref.set} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   178
    @{term_type Ref.noteq}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   179
  \end{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   180
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   181
  Monad operations:
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   182
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   183
  \begin{quote}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   184
    @{term_type Ref.ref} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   185
    @{term_type Ref.lookup} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   186
    @{term_type Ref.update} \\
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   187
    @{term_type Ref.change}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   188
  \end{quote}
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   189
\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   190
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   191
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   192
section \<open>Code generation\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   193
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   194
text \<open>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   195
  Imperative HOL sets up the code generator in a way that imperative
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   196
  operations are mapped to suitable counterparts in the target
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   197
  language.  For \<open>Haskell\<close>, a suitable \<open>ST\<close> monad is used;
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   198
  for \<open>SML\<close>, \<open>Ocaml\<close> and \<open>Scala\<close> unit values ensure
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   199
  that the evaluation order is the same as you would expect from the
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   200
  original monadic expressions.  These units may look cumbersome; the
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   201
  target language variants \<open>SML_imp\<close>, \<open>Ocaml_imp\<close> and
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   202
  \<open>Scala_imp\<close> make some effort to optimize some of them away.
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   203
\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   204
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   205
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   206
section \<open>Some hints for using the framework\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   207
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   208
text \<open>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   209
  Of course a framework itself does not by itself indicate how to make
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   210
  best use of it.  Here some hints drawn from prior experiences with
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   211
  Imperative HOL:
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   212
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   213
  \begin{itemize}
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   214
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   215
    \item Proofs on bare heaps should be strictly separated from those
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   216
      for monadic expressions.  The first capture the essence, while the
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   217
      latter just describe a certain wrapping-up.
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   218
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   219
    \item A good methodology is to gradually improve an imperative
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   220
      program from a functional one.  In the extreme case this means
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   221
      that an original functional program is decomposed into suitable
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   222
      operations with exactly one corresponding imperative operation.
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   223
      Having shown suitable correspondence lemmas between those, the
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   224
      correctness prove of the whole imperative program simply
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   225
      consists of composing those.
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   226
      
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   227
    \item Whether one should prefer equational reasoning (fact
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   228
      collection \<open>execute_simps\<close> or relational reasoning (fact
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   229
      collections \<open>effect_intros\<close> and \<open>effect_elims\<close>) depends
39610
23bdf736d84f tuned text
haftmann
parents: 39307
diff changeset
   230
      on the problems to solve.  For complex expressions or
23bdf736d84f tuned text
haftmann
parents: 39307
diff changeset
   231
      expressions involving binders, the relation style usually is
23bdf736d84f tuned text
haftmann
parents: 39307
diff changeset
   232
      superior but requires more proof text.
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   233
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   234
    \item Note that you can extend the fact collections of Imperative
39610
23bdf736d84f tuned text
haftmann
parents: 39307
diff changeset
   235
      HOL yourself whenever appropriate.
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   236
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   237
  \end{itemize}
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62390
diff changeset
   238
\<close>
39307
8d42d668b5b0 added Imperative HOL overview
haftmann
parents:
diff changeset
   239
62390
842917225d56 more canonical names
nipkow
parents: 61143
diff changeset
   240
end