| author | Lars Hupel <lars.hupel@mytum.de> | 
| Tue, 11 Feb 2014 11:30:33 +0100 | |
| changeset 55390 | 36550a4eac5e | 
| parent 55335 | 8192d3acadbe | 
| child 55552 | e4907b74a347 | 
| permissions | -rw-r--r-- | 
| 54730 | 1  | 
(* Title: Pure/Tools/simplifier_trace.ML  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
2  | 
Author: Lars Hupel  | 
| 54730 | 3  | 
|
4  | 
Interactive Simplifier trace.  | 
|
5  | 
*)  | 
|
6  | 
||
7  | 
signature SIMPLIFIER_TRACE =  | 
|
8  | 
sig  | 
|
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
9  | 
val add_term_breakpoint: term -> Context.generic -> Context.generic  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
10  | 
val add_thm_breakpoint: thm -> Context.generic -> Context.generic  | 
| 54730 | 11  | 
end  | 
12  | 
||
13  | 
structure Simplifier_Trace: SIMPLIFIER_TRACE =  | 
|
14  | 
struct  | 
|
15  | 
||
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
16  | 
(** background data **)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
17  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
18  | 
datatype mode = Disabled | Normal | Full  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
19  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
20  | 
fun merge_modes Disabled m = m  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
21  | 
| merge_modes Normal Full = Full  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
22  | 
| merge_modes Normal _ = Normal  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
23  | 
| merge_modes Full _ = Full  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
24  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
25  | 
val empty_breakpoints =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
26  | 
(Item_Net.init (op =) single (* FIXME equality on terms? *),  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
27  | 
Item_Net.init eq_rrule (single o Thm.full_prop_of o #thm))  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
28  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
29  | 
fun merge_breakpoints ((term_bs1, thm_bs1), (term_bs2, thm_bs2)) =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
30  | 
(Item_Net.merge (term_bs1, term_bs2),  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
31  | 
Item_Net.merge (thm_bs1, thm_bs2))  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
32  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
33  | 
structure Data = Generic_Data  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
34  | 
(  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
35  | 
type T =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
36  | 
    {max_depth: int,
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
37  | 
depth: int,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
38  | 
mode: mode,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
39  | 
interactive: bool,  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
40  | 
memory: bool,  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
41  | 
parent: int,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
42  | 
breakpoints: term Item_Net.T * rrule Item_Net.T}  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
43  | 
val empty =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
44  | 
    {max_depth = 10,
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
45  | 
depth = 0,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
46  | 
mode = Disabled,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
47  | 
interactive = false,  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
48  | 
memory = true,  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
49  | 
parent = 0,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
50  | 
breakpoints = empty_breakpoints}  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
51  | 
val extend = I  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
52  | 
  fun merge ({max_depth = max_depth1, mode = mode1, interactive = interactive1,
 | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
53  | 
memory = memory1, breakpoints = breakpoints1, ...}: T,  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
54  | 
             {max_depth = max_depth2, mode = mode2, interactive = interactive2,
 | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
55  | 
memory = memory2, breakpoints = breakpoints2, ...}: T) =  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
56  | 
    {max_depth = Int.max (max_depth1, max_depth2),
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
57  | 
depth = 0,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
58  | 
mode = merge_modes mode1 mode2,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
59  | 
interactive = interactive1 orelse interactive2,  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
60  | 
memory = memory1 andalso memory2,  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
61  | 
parent = 0,  | 
| 55335 | 62  | 
breakpoints = merge_breakpoints (breakpoints1, breakpoints2)}: T  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
63  | 
)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
64  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
65  | 
fun map_breakpoints f_term f_thm =  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
66  | 
Data.map  | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
67  | 
    (fn {max_depth, depth, mode, interactive, parent, memory, breakpoints = (term_bs, thm_bs)} =>
 | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
68  | 
      {max_depth = max_depth,
 | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
69  | 
depth = depth,  | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
70  | 
mode = mode,  | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
71  | 
interactive = interactive,  | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
72  | 
memory = memory,  | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
73  | 
parent = parent,  | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
74  | 
breakpoints = (f_term term_bs, f_thm thm_bs)})  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
75  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
76  | 
fun add_term_breakpoint term =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
77  | 
map_breakpoints (Item_Net.update term) I  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
78  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
79  | 
fun add_thm_breakpoint thm context =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
80  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
81  | 
val rrules = mk_rrules (Context.proof_of context) [thm]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
82  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
83  | 
map_breakpoints I (fold Item_Net.update rrules) context  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
84  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
85  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
86  | 
fun is_breakpoint (term, rrule) context =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
87  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
88  | 
    val {breakpoints, ...} = Data.get context
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
89  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
90  | 
fun matches pattern = Pattern.matches (Context.theory_of context) (pattern, term)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
91  | 
val term_matches = filter matches (Item_Net.retrieve_matching (fst breakpoints) term)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
92  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
93  | 
    val {thm = thm, ...} = rrule
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
94  | 
val thm_matches = exists (eq_rrule o pair rrule)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
95  | 
(Item_Net.retrieve_matching (snd breakpoints) (Thm.full_prop_of thm))  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
96  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
97  | 
(term_matches, thm_matches)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
98  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
99  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
100  | 
(** config and attributes **)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
101  | 
|
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
102  | 
fun config raw_mode interactive max_depth memory =  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
103  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
104  | 
val mode = case raw_mode of  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
105  | 
"normal" => Normal  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
106  | 
| "full" => Full  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
107  | 
    | _ => error ("Simplifier_Trace.config: unknown mode " ^ raw_mode)
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
108  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
109  | 
    val update = Data.map (fn {depth, parent, breakpoints, ...} =>
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
110  | 
      {max_depth = max_depth,
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
111  | 
depth = depth,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
112  | 
mode = mode,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
113  | 
interactive = interactive,  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
114  | 
memory = memory,  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
115  | 
parent = parent,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
116  | 
breakpoints = breakpoints})  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
117  | 
in Thm.declaration_attribute (K update) end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
118  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
119  | 
fun term_breakpoint terms =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
120  | 
Thm.declaration_attribute (K (fold add_term_breakpoint terms))  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
121  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
122  | 
val thm_breakpoint =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
123  | 
Thm.declaration_attribute add_thm_breakpoint  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
124  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
125  | 
(** tracing state **)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
126  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
127  | 
val futures =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
128  | 
Synchronized.var "Simplifier_Trace.futures" (Inttab.empty: string future Inttab.table)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
129  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
130  | 
(** markup **)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
131  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
132  | 
fun output_result (id, data) =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
133  | 
Output.result (Markup.serial_properties id) data  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
134  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
135  | 
val serialN = "serial"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
136  | 
val parentN = "parent"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
137  | 
val textN = "text"  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
138  | 
val memoryN = "memory"  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
139  | 
val successN = "success"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
140  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
141  | 
val logN = "simp_trace_log"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
142  | 
val stepN = "simp_trace_step"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
143  | 
val recurseN = "simp_trace_recurse"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
144  | 
val hintN = "simp_trace_hint"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
145  | 
val ignoreN = "simp_trace_ignore"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
146  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
147  | 
val cancelN = "simp_trace_cancel"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
148  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
149  | 
type payload =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
150  | 
  {props: Properties.T,
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
151  | 
pretty: Pretty.T}  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
152  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
153  | 
fun empty_payload () : payload =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
154  | 
  {props = [], pretty = Pretty.str ""}
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
155  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
156  | 
fun mk_generic_result markup text triggered (payload : unit -> payload) ctxt =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
157  | 
let  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
158  | 
    val {max_depth, depth, mode, interactive, memory, parent, ...} = Data.get (Context.Proof ctxt)
 | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
159  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
160  | 
val eligible =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
161  | 
case mode of  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
162  | 
Disabled => false  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
163  | 
| Normal => triggered  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
164  | 
| Full => true  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
165  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
166  | 
val markup' = if markup = stepN andalso not interactive then logN else markup  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
167  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
168  | 
if not eligible orelse depth > max_depth then  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
169  | 
NONE  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
170  | 
else  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
171  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
172  | 
        val {props = more_props, pretty} = payload ()
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
173  | 
val props =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
174  | 
[(textN, text),  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
175  | 
(memoryN, Markup.print_bool memory),  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
176  | 
(parentN, Markup.print_int parent)]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
177  | 
val data =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
178  | 
Pretty.string_of (Pretty.markup (markup', props @ more_props) [pretty])  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
179  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
180  | 
SOME (serial (), data)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
181  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
182  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
183  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
184  | 
(** tracing output **)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
185  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
186  | 
fun send_request (result_id, content) =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
187  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
188  | 
fun break () =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
189  | 
(Output.protocol_message  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
190  | 
[(Markup.functionN, cancelN),  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
191  | 
(serialN, Markup.print_int result_id)]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
192  | 
"";  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
193  | 
Synchronized.change futures (Inttab.delete_safe result_id))  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
194  | 
val promise = Future.promise break : string future  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
195  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
196  | 
Synchronized.change futures (Inttab.update_new (result_id, promise));  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
197  | 
output_result (result_id, content);  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
198  | 
promise  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
199  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
200  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
201  | 
|
| 55335 | 202  | 
type data = {term: term, thm: thm, unconditional: bool, ctxt: Proof.context, rrule: rrule}
 | 
203  | 
||
204  | 
fun step ({term, thm, unconditional, ctxt, rrule}: data) =
 | 
|
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
205  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
206  | 
val (matching_terms, thm_triggered) = is_breakpoint (term, rrule) (Context.Proof ctxt)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
207  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
208  | 
    val {name, ...} = rrule
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
209  | 
val term_triggered = not (null matching_terms)  | 
| 54730 | 210  | 
|
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
211  | 
val text =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
212  | 
if unconditional then  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
213  | 
"Apply rewrite rule?"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
214  | 
else  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
215  | 
"Apply conditional rewrite rule?"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
216  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
217  | 
fun payload () =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
218  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
219  | 
(* FIXME pretty printing via Proof_Context.pretty_fact *)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
220  | 
val pretty_thm = Pretty.block  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
221  | 
          [Pretty.str ("Instance of " ^ name ^ ":"),
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
222  | 
Pretty.brk 1,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
223  | 
Syntax.pretty_term ctxt (Thm.prop_of thm)]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
224  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
225  | 
val pretty_term = Pretty.block  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
226  | 
[Pretty.str "Trying to rewrite:",  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
227  | 
Pretty.brk 1,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
228  | 
Syntax.pretty_term ctxt term]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
229  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
230  | 
val pretty_matchings =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
231  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
232  | 
val items = map (Pretty.item o single o Syntax.pretty_term ctxt) matching_terms  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
233  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
234  | 
if not (null matching_terms) then  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
235  | 
[Pretty.block (Pretty.fbreaks (Pretty.str "Matching terms:" :: items))]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
236  | 
else  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
237  | 
[]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
238  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
239  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
240  | 
val pretty =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
241  | 
Pretty.chunks ([pretty_thm, pretty_term] @ pretty_matchings)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
242  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
243  | 
        {props = [], pretty = pretty}
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
244  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
245  | 
|
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
246  | 
    val {max_depth, depth, mode, interactive, memory, breakpoints, ...} =
 | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
247  | 
Data.get (Context.Proof ctxt)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
248  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
249  | 
fun mk_promise result =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
250  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
251  | 
val result_id = #1 result  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
252  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
253  | 
fun put mode' interactive' = Data.put  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
254  | 
          {max_depth = max_depth,
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
255  | 
depth = depth,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
256  | 
mode = mode',  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
257  | 
interactive = interactive',  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
258  | 
memory = memory,  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
259  | 
parent = result_id,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
260  | 
breakpoints = breakpoints} (Context.Proof ctxt) |>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
261  | 
Context.the_proof  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
262  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
263  | 
fun to_response "skip" = NONE  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
264  | 
| to_response "continue" = SOME (put mode true)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
265  | 
| to_response "continue_trace" = SOME (put Full true)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
266  | 
| to_response "continue_passive" = SOME (put mode false)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
267  | 
| to_response "continue_disable" = SOME (put Disabled false)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
268  | 
| to_response _ = raise Fail "Simplifier_Trace.step: invalid message"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
269  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
270  | 
if not interactive then  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
271  | 
(output_result result; Future.value (SOME (put mode false)))  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
272  | 
else  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
273  | 
Future.map to_response (send_request result)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
274  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
275  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
276  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
277  | 
case mk_generic_result stepN text (thm_triggered orelse term_triggered) payload ctxt of  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
278  | 
NONE => Future.value (SOME ctxt)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
279  | 
| SOME res => mk_promise res  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
280  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
281  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
282  | 
fun recurse text term ctxt =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
283  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
284  | 
fun payload () =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
285  | 
      {props = [],
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
286  | 
pretty = Syntax.pretty_term ctxt term}  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
287  | 
|
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
288  | 
    val {max_depth, depth, mode, interactive, memory, breakpoints, ...} =
 | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
289  | 
Data.get (Context.Proof ctxt)  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
290  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
291  | 
fun put result_id = Data.put  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
292  | 
      {max_depth = max_depth,
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
293  | 
depth = depth + 1,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
294  | 
mode = if depth >= max_depth then Disabled else mode,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
295  | 
interactive = interactive,  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
296  | 
memory = memory,  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
297  | 
parent = result_id,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
298  | 
breakpoints = breakpoints} (Context.Proof ctxt)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
299  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
300  | 
val context' =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
301  | 
case mk_generic_result recurseN text true payload ctxt of  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
302  | 
NONE =>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
303  | 
put 0  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
304  | 
| SOME res =>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
305  | 
(output_result res; put (#1 res))  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
306  | 
in Context.the_proof context' end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
307  | 
|
| 55335 | 308  | 
fun indicate_failure ({term, ctxt, thm, rrule, ...}: data) ctxt' =
 | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
309  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
310  | 
fun payload () =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
311  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
312  | 
        val {name, ...} = rrule
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
313  | 
val pretty_thm =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
314  | 
(* FIXME pretty printing via Proof_Context.pretty_fact *)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
315  | 
Pretty.block  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
316  | 
            [Pretty.str ("In an instance of " ^ name ^ ":"),
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
317  | 
Pretty.brk 1,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
318  | 
Syntax.pretty_term ctxt (Thm.prop_of thm)]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
319  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
320  | 
val pretty_term =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
321  | 
Pretty.block  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
322  | 
[Pretty.str "Was trying to rewrite:",  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
323  | 
Pretty.brk 1,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
324  | 
Syntax.pretty_term ctxt term]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
325  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
326  | 
val pretty =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
327  | 
Pretty.chunks [pretty_thm, pretty_term]  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
328  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
329  | 
        {props = [(successN, "false")], pretty = pretty}
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
330  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
331  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
332  | 
    val {interactive, ...} = Data.get (Context.Proof ctxt)
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
333  | 
    val {parent, ...} = Data.get (Context.Proof ctxt')
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
334  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
335  | 
fun mk_promise result =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
336  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
337  | 
val result_id = #1 result  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
338  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
339  | 
fun to_response "exit" =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
340  | 
false  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
341  | 
| to_response "redo" =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
342  | 
(Option.app output_result  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
343  | 
(mk_generic_result ignoreN "Ignore" true empty_payload ctxt');  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
344  | 
true)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
345  | 
| to_response _ =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
346  | 
raise Fail "Simplifier_Trace.indicate_failure: invalid message"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
347  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
348  | 
if not interactive then  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
349  | 
(output_result result; Future.value false)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
350  | 
else  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
351  | 
Future.map to_response (send_request result)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
352  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
353  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
354  | 
case mk_generic_result hintN "Step failed" true payload ctxt' of  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
355  | 
NONE => Future.value false  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
356  | 
| SOME res => mk_promise res  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
357  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
358  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
359  | 
fun indicate_success thm ctxt =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
360  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
361  | 
fun payload () =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
362  | 
      {props = [(successN, "true")],
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
363  | 
pretty = Syntax.pretty_term ctxt (Thm.prop_of thm)}  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
364  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
365  | 
Option.app output_result (mk_generic_result hintN "Successfully rewrote" true payload ctxt)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
366  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
367  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
368  | 
(** setup **)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
369  | 
|
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
370  | 
fun simp_apply args ctxt cont =  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
371  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
372  | 
    val {unconditional: bool, term: term, thm: thm, rrule: rrule} = args
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
373  | 
val data =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
374  | 
      {term = term,
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
375  | 
unconditional = unconditional,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
376  | 
ctxt = ctxt,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
377  | 
thm = thm,  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
378  | 
rrule = rrule}  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
379  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
380  | 
case Future.join (step data) of  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
381  | 
NONE =>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
382  | 
NONE  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
383  | 
| SOME ctxt' =>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
384  | 
let val res = cont ctxt' in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
385  | 
case res of  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
386  | 
NONE =>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
387  | 
if Future.join (indicate_failure data ctxt') then  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
388  | 
simp_apply args ctxt cont  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
389  | 
else  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
390  | 
NONE  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
391  | 
| SOME (thm, _) =>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
392  | 
(indicate_success thm ctxt';  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
393  | 
res)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
394  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
395  | 
end  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
396  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
397  | 
val _ = Session.protocol_handler "isabelle.Simplifier_Trace$Handler"  | 
| 54730 | 398  | 
|
399  | 
val _ = Theory.setup  | 
|
| 
54731
 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 
wenzelm 
parents: 
54730 
diff
changeset
 | 
400  | 
(Simplifier.set_trace_ops  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
401  | 
    {trace_invoke = fn {depth, term} => recurse "Simplifier invoked" term,
 | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
402  | 
trace_apply = simp_apply})  | 
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
403  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
404  | 
val _ =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
405  | 
Isabelle_Process.protocol_command "Document.simp_trace_reply"  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
406  | 
(fn [s, r] =>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
407  | 
let  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
408  | 
val serial = Markup.parse_int s  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
409  | 
fun lookup_delete tab =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
410  | 
(Inttab.lookup tab serial, Inttab.delete_safe serial tab)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
411  | 
fun apply_result (SOME promise) = Future.fulfill promise r  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
412  | 
| apply_result NONE = () (* FIXME handle protocol failure, just like in active.ML? *)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
413  | 
in  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
414  | 
(Synchronized.change_result futures lookup_delete |> apply_result)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
415  | 
handle exn => if Exn.is_interrupt exn then () (*sic!*) else reraise exn  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
416  | 
end)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
417  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
418  | 
(** attributes **)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
419  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
420  | 
val pat_parser =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
421  | 
Args.context -- Scan.lift Args.name_inner_syntax >> uncurry Proof_Context.read_term_schematic  | 
| 54730 | 422  | 
|
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
423  | 
val mode_parser: string parser =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
424  | 
Scan.optional  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
425  | 
(Args.$$$ "mode" |-- Args.$$$ "=" |-- (Args.$$$ "normal" || Args.$$$ "full"))  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
426  | 
"normal"  | 
| 54730 | 427  | 
|
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
428  | 
val interactive_parser: bool parser =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
429  | 
Scan.optional (Args.$$$ "interactive" >> K true) false  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
430  | 
|
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
431  | 
val memory_parser: bool parser =  | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
432  | 
Scan.optional (Args.$$$ "no_memory" >> K false) true  | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
433  | 
|
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
434  | 
val depth_parser =  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
435  | 
Scan.optional (Args.$$$ "depth" |-- Args.$$$ "=" |-- Parse.nat) 10  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
436  | 
|
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
437  | 
val config_parser =  | 
| 
55390
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
438  | 
(interactive_parser -- mode_parser -- depth_parser -- memory_parser) >>  | 
| 
 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
55335 
diff
changeset
 | 
439  | 
(fn (((interactive, mode), depth), memory) => config mode interactive depth memory)  | 
| 54730 | 440  | 
|
| 
55316
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
441  | 
val _ = Theory.setup  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
442  | 
  (Attrib.setup @{binding break_term}
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
443  | 
((Scan.repeat1 pat_parser) >> term_breakpoint)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
444  | 
"declaration of a term breakpoint" #>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
445  | 
   Attrib.setup @{binding break_thm}
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
446  | 
(Scan.succeed thm_breakpoint)  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
447  | 
"declaration of a theorem breakpoint" #>  | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
448  | 
   Attrib.setup @{binding simplifier_trace} (Scan.lift config_parser)
 | 
| 
 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 
Lars Hupel <lars.hupel@mytum.de> 
parents: 
54731 
diff
changeset
 | 
449  | 
"simplifier trace configuration")  | 
| 54730 | 450  | 
|
451  | 
end  |