14 Proof.context -> (term * term list) list -> bool -> int list -> (bool * term list) option * Quickcheck.report option |
14 Proof.context -> (term * term list) list -> bool -> int list -> (bool * term list) option * Quickcheck.report option |
15 val put_counterexample: (unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> (bool * term list) option * seed) |
15 val put_counterexample: (unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> (bool * term list) option * seed) |
16 -> Proof.context -> Proof.context |
16 -> Proof.context -> Proof.context |
17 val put_counterexample_report: (unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> ((bool * term list) option * (bool list * bool)) * seed) |
17 val put_counterexample_report: (unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> ((bool * term list) option * (bool list * bool)) * seed) |
18 -> Proof.context -> Proof.context |
18 -> Proof.context -> Proof.context |
19 val instantiate_random_datatype : Datatype_Aux.config -> Datatype_Aux.descr -> |
19 val instantiate_random_datatype : Old_Datatype_Aux.config -> Old_Datatype_Aux.descr -> |
20 (string * sort) list -> string list -> string -> string list * string list -> typ list * typ list -> theory -> theory |
20 (string * sort) list -> string list -> string -> string list * string list -> typ list * typ list -> theory -> theory |
21 val setup: theory -> theory |
21 val setup: theory -> theory |
22 end; |
22 end; |
23 |
23 |
24 structure Random_Generators : RANDOM_GENERATORS = |
24 structure Random_Generators : RANDOM_GENERATORS = |
95 fun subst_v t' = map_aterms (fn t as Free (w, _) => if v = w then t' else t | t => t); |
95 fun subst_v t' = map_aterms (fn t as Free (w, _) => if v = w then t' else t | t => t); |
96 val t_rhs = lambda t_k proto_t_rhs; |
96 val t_rhs = lambda t_k proto_t_rhs; |
97 val eqs0 = [subst_v @{term "0::natural"} eq, |
97 val eqs0 = [subst_v @{term "0::natural"} eq, |
98 subst_v (@{const Code_Numeral.Suc} $ t_k) eq]; |
98 subst_v (@{const Code_Numeral.Suc} $ t_k) eq]; |
99 val eqs1 = map (Pattern.rewrite_term thy rew_ts []) eqs0; |
99 val eqs1 = map (Pattern.rewrite_term thy rew_ts []) eqs0; |
100 val ((_, (_, eqs2)), lthy') = Primrec.add_primrec_simple |
100 val ((_, (_, eqs2)), lthy') = Old_Primrec.add_primrec_simple |
101 [((Binding.conceal (Binding.name random_aux), T), NoSyn)] eqs1 lthy; |
101 [((Binding.conceal (Binding.name random_aux), T), NoSyn)] eqs1 lthy; |
102 val cT_random_aux = inst pt_random_aux; |
102 val cT_random_aux = inst pt_random_aux; |
103 val cT_rhs = inst pt_rhs; |
103 val cT_rhs = inst pt_rhs; |
104 val rule = @{thm random_aux_rec} |
104 val rule = @{thm random_aux_rec} |
105 |> Drule.instantiate_normalize ([(aT, icT)], |
105 |> Drule.instantiate_normalize ([(aT, icT)], |
202 fun mk_random_fun_lift [] t = t |
202 fun mk_random_fun_lift [] t = t |
203 | mk_random_fun_lift (fT :: fTs) t = |
203 | mk_random_fun_lift (fT :: fTs) t = |
204 mk_const @{const_name random_fun_lift} [fTs ---> T, fT] $ |
204 mk_const @{const_name random_fun_lift} [fTs ---> T, fT] $ |
205 mk_random_fun_lift fTs t; |
205 mk_random_fun_lift fTs t; |
206 val t = mk_random_fun_lift fTs (nth random_auxs k $ size_pred $ size'); |
206 val t = mk_random_fun_lift fTs (nth random_auxs k $ size_pred $ size'); |
207 val size = Option.map snd (Datatype_Aux.find_shortest_path descr k) |
207 val size = Option.map snd (Old_Datatype_Aux.find_shortest_path descr k) |
208 |> the_default 0; |
208 |> the_default 0; |
209 in (SOME size, (t, fTs ---> T)) end; |
209 in (SOME size, (t, fTs ---> T)) end; |
210 val tss = Datatype_Aux.interpret_construction descr vs |
210 val tss = Old_Datatype_Aux.interpret_construction descr vs |
211 { atyp = mk_random_call, dtyp = mk_random_aux_call }; |
211 { atyp = mk_random_call, dtyp = mk_random_aux_call }; |
212 fun mk_consexpr simpleT (c, xs) = |
212 fun mk_consexpr simpleT (c, xs) = |
213 let |
213 let |
214 val (ks, simple_tTs) = split_list xs; |
214 val (ks, simple_tTs) = split_list xs; |
215 val T = termifyT simpleT; |
215 val T = termifyT simpleT; |
243 val auxs_rhss = map mk_select gen_exprss; |
243 val auxs_rhss = map mk_select gen_exprss; |
244 in (random_auxs, auxs_lhss ~~ auxs_rhss) end; |
244 in (random_auxs, auxs_lhss ~~ auxs_rhss) end; |
245 |
245 |
246 fun instantiate_random_datatype config descr vs tycos prfx (names, auxnames) (Ts, Us) thy = |
246 fun instantiate_random_datatype config descr vs tycos prfx (names, auxnames) (Ts, Us) thy = |
247 let |
247 let |
248 val _ = Datatype_Aux.message config "Creating quickcheck generators ..."; |
248 val _ = Old_Datatype_Aux.message config "Creating quickcheck generators ..."; |
249 val mk_prop_eq = HOLogic.mk_Trueprop o HOLogic.mk_eq; |
249 val mk_prop_eq = HOLogic.mk_Trueprop o HOLogic.mk_eq; |
250 fun mk_size_arg k = case Datatype_Aux.find_shortest_path descr k |
250 fun mk_size_arg k = case Old_Datatype_Aux.find_shortest_path descr k |
251 of SOME (_, l) => if l = 0 then size |
251 of SOME (_, l) => if l = 0 then size |
252 else @{term "max :: natural \<Rightarrow> natural \<Rightarrow> natural"} |
252 else @{term "max :: natural \<Rightarrow> natural \<Rightarrow> natural"} |
253 $ HOLogic.mk_number @{typ natural} l $ size |
253 $ HOLogic.mk_number @{typ natural} l $ size |
254 | NONE => size; |
254 | NONE => size; |
255 val (random_auxs, auxs_eqs) = (apsnd o map) mk_prop_eq |
255 val (random_auxs, auxs_eqs) = (apsnd o map) mk_prop_eq |