quickcheck setup for float, inspired by rat::{exhaustive,full_exhaustive,random}
authorimmler
Wed, 12 Nov 2014 17:37:43 +0100
changeset 58987 119680ebf37c
parent 58986 ec7373051a6c
child 58988 6ebf918128b9
quickcheck setup for float, inspired by rat::{exhaustive,full_exhaustive,random}
src/HOL/Library/Float.thy
--- a/src/HOL/Library/Float.thy	Wed Nov 12 17:37:43 2014 +0100
+++ b/src/HOL/Library/Float.thy	Wed Nov 12 17:37:43 2014 +0100
@@ -260,6 +260,46 @@
     and float_of_neg_numeral[simp]: "- numeral k = float_of (- numeral k)"
   unfolding real_of_float_eq by simp_all
 
+subsection {* Quickcheck *}
+
+instantiation float :: exhaustive
+begin
+
+definition exhaustive_float where
+  "exhaustive_float f d =
+    Quickcheck_Exhaustive.exhaustive (%x. Quickcheck_Exhaustive.exhaustive (%y. f (Float x y)) d) d"
+
+instance ..
+
+end
+
+definition (in term_syntax) [code_unfold]:
+  "valtermify_float x y = Code_Evaluation.valtermify Float {\<cdot>} x {\<cdot>} y"
+
+instantiation float :: full_exhaustive
+begin
+
+definition full_exhaustive_float where
+  "full_exhaustive_float f d =
+    Quickcheck_Exhaustive.full_exhaustive
+      (\<lambda>x. Quickcheck_Exhaustive.full_exhaustive (\<lambda>y. f (valtermify_float x y)) d) d"
+
+instance ..
+
+end
+
+instantiation float :: random
+begin
+
+definition "Quickcheck_Random.random i =
+  scomp (Quickcheck_Random.random (2 ^ nat_of_natural i))
+    (\<lambda>man. scomp (Quickcheck_Random.random i) (\<lambda>exp. Pair (valtermify_float man exp)))"
+
+instance ..
+
+end
+
+
 subsection {* Represent floats as unique mantissa and exponent *}
 
 lemma int_induct_abs[case_names less]: