244 fun mk_random_fun_lift [] t = t |
244 fun mk_random_fun_lift [] t = t |
245 | mk_random_fun_lift (fT :: fTs) t = |
245 | mk_random_fun_lift (fT :: fTs) t = |
246 mk_const @{const_name random_fun_lift} [fTs ---> T, fT] $ |
246 mk_const @{const_name random_fun_lift} [fTs ---> T, fT] $ |
247 mk_random_fun_lift fTs t; |
247 mk_random_fun_lift fTs t; |
248 val t = mk_random_fun_lift fTs (nth random_auxs k $ size_pred $ size'); |
248 val t = mk_random_fun_lift fTs (nth random_auxs k $ size_pred $ size'); |
249 val size = Option.map snd (DatatypeCodegen.find_shortest_path descr k) |
249 val size = Option.map snd (Datatype_Aux.find_shortest_path descr k) |
250 |> the_default 0; |
250 |> the_default 0; |
251 in (SOME size, (t, fTs ---> T)) end; |
251 in (SOME size, (t, fTs ---> T)) end; |
252 val tss = DatatypeAux.interpret_construction descr vs |
252 val tss = Datatype_Aux.interpret_construction descr vs |
253 { atyp = mk_random_call, dtyp = mk_random_aux_call }; |
253 { atyp = mk_random_call, dtyp = mk_random_aux_call }; |
254 fun mk_consexpr simpleT (c, xs) = |
254 fun mk_consexpr simpleT (c, xs) = |
255 let |
255 let |
256 val (ks, simple_tTs) = split_list xs; |
256 val (ks, simple_tTs) = split_list xs; |
257 val T = termifyT simpleT; |
257 val T = termifyT simpleT; |
285 val auxs_rhss = map mk_select gen_exprss; |
285 val auxs_rhss = map mk_select gen_exprss; |
286 in (random_auxs, auxs_lhss ~~ auxs_rhss) end; |
286 in (random_auxs, auxs_lhss ~~ auxs_rhss) end; |
287 |
287 |
288 fun mk_random_datatype config descr vs tycos prfx (names, auxnames) (Ts, Us) thy = |
288 fun mk_random_datatype config descr vs tycos prfx (names, auxnames) (Ts, Us) thy = |
289 let |
289 let |
290 val _ = DatatypeAux.message config "Creating quickcheck generators ..."; |
290 val _ = Datatype_Aux.message config "Creating quickcheck generators ..."; |
291 val mk_prop_eq = HOLogic.mk_Trueprop o HOLogic.mk_eq; |
291 val mk_prop_eq = HOLogic.mk_Trueprop o HOLogic.mk_eq; |
292 fun mk_size_arg k = case DatatypeCodegen.find_shortest_path descr k |
292 fun mk_size_arg k = case Datatype_Aux.find_shortest_path descr k |
293 of SOME (_, l) => if l = 0 then size |
293 of SOME (_, l) => if l = 0 then size |
294 else @{term "max :: code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"} |
294 else @{term "max :: code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"} |
295 $ HOLogic.mk_number @{typ code_numeral} l $ size |
295 $ HOLogic.mk_number @{typ code_numeral} l $ size |
296 | NONE => size; |
296 | NONE => size; |
297 val (random_auxs, auxs_eqs) = (apsnd o map) mk_prop_eq |
297 val (random_auxs, auxs_eqs) = (apsnd o map) mk_prop_eq |
326 val (descr, raw_vs, tycos, prfx, (names, auxnames), raw_TUs) = |
326 val (descr, raw_vs, tycos, prfx, (names, auxnames), raw_TUs) = |
327 Datatype.the_descr thy raw_tycos; |
327 Datatype.the_descr thy raw_tycos; |
328 val typerep_vs = (map o apsnd) |
328 val typerep_vs = (map o apsnd) |
329 (curry (Sorts.inter_sort algebra) @{sort typerep}) raw_vs; |
329 (curry (Sorts.inter_sort algebra) @{sort typerep}) raw_vs; |
330 val random_insts = (map (rpair @{sort random}) o flat o maps snd o maps snd) |
330 val random_insts = (map (rpair @{sort random}) o flat o maps snd o maps snd) |
331 (DatatypeAux.interpret_construction descr typerep_vs |
331 (Datatype_Aux.interpret_construction descr typerep_vs |
332 { atyp = single, dtyp = (K o K o K) [] }); |
332 { atyp = single, dtyp = (K o K o K) [] }); |
333 val term_of_insts = (map (rpair @{sort term_of}) o flat o maps snd o maps snd) |
333 val term_of_insts = (map (rpair @{sort term_of}) o flat o maps snd o maps snd) |
334 (DatatypeAux.interpret_construction descr typerep_vs |
334 (Datatype_Aux.interpret_construction descr typerep_vs |
335 { atyp = K [], dtyp = K o K }); |
335 { atyp = K [], dtyp = K o K }); |
336 val has_inst = exists (fn tyco => |
336 val has_inst = exists (fn tyco => |
337 can (Sorts.mg_domain algebra tyco) @{sort random}) tycos; |
337 can (Sorts.mg_domain algebra tyco) @{sort random}) tycos; |
338 in if has_inst then thy |
338 in if has_inst then thy |
339 else case perhaps_constrain thy (random_insts @ term_of_insts) typerep_vs |
339 else case perhaps_constrain thy (random_insts @ term_of_insts) typerep_vs |