13 val ensure_random_typecopy: string -> theory -> theory |
13 val ensure_random_typecopy: string -> theory -> theory |
14 val random_aux_specification: string -> term list -> local_theory -> local_theory |
14 val random_aux_specification: string -> term list -> local_theory -> local_theory |
15 val mk_random_aux_eqs: theory -> DatatypeAux.descr -> (string * sort) list |
15 val mk_random_aux_eqs: theory -> DatatypeAux.descr -> (string * sort) list |
16 -> string list -> string list * string list -> typ list * typ list |
16 -> string list -> string list * string list -> typ list * typ list |
17 -> string * (term list * (term * term) list) |
17 -> string * (term list * (term * term) list) |
18 val ensure_random_datatype: string list -> theory -> theory |
18 val ensure_random_datatype: DatatypeAux.datatype_config -> string list -> theory -> theory |
19 val eval_ref: (unit -> int -> seed -> term list option * seed) option ref |
19 val eval_ref: (unit -> int -> seed -> term list option * seed) option ref |
20 val setup: theory -> theory |
20 val setup: theory -> theory |
21 end; |
21 end; |
22 |
22 |
23 structure Quickcheck_Generators : QUICKCHECK_GENERATORS = |
23 structure Quickcheck_Generators : QUICKCHECK_GENERATORS = |
318 val auxs_lhss = map (fn t => t $ i $ j $ seed) random_auxs; |
318 val auxs_lhss = map (fn t => t $ i $ j $ seed) random_auxs; |
319 val auxs_rhss = map mk_select gen_exprss; |
319 val auxs_rhss = map mk_select gen_exprss; |
320 val prefix = space_implode "_" (random_auxN :: names); |
320 val prefix = space_implode "_" (random_auxN :: names); |
321 in (prefix, (random_auxs, auxs_lhss ~~ auxs_rhss)) end; |
321 in (prefix, (random_auxs, auxs_lhss ~~ auxs_rhss)) end; |
322 |
322 |
323 fun mk_random_datatype descr vs tycos (names, auxnames) (Ts, Us) thy = |
323 fun mk_random_datatype config descr vs tycos (names, auxnames) (Ts, Us) thy = |
324 let |
324 let |
325 val _ = DatatypeAux.message "Creating quickcheck generators ..."; |
325 val _ = DatatypeAux.message config "Creating quickcheck generators ..."; |
326 val i = @{term "i\<Colon>code_numeral"}; |
326 val i = @{term "i\<Colon>code_numeral"}; |
327 val mk_prop_eq = HOLogic.mk_Trueprop o HOLogic.mk_eq; |
327 val mk_prop_eq = HOLogic.mk_Trueprop o HOLogic.mk_eq; |
328 fun mk_size_arg k = case DatatypeCodegen.find_shortest_path descr k |
328 fun mk_size_arg k = case DatatypeCodegen.find_shortest_path descr k |
329 of SOME (_, l) => if l = 0 then i |
329 of SOME (_, l) => if l = 0 then i |
330 else @{term "max :: code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"} |
330 else @{term "max :: code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"} |
354 |> fold (fn (v, sort) => Vartab.update ((v, 0), sort)) raw_vs |
354 |> fold (fn (v, sort) => Vartab.update ((v, 0), sort)) raw_vs |
355 |> fold meet_random insts; |
355 |> fold meet_random insts; |
356 in SOME (fn (v, _) => (v, (the o Vartab.lookup vtab) (v, 0))) |
356 in SOME (fn (v, _) => (v, (the o Vartab.lookup vtab) (v, 0))) |
357 end handle CLASS_ERROR => NONE; |
357 end handle CLASS_ERROR => NONE; |
358 |
358 |
359 fun ensure_random_datatype raw_tycos thy = |
359 fun ensure_random_datatype config raw_tycos thy = |
360 let |
360 let |
361 val pp = Syntax.pp_global thy; |
361 val pp = Syntax.pp_global thy; |
362 val algebra = Sign.classes_of thy; |
362 val algebra = Sign.classes_of thy; |
363 val (descr, raw_vs, tycos, (names, auxnames), raw_TUs) = |
363 val (descr, raw_vs, tycos, (names, auxnames), raw_TUs) = |
364 DatatypePackage.the_datatype_descr thy raw_tycos; |
364 DatatypePackage.the_datatype_descr thy raw_tycos; |
368 (DatatypeAux.interpret_construction descr raw_vs { atyp = K [], dtyp = K o K }); |
368 (DatatypeAux.interpret_construction descr raw_vs { atyp = K [], dtyp = K o K }); |
369 val has_inst = exists (fn tyco => |
369 val has_inst = exists (fn tyco => |
370 can (Sorts.mg_domain algebra tyco) @{sort random}) tycos; |
370 can (Sorts.mg_domain algebra tyco) @{sort random}) tycos; |
371 in if has_inst then thy |
371 in if has_inst then thy |
372 else case perhaps_constrain thy (random_insts @ term_of_insts) raw_vs |
372 else case perhaps_constrain thy (random_insts @ term_of_insts) raw_vs |
373 of SOME constrain => mk_random_datatype descr |
373 of SOME constrain => mk_random_datatype config descr |
374 (map constrain raw_vs) tycos (names, auxnames) |
374 (map constrain raw_vs) tycos (names, auxnames) |
375 ((pairself o map o map_atyps) (fn TFree v => TFree (constrain v)) raw_TUs) thy |
375 ((pairself o map o map_atyps) (fn TFree v => TFree (constrain v)) raw_TUs) thy |
376 | NONE => thy |
376 | NONE => thy |
377 end; |
377 end; |
378 |
378 |