author | wenzelm |
Mon, 06 Apr 2015 23:14:05 +0200 | |
changeset 59940 | 087d81f5213e |
parent 59621 | 291934bac95e |
child 59970 | e9f73d87d904 |
permissions | -rw-r--r-- |
37744 | 1 |
(* Title: HOL/Mutabelle/mutabelle_extra.ML |
34965 | 2 |
Author: Stefan Berghofer, Jasmin Blanchette, Lukas Bulwahn, TU Muenchen |
3 |
||
41408 | 4 |
Invokation of Counterexample generators. |
34965 | 5 |
*) |
41408 | 6 |
|
34965 | 7 |
signature MUTABELLE_EXTRA = |
8 |
sig |
|
9 |
||
10 |
val take_random : int -> 'a list -> 'a list |
|
11 |
||
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
12 |
datatype outcome = GenuineCex | PotentialCex | NoCex | Donno | Timeout | Error | Solved | Unsolved |
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
13 |
type timings = (string * int) list |
34965 | 14 |
|
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
15 |
type mtd = string * (theory -> term -> outcome * timings) |
35324
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
bulwahn
parents:
35092
diff
changeset
|
16 |
|
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
17 |
type mutant_subentry = term * (string * (outcome * timings)) list |
34965 | 18 |
type detailed_entry = string * bool * term * mutant_subentry list |
19 |
||
20 |
type subentry = string * int * int * int * int * int * int |
|
21 |
type entry = string * bool * subentry list |
|
22 |
type report = entry list |
|
23 |
||
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
24 |
val quickcheck_mtd : (Proof.context -> Proof.context) -> string -> mtd |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
25 |
|
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
26 |
val solve_direct_mtd : mtd |
46641 | 27 |
val try0_mtd : mtd |
40974 | 28 |
(* |
40971
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
29 |
val sledgehammer_mtd : mtd |
40974 | 30 |
*) |
41190 | 31 |
val nitpick_mtd : mtd |
32 |
||
34965 | 33 |
val refute_mtd : mtd |
34 |
||
35 |
val freezeT : term -> term |
|
36 |
val thms_of : bool -> theory -> thm list |
|
37 |
||
38 |
val string_for_report : report -> string |
|
39 |
val write_report : string -> report -> unit |
|
40 |
val mutate_theorems_and_write_report : |
|
46454
d72ab6bf6e6d
making num_mutations a configuration that can be changed with the mutabelle bash command
bulwahn
parents:
46453
diff
changeset
|
41 |
theory -> int * int -> mtd list -> thm list -> string -> unit |
34965 | 42 |
|
56147 | 43 |
val init_random : real -> unit |
34965 | 44 |
end; |
45 |
||
46 |
structure MutabelleExtra : MUTABELLE_EXTRA = |
|
47 |
struct |
|
48 |
||
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
49 |
(* Another Random engine *) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
50 |
|
34965 | 51 |
exception RANDOM; |
52 |
||
53 |
fun rmod x y = x - y * Real.realFloor (x / y); |
|
54 |
||
55 |
local |
|
56147 | 56 |
(* Own seed; can't rely on the Isabelle one to stay the same *) |
57 |
val random_seed = Synchronized.var "random_seed" 1.0; |
|
58 |
||
34965 | 59 |
val a = 16807.0; |
60 |
val m = 2147483647.0; |
|
61 |
in |
|
62 |
||
56147 | 63 |
fun init_random r = Synchronized.change random_seed (K r); |
64 |
||
65 |
fun random () = |
|
66 |
Synchronized.change_result random_seed |
|
67 |
(fn s => |
|
68 |
let val r = rmod (a * s) m |
|
69 |
in (r, r) end); |
|
34965 | 70 |
|
71 |
end; |
|
72 |
||
73 |
fun random_range l h = |
|
74 |
if h < l orelse l < 0 then raise RANDOM |
|
75 |
else l + Real.floor (rmod (random ()) (real (h - l + 1))); |
|
76 |
||
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
77 |
fun take_random 0 _ = [] |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
78 |
| take_random _ [] = [] |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
79 |
| take_random n xs = |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
80 |
let val j = random_range 0 (length xs - 1) in |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
81 |
Library.nth xs j :: take_random (n - 1) (nth_drop j xs) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
82 |
end |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
83 |
|
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
84 |
(* possible outcomes *) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
85 |
|
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
86 |
datatype outcome = GenuineCex | PotentialCex | NoCex | Donno | Timeout | Error | Solved | Unsolved |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
87 |
|
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
88 |
fun string_of_outcome GenuineCex = "GenuineCex" |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
89 |
| string_of_outcome PotentialCex = "PotentialCex" |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
90 |
| string_of_outcome NoCex = "NoCex" |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
91 |
| string_of_outcome Donno = "Donno" |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
92 |
| string_of_outcome Timeout = "Timeout" |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
93 |
| string_of_outcome Error = "Error" |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
94 |
| string_of_outcome Solved = "Solved" |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
95 |
| string_of_outcome Unsolved = "Unsolved" |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
96 |
|
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
97 |
type timings = (string * int) list |
34965 | 98 |
|
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
99 |
type mtd = string * (theory -> term -> outcome * timings) |
35324
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
bulwahn
parents:
35092
diff
changeset
|
100 |
|
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
101 |
type mutant_subentry = term * (string * (outcome * timings)) list |
34965 | 102 |
type detailed_entry = string * bool * term * mutant_subentry list |
103 |
||
104 |
type subentry = string * int * int * int * int * int * int |
|
105 |
type entry = string * bool * subentry list |
|
106 |
type report = entry list |
|
107 |
||
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
108 |
(* possible invocations *) |
34965 | 109 |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
110 |
(** quickcheck **) |
34965 | 111 |
|
51092 | 112 |
fun invoke_quickcheck change_options thy t = |
46452
e4f1cda51df6
increase timeout to 30 seconds; changing mutabelle script
bulwahn
parents:
46434
diff
changeset
|
113 |
TimeLimit.timeLimit (seconds 30.0) |
34965 | 114 |
(fn _ => |
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
115 |
let |
45159
3f1d1ce024cb
moving some common functions from quickcheck to the more HOL-specific quickcheck_common; renamed inductive_SML's configurations to more canonical names; adds automatically left and right hand sides of equations as evaluation terms
bulwahn
parents:
44845
diff
changeset
|
116 |
val ctxt' = change_options (Proof_Context.init_global thy) |
46376
110ba6344446
mutabelle must handle the case where quickcheck returns multiple results
bulwahn
parents:
46326
diff
changeset
|
117 |
val (result :: _) = case Quickcheck.active_testers ctxt' of |
45159
3f1d1ce024cb
moving some common functions from quickcheck to the more HOL-specific quickcheck_common; renamed inductive_SML's configurations to more canonical names; adds automatically left and right hand sides of equations as evaluation terms
bulwahn
parents:
44845
diff
changeset
|
118 |
[] => error "No active testers for quickcheck" |
45428
aa35c9454a95
quickcheck invocations in mutabelle must not catch codegenerator errors internally
bulwahn
parents:
45397
diff
changeset
|
119 |
| [tester] => tester ctxt' false [] [(t, [])] |
45159
3f1d1ce024cb
moving some common functions from quickcheck to the more HOL-specific quickcheck_common; renamed inductive_SML's configurations to more canonical names; adds automatically left and right hand sides of equations as evaluation terms
bulwahn
parents:
44845
diff
changeset
|
120 |
| _ => error "Multiple active testers for quickcheck" |
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
121 |
in |
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
122 |
case Quickcheck.counterexample_of result of |
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
123 |
NONE => (NoCex, Quickcheck.timings_of result) |
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
124 |
| SOME _ => (GenuineCex, Quickcheck.timings_of result) |
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
125 |
end) () |
40931 | 126 |
handle TimeLimit.TimeOut => |
56467 | 127 |
(Timeout, [("timelimit", Real.floor (Options.default_real @{system_option auto_time_limit}))]) |
34965 | 128 |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
129 |
fun quickcheck_mtd change_options quickcheck_generator = |
51092 | 130 |
("quickcheck_" ^ quickcheck_generator, invoke_quickcheck change_options) |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
131 |
|
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
132 |
(** solve direct **) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
133 |
|
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
134 |
fun invoke_solve_direct thy t = |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
135 |
let |
42361 | 136 |
val state = Proof.theorem NONE (K I) (map (single o rpair []) [t]) (Proof_Context.init_global thy) |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
137 |
in |
43030 | 138 |
case Solve_Direct.solve_direct state of |
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
139 |
(true, _) => (Solved, []) |
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
140 |
| (false, _) => (Unsolved, []) |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
141 |
end |
34965 | 142 |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
143 |
val solve_direct_mtd = ("solve_direct", invoke_solve_direct) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
144 |
|
46641 | 145 |
(** try0 **) |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
146 |
|
46641 | 147 |
fun invoke_try0 thy t = |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
148 |
let |
42361 | 149 |
val state = Proof.theorem NONE (K I) (map (single o rpair []) [t]) (Proof_Context.init_global thy) |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
150 |
in |
46641 | 151 |
case Try0.try0 (SOME (seconds 5.0)) ([], [], [], []) state of |
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
152 |
true => (Solved, []) |
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
153 |
| false => (Unsolved, []) |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
154 |
end |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
155 |
|
46641 | 156 |
val try0_mtd = ("try0", invoke_try0) |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
157 |
|
40971
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
158 |
(** sledgehammer **) |
40974 | 159 |
(* |
40971
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
160 |
fun invoke_sledgehammer thy t = |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
161 |
if can (Goal.prove_global thy (Term.add_free_names t []) [] t) |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
162 |
(fn {context, ...} => Sledgehammer_Tactics.sledgehammer_with_metis_tac context 1) then |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
163 |
(Solved, ([], NONE)) |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
164 |
else |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
165 |
(Unsolved, ([], NONE)) |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
166 |
|
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
167 |
val sledgehammer_mtd = ("sledgehammer", invoke_sledgehammer) |
40974 | 168 |
*) |
45397 | 169 |
|
34965 | 170 |
fun invoke_refute thy t = |
171 |
let |
|
45397 | 172 |
val params = [] |
173 |
val res = Refute.refute_term (Proof_Context.init_global thy) params [] t |
|
58843 | 174 |
val _ = writeln ("Refute: " ^ res) |
34965 | 175 |
in |
45397 | 176 |
(rpair []) (case res of |
34965 | 177 |
"genuine" => GenuineCex |
178 |
| "likely_genuine" => GenuineCex |
|
179 |
| "potential" => PotentialCex |
|
180 |
| "none" => NoCex |
|
181 |
| "unknown" => Donno |
|
45397 | 182 |
| _ => Error) |
34965 | 183 |
end |
45397 | 184 |
handle Refute.REFUTE (loc, details) => |
34965 | 185 |
(error ("Unhandled Refute error (" ^ quote loc ^ "): " ^ details ^ |
186 |
".")) |
|
187 |
val refute_mtd = ("refute", invoke_refute) |
|
188 |
||
41190 | 189 |
(** nitpick **) |
34965 | 190 |
|
191 |
fun invoke_nitpick thy t = |
|
192 |
let |
|
42361 | 193 |
val ctxt = Proof_Context.init_global thy |
34965 | 194 |
val state = Proof.init ctxt |
41190 | 195 |
val (res, _) = Nitpick.pick_nits_in_term state |
55199 | 196 |
(Nitpick_Commands.default_params thy []) Nitpick.Normal 1 1 1 [] [] [] t |
58843 | 197 |
val _ = writeln ("Nitpick: " ^ res) |
34965 | 198 |
in |
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
199 |
(rpair []) (case res of |
41190 | 200 |
"genuine" => GenuineCex |
201 |
| "likely_genuine" => GenuineCex |
|
202 |
| "potential" => PotentialCex |
|
203 |
| "none" => NoCex |
|
204 |
| "unknown" => Donno |
|
205 |
| _ => Error) |
|
34965 | 206 |
end |
41190 | 207 |
|
34965 | 208 |
val nitpick_mtd = ("nitpick", invoke_nitpick) |
209 |
||
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
210 |
(* filtering forbidden theorems and mutants *) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
211 |
|
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38857
diff
changeset
|
212 |
val comms = [@{const_name HOL.eq}, @{const_name HOL.disj}, @{const_name HOL.conj}] |
34965 | 213 |
|
214 |
val forbidden = |
|
215 |
[(* (@{const_name "power"}, "'a"), *) |
|
35325
4123977b469d
adding ROOT.ML to HOL-Mutabelle session; uncommenting HOL.induct constants in Mutabelle session
bulwahn
parents:
35324
diff
changeset
|
216 |
(*(@{const_name induct_equal}, "'a"), |
4123977b469d
adding ROOT.ML to HOL-Mutabelle session; uncommenting HOL.induct constants in Mutabelle session
bulwahn
parents:
35324
diff
changeset
|
217 |
(@{const_name induct_implies}, "'a"), |
4123977b469d
adding ROOT.ML to HOL-Mutabelle session; uncommenting HOL.induct constants in Mutabelle session
bulwahn
parents:
35324
diff
changeset
|
218 |
(@{const_name induct_conj}, "'a"),*) |
34965 | 219 |
(@{const_name "undefined"}, "'a"), |
220 |
(@{const_name "default"}, "'a"), |
|
56241 | 221 |
(@{const_name "Pure.dummy_pattern"}, "'a::{}"), |
36255
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
222 |
(@{const_name "HOL.simp_implies"}, "prop => prop => prop"), |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
223 |
(@{const_name "bot_fun_inst.bot_fun"}, "'a"), |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
224 |
(@{const_name "top_fun_inst.top_fun"}, "'a"), |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
225 |
(@{const_name "Pure.term"}, "'a"), |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
226 |
(@{const_name "top_class.top"}, "'a"), |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
227 |
(@{const_name "Quotient.Quot_True"}, "'a")(*, |
34965 | 228 |
(@{const_name "uminus"}, "'a"), |
229 |
(@{const_name "Nat.size"}, "'a"), |
|
35092
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
haftmann
parents:
34974
diff
changeset
|
230 |
(@{const_name "Groups.abs"}, "'a") *)] |
34965 | 231 |
|
232 |
val forbidden_thms = |
|
233 |
["finite_intvl_succ_class", |
|
234 |
"nibble"] |
|
235 |
||
58111 | 236 |
val forbidden_consts = [@{const_name Pure.type}] |
34965 | 237 |
|
238 |
fun is_forbidden_theorem (s, th) = |
|
59582 | 239 |
let val consts = Term.add_const_names (Thm.prop_of th) [] in |
46711
f745bcc4a1e5
more explicit Long_Name operations (NB: analyzing qualifiers is inherently fragile);
wenzelm
parents:
46641
diff
changeset
|
240 |
exists (member (op =) (Long_Name.explode s)) forbidden_thms orelse |
36692
54b64d4ad524
farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
haftmann
parents:
36610
diff
changeset
|
241 |
exists (member (op =) forbidden_consts) consts orelse |
46711
f745bcc4a1e5
more explicit Long_Name operations (NB: analyzing qualifiers is inherently fragile);
wenzelm
parents:
46641
diff
changeset
|
242 |
length (Long_Name.explode s) <> 2 orelse |
f745bcc4a1e5
more explicit Long_Name operations (NB: analyzing qualifiers is inherently fragile);
wenzelm
parents:
46641
diff
changeset
|
243 |
String.isPrefix "type_definition" (List.last (Long_Name.explode s)) orelse |
34965 | 244 |
String.isSuffix "_def" s orelse |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
245 |
String.isSuffix "_raw" s orelse |
46711
f745bcc4a1e5
more explicit Long_Name operations (NB: analyzing qualifiers is inherently fragile);
wenzelm
parents:
46641
diff
changeset
|
246 |
String.isPrefix "term_of" (List.last (Long_Name.explode s)) |
34965 | 247 |
end |
248 |
||
36255
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
249 |
val forbidden_mutant_constnames = |
59940
087d81f5213e
local setup of induction tools, with restricted access to auxiliary consts;
wenzelm
parents:
59621
diff
changeset
|
250 |
[@{const_name HOL.induct_equal}, |
087d81f5213e
local setup of induction tools, with restricted access to auxiliary consts;
wenzelm
parents:
59621
diff
changeset
|
251 |
@{const_name HOL.induct_implies}, |
087d81f5213e
local setup of induction tools, with restricted access to auxiliary consts;
wenzelm
parents:
59621
diff
changeset
|
252 |
@{const_name HOL.induct_conj}, |
087d81f5213e
local setup of induction tools, with restricted access to auxiliary consts;
wenzelm
parents:
59621
diff
changeset
|
253 |
@{const_name HOL.induct_forall}, |
36255
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
254 |
@{const_name undefined}, |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
255 |
@{const_name default}, |
56241 | 256 |
@{const_name Pure.dummy_pattern}, |
36255
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
257 |
@{const_name "HOL.simp_implies"}, |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
258 |
@{const_name "bot_fun_inst.bot_fun"}, |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
259 |
@{const_name "top_fun_inst.top_fun"}, |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
260 |
@{const_name "Pure.term"}, |
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
261 |
@{const_name "top_class.top"}, |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
262 |
(*@{const_name "HOL.equal"},*) |
40971
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
263 |
@{const_name "Quotient.Quot_True"}, |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
264 |
@{const_name "equal_fun_inst.equal_fun"}, |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
265 |
@{const_name "equal_bool_inst.equal_bool"}, |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
266 |
@{const_name "ord_fun_inst.less_eq_fun"}, |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
267 |
@{const_name "ord_fun_inst.less_fun"}, |
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
268 |
@{const_name Meson.skolem}, |
43111 | 269 |
@{const_name ATP.fequal}, |
46326 | 270 |
@{const_name ATP.fEx}, |
42435
c3d880b13aa9
adding two further code-generator internal constants to the blacklist of Mutabelle
bulwahn
parents:
42361
diff
changeset
|
271 |
@{const_name transfer_morphism}, |
c3d880b13aa9
adding two further code-generator internal constants to the blacklist of Mutabelle
bulwahn
parents:
42361
diff
changeset
|
272 |
@{const_name enum_prod_inst.enum_all_prod}, |
46314
f6532c597300
adding some more forbidden constant names for the mutated conjecture generation
bulwahn
parents:
46310
diff
changeset
|
273 |
@{const_name enum_prod_inst.enum_ex_prod}, |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
51092
diff
changeset
|
274 |
@{const_name Quickcheck_Random.catch_match}, |
46434
6d2af424d0f8
adding some forbidden constant names for mutabelle
bulwahn
parents:
46433
diff
changeset
|
275 |
@{const_name Quickcheck_Exhaustive.unknown}, |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46711
diff
changeset
|
276 |
@{const_name Num.Bit0}, @{const_name Num.Bit1} |
56245 | 277 |
(*@{const_name Pure.imp}, @{const_name Pure.eq}*)] |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
278 |
|
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
279 |
val forbidden_mutant_consts = |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
280 |
[ |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
281 |
(@{const_name "Groups.zero_class.zero"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
282 |
(@{const_name "Groups.one_class.one"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
283 |
(@{const_name "Groups.plus_class.plus"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
284 |
(@{const_name "Groups.minus_class.minus"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
285 |
(@{const_name "Groups.times_class.times"}, @{typ "prop => prop => prop"}), |
44064
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
huffman
parents:
43883
diff
changeset
|
286 |
(@{const_name "Fields.inverse_class.divide"}, @{typ "prop => prop => prop"}), |
44845 | 287 |
(@{const_name "Lattices.inf_class.inf"}, @{typ "prop => prop => prop"}), |
288 |
(@{const_name "Lattices.sup_class.sup"}, @{typ "prop => prop => prop"}), |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
289 |
(@{const_name "Orderings.bot_class.bot"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
290 |
(@{const_name "Orderings.ord_class.min"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
291 |
(@{const_name "Orderings.ord_class.max"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
292 |
(@{const_name "Divides.div_class.mod"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
293 |
(@{const_name "Divides.div_class.div"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
294 |
(@{const_name "GCD.gcd_class.gcd"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
295 |
(@{const_name "GCD.gcd_class.lcm"}, @{typ "prop => prop => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
296 |
(@{const_name "Orderings.bot_class.bot"}, @{typ "bool => prop"}), |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
297 |
(@{const_name "Groups.one_class.one"}, @{typ "bool => prop"}), |
46326 | 298 |
(@{const_name "Groups.zero_class.zero"},@{typ "bool => prop"}), |
299 |
(@{const_name "equal_class.equal"},@{typ "bool => bool => bool"})] |
|
36255
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
300 |
|
34965 | 301 |
fun is_forbidden_mutant t = |
36255
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
302 |
let |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
303 |
val const_names = Term.add_const_names t [] |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
304 |
val consts = Term.add_consts t [] |
36255
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
305 |
in |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
306 |
exists (String.isPrefix "Nitpick") const_names orelse |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
307 |
exists (String.isSubstring "_sumC") const_names orelse |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
308 |
exists (member (op =) forbidden_mutant_constnames) const_names orelse |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
309 |
exists (member (op =) forbidden_mutant_consts) consts |
34965 | 310 |
end |
311 |
||
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
312 |
(* executable via quickcheck *) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
313 |
|
40248 | 314 |
fun is_executable_term thy t = |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
315 |
let |
42361 | 316 |
val ctxt = Proof_Context.init_global thy |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
317 |
in |
46452
e4f1cda51df6
increase timeout to 30 seconds; changing mutabelle script
bulwahn
parents:
46434
diff
changeset
|
318 |
can (TimeLimit.timeLimit (seconds 30.0) |
45159
3f1d1ce024cb
moving some common functions from quickcheck to the more HOL-specific quickcheck_common; renamed inductive_SML's configurations to more canonical names; adds automatically left and right hand sides of equations as evaluation terms
bulwahn
parents:
44845
diff
changeset
|
319 |
(Quickcheck.test_terms |
45165
f4896c792316
adding testing of quickcheck narrowing with finite types to mutabelle script; modified is_executable in mutabelle_extra
bulwahn
parents:
45159
diff
changeset
|
320 |
((Context.proof_map (Quickcheck.set_active_testers ["exhaustive"]) #> |
f4896c792316
adding testing of quickcheck narrowing with finite types to mutabelle script; modified is_executable in mutabelle_extra
bulwahn
parents:
45159
diff
changeset
|
321 |
Config.put Quickcheck.finite_types true #> |
41106 | 322 |
Config.put Quickcheck.finite_type_size 1 #> |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
323 |
Config.put Quickcheck.size 1 #> Config.put Quickcheck.iterations 1) ctxt) |
45159
3f1d1ce024cb
moving some common functions from quickcheck to the more HOL-specific quickcheck_common; renamed inductive_SML's configurations to more canonical names; adds automatically left and right hand sides of equations as evaluation terms
bulwahn
parents:
44845
diff
changeset
|
324 |
(false, false) [])) (map (rpair [] o Object_Logic.atomize_term thy) |
3f1d1ce024cb
moving some common functions from quickcheck to the more HOL-specific quickcheck_common; renamed inductive_SML's configurations to more canonical names; adds automatically left and right hand sides of equations as evaluation terms
bulwahn
parents:
44845
diff
changeset
|
325 |
(fst (Variable.import_terms true [t] ctxt))) |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
326 |
end |
40248 | 327 |
|
59582 | 328 |
fun is_executable_thm thy th = is_executable_term thy (Thm.prop_of th) |
34965 | 329 |
|
330 |
val freezeT = |
|
331 |
map_types (map_type_tvar (fn ((a, i), S) => |
|
332 |
TFree (if i = 0 then a else a ^ "_" ^ string_of_int i, S))) |
|
333 |
||
334 |
fun thms_of all thy = |
|
335 |
filter |
|
59582 | 336 |
(fn th => (all orelse Context.theory_name (Thm.theory_of_thm th) = Context.theory_name thy) |
34965 | 337 |
(* andalso is_executable_thm thy th *)) |
56161 | 338 |
(map snd (filter_out is_forbidden_theorem (Global_Theory.all_thms_of thy false))) |
34965 | 339 |
|
49441
0ae4216a1783
recording elapsed time in mutabelle for more detailed evaluation
bulwahn
parents:
47715
diff
changeset
|
340 |
fun elapsed_time description e = |
0ae4216a1783
recording elapsed time in mutabelle for more detailed evaluation
bulwahn
parents:
47715
diff
changeset
|
341 |
let val ({elapsed, ...}, result) = Timing.timing e () |
0ae4216a1783
recording elapsed time in mutabelle for more detailed evaluation
bulwahn
parents:
47715
diff
changeset
|
342 |
in (result, (description, Time.toMilliseconds elapsed)) end |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
343 |
(* |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
344 |
fun unsafe_invoke_mtd thy (mtd_name, invoke_mtd) t = |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
345 |
let |
58843 | 346 |
val _ = writeln ("Invoking " ^ mtd_name) |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
347 |
val ((res, (timing, reports)), time) = cpu_time "total time" (fn () => invoke_mtd thy t |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
348 |
handle ERROR s => (tracing s; (Error, ([], NONE)))) |
58843 | 349 |
val _ = writeln (" Done") |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
350 |
in (res, (time :: timing, reports)) end |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
351 |
*) |
34965 | 352 |
fun safe_invoke_mtd thy (mtd_name, invoke_mtd) t = |
353 |
let |
|
58843 | 354 |
val _ = writeln ("Invoking " ^ mtd_name) |
49441
0ae4216a1783
recording elapsed time in mutabelle for more detailed evaluation
bulwahn
parents:
47715
diff
changeset
|
355 |
val (res, timing) = elapsed_time "total time" |
0ae4216a1783
recording elapsed time in mutabelle for more detailed evaluation
bulwahn
parents:
47715
diff
changeset
|
356 |
(fn () => case try (invoke_mtd thy) t of |
51092 | 357 |
SOME (res, _) => res |
58843 | 358 |
| NONE => (writeln ("**** PROBLEMS WITH " ^ Syntax.string_of_term_global thy t); |
49441
0ae4216a1783
recording elapsed time in mutabelle for more detailed evaluation
bulwahn
parents:
47715
diff
changeset
|
359 |
Error)) |
58843 | 360 |
val _ = writeln (" Done") |
49441
0ae4216a1783
recording elapsed time in mutabelle for more detailed evaluation
bulwahn
parents:
47715
diff
changeset
|
361 |
in (res, [timing]) end |
34965 | 362 |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
363 |
(* creating entries *) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
364 |
|
34965 | 365 |
fun create_detailed_entry thy thm exec mutants mtds = |
366 |
let |
|
367 |
fun create_mutant_subentry mutant = (mutant, |
|
368 |
map (fn (mtd_name, invoke_mtd) => |
|
369 |
(mtd_name, safe_invoke_mtd thy (mtd_name, invoke_mtd) mutant)) mtds) |
|
370 |
in |
|
59582 | 371 |
(Thm.get_name_hint thm, exec, Thm.prop_of thm, map create_mutant_subentry mutants) |
34965 | 372 |
end |
373 |
||
374 |
(* (theory -> thm -> bool -> term list -> mtd list -> 'a) -> theory -> mtd list -> thm -> 'a *) |
|
46454
d72ab6bf6e6d
making num_mutations a configuration that can be changed with the mutabelle bash command
bulwahn
parents:
46453
diff
changeset
|
375 |
fun mutate_theorem create_entry thy (num_mutations, max_mutants) mtds thm = |
34965 | 376 |
let |
377 |
val exec = is_executable_thm thy thm |
|
43277 | 378 |
val _ = tracing (if exec then "EXEC" else "NOEXEC") |
34965 | 379 |
val mutants = |
380 |
(if num_mutations = 0 then |
|
381 |
[Thm.prop_of thm] |
|
382 |
else |
|
383 |
Mutabelle.mutate_mix (Thm.prop_of thm) thy comms forbidden |
|
384 |
num_mutations) |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
385 |
|> tap (fn muts => tracing ("mutants: " ^ string_of_int (length muts))) |
34965 | 386 |
|> filter_out is_forbidden_mutant |
387 |
val mutants = |
|
388 |
if exec then |
|
389 |
let |
|
58843 | 390 |
val _ = writeln ("BEFORE PARTITION OF " ^ |
41491 | 391 |
string_of_int (length mutants) ^ " MUTANTS") |
34965 | 392 |
val (execs, noexecs) = List.partition (is_executable_term thy) (take_random (20 * max_mutants) mutants) |
41491 | 393 |
val _ = tracing ("AFTER PARTITION (" ^ string_of_int (length execs) ^ |
394 |
" vs " ^ string_of_int (length noexecs) ^ ")") |
|
34965 | 395 |
in |
396 |
execs @ take_random (Int.max (0, max_mutants - length execs)) noexecs |
|
397 |
end |
|
398 |
else |
|
399 |
mutants |
|
400 |
val mutants = mutants |
|
401 |
|> map Mutabelle.freeze |> map freezeT |
|
402 |
(* |> filter (not o is_forbidden_mutant) *) |
|
42429 | 403 |
|> map_filter (try (Sign.cert_term thy)) |
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59582
diff
changeset
|
404 |
|> filter (is_some o try (Thm.global_cterm_of thy)) |
42429 | 405 |
|> filter (is_some o try (Syntax.check_term (Proof_Context.init_global thy))) |
40971
6604115019bf
adding filtering, sytactic welltyping, and sledgehammer method in mutabelle
bulwahn
parents:
40932
diff
changeset
|
406 |
|> take_random max_mutants |
58843 | 407 |
val _ = map (fn t => writeln ("MUTANT: " ^ Syntax.string_of_term_global thy t)) mutants |
34965 | 408 |
in |
409 |
create_entry thy thm exec mutants mtds |
|
410 |
end |
|
411 |
||
35324
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
bulwahn
parents:
35092
diff
changeset
|
412 |
fun string_of_mutant_subentry' thy thm_name (t, results) = |
35380
6ac5b81a763d
adopting Mutabelle to quickcheck reporting; improving quickcheck reporting
bulwahn
parents:
35325
diff
changeset
|
413 |
let |
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
414 |
(* fun string_of_report (Quickcheck.Report {iterations = i, raised_match_errors = e, |
35380
6ac5b81a763d
adopting Mutabelle to quickcheck reporting; improving quickcheck reporting
bulwahn
parents:
35325
diff
changeset
|
415 |
satisfied_assms = s, positive_concl_tests = p}) = |
6ac5b81a763d
adopting Mutabelle to quickcheck reporting; improving quickcheck reporting
bulwahn
parents:
35325
diff
changeset
|
416 |
"errors: " ^ string_of_int e ^ "; conclusion tests: " ^ string_of_int p |
6ac5b81a763d
adopting Mutabelle to quickcheck reporting; improving quickcheck reporting
bulwahn
parents:
35325
diff
changeset
|
417 |
fun string_of_reports NONE = "" |
6ac5b81a763d
adopting Mutabelle to quickcheck reporting; improving quickcheck reporting
bulwahn
parents:
35325
diff
changeset
|
418 |
| string_of_reports (SOME reports) = |
6ac5b81a763d
adopting Mutabelle to quickcheck reporting; improving quickcheck reporting
bulwahn
parents:
35325
diff
changeset
|
419 |
cat_lines (map (fn (size, [report]) => |
42089
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
420 |
"size " ^ string_of_int size ^ ": " ^ string_of_report report) (rev reports))*) |
904897d0c5bd
adapting mutabelle; exporting more Quickcheck functions
bulwahn
parents:
42032
diff
changeset
|
421 |
fun string_of_mtd_result (mtd_name, (outcome, timing)) = |
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
422 |
mtd_name ^ ": " ^ string_of_outcome outcome |
49441
0ae4216a1783
recording elapsed time in mutabelle for more detailed evaluation
bulwahn
parents:
47715
diff
changeset
|
423 |
^ "(" ^ space_implode "; " (map (fn (s, t) => (s ^ ": " ^ string_of_int t)) timing) ^ ")" |
36255
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
424 |
(*^ "\n" ^ string_of_reports reports*) |
35380
6ac5b81a763d
adopting Mutabelle to quickcheck reporting; improving quickcheck reporting
bulwahn
parents:
35325
diff
changeset
|
425 |
in |
59433 | 426 |
"mutant of " ^ thm_name ^ ":\n" ^ |
427 |
YXML.content_of (Syntax.string_of_term_global thy t) ^ "\n" ^ |
|
428 |
space_implode "; " (map string_of_mtd_result results) |
|
35380
6ac5b81a763d
adopting Mutabelle to quickcheck reporting; improving quickcheck reporting
bulwahn
parents:
35325
diff
changeset
|
429 |
end |
35324
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
bulwahn
parents:
35092
diff
changeset
|
430 |
|
34965 | 431 |
fun string_of_detailed_entry thy (thm_name, exec, t, mutant_subentries) = |
432 |
thm_name ^ " " ^ (if exec then "[exe]" else "[noexe]") ^ ": " ^ |
|
36255
f8b3381e1437
tuning mutabelle; adding output of mutant theoryfile for interactive evaluation
bulwahn
parents:
35625
diff
changeset
|
433 |
Syntax.string_of_term_global thy t ^ "\n" ^ |
35324
c9f428269b38
adopting mutabelle and quickcheck to return timing information; exporting make_case_combs in datatype package for predicate compiler; adding Spec_Rules declaration for tail recursive functions; improving the predicate compiler and function flattening
bulwahn
parents:
35092
diff
changeset
|
434 |
cat_lines (map (string_of_mutant_subentry' thy thm_name) mutant_subentries) ^ "\n" |
34965 | 435 |
|
436 |
(* subentry -> string *) |
|
437 |
fun string_for_subentry (mtd_name, genuine_cex, potential_cex, no_cex, donno, |
|
438 |
timeout, error) = |
|
41491 | 439 |
" " ^ mtd_name ^ ": " ^ string_of_int genuine_cex ^ "+ " ^ |
440 |
string_of_int potential_cex ^ "= " ^ string_of_int no_cex ^ "- " ^ |
|
441 |
string_of_int donno ^ "? " ^ string_of_int timeout ^ "T " ^ |
|
442 |
string_of_int error ^ "!" |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
443 |
|
34965 | 444 |
(* entry -> string *) |
445 |
fun string_for_entry (thm_name, exec, subentries) = |
|
446 |
thm_name ^ " " ^ (if exec then "[exe]" else "[noexe]") ^ ":\n" ^ |
|
447 |
cat_lines (map string_for_subentry subentries) ^ "\n" |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
448 |
|
34965 | 449 |
(* report -> string *) |
450 |
fun string_for_report report = cat_lines (map string_for_entry report) |
|
451 |
||
452 |
(* string -> report -> unit *) |
|
453 |
fun write_report file_name = |
|
454 |
File.write (Path.explode file_name) o string_for_report |
|
455 |
||
456 |
(* theory -> mtd list -> thm list -> string -> unit *) |
|
46454
d72ab6bf6e6d
making num_mutations a configuration that can be changed with the mutabelle bash command
bulwahn
parents:
46453
diff
changeset
|
457 |
fun mutate_theorems_and_write_report thy (num_mutations, max_mutants) mtds thms file_name = |
34965 | 458 |
let |
58843 | 459 |
val _ = writeln "Starting Mutabelle..." |
42361 | 460 |
val ctxt = Proof_Context.init_global thy |
34965 | 461 |
val path = Path.explode file_name |
462 |
(* for normal report: *) |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
463 |
(* |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
464 |
val (gen_create_entry, gen_string_for_entry) = (create_entry, string_for_entry) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
465 |
*) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
466 |
(* for detailled report: *) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
467 |
val (gen_create_entry, gen_string_for_entry) = (create_detailed_entry, string_of_detailed_entry thy) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
468 |
(* for theory creation: *) |
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
469 |
(*val (gen_create_entry, gen_string_for_entry) = (create_detailed_entry, theoryfile_string_of_detailed_entry thy)*) |
34965 | 470 |
in |
471 |
File.write path ( |
|
472 |
"Mutation options = " ^ |
|
473 |
"max_mutants: " ^ string_of_int max_mutants ^ |
|
474 |
"; num_mutations: " ^ string_of_int num_mutations ^ "\n" ^ |
|
475 |
"QC options = " ^ |
|
476 |
(*"quickcheck_generator: " ^ quickcheck_generator ^ ";*) |
|
40653
d921c97bdbd8
adding AFP tests to Mutabelle_Extra; adopting mutabelle to recent quickcheck changes; filtering strange mutants; adding solvers to mutabelle; restructuring mutabelle
bulwahn
parents:
40381
diff
changeset
|
477 |
"size: " ^ string_of_int (Config.get ctxt Quickcheck.size) ^ |
43244 | 478 |
"; iterations: " ^ string_of_int (Config.get ctxt Quickcheck.iterations) ^ "\n" ^ |
479 |
"Isabelle environment = ISABELLE_GHC: " ^ getenv "ISABELLE_GHC" ^ "\n"); |
|
46454
d72ab6bf6e6d
making num_mutations a configuration that can be changed with the mutabelle bash command
bulwahn
parents:
46453
diff
changeset
|
480 |
map (File.append path o gen_string_for_entry o mutate_theorem gen_create_entry thy (num_mutations, max_mutants) mtds) thms; |
34965 | 481 |
() |
482 |
end |
|
483 |
||
484 |
end; |