# HG changeset patch # User bulwahn # Date 1292584458 -3600 # Node ID 2e901158675eef36b6527414b279700988bc5a1f # Parent cf5e008d38c425531b2c4319985d6e915e20b067 adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real diff -r cf5e008d38c4 -r 2e901158675e src/HOL/Predicate_Compile_Examples/Hotel_Example_Small_Generator.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 \ 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 diff -r cf5e008d38c4 -r 2e901158675e src/HOL/Rat.thy --- 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 "\>" 60) no_notation scomp (infixl "\\" 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 diff -r cf5e008d38c4 -r 2e901158675e src/HOL/RealDef.thy --- 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 "\>" 60) no_notation scomp (infixl "\\" 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 diff -r cf5e008d38c4 -r 2e901158675e src/HOL/Smallcheck.thy --- 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 diff -r cf5e008d38c4 -r 2e901158675e src/HOL/ex/Quickcheck_Examples.thy --- 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 \ 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 \ 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 \ 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 \ z * z" +quickcheck[exhaustive, size = 10, expect = counterexample] +quickcheck[random, size = 10] +oops + end