| author | wenzelm | 
| Tue, 25 Feb 2014 14:34:18 +0100 | |
| changeset 55742 | a989bdaf8121 | 
| parent 55686 | e99ed112d303 | 
| child 55944 | 7ab8f003fe41 | 
| permissions | -rw-r--r-- | 
| 26840 | 1 | theory HOL_Specific | 
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 2 | imports Base Main "~~/src/HOL/Library/Old_Recdef" "~~/src/Tools/Adhoc_Overloading" | 
| 26840 | 3 | begin | 
| 4 | ||
| 50109 | 5 | chapter {* Higher-Order Logic *}
 | 
| 42914 | 6 | |
| 7 | text {* Isabelle/HOL is based on Higher-Order Logic, a polymorphic
 | |
| 8 | version of Church's Simple Theory of Types. HOL can be best | |
| 9 | understood as a simply-typed version of classical set theory. The | |
| 10 | logic was first implemented in Gordon's HOL system | |
| 11 |   \cite{mgordon-hol}.  It extends Church's original logic
 | |
| 12 |   \cite{church40} by explicit type variables (naive polymorphism) and
 | |
| 13 | a sound axiomatization scheme for new types based on subsets of | |
| 14 | existing types. | |
| 15 | ||
| 16 |   Andrews's book \cite{andrews86} is a full description of the
 | |
| 17 | original Church-style higher-order logic, with proofs of correctness | |
| 18 | and completeness wrt.\ certain set-theoretic interpretations. The | |
| 19 | particular extensions of Gordon-style HOL are explained semantically | |
| 20 |   in two chapters of the 1993 HOL book \cite{pitts93}.
 | |
| 21 | ||
| 22 | Experience with HOL over decades has demonstrated that higher-order | |
| 23 | logic is widely applicable in many areas of mathematics and computer | |
| 24 | science. In a sense, Higher-Order Logic is simpler than First-Order | |
| 25 | Logic, because there are fewer restrictions and special cases. Note | |
| 26 |   that HOL is \emph{weaker} than FOL with axioms for ZF set theory,
 | |
| 27 | which is traditionally considered the standard foundation of regular | |
| 28 | mathematics, but for most applications this does not matter. If you | |
| 29 | prefer ML to Lisp, you will probably prefer HOL to ZF. | |
| 30 | ||
| 31 |   \medskip The syntax of HOL follows @{text "\<lambda>"}-calculus and
 | |
| 32 | functional programming. Function application is curried. To apply | |
| 33 |   the function @{text f} of type @{text "\<tau>\<^sub>1 \<Rightarrow> \<tau>\<^sub>2 \<Rightarrow> \<tau>\<^sub>3"} to the
 | |
| 34 |   arguments @{text a} and @{text b} in HOL, you simply write @{text "f
 | |
| 35 | a b"} (as in ML or Haskell). There is no ``apply'' operator; the | |
| 36 |   existing application of the Pure @{text "\<lambda>"}-calculus is re-used.
 | |
| 37 |   Note that in HOL @{text "f (a, b)"} means ``@{text "f"} applied to
 | |
| 38 |   the pair @{text "(a, b)"} (which is notation for @{text "Pair a
 | |
| 39 | b"}). The latter typically introduces extra formal efforts that can | |
| 40 | be avoided by currying functions by default. Explicit tuples are as | |
| 41 | infrequent in HOL formalizations as in good ML or Haskell programs. | |
| 42 | ||
| 43 | \medskip Isabelle/HOL has a distinct feel, compared to other | |
| 44 | object-logics like Isabelle/ZF. It identifies object-level types | |
| 45 | with meta-level types, taking advantage of the default | |
| 46 | type-inference mechanism of Isabelle/Pure. HOL fully identifies | |
| 47 | object-level functions with meta-level functions, with native | |
| 48 | abstraction and application. | |
| 49 | ||
| 50 | These identifications allow Isabelle to support HOL particularly | |
| 51 | nicely, but they also mean that HOL requires some sophistication | |
| 52 | from the user. In particular, an understanding of Hindley-Milner | |
| 53 | type-inference with type-classes, which are both used extensively in | |
| 54 | the standard libraries and applications. Beginners can set | |
| 55 |   @{attribute show_types} or even @{attribute show_sorts} to get more
 | |
| 56 | explicit information about the result of type-inference. *} | |
| 57 | ||
| 58 | ||
| 50109 | 59 | chapter {* Derived specification elements *}
 | 
| 60 | ||
| 42908 | 61 | section {* Inductive and coinductive definitions \label{sec:hol-inductive} *}
 | 
| 62 | ||
| 46280 | 63 | text {*
 | 
| 64 |   \begin{matharray}{rcl}
 | |
| 65 |     @{command_def (HOL) "inductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | |
| 66 |     @{command_def (HOL) "inductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | |
| 67 |     @{command_def (HOL) "coinductive"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | |
| 68 |     @{command_def (HOL) "coinductive_set"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | |
| 50302 | 69 |     @{command_def "print_inductives"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
 | 
| 46280 | 70 |     @{attribute_def (HOL) mono} & : & @{text attribute} \\
 | 
| 71 |   \end{matharray}
 | |
| 72 | ||
| 73 |   An \emph{inductive definition} specifies the least predicate or set
 | |
| 74 |   @{text R} closed under given rules: applying a rule to elements of
 | |
| 75 |   @{text R} yields a result within @{text R}.  For example, a
 | |
| 76 | structural operational semantics is an inductive definition of an | |
| 77 | evaluation relation. | |
| 42908 | 78 | |
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 79 |   Dually, a \emph{coinductive definition} specifies the greatest
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 80 |   predicate or set @{text R} that is consistent with given rules:
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 81 |   every element of @{text R} can be seen as arising by applying a rule
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 82 |   to elements of @{text R}.  An important example is using
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 83 | bisimulation relations to formalise equivalence of processes and | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 84 | infinite data structures. | 
| 47859 | 85 | |
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 86 | Both inductive and coinductive definitions are based on the | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 87 | Knaster-Tarski fixed-point theorem for complete lattices. The | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 88 | collection of introduction rules given by the user determines a | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 89 | functor on subsets of set-theoretic relations. The required | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 90 | monotonicity of the recursion scheme is proven as a prerequisite to | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 91 | the fixed-point definition and the resulting consequences. This | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 92 | works by pushing inclusion through logical connectives and any other | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 93 | operator that might be wrapped around recursive occurrences of the | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 94 | defined relation: there must be a monotonicity theorem of the form | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 95 |   @{text "A \<le> B \<Longrightarrow> \<M> A \<le> \<M> B"}, for each premise @{text "\<M> R t"} in an
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 96 | introduction rule. The default rule declarations of Isabelle/HOL | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 97 | already take care of most common situations. | 
| 42907 
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
 wenzelm parents: 
42705diff
changeset | 98 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 99 |   @{rail \<open>
 | 
| 42908 | 100 |     (@@{command (HOL) inductive} | @@{command (HOL) inductive_set} |
 | 
| 101 |       @@{command (HOL) coinductive} | @@{command (HOL) coinductive_set})
 | |
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 102 |     @{syntax target}? \<newline>
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 103 |     @{syntax "fixes"} (@'for' @{syntax "fixes"})? (@'where' clauses)? \<newline>
 | 
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 104 |     (@'monos' @{syntax thmrefs})?
 | 
| 42908 | 105 | ; | 
| 106 |     clauses: (@{syntax thmdecl}? @{syntax prop} + '|')
 | |
| 107 | ; | |
| 108 |     @@{attribute (HOL) mono} (() | 'add' | 'del')
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 109 | \<close>} | 
| 42908 | 110 | |
| 111 |   \begin{description}
 | |
| 112 | ||
| 113 |   \item @{command (HOL) "inductive"} and @{command (HOL)
 | |
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 114 | "coinductive"} define (co)inductive predicates from the introduction | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 115 | rules. | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 116 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 117 |   The propositions given as @{text "clauses"} in the @{keyword
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 118 |   "where"} part are either rules of the usual @{text "\<And>/\<Longrightarrow>"} format
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 119 |   (with arbitrary nesting), or equalities using @{text "\<equiv>"}.  The
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 120 | latter specifies extra-logical abbreviations in the sense of | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 121 |   @{command_ref abbreviation}.  Introducing abstract syntax
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 122 | simultaneously with the actual introduction rules is occasionally | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 123 | useful for complex specifications. | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 124 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 125 |   The optional @{keyword "for"} part contains a list of parameters of
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 126 | the (co)inductive predicates that remain fixed throughout the | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 127 | definition, in contrast to arguments of the relation that may vary | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 128 |   in each occurrence within the given @{text "clauses"}.
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 129 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 130 |   The optional @{keyword "monos"} declaration contains additional
 | 
| 42908 | 131 |   \emph{monotonicity theorems}, which are required for each operator
 | 
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 132 | applied to a recursive set in the introduction rules. | 
| 42908 | 133 | |
| 134 |   \item @{command (HOL) "inductive_set"} and @{command (HOL)
 | |
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 135 | "coinductive_set"} are wrappers for to the previous commands for | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 136 | native HOL predicates. This allows to define (co)inductive sets, | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 137 | where multiple arguments are simulated via tuples. | 
| 42908 | 138 | |
| 50302 | 139 |   \item @{command "print_inductives"} prints (co)inductive definitions and
 | 
| 140 | monotonicity rules. | |
| 141 | ||
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 142 |   \item @{attribute (HOL) mono} declares monotonicity rules in the
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 143 | context. These rule are involved in the automated monotonicity | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 144 | proof of the above inductive and coinductive definitions. | 
| 42908 | 145 | |
| 146 |   \end{description}
 | |
| 147 | *} | |
| 148 | ||
| 149 | ||
| 150 | subsection {* Derived rules *}
 | |
| 151 | ||
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 152 | text {* A (co)inductive definition of @{text R} provides the following
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 153 | main theorems: | 
| 42908 | 154 | |
| 155 |   \begin{description}
 | |
| 156 | ||
| 157 |   \item @{text R.intros} is the list of introduction rules as proven
 | |
| 158 | theorems, for the recursive predicates (or sets). The rules are | |
| 159 | also available individually, using the names given them in the | |
| 160 | theory file; | |
| 161 | ||
| 162 |   \item @{text R.cases} is the case analysis (or elimination) rule;
 | |
| 163 | ||
| 164 |   \item @{text R.induct} or @{text R.coinduct} is the (co)induction
 | |
| 44273 
336752fb25df
adding documentation about simps equation in the inductive package
 bulwahn parents: 
44055diff
changeset | 165 | rule; | 
| 
336752fb25df
adding documentation about simps equation in the inductive package
 bulwahn parents: 
44055diff
changeset | 166 | |
| 
336752fb25df
adding documentation about simps equation in the inductive package
 bulwahn parents: 
44055diff
changeset | 167 |   \item @{text R.simps} is the equation unrolling the fixpoint of the
 | 
| 
336752fb25df
adding documentation about simps equation in the inductive package
 bulwahn parents: 
44055diff
changeset | 168 | predicate one step. | 
| 47859 | 169 | |
| 42908 | 170 |   \end{description}
 | 
| 171 | ||
| 172 |   When several predicates @{text "R\<^sub>1, \<dots>, R\<^sub>n"} are
 | |
| 173 | defined simultaneously, the list of introduction rules is called | |
| 174 |   @{text "R\<^sub>1_\<dots>_R\<^sub>n.intros"}, the case analysis rules are
 | |
| 175 |   called @{text "R\<^sub>1.cases, \<dots>, R\<^sub>n.cases"}, and the list
 | |
| 176 |   of mutual induction rules is called @{text
 | |
| 177 | "R\<^sub>1_\<dots>_R\<^sub>n.inducts"}. | |
| 178 | *} | |
| 179 | ||
| 180 | ||
| 181 | subsection {* Monotonicity theorems *}
 | |
| 182 | ||
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 183 | text {* The context maintains a default set of theorems that are used
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 184 | in monotonicity proofs. New rules can be declared via the | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 185 |   @{attribute (HOL) mono} attribute.  See the main Isabelle/HOL
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 186 | sources for some examples. The general format of such monotonicity | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 187 | theorems is as follows: | 
| 42908 | 188 | |
| 189 |   \begin{itemize}
 | |
| 190 | ||
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 191 |   \item Theorems of the form @{text "A \<le> B \<Longrightarrow> \<M> A \<le> \<M> B"}, for proving
 | 
| 42908 | 192 | monotonicity of inductive definitions whose introduction rules have | 
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 193 |   premises involving terms such as @{text "\<M> R t"}.
 | 
| 42908 | 194 | |
| 195 | \item Monotonicity theorems for logical operators, which are of the | |
| 196 |   general form @{text "(\<dots> \<longrightarrow> \<dots>) \<Longrightarrow> \<dots> (\<dots> \<longrightarrow> \<dots>) \<Longrightarrow> \<dots> \<longrightarrow> \<dots>"}.  For example, in
 | |
| 197 |   the case of the operator @{text "\<or>"}, the corresponding theorem is
 | |
| 198 | \[ | |
| 199 |   \infer{@{text "P\<^sub>1 \<or> P\<^sub>2 \<longrightarrow> Q\<^sub>1 \<or> Q\<^sub>2"}}{@{text "P\<^sub>1 \<longrightarrow> Q\<^sub>1"} & @{text "P\<^sub>2 \<longrightarrow> Q\<^sub>2"}}
 | |
| 200 | \] | |
| 201 | ||
| 202 | \item De Morgan style equations for reasoning about the ``polarity'' | |
| 203 | of expressions, e.g. | |
| 204 | \[ | |
| 205 |   @{prop "\<not> \<not> P \<longleftrightarrow> P"} \qquad\qquad
 | |
| 206 |   @{prop "\<not> (P \<and> Q) \<longleftrightarrow> \<not> P \<or> \<not> Q"}
 | |
| 207 | \] | |
| 208 | ||
| 209 | \item Equations for reducing complex operators to more primitive | |
| 210 | ones whose monotonicity can easily be proved, e.g. | |
| 211 | \[ | |
| 212 |   @{prop "(P \<longrightarrow> Q) \<longleftrightarrow> \<not> P \<or> Q"} \qquad\qquad
 | |
| 213 |   @{prop "Ball A P \<equiv> \<forall>x. x \<in> A \<longrightarrow> P x"}
 | |
| 214 | \] | |
| 215 | ||
| 216 |   \end{itemize}
 | |
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 217 | *} | 
| 42908 | 218 | |
| 42913 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 219 | subsubsection {* Examples *}
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 220 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 221 | text {* The finite powerset operator can be defined inductively like this: *}
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 222 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 223 | inductive_set Fin :: "'a set \<Rightarrow> 'a set set" for A :: "'a set" | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 224 | where | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 225 |   empty: "{} \<in> Fin A"
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 226 | | insert: "a \<in> A \<Longrightarrow> B \<in> Fin A \<Longrightarrow> insert a B \<in> Fin A" | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 227 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 228 | text {* The accessible part of a relation is defined as follows: *}
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 229 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 230 | inductive acc :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool"
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 231 | for r :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<prec>" 50) | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 232 | where acc: "(\<And>y. y \<prec> x \<Longrightarrow> acc r y) \<Longrightarrow> acc r x" | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 233 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 234 | text {* Common logical connectives can be easily characterized as
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 235 | non-recursive inductive definitions with parameters, but without | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 236 | arguments. *} | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 237 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 238 | inductive AND for A B :: bool | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 239 | where "A \<Longrightarrow> B \<Longrightarrow> AND A B" | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 240 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 241 | inductive OR for A B :: bool | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 242 | where "A \<Longrightarrow> OR A B" | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 243 | | "B \<Longrightarrow> OR A B" | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 244 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 245 | inductive EXISTS for B :: "'a \<Rightarrow> bool" | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 246 | where "B a \<Longrightarrow> EXISTS B" | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 247 | |
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 248 | text {* Here the @{text "cases"} or @{text "induct"} rules produced by
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 249 |   the @{command inductive} package coincide with the expected
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 250 | elimination rules for Natural Deduction. Already in the original | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 251 |   article by Gerhard Gentzen \cite{Gentzen:1935} there is a hint that
 | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 252 | each connective can be characterized by its introductions, and the | 
| 
68bc69bdce88
updated and re-unified (co)inductive definitions in HOL;
 wenzelm parents: 
42912diff
changeset | 253 | elimination can be constructed systematically. *} | 
| 42908 | 254 | |
| 255 | ||
| 256 | section {* Recursive functions \label{sec:recursion} *}
 | |
| 257 | ||
| 258 | text {*
 | |
| 259 |   \begin{matharray}{rcl}
 | |
| 260 |     @{command_def (HOL) "primrec"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | |
| 261 |     @{command_def (HOL) "fun"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | |
| 262 |     @{command_def (HOL) "function"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\
 | |
| 263 |     @{command_def (HOL) "termination"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\
 | |
| 54017 
2a3c07f49615
basic documentation for function elimination rules and fun_cases
 krauss parents: 
53982diff
changeset | 264 |     @{command_def (HOL) "fun_cases"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | 
| 42908 | 265 |   \end{matharray}
 | 
| 266 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 267 |   @{rail \<open>
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 268 |     @@{command (HOL) primrec} @{syntax target}? @{syntax "fixes"} @'where' equations
 | 
| 42908 | 269 | ; | 
| 270 |     (@@{command (HOL) fun} | @@{command (HOL) function}) @{syntax target}? functionopts?
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 271 |       @{syntax "fixes"} \<newline> @'where' equations
 | 
| 26849 | 272 | ; | 
| 273 | ||
| 42908 | 274 |     equations: (@{syntax thmdecl}? @{syntax prop} + '|')
 | 
| 26849 | 275 | ; | 
| 42908 | 276 |     functionopts: '(' (('sequential' | 'domintros') + ',') ')'
 | 
| 26849 | 277 | ; | 
| 42908 | 278 |     @@{command (HOL) termination} @{syntax term}?
 | 
| 54017 
2a3c07f49615
basic documentation for function elimination rules and fun_cases
 krauss parents: 
53982diff
changeset | 279 | ; | 
| 
2a3c07f49615
basic documentation for function elimination rules and fun_cases
 krauss parents: 
53982diff
changeset | 280 |     @@{command (HOL) fun_cases} (@{syntax thmdecl}? @{syntax prop} + @'and')
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 281 | \<close>} | 
| 26849 | 282 | |
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 283 |   \begin{description}
 | 
| 42123 | 284 | |
| 42908 | 285 |   \item @{command (HOL) "primrec"} defines primitive recursive
 | 
| 42912 | 286 |   functions over datatypes (see also @{command_ref (HOL) datatype} and
 | 
| 287 |   @{command_ref (HOL) rep_datatype}).  The given @{text equations}
 | |
| 288 | specify reduction rules that are produced by instantiating the | |
| 289 | generic combinator for primitive recursion that is available for | |
| 290 | each datatype. | |
| 291 | ||
| 292 | Each equation needs to be of the form: | |
| 293 | ||
| 294 |   @{text [display] "f x\<^sub>1 \<dots> x\<^sub>m (C y\<^sub>1 \<dots> y\<^sub>k) z\<^sub>1 \<dots> z\<^sub>n = rhs"}
 | |
| 295 | ||
| 296 |   such that @{text C} is a datatype constructor, @{text rhs} contains
 | |
| 297 | only the free variables on the left-hand side (or from the context), | |
| 298 |   and all recursive occurrences of @{text "f"} in @{text "rhs"} are of
 | |
| 299 |   the form @{text "f \<dots> y\<^sub>i \<dots>"} for some @{text i}.  At most one
 | |
| 300 | reduction rule for each constructor can be given. The order does | |
| 301 | not matter. For missing constructors, the function is defined to | |
| 302 | return a default value, but this equation is made difficult to | |
| 303 | access for users. | |
| 304 | ||
| 305 |   The reduction rules are declared as @{attribute simp} by default,
 | |
| 306 |   which enables standard proof methods like @{method simp} and
 | |
| 307 |   @{method auto} to normalize expressions of @{text "f"} applied to
 | |
| 308 | datatype constructions, by simulating symbolic computation via | |
| 309 | rewriting. | |
| 35744 | 310 | |
| 42908 | 311 |   \item @{command (HOL) "function"} defines functions by general
 | 
| 312 | wellfounded recursion. A detailed description with examples can be | |
| 313 |   found in \cite{isabelle-function}. The function is specified by a
 | |
| 314 | set of (possibly conditional) recursive equations with arbitrary | |
| 315 | pattern matching. The command generates proof obligations for the | |
| 316 | completeness and the compatibility of patterns. | |
| 42907 
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
 wenzelm parents: 
42705diff
changeset | 317 | |
| 42908 | 318 | The defined function is considered partial, and the resulting | 
| 319 |   simplification rules (named @{text "f.psimps"}) and induction rule
 | |
| 320 |   (named @{text "f.pinduct"}) are guarded by a generated domain
 | |
| 321 |   predicate @{text "f_dom"}. The @{command (HOL) "termination"}
 | |
| 322 | command can then be used to establish that the function is total. | |
| 42123 | 323 | |
| 42908 | 324 |   \item @{command (HOL) "fun"} is a shorthand notation for ``@{command
 | 
| 325 |   (HOL) "function"}~@{text "(sequential)"}, followed by automated
 | |
| 326 | proof attempts regarding pattern matching and termination. See | |
| 327 |   \cite{isabelle-function} for further details.
 | |
| 42123 | 328 | |
| 42908 | 329 |   \item @{command (HOL) "termination"}~@{text f} commences a
 | 
| 330 |   termination proof for the previously defined function @{text f}.  If
 | |
| 331 | this is omitted, the command refers to the most recent function | |
| 332 | definition. After the proof is closed, the recursive equations and | |
| 333 | the induction principle is established. | |
| 26849 | 334 | |
| 54017 
2a3c07f49615
basic documentation for function elimination rules and fun_cases
 krauss parents: 
53982diff
changeset | 335 |   \item @{command (HOL) "fun_cases"} generates specialized elimination
 | 
| 
2a3c07f49615
basic documentation for function elimination rules and fun_cases
 krauss parents: 
53982diff
changeset | 336 | rules for function equations. It expects one or more function equations | 
| 
2a3c07f49615
basic documentation for function elimination rules and fun_cases
 krauss parents: 
53982diff
changeset | 337 | and produces rules that eliminate the given equalities, following the cases | 
| 
2a3c07f49615
basic documentation for function elimination rules and fun_cases
 krauss parents: 
53982diff
changeset | 338 | given in the function definition. | 
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 339 |   \end{description}
 | 
| 42907 
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
 wenzelm parents: 
42705diff
changeset | 340 | |
| 42908 | 341 |   Recursive definitions introduced by the @{command (HOL) "function"}
 | 
| 42912 | 342 |   command accommodate reasoning by induction (cf.\ @{method induct}):
 | 
| 343 |   rule @{text "f.induct"} refers to a specific induction rule, with
 | |
| 344 | parameters named according to the user-specified equations. Cases | |
| 345 |   are numbered starting from 1.  For @{command (HOL) "primrec"}, the
 | |
| 346 | induction principle coincides with structural recursion on the | |
| 347 | datatype where the recursion is carried out. | |
| 42908 | 348 | |
| 349 | The equations provided by these packages may be referred later as | |
| 350 |   theorem list @{text "f.simps"}, where @{text f} is the (collective)
 | |
| 351 | name of the functions defined. Individual equations may be named | |
| 352 | explicitly as well. | |
| 353 | ||
| 354 |   The @{command (HOL) "function"} command accepts the following
 | |
| 355 | options. | |
| 356 | ||
| 357 |   \begin{description}
 | |
| 358 | ||
| 359 |   \item @{text sequential} enables a preprocessor which disambiguates
 | |
| 360 | overlapping patterns by making them mutually disjoint. Earlier | |
| 361 | equations take precedence over later ones. This allows to give the | |
| 362 | specification in a format very similar to functional programming. | |
| 363 | Note that the resulting simplification and induction rules | |
| 364 | correspond to the transformed specification, not the one given | |
| 365 | originally. This usually means that each equation given by the user | |
| 366 | may result in several theorems. Also note that this automatic | |
| 367 | transformation only works for ML-style datatype patterns. | |
| 368 | ||
| 369 |   \item @{text domintros} enables the automated generation of
 | |
| 370 | introduction rules for the domain predicate. While mostly not | |
| 371 | needed, they can be helpful in some proofs about partial functions. | |
| 372 | ||
| 373 |   \end{description}
 | |
| 26849 | 374 | *} | 
| 375 | ||
| 42912 | 376 | subsubsection {* Example: evaluation of expressions *}
 | 
| 377 | ||
| 378 | text {* Subsequently, we define mutual datatypes for arithmetic and
 | |
| 379 |   boolean expressions, and use @{command primrec} for evaluation
 | |
| 380 | functions that follow the same recursive structure. *} | |
| 381 | ||
| 382 | datatype 'a aexp = | |
| 383 | IF "'a bexp" "'a aexp" "'a aexp" | |
| 384 | | Sum "'a aexp" "'a aexp" | |
| 385 | | Diff "'a aexp" "'a aexp" | |
| 386 | | Var 'a | |
| 387 | | Num nat | |
| 388 | and 'a bexp = | |
| 389 | Less "'a aexp" "'a aexp" | |
| 390 | | And "'a bexp" "'a bexp" | |
| 391 | | Neg "'a bexp" | |
| 392 | ||
| 393 | ||
| 394 | text {* \medskip Evaluation of arithmetic and boolean expressions *}
 | |
| 395 | ||
| 396 | primrec evala :: "('a \<Rightarrow> nat) \<Rightarrow> 'a aexp \<Rightarrow> nat"
 | |
| 397 |   and evalb :: "('a \<Rightarrow> nat) \<Rightarrow> 'a bexp \<Rightarrow> bool"
 | |
| 398 | where | |
| 399 | "evala env (IF b a1 a2) = (if evalb env b then evala env a1 else evala env a2)" | |
| 400 | | "evala env (Sum a1 a2) = evala env a1 + evala env a2" | |
| 401 | | "evala env (Diff a1 a2) = evala env a1 - evala env a2" | |
| 402 | | "evala env (Var v) = env v" | |
| 403 | | "evala env (Num n) = n" | |
| 404 | | "evalb env (Less a1 a2) = (evala env a1 < evala env a2)" | |
| 405 | | "evalb env (And b1 b2) = (evalb env b1 \<and> evalb env b2)" | |
| 406 | | "evalb env (Neg b) = (\<not> evalb env b)" | |
| 407 | ||
| 408 | text {* Since the value of an expression depends on the value of its
 | |
| 409 |   variables, the functions @{const evala} and @{const evalb} take an
 | |
| 410 |   additional parameter, an \emph{environment} that maps variables to
 | |
| 411 | their values. | |
| 412 | ||
| 413 | \medskip Substitution on expressions can be defined similarly. The | |
| 414 |   mapping @{text f} of type @{typ "'a \<Rightarrow> 'a aexp"} given as a
 | |
| 415 |   parameter is lifted canonically on the types @{typ "'a aexp"} and
 | |
| 416 |   @{typ "'a bexp"}, respectively.
 | |
| 417 | *} | |
| 418 | ||
| 419 | primrec substa :: "('a \<Rightarrow> 'b aexp) \<Rightarrow> 'a aexp \<Rightarrow> 'b aexp"
 | |
| 420 |   and substb :: "('a \<Rightarrow> 'b aexp) \<Rightarrow> 'a bexp \<Rightarrow> 'b bexp"
 | |
| 421 | where | |
| 422 | "substa f (IF b a1 a2) = IF (substb f b) (substa f a1) (substa f a2)" | |
| 423 | | "substa f (Sum a1 a2) = Sum (substa f a1) (substa f a2)" | |
| 424 | | "substa f (Diff a1 a2) = Diff (substa f a1) (substa f a2)" | |
| 425 | | "substa f (Var v) = f v" | |
| 426 | | "substa f (Num n) = Num n" | |
| 427 | | "substb f (Less a1 a2) = Less (substa f a1) (substa f a2)" | |
| 428 | | "substb f (And b1 b2) = And (substb f b1) (substb f b2)" | |
| 429 | | "substb f (Neg b) = Neg (substb f b)" | |
| 430 | ||
| 431 | text {* In textbooks about semantics one often finds substitution
 | |
| 432 | theorems, which express the relationship between substitution and | |
| 433 |   evaluation.  For @{typ "'a aexp"} and @{typ "'a bexp"}, we can prove
 | |
| 434 | such a theorem by mutual induction, followed by simplification. | |
| 435 | *} | |
| 436 | ||
| 437 | lemma subst_one: | |
| 438 | "evala env (substa (Var (v := a')) a) = evala (env (v := evala env a')) a" | |
| 439 | "evalb env (substb (Var (v := a')) b) = evalb (env (v := evala env a')) b" | |
| 440 | by (induct a and b) simp_all | |
| 441 | ||
| 442 | lemma subst_all: | |
| 443 | "evala env (substa s a) = evala (\<lambda>x. evala env (s x)) a" | |
| 444 | "evalb env (substb s b) = evalb (\<lambda>x. evala env (s x)) b" | |
| 445 | by (induct a and b) simp_all | |
| 446 | ||
| 447 | ||
| 448 | subsubsection {* Example: a substitution function for terms *}
 | |
| 449 | ||
| 450 | text {* Functions on datatypes with nested recursion are also defined
 | |
| 451 | by mutual primitive recursion. *} | |
| 452 | ||
| 453 | datatype ('a, 'b) "term" = Var 'a | App 'b "('a, 'b) term list"
 | |
| 454 | ||
| 455 | text {* A substitution function on type @{typ "('a, 'b) term"} can be
 | |
| 456 |   defined as follows, by working simultaneously on @{typ "('a, 'b)
 | |
| 457 | term list"}: *} | |
| 458 | ||
| 459 | primrec subst_term :: "('a \<Rightarrow> ('a, 'b) term) \<Rightarrow> ('a, 'b) term \<Rightarrow> ('a, 'b) term" and
 | |
| 460 |   subst_term_list :: "('a \<Rightarrow> ('a, 'b) term) \<Rightarrow> ('a, 'b) term list \<Rightarrow> ('a, 'b) term list"
 | |
| 461 | where | |
| 462 | "subst_term f (Var a) = f a" | |
| 463 | | "subst_term f (App b ts) = App b (subst_term_list f ts)" | |
| 464 | | "subst_term_list f [] = []" | |
| 465 | | "subst_term_list f (t # ts) = subst_term f t # subst_term_list f ts" | |
| 466 | ||
| 467 | text {* The recursion scheme follows the structure of the unfolded
 | |
| 468 |   definition of type @{typ "('a, 'b) term"}.  To prove properties of this
 | |
| 469 | substitution function, mutual induction is needed: | |
| 470 | *} | |
| 471 | ||
| 472 | lemma "subst_term (subst_term f1 \<circ> f2) t = subst_term f1 (subst_term f2 t)" and | |
| 473 | "subst_term_list (subst_term f1 \<circ> f2) ts = subst_term_list f1 (subst_term_list f2 ts)" | |
| 474 | by (induct t and ts) simp_all | |
| 475 | ||
| 476 | ||
| 477 | subsubsection {* Example: a map function for infinitely branching trees *}
 | |
| 478 | ||
| 479 | text {* Defining functions on infinitely branching datatypes by
 | |
| 480 | primitive recursion is just as easy. | |
| 481 | *} | |
| 482 | ||
| 483 | datatype 'a tree = Atom 'a | Branch "nat \<Rightarrow> 'a tree" | |
| 484 | ||
| 485 | primrec map_tree :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a tree \<Rightarrow> 'b tree"
 | |
| 486 | where | |
| 487 | "map_tree f (Atom a) = Atom (f a)" | |
| 488 | | "map_tree f (Branch ts) = Branch (\<lambda>x. map_tree f (ts x))" | |
| 489 | ||
| 490 | text {* Note that all occurrences of functions such as @{text ts}
 | |
| 491 |   above must be applied to an argument.  In particular, @{term
 | |
| 492 | "map_tree f \<circ> ts"} is not allowed here. *} | |
| 493 | ||
| 494 | text {* Here is a simple composition lemma for @{term map_tree}: *}
 | |
| 495 | ||
| 496 | lemma "map_tree g (map_tree f t) = map_tree (g \<circ> f) t" | |
| 497 | by (induct t) simp_all | |
| 498 | ||
| 42907 
dfd4ef8e73f6
updated and re-unified HOL typedef, with some live examples;
 wenzelm parents: 
42705diff
changeset | 499 | |
| 42908 | 500 | subsection {* Proof methods related to recursive definitions *}
 | 
| 26849 | 501 | |
| 502 | text {*
 | |
| 503 |   \begin{matharray}{rcl}
 | |
| 42908 | 504 |     @{method_def (HOL) pat_completeness} & : & @{text method} \\
 | 
| 505 |     @{method_def (HOL) relation} & : & @{text method} \\
 | |
| 506 |     @{method_def (HOL) lexicographic_order} & : & @{text method} \\
 | |
| 507 |     @{method_def (HOL) size_change} & : & @{text method} \\
 | |
| 45944 
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
 bulwahn parents: 
45943diff
changeset | 508 |     @{method_def (HOL) induction_schema} & : & @{text method} \\
 | 
| 26849 | 509 |   \end{matharray}
 | 
| 510 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 511 |   @{rail \<open>
 | 
| 42908 | 512 |     @@{method (HOL) relation} @{syntax term}
 | 
| 513 | ; | |
| 514 |     @@{method (HOL) lexicographic_order} (@{syntax clasimpmod} * )
 | |
| 515 | ; | |
| 516 |     @@{method (HOL) size_change} ( orders (@{syntax clasimpmod} * ) )
 | |
| 517 | ; | |
| 45944 
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
 bulwahn parents: 
45943diff
changeset | 518 |     @@{method (HOL) induction_schema}
 | 
| 
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
 bulwahn parents: 
45943diff
changeset | 519 | ; | 
| 42908 | 520 | orders: ( 'max' | 'min' | 'ms' ) * | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 521 | \<close>} | 
| 42908 | 522 | |
| 523 |   \begin{description}
 | |
| 524 | ||
| 525 |   \item @{method (HOL) pat_completeness} is a specialized method to
 | |
| 526 | solve goals regarding the completeness of pattern matching, as | |
| 527 |   required by the @{command (HOL) "function"} package (cf.\
 | |
| 528 |   \cite{isabelle-function}).
 | |
| 529 | ||
| 530 |   \item @{method (HOL) relation}~@{text R} introduces a termination
 | |
| 531 |   proof using the relation @{text R}.  The resulting proof state will
 | |
| 532 |   contain goals expressing that @{text R} is wellfounded, and that the
 | |
| 533 |   arguments of recursive calls decrease with respect to @{text R}.
 | |
| 534 | Usually, this method is used as the initial proof step of manual | |
| 535 | termination proofs. | |
| 536 | ||
| 537 |   \item @{method (HOL) "lexicographic_order"} attempts a fully
 | |
| 538 | automated termination proof by searching for a lexicographic | |
| 539 | combination of size measures on the arguments of the function. The | |
| 540 |   method accepts the same arguments as the @{method auto} method,
 | |
| 42930 | 541 |   which it uses internally to prove local descents.  The @{syntax
 | 
| 542 |   clasimpmod} modifiers are accepted (as for @{method auto}).
 | |
| 42908 | 543 | |
| 544 | In case of failure, extensive information is printed, which can help | |
| 545 |   to analyse the situation (cf.\ \cite{isabelle-function}).
 | |
| 546 | ||
| 547 |   \item @{method (HOL) "size_change"} also works on termination goals,
 | |
| 548 | using a variation of the size-change principle, together with a | |
| 549 |   graph decomposition technique (see \cite{krauss_phd} for details).
 | |
| 550 |   Three kinds of orders are used internally: @{text max}, @{text min},
 | |
| 551 |   and @{text ms} (multiset), which is only available when the theory
 | |
| 552 |   @{text Multiset} is loaded. When no order kinds are given, they are
 | |
| 553 | tried in order. The search for a termination proof uses SAT solving | |
| 554 | internally. | |
| 555 | ||
| 42930 | 556 |   For local descent proofs, the @{syntax clasimpmod} modifiers are
 | 
| 557 |   accepted (as for @{method auto}).
 | |
| 42908 | 558 | |
| 45944 
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
 bulwahn parents: 
45943diff
changeset | 559 |   \item @{method (HOL) induction_schema} derives user-specified
 | 
| 46283 | 560 | induction rules from well-founded induction and completeness of | 
| 561 | patterns. This factors out some operations that are done internally | |
| 562 | by the function package and makes them available separately. See | |
| 563 |   @{file "~~/src/HOL/ex/Induction_Schema.thy"} for examples.
 | |
| 45944 
e586f6d136b7
added some basic documentation about method induction_schema extracted from old NEWS
 bulwahn parents: 
45943diff
changeset | 564 | |
| 42908 | 565 |   \end{description}
 | 
| 566 | *} | |
| 567 | ||
| 568 | ||
| 569 | subsection {* Functions with explicit partiality *}
 | |
| 570 | ||
| 571 | text {*
 | |
| 572 |   \begin{matharray}{rcl}
 | |
| 573 |     @{command_def (HOL) "partial_function"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | |
| 574 |     @{attribute_def (HOL) "partial_function_mono"} & : & @{text attribute} \\
 | |
| 575 |   \end{matharray}
 | |
| 576 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 577 |   @{rail \<open>
 | 
| 42908 | 578 |     @@{command (HOL) partial_function} @{syntax target}?
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 579 |       '(' @{syntax nameref} ')' @{syntax "fixes"} \<newline>
 | 
| 42908 | 580 |       @'where' @{syntax thmdecl}? @{syntax prop}
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 581 | \<close>} | 
| 26849 | 582 | |
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 583 |   \begin{description}
 | 
| 42123 | 584 | |
| 42908 | 585 |   \item @{command (HOL) "partial_function"}~@{text "(mode)"} defines
 | 
| 586 | recursive functions based on fixpoints in complete partial | |
| 587 | orders. No termination proof is required from the user or | |
| 588 | constructed internally. Instead, the possibility of non-termination | |
| 589 | is modelled explicitly in the result type, which contains an | |
| 590 | explicit bottom element. | |
| 591 | ||
| 592 | Pattern matching and mutual recursion are currently not supported. | |
| 593 | Thus, the specification consists of a single function described by a | |
| 594 | single recursive equation. | |
| 595 | ||
| 596 | There are no fixed syntactic restrictions on the body of the | |
| 597 | function, but the induced functional must be provably monotonic | |
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 598 | wrt.\ the underlying order. The monotonicity proof is performed | 
| 42908 | 599 | internally, and the definition is rejected when it fails. The proof | 
| 600 | can be influenced by declaring hints using the | |
| 601 |   @{attribute (HOL) partial_function_mono} attribute.
 | |
| 602 | ||
| 603 |   The mandatory @{text mode} argument specifies the mode of operation
 | |
| 604 | of the command, which directly corresponds to a complete partial | |
| 605 | order on the result type. By default, the following modes are | |
| 606 | defined: | |
| 26849 | 607 | |
| 42908 | 608 |   \begin{description}
 | 
| 46283 | 609 | |
| 42908 | 610 |   \item @{text option} defines functions that map into the @{type
 | 
| 611 |   option} type. Here, the value @{term None} is used to model a
 | |
| 612 |   non-terminating computation. Monotonicity requires that if @{term
 | |
| 46283 | 613 | None} is returned by a recursive call, then the overall result must | 
| 614 |   also be @{term None}. This is best achieved through the use of the
 | |
| 615 |   monadic operator @{const "Option.bind"}.
 | |
| 42908 | 616 | |
| 617 |   \item @{text tailrec} defines functions with an arbitrary result
 | |
| 618 |   type and uses the slightly degenerated partial order where @{term
 | |
| 619 | "undefined"} is the bottom element. Now, monotonicity requires that | |
| 620 |   if @{term undefined} is returned by a recursive call, then the
 | |
| 621 |   overall result must also be @{term undefined}. In practice, this is
 | |
| 622 | only satisfied when each recursive call is a tail call, whose result | |
| 623 | is directly returned. Thus, this mode of operation allows the | |
| 624 | definition of arbitrary tail-recursive functions. | |
| 46283 | 625 | |
| 42908 | 626 |   \end{description}
 | 
| 627 | ||
| 628 | Experienced users may define new modes by instantiating the locale | |
| 629 |   @{const "partial_function_definitions"} appropriately.
 | |
| 630 | ||
| 631 |   \item @{attribute (HOL) partial_function_mono} declares rules for
 | |
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 632 | use in the internal monotonicity proofs of partial function | 
| 42908 | 633 | definitions. | 
| 26849 | 634 | |
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 635 |   \end{description}
 | 
| 42908 | 636 | |
| 637 | *} | |
| 638 | ||
| 639 | ||
| 640 | subsection {* Old-style recursive function definitions (TFL) *}
 | |
| 641 | ||
| 642 | text {*
 | |
| 643 |   \begin{matharray}{rcl}
 | |
| 644 |     @{command_def (HOL) "recdef"} & : & @{text "theory \<rightarrow> theory)"} \\
 | |
| 645 |     @{command_def (HOL) "recdef_tc"}@{text "\<^sup>*"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
 | |
| 646 |   \end{matharray}
 | |
| 647 | ||
| 46280 | 648 |   The old TFL commands @{command (HOL) "recdef"} and @{command (HOL)
 | 
| 649 |   "recdef_tc"} for defining recursive are mostly obsolete; @{command
 | |
| 650 |   (HOL) "function"} or @{command (HOL) "fun"} should be used instead.
 | |
| 651 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 652 |   @{rail \<open>
 | 
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 653 |     @@{command (HOL) recdef} ('(' @'permissive' ')')? \<newline>
 | 
| 42908 | 654 |       @{syntax name} @{syntax term} (@{syntax prop} +) hints?
 | 
| 655 | ; | |
| 656 |     recdeftc @{syntax thmdecl}? tc
 | |
| 657 | ; | |
| 658 |     hints: '(' @'hints' ( recdefmod * ) ')'
 | |
| 659 | ; | |
| 660 |     recdefmod: (('recdef_simp' | 'recdef_cong' | 'recdef_wf')
 | |
| 661 |       (() | 'add' | 'del') ':' @{syntax thmrefs}) | @{syntax clasimpmod}
 | |
| 662 | ; | |
| 663 |     tc: @{syntax nameref} ('(' @{syntax nat} ')')?
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 664 | \<close>} | 
| 42908 | 665 | |
| 666 |   \begin{description}
 | |
| 667 | ||
| 668 |   \item @{command (HOL) "recdef"} defines general well-founded
 | |
| 669 | recursive functions (using the TFL package), see also | |
| 670 |   \cite{isabelle-HOL}.  The ``@{text "(permissive)"}'' option tells
 | |
| 671 | TFL to recover from failed proof attempts, returning unfinished | |
| 672 |   results.  The @{text recdef_simp}, @{text recdef_cong}, and @{text
 | |
| 673 | recdef_wf} hints refer to auxiliary rules to be used in the internal | |
| 674 |   automated proof process of TFL.  Additional @{syntax clasimpmod}
 | |
| 42930 | 675 | declarations may be given to tune the context of the Simplifier | 
| 676 |   (cf.\ \secref{sec:simplifier}) and Classical reasoner (cf.\
 | |
| 677 |   \secref{sec:classical}).
 | |
| 42908 | 678 | |
| 679 |   \item @{command (HOL) "recdef_tc"}~@{text "c (i)"} recommences the
 | |
| 680 |   proof for leftover termination condition number @{text i} (default
 | |
| 681 |   1) as generated by a @{command (HOL) "recdef"} definition of
 | |
| 682 |   constant @{text c}.
 | |
| 683 | ||
| 684 |   Note that in most cases, @{command (HOL) "recdef"} is able to finish
 | |
| 685 | its internal proofs without manual intervention. | |
| 686 | ||
| 687 |   \end{description}
 | |
| 688 | ||
| 689 |   \medskip Hints for @{command (HOL) "recdef"} may be also declared
 | |
| 690 | globally, using the following attributes. | |
| 691 | ||
| 692 |   \begin{matharray}{rcl}
 | |
| 693 |     @{attribute_def (HOL) recdef_simp} & : & @{text attribute} \\
 | |
| 694 |     @{attribute_def (HOL) recdef_cong} & : & @{text attribute} \\
 | |
| 695 |     @{attribute_def (HOL) recdef_wf} & : & @{text attribute} \\
 | |
| 696 |   \end{matharray}
 | |
| 697 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 698 |   @{rail \<open>
 | 
| 42908 | 699 |     (@@{attribute (HOL) recdef_simp} | @@{attribute (HOL) recdef_cong} |
 | 
| 700 |       @@{attribute (HOL) recdef_wf}) (() | 'add' | 'del')
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 701 | \<close>} | 
| 42908 | 702 | *} | 
| 703 | ||
| 704 | ||
| 705 | section {* Datatypes \label{sec:hol-datatype} *}
 | |
| 706 | ||
| 707 | text {*
 | |
| 708 |   \begin{matharray}{rcl}
 | |
| 709 |     @{command_def (HOL) "datatype"} & : & @{text "theory \<rightarrow> theory"} \\
 | |
| 710 |     @{command_def (HOL) "rep_datatype"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
 | |
| 711 |   \end{matharray}
 | |
| 712 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 713 |   @{rail \<open>
 | 
| 42908 | 714 |     @@{command (HOL) datatype} (spec + @'and')
 | 
| 715 | ; | |
| 716 |     @@{command (HOL) rep_datatype} ('(' (@{syntax name} +) ')')? (@{syntax term} +)
 | |
| 717 | ; | |
| 718 | ||
| 45839 
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
 wenzelm parents: 
45768diff
changeset | 719 |     spec: @{syntax typespec_sorts} @{syntax mixfix}? '=' (cons + '|')
 | 
| 42908 | 720 | ; | 
| 721 |     cons: @{syntax name} (@{syntax type} * ) @{syntax mixfix}?
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 722 | \<close>} | 
| 42908 | 723 | |
| 724 |   \begin{description}
 | |
| 725 | ||
| 726 |   \item @{command (HOL) "datatype"} defines inductive datatypes in
 | |
| 727 | HOL. | |
| 728 | ||
| 729 |   \item @{command (HOL) "rep_datatype"} represents existing types as
 | |
| 42909 | 730 | datatypes. | 
| 731 | ||
| 732 |   For foundational reasons, some basic types such as @{typ nat}, @{typ
 | |
| 733 |   "'a \<times> 'b"}, @{typ "'a + 'b"}, @{typ bool} and @{typ unit} are
 | |
| 734 |   introduced by more primitive means using @{command_ref typedef}.  To
 | |
| 735 |   recover the rich infrastructure of @{command datatype} (e.g.\ rules
 | |
| 736 |   for @{method cases} and @{method induct} and the primitive recursion
 | |
| 737 | combinators), such types may be represented as actual datatypes | |
| 738 | later. This is done by specifying the constructors of the desired | |
| 739 | type, and giving a proof of the induction rule, distinctness and | |
| 740 | injectivity of constructors. | |
| 741 | ||
| 742 |   For example, see @{file "~~/src/HOL/Sum_Type.thy"} for the
 | |
| 743 | representation of the primitive sum type as fully-featured datatype. | |
| 42908 | 744 | |
| 745 |   \end{description}
 | |
| 746 | ||
| 42909 | 747 |   The generated rules for @{method induct} and @{method cases} provide
 | 
| 748 | case names according to the given constructors, while parameters are | |
| 749 |   named after the types (see also \secref{sec:cases-induct}).
 | |
| 42908 | 750 | |
| 751 |   See \cite{isabelle-HOL} for more details on datatypes, but beware of
 | |
| 752 | the old-style theory syntax being used there! Apart from proper | |
| 753 | proof methods for case-analysis and induction, there are also | |
| 754 |   emulations of ML tactics @{method (HOL) case_tac} and @{method (HOL)
 | |
| 755 |   induct_tac} available, see \secref{sec:hol-induct-tac}; these admit
 | |
| 756 | to refer directly to the internal structure of subgoals (including | |
| 757 | internally bound parameters). | |
| 26849 | 758 | *} | 
| 759 | ||
| 760 | ||
| 42910 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 761 | subsubsection {* Examples *}
 | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 762 | |
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 763 | text {* We define a type of finite sequences, with slightly different
 | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 764 |   names than the existing @{typ "'a list"} that is already in @{theory
 | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 765 | Main}: *} | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 766 | |
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 767 | datatype 'a seq = Empty | Seq 'a "'a seq" | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 768 | |
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 769 | text {* We can now prove some simple lemma by structural induction: *}
 | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 770 | |
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 771 | lemma "Seq x xs \<noteq> xs" | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 772 | proof (induct xs arbitrary: x) | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 773 | case Empty | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 774 |   txt {* This case can be proved using the simplifier: the freeness
 | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 775 |     properties of the datatype are already declared as @{attribute
 | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 776 | simp} rules. *} | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 777 | show "Seq x Empty \<noteq> Empty" | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 778 | by simp | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 779 | next | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 780 | case (Seq y ys) | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 781 |   txt {* The step case is proved similarly. *}
 | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 782 | show "Seq x (Seq y ys) \<noteq> Seq y ys" | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 783 | using `Seq y ys \<noteq> ys` by simp | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 784 | qed | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 785 | |
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 786 | text {* Here is a more succinct version of the same proof: *}
 | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 787 | |
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 788 | lemma "Seq x xs \<noteq> xs" | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 789 | by (induct xs arbitrary: x) simp_all | 
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 790 | |
| 
6834af822a8b
updated and simplified HOL datatype examples (NB: special treatment of distinctness has been discontinued in the vicinity of 542b34b178ec);
 wenzelm parents: 
42909diff
changeset | 791 | |
| 26849 | 792 | section {* Records \label{sec:hol-record} *}
 | 
| 793 | ||
| 794 | text {*
 | |
| 795 | In principle, records merely generalize the concept of tuples, where | |
| 796 | components may be addressed by labels instead of just position. The | |
| 797 | logical infrastructure of records in Isabelle/HOL is slightly more | |
| 798 | advanced, though, supporting truly extensible record schemes. This | |
| 799 | admits operations that are polymorphic with respect to record | |
| 800 | extension, yielding ``object-oriented'' effects like (single) | |
| 801 |   inheritance.  See also \cite{NaraschewskiW-TPHOLs98} for more
 | |
| 802 | details on object-oriented verification and record subtyping in HOL. | |
| 803 | *} | |
| 804 | ||
| 805 | ||
| 806 | subsection {* Basic concepts *}
 | |
| 807 | ||
| 808 | text {*
 | |
| 809 |   Isabelle/HOL supports both \emph{fixed} and \emph{schematic} records
 | |
| 810 | at the level of terms and types. The notation is as follows: | |
| 811 | ||
| 812 |   \begin{center}
 | |
| 813 |   \begin{tabular}{l|l|l}
 | |
| 814 | & record terms & record types \\ \hline | |
| 815 |     fixed & @{text "\<lparr>x = a, y = b\<rparr>"} & @{text "\<lparr>x :: A, y :: B\<rparr>"} \\
 | |
| 816 |     schematic & @{text "\<lparr>x = a, y = b, \<dots> = m\<rparr>"} &
 | |
| 817 |       @{text "\<lparr>x :: A, y :: B, \<dots> :: M\<rparr>"} \\
 | |
| 818 |   \end{tabular}
 | |
| 819 |   \end{center}
 | |
| 820 | ||
| 821 |   \noindent The ASCII representation of @{text "\<lparr>x = a\<rparr>"} is @{text
 | |
| 822 | "(| x = a |)"}. | |
| 823 | ||
| 824 |   A fixed record @{text "\<lparr>x = a, y = b\<rparr>"} has field @{text x} of value
 | |
| 825 |   @{text a} and field @{text y} of value @{text b}.  The corresponding
 | |
| 826 |   type is @{text "\<lparr>x :: A, y :: B\<rparr>"}, assuming that @{text "a :: A"}
 | |
| 827 |   and @{text "b :: B"}.
 | |
| 828 | ||
| 829 |   A record scheme like @{text "\<lparr>x = a, y = b, \<dots> = m\<rparr>"} contains fields
 | |
| 830 |   @{text x} and @{text y} as before, but also possibly further fields
 | |
| 831 |   as indicated by the ``@{text "\<dots>"}'' notation (which is actually part
 | |
| 832 |   of the syntax).  The improper field ``@{text "\<dots>"}'' of a record
 | |
| 833 |   scheme is called the \emph{more part}.  Logically it is just a free
 | |
| 834 | variable, which is occasionally referred to as ``row variable'' in | |
| 835 | the literature. The more part of a record scheme may be | |
| 836 | instantiated by zero or more further components. For example, the | |
| 837 |   previous scheme may get instantiated to @{text "\<lparr>x = a, y = b, z =
 | |
| 26852 | 838 |   c, \<dots> = m'\<rparr>"}, where @{text m'} refers to a different more part.
 | 
| 26849 | 839 | Fixed records are special instances of record schemes, where | 
| 840 |   ``@{text "\<dots>"}'' is properly terminated by the @{text "() :: unit"}
 | |
| 841 |   element.  In fact, @{text "\<lparr>x = a, y = b\<rparr>"} is just an abbreviation
 | |
| 842 |   for @{text "\<lparr>x = a, y = b, \<dots> = ()\<rparr>"}.
 | |
| 42123 | 843 | |
| 26849 | 844 | \medskip Two key observations make extensible records in a simply | 
| 845 | typed language like HOL work out: | |
| 846 | ||
| 847 |   \begin{enumerate}
 | |
| 848 | ||
| 849 | \item the more part is internalized, as a free term or type | |
| 850 | variable, | |
| 851 | ||
| 26852 | 852 | \item field names are externalized, they cannot be accessed within | 
| 853 | the logic as first-class values. | |
| 26849 | 854 | |
| 855 |   \end{enumerate}
 | |
| 856 | ||
| 857 | \medskip In Isabelle/HOL record types have to be defined explicitly, | |
| 858 | fixing their field names and types, and their (optional) parent | |
| 859 | record. Afterwards, records may be formed using above syntax, while | |
| 860 | obeying the canonical order of fields as given by their declaration. | |
| 861 | The record package provides several standard operations like | |
| 862 | selectors and updates. The common setup for various generic proof | |
| 863 | tools enable succinct reasoning patterns. See also the Isabelle/HOL | |
| 864 |   tutorial \cite{isabelle-hol-book} for further instructions on using
 | |
| 865 | records in practice. | |
| 866 | *} | |
| 867 | ||
| 868 | ||
| 869 | subsection {* Record specifications *}
 | |
| 870 | ||
| 871 | text {*
 | |
| 872 |   \begin{matharray}{rcl}
 | |
| 28761 
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
 wenzelm parents: 
28760diff
changeset | 873 |     @{command_def (HOL) "record"} & : & @{text "theory \<rightarrow> theory"} \\
 | 
| 26849 | 874 |   \end{matharray}
 | 
| 875 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 876 |   @{rail \<open>
 | 
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 877 |     @@{command (HOL) record} @{syntax typespec_sorts} '=' \<newline>
 | 
| 46494 
ea2ae63336f3
clarified outer syntax "constdecl", which is only local to some rail diagrams;
 wenzelm parents: 
46457diff
changeset | 878 |       (@{syntax type} '+')? (constdecl +)
 | 
| 
ea2ae63336f3
clarified outer syntax "constdecl", which is only local to some rail diagrams;
 wenzelm parents: 
46457diff
changeset | 879 | ; | 
| 
ea2ae63336f3
clarified outer syntax "constdecl", which is only local to some rail diagrams;
 wenzelm parents: 
46457diff
changeset | 880 |     constdecl: @{syntax name} '::' @{syntax type} @{syntax mixfix}?
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 881 | \<close>} | 
| 26849 | 882 | |
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 883 |   \begin{description}
 | 
| 26849 | 884 | |
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 885 |   \item @{command (HOL) "record"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t = \<tau> + c\<^sub>1 :: \<sigma>\<^sub>1
 | 
| 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 886 |   \<dots> c\<^sub>n :: \<sigma>\<^sub>n"} defines extensible record type @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"},
 | 
| 26849 | 887 |   derived from the optional parent record @{text "\<tau>"} by adding new
 | 
| 888 |   field components @{text "c\<^sub>i :: \<sigma>\<^sub>i"} etc.
 | |
| 889 | ||
| 890 |   The type variables of @{text "\<tau>"} and @{text "\<sigma>\<^sub>i"} need to be
 | |
| 891 |   covered by the (distinct) parameters @{text "\<alpha>\<^sub>1, \<dots>,
 | |
| 892 |   \<alpha>\<^sub>m"}.  Type constructor @{text t} has to be new, while @{text
 | |
| 893 | \<tau>} needs to specify an instance of an existing record type. At | |
| 894 |   least one new field @{text "c\<^sub>i"} has to be specified.
 | |
| 895 | Basically, field names need to belong to a unique record. This is | |
| 896 | not a real restriction in practice, since fields are qualified by | |
| 897 | the record name internally. | |
| 898 | ||
| 899 |   The parent record specification @{text \<tau>} is optional; if omitted
 | |
| 900 |   @{text t} becomes a root record.  The hierarchy of all records
 | |
| 901 | declared within a theory context forms a forest structure, i.e.\ a | |
| 902 | set of trees starting with a root record each. There is no way to | |
| 903 | merge multiple parent records! | |
| 904 | ||
| 905 |   For convenience, @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"} is made a
 | |
| 906 |   type abbreviation for the fixed record type @{text "\<lparr>c\<^sub>1 ::
 | |
| 907 |   \<sigma>\<^sub>1, \<dots>, c\<^sub>n :: \<sigma>\<^sub>n\<rparr>"}, likewise is @{text
 | |
| 908 | "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m, \<zeta>) t_scheme"} made an abbreviation for | |
| 909 |   @{text "\<lparr>c\<^sub>1 :: \<sigma>\<^sub>1, \<dots>, c\<^sub>n :: \<sigma>\<^sub>n, \<dots> ::
 | |
| 910 | \<zeta>\<rparr>"}. | |
| 911 | ||
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 912 |   \end{description}
 | 
| 26849 | 913 | *} | 
| 914 | ||
| 915 | ||
| 916 | subsection {* Record operations *}
 | |
| 917 | ||
| 918 | text {*
 | |
| 919 | Any record definition of the form presented above produces certain | |
| 920 | standard operations. Selectors and updates are provided for any | |
| 921 |   field, including the improper one ``@{text more}''.  There are also
 | |
| 922 | cumulative record constructor functions. To simplify the | |
| 923 |   presentation below, we assume for now that @{text "(\<alpha>\<^sub>1, \<dots>,
 | |
| 924 |   \<alpha>\<^sub>m) t"} is a root record with fields @{text "c\<^sub>1 ::
 | |
| 925 | \<sigma>\<^sub>1, \<dots>, c\<^sub>n :: \<sigma>\<^sub>n"}. | |
| 926 | ||
| 927 |   \medskip \textbf{Selectors} and \textbf{updates} are available for
 | |
| 928 |   any field (including ``@{text more}''):
 | |
| 929 | ||
| 930 |   \begin{matharray}{lll}
 | |
| 26852 | 931 |     @{text "c\<^sub>i"} & @{text "::"} & @{text "\<lparr>\<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<sigma>\<^sub>i"} \\
 | 
| 932 |     @{text "c\<^sub>i_update"} & @{text "::"} & @{text "\<sigma>\<^sub>i \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr>"} \\
 | |
| 26849 | 933 |   \end{matharray}
 | 
| 934 | ||
| 935 |   There is special syntax for application of updates: @{text "r\<lparr>x :=
 | |
| 936 |   a\<rparr>"} abbreviates term @{text "x_update a r"}.  Further notation for
 | |
| 937 |   repeated updates is also available: @{text "r\<lparr>x := a\<rparr>\<lparr>y := b\<rparr>\<lparr>z :=
 | |
| 938 |   c\<rparr>"} may be written @{text "r\<lparr>x := a, y := b, z := c\<rparr>"}.  Note that
 | |
| 939 | because of postfix notation the order of fields shown here is | |
| 940 | reverse than in the actual term. Since repeated updates are just | |
| 941 |   function applications, fields may be freely permuted in @{text "\<lparr>x
 | |
| 942 | := a, y := b, z := c\<rparr>"}, as far as logical equality is concerned. | |
| 943 | Thus commutativity of independent updates can be proven within the | |
| 944 | logic for any two fields, but not as a general theorem. | |
| 945 | ||
| 946 |   \medskip The \textbf{make} operation provides a cumulative record
 | |
| 947 | constructor function: | |
| 948 | ||
| 949 |   \begin{matharray}{lll}
 | |
| 26852 | 950 |     @{text "t.make"} & @{text "::"} & @{text "\<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>n \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\
 | 
| 26849 | 951 |   \end{matharray}
 | 
| 952 | ||
| 953 | \medskip We now reconsider the case of non-root records, which are | |
| 954 | derived of some parent. In general, the latter may depend on | |
| 955 |   another parent as well, resulting in a list of \emph{ancestor
 | |
| 956 | records}. Appending the lists of fields of all ancestors results in | |
| 957 | a certain field prefix. The record package automatically takes care | |
| 958 | of this by lifting operations over this context of ancestor fields. | |
| 959 |   Assuming that @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>m) t"} has ancestor
 | |
| 960 |   fields @{text "b\<^sub>1 :: \<rho>\<^sub>1, \<dots>, b\<^sub>k :: \<rho>\<^sub>k"},
 | |
| 961 | the above record operations will get the following types: | |
| 962 | ||
| 26852 | 963 | \medskip | 
| 964 |   \begin{tabular}{lll}
 | |
| 965 |     @{text "c\<^sub>i"} & @{text "::"} & @{text "\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<sigma>\<^sub>i"} \\
 | |
| 42123 | 966 |     @{text "c\<^sub>i_update"} & @{text "::"} & @{text "\<sigma>\<^sub>i \<Rightarrow>
 | 
| 26852 | 967 | \<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> | 
| 968 | \<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr>"} \\ | |
| 969 |     @{text "t.make"} & @{text "::"} & @{text "\<rho>\<^sub>1 \<Rightarrow> \<dots> \<rho>\<^sub>k \<Rightarrow> \<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>n \<Rightarrow>
 | |
| 970 | \<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\ | |
| 971 |   \end{tabular}
 | |
| 972 | \medskip | |
| 26849 | 973 | |
| 26852 | 974 | \noindent Some further operations address the extension aspect of a | 
| 26849 | 975 |   derived record scheme specifically: @{text "t.fields"} produces a
 | 
| 976 | record fragment consisting of exactly the new fields introduced here | |
| 977 |   (the result may serve as a more part elsewhere); @{text "t.extend"}
 | |
| 978 |   takes a fixed record and adds a given more part; @{text
 | |
| 979 | "t.truncate"} restricts a record scheme to a fixed record. | |
| 980 | ||
| 26852 | 981 | \medskip | 
| 982 |   \begin{tabular}{lll}
 | |
| 983 |     @{text "t.fields"} & @{text "::"} & @{text "\<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>n \<Rightarrow> \<lparr>\<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\
 | |
| 984 |     @{text "t.extend"} & @{text "::"} & @{text "\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>\<rparr> \<Rightarrow>
 | |
| 985 | \<zeta> \<Rightarrow> \<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr>"} \\ | |
| 986 |     @{text "t.truncate"} & @{text "::"} & @{text "\<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>, \<dots> :: \<zeta>\<rparr> \<Rightarrow> \<lparr>\<^vec>b :: \<^vec>\<rho>, \<^vec>c :: \<^vec>\<sigma>\<rparr>"} \\
 | |
| 987 |   \end{tabular}
 | |
| 988 | \medskip | |
| 26849 | 989 | |
| 990 |   \noindent Note that @{text "t.make"} and @{text "t.fields"} coincide
 | |
| 991 | for root records. | |
| 992 | *} | |
| 993 | ||
| 994 | ||
| 995 | subsection {* Derived rules and proof tools *}
 | |
| 996 | ||
| 997 | text {*
 | |
| 998 | The record package proves several results internally, declaring | |
| 999 | these facts to appropriate proof tools. This enables users to | |
| 1000 | reason about record structures quite conveniently. Assume that | |
| 1001 |   @{text t} is a record type as specified above.
 | |
| 1002 | ||
| 1003 |   \begin{enumerate}
 | |
| 42123 | 1004 | |
| 26849 | 1005 | \item Standard conversions for selectors or updates applied to | 
| 1006 | record constructor terms are made part of the default Simplifier | |
| 1007 | context; thus proofs by reduction of basic operations merely require | |
| 1008 |   the @{method simp} method without further arguments.  These rules
 | |
| 1009 |   are available as @{text "t.simps"}, too.
 | |
| 42123 | 1010 | |
| 26849 | 1011 | \item Selectors applied to updated records are automatically reduced | 
| 1012 | by an internal simplification procedure, which is also part of the | |
| 1013 | standard Simplifier setup. | |
| 1014 | ||
| 1015 |   \item Inject equations of a form analogous to @{prop "(x, y) = (x',
 | |
| 1016 | y') \<equiv> x = x' \<and> y = y'"} are declared to the Simplifier and Classical | |
| 1017 |   Reasoner as @{attribute iff} rules.  These rules are available as
 | |
| 1018 |   @{text "t.iffs"}.
 | |
| 1019 | ||
| 1020 |   \item The introduction rule for record equality analogous to @{text
 | |
| 1021 | "x r = x r' \<Longrightarrow> y r = y r' \<dots> \<Longrightarrow> r = r'"} is declared to the Simplifier, | |
| 1022 |   and as the basic rule context as ``@{attribute intro}@{text "?"}''.
 | |
| 1023 |   The rule is called @{text "t.equality"}.
 | |
| 1024 | ||
| 1025 | \item Representations of arbitrary record expressions as canonical | |
| 1026 |   constructor terms are provided both in @{method cases} and @{method
 | |
| 1027 | induct} format (cf.\ the generic proof methods of the same name, | |
| 1028 |   \secref{sec:cases-induct}).  Several variations are available, for
 | |
| 1029 | fixed records, record schemes, more parts etc. | |
| 42123 | 1030 | |
| 26849 | 1031 | The generic proof methods are sufficiently smart to pick the most | 
| 1032 | sensible rule according to the type of the indicated record | |
| 1033 |   expression: users just need to apply something like ``@{text "(cases
 | |
| 1034 | r)"}'' to a certain proof problem. | |
| 1035 | ||
| 1036 |   \item The derived record operations @{text "t.make"}, @{text
 | |
| 1037 |   "t.fields"}, @{text "t.extend"}, @{text "t.truncate"} are \emph{not}
 | |
| 1038 | treated automatically, but usually need to be expanded by hand, | |
| 1039 |   using the collective fact @{text "t.defs"}.
 | |
| 1040 | ||
| 1041 |   \end{enumerate}
 | |
| 1042 | *} | |
| 1043 | ||
| 1044 | ||
| 42911 | 1045 | subsubsection {* Examples *}
 | 
| 1046 | ||
| 1047 | text {* See @{file "~~/src/HOL/ex/Records.thy"}, for example. *}
 | |
| 1048 | ||
| 42908 | 1049 | section {* Typedef axiomatization \label{sec:hol-typedef} *}
 | 
| 1050 | ||
| 46280 | 1051 | text {*
 | 
| 1052 |   \begin{matharray}{rcl}
 | |
| 1053 |     @{command_def (HOL) "typedef"} & : & @{text "local_theory \<rightarrow> proof(prove)"} \\
 | |
| 1054 |   \end{matharray}
 | |
| 1055 | ||
| 1056 | A Gordon/HOL-style type definition is a certain axiom scheme that | |
| 1057 | identifies a new type with a subset of an existing type. More | |
| 42908 | 1058 | precisely, the new type is defined by exhibiting an existing type | 
| 1059 |   @{text \<tau>}, a set @{text "A :: \<tau> set"}, and a theorem that proves
 | |
| 1060 |   @{prop "\<exists>x. x \<in> A"}.  Thus @{text A} is a non-empty subset of @{text
 | |
| 1061 | \<tau>}, and the new type denotes this subset. New functions are | |
| 1062 | postulated that establish an isomorphism between the new type and | |
| 1063 |   the subset.  In general, the type @{text \<tau>} may involve type
 | |
| 1064 |   variables @{text "\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n"} which means that the type definition
 | |
| 1065 |   produces a type constructor @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"} depending on
 | |
| 1066 | those type arguments. | |
| 1067 | ||
| 1068 | The axiomatization can be considered a ``definition'' in the sense | |
| 1069 | of the particular set-theoretic interpretation of HOL | |
| 1070 |   \cite{pitts93}, where the universe of types is required to be
 | |
| 1071 | downwards-closed wrt.\ arbitrary non-empty subsets. Thus genuinely | |
| 1072 |   new types introduced by @{command "typedef"} stay within the range
 | |
| 1073 |   of HOL models by construction.  Note that @{command_ref
 | |
| 1074 | type_synonym} from Isabelle/Pure merely introduces syntactic | |
| 1075 | abbreviations, without any logical significance. | |
| 47859 | 1076 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1077 |   @{rail \<open>
 | 
| 49836 
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
 wenzelm parents: 
49834diff
changeset | 1078 |     @@{command (HOL) typedef} abs_type '=' rep_set
 | 
| 26849 | 1079 | ; | 
| 42908 | 1080 |     abs_type: @{syntax typespec_sorts} @{syntax mixfix}?
 | 
| 1081 | ; | |
| 1082 |     rep_set: @{syntax term} (@'morphisms' @{syntax name} @{syntax name})?
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1083 | \<close>} | 
| 26849 | 1084 | |
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 1085 |   \begin{description}
 | 
| 26849 | 1086 | |
| 42908 | 1087 |   \item @{command (HOL) "typedef"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t = A"}
 | 
| 1088 | axiomatizes a type definition in the background theory of the | |
| 1089 | current context, depending on a non-emptiness result of the set | |
| 1090 |   @{text A} that needs to be proven here.  The set @{text A} may
 | |
| 1091 |   contain type variables @{text "\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n"} as specified on the LHS,
 | |
| 1092 | but no term variables. | |
| 1093 | ||
| 1094 | Even though a local theory specification, the newly introduced type | |
| 1095 | constructor cannot depend on parameters or assumptions of the | |
| 1096 | context: this is structurally impossible in HOL. In contrast, the | |
| 1097 | non-emptiness proof may use local assumptions in unusual situations, | |
| 1098 | which could result in different interpretations in target contexts: | |
| 1099 |   the meaning of the bijection between the representing set @{text A}
 | |
| 1100 |   and the new type @{text t} may then change in different application
 | |
| 1101 | contexts. | |
| 1102 | ||
| 49836 
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
 wenzelm parents: 
49834diff
changeset | 1103 |   For @{command (HOL) "typedef"}~@{text "t = A"} the newly introduced
 | 
| 
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
 wenzelm parents: 
49834diff
changeset | 1104 |   type @{text t} is accompanied by a pair of morphisms to relate it to
 | 
| 
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
 wenzelm parents: 
49834diff
changeset | 1105 | the representing set over the old type. By default, the injection | 
| 
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
 wenzelm parents: 
49834diff
changeset | 1106 |   from type to set is called @{text Rep_t} and its inverse @{text
 | 
| 
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
 wenzelm parents: 
49834diff
changeset | 1107 |   Abs_t}: An explicit @{keyword (HOL) "morphisms"} specification
 | 
| 
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
 wenzelm parents: 
49834diff
changeset | 1108 | allows to provide alternative names. | 
| 26849 | 1109 | |
| 42908 | 1110 |   The core axiomatization uses the locale predicate @{const
 | 
| 1111 | type_definition} as defined in Isabelle/HOL. Various basic | |
| 1112 | consequences of that are instantiated accordingly, re-using the | |
| 1113 | locale facts with names derived from the new type constructor. Thus | |
| 1114 |   the generic @{thm type_definition.Rep} is turned into the specific
 | |
| 1115 |   @{text "Rep_t"}, for example.
 | |
| 1116 | ||
| 1117 |   Theorems @{thm type_definition.Rep}, @{thm
 | |
| 1118 |   type_definition.Rep_inverse}, and @{thm type_definition.Abs_inverse}
 | |
| 1119 | provide the most basic characterization as a corresponding | |
| 1120 | injection/surjection pair (in both directions). The derived rules | |
| 1121 |   @{thm type_definition.Rep_inject} and @{thm
 | |
| 1122 | type_definition.Abs_inject} provide a more convenient version of | |
| 1123 | injectivity, suitable for automated proof tools (e.g.\ in | |
| 1124 |   declarations involving @{attribute simp} or @{attribute iff}).
 | |
| 1125 |   Furthermore, the rules @{thm type_definition.Rep_cases}~/ @{thm
 | |
| 1126 |   type_definition.Rep_induct}, and @{thm type_definition.Abs_cases}~/
 | |
| 1127 |   @{thm type_definition.Abs_induct} provide alternative views on
 | |
| 1128 | surjectivity. These rules are already declared as set or type rules | |
| 1129 |   for the generic @{method cases} and @{method induct} methods,
 | |
| 1130 | respectively. | |
| 1131 | ||
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 1132 |   \end{description}
 | 
| 26849 | 1133 | |
| 42908 | 1134 |   \begin{warn}
 | 
| 1135 |   If you introduce a new type axiomatically, i.e.\ via @{command_ref
 | |
| 1136 |   typedecl} and @{command_ref axiomatization}, the minimum requirement
 | |
| 1137 | is that it has a non-empty model, to avoid immediate collapse of the | |
| 1138 | HOL logic. Moreover, one needs to demonstrate that the | |
| 1139 | interpretation of such free-form axiomatizations can coexist with | |
| 1140 |   that of the regular @{command_def typedef} scheme, and any extension
 | |
| 49836 
c13b39542972
simplified 'typedef' specifications: discontinued implicit set definition and alternative name;
 wenzelm parents: 
49834diff
changeset | 1141 | that other people might have introduced elsewhere. | 
| 42908 | 1142 |   \end{warn}
 | 
| 1143 | *} | |
| 1144 | ||
| 1145 | subsubsection {* Examples *}
 | |
| 1146 | ||
| 1147 | text {* Type definitions permit the introduction of abstract data
 | |
| 1148 | types in a safe way, namely by providing models based on already | |
| 1149 |   existing types.  Given some abstract axiomatic description @{text P}
 | |
| 1150 | of a type, this involves two steps: | |
| 1151 | ||
| 1152 |   \begin{enumerate}
 | |
| 1153 | ||
| 1154 |   \item Find an appropriate type @{text \<tau>} and subset @{text A} which
 | |
| 1155 |   has the desired properties @{text P}, and make a type definition
 | |
| 1156 | based on this representation. | |
| 1157 | ||
| 1158 |   \item Prove that @{text P} holds for @{text \<tau>} by lifting @{text P}
 | |
| 1159 | from the representation. | |
| 26849 | 1160 | |
| 42908 | 1161 |   \end{enumerate}
 | 
| 1162 | ||
| 1163 | You can later forget about the representation and work solely in | |
| 1164 |   terms of the abstract properties @{text P}.
 | |
| 1165 | ||
| 1166 | \medskip The following trivial example pulls a three-element type | |
| 1167 | into existence within the formal logical environment of HOL. *} | |
| 1168 | ||
| 49834 | 1169 | typedef three = "{(True, True), (True, False), (False, True)}"
 | 
| 42908 | 1170 | by blast | 
| 1171 | ||
| 1172 | definition "One = Abs_three (True, True)" | |
| 1173 | definition "Two = Abs_three (True, False)" | |
| 1174 | definition "Three = Abs_three (False, True)" | |
| 1175 | ||
| 1176 | lemma three_distinct: "One \<noteq> Two" "One \<noteq> Three" "Two \<noteq> Three" | |
| 49812 
e3945ddcb9aa
eliminated some remaining uses of typedef with implicit set definition;
 wenzelm parents: 
48985diff
changeset | 1177 | by (simp_all add: One_def Two_def Three_def Abs_three_inject) | 
| 42908 | 1178 | |
| 1179 | lemma three_cases: | |
| 1180 | fixes x :: three obtains "x = One" | "x = Two" | "x = Three" | |
| 49812 
e3945ddcb9aa
eliminated some remaining uses of typedef with implicit set definition;
 wenzelm parents: 
48985diff
changeset | 1181 | by (cases x) (auto simp: One_def Two_def Three_def Abs_three_inject) | 
| 42908 | 1182 | |
| 1183 | text {* Note that such trivial constructions are better done with
 | |
| 1184 |   derived specification mechanisms such as @{command datatype}: *}
 | |
| 1185 | ||
| 1186 | datatype three' = One' | Two' | Three' | |
| 1187 | ||
| 1188 | text {* This avoids re-doing basic definitions and proofs from the
 | |
| 1189 |   primitive @{command typedef} above. *}
 | |
| 26849 | 1190 | |
| 1191 | ||
| 50109 | 1192 | |
| 41396 | 1193 | section {* Functorial structure of types *}
 | 
| 1194 | ||
| 1195 | text {*
 | |
| 1196 |   \begin{matharray}{rcl}
 | |
| 55467 
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
 blanchet parents: 
55372diff
changeset | 1197 |     @{command_def (HOL) "functor"} & : & @{text "local_theory \<rightarrow> proof(prove)"}
 | 
| 41396 | 1198 |   \end{matharray}
 | 
| 1199 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1200 |   @{rail \<open>
 | 
| 55467 
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
 blanchet parents: 
55372diff
changeset | 1201 |     @@{command (HOL) functor} (@{syntax name} ':')? @{syntax term}
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1202 | \<close>} | 
| 41396 | 1203 | |
| 1204 |   \begin{description}
 | |
| 1205 | ||
| 55467 
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
 blanchet parents: 
55372diff
changeset | 1206 |   \item @{command (HOL) "functor"}~@{text "prefix: m"} allows to
 | 
| 42617 | 1207 | prove and register properties about the functorial structure of type | 
| 1208 | constructors. These properties then can be used by other packages | |
| 1209 | to deal with those type constructors in certain type constructions. | |
| 1210 | Characteristic theorems are noted in the current local theory. By | |
| 1211 | default, they are prefixed with the base name of the type | |
| 1212 | constructor, an explicit prefix can be given alternatively. | |
| 41396 | 1213 | |
| 1214 |   The given term @{text "m"} is considered as \emph{mapper} for the
 | |
| 1215 | corresponding type constructor and must conform to the following | |
| 1216 | type pattern: | |
| 1217 | ||
| 1218 |   \begin{matharray}{lll}
 | |
| 1219 |     @{text "m"} & @{text "::"} &
 | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1220 |       @{text "\<sigma>\<^sub>1 \<Rightarrow> \<dots> \<sigma>\<^sub>k \<Rightarrow> (\<^vec>\<alpha>\<^sub>n) t \<Rightarrow> (\<^vec>\<beta>\<^sub>n) t"} \\
 | 
| 41396 | 1221 |   \end{matharray}
 | 
| 1222 | ||
| 1223 |   \noindent where @{text t} is the type constructor, @{text
 | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1224 |   "\<^vec>\<alpha>\<^sub>n"} and @{text "\<^vec>\<beta>\<^sub>n"} are distinct
 | 
| 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1225 |   type variables free in the local theory and @{text "\<sigma>\<^sub>1"},
 | 
| 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1226 |   \ldots, @{text "\<sigma>\<^sub>k"} is a subsequence of @{text "\<alpha>\<^sub>1 \<Rightarrow>
 | 
| 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1227 |   \<beta>\<^sub>1"}, @{text "\<beta>\<^sub>1 \<Rightarrow> \<alpha>\<^sub>1"}, \ldots,
 | 
| 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1228 |   @{text "\<alpha>\<^sub>n \<Rightarrow> \<beta>\<^sub>n"}, @{text "\<beta>\<^sub>n \<Rightarrow>
 | 
| 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1229 | \<alpha>\<^sub>n"}. | 
| 41396 | 1230 | |
| 1231 |   \end{description}
 | |
| 1232 | *} | |
| 1233 | ||
| 47859 | 1234 | |
| 50109 | 1235 | section {* Quotient types *}
 | 
| 1236 | ||
| 1237 | text {*
 | |
| 1238 |   \begin{matharray}{rcl}
 | |
| 1239 |     @{command_def (HOL) "quotient_type"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\
 | |
| 1240 |     @{command_def (HOL) "quotient_definition"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\
 | |
| 1241 |     @{command_def (HOL) "print_quotmapsQ3"} & : & @{text "context \<rightarrow>"}\\
 | |
| 1242 |     @{command_def (HOL) "print_quotientsQ3"} & : & @{text "context \<rightarrow>"}\\
 | |
| 1243 |     @{command_def (HOL) "print_quotconsts"} & : & @{text "context \<rightarrow>"}\\
 | |
| 1244 |     @{method_def (HOL) "lifting"} & : & @{text method} \\
 | |
| 1245 |     @{method_def (HOL) "lifting_setup"} & : & @{text method} \\
 | |
| 1246 |     @{method_def (HOL) "descending"} & : & @{text method} \\
 | |
| 1247 |     @{method_def (HOL) "descending_setup"} & : & @{text method} \\
 | |
| 1248 |     @{method_def (HOL) "partiality_descending"} & : & @{text method} \\
 | |
| 1249 |     @{method_def (HOL) "partiality_descending_setup"} & : & @{text method} \\
 | |
| 1250 |     @{method_def (HOL) "regularize"} & : & @{text method} \\
 | |
| 1251 |     @{method_def (HOL) "injection"} & : & @{text method} \\
 | |
| 1252 |     @{method_def (HOL) "cleaning"} & : & @{text method} \\
 | |
| 1253 |     @{attribute_def (HOL) "quot_thm"} & : & @{text attribute} \\
 | |
| 1254 |     @{attribute_def (HOL) "quot_lifted"} & : & @{text attribute} \\
 | |
| 1255 |     @{attribute_def (HOL) "quot_respect"} & : & @{text attribute} \\
 | |
| 1256 |     @{attribute_def (HOL) "quot_preserve"} & : & @{text attribute} \\
 | |
| 1257 |   \end{matharray}
 | |
| 1258 | ||
| 1259 | The quotient package defines a new quotient type given a raw type | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1260 | and a partial equivalence relation. The package also historically | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1261 | includes automation for transporting definitions and theorems. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1262 | But most of this automation was superseded by the Lifting and Transfer | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1263 | packages. The user should consider using these two new packages for | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1264 | lifting definitions and transporting theorems. | 
| 50109 | 1265 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1266 |   @{rail \<open>
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1267 |     @@{command (HOL) quotient_type} (spec)
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1268 | ; | 
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 1269 |     spec: @{syntax typespec} @{syntax mixfix}? '=' \<newline>
 | 
| 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 1270 |      @{syntax type} '/' ('partial' ':')? @{syntax term} \<newline>
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1271 |      (@'morphisms' @{syntax name} @{syntax name})? (@'parametric' @{syntax thmref})?
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1272 | \<close>} | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1273 | |
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1274 |   @{rail \<open>
 | 
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 1275 |     @@{command (HOL) quotient_definition} constdecl? @{syntax thmdecl}? \<newline>
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1276 |     @{syntax term} 'is' @{syntax term}
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1277 | ; | 
| 50109 | 1278 |     constdecl: @{syntax name} ('::' @{syntax type})? @{syntax mixfix}?
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1279 | \<close>} | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1280 | |
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1281 |   @{rail \<open>
 | 
| 50109 | 1282 |     @@{method (HOL) lifting} @{syntax thmrefs}?
 | 
| 1283 | ; | |
| 1284 |     @@{method (HOL) lifting_setup} @{syntax thmrefs}?
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1285 | \<close>} | 
| 50109 | 1286 | |
| 1287 |   \begin{description}
 | |
| 1288 | ||
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1289 |   \item @{command (HOL) "quotient_type"} defines a new quotient type @{text \<tau>}. The
 | 
| 50109 | 1290 |   injection from a quotient type to a raw type is called @{text
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1291 |   rep_\<tau>}, its inverse @{text abs_\<tau>} unless explicit @{keyword (HOL)
 | 
| 50109 | 1292 |   "morphisms"} specification provides alternative names. @{command
 | 
| 1293 | (HOL) "quotient_type"} requires the user to prove that the relation | |
| 1294 |   is an equivalence relation (predicate @{text equivp}), unless the
 | |
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1295 |   user specifies explicitly @{text partial} in which case the
 | 
| 50109 | 1296 |   obligation is @{text part_equivp}.  A quotient defined with @{text
 | 
| 1297 | partial} is weaker in the sense that less things can be proved | |
| 1298 | automatically. | |
| 1299 | ||
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1300 | The command internally proves a Quotient theorem and sets up the Lifting | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1301 |   package by the command @{command (HOL) setup_lifting}. Thus the Lifting 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1302 | and Transfer packages can be used also with quotient types defined by | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1303 |   @{command (HOL) "quotient_type"} without any extra set-up. The parametricity 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1304 | theorem for the equivalence relation R can be provided as an extra argument | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1305 |   of the command and is passed to the corresponding internal call of @{command (HOL) setup_lifting}.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1306 | This theorem allows the Lifting package to generate a stronger transfer rule for equality. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1307 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1308 |   \end{description}
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1309 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1310 | The most of the rest of the package was superseded by the Lifting and Transfer | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1311 | packages. The user should consider using these two new packages for | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1312 | lifting definitions and transporting theorems. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1313 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1314 |   \begin{description}  
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1315 | |
| 50109 | 1316 |   \item @{command (HOL) "quotient_definition"} defines a constant on
 | 
| 1317 | the quotient type. | |
| 1318 | ||
| 1319 |   \item @{command (HOL) "print_quotmapsQ3"} prints quotient map
 | |
| 1320 | functions. | |
| 1321 | ||
| 1322 |   \item @{command (HOL) "print_quotientsQ3"} prints quotients.
 | |
| 1323 | ||
| 1324 |   \item @{command (HOL) "print_quotconsts"} prints quotient constants.
 | |
| 1325 | ||
| 1326 |   \item @{method (HOL) "lifting"} and @{method (HOL) "lifting_setup"}
 | |
| 1327 | methods match the current goal with the given raw theorem to be | |
| 1328 | lifted producing three new subgoals: regularization, injection and | |
| 1329 |     cleaning subgoals. @{method (HOL) "lifting"} tries to apply the
 | |
| 1330 | heuristics for automatically solving these three subgoals and | |
| 1331 | leaves only the subgoals unsolved by the heuristics to the user as | |
| 1332 |     opposed to @{method (HOL) "lifting_setup"} which leaves the three
 | |
| 1333 | subgoals unsolved. | |
| 1334 | ||
| 1335 |   \item @{method (HOL) "descending"} and @{method (HOL)
 | |
| 1336 | "descending_setup"} try to guess a raw statement that would lift | |
| 1337 | to the current subgoal. Such statement is assumed as a new subgoal | |
| 1338 |     and @{method (HOL) "descending"} continues in the same way as
 | |
| 1339 |     @{method (HOL) "lifting"} does. @{method (HOL) "descending"} tries
 | |
| 1340 | to solve the arising regularization, injection and cleaning | |
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1341 |     subgoals with the analogous method @{method (HOL)
 | 
| 50109 | 1342 | "descending_setup"} which leaves the four unsolved subgoals. | 
| 1343 | ||
| 1344 |   \item @{method (HOL) "partiality_descending"} finds the regularized
 | |
| 1345 | theorem that would lift to the current subgoal, lifts it and | |
| 1346 | leaves as a subgoal. This method can be used with partial | |
| 1347 | equivalence quotients where the non regularized statements would | |
| 1348 |     not be true. @{method (HOL) "partiality_descending_setup"} leaves
 | |
| 1349 | the injection and cleaning subgoals unchanged. | |
| 1350 | ||
| 1351 |   \item @{method (HOL) "regularize"} applies the regularization
 | |
| 1352 | heuristics to the current subgoal. | |
| 1353 | ||
| 1354 |   \item @{method (HOL) "injection"} applies the injection heuristics
 | |
| 1355 | to the current goal using the stored quotient respectfulness | |
| 1356 | theorems. | |
| 1357 | ||
| 1358 |   \item @{method (HOL) "cleaning"} applies the injection cleaning
 | |
| 1359 | heuristics to the current subgoal using the stored quotient | |
| 1360 | preservation theorems. | |
| 1361 | ||
| 1362 |   \item @{attribute (HOL) quot_lifted} attribute tries to
 | |
| 1363 | automatically transport the theorem to the quotient type. | |
| 1364 | The attribute uses all the defined quotients types and quotient | |
| 1365 | constants often producing undesired results or theorems that | |
| 1366 | cannot be lifted. | |
| 1367 | ||
| 1368 |   \item @{attribute (HOL) quot_respect} and @{attribute (HOL)
 | |
| 1369 | quot_preserve} attributes declare a theorem as a respectfulness | |
| 1370 | and preservation theorem respectively. These are stored in the | |
| 1371 |     local theory store and used by the @{method (HOL) "injection"}
 | |
| 1372 |     and @{method (HOL) "cleaning"} methods respectively.
 | |
| 1373 | ||
| 1374 |   \item @{attribute (HOL) quot_thm} declares that a certain theorem
 | |
| 1375 | is a quotient extension theorem. Quotient extension theorems | |
| 1376 | allow for quotienting inside container types. Given a polymorphic | |
| 1377 | type that serves as a container, a map function defined for this | |
| 55467 
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
 blanchet parents: 
55372diff
changeset | 1378 |     container using @{command (HOL) "functor"} and a relation
 | 
| 50109 | 1379 | map defined for for the container type, the quotient extension | 
| 1380 |     theorem should be @{term "Quotient3 R Abs Rep \<Longrightarrow> Quotient3
 | |
| 1381 | (rel_map R) (map Abs) (map Rep)"}. Quotient extension theorems | |
| 1382 | are stored in a database and are used all the steps of lifting | |
| 1383 | theorems. | |
| 1384 | ||
| 1385 |   \end{description}
 | |
| 1386 | *} | |
| 1387 | ||
| 1388 | ||
| 1389 | ||
| 1390 | section {* Definition by specification \label{sec:hol-specification} *}
 | |
| 1391 | ||
| 1392 | text {*
 | |
| 1393 |   \begin{matharray}{rcl}
 | |
| 1394 |     @{command_def (HOL) "specification"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
 | |
| 1395 |     @{command_def (HOL) "ax_specification"} & : & @{text "theory \<rightarrow> proof(prove)"} \\
 | |
| 1396 |   \end{matharray}
 | |
| 1397 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1398 |   @{rail \<open>
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1399 |     (@@{command (HOL) specification} | @@{command (HOL) ax_specification})
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1400 |       '(' (decl +) ')' \<newline> (@{syntax thmdecl}? @{syntax prop} +)
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1401 | ; | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1402 |     decl: ((@{syntax name} ':')? @{syntax term} '(' @'overloaded' ')'?)
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1403 | \<close>} | 
| 50109 | 1404 | |
| 1405 |   \begin{description}
 | |
| 1406 | ||
| 1407 |   \item @{command (HOL) "specification"}~@{text "decls \<phi>"} sets up a
 | |
| 1408 | goal stating the existence of terms with the properties specified to | |
| 1409 |   hold for the constants given in @{text decls}.  After finishing the
 | |
| 1410 | proof, the theory will be augmented with definitions for the given | |
| 1411 | constants, as well as with theorems stating the properties for these | |
| 1412 | constants. | |
| 1413 | ||
| 1414 |   \item @{command (HOL) "ax_specification"}~@{text "decls \<phi>"} sets up
 | |
| 1415 | a goal stating the existence of terms with the properties specified | |
| 1416 |   to hold for the constants given in @{text decls}.  After finishing
 | |
| 1417 | the proof, the theory will be augmented with axioms expressing the | |
| 1418 | properties given in the first place. | |
| 1419 | ||
| 1420 |   \item @{text decl} declares a constant to be defined by the
 | |
| 1421 |   specification given.  The definition for the constant @{text c} is
 | |
| 1422 |   bound to the name @{text c_def} unless a theorem name is given in
 | |
| 1423 | the declaration. Overloaded constants should be declared as such. | |
| 1424 | ||
| 1425 |   \end{description}
 | |
| 1426 | ||
| 1427 |   Whether to use @{command (HOL) "specification"} or @{command (HOL)
 | |
| 1428 |   "ax_specification"} is to some extent a matter of style.  @{command
 | |
| 1429 | (HOL) "specification"} introduces no new axioms, and so by | |
| 1430 |   construction cannot introduce inconsistencies, whereas @{command
 | |
| 1431 | (HOL) "ax_specification"} does introduce axioms, but only after the | |
| 1432 | user has explicitly proven it to be safe. A practical issue must be | |
| 1433 | considered, though: After introducing two constants with the same | |
| 1434 |   properties using @{command (HOL) "specification"}, one can prove
 | |
| 1435 | that the two constants are, in fact, equal. If this might be a | |
| 1436 |   problem, one should use @{command (HOL) "ax_specification"}.
 | |
| 1437 | *} | |
| 1438 | ||
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1439 | section {* Adhoc overloading of constants *}
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1440 | |
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1441 | text {*
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1442 |   \begin{tabular}{rcll}
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1443 |   @{command_def "adhoc_overloading"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1444 |   @{command_def "no_adhoc_overloading"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1445 |   @{attribute_def "show_variants"} & : & @{text "attribute"} & default @{text false} \\
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1446 |   \end{tabular}
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1447 | |
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1448 | \medskip | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1449 | |
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1450 | Adhoc overloading allows to overload a constant depending on | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1451 | its type. Typically this involves the introduction of an | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1452 | uninterpreted constant (used for input and output) and the addition | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1453 | of some variants (used internally). For examples see | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1454 |   @{file "~~/src/HOL/ex/Adhoc_Overloading_Examples.thy"} and
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1455 |   @{file "~~/src/HOL/Library/Monad_Syntax.thy"}.
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1456 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1457 |   @{rail \<open>
 | 
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1458 |     (@@{command adhoc_overloading} | @@{command no_adhoc_overloading})
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1459 |       (@{syntax nameref} (@{syntax term} + ) + @'and')
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1460 | \<close>} | 
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1461 | |
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1462 |   \begin{description}
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1463 | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1464 |   \item @{command "adhoc_overloading"}~@{text "c v\<^sub>1 ... v\<^sub>n"}
 | 
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1465 | associates variants with an existing constant. | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1466 | |
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1467 |   \item @{command "no_adhoc_overloading"} is similar to
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1468 |   @{command "adhoc_overloading"}, but removes the specified variants
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1469 | from the present context. | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1470 | |
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1471 |   \item @{attribute "show_variants"} controls printing of variants
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1472 | of overloaded constants. If enabled, the internally used variants | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1473 | are printed instead of their respective overloaded constants. This | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1474 | is occasionally useful to check whether the system agrees with a | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1475 | user's expectations about derived variants. | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1476 | |
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1477 |   \end{description}
 | 
| 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 1478 | *} | 
| 50109 | 1479 | |
| 1480 | chapter {* Proof tools *}
 | |
| 1481 | ||
| 1482 | section {* Adhoc tuples *}
 | |
| 1483 | ||
| 1484 | text {*
 | |
| 1485 |   \begin{matharray}{rcl}
 | |
| 1486 |     @{attribute_def (HOL) split_format}@{text "\<^sup>*"} & : & @{text attribute} \\
 | |
| 1487 |   \end{matharray}
 | |
| 1488 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1489 |   @{rail \<open>
 | 
| 50109 | 1490 |     @@{attribute (HOL) split_format} ('(' 'complete' ')')?
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1491 | \<close>} | 
| 50109 | 1492 | |
| 1493 |   \begin{description}
 | |
| 1494 | ||
| 1495 |   \item @{attribute (HOL) split_format}\ @{text "(complete)"} causes
 | |
| 1496 | arguments in function applications to be represented canonically | |
| 1497 | according to their tuple type structure. | |
| 1498 | ||
| 1499 | Note that this operation tends to invent funny names for new local | |
| 1500 | parameters introduced. | |
| 1501 | ||
| 1502 |   \end{description}
 | |
| 1503 | *} | |
| 1504 | ||
| 1505 | ||
| 47821 | 1506 | section {* Transfer package *}
 | 
| 1507 | ||
| 1508 | text {*
 | |
| 1509 |   \begin{matharray}{rcl}
 | |
| 1510 |     @{method_def (HOL) "transfer"} & : & @{text method} \\
 | |
| 1511 |     @{method_def (HOL) "transfer'"} & : & @{text method} \\
 | |
| 1512 |     @{method_def (HOL) "transfer_prover"} & : & @{text method} \\
 | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1513 |     @{attribute_def (HOL) "Transfer.transferred"} & : & @{text attribute} \\
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1514 |     @{attribute_def (HOL) "untransferred"} & : & @{text attribute} \\
 | 
| 47821 | 1515 |     @{attribute_def (HOL) "transfer_rule"} & : & @{text attribute} \\
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1516 |     @{attribute_def (HOL) "transfer_domain_rule"} & : & @{text attribute} \\
 | 
| 47821 | 1517 |     @{attribute_def (HOL) "relator_eq"} & : & @{text attribute} \\
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1518 |     @{attribute_def (HOL) "relator_domain"} & : & @{text attribute} \\
 | 
| 47821 | 1519 |   \end{matharray}
 | 
| 1520 | ||
| 1521 |   \begin{description}
 | |
| 1522 | ||
| 1523 |   \item @{method (HOL) "transfer"} method replaces the current subgoal
 | |
| 1524 | with a logically equivalent one that uses different types and | |
| 1525 | constants. The replacement of types and constants is guided by the | |
| 1526 | database of transfer rules. Goals are generalized over all free | |
| 1527 | variables by default; this is necessary for variables whose types | |
| 1528 | change, but can be overridden for specific variables with e.g. | |
| 1529 |     @{text "transfer fixing: x y z"}.
 | |
| 1530 | ||
| 1531 |   \item @{method (HOL) "transfer'"} is a variant of @{method (HOL)
 | |
| 1532 | transfer} that allows replacing a subgoal with one that is | |
| 1533 | logically stronger (rather than equivalent). For example, a | |
| 1534 | subgoal involving equality on a quotient type could be replaced | |
| 1535 | with a subgoal involving equality (instead of the corresponding | |
| 1536 | equivalence relation) on the underlying raw type. | |
| 1537 | ||
| 1538 |   \item @{method (HOL) "transfer_prover"} method assists with proving
 | |
| 1539 | a transfer rule for a new constant, provided the constant is | |
| 1540 | defined in terms of other constants that already have transfer | |
| 1541 | rules. It should be applied after unfolding the constant | |
| 1542 | definitions. | |
| 1543 | ||
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1544 |   \item @{attribute (HOL) "untransferred"} proves the same equivalent theorem
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1545 |      as @{method (HOL) "transfer"} internally does.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1546 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1547 |   \item @{attribute (HOL) Transfer.transferred} works in the opposite
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1548 |     direction than @{method (HOL) "transfer'"}. E.g., given the transfer
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1549 |     relation @{text "ZN x n \<equiv> (x = int n)"}, corresponding transfer rules and the theorem
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1550 |     @{text "\<forall>x::int \<in> {0..}. x < x + 1"}, the attribute would prove 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1551 |     @{text "\<forall>n::nat. n < n + 1"}. The attribute is still in experimental
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1552 | phase of development. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1553 | |
| 47821 | 1554 |   \item @{attribute (HOL) "transfer_rule"} attribute maintains a
 | 
| 1555 | collection of transfer rules, which relate constants at two | |
| 1556 | different types. Typical transfer rules may relate different type | |
| 1557 | instances of the same polymorphic constant, or they may relate an | |
| 1558 | operation on a raw type to a corresponding operation on an | |
| 1559 | abstract type (quotient or subtype). For example: | |
| 1560 | ||
| 1561 |     @{text "((A ===> B) ===> list_all2 A ===> list_all2 B) map map"}\\
 | |
| 1562 |     @{text "(cr_int ===> cr_int ===> cr_int) (\<lambda>(x,y) (u,v). (x+u, y+v)) plus"}
 | |
| 1563 | ||
| 1564 | Lemmas involving predicates on relations can also be registered | |
| 1565 | using the same attribute. For example: | |
| 1566 | ||
| 1567 |     @{text "bi_unique A \<Longrightarrow> (list_all2 A ===> op =) distinct distinct"}\\
 | |
| 1568 |     @{text "\<lbrakk>bi_unique A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (prod_rel A B)"}
 | |
| 1569 | ||
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1570 |   \item @{attribute (HOL) "transfer_domain_rule"} attribute maintains a collection
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1571 | of rules, which specify a domain of a transfer relation by a predicate. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1572 |     E.g., given the transfer relation @{text "ZN x n \<equiv> (x = int n)"}, 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1573 | one can register the following transfer domain rule: | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1574 |     @{text "Domainp ZN = (\<lambda>x. x \<ge> 0)"}. The rules allow the package to produce
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1575 | more readable transferred goals, e.g., when quantifiers are transferred. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1576 | |
| 47821 | 1577 |   \item @{attribute (HOL) relator_eq} attribute collects identity laws
 | 
| 1578 |     for relators of various type constructors, e.g. @{text "list_all2
 | |
| 1579 |     (op =) = (op =)"}. The @{method (HOL) transfer} method uses these
 | |
| 1580 | lemmas to infer transfer rules for non-polymorphic constants on | |
| 1581 | the fly. | |
| 1582 | ||
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1583 |   \item @{attribute_def (HOL) "relator_domain"} attribute collects rules 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1584 |     describing domains of relators by predicators. E.g., @{text "Domainp A = P \<Longrightarrow>
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1585 | Domainp (list_all2 A) = (list_all P)"}. This allows the package to lift transfer | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1586 | domain rules through type constructors. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1587 | |
| 47821 | 1588 |   \end{description}
 | 
| 1589 | ||
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1590 |   Theoretical background can be found in \cite{Huffman-Kuncar:2013:lifting_transfer}.
 | 
| 47821 | 1591 | *} | 
| 1592 | ||
| 47859 | 1593 | |
| 47802 | 1594 | section {* Lifting package *}
 | 
| 1595 | ||
| 1596 | text {*
 | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1597 | The Lifting package allows users to lift terms of the raw type to the abstract type, which is | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1598 | a necessary step in building a library for an abstract type. Lifting defines a new constant | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1599 | by combining coercion functions (Abs and Rep) with the raw term. It also proves an appropriate | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1600 | transfer rule for the Transfer package and, if possible, an equation for the code generator. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1601 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1602 |   The Lifting package provides two main commands: @{command (HOL) "setup_lifting"} for initializing 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1603 |   the package to work with a new type, and @{command (HOL) "lift_definition"} for lifting constants. 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1604 | The Lifting package works with all four kinds of type abstraction: type copies, subtypes, | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1605 | total quotients and partial quotients. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1606 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1607 |   Theoretical background can be found in \cite{Huffman-Kuncar:2013:lifting_transfer}.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1608 | |
| 47802 | 1609 |   \begin{matharray}{rcl}
 | 
| 1610 |     @{command_def (HOL) "setup_lifting"} & : & @{text "local_theory \<rightarrow> local_theory"}\\
 | |
| 1611 |     @{command_def (HOL) "lift_definition"} & : & @{text "local_theory \<rightarrow> proof(prove)"}\\
 | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1612 |     @{command_def (HOL) "lifting_forget"} & : & @{text "local_theory \<rightarrow> local_theory"}\\
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1613 |     @{command_def (HOL) "lifting_update"} & : & @{text "local_theory \<rightarrow> local_theory"}\\
 | 
| 53219 
ca237b9e4542
use only one data slot; rename print_quotmaps to print_quot_maps; tuned
 kuncar parents: 
53015diff
changeset | 1614 |     @{command_def (HOL) "print_quot_maps"} & : & @{text "context \<rightarrow>"}\\
 | 
| 47802 | 1615 |     @{command_def (HOL) "print_quotients"} & : & @{text "context \<rightarrow>"}\\
 | 
| 1616 |     @{attribute_def (HOL) "quot_map"} & : & @{text attribute} \\
 | |
| 1617 |     @{attribute_def (HOL) "invariant_commute"} & : & @{text attribute} \\
 | |
| 50877 | 1618 |     @{attribute_def (HOL) "reflexivity_rule"} & : & @{text attribute} \\
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1619 |     @{attribute_def (HOL) "relator_mono"} & : & @{text attribute} \\
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1620 |     @{attribute_def (HOL) "relator_distr"} & : & @{text attribute} \\
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1621 |     @{attribute_def (HOL) "quot_del"} & : & @{text attribute} \\
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1622 |     @{attribute_def (HOL) "lifting_restore"} & : & @{text attribute} \\   
 | 
| 47802 | 1623 |   \end{matharray}
 | 
| 1624 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1625 |   @{rail \<open>
 | 
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 1626 |     @@{command (HOL) setup_lifting} ('(' 'no_code' ')')? \<newline>
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1627 |       @{syntax thmref} @{syntax thmref}? (@'parametric' @{syntax thmref})?;
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1628 | \<close>} | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1629 | |
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1630 |   @{rail \<open>
 | 
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 1631 |     @@{command (HOL) lift_definition} @{syntax name} '::' @{syntax type}  @{syntax mixfix}? \<newline>
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1632 |       'is' @{syntax term} (@'parametric' @{syntax thmref})?;
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1633 | \<close>} | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1634 | |
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1635 |   @{rail \<open>
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1636 |     @@{command (HOL) lifting_forget} @{syntax nameref};
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1637 | \<close>} | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1638 | |
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1639 |   @{rail \<open>
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1640 |     @@{command (HOL) lifting_update} @{syntax nameref};
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1641 | \<close>} | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1642 | |
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1643 |   @{rail \<open>
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1644 |     @@{attribute (HOL) lifting_restore} @{syntax thmref} (@{syntax thmref} @{syntax thmref})?;
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1645 | \<close>} | 
| 47802 | 1646 | |
| 1647 |   \begin{description}
 | |
| 1648 | ||
| 47859 | 1649 |   \item @{command (HOL) "setup_lifting"} Sets up the Lifting package
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1650 | to work with a user-defined type. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1651 | The command supports two modes. The first one is a low-level mode when | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1652 | the user must provide as a first | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1653 |     argument of @{command (HOL) "setup_lifting"} a
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1654 |     quotient theorem @{text "Quotient R Abs Rep T"}. The
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1655 | package configures a transfer rule for equality, a domain transfer | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1656 |     rules and sets up the @{command_def (HOL) "lift_definition"}
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1657 |     command to work with the abstract type. An optional theorem @{text "reflp R"}, which certifies that 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1658 | the equivalence relation R is total, | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1659 | can be provided as a second argument. This allows the package to generate stronger transfer | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1660 | rules. And finally, the parametricity theorem for R can be provided as a third argument. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1661 | This allows the package to generate a stronger transfer rule for equality. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1662 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1663 |     Users generally will not prove the @{text Quotient} theorem manually for 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1664 | new types, as special commands exist to automate the process. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1665 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1666 |     When a new subtype is defined by @{command (HOL) typedef}, @{command (HOL) "lift_definition"} 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1667 | can be used in its | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1668 |     second mode, where only the type_definition theorem @{text "type_definition Rep Abs A"}
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1669 | is used as an argument of the command. The command internally proves the corresponding | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1670 |     Quotient theorem and registers it with @{command (HOL) setup_lifting} using its first mode.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1671 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1672 |     For quotients, the command @{command (HOL) quotient_type} can be used. The command defines 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1673 | a new quotient type and similarly to the previous case, the corresponding Quotient theorem is proved | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1674 |     and registered by @{command (HOL) setup_lifting}.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1675 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1676 |     The command @{command (HOL) "setup_lifting"} also sets up the code generator
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1677 |     for the new type. Later on, when a new constant is defined by @{command (HOL) "lift_definition"},
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1678 | the Lifting package proves and registers a code equation (if there is one) for the new constant. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1679 |     If the option @{text "no_code"} is specified, the Lifting package does not set up the code
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1680 | generator and as a consequence no code equations involving an abstract type are registered | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1681 |     by @{command (HOL) "lift_definition"}.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1682 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1683 |   \item @{command (HOL) "lift_definition"} @{text "f :: \<tau>"} @{keyword (HOL) "is"} @{text t}
 | 
| 47859 | 1684 |     Defines a new function @{text f} with an abstract type @{text \<tau>}
 | 
| 1685 |     in terms of a corresponding operation @{text t} on a
 | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1686 |     representation type. More formally, if @{text "t :: \<sigma>"}, then
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1687 |     the command builds a term @{text "F"} as a corresponding combination of abstraction 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1688 |     and representation functions such that @{text "F :: \<sigma> \<Rightarrow> \<tau>" } and 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1689 |     defines @{text f} is as @{text "f \<equiv> F t"}.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1690 |     The term @{text t} does not have to be necessarily a constant but it can be any term.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1691 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1692 | The command opens a proof environment and the user must discharge | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1693 |     a respectfulness proof obligation. For a type copy, i.e., a typedef with @{text
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1694 | UNIV}, the obligation is discharged automatically. The proof goal is | 
| 47802 | 1695 | presented in a user-friendly, readable form. A respectfulness | 
| 47859 | 1696 |     theorem in the standard format @{text f.rsp} and a transfer rule
 | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1697 |     @{text f.transfer} for the Transfer package are generated by the
 | 
| 47859 | 1698 | package. | 
| 47802 | 1699 | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1700 |     The user can specify a parametricity theorem for @{text t} after the keyword 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1701 |     @{keyword "parametric"}, which allows the command
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1702 |     to generate a parametric transfer rule for @{text f}.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1703 | |
| 50879 | 1704 | For each constant defined through trivial quotients (type copies or | 
| 1705 |     subtypes) @{text f.rep_eq} is generated. The equation is a code certificate
 | |
| 1706 |     that defines @{text f} using the representation function.
 | |
| 1707 | ||
| 1708 |     For each constant @{text f.abs_eq} is generated. The equation is unconditional
 | |
| 1709 |     for total quotients. The equation defines @{text f} using
 | |
| 1710 | the abstraction function. | |
| 1711 | ||
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1712 |     Integration with [@{attribute code} abstract]: For subtypes (e.g.,
 | 
| 47859 | 1713 |     corresponding to a datatype invariant, such as dlist), @{command
 | 
| 50879 | 1714 | (HOL) "lift_definition"} uses a code certificate theorem | 
| 1715 |     @{text f.rep_eq} as a code equation.
 | |
| 1716 | ||
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1717 |     Integration with [@{attribute code} equation]: For total quotients, @{command
 | 
| 50879 | 1718 |     (HOL) "lift_definition"} uses @{text f.abs_eq} as a code equation.
 | 
| 47802 | 1719 | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1720 |   \item @{command (HOL) lifting_forget} and  @{command (HOL) lifting_update}
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1721 | These two commands serve for storing and deleting the set-up of | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1722 | the Lifting package and corresponding transfer rules defined by this package. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1723 | This is useful for hiding of type construction details of an abstract type | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1724 | when the construction is finished but it still allows additions to this construction | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1725 | when this is later necessary. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1726 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1727 |     Whenever the Lifting package is set up with a new abstract type @{text "\<tau>"} by  
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1728 |     @{command_def (HOL) "lift_definition"}, the package defines a new bundle
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1729 |     that is called @{text "\<tau>.lifting"}. This bundle already includes set-up for the Lifting package. 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1730 | The new transfer rules | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1731 |     introduced by @{command (HOL) "lift_definition"} can be stored in the bundle by
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1732 |     the command @{command (HOL) "lifting_update"} @{text "\<tau>.lifting"}.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1733 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1734 |     The command @{command (HOL) "lifting_forget"} @{text "\<tau>.lifting"} deletes set-up of the Lifting 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1735 | package | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1736 |     for @{text \<tau>} and deletes all the transfer rules that were introduced
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1737 |     by @{command (HOL) "lift_definition"} using @{text \<tau>} as an abstract type.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1738 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1739 | The stored set-up in a bundle can be reintroduced by the Isar commands for including a bundle | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1740 |     (@{command "include"}, @{keyword "includes"} and @{command "including"}).
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1741 | |
| 53219 
ca237b9e4542
use only one data slot; rename print_quotmaps to print_quot_maps; tuned
 kuncar parents: 
53015diff
changeset | 1742 |   \item @{command (HOL) "print_quot_maps"} prints stored quotient map
 | 
| 47859 | 1743 | theorems. | 
| 1744 | ||
| 1745 |   \item @{command (HOL) "print_quotients"} prints stored quotient
 | |
| 1746 | theorems. | |
| 1747 | ||
| 1748 |   \item @{attribute (HOL) quot_map} registers a quotient map
 | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1749 |     theorem. E.g., @{text "Quotient R Abs Rep T \<Longrightarrow> 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1750 | Quotient (list_all2 R) (map Abs) (map Rep) (list_all2 T)"}. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1751 |     For examples see @{file
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1752 |     "~~/src/HOL/List.thy"} or @{file "~~/src/HOL/Lifting.thy"} or Lifting_*.thy files
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1753 | in the same directory. | 
| 47859 | 1754 | |
| 50877 | 1755 |   \item @{attribute (HOL) invariant_commute} registers a theorem that
 | 
| 47859 | 1756 |     shows a relationship between the constant @{text
 | 
| 1757 | Lifting.invariant} (used for internal encoding of proper subtypes) | |
| 1758 |     and a relator.  Such theorems allows the package to hide @{text
 | |
| 1759 | Lifting.invariant} from a user in a user-readable form of a | |
| 1760 |     respectfulness theorem. For examples see @{file
 | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1761 | "~~/src/HOL/List.thy"} or Lifting_*.thy files in the same directory. | 
| 47802 | 1762 | |
| 50877 | 1763 |   \item @{attribute (HOL) reflexivity_rule} registers a theorem that shows
 | 
| 55564 
e81ee43ab290
delete or move now not necessary reflexivity rules due to 1726f46d2aa8
 kuncar parents: 
55467diff
changeset | 1764 | that a relator respects left-totality and left_uniqueness. For examples | 
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1765 |     see @{file "~~/src/HOL/List.thy"} or @{file "~~/src/HOL/Lifting.thy"} or Lifting_*.thy files 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1766 | in the same directory. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1767 | The property is used in a reflexivity prover, which is used for discharging respectfulness | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1768 | theorems for type copies and also for discharging assumptions of abstraction function equations. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1769 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1770 |   \item @{attribute (HOL) "relator_mono"} registers a property describing a monotonicity of a relator.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1771 |     E.g., @{text "A \<le> B \<Longrightarrow> list_all2 A \<le> list_all2 B"}. For examples 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1772 |     see @{file "~~/src/HOL/List.thy"} or @{file "~~/src/HOL/Lifting.thy"} 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1773 | or Lifting_*.thy files in the same directory. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1774 |     This property is needed for proving a stronger transfer rule in @{command_def (HOL) "lift_definition"}
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1775 | when a parametricity theorem for the raw term is specified. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1776 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1777 |   \item @{attribute (HOL) "relator_distr"} registers a property describing a distributivity
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1778 | of the relation composition and a relator. E.g., | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1779 |     @{text "list_all2 R \<circ>\<circ> list_all2 S = list_all2 (R \<circ>\<circ> S)"}. 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1780 |     This property is needed for proving a stronger transfer rule in @{command_def (HOL) "lift_definition"}
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1781 | when a parametricity theorem for the raw term is specified. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1782 | When this equality does not hold unconditionally (e.g., for the function type), the user can specified | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1783 | each direction separately and also register multiple theorems with different set of assumptions. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1784 | This attribute can be used only after the monotonicity property was already registered by | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1785 |     @{attribute (HOL) "relator_mono"}. For examples 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1786 |     see @{file "~~/src/HOL/List.thy"} or @{file "~~/src/HOL/Lifting.thy"} 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1787 | or Lifting_*.thy files in the same directory. | 
| 50877 | 1788 | |
| 1789 |   \item @{attribute (HOL) quot_del} deletes a corresponding Quotient theorem
 | |
| 1790 | from the Lifting infrastructure and thus de-register the corresponding quotient. | |
| 1791 |     This effectively causes that @{command (HOL) lift_definition}  will not
 | |
| 54334 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1792 | do any lifting for the corresponding type. This attribute is rather used for low-level | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1793 |     manipulation with set-up of the Lifting package because @{command (HOL) lifting_forget} is
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1794 | preferred for normal usage. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1795 | |
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1796 |   \item @{attribute (HOL) lifting_restore} @{text "Quotient_thm pcr_def pcr_cr_eq_thm"} 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1797 |     registers the Quotient theorem @{text Quotient_thm} in the Lifting infrastructure 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1798 |     and thus sets up lifting for an abstract type @{text \<tau>} (that is defined by @{text Quotient_thm}).
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1799 |     Optional theorems @{text pcr_def} and @{text pcr_cr_eq_thm} can be specified to register 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1800 | the parametrized | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1801 |     correspondence relation for @{text \<tau>}. E.g., for @{text "'a dlist"}, @{text pcr_def} is
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1802 |     @{text "pcr_dlist A \<equiv> list_all2 A \<circ>\<circ> cr_dlist"} and @{text pcr_cr_eq_thm} is 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1803 |     @{text "pcr_dlist op= = op="}.
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1804 | This attribute is rather used for low-level | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1805 |     manipulation with set-up of the Lifting package because using of the bundle @{text \<tau>.lifting} 
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1806 |     together with the commands @{command (HOL) lifting_forget} and @{command (HOL) lifting_update} is
 | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1807 | preferred for normal usage. | 
| 
409d7f7247f4
update documentation of Lifting/Transfer and Quotient
 kuncar parents: 
54017diff
changeset | 1808 | |
| 47802 | 1809 |   \end{description}
 | 
| 1810 | *} | |
| 1811 | ||
| 47859 | 1812 | |
| 43994 | 1813 | section {* Coercive subtyping *}
 | 
| 1814 | ||
| 1815 | text {*
 | |
| 1816 |   \begin{matharray}{rcl}
 | |
| 1817 |     @{attribute_def (HOL) coercion} & : & @{text attribute} \\
 | |
| 1818 |     @{attribute_def (HOL) coercion_enabled} & : & @{text attribute} \\
 | |
| 1819 |     @{attribute_def (HOL) coercion_map} & : & @{text attribute} \\
 | |
| 1820 |   \end{matharray}
 | |
| 1821 | ||
| 46280 | 1822 | Coercive subtyping allows the user to omit explicit type | 
| 1823 |   conversions, also called \emph{coercions}.  Type inference will add
 | |
| 1824 | them as necessary when parsing a term. See | |
| 1825 |   \cite{traytel-berghofer-nipkow-2011} for details.
 | |
| 1826 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1827 |   @{rail \<open>
 | 
| 43994 | 1828 |     @@{attribute (HOL) coercion} (@{syntax term})?
 | 
| 1829 | ; | |
| 1830 |     @@{attribute (HOL) coercion_map} (@{syntax term})?
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1831 | \<close>} | 
| 43994 | 1832 | |
| 1833 |   \begin{description}
 | |
| 1834 | ||
| 1835 |   \item @{attribute (HOL) "coercion"}~@{text "f"} registers a new
 | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1836 |   coercion function @{text "f :: \<sigma>\<^sub>1 \<Rightarrow> \<sigma>\<^sub>2"} where @{text "\<sigma>\<^sub>1"} and
 | 
| 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1837 |   @{text "\<sigma>\<^sub>2"} are type constructors without arguments.  Coercions are
 | 
| 46280 | 1838 | composed by the inference algorithm if needed. Note that the type | 
| 1839 | inference algorithm is complete only if the registered coercions | |
| 1840 | form a lattice. | |
| 43994 | 1841 | |
| 46280 | 1842 |   \item @{attribute (HOL) "coercion_map"}~@{text "map"} registers a
 | 
| 1843 | new map function to lift coercions through type constructors. The | |
| 1844 |   function @{text "map"} must conform to the following type pattern
 | |
| 43994 | 1845 | |
| 1846 |   \begin{matharray}{lll}
 | |
| 1847 |     @{text "map"} & @{text "::"} &
 | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1848 |       @{text "f\<^sub>1 \<Rightarrow> \<dots> \<Rightarrow> f\<^sub>n \<Rightarrow> (\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t \<Rightarrow> (\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n) t"} \\
 | 
| 43994 | 1849 |   \end{matharray}
 | 
| 1850 | ||
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1851 |   where @{text "t"} is a type constructor and @{text "f\<^sub>i"} is of type
 | 
| 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 1852 |   @{text "\<alpha>\<^sub>i \<Rightarrow> \<beta>\<^sub>i"} or @{text "\<beta>\<^sub>i \<Rightarrow> \<alpha>\<^sub>i"}.  Registering a map function
 | 
| 46280 | 1853 | overwrites any existing map function for this particular type | 
| 1854 | constructor. | |
| 43994 | 1855 | |
| 1856 |   \item @{attribute (HOL) "coercion_enabled"} enables the coercion
 | |
| 1857 | inference algorithm. | |
| 1858 | ||
| 1859 |   \end{description}
 | |
| 1860 | *} | |
| 1861 | ||
| 1862 | ||
| 26849 | 1863 | section {* Arithmetic proof support *}
 | 
| 1864 | ||
| 1865 | text {*
 | |
| 1866 |   \begin{matharray}{rcl}
 | |
| 28761 
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
 wenzelm parents: 
28760diff
changeset | 1867 |     @{method_def (HOL) arith} & : & @{text method} \\
 | 
| 30863 | 1868 |     @{attribute_def (HOL) arith} & : & @{text attribute} \\
 | 
| 28761 
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
 wenzelm parents: 
28760diff
changeset | 1869 |     @{attribute_def (HOL) arith_split} & : & @{text attribute} \\
 | 
| 26849 | 1870 |   \end{matharray}
 | 
| 1871 | ||
| 46280 | 1872 |   \begin{description}
 | 
| 26849 | 1873 | |
| 46280 | 1874 |   \item @{method (HOL) arith} decides linear arithmetic problems (on
 | 
| 1875 |   types @{text nat}, @{text int}, @{text real}).  Any current facts
 | |
| 1876 | are inserted into the goal before running the procedure. | |
| 26849 | 1877 | |
| 46280 | 1878 |   \item @{attribute (HOL) arith} declares facts that are supplied to
 | 
| 1879 | the arithmetic provers implicitly. | |
| 1880 | ||
| 1881 |   \item @{attribute (HOL) arith_split} attribute declares case split
 | |
| 30865 | 1882 |   rules to be expanded before @{method (HOL) arith} is invoked.
 | 
| 30863 | 1883 | |
| 46280 | 1884 |   \end{description}
 | 
| 1885 | ||
| 1886 | Note that a simpler (but faster) arithmetic prover is already | |
| 1887 | invoked by the Simplifier. | |
| 26849 | 1888 | *} | 
| 1889 | ||
| 1890 | ||
| 30169 | 1891 | section {* Intuitionistic proof search *}
 | 
| 1892 | ||
| 1893 | text {*
 | |
| 1894 |   \begin{matharray}{rcl}
 | |
| 30171 | 1895 |     @{method_def (HOL) iprover} & : & @{text method} \\
 | 
| 30169 | 1896 |   \end{matharray}
 | 
| 1897 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1898 |   @{rail \<open>
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1899 |     @@{method (HOL) iprover} (@{syntax rulemod} *)
 | 
| 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1900 | \<close>} | 
| 30169 | 1901 | |
| 46280 | 1902 |   \begin{description}
 | 
| 1903 | ||
| 1904 |   \item @{method (HOL) iprover} performs intuitionistic proof search,
 | |
| 1905 | depending on specifically declared rules from the context, or given | |
| 1906 | as explicit arguments. Chained facts are inserted into the goal | |
| 1907 | before commencing proof search. | |
| 35613 | 1908 | |
| 30169 | 1909 |   Rules need to be classified as @{attribute (Pure) intro},
 | 
| 1910 |   @{attribute (Pure) elim}, or @{attribute (Pure) dest}; here the
 | |
| 1911 |   ``@{text "!"}'' indicator refers to ``safe'' rules, which may be
 | |
| 1912 | applied aggressively (without considering back-tracking later). | |
| 1913 |   Rules declared with ``@{text "?"}'' are ignored in proof search (the
 | |
| 42626 | 1914 |   single-step @{method (Pure) rule} method still observes these).  An
 | 
| 30169 | 1915 | explicit weight annotation may be given as well; otherwise the | 
| 1916 | number of rule premises will be taken into account here. | |
| 46280 | 1917 | |
| 1918 |   \end{description}
 | |
| 30169 | 1919 | *} | 
| 1920 | ||
| 46280 | 1921 | |
| 43578 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1922 | section {* Model Elimination and Resolution *}
 | 
| 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1923 | |
| 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1924 | text {*
 | 
| 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1925 |   \begin{matharray}{rcl}
 | 
| 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1926 |     @{method_def (HOL) "meson"} & : & @{text method} \\
 | 
| 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1927 |     @{method_def (HOL) "metis"} & : & @{text method} \\
 | 
| 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1928 |   \end{matharray}
 | 
| 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1929 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1930 |   @{rail \<open>
 | 
| 43578 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1931 |     @@{method (HOL) meson} @{syntax thmrefs}?
 | 
| 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1932 | ; | 
| 46280 | 1933 |     @@{method (HOL) metis}
 | 
| 1934 |       ('(' ('partial_types' | 'full_types' | 'no_types' | @{syntax name}) ')')?
 | |
| 1935 |       @{syntax thmrefs}?
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1936 | \<close>} | 
| 43578 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1937 | |
| 46280 | 1938 |   \begin{description}
 | 
| 1939 | ||
| 1940 |   \item @{method (HOL) meson} implements Loveland's model elimination
 | |
| 1941 |   procedure \cite{loveland-78}.  See @{file
 | |
| 1942 | "~~/src/HOL/ex/Meson_Test.thy"} for examples. | |
| 43578 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1943 | |
| 46280 | 1944 |   \item @{method (HOL) metis} combines ordered resolution and ordered
 | 
| 1945 | paramodulation to find first-order (or mildly higher-order) proofs. | |
| 1946 | The first optional argument specifies a type encoding; see the | |
| 1947 |   Sledgehammer manual \cite{isabelle-sledgehammer} for details.  The
 | |
| 1948 |   directory @{file "~~/src/HOL/Metis_Examples"} contains several small
 | |
| 1949 |   theories developed to a large extent using @{method (HOL) metis}.
 | |
| 1950 | ||
| 1951 |   \end{description}
 | |
| 43578 
36ba44fe0781
document "meson" and "metis" in HOL specific section of the Isar ref manual
 blanchet parents: 
43270diff
changeset | 1952 | *} | 
| 30169 | 1953 | |
| 46280 | 1954 | |
| 50130 | 1955 | section {* Algebraic reasoning via Gr\"obner bases *}
 | 
| 1956 | ||
| 1957 | text {*
 | |
| 1958 |   \begin{matharray}{rcl}
 | |
| 1959 |     @{method_def (HOL) "algebra"} & : & @{text method} \\
 | |
| 1960 |     @{attribute_def (HOL) algebra} & : & @{text attribute} \\
 | |
| 1961 |   \end{matharray}
 | |
| 1962 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1963 |   @{rail \<open>
 | 
| 50130 | 1964 |     @@{method (HOL) algebra}
 | 
| 1965 |       ('add' ':' @{syntax thmrefs})?
 | |
| 1966 |       ('del' ':' @{syntax thmrefs})?
 | |
| 1967 | ; | |
| 1968 |     @@{attribute (HOL) algebra} (() | 'add' | 'del')
 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 1969 | \<close>} | 
| 50130 | 1970 | |
| 1971 |   \begin{description}
 | |
| 1972 | ||
| 1973 |   \item @{method (HOL) algebra} performs algebraic reasoning via
 | |
| 1974 |   Gr\"obner bases, see also \cite{Chaieb-Wenzel:2007} and
 | |
| 1975 |   \cite[\S3.2]{Chaieb-thesis}. The method handles deals with two main
 | |
| 1976 | classes of problems: | |
| 1977 | ||
| 1978 |   \begin{enumerate}
 | |
| 1979 | ||
| 1980 | \item Universal problems over multivariate polynomials in a | |
| 1981 | (semi)-ring/field/idom; the capabilities of the method are augmented | |
| 1982 | according to properties of these structures. For this problem class | |
| 1983 | the method is only complete for algebraically closed fields, since | |
| 1984 | the underlying method is based on Hilbert's Nullstellensatz, where | |
| 1985 | the equivalence only holds for algebraically closed fields. | |
| 1986 | ||
| 1987 |   The problems can contain equations @{text "p = 0"} or inequations
 | |
| 1988 |   @{text "q \<noteq> 0"} anywhere within a universal problem statement.
 | |
| 1989 | ||
| 1990 | \item All-exists problems of the following restricted (but useful) | |
| 1991 | form: | |
| 1992 | ||
| 1993 |   @{text [display] "\<forall>x\<^sub>1 \<dots> x\<^sub>n.
 | |
| 1994 | e\<^sub>1(x\<^sub>1, \<dots>, x\<^sub>n) = 0 \<and> \<dots> \<and> e\<^sub>m(x\<^sub>1, \<dots>, x\<^sub>n) = 0 \<longrightarrow> | |
| 1995 | (\<exists>y\<^sub>1 \<dots> y\<^sub>k. | |
| 1996 | p\<^sub>1\<^sub>1(x\<^sub>1, \<dots> ,x\<^sub>n) * y\<^sub>1 + \<dots> + p\<^sub>1\<^sub>k(x\<^sub>1, \<dots>, x\<^sub>n) * y\<^sub>k = 0 \<and> | |
| 1997 | \<dots> \<and> | |
| 1998 | p\<^sub>t\<^sub>1(x\<^sub>1, \<dots>, x\<^sub>n) * y\<^sub>1 + \<dots> + p\<^sub>t\<^sub>k(x\<^sub>1, \<dots>, x\<^sub>n) * y\<^sub>k = 0)"} | |
| 1999 | ||
| 2000 |   Here @{text "e\<^sub>1, \<dots>, e\<^sub>n"} and the @{text "p\<^sub>i\<^sub>j"} are multivariate
 | |
| 2001 | polynomials only in the variables mentioned as arguments. | |
| 2002 | ||
| 2003 |   \end{enumerate}
 | |
| 2004 | ||
| 2005 | The proof method is preceded by a simplification step, which may be | |
| 2006 |   modified by using the form @{text "(algebra add: ths\<^sub>1 del: ths\<^sub>2)"}.
 | |
| 2007 | This acts like declarations for the Simplifier | |
| 2008 |   (\secref{sec:simplifier}) on a private simpset for this tool.
 | |
| 2009 | ||
| 2010 |   \item @{attribute algebra} (as attribute) manages the default
 | |
| 2011 | collection of pre-simplification rules of the above proof method. | |
| 2012 | ||
| 2013 |   \end{description}
 | |
| 2014 | *} | |
| 2015 | ||
| 2016 | ||
| 2017 | subsubsection {* Example *}
 | |
| 2018 | ||
| 2019 | text {* The subsequent example is from geometry: collinearity is
 | |
| 2020 | invariant by rotation. *} | |
| 2021 | ||
| 2022 | type_synonym point = "int \<times> int" | |
| 2023 | ||
| 2024 | fun collinear :: "point \<Rightarrow> point \<Rightarrow> point \<Rightarrow> bool" where | |
| 2025 | "collinear (Ax, Ay) (Bx, By) (Cx, Cy) \<longleftrightarrow> | |
| 2026 | (Ax - Bx) * (By - Cy) = (Ay - By) * (Bx - Cx)" | |
| 2027 | ||
| 2028 | lemma collinear_inv_rotation: | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52895diff
changeset | 2029 | assumes "collinear (Ax, Ay) (Bx, By) (Cx, Cy)" and "c\<^sup>2 + s\<^sup>2 = 1" | 
| 50130 | 2030 | shows "collinear (Ax * c - Ay * s, Ay * c + Ax * s) | 
| 2031 | (Bx * c - By * s, By * c + Bx * s) (Cx * c - Cy * s, Cy * c + Cx * s)" | |
| 2032 | using assms by (algebra add: collinear.simps) | |
| 2033 | ||
| 2034 | text {*
 | |
| 53982 | 2035 |  See also @{file "~~/src/HOL/ex/Groebner_Examples.thy"}.
 | 
| 50130 | 2036 | *} | 
| 2037 | ||
| 2038 | ||
| 30171 | 2039 | section {* Coherent Logic *}
 | 
| 2040 | ||
| 2041 | text {*
 | |
| 2042 |   \begin{matharray}{rcl}
 | |
| 2043 |     @{method_def (HOL) "coherent"} & : & @{text method} \\
 | |
| 2044 |   \end{matharray}
 | |
| 2045 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2046 |   @{rail \<open>
 | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2047 |     @@{method (HOL) coherent} @{syntax thmrefs}?
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2048 | \<close>} | 
| 30171 | 2049 | |
| 46280 | 2050 |   \begin{description}
 | 
| 2051 | ||
| 2052 |   \item @{method (HOL) coherent} solves problems of \emph{Coherent
 | |
| 2053 |   Logic} \cite{Bezem-Coquand:2005}, which covers applications in
 | |
| 2054 | confluence theory, lattice theory and projective geometry. See | |
| 2055 |   @{file "~~/src/HOL/ex/Coherent.thy"} for some examples.
 | |
| 2056 | ||
| 2057 |   \end{description}
 | |
| 30171 | 2058 | *} | 
| 2059 | ||
| 2060 | ||
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2061 | section {* Proving propositions *}
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2062 | |
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2063 | text {*
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2064 | In addition to the standard proof methods, a number of diagnosis | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2065 | tools search for proofs and provide an Isar proof snippet on success. | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2066 | These tools are available via the following commands. | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2067 | |
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2068 |   \begin{matharray}{rcl}
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2069 |     @{command_def (HOL) "solve_direct"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2070 |     @{command_def (HOL) "try"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\
 | 
| 46641 | 2071 |     @{command_def (HOL) "try0"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\
 | 
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2072 |     @{command_def (HOL) "sledgehammer"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2073 |     @{command_def (HOL) "sledgehammer_params"} & : & @{text "theory \<rightarrow> theory"}
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2074 |   \end{matharray}
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2075 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2076 |   @{rail \<open>
 | 
| 43040 | 2077 |     @@{command (HOL) try}
 | 
| 2078 | ; | |
| 2079 | ||
| 46641 | 2080 |     @@{command (HOL) try0} ( ( ( 'simp' | 'intro' | 'elim' | 'dest' ) ':' @{syntax thmrefs} ) + ) ?
 | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2081 |       @{syntax nat}?
 | 
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2082 | ; | 
| 43040 | 2083 | |
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2084 |     @@{command (HOL) sledgehammer} ( '[' args ']' )? facts? @{syntax nat}?
 | 
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2085 | ; | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2086 | |
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2087 |     @@{command (HOL) sledgehammer_params} ( ( '[' args ']' ) ? )
 | 
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2088 | ; | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2089 |     args: ( @{syntax name} '=' value + ',' )
 | 
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2090 | ; | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2091 |     facts: '(' ( ( ( ( 'add' | 'del' ) ':' ) ? @{syntax thmrefs} ) + ) ? ')'
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2092 | \<close>} % FIXME check args "value" | 
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2093 | |
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2094 |   \begin{description}
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2095 | |
| 46283 | 2096 |   \item @{command (HOL) "solve_direct"} checks whether the current
 | 
| 2097 | subgoals can be solved directly by an existing theorem. Duplicate | |
| 2098 | lemmas can be detected in this way. | |
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2099 | |
| 46641 | 2100 |   \item @{command (HOL) "try0"} attempts to prove a subgoal
 | 
| 46283 | 2101 |   using a combination of standard proof methods (@{method auto},
 | 
| 2102 |   @{method simp}, @{method blast}, etc.).  Additional facts supplied
 | |
| 2103 |   via @{text "simp:"}, @{text "intro:"}, @{text "elim:"}, and @{text
 | |
| 2104 | "dest:"} are passed to the appropriate proof methods. | |
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2105 | |
| 43914 
64819f353c53
updating documentation about quickcheck; adding information about try
 bulwahn parents: 
43578diff
changeset | 2106 |   \item @{command (HOL) "try"} attempts to prove or disprove a subgoal
 | 
| 46283 | 2107 |   using a combination of provers and disprovers (@{command (HOL)
 | 
| 2108 |   "solve_direct"}, @{command (HOL) "quickcheck"}, @{command (HOL)
 | |
| 46641 | 2109 |   "try0"}, @{command (HOL) "sledgehammer"}, @{command (HOL)
 | 
| 46283 | 2110 | "nitpick"}). | 
| 43914 
64819f353c53
updating documentation about quickcheck; adding information about try
 bulwahn parents: 
43578diff
changeset | 2111 | |
| 46283 | 2112 |   \item @{command (HOL) "sledgehammer"} attempts to prove a subgoal
 | 
| 2113 | using external automatic provers (resolution provers and SMT | |
| 2114 |   solvers). See the Sledgehammer manual \cite{isabelle-sledgehammer}
 | |
| 2115 | for details. | |
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2116 | |
| 46283 | 2117 |   \item @{command (HOL) "sledgehammer_params"} changes @{command (HOL)
 | 
| 2118 | "sledgehammer"} configuration options persistently. | |
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2119 | |
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2120 |   \end{description}
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2121 | *} | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2122 | |
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2123 | |
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2124 | section {* Checking and refuting propositions *}
 | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2125 | |
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2126 | text {*
 | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2127 | Identifying incorrect propositions usually involves evaluation of | 
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2128 | particular assignments and systematic counterexample search. This | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2129 | is supported by the following commands. | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2130 | |
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2131 |   \begin{matharray}{rcl}
 | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2132 |     @{command_def (HOL) "value"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
 | 
| 45409 
5abb0e738b00
adding some documentation about the values command to the isar reference
 bulwahn parents: 
45408diff
changeset | 2133 |     @{command_def (HOL) "values"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
 | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2134 |     @{command_def (HOL) "quickcheck"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\
 | 
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2135 |     @{command_def (HOL) "nitpick"}@{text "\<^sup>*"} & : & @{text "proof \<rightarrow>"} \\
 | 
| 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2136 |     @{command_def (HOL) "quickcheck_params"} & : & @{text "theory \<rightarrow> theory"} \\
 | 
| 45943 
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
 bulwahn parents: 
45839diff
changeset | 2137 |     @{command_def (HOL) "nitpick_params"} & : & @{text "theory \<rightarrow> theory"} \\
 | 
| 46592 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2138 |     @{command_def (HOL) "quickcheck_generator"} & : & @{text "theory \<rightarrow> theory"} \\
 | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2139 |     @{command_def (HOL) "find_unused_assms"} & : & @{text "context \<rightarrow>"}
 | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2140 |   \end{matharray}
 | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2141 | |
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2142 |   @{rail \<open>
 | 
| 46628 | 2143 |     @@{command (HOL) value} ( '[' @{syntax name} ']' )? modes? @{syntax term}
 | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2144 | ; | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2145 | |
| 45409 
5abb0e738b00
adding some documentation about the values command to the isar reference
 bulwahn parents: 
45408diff
changeset | 2146 |     @@{command (HOL) values} modes? @{syntax nat}? @{syntax term}
 | 
| 
5abb0e738b00
adding some documentation about the values command to the isar reference
 bulwahn parents: 
45408diff
changeset | 2147 | ; | 
| 
5abb0e738b00
adding some documentation about the values command to the isar reference
 bulwahn parents: 
45408diff
changeset | 2148 | |
| 49993 
80402e0e78e3
removed "refute" command from Isar manual, now that it has been moved outside "Main"
 blanchet parents: 
49836diff
changeset | 2149 |     (@@{command (HOL) quickcheck} | @@{command (HOL) nitpick})
 | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2150 |       ( '[' args ']' )? @{syntax nat}?
 | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2151 | ; | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2152 | |
| 49993 
80402e0e78e3
removed "refute" command from Isar manual, now that it has been moved outside "Main"
 blanchet parents: 
49836diff
changeset | 2153 |     (@@{command (HOL) quickcheck_params} |
 | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2154 |       @@{command (HOL) nitpick_params}) ( '[' args ']' )?
 | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2155 | ; | 
| 46592 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2156 | |
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2157 |     @@{command (HOL) quickcheck_generator} @{syntax nameref} \<newline>
 | 
| 45943 
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
 bulwahn parents: 
45839diff
changeset | 2158 |       'operations:' ( @{syntax term} +)
 | 
| 
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
 bulwahn parents: 
45839diff
changeset | 2159 | ; | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2160 | |
| 46628 | 2161 |     @@{command (HOL) find_unused_assms} @{syntax name}?
 | 
| 46592 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2162 | ; | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2163 |     modes: '(' (@{syntax name} +) ')'
 | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2164 | ; | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2165 |     args: ( @{syntax name} '=' value + ',' )
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2166 | \<close>} % FIXME check "value" | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2167 | |
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2168 |   \begin{description}
 | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2169 | |
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2170 |   \item @{command (HOL) "value"}~@{text t} evaluates and prints a
 | 
| 46283 | 2171 |   term; optionally @{text modes} can be specified, which are appended
 | 
| 2172 |   to the current print mode; see \secref{sec:print-modes}.
 | |
| 2173 | Internally, the evaluation is performed by registered evaluators, | |
| 2174 | which are invoked sequentially until a result is returned. | |
| 2175 | Alternatively a specific evaluator can be selected using square | |
| 2176 | brackets; typical evaluators use the current set of code equations | |
| 2177 |   to normalize and include @{text simp} for fully symbolic evaluation
 | |
| 2178 |   using the simplifier, @{text nbe} for \emph{normalization by
 | |
| 2179 |   evaluation} and \emph{code} for code generation in SML.
 | |
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2180 | |
| 46283 | 2181 |   \item @{command (HOL) "values"}~@{text t} enumerates a set
 | 
| 2182 | comprehension by evaluation and prints its values up to the given | |
| 2183 |   number of solutions; optionally @{text modes} can be specified,
 | |
| 2184 | which are appended to the current print mode; see | |
| 2185 |   \secref{sec:print-modes}.
 | |
| 45409 
5abb0e738b00
adding some documentation about the values command to the isar reference
 bulwahn parents: 
45408diff
changeset | 2186 | |
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2187 |   \item @{command (HOL) "quickcheck"} tests the current goal for
 | 
| 46283 | 2188 | counterexamples using a series of assignments for its free | 
| 2189 | variables; by default the first subgoal is tested, an other can be | |
| 2190 | selected explicitly using an optional goal index. Assignments can | |
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 2191 | be chosen exhausting the search space up to a given size, or using a | 
| 46283 | 2192 | fixed number of random assignments in the search space, or exploring | 
| 2193 | the search space symbolically using narrowing. By default, | |
| 2194 | quickcheck uses exhaustive testing. A number of configuration | |
| 2195 |   options are supported for @{command (HOL) "quickcheck"}, notably:
 | |
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2196 | |
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2197 |     \begin{description}
 | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2198 | |
| 43914 
64819f353c53
updating documentation about quickcheck; adding information about try
 bulwahn parents: 
43578diff
changeset | 2199 |     \item[@{text tester}] specifies which testing approach to apply.
 | 
| 46283 | 2200 |     There are three testers, @{text exhaustive}, @{text random}, and
 | 
| 2201 |     @{text narrowing}.  An unknown configuration option is treated as
 | |
| 2202 |     an argument to tester, making @{text "tester ="} optional.  When
 | |
| 2203 | multiple testers are given, these are applied in parallel. If no | |
| 2204 | tester is specified, quickcheck uses the testers that are set | |
| 2205 |     active, i.e., configurations @{attribute
 | |
| 2206 |     quickcheck_exhaustive_active}, @{attribute
 | |
| 2207 |     quickcheck_random_active}, @{attribute
 | |
| 2208 | quickcheck_narrowing_active} are set to true. | |
| 2209 | ||
| 40254 | 2210 |     \item[@{text size}] specifies the maximum size of the search space
 | 
| 2211 | for assignment values. | |
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2212 | |
| 45758 
6210c350d88b
documenting the genuine_only option in quickcheck;
 bulwahn parents: 
45701diff
changeset | 2213 |     \item[@{text genuine_only}] sets quickcheck only to return genuine
 | 
| 46283 | 2214 | counterexample, but not potentially spurious counterexamples due | 
| 2215 | to underspecified functions. | |
| 46498 
2754784e9153
adding documentation for abort_potential option in quickcheck
 bulwahn parents: 
46494diff
changeset | 2216 | |
| 
2754784e9153
adding documentation for abort_potential option in quickcheck
 bulwahn parents: 
46494diff
changeset | 2217 |     \item[@{text abort_potential}] sets quickcheck to abort once it
 | 
| 
2754784e9153
adding documentation for abort_potential option in quickcheck
 bulwahn parents: 
46494diff
changeset | 2218 | found a potentially spurious counterexample and to not continue | 
| 
2754784e9153
adding documentation for abort_potential option in quickcheck
 bulwahn parents: 
46494diff
changeset | 2219 | to search for a further genuine counterexample. | 
| 
2754784e9153
adding documentation for abort_potential option in quickcheck
 bulwahn parents: 
46494diff
changeset | 2220 |     For this option to be effective, the @{text genuine_only} option
 | 
| 
2754784e9153
adding documentation for abort_potential option in quickcheck
 bulwahn parents: 
46494diff
changeset | 2221 | must be set to false. | 
| 47859 | 2222 | |
| 42092 
f07b373f25d3
adding documentation about the eval option in quickcheck
 bulwahn parents: 
41846diff
changeset | 2223 |     \item[@{text eval}] takes a term or a list of terms and evaluates
 | 
| 46283 | 2224 | these terms under the variable assignment found by quickcheck. | 
| 48159 | 2225 | This option is currently only supported by the default | 
| 2226 | (exhaustive) tester. | |
| 42123 | 2227 | |
| 40254 | 2228 |     \item[@{text iterations}] sets how many sets of assignments are
 | 
| 2229 | generated for each particular size. | |
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2230 | |
| 40254 | 2231 |     \item[@{text no_assms}] specifies whether assumptions in
 | 
| 2232 | structured proofs should be ignored. | |
| 35331 | 2233 | |
| 47349 
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
 bulwahn parents: 
46641diff
changeset | 2234 |     \item[@{text locale}] specifies how to process conjectures in
 | 
| 
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
 bulwahn parents: 
46641diff
changeset | 2235 | a locale context, i.e., they can be interpreted or expanded. | 
| 
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
 bulwahn parents: 
46641diff
changeset | 2236 | The option is a whitespace-separated list of the two words | 
| 
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
 bulwahn parents: 
46641diff
changeset | 2237 |     @{text interpret} and @{text expand}. The list determines the
 | 
| 47859 | 2238 | order they are employed. The default setting is to first use | 
| 47349 
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
 bulwahn parents: 
46641diff
changeset | 2239 | interpretations and then test the expanded conjecture. | 
| 
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
 bulwahn parents: 
46641diff
changeset | 2240 | The option is only provided as attribute declaration, but not | 
| 47859 | 2241 | as parameter to the command. | 
| 47349 
803729c9fd4d
documenting options quickcheck_locale; adjusting IsarRef documentation of Quotient predicate; NEWS
 bulwahn parents: 
46641diff
changeset | 2242 | |
| 40254 | 2243 |     \item[@{text timeout}] sets the time limit in seconds.
 | 
| 40245 
59f011c1877a
updating documentation on quickcheck in the Isar reference
 bulwahn parents: 
40171diff
changeset | 2244 | |
| 40254 | 2245 |     \item[@{text default_type}] sets the type(s) generally used to
 | 
| 2246 | instantiate type variables. | |
| 40245 
59f011c1877a
updating documentation on quickcheck in the Isar reference
 bulwahn parents: 
40171diff
changeset | 2247 | |
| 40254 | 2248 |     \item[@{text report}] if set quickcheck reports how many tests
 | 
| 2249 | fulfilled the preconditions. | |
| 40245 
59f011c1877a
updating documentation on quickcheck in the Isar reference
 bulwahn parents: 
40171diff
changeset | 2250 | |
| 46592 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2251 |     \item[@{text use_subtype}] if set quickcheck automatically lifts
 | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2252 | conjectures to registered subtypes if possible, and tests the | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2253 | lifted conjecture. | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2254 | |
| 45766 
46046d8e9659
updating documentation about quiet and verbose options in quickcheck
 bulwahn parents: 
45758diff
changeset | 2255 |     \item[@{text quiet}] if set quickcheck does not output anything
 | 
| 
46046d8e9659
updating documentation about quiet and verbose options in quickcheck
 bulwahn parents: 
45758diff
changeset | 2256 | while testing. | 
| 47859 | 2257 | |
| 46283 | 2258 |     \item[@{text verbose}] if set quickcheck informs about the current
 | 
| 2259 | size and cardinality while testing. | |
| 40245 
59f011c1877a
updating documentation on quickcheck in the Isar reference
 bulwahn parents: 
40171diff
changeset | 2260 | |
| 40254 | 2261 |     \item[@{text expect}] can be used to check if the user's
 | 
| 2262 |     expectation was met (@{text no_expectation}, @{text
 | |
| 2263 |     no_counterexample}, or @{text counterexample}).
 | |
| 40245 
59f011c1877a
updating documentation on quickcheck in the Isar reference
 bulwahn parents: 
40171diff
changeset | 2264 | |
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2265 |     \end{description}
 | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2266 | |
| 46283 | 2267 | These option can be given within square brackets. | 
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2268 | |
| 46283 | 2269 |   \item @{command (HOL) "quickcheck_params"} changes @{command (HOL)
 | 
| 2270 | "quickcheck"} configuration options persistently. | |
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2271 | |
| 45943 
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
 bulwahn parents: 
45839diff
changeset | 2272 |   \item @{command (HOL) "quickcheck_generator"} creates random and
 | 
| 46283 | 2273 | exhaustive value generators for a given type and operations. It | 
| 2274 | generates values by using the operations as if they were | |
| 2275 | constructors of that type. | |
| 45943 
8c4a5e664fbc
adding documentation about the quickcheck_generator command in the IsarRef
 bulwahn parents: 
45839diff
changeset | 2276 | |
| 46283 | 2277 |   \item @{command (HOL) "nitpick"} tests the current goal for
 | 
| 2278 | counterexamples using a reduction to first-order relational | |
| 2279 |   logic. See the Nitpick manual \cite{isabelle-nitpick} for details.
 | |
| 42215 
de9d43c427ae
document "nitpick(_params)", "refute(_params)", "try", "sledgehammer(_params)", and "solve_direct"
 blanchet parents: 
42123diff
changeset | 2280 | |
| 46283 | 2281 |   \item @{command (HOL) "nitpick_params"} changes @{command (HOL)
 | 
| 2282 | "nitpick"} configuration options persistently. | |
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2283 | |
| 46592 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2284 |   \item @{command (HOL) "find_unused_assms"} finds potentially superfluous
 | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2285 | assumptions in theorems using quickcheck. | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2286 | It takes the theory name to be checked for superfluous assumptions as | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2287 | optional argument. If not provided, it checks the current theory. | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2288 | Options to the internal quickcheck invocations can be changed with | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2289 | common configuration declarations. | 
| 
d5d49bd4a7b4
adding documentation about find_unused_assms command and use_subtype option in the IsarRef
 bulwahn parents: 
46498diff
changeset | 2290 | |
| 31912 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2291 |   \end{description}
 | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2292 | *} | 
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2293 | |
| 
f5bd306f5e9d
more friendly wrt. PGs interpretation of compound *); added dedicated section on value and quickcheck
 haftmann parents: 
31254diff
changeset | 2294 | |
| 28752 | 2295 | section {* Unstructured case analysis and induction \label{sec:hol-induct-tac} *}
 | 
| 26849 | 2296 | |
| 2297 | text {*
 | |
| 27123 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2298 | The following tools of Isabelle/HOL support cases analysis and | 
| 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2299 | induction in unstructured tactic scripts; see also | 
| 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2300 |   \secref{sec:cases-induct} for proper Isar versions of similar ideas.
 | 
| 26849 | 2301 | |
| 2302 |   \begin{matharray}{rcl}
 | |
| 28761 
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
 wenzelm parents: 
28760diff
changeset | 2303 |     @{method_def (HOL) case_tac}@{text "\<^sup>*"} & : & @{text method} \\
 | 
| 
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
 wenzelm parents: 
28760diff
changeset | 2304 |     @{method_def (HOL) induct_tac}@{text "\<^sup>*"} & : & @{text method} \\
 | 
| 
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
 wenzelm parents: 
28760diff
changeset | 2305 |     @{method_def (HOL) ind_cases}@{text "\<^sup>*"} & : & @{text method} \\
 | 
| 
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
 wenzelm parents: 
28760diff
changeset | 2306 |     @{command_def (HOL) "inductive_cases"}@{text "\<^sup>*"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
 | 
| 26849 | 2307 |   \end{matharray}
 | 
| 2308 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2309 |   @{rail \<open>
 | 
| 42705 | 2310 |     @@{method (HOL) case_tac} @{syntax goal_spec}? @{syntax term} rule?
 | 
| 26849 | 2311 | ; | 
| 42705 | 2312 |     @@{method (HOL) induct_tac} @{syntax goal_spec}? (@{syntax insts} * @'and') rule?
 | 
| 26849 | 2313 | ; | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2314 |     @@{method (HOL) ind_cases} (@{syntax prop}+) (@'for' (@{syntax name}+))?
 | 
| 26849 | 2315 | ; | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2316 |     @@{command (HOL) inductive_cases} (@{syntax thmdecl}? (@{syntax prop}+) + @'and')
 | 
| 26849 | 2317 | ; | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2318 |     rule: 'rule' ':' @{syntax thmref}
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2319 | \<close>} | 
| 26849 | 2320 | |
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 2321 |   \begin{description}
 | 
| 26849 | 2322 | |
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 2323 |   \item @{method (HOL) case_tac} and @{method (HOL) induct_tac} admit
 | 
| 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 2324 | to reason about inductive types. Rules are selected according to | 
| 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 2325 |   the declarations by the @{attribute cases} and @{attribute induct}
 | 
| 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 2326 |   attributes, cf.\ \secref{sec:cases-induct}.  The @{command (HOL)
 | 
| 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 2327 | datatype} package already takes care of this. | 
| 27123 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2328 | |
| 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2329 | These unstructured tactics feature both goal addressing and dynamic | 
| 26849 | 2330 |   instantiation.  Note that named rule cases are \emph{not} provided
 | 
| 27123 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2331 |   as would be by the proper @{method cases} and @{method induct} proof
 | 
| 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2332 |   methods (see \secref{sec:cases-induct}).  Unlike the @{method
 | 
| 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2333 |   induct} method, @{method induct_tac} does not handle structured rule
 | 
| 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2334 | statements, only the compact object-logic conclusion of the subgoal | 
| 
11fcdd5897dd
case_tac/induct_tac: use same declarations as cases/induct;
 wenzelm parents: 
27103diff
changeset | 2335 | being addressed. | 
| 42123 | 2336 | |
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 2337 |   \item @{method (HOL) ind_cases} and @{command (HOL)
 | 
| 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 2338 |   "inductive_cases"} provide an interface to the internal @{ML_text
 | 
| 26860 | 2339 | mk_cases} operation. Rules are simplified in an unrestricted | 
| 2340 | forward manner. | |
| 26849 | 2341 | |
| 2342 |   While @{method (HOL) ind_cases} is a proof method to apply the
 | |
| 2343 |   result immediately as elimination rules, @{command (HOL)
 | |
| 2344 | "inductive_cases"} provides case split theorems at the theory level | |
| 2345 |   for later use.  The @{keyword "for"} argument of the @{method (HOL)
 | |
| 2346 | ind_cases} method allows to specify a list of variables that should | |
| 2347 | be generalized before applying the resulting rule. | |
| 2348 | ||
| 28760 
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
 wenzelm parents: 
28752diff
changeset | 2349 |   \end{description}
 | 
| 26849 | 2350 | *} | 
| 2351 | ||
| 2352 | ||
| 50109 | 2353 | chapter {* Executable code *}
 | 
| 26849 | 2354 | |
| 42627 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2355 | text {* For validation purposes, it is often useful to \emph{execute}
 | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2356 | specifications. In principle, execution could be simulated by | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2357 | Isabelle's inference kernel, i.e. by a combination of resolution and | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2358 | simplification. Unfortunately, this approach is rather inefficient. | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2359 | A more efficient way of executing specifications is to translate | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2360 | them into a functional programming language such as ML. | 
| 26849 | 2361 | |
| 45192 | 2362 | Isabelle provides a generic framework to support code generation | 
| 42627 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2363 | from executable specifications. Isabelle/HOL instantiates these | 
| 45192 | 2364 | mechanisms in a way that is amenable to end-user applications. Code | 
| 2365 | can be generated for functional programs (including overloading | |
| 2366 |   using type classes) targeting SML \cite{SML}, OCaml \cite{OCaml},
 | |
| 2367 |   Haskell \cite{haskell-revised-report} and Scala
 | |
| 42627 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2368 |   \cite{scala-overview-tech-report}.  Conceptually, code generation is
 | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2369 |   split up in three steps: \emph{selection} of code theorems,
 | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2370 |   \emph{translation} into an abstract executable view and
 | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2371 |   \emph{serialization} to a specific \emph{target language}.
 | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2372 | Inductive specifications can be executed using the predicate | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2373 |   compiler which operates within HOL.  See \cite{isabelle-codegen} for
 | 
| 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2374 | an introduction. | 
| 37422 | 2375 | |
| 2376 |   \begin{matharray}{rcl}
 | |
| 2377 |     @{command_def (HOL) "export_code"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
 | |
| 2378 |     @{attribute_def (HOL) code} & : & @{text attribute} \\
 | |
| 2379 |     @{command_def (HOL) "code_datatype"} & : & @{text "theory \<rightarrow> theory"} \\
 | |
| 2380 |     @{command_def (HOL) "print_codesetup"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
 | |
| 45232 
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
 bulwahn parents: 
45192diff
changeset | 2381 |     @{attribute_def (HOL) code_unfold} & : & @{text attribute} \\
 | 
| 37422 | 2382 |     @{attribute_def (HOL) code_post} & : & @{text attribute} \\
 | 
| 46028 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2383 |     @{attribute_def (HOL) code_abbrev} & : & @{text attribute} \\
 | 
| 37422 | 2384 |     @{command_def (HOL) "print_codeproc"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
 | 
| 2385 |     @{command_def (HOL) "code_thms"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
 | |
| 2386 |     @{command_def (HOL) "code_deps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
 | |
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2387 |     @{command_def (HOL) "code_reserved"} & : & @{text "theory \<rightarrow> theory"} \\
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2388 |     @{command_def (HOL) "code_printing"} & : & @{text "theory \<rightarrow> theory"} \\
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2389 |     @{command_def (HOL) "code_identifier"} & : & @{text "theory \<rightarrow> theory"} \\
 | 
| 37422 | 2390 |     @{command_def (HOL) "code_monad"} & : & @{text "theory \<rightarrow> theory"} \\
 | 
| 45408 
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
 bulwahn parents: 
45232diff
changeset | 2391 |     @{command_def (HOL) "code_reflect"} & : & @{text "theory \<rightarrow> theory"} \\
 | 
| 
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
 bulwahn parents: 
45232diff
changeset | 2392 |     @{command_def (HOL) "code_pred"} & : & @{text "theory \<rightarrow> proof(prove)"}
 | 
| 37422 | 2393 |   \end{matharray}
 | 
| 2394 | ||
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2395 |   @{rail \<open>
 | 
| 55686 
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
 haftmann parents: 
55677diff
changeset | 2396 |     @@{command (HOL) export_code} ( @'open' ) ? ( constexpr + ) \<newline>
 | 
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2397 |        ( ( @'in' target ( @'module_name' @{syntax string} ) ? \<newline>
 | 
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52378diff
changeset | 2398 |         ( @'file' @{syntax string} ) ? ( '(' args ')' ) ?) + ) ?
 | 
| 37422 | 2399 | ; | 
| 2400 | ||
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2401 |     const: @{syntax term}
 | 
| 37422 | 2402 | ; | 
| 2403 | ||
| 40711 
81bc73585eec
globbing constant expressions use more idiomatic underscore rather than star
 haftmann parents: 
40709diff
changeset | 2404 | constexpr: ( const | 'name._' | '_' ) | 
| 37422 | 2405 | ; | 
| 2406 | ||
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2407 |     typeconstructor: @{syntax nameref}
 | 
| 37422 | 2408 | ; | 
| 2409 | ||
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2410 |     class: @{syntax nameref}
 | 
| 37422 | 2411 | ; | 
| 2412 | ||
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2413 | target: 'SML' | 'OCaml' | 'Haskell' | 'Scala' | 'Eval' | 
| 37422 | 2414 | ; | 
| 2415 | ||
| 54890 
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
 haftmann parents: 
54338diff
changeset | 2416 |     @@{attribute (HOL) code} ( 'del' | 'equation' | 'abstype' | 'abstract'
 | 
| 
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
 haftmann parents: 
54338diff
changeset | 2417 | | 'drop:' ( const + ) | 'abort:' ( const + ) )? | 
| 37422 | 2418 | ; | 
| 2419 | ||
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2420 |     @@{command (HOL) code_datatype} ( const + )
 | 
| 37422 | 2421 | ; | 
| 2422 | ||
| 45232 
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
 bulwahn parents: 
45192diff
changeset | 2423 |     @@{attribute (HOL) code_unfold} ( 'del' ) ?
 | 
| 37422 | 2424 | ; | 
| 2425 | ||
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2426 |     @@{attribute (HOL) code_post} ( 'del' ) ?
 | 
| 37422 | 2427 | ; | 
| 2428 | ||
| 46028 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2429 |     @@{attribute (HOL) code_abbrev}
 | 
| 45232 
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
 bulwahn parents: 
45192diff
changeset | 2430 | ; | 
| 
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
 bulwahn parents: 
45192diff
changeset | 2431 | |
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2432 |     @@{command (HOL) code_thms} ( constexpr + ) ?
 | 
| 37422 | 2433 | ; | 
| 2434 | ||
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2435 |     @@{command (HOL) code_deps} ( constexpr + ) ?
 | 
| 37422 | 2436 | ; | 
| 2437 | ||
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2438 |     @@{command (HOL) code_reserved} target ( @{syntax string} + )
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2439 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2440 | |
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2441 | symbol_const: ( @'constant' const ) | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2442 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2443 | |
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2444 | symbol_typeconstructor: ( @'type_constructor' typeconstructor ) | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2445 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2446 | |
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2447 | symbol_class: ( @'type_class' class ) | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2448 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2449 | |
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2450 | symbol_class_relation: ( @'class_relation' class ( '<' | '\<subseteq>' ) class ) | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2451 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2452 | |
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2453 | symbol_class_instance: ( @'class_instance' typeconstructor @'::' class ) | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2454 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2455 | |
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2456 | symbol_module: ( @'code_module' name ) | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2457 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2458 | |
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2459 |     syntax: @{syntax string} | ( @'infix' | @'infixl' | @'infixr' ) @{syntax nat} @{syntax string}
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2460 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2461 | |
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2462 | printing_const: symbol_const ( '\<rightharpoonup>' | '=>' ) \<newline> | 
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2463 |       ( '(' target ')' syntax ? + @'and' )
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2464 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2465 | |
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2466 | printing_typeconstructor: symbol_typeconstructor ( '\<rightharpoonup>' | '=>' ) \<newline> | 
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2467 |       ( '(' target ')' syntax ? + @'and' )
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2468 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2469 | |
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2470 | printing_class: symbol_class ( '\<rightharpoonup>' | '=>' ) \<newline> | 
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2471 |       ( '(' target ')' @{syntax string} ? + @'and' )
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2472 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2473 | |
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2474 | printing_class_relation: symbol_class_relation ( '\<rightharpoonup>' | '=>' ) \<newline> | 
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2475 |       ( '(' target ')' @{syntax string} ? + @'and' )
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2476 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2477 | |
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2478 | printing_class_instance: symbol_class_instance ( '\<rightharpoonup>' | '=>' ) \<newline> | 
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2479 |       ( '(' target ')' '-' ? + @'and' )
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2480 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2481 | |
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2482 | printing_module: symbol_module ( '\<rightharpoonup>' | '=>' ) \<newline> | 
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2483 |       ( '(' target ')' ( @{syntax string} ( @'attach' ( const + ) ) ? ) ? + @'and' )
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2484 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2485 | |
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2486 |     @@{command (HOL) code_printing} ( ( printing_const | printing_typeconstructor
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2487 | | printing_class | printing_class_relation | printing_class_instance | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2488 | | printing_module ) + '|' ) | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2489 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2490 | |
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2491 |     @@{command (HOL) code_identifier} ( ( symbol_const | symbol_typeconstructor
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2492 | | symbol_class | symbol_class_relation | symbol_class_instance | 
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2493 | | symbol_module ) ( '\<rightharpoonup>' | '=>' ) \<newline> | 
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2494 |       ( '(' target ')' @{syntax string} ? + @'and' ) + '|' )
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2495 | ; | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2496 | |
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2497 |     @@{command (HOL) code_monad} const const target
 | 
| 37422 | 2498 | ; | 
| 2499 | ||
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2500 |     @@{command (HOL) code_reflect} @{syntax string} \<newline>
 | 
| 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2501 |       ( @'datatypes' ( @{syntax string} '=' ( '_' | ( @{syntax string} + '|' ) + @'and' ) ) ) ? \<newline>
 | 
| 42596 
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
 wenzelm parents: 
42215diff
changeset | 2502 |       ( @'functions' ( @{syntax string} + ) ) ? ( @'file' @{syntax string} ) ?
 | 
| 37422 | 2503 | ; | 
| 2504 | ||
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2505 |     @@{command (HOL) code_pred} \<newline> ('(' @'modes' ':' modedecl ')')? \<newline> const
 | 
| 45408 
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
 bulwahn parents: 
45232diff
changeset | 2506 | ; | 
| 
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
 bulwahn parents: 
45232diff
changeset | 2507 | |
| 55029 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2508 | modedecl: (modes | ((const ':' modes) \<newline> | 
| 
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
 wenzelm parents: 
54890diff
changeset | 2509 | (@'and' ((const ':' modes @'and') +))?)) | 
| 45408 
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
 bulwahn parents: 
45232diff
changeset | 2510 | ; | 
| 47859 | 2511 | |
| 45408 
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
 bulwahn parents: 
45232diff
changeset | 2512 | modes: mode @'as' const | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55029diff
changeset | 2513 | \<close>} | 
| 37422 | 2514 | |
| 2515 |   \begin{description}
 | |
| 2516 | ||
| 2517 |   \item @{command (HOL) "export_code"} generates code for a given list
 | |
| 39608 | 2518 | of constants in the specified target language(s). If no | 
| 2519 | serialization instruction is given, only abstract code is generated | |
| 2520 | internally. | |
| 37422 | 2521 | |
| 2522 | Constants may be specified by giving them literally, referring to | |
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 2523 |   all executable constants within a certain theory by giving @{text
 | 
| 55686 
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
 haftmann parents: 
55677diff
changeset | 2524 |   "name._"}, or referring to \emph{all} executable constants currently
 | 
| 
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
 haftmann parents: 
55677diff
changeset | 2525 |   available by giving @{text "_"}.
 | 
| 
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
 haftmann parents: 
55677diff
changeset | 2526 | |
| 
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
 haftmann parents: 
55677diff
changeset | 2527 | By default, exported identifiers are minimized per module. This | 
| 
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
 haftmann parents: 
55677diff
changeset | 2528 |   can be suppressed by prepending @{keyword "open"} before the list
 | 
| 
e99ed112d303
NEWS and documentation, including correction of long-overseen "*"
 haftmann parents: 
55677diff
changeset | 2529 | of contants. | 
| 37422 | 2530 | |
| 2531 | By default, for each involved theory one corresponding name space | |
| 52895 
a806aa7a5370
some documentation for adhoc overloading;
 Christian Sternagel parents: 
52637diff
changeset | 2532 | module is generated. Alternatively, a module name may be specified | 
| 37422 | 2533 |   after the @{keyword "module_name"} keyword; then \emph{all} code is
 | 
| 2534 | placed in this module. | |
| 2535 | ||
| 39608 | 2536 |   For \emph{SML}, \emph{OCaml} and \emph{Scala} the file specification
 | 
| 2537 |   refers to a single file; for \emph{Haskell}, it refers to a whole
 | |
| 2538 | directory, where code is generated in multiple files reflecting the | |
| 2539 | module hierarchy. Omitting the file specification denotes standard | |
| 37749 | 2540 | output. | 
| 37422 | 2541 | |
| 55677 | 2542 | Serializers take an optional list of arguments in parentheses. | 
| 39608 | 2543 |   For \emph{Haskell} a module name prefix may be given using the
 | 
| 2544 |   ``@{text "root:"}'' argument; ``@{text string_classes}'' adds a
 | |
| 2545 |   ``@{verbatim "deriving (Read, Show)"}'' clause to each appropriate
 | |
| 2546 | datatype declaration. | |
| 37422 | 2547 | |
| 52637 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2548 |   \item @{attribute (HOL) code} declare code equations for code
 | 
| 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2549 |   generation.  Variant @{text "code equation"} declares a conventional
 | 
| 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2550 |   equation as code equation.  Variants @{text "code abstype"} and
 | 
| 38462 
34d3de1254cd
formally document `code abstype` and `code abstract` attributes
 haftmann parents: 
37820diff
changeset | 2551 |   @{text "code abstract"} declare abstract datatype certificates or
 | 
| 
34d3de1254cd
formally document `code abstype` and `code abstract` attributes
 haftmann parents: 
37820diff
changeset | 2552 | code equations on abstract datatype representations respectively. | 
| 52637 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2553 |   Vanilla @{text "code"} falls back to @{text "code equation"}
 | 
| 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2554 |   or @{text "code abstype"} depending on the syntactic shape
 | 
| 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2555 |   of the underlying equation.  Variant @{text "code del"}
 | 
| 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2556 | deselects a code equation for code generation. | 
| 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2557 | |
| 54890 
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
 haftmann parents: 
54338diff
changeset | 2558 |   Variants @{text "code drop:"} and @{text "code abort:"} take
 | 
| 
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
 haftmann parents: 
54338diff
changeset | 2559 | a list of constant as arguments and drop all code equations declared | 
| 
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
 haftmann parents: 
54338diff
changeset | 2560 |   for them.  In the case of {text abort}, these constants then are
 | 
| 
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
 haftmann parents: 
54338diff
changeset | 2561 | are not required to have a definition by means of code equations; | 
| 
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
 haftmann parents: 
54338diff
changeset | 2562 | if needed these are implemented by program abort (exception) instead. | 
| 
cb892d835803
fundamental treatment of undefined vs. universally partial replaces code_abort
 haftmann parents: 
54338diff
changeset | 2563 | |
| 52637 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2564 | Usually packages introducing code equations provide a reasonable | 
| 
1501ebe39711
attribute "code" declares concrete and abstract code equations uniformly; added explicit "code equation" instead
 haftmann parents: 
52476diff
changeset | 2565 | default setup for selection. | 
| 37422 | 2566 | |
| 2567 |   \item @{command (HOL) "code_datatype"} specifies a constructor set
 | |
| 2568 | for a logical type. | |
| 2569 | ||
| 2570 |   \item @{command (HOL) "print_codesetup"} gives an overview on
 | |
| 2571 | selected code equations and code generator datatypes. | |
| 2572 | ||
| 45232 
eb56e1774c26
updating documentation: code_inline -> code_unfold; added documentation about attribute code_unfold_post
 bulwahn parents: 
45192diff
changeset | 2573 |   \item @{attribute (HOL) code_unfold} declares (or with option
 | 
| 46028 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2574 |   ``@{text "del"}'' removes) theorems which during preprocessing
 | 
| 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2575 | are applied as rewrite rules to any code equation or evaluation | 
| 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2576 | input. | 
| 37422 | 2577 | |
| 39608 | 2578 |   \item @{attribute (HOL) code_post} declares (or with option ``@{text
 | 
| 2579 | "del"}'' removes) theorems which are applied as rewrite rules to any | |
| 2580 | result of an evaluation. | |
| 37422 | 2581 | |
| 46028 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2582 |   \item @{attribute (HOL) code_abbrev} declares equations which are
 | 
| 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2583 | applied as rewrite rules to any result of an evaluation and | 
| 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2584 | symmetrically during preprocessing to any code equation or evaluation | 
| 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2585 | input. | 
| 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45944diff
changeset | 2586 | |
| 39608 | 2587 |   \item @{command (HOL) "print_codeproc"} prints the setup of the code
 | 
| 2588 | generator preprocessor. | |
| 37422 | 2589 | |
| 2590 |   \item @{command (HOL) "code_thms"} prints a list of theorems
 | |
| 2591 | representing the corresponding program containing all given | |
| 2592 | constants after preprocessing. | |
| 2593 | ||
| 2594 |   \item @{command (HOL) "code_deps"} visualizes dependencies of
 | |
| 2595 | theorems representing the corresponding program containing all given | |
| 2596 | constants after preprocessing. | |
| 2597 | ||
| 2598 |   \item @{command (HOL) "code_reserved"} declares a list of names as
 | |
| 2599 | reserved for a given target, preventing it to be shadowed by any | |
| 2600 | generated code. | |
| 2601 | ||
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2602 |   \item @{command (HOL) "code_printing"} associates a series of symbols
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2603 | (constants, type constructors, classes, class relations, instances, | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2604 | module names) with target-specific serializations; omitting a serialization | 
| 55372 | 2605 | deletes an existing serialization. | 
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2606 | |
| 37422 | 2607 |   \item @{command (HOL) "code_monad"} provides an auxiliary mechanism
 | 
| 2608 | to generate monadic code for Haskell. | |
| 2609 | ||
| 52378 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2610 |   \item @{command (HOL) "code_identifier"} associates a a series of symbols
 | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2611 | (constants, type constructors, classes, class relations, instances, | 
| 
08dbf9ff2140
documentation on code_printing and code_identifier
 haftmann parents: 
50879diff
changeset | 2612 | module names) with target-specific hints how these symbols shall be named. | 
| 55293 
42cf5802d36a
code generation: explicitly declared identifiers gain predence over implicit ones
 haftmann parents: 
55112diff
changeset | 2613 | These hints gain precedence over names for symbols with no hints at all. | 
| 
42cf5802d36a
code generation: explicitly declared identifiers gain predence over implicit ones
 haftmann parents: 
55112diff
changeset | 2614 | Conflicting hints are subject to name disambiguation. | 
| 
42cf5802d36a
code generation: explicitly declared identifiers gain predence over implicit ones
 haftmann parents: 
55112diff
changeset | 2615 |   \emph{Warning:} It is at the discretion
 | 
| 52476 | 2616 | of the user to ensure that name prefixes of identifiers in compound | 
| 2617 | statements like type classes or datatypes are still the same. | |
| 37422 | 2618 | |
| 39608 | 2619 |   \item @{command (HOL) "code_reflect"} without a ``@{text "file"}''
 | 
| 2620 | argument compiles code into the system runtime environment and | |
| 2621 | modifies the code generator setup that future invocations of system | |
| 2622 |   runtime code generation referring to one of the ``@{text
 | |
| 47859 | 2623 |   "datatypes"}'' or ``@{text "functions"}'' entities use these
 | 
| 2624 |   precompiled entities.  With a ``@{text "file"}'' argument, the
 | |
| 2625 | corresponding code is generated into that specified file without | |
| 2626 | modifying the code generator setup. | |
| 2627 | ||
| 2628 |   \item @{command (HOL) "code_pred"} creates code equations for a
 | |
| 2629 | predicate given a set of introduction rules. Optional mode | |
| 2630 | annotations determine which arguments are supposed to be input or | |
| 2631 | output. If alternative introduction rules are declared, one must | |
| 2632 | prove a corresponding elimination rule. | |
| 45408 
7156f63ce3c2
adding a minimal documentation about the code_pred command to the isar reference
 bulwahn parents: 
45232diff
changeset | 2633 | |
| 37422 | 2634 |   \end{description}
 | 
| 42627 
8749742785b8
moved material about old codegen to isar-ref manual;
 wenzelm parents: 
42626diff
changeset | 2635 | *} | 
| 37422 | 2636 | |
| 26840 | 2637 | end |