diff -r f92bf6674699 -r 846c72206207 src/HOL/Isar_Examples/Hoare_Ex.thy --- a/src/HOL/Isar_Examples/Hoare_Ex.thy Mon Nov 02 11:43:02 2015 +0100 +++ b/src/HOL/Isar_Examples/Hoare_Ex.thy Mon Nov 02 13:58:19 2015 +0100 @@ -6,9 +6,9 @@ subsection \State spaces\ -text \First of all we provide a store of program variables that - occur in any of the programs considered later. Slightly unexpected - things may happen when attempting to work with undeclared variables.\ +text \First of all we provide a store of program variables that occur in any + of the programs considered later. Slightly unexpected things may happen + when attempting to work with undeclared variables.\ record vars = I :: nat @@ -16,29 +16,28 @@ N :: nat S :: nat -text \While all of our variables happen to have the same type, - nothing would prevent us from working with many-sorted programs as - well, or even polymorphic ones. Also note that Isabelle/HOL's - extensible record types even provides simple means to extend the - state space later.\ +text \While all of our variables happen to have the same type, nothing would + prevent us from working with many-sorted programs as well, or even + polymorphic ones. Also note that Isabelle/HOL's extensible record types + even provides simple means to extend the state space later.\ subsection \Basic examples\ -text \We look at few trivialities involving assignment and - sequential composition, in order to get an idea of how to work with - our formulation of Hoare Logic.\ +text \We look at few trivialities involving assignment and sequential + composition, in order to get an idea of how to work with our formulation + of Hoare Logic.\ -text \Using the basic @{text assign} rule directly is a bit +text \Using the basic \assign\ rule directly is a bit cumbersome.\ lemma "\ \\(N_update (\_. (2 * \N))) \ \\N = 10\\ \N := 2 * \N \\N = 10\" by (rule assign) -text \Certainly we want the state modification already done, e.g.\ - by simplification. The \name{hoare} method performs the basic state - update for us; we may apply the Simplifier afterwards to achieve - ``obvious'' consequences as well.\ +text \Certainly we want the state modification already done, e.g.\ by + simplification. The \hoare\ method performs the basic state update for us; + we may apply the Simplifier afterwards to achieve ``obvious'' consequences + as well.\ lemma "\ \True\ \N := 10 \\N = 10\" by hoare @@ -67,8 +66,8 @@ \\M = b \ \N = a\" by hoare simp -text \It is important to note that statements like the following one - can only be proven for each individual program variable. Due to the +text \It is important to note that statements like the following one can + only be proven for each individual program variable. Due to the extra-logical nature of record fields, we cannot formulate a theorem relating record selectors and updates schematically.\ @@ -84,9 +83,9 @@ oops -text \In the following assignments we make use of the consequence - rule in order to achieve the intended precondition. Certainly, the - \name{hoare} method is able to handle this case, too.\ +text \In the following assignments we make use of the consequence rule in + order to achieve the intended precondition. Certainly, the \hoare\ method + is able to handle this case, too.\ lemma "\ \\M = \N\ \M := \M + 1 \\M \ \N\" proof - @@ -114,10 +113,10 @@ subsection \Multiplication by addition\ -text \We now do some basic examples of actual \texttt{WHILE} - programs. This one is a loop for calculating the product of two - natural numbers, by iterated addition. We first give detailed - structured proof based on single-step Hoare rules.\ +text \We now do some basic examples of actual \<^verbatim>\WHILE\ programs. This one is + a loop for calculating the product of two natural numbers, by iterated + addition. We first give detailed structured proof based on single-step + Hoare rules.\ lemma "\ \\M = 0 \ \S = 0\ @@ -141,10 +140,10 @@ finally show ?thesis . qed -text \The subsequent version of the proof applies the @{text hoare} - method to reduce the Hoare statement to a purely logical problem - that can be solved fully automatically. Note that we have to - specify the \texttt{WHILE} loop invariant in the original statement.\ +text \The subsequent version of the proof applies the \hoare\ method to + reduce the Hoare statement to a purely logical problem that can be solved + fully automatically. Note that we have to specify the \<^verbatim>\WHILE\ loop + invariant in the original statement.\ lemma "\ \\M = 0 \ \S = 0\ @@ -157,15 +156,15 @@ subsection \Summing natural numbers\ -text \We verify an imperative program to sum natural numbers up to a - given limit. First some functional definition for proper - specification of the problem.\ +text \We verify an imperative program to sum natural numbers up to a given + limit. First some functional definition for proper specification of the + problem. -text \The following proof is quite explicit in the individual steps - taken, with the \name{hoare} method only applied locally to take - care of assignment and sequential composition. Note that we express - intermediate proof obligation in pure logic, without referring to - the state space.\ + \<^medskip> + The following proof is quite explicit in the individual steps taken, with + the \hoare\ method only applied locally to take care of assignment and + sequential composition. Note that we express intermediate proof obligation + in pure logic, without referring to the state space.\ theorem "\ \True\ @@ -203,9 +202,8 @@ finally show ?thesis . qed -text \The next version uses the @{text hoare} method, while still - explaining the resulting proof obligations in an abstract, - structured manner.\ +text \The next version uses the \hoare\ method, while still explaining the + resulting proof obligations in an abstract, structured manner.\ theorem "\ \True\ @@ -230,8 +228,8 @@ qed qed -text \Certainly, this proof may be done fully automatic as well, - provided that the invariant is given beforehand.\ +text \Certainly, this proof may be done fully automatic as well, provided + that the invariant is given beforehand.\ theorem "\ \True\ @@ -248,8 +246,8 @@ subsection \Time\ -text \A simple embedding of time in Hoare logic: function @{text - timeit} inserts an extra variable to keep track of the elapsed time.\ +text \A simple embedding of time in Hoare logic: function \timeit\ inserts + an extra variable to keep track of the elapsed time.\ record tstate = time :: nat