src/HOL/Tools/Quickcheck/exhaustive_generators.ML
changeset 45753 196697f71488
parent 45732 ac5775bbc748
child 45754 394ecd91434a
equal deleted inserted replaced
45752:b5db02fa9536 45753:196697f71488
   358   let
   358   let
   359     val thy = Proof_Context.theory_of ctxt
   359     val thy = Proof_Context.theory_of ctxt
   360     val ctxt' = Variable.auto_fixes t ctxt
   360     val ctxt' = Variable.auto_fixes t ctxt
   361     val names = Term.add_free_names t []
   361     val names = Term.add_free_names t []
   362     val frees = map Free (Term.add_frees t [])
   362     val frees = map Free (Term.add_frees t [])
   363     val ([depth_name], ctxt'') = Variable.variant_fixes ["depth"] ctxt'
   363     val ([depth_name, genuine_only_name], ctxt'') =
       
   364       Variable.variant_fixes ["depth", "genuine_only"] ctxt'
   364     val (term_names, ctxt''') = Variable.variant_fixes (map (prefix "t_") names) ctxt''
   365     val (term_names, ctxt''') = Variable.variant_fixes (map (prefix "t_") names) ctxt''
   365     val depth = Free (depth_name, @{typ code_numeral})
   366     val depth = Free (depth_name, @{typ code_numeral})
       
   367     val genuine_only = Free (depth_name, @{typ bool})    
   366     val term_vars = map (fn n => Free (n, @{typ "unit => term"})) term_names
   368     val term_vars = map (fn n => Free (n, @{typ "unit => term"})) term_names
   367     fun lookup v = the (AList.lookup (op =) (names ~~ (frees ~~ term_vars)) v)
   369     fun lookup v = the (AList.lookup (op =) (names ~~ (frees ~~ term_vars)) v)
   368     val return = mk_return (HOLogic.mk_list @{typ term}
   370     val return = mk_return (HOLogic.mk_list @{typ term}
   369           (map (fn v => v $ @{term "()"}) term_vars @ map mk_safe_term eval_terms))
   371           (map (fn v => v $ @{term "()"}) term_vars @ map mk_safe_term eval_terms))
   370     fun mk_exhaustive_closure (free as Free (_, T), term_var) t =
   372     fun mk_exhaustive_closure (free as Free (_, T), term_var) t =
   371       if Sign.of_sort thy (T, @{sort enum}) then
   373       if Sign.of_sort thy (T, @{sort enum}) then
   372         Const (@{const_name "Quickcheck_Exhaustive.check_all_class.check_all"}, check_allT T)
   374         Const (@{const_name "Quickcheck_Exhaustive.check_all_class.check_all"}, check_allT T)
   373           $ (HOLogic.split_const (T, @{typ "unit => term"}, resultT) 
   375           $ (HOLogic.split_const (T, @{typ "unit => term"}, resultT)
   374             $ lambda free (lambda term_var t))
   376             $ lambda free (lambda term_var t))
   375       else
   377       else
   376         Const (@{const_name "Quickcheck_Exhaustive.full_exhaustive_class.full_exhaustive"}, full_exhaustiveT T)
   378         Const (@{const_name "Quickcheck_Exhaustive.full_exhaustive_class.full_exhaustive"}, full_exhaustiveT T)
   377           $ (HOLogic.split_const (T, @{typ "unit => term"}, resultT)
   379           $ (HOLogic.split_const (T, @{typ "unit => term"}, resultT)
   378             $ lambda free (lambda term_var t)) $ depth
   380             $ lambda free (lambda term_var t)) $ depth
   379     val none_t = Const (@{const_name "None"}, resultT)
   381     val none_t = Const (@{const_name "None"}, resultT)
   380     val mk_if = Quickcheck_Common.mk_safe_if ctxt
   382     val mk_if = Quickcheck_Common.mk_safe_if ctxt
   381     val mk_test_term = mk_test_term lookup mk_exhaustive_closure mk_if none_t return ctxt
   383     val mk_test_term = mk_test_term lookup mk_exhaustive_closure mk_if none_t return ctxt
   382   in lambda depth (mk_test_term t) end
   384   in lambda genuine_only (lambda depth (mk_test_term t)) end
   383 
   385 
   384 fun mk_parametric_generator_expr mk_generator_expr =
   386 fun mk_parametric_generator_expr mk_generator_expr =
   385   Quickcheck_Common.gen_mk_parametric_generator_expr 
   387   Quickcheck_Common.gen_mk_parametric_generator_expr 
   386     ((mk_generator_expr, absdummy @{typ "code_numeral"} (Const (@{const_name "None"}, resultT))),
   388     ((mk_generator_expr, absdummy @{typ "code_numeral"} (Const (@{const_name "None"}, resultT))),
   387       @{typ "code_numeral"} --> resultT)
   389       @{typ "code_numeral"} --> resultT)