adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
authorbulwahn
Fri, 17 Dec 2010 12:14:18 +0100
changeset 41231 2e901158675e
parent 41223 cf5e008d38c4
child 41234 c99ed404cb11
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
src/HOL/Predicate_Compile_Examples/Hotel_Example_Small_Generator.thy
src/HOL/Rat.thy
src/HOL/RealDef.thy
src/HOL/Smallcheck.thy
src/HOL/ex/Quickcheck_Examples.thy
--- a/src/HOL/Predicate_Compile_Examples/Hotel_Example_Small_Generator.thy	Fri Dec 17 08:37:35 2010 +0100
+++ b/src/HOL/Predicate_Compile_Examples/Hotel_Example_Small_Generator.thy	Fri Dec 17 12:14:18 2010 +0100
@@ -50,7 +50,7 @@
 
 lemma
   "hotel s ==> feels_safe s r ==> g \<in> isin s r ==> owns s r = Some g"
-quickcheck[tester = small_generators_depth_14, finite_types = false, iterations = 1, size = 1, timeout = 60.0, expect = no_counterexample, timeout = 60]
+(*quickcheck[tester = small_generators_depth_14, finite_types = false, iterations = 1, size = 1, timeout = 60.0, expect = no_counterexample, timeout = 60]*)
 quickcheck[tester = small_generators_depth_15, finite_types = false, iterations = 1, size = 1, timeout = 60.0, expect = counterexample, timeout = 60]
 oops
 
--- a/src/HOL/Rat.thy	Fri Dec 17 08:37:35 2010 +0100
+++ b/src/HOL/Rat.thy	Fri Dec 17 12:14:18 2010 +0100
@@ -1132,6 +1132,17 @@
 no_notation fcomp (infixl "\<circ>>" 60)
 no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
 
+instantiation rat :: full_small
+begin
+
+definition
+  "full_small f d = full_small (%(k, kt). full_small (%(l, lt).
+     f (valterm_fract (Code_Numeral.int_of k, %_. Code_Evaluation.term_of (Code_Numeral.int_of k)) (Code_Numeral.int_of l, %_. Code_Evaluation.term_of (Code_Numeral.int_of l)))) d) d"
+
+instance ..
+
+end
+
 text {* Setup for SML code generator *}
 
 types_code
--- a/src/HOL/RealDef.thy	Fri Dec 17 08:37:35 2010 +0100
+++ b/src/HOL/RealDef.thy	Fri Dec 17 12:14:18 2010 +0100
@@ -1768,6 +1768,16 @@
 no_notation fcomp (infixl "\<circ>>" 60)
 no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
 
+instantiation real :: full_small
+begin
+
+definition
+  "full_small f d = full_small (%r. f (valterm_ratreal r)) d"
+
+instance ..
+
+end
+
 text {* Setup for SML code generator *}
 
 types_code
--- a/src/HOL/Smallcheck.thy	Fri Dec 17 08:37:35 2010 +0100
+++ b/src/HOL/Smallcheck.thy	Fri Dec 17 12:14:18 2010 +0100
@@ -67,6 +67,31 @@
 
 end
 
+instantiation code_numeral :: full_small
+begin
+
+function full_small_code_numeral' :: "(code_numeral * (unit => term) => term list option) => code_numeral => code_numeral => term list option"
+  where "full_small_code_numeral' f d i = (if d < i then None else (case f (i, %_. Code_Evaluation.term_of i) of Some t => Some t | None => full_small_code_numeral' f d (i + 1)))"
+by pat_completeness auto
+
+termination 
+  by (relation "measure (%(_, d, i). Code_Numeral.nat_of (d + 1 - i))") auto
+
+definition "full_small f d = full_small_code_numeral' f d 0"
+
+instance ..
+
+end
+
+instantiation nat :: full_small
+begin
+
+definition "full_small f d = full_small (%(x, xt). f (Code_Numeral.nat_of x, %_. Code_Evaluation.term_of (Code_Numeral.nat_of x))) d"
+
+instance ..
+
+end
+
 instantiation int :: full_small
 begin
 
--- a/src/HOL/ex/Quickcheck_Examples.thy	Fri Dec 17 08:37:35 2010 +0100
+++ b/src/HOL/ex/Quickcheck_Examples.thy	Fri Dec 17 12:14:18 2010 +0100
@@ -6,7 +6,7 @@
 header {* Examples for the 'quickcheck' command *}
 
 theory Quickcheck_Examples
-imports Main
+imports Complex_Main
 begin
 
 text {*
@@ -237,7 +237,7 @@
 quickcheck[exhaustive, expect = counterexample]
 oops
 
-section {* Examples with quantifiers *}
+subsection {* Examples with quantifiers *}
 
 text {*
   These examples show that we can handle quantifiers.
@@ -258,4 +258,34 @@
   quickcheck[expect = counterexample]
 oops
 
+subsection {* Examples with numerical types *}
+
+text {*
+Quickcheck supports the common types nat, int, rat and real.
+*}
+
+lemma
+  "(x :: nat) > 0 ==> y > 0 ==> z > 0 ==> x * x + y * y \<noteq> z * z"
+quickcheck[exhaustive, size = 10, expect = counterexample]
+quickcheck[random, size = 10]
+oops
+
+lemma
+  "(x :: int) > 0 ==> y > 0 ==> z > 0 ==> x * x + y * y \<noteq> z * z"
+quickcheck[exhaustive, size = 10, expect = counterexample]
+quickcheck[random, size = 10]
+oops
+
+lemma
+  "(x :: rat) > 0 ==> y > 0 ==> z > 0 ==> x * x + y * y \<noteq> z * z"
+quickcheck[exhaustive, size = 10, expect = counterexample]
+quickcheck[random, size = 10]
+oops
+
+lemma
+  "(x :: real) > 0 ==> y > 0 ==> z > 0 ==> x * x + y * y \<noteq> z * z"
+quickcheck[exhaustive, size = 10, expect = counterexample]
+quickcheck[random, size = 10]
+oops
+
 end