src/HOL/Isar_Examples/Hoare_Ex.thy
changeset 60410 a197387e1854
parent 58882 6e2010ab8bd9
child 60416 e1ff959f4f1b
equal deleted inserted replaced
60409:240ad53041c9 60410:a197387e1854
    97   finally show ?thesis .
    97   finally show ?thesis .
    98 qed
    98 qed
    99 
    99 
   100 lemma "\<turnstile> \<lbrace>\<acute>M = \<acute>N\<rbrace> \<acute>M := \<acute>M + 1 \<lbrace>\<acute>M \<noteq> \<acute>N\<rbrace>"
   100 lemma "\<turnstile> \<lbrace>\<acute>M = \<acute>N\<rbrace> \<acute>M := \<acute>M + 1 \<lbrace>\<acute>M \<noteq> \<acute>N\<rbrace>"
   101 proof -
   101 proof -
   102   have "\<And>m n::nat. m = n \<longrightarrow> m + 1 \<noteq> n"
   102   have "m = n \<longrightarrow> m + 1 \<noteq> n" for m n :: nat
   103       -- \<open>inclusion of assertions expressed in ``pure'' logic,\<close>
   103       -- \<open>inclusion of assertions expressed in ``pure'' logic,\<close>
   104       -- \<open>without mentioning the state space\<close>
   104       -- \<open>without mentioning the state space\<close>
   105     by simp
   105     by simp
   106   also have "\<turnstile> \<lbrace>\<acute>M + 1 \<noteq> \<acute>N\<rbrace> \<acute>M := \<acute>M + 1 \<lbrace>\<acute>M \<noteq> \<acute>N\<rbrace>"
   106   also have "\<turnstile> \<lbrace>\<acute>M + 1 \<noteq> \<acute>N\<rbrace> \<acute>M := \<acute>M + 1 \<lbrace>\<acute>M \<noteq> \<acute>N\<rbrace>"
   107     by hoare
   107     by hoare
   190     finally show ?thesis .
   190     finally show ?thesis .
   191   qed
   191   qed
   192   also have "\<turnstile> \<dots> ?while \<lbrace>?inv \<acute>S \<acute>I \<and> \<not> \<acute>I \<noteq> n\<rbrace>"
   192   also have "\<turnstile> \<dots> ?while \<lbrace>?inv \<acute>S \<acute>I \<and> \<not> \<acute>I \<noteq> n\<rbrace>"
   193   proof
   193   proof
   194     let ?body = "\<acute>S := \<acute>S + \<acute>I; \<acute>I := \<acute>I + 1"
   194     let ?body = "\<acute>S := \<acute>S + \<acute>I; \<acute>I := \<acute>I + 1"
   195     have "\<And>s i. ?inv s i \<and> i \<noteq> n \<longrightarrow> ?inv (s + i) (i + 1)"
   195     have "?inv s i \<and> i \<noteq> n \<longrightarrow> ?inv (s + i) (i + 1)" for s i
   196       by simp
   196       by simp
   197     also have "\<turnstile> \<lbrace>\<acute>S + \<acute>I = ?sum (\<acute>I + 1)\<rbrace> ?body \<lbrace>?inv \<acute>S \<acute>I\<rbrace>"
   197     also have "\<turnstile> \<lbrace>\<acute>S + \<acute>I = ?sum (\<acute>I + 1)\<rbrace> ?body \<lbrace>?inv \<acute>S \<acute>I\<rbrace>"
   198       by hoare
   198       by hoare
   199     finally show "\<turnstile> \<lbrace>?inv \<acute>S \<acute>I \<and> \<acute>I \<noteq> n\<rbrace> ?body \<lbrace>?inv \<acute>S \<acute>I\<rbrace>" .
   199     finally show "\<turnstile> \<lbrace>?inv \<acute>S \<acute>I \<and> \<acute>I \<noteq> n\<rbrace> ?body \<lbrace>?inv \<acute>S \<acute>I\<rbrace>" .
   200   qed
   200   qed
   201   also have "\<And>s i. s = ?sum i \<and> \<not> i \<noteq> n \<longrightarrow> s = ?sum n"
   201   also have "s = ?sum i \<and> \<not> i \<noteq> n \<longrightarrow> s = ?sum n" for s i
   202     by simp
   202     by simp
   203   finally show ?thesis .
   203   finally show ?thesis .
   204 qed
   204 qed
   205 
   205 
   206 text \<open>The next version uses the @{text hoare} method, while still
   206 text \<open>The next version uses the @{text hoare} method, while still