src/HOL/Tools/smallvalue_generators.ML
changeset 41178 f4d3acf0c4cc
parent 41177 810a885decee
child 41472 f6ab14e61604
equal deleted inserted replaced
41177:810a885decee 41178:f4d3acf0c4cc
   278       Const (@{const_name "Smallcheck.full_small_class.full_small"}, full_smallT T)
   278       Const (@{const_name "Smallcheck.full_small_class.full_small"}, full_smallT T)
   279         $ (HOLogic.split_const (T, @{typ "unit => term"}, @{typ "term list option"}) 
   279         $ (HOLogic.split_const (T, @{typ "unit => term"}, @{typ "term list option"}) 
   280         $ absdummy (T, absdummy (@{typ "unit => term"}, t))) $ Bound i
   280         $ absdummy (T, absdummy (@{typ "unit => term"}, t))) $ Bound i
   281   in Abs ("d", @{typ code_numeral}, fold_rev mk_small_closure bounds check) end
   281   in Abs ("d", @{typ code_numeral}, fold_rev mk_small_closure bounds check) end
   282 
   282 
   283 fun make_set T1 [] = Const (@{const_abbrev Set.empty}, T1 --> @{typ bool})
   283 (** post-processing of function terms **)
   284   | make_set T1 ((t1, @{const False}) :: tps) = make_set T1 tps
       
   285   | make_set T1 ((t1, @{const True}) :: tps) =
       
   286     Const (@{const_name insert}, T1 --> (T1 --> @{typ bool}) --> T1 --> @{typ bool})
       
   287       $ t1 $ (make_set T1 tps)
       
   288   | make_set T1 ((_, t) :: tps) = raise TERM ("make_set", [t])
       
   289 
   284 
   290 fun dest_fun_upd (Const (@{const_name fun_upd}, _) $ t0 $ t1 $ t2) = (t0, (t1, t2))
   285 fun dest_fun_upd (Const (@{const_name fun_upd}, _) $ t0 $ t1 $ t2) = (t0, (t1, t2))
   291   | dest_fun_upd t = raise TERM ("dest_fun_upd", [t])
   286   | dest_fun_upd t = raise TERM ("dest_fun_upd", [t])
   292 
   287 
   293 fun mk_fun_upd T1 T2 (t1, t2) t = 
   288 fun mk_fun_upd T1 T2 (t1, t2) t = 
   301       | _ => raise TERM ("dest_plain_fun", [t]))
   296       | _ => raise TERM ("dest_plain_fun", [t]))
   302   | SOME (t0, (t1, t2)) => (t1, t2) :: dest_plain_fun t0
   297   | SOME (t0, (t1, t2)) => (t1, t2) :: dest_plain_fun t0
   303 
   298 
   304 fun make_plain_fun T1 T2 tps =
   299 fun make_plain_fun T1 T2 tps =
   305   fold_rev (mk_fun_upd T1 T2) tps (absdummy (T1, Const ("_", T2)))
   300   fold_rev (mk_fun_upd T1 T2) tps (absdummy (T1, Const ("_", T2)))
       
   301 
       
   302 fun make_set T1 [] = Const (@{const_abbrev Set.empty}, T1 --> @{typ bool})
       
   303   | make_set T1 ((_, @{const False}) :: tps) = make_set T1 tps
       
   304   | make_set T1 ((t1, @{const True}) :: tps) =
       
   305     Const (@{const_name insert}, T1 --> (T1 --> @{typ bool}) --> T1 --> @{typ bool})
       
   306       $ t1 $ (make_set T1 tps)
       
   307   | make_set T1 ((_, t) :: tps) = raise TERM ("make_set", [t])
       
   308 
       
   309 fun make_map T1 T2 [] = Const (@{const_abbrev Map.empty}, T1 --> T2)
       
   310   | make_map T1 T2 ((_, Const (@{const_name None}, _)) :: tps) = make_map T1 T2 tps
       
   311   | make_map T1 T2 ((t1, t2) :: tps) = mk_fun_upd T1 T2 (t1, t2) (make_map T1 T2 tps)
   306   
   312   
   307 fun post_process_term t =
   313 fun post_process_term t =
   308   case fastype_of t of
   314   case fastype_of t of
   309     Type (@{type_name fun}, [T1, T2]) =>
   315     Type (@{type_name fun}, [T1, T2]) =>
   310       dest_plain_fun t |> map (pairself post_process_term) |>
   316       (case try dest_plain_fun t of
   311         (if T2 = @{typ bool} then rev #> make_set T1 else make_plain_fun T1 T2)
   317         SOME tps =>
       
   318           tps
       
   319           |> map (pairself post_process_term)
       
   320           |> (case T2 of
       
   321             @{typ bool} => rev #> make_set T1
       
   322           | Type (@{type_name option}, _) => make_map T1 T2
       
   323           | _ => make_plain_fun T1 T2)
       
   324       | NONE => t)
   312   | _ => t
   325   | _ => t
       
   326 
       
   327 (** generator compiliation **)
   313 
   328 
   314 fun compile_generator_expr ctxt t =
   329 fun compile_generator_expr ctxt t =
   315   let
   330   let
   316     val thy = ProofContext.theory_of ctxt
   331     val thy = ProofContext.theory_of ctxt
   317     val t' =
   332     val t' =