src/HOL/Quickcheck_Exhaustive.thy
changeset 72607 feebdaa346e5
parent 69605 a96320074298
equal deleted inserted replaced
72606:e7ee815b04bf 72607:feebdaa346e5
   178 
   178 
   179 instance ..
   179 instance ..
   180 
   180 
   181 end
   181 end
   182 
   182 
   183 definition (in term_syntax)
   183 context
       
   184   includes term_syntax
       
   185 begin
       
   186 
       
   187 definition
   184   [code_unfold]: "valtermify_pair x y =
   188   [code_unfold]: "valtermify_pair x y =
   185     Code_Evaluation.valtermify (Pair :: 'a::typerep \<Rightarrow> 'b::typerep \<Rightarrow> 'a \<times> 'b) {\<cdot>} x {\<cdot>} y"
   189     Code_Evaluation.valtermify (Pair :: 'a::typerep \<Rightarrow> 'b::typerep \<Rightarrow> 'a \<times> 'b) {\<cdot>} x {\<cdot>} y"
       
   190 
       
   191 end
   186 
   192 
   187 instantiation prod :: (full_exhaustive, full_exhaustive) full_exhaustive
   193 instantiation prod :: (full_exhaustive, full_exhaustive) full_exhaustive
   188 begin
   194 begin
   189 
   195 
   190 definition "full_exhaustive f d =
   196 definition "full_exhaustive f d =
   251   "valtermify_absdummy =
   257   "valtermify_absdummy =
   252     (\<lambda>(v, t).
   258     (\<lambda>(v, t).
   253       (\<lambda>_::'a. v,
   259       (\<lambda>_::'a. v,
   254         \<lambda>u::unit. Code_Evaluation.Abs (STR ''x'') (Typerep.typerep TYPE('a::typerep)) (t ())))"
   260         \<lambda>u::unit. Code_Evaluation.Abs (STR ''x'') (Typerep.typerep TYPE('a::typerep)) (t ())))"
   255 
   261 
   256 definition (in term_syntax)
   262 context
       
   263   includes term_syntax
       
   264 begin
       
   265 
       
   266 definition
   257   [code_unfold]: "valtermify_fun_upd g a b =
   267   [code_unfold]: "valtermify_fun_upd g a b =
   258     Code_Evaluation.valtermify
   268     Code_Evaluation.valtermify
   259       (fun_upd :: ('a::typerep \<Rightarrow> 'b::typerep) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'b) {\<cdot>} g {\<cdot>} a {\<cdot>} b"
   269       (fun_upd :: ('a::typerep \<Rightarrow> 'b::typerep) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'b) {\<cdot>} g {\<cdot>} a {\<cdot>} b"
       
   270 
       
   271 end
   260 
   272 
   261 instantiation "fun" :: ("{equal,full_exhaustive}", full_exhaustive) full_exhaustive
   273 instantiation "fun" :: ("{equal,full_exhaustive}", full_exhaustive) full_exhaustive
   262 begin
   274 begin
   263 
   275 
   264 fun full_exhaustive_fun' ::
   276 fun full_exhaustive_fun' ::
   294   "check_all_n_lists f n =
   306   "check_all_n_lists f n =
   295     (if n = 0 then f ([], (\<lambda>_. []))
   307     (if n = 0 then f ([], (\<lambda>_. []))
   296      else check_all (\<lambda>(x, xt).
   308      else check_all (\<lambda>(x, xt).
   297       check_all_n_lists (\<lambda>(xs, xst). f ((x # xs), (\<lambda>_. (xt () # xst ())))) (n - 1)))"
   309       check_all_n_lists (\<lambda>(xs, xst). f ((x # xs), (\<lambda>_. (xt () # xst ())))) (n - 1)))"
   298 
   310 
   299 definition (in term_syntax)
   311 context
       
   312   includes term_syntax
       
   313 begin
       
   314 
       
   315 definition
   300   [code_unfold]: "termify_fun_upd g a b =
   316   [code_unfold]: "termify_fun_upd g a b =
   301     (Code_Evaluation.termify
   317     (Code_Evaluation.termify
   302       (fun_upd :: ('a::typerep \<Rightarrow> 'b::typerep) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'b) <\<cdot>> g <\<cdot>> a <\<cdot>> b)"
   318       (fun_upd :: ('a::typerep \<Rightarrow> 'b::typerep) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'b) <\<cdot>> g <\<cdot>> a <\<cdot>> b)"
       
   319 
       
   320 end
   303 
   321 
   304 definition mk_map_term ::
   322 definition mk_map_term ::
   305   "(unit \<Rightarrow> typerep) \<Rightarrow> (unit \<Rightarrow> typerep) \<Rightarrow>
   323   "(unit \<Rightarrow> typerep) \<Rightarrow> (unit \<Rightarrow> typerep) \<Rightarrow>
   306     (unit \<Rightarrow> term list) \<Rightarrow> (unit \<Rightarrow> term list) \<Rightarrow> unit \<Rightarrow> term"
   324     (unit \<Rightarrow> term list) \<Rightarrow> (unit \<Rightarrow> term list) \<Rightarrow> unit \<Rightarrow> term"
   307   where "mk_map_term T1 T2 domm rng =
   325   where "mk_map_term T1 T2 domm rng =
   355 
   373 
   356 instance ..
   374 instance ..
   357 
   375 
   358 end
   376 end
   359 
   377 
   360 fun (in term_syntax) check_all_subsets ::
   378 context
       
   379   includes term_syntax
       
   380 begin
       
   381 
       
   382 fun check_all_subsets ::
   361   "(('a::typerep) set \<times> (unit \<Rightarrow> term) \<Rightarrow> (bool \<times> term list) option) \<Rightarrow>
   383   "(('a::typerep) set \<times> (unit \<Rightarrow> term) \<Rightarrow> (bool \<times> term list) option) \<Rightarrow>
   362     ('a \<times> (unit \<Rightarrow> term)) list \<Rightarrow> (bool \<times> term list) option"
   384     ('a \<times> (unit \<Rightarrow> term)) list \<Rightarrow> (bool \<times> term list) option"
   363 where
   385 where
   364   "check_all_subsets f [] = f valterm_emptyset"
   386   "check_all_subsets f [] = f valterm_emptyset"
   365 | "check_all_subsets f (x # xs) =
   387 | "check_all_subsets f (x # xs) =
   366     check_all_subsets (\<lambda>s. case f s of Some ts \<Rightarrow> Some ts | None \<Rightarrow> f (valtermify_insert x s)) xs"
   388     check_all_subsets (\<lambda>s. case f s of Some ts \<Rightarrow> Some ts | None \<Rightarrow> f (valtermify_insert x s)) xs"
   367 
   389 
   368 
   390 definition
   369 definition (in term_syntax)
       
   370   [code_unfold]: "term_emptyset = Code_Evaluation.termify ({} :: ('a::typerep) set)"
   391   [code_unfold]: "term_emptyset = Code_Evaluation.termify ({} :: ('a::typerep) set)"
   371 
   392 
   372 definition (in term_syntax)
   393 definition
   373   [code_unfold]: "termify_insert x s =
   394   [code_unfold]: "termify_insert x s =
   374     Code_Evaluation.termify (insert :: ('a::typerep) \<Rightarrow> 'a set \<Rightarrow> 'a set)  <\<cdot>> x <\<cdot>> s"
   395     Code_Evaluation.termify (insert :: ('a::typerep) \<Rightarrow> 'a set \<Rightarrow> 'a set)  <\<cdot>> x <\<cdot>> s"
   375 
   396 
   376 definition (in term_syntax) setify :: "('a::typerep) itself \<Rightarrow> term list \<Rightarrow> term"
   397 definition setify :: "('a::typerep) itself \<Rightarrow> term list \<Rightarrow> term"
   377 where
   398 where
   378   "setify T ts = foldr (termify_insert T) ts (term_emptyset T)"
   399   "setify T ts = foldr (termify_insert T) ts (term_emptyset T)"
       
   400 
       
   401 end
   379 
   402 
   380 instantiation set :: (check_all) check_all
   403 instantiation set :: (check_all) check_all
   381 begin
   404 begin
   382 
   405 
   383 definition
   406 definition
   421 
   444 
   422 instance ..
   445 instance ..
   423 
   446 
   424 end
   447 end
   425 
   448 
   426 definition (in term_syntax) [code_unfold]:
   449 context
       
   450   includes term_syntax
       
   451 begin
       
   452 
       
   453 definition [code_unfold]:
   427   "termify_pair x y =
   454   "termify_pair x y =
   428     Code_Evaluation.termify (Pair :: 'a::typerep \<Rightarrow> 'b :: typerep \<Rightarrow> 'a * 'b) <\<cdot>> x <\<cdot>> y"
   455     Code_Evaluation.termify (Pair :: 'a::typerep \<Rightarrow> 'b :: typerep \<Rightarrow> 'a * 'b) <\<cdot>> x <\<cdot>> y"
       
   456 
       
   457 end
   429 
   458 
   430 instantiation prod :: (check_all, check_all) check_all
   459 instantiation prod :: (check_all, check_all) check_all
   431 begin
   460 begin
   432 
   461 
   433 definition "check_all f = check_all (\<lambda>x. check_all (\<lambda>y. f (valtermify_pair x y)))"
   462 definition "check_all f = check_all (\<lambda>x. check_all (\<lambda>y. f (valtermify_pair x y)))"
   440 
   469 
   441 instance ..
   470 instance ..
   442 
   471 
   443 end
   472 end
   444 
   473 
   445 definition (in term_syntax)
   474 context
       
   475   includes term_syntax
       
   476 begin
       
   477 
       
   478 definition
   446   [code_unfold]: "valtermify_Inl x =
   479   [code_unfold]: "valtermify_Inl x =
   447     Code_Evaluation.valtermify (Inl :: 'a::typerep \<Rightarrow> 'a + 'b :: typerep) {\<cdot>} x"
   480     Code_Evaluation.valtermify (Inl :: 'a::typerep \<Rightarrow> 'a + 'b :: typerep) {\<cdot>} x"
   448 
   481 
   449 definition (in term_syntax)
   482 definition
   450   [code_unfold]: "valtermify_Inr x =
   483   [code_unfold]: "valtermify_Inr x =
   451     Code_Evaluation.valtermify (Inr :: 'b::typerep \<Rightarrow> 'a::typerep + 'b) {\<cdot>} x"
   484     Code_Evaluation.valtermify (Inr :: 'b::typerep \<Rightarrow> 'a::typerep + 'b) {\<cdot>} x"
       
   485 
       
   486 end
   452 
   487 
   453 instantiation sum :: (check_all, check_all) check_all
   488 instantiation sum :: (check_all, check_all) check_all
   454 begin
   489 begin
   455 
   490 
   456 definition
   491 definition