New example involving functions.
authorberghofe
Thu, 10 Jan 2008 19:25:08 +0100
changeset 25891 1bd12187a96e
parent 25890 0ba401ddbaed
child 25892 3ff9d646a66a
New example involving functions.
src/HOL/ex/Quickcheck_Examples.thy
--- a/src/HOL/ex/Quickcheck_Examples.thy	Thu Jan 10 19:24:23 2008 +0100
+++ b/src/HOL/ex/Quickcheck_Examples.thy	Thu Jan 10 19:25:08 2008 +0100
@@ -41,6 +41,22 @@
   quickcheck
   oops
 
+text {* An example involving functions inside other data structures *}
+
+consts app :: "('a \<Rightarrow> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a"
+
+primrec
+  "app [] x = x"
+  "app (f # fs) x = app fs (f x)"
+
+lemma "app (fs @ gs) x = app gs (app fs x)"
+  quickcheck
+  by (induct fs arbitrary: x) simp_all
+
+lemma "app (fs @ gs) x = app fs (app gs x)"
+  quickcheck
+  oops
+
 consts
   occurs :: "'a \<Rightarrow> 'a list \<Rightarrow> nat"
 primrec
@@ -53,7 +69,7 @@
   "del1 a [] = []"
   "del1 a (x#xs) = (if (x=a) then xs else (x#del1 a xs))"
 
-(* A lemma, you'd think to be true from our experience with delAll*)
+text {* A lemma, you'd think to be true from our experience with delAll *}
 lemma "Suc (occurs a (del1 a xs)) = occurs a xs"
   -- {* Wrong. Precondition needed.*}
   quickcheck