| author | blanchet | 
| Mon, 22 Feb 2010 11:57:33 +0100 | |
| changeset 35280 | 54ab4921f826 | 
| parent 34232 | 36a2a3029fd3 | 
| child 36270 | fd95c0514623 | 
| permissions | -rw-r--r-- | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
1  | 
(* Title: HOL/Tools/Function/function_core.ML  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
2  | 
Author: Alexander Krauss, TU Muenchen  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
3  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
4  | 
A package for general recursive function definitions:  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
5  | 
Main functionality.  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
6  | 
*)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
7  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
8  | 
signature FUNCTION_CORE =  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
9  | 
sig  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
10  | 
val trace: bool Unsynchronized.ref  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
11  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
12  | 
val prepare_function : Function_Common.function_config  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
13  | 
-> string (* defname *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
14  | 
-> ((bstring * typ) * mixfix) list (* defined symbol *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
15  | 
-> ((bstring * typ) list * term list * term * term) list (* specification *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
16  | 
-> local_theory  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
17  | 
-> (term (* f *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
18  | 
* thm (* goalstate *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
19  | 
* (thm -> Function_Common.function_result) (* continuation *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
20  | 
) * local_theory  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
21  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
22  | 
end  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
23  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
24  | 
structure Function_Core : FUNCTION_CORE =  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
25  | 
struct  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
26  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
27  | 
val trace = Unsynchronized.ref false  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
28  | 
fun trace_msg msg = if ! trace then tracing (msg ()) else ()  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
29  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
30  | 
val boolT = HOLogic.boolT  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
31  | 
val mk_eq = HOLogic.mk_eq  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
32  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
33  | 
open Function_Lib  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
34  | 
open Function_Common  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
35  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
36  | 
datatype globals = Globals of  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
37  | 
 {fvar: term,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
38  | 
domT: typ,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
39  | 
ranT: typ,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
40  | 
h: term,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
41  | 
y: term,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
42  | 
x: term,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
43  | 
z: term,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
44  | 
a: term,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
45  | 
P: term,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
46  | 
D: term,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
47  | 
Pbool:term}  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
48  | 
|
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
49  | 
datatype rec_call_info = RCInfo of  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
50  | 
 {RIvs: (string * typ) list,  (* Call context: fixes and assumes *)
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
51  | 
CCas: thm list,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
52  | 
rcarg: term, (* The recursive argument *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
53  | 
llRI: thm,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
54  | 
h_assum: term}  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
55  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
56  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
57  | 
datatype clause_context = ClauseContext of  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
58  | 
 {ctxt : Proof.context,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
59  | 
qs : term list,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
60  | 
gs : term list,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
61  | 
lhs: term,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
62  | 
rhs: term,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
63  | 
cqs: cterm list,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
64  | 
ags: thm list,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
65  | 
case_hyp : thm}  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
66  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
67  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
68  | 
fun transfer_clause_ctx thy (ClauseContext { ctxt, qs, gs, lhs, rhs, cqs, ags, case_hyp }) =
 | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
69  | 
  ClauseContext { ctxt = ProofContext.transfer thy ctxt,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
70  | 
qs = qs, gs = gs, lhs = lhs, rhs = rhs, cqs = cqs, ags = ags, case_hyp = case_hyp }  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
71  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
72  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
73  | 
datatype clause_info = ClauseInfo of  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
74  | 
 {no: int,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
75  | 
qglr : ((string * typ) list * term list * term * term),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
76  | 
cdata : clause_context,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
77  | 
tree: Function_Ctx_Tree.ctx_tree,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
78  | 
lGI: thm,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
79  | 
RCs: rec_call_info list}  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
80  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
81  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
82  | 
(* Theory dependencies. *)  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
83  | 
val acc_induct_rule = @{thm accp_induct_rule}
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
84  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
85  | 
val ex1_implies_ex = @{thm FunDef.fundef_ex1_existence}
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
86  | 
val ex1_implies_un = @{thm FunDef.fundef_ex1_uniqueness}
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
87  | 
val ex1_implies_iff = @{thm FunDef.fundef_ex1_iff}
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
88  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
89  | 
val acc_downward = @{thm accp_downward}
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
90  | 
val accI = @{thm accp.accI}
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
91  | 
val case_split = @{thm HOL.case_split}
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
92  | 
val fundef_default_value = @{thm FunDef.fundef_default_value}
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
93  | 
val not_acc_down = @{thm not_accp_down}
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
94  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
95  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
96  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
97  | 
fun find_calls tree =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
98  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
99  | 
fun add_Ri (fixes,assumes) (_ $ arg) _ (_, xs) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
100  | 
([], (fixes, assumes, arg) :: xs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
101  | 
| add_Ri _ _ _ _ = raise Match  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
102  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
103  | 
rev (Function_Ctx_Tree.traverse_tree add_Ri tree [])  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
104  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
105  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
106  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
107  | 
(** building proof obligations *)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
108  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
109  | 
fun mk_compat_proof_obligations domT ranT fvar f glrs =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
110  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
111  | 
fun mk_impl ((qs, gs, lhs, rhs),(qs', gs', lhs', rhs')) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
112  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
113  | 
val shift = incr_boundvars (length qs')  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
114  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
115  | 
Logic.mk_implies  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
116  | 
(HOLogic.mk_Trueprop (HOLogic.eq_const domT $ shift lhs $ lhs'),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
117  | 
HOLogic.mk_Trueprop (HOLogic.eq_const ranT $ shift rhs $ rhs'))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
118  | 
|> fold_rev (curry Logic.mk_implies) (map shift gs @ gs')  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
119  | 
|> fold_rev (fn (n,T) => fn b => Term.all T $ Abs(n,T,b)) (qs @ qs')  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
120  | 
|> curry abstract_over fvar  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
121  | 
|> curry subst_bound f  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
122  | 
end  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
123  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
124  | 
map mk_impl (unordered_pairs glrs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
125  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
126  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
127  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
128  | 
fun mk_completeness (Globals {x, Pbool, ...}) clauses qglrs =
 | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
129  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
130  | 
    fun mk_case (ClauseContext {qs, gs, lhs, ...}, (oqs, _, _, _)) =
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
131  | 
HOLogic.mk_Trueprop Pbool  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
132  | 
|> curry Logic.mk_implies (HOLogic.mk_Trueprop (mk_eq (x, lhs)))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
133  | 
|> fold_rev (curry Logic.mk_implies) gs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
134  | 
|> fold_rev mk_forall_rename (map fst oqs ~~ qs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
135  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
136  | 
HOLogic.mk_Trueprop Pbool  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
137  | 
|> fold_rev (curry Logic.mk_implies o mk_case) (clauses ~~ qglrs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
138  | 
    |> mk_forall_rename ("x", x)
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
139  | 
    |> mk_forall_rename ("P", Pbool)
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
140  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
141  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
142  | 
(** making a context with it's own local bindings **)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
143  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
144  | 
fun mk_clause_context x ctxt (pre_qs,pre_gs,pre_lhs,pre_rhs) =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
145  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
146  | 
val (qs, ctxt') = Variable.variant_fixes (map fst pre_qs) ctxt  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
147  | 
|>> map2 (fn (_, T) => fn n => Free (n, T)) pre_qs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
148  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
149  | 
val thy = ProofContext.theory_of ctxt'  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
150  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
151  | 
fun inst t = subst_bounds (rev qs, t)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
152  | 
val gs = map inst pre_gs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
153  | 
val lhs = inst pre_lhs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
154  | 
val rhs = inst pre_rhs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
155  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
156  | 
val cqs = map (cterm_of thy) qs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
157  | 
val ags = map (assume o cterm_of thy) gs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
158  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
159  | 
val case_hyp = assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (x, lhs))))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
160  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
161  | 
    ClauseContext { ctxt = ctxt', qs = qs, gs = gs, lhs = lhs, rhs = rhs,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
162  | 
cqs = cqs, ags = ags, case_hyp = case_hyp }  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
163  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
164  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
165  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
166  | 
(* lowlevel term function. FIXME: remove *)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
167  | 
fun abstract_over_list vs body =  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
168  | 
let  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
169  | 
fun abs lev v tm =  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
170  | 
if v aconv tm then Bound lev  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
171  | 
else  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
172  | 
(case tm of  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
173  | 
Abs (a, T, t) => Abs (a, T, abs (lev + 1) v t)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
174  | 
| t $ u => abs lev v t $ abs lev v u  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
175  | 
| t => t)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
176  | 
in  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
177  | 
fold_index (fn (i, v) => fn t => abs i v t) vs body  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
178  | 
end  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
179  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
180  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
181  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
182  | 
fun mk_clause_info globals G f no cdata qglr tree RCs GIntro_thm RIntro_thms =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
183  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
184  | 
    val Globals {h, ...} = globals
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
185  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
186  | 
    val ClauseContext { ctxt, qs, cqs, ags, ... } = cdata
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
187  | 
val cert = Thm.cterm_of (ProofContext.theory_of ctxt)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
188  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
189  | 
(* Instantiate the GIntro thm with "f" and import into the clause context. *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
190  | 
val lGI = GIntro_thm  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
191  | 
|> forall_elim (cert f)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
192  | 
|> fold forall_elim cqs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
193  | 
|> fold Thm.elim_implies ags  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
194  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
195  | 
fun mk_call_info (rcfix, rcassm, rcarg) RI =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
196  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
197  | 
val llRI = RI  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
198  | 
|> fold forall_elim cqs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
199  | 
|> fold (forall_elim o cert o Free) rcfix  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
200  | 
|> fold Thm.elim_implies ags  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
201  | 
|> fold Thm.elim_implies rcassm  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
202  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
203  | 
val h_assum =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
204  | 
HOLogic.mk_Trueprop (G $ rcarg $ (h $ rcarg))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
205  | 
|> fold_rev (curry Logic.mk_implies o prop_of) rcassm  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
206  | 
|> fold_rev (Logic.all o Free) rcfix  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
207  | 
|> Pattern.rewrite_term (ProofContext.theory_of ctxt) [(f, h)] []  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
208  | 
|> abstract_over_list (rev qs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
209  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
210  | 
        RCInfo {RIvs=rcfix, rcarg=rcarg, CCas=rcassm, llRI=llRI, h_assum=h_assum}
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
211  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
212  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
213  | 
val RC_infos = map2 mk_call_info RCs RIntro_thms  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
214  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
215  | 
    ClauseInfo {no=no, cdata=cdata, qglr=qglr, lGI=lGI, RCs=RC_infos,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
216  | 
tree=tree}  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
217  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
218  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
219  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
220  | 
fun store_compat_thms 0 thms = []  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
221  | 
| store_compat_thms n thms =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
222  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
223  | 
val (thms1, thms2) = chop n thms  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
224  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
225  | 
(thms1 :: store_compat_thms (n - 1) thms2)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
226  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
227  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
228  | 
(* expects i <= j *)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
229  | 
fun lookup_compat_thm i j cts =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
230  | 
nth (nth cts (i - 1)) (j - i)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
231  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
232  | 
(* Returns "Gsi, Gsj, lhs_i = lhs_j |-- rhs_j_f = rhs_i_f" *)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
233  | 
(* if j < i, then turn around *)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
234  | 
fun get_compat_thm thy cts i j ctxi ctxj =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
235  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
236  | 
    val ClauseContext {cqs=cqsi,ags=agsi,lhs=lhsi,...} = ctxi
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
237  | 
    val ClauseContext {cqs=cqsj,ags=agsj,lhs=lhsj,...} = ctxj
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
238  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
239  | 
val lhsi_eq_lhsj = cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj)))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
240  | 
in if j < i then  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
241  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
242  | 
val compat = lookup_compat_thm j i cts  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
243  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
244  | 
compat (* "!!qj qi. Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
245  | 
|> fold forall_elim (cqsj @ cqsi) (* "Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
246  | 
|> fold Thm.elim_implies agsj  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
247  | 
|> fold Thm.elim_implies agsi  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
248  | 
|> Thm.elim_implies ((assume lhsi_eq_lhsj) RS sym) (* "Gsj, Gsi, lhsi = lhsj |-- rhsj = rhsi" *)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
249  | 
end  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
250  | 
else  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
251  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
252  | 
val compat = lookup_compat_thm i j cts  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
253  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
254  | 
compat (* "!!qi qj. Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
255  | 
|> fold forall_elim (cqsi @ cqsj) (* "Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
256  | 
|> fold Thm.elim_implies agsi  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
257  | 
|> fold Thm.elim_implies agsj  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
258  | 
|> Thm.elim_implies (assume lhsi_eq_lhsj)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
259  | 
|> (fn thm => thm RS sym) (* "Gsi, Gsj, lhsi = lhsj |-- rhsj = rhsi" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
260  | 
end  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
261  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
262  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
263  | 
(* Generates the replacement lemma in fully quantified form. *)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
264  | 
fun mk_replacement_lemma thy h ih_elim clause =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
265  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
266  | 
    val ClauseInfo {cdata=ClauseContext {qs, lhs, cqs, ags, case_hyp, ...},
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
267  | 
RCs, tree, ...} = clause  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
268  | 
local open Conv in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
269  | 
val ih_conv = arg1_conv o arg_conv o arg_conv  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
270  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
271  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
272  | 
val ih_elim_case =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
273  | 
Conv.fconv_rule (ih_conv (K (case_hyp RS eq_reflection))) ih_elim  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
274  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
275  | 
    val Ris = map (fn RCInfo {llRI, ...} => llRI) RCs
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
276  | 
    val h_assums = map (fn RCInfo {h_assum, ...} =>
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
277  | 
assume (cterm_of thy (subst_bounds (rev qs, h_assum)))) RCs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
278  | 
|
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
279  | 
val (eql, _) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
280  | 
Function_Ctx_Tree.rewrite_by_tree thy h ih_elim_case (Ris ~~ h_assums) tree  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
281  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
282  | 
val replace_lemma = (eql RS meta_eq_to_obj_eq)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
283  | 
|> implies_intr (cprop_of case_hyp)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
284  | 
|> fold_rev (implies_intr o cprop_of) h_assums  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
285  | 
|> fold_rev (implies_intr o cprop_of) ags  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
286  | 
|> fold_rev forall_intr cqs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
287  | 
|> Thm.close_derivation  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
288  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
289  | 
replace_lemma  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
290  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
291  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
292  | 
|
| 
33855
 
cd8acf137c9c
eliminated dead code and some unused bindings, reported by polyml
 
krauss 
parents: 
33766 
diff
changeset
 | 
293  | 
fun mk_uniqueness_clause thy globals compat_store clausei clausej RLj =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
294  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
295  | 
    val Globals {h, y, x, fvar, ...} = globals
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
296  | 
    val ClauseInfo {no=i, cdata=cctxi as ClauseContext {ctxt=ctxti, lhs=lhsi, case_hyp, ...}, ...} = clausei
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
297  | 
    val ClauseInfo {no=j, qglr=cdescj, RCs=RCsj, ...} = clausej
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
298  | 
|
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
299  | 
    val cctxj as ClauseContext {ags = agsj', lhs = lhsj', rhs = rhsj', qs = qsj', cqs = cqsj', ...} =
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
300  | 
mk_clause_context x ctxti cdescj  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
301  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
302  | 
val rhsj'h = Pattern.rewrite_term thy [(fvar,h)] [] rhsj'  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
303  | 
val compat = get_compat_thm thy compat_store i j cctxi cctxj  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
304  | 
    val Ghsj' = map (fn RCInfo {h_assum, ...} => assume (cterm_of thy (subst_bounds (rev qsj', h_assum)))) RCsj
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
305  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
306  | 
val RLj_import = RLj  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
307  | 
|> fold forall_elim cqsj'  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
308  | 
|> fold Thm.elim_implies agsj'  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
309  | 
|> fold Thm.elim_implies Ghsj'  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
310  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
311  | 
val y_eq_rhsj'h = assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (y, rhsj'h))))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
312  | 
val lhsi_eq_lhsj' = assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj'))))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
313  | 
(* lhs_i = lhs_j' |-- lhs_i = lhs_j' *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
314  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
315  | 
(trans OF [case_hyp, lhsi_eq_lhsj']) (* lhs_i = lhs_j' |-- x = lhs_j' *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
316  | 
|> implies_elim RLj_import  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
317  | 
(* Rj1' ... Rjk', lhs_i = lhs_j' |-- rhs_j'_h = rhs_j'_f *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
318  | 
|> (fn it => trans OF [it, compat])  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
319  | 
(* lhs_i = lhs_j', Gj', Rj1' ... Rjk' |-- rhs_j'_h = rhs_i_f *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
320  | 
|> (fn it => trans OF [y_eq_rhsj'h, it])  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
321  | 
(* lhs_i = lhs_j', Gj', Rj1' ... Rjk', y = rhs_j_h' |-- y = rhs_i_f *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
322  | 
|> fold_rev (implies_intr o cprop_of) Ghsj'  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
323  | 
|> fold_rev (implies_intr o cprop_of) agsj'  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
324  | 
(* lhs_i = lhs_j' , y = rhs_j_h' |-- Gj', Rj1'...Rjk' ==> y = rhs_i_f *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
325  | 
|> implies_intr (cprop_of y_eq_rhsj'h)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
326  | 
|> implies_intr (cprop_of lhsi_eq_lhsj')  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
327  | 
|> fold_rev forall_intr (cterm_of thy h :: cqsj')  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
328  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
329  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
330  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
331  | 
|
| 
33855
 
cd8acf137c9c
eliminated dead code and some unused bindings, reported by polyml
 
krauss 
parents: 
33766 
diff
changeset
 | 
332  | 
fun mk_uniqueness_case thy globals G f ihyp ih_intro G_cases compat_store clauses rep_lemmas clausei =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
333  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
334  | 
    val Globals {x, y, ranT, fvar, ...} = globals
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
335  | 
    val ClauseInfo {cdata = ClauseContext {lhs, rhs, cqs, ags, case_hyp, ...}, lGI, RCs, ...} = clausei
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
336  | 
val rhsC = Pattern.rewrite_term thy [(fvar, f)] [] rhs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
337  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
338  | 
val ih_intro_case = full_simplify (HOL_basic_ss addsimps [case_hyp]) ih_intro  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
339  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
340  | 
    fun prep_RC (RCInfo {llRI, RIvs, CCas, ...}) = (llRI RS ih_intro_case)
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
341  | 
|> fold_rev (implies_intr o cprop_of) CCas  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
342  | 
|> fold_rev (forall_intr o cterm_of thy o Free) RIvs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
343  | 
|
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
344  | 
val existence = fold (curry op COMP o prep_RC) RCs lGI  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
345  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
346  | 
val P = cterm_of thy (mk_eq (y, rhsC))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
347  | 
val G_lhs_y = assume (cterm_of thy (HOLogic.mk_Trueprop (G $ lhs $ y)))  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
348  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
349  | 
val unique_clauses =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
350  | 
map2 (mk_uniqueness_clause thy globals compat_store clausei) clauses rep_lemmas  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
351  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
352  | 
val uniqueness = G_cases  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
353  | 
|> forall_elim (cterm_of thy lhs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
354  | 
|> forall_elim (cterm_of thy y)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
355  | 
|> forall_elim P  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
356  | 
|> Thm.elim_implies G_lhs_y  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
357  | 
|> fold Thm.elim_implies unique_clauses  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
358  | 
|> implies_intr (cprop_of G_lhs_y)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
359  | 
|> forall_intr (cterm_of thy y)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
360  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
361  | 
val P2 = cterm_of thy (lambda y (G $ lhs $ y)) (* P2 y := (lhs, y): G *)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
362  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
363  | 
val exactly_one =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
364  | 
ex1I |> instantiate' [SOME (ctyp_of thy ranT)] [SOME P2, SOME (cterm_of thy rhsC)]  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
365  | 
|> curry (op COMP) existence  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
366  | 
|> curry (op COMP) uniqueness  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
367  | 
|> simplify (HOL_basic_ss addsimps [case_hyp RS sym])  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
368  | 
|> implies_intr (cprop_of case_hyp)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
369  | 
|> fold_rev (implies_intr o cprop_of) ags  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
370  | 
|> fold_rev forall_intr cqs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
371  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
372  | 
val function_value =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
373  | 
existence  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
374  | 
|> implies_intr ihyp  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
375  | 
|> implies_intr (cprop_of case_hyp)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
376  | 
|> forall_intr (cterm_of thy x)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
377  | 
|> forall_elim (cterm_of thy lhs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
378  | 
|> curry (op RS) refl  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
379  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
380  | 
(exactly_one, function_value)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
381  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
382  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
383  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
384  | 
fun prove_stuff ctxt globals G f R clauses complete compat compat_store G_elim f_def =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
385  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
386  | 
    val Globals {h, domT, ranT, x, ...} = globals
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
387  | 
val thy = ProofContext.theory_of ctxt  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
388  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
389  | 
(* Inductive Hypothesis: !!z. (z,x):R ==> EX!y. (z,y):G *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
390  | 
    val ihyp = Term.all domT $ Abs ("z", domT,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
391  | 
Logic.mk_implies (HOLogic.mk_Trueprop (R $ Bound 0 $ x),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
392  | 
        HOLogic.mk_Trueprop (Const ("Ex1", (ranT --> boolT) --> boolT) $
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
393  | 
          Abs ("y", ranT, G $ Bound 1 $ Bound 0))))
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
394  | 
|> cterm_of thy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
395  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
396  | 
val ihyp_thm = assume ihyp |> Thm.forall_elim_vars 0  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
397  | 
val ih_intro = ihyp_thm RS (f_def RS ex1_implies_ex)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
398  | 
val ih_elim = ihyp_thm RS (f_def RS ex1_implies_un)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
399  | 
|> instantiate' [] [NONE, SOME (cterm_of thy h)]  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
400  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
401  | 
val _ = trace_msg (K "Proving Replacement lemmas...")  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
402  | 
val repLemmas = map (mk_replacement_lemma thy h ih_elim) clauses  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
403  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
404  | 
val _ = trace_msg (K "Proving cases for unique existence...")  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
405  | 
val (ex1s, values) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
406  | 
split_list (map (mk_uniqueness_case thy globals G f ihyp ih_intro G_elim compat_store clauses repLemmas) clauses)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
407  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
408  | 
val _ = trace_msg (K "Proving: Graph is a function")  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
409  | 
val graph_is_function = complete  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
410  | 
|> Thm.forall_elim_vars 0  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
411  | 
|> fold (curry op COMP) ex1s  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
412  | 
|> implies_intr (ihyp)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
413  | 
|> implies_intr (cterm_of thy (HOLogic.mk_Trueprop (mk_acc domT R $ x)))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
414  | 
|> forall_intr (cterm_of thy x)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
415  | 
|> (fn it => Drule.compose_single (it, 2, acc_induct_rule)) (* "EX! y. (?x,y):G" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
416  | 
|> (fn it => fold (forall_intr o cterm_of thy o Var) (Term.add_vars (prop_of it) []) it)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
417  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
418  | 
val goalstate = Conjunction.intr graph_is_function complete  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
419  | 
|> Thm.close_derivation  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
420  | 
|> Goal.protect  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
421  | 
|> fold_rev (implies_intr o cprop_of) compat  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
422  | 
|> implies_intr (cprop_of complete)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
423  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
424  | 
(goalstate, values)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
425  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
426  | 
|
| 
33348
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
427  | 
(* wrapper -- restores quantifiers in rule specifications *)  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
428  | 
fun inductive_def (binding as ((R, T), _)) intrs lthy =  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
429  | 
let  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
430  | 
    val ({intrs = intrs_gen, elims = [elim_gen], preds = [ Rdef ], induct, ...}, lthy) =
 | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
431  | 
lthy  | 
| 33671 | 432  | 
|> Local_Theory.conceal  | 
| 
33348
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
433  | 
|> Inductive.add_inductive_i  | 
| 33350 | 434  | 
          {quiet_mode = true,
 | 
435  | 
verbose = ! trace,  | 
|
| 
33348
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
436  | 
alt_name = Binding.empty,  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
437  | 
coind = false,  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
438  | 
no_elim = false,  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
439  | 
no_ind = false,  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
440  | 
skip_mono = true,  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
441  | 
fork_mono = false}  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
442  | 
[binding] (* relation *)  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
443  | 
[] (* no parameters *)  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
444  | 
(map (fn t => (Attrib.empty_binding, t)) intrs) (* intro rules *)  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
445  | 
[] (* no special monos *)  | 
| 33671 | 446  | 
||> Local_Theory.restore_naming lthy  | 
| 
33348
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
447  | 
|
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
448  | 
val cert = cterm_of (ProofContext.theory_of lthy)  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
449  | 
fun requantify orig_intro thm =  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
450  | 
let  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
451  | 
val (qs, t) = dest_all_all orig_intro  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
452  | 
val frees = frees_in_term lthy t |> remove (op =) (Binding.name_of R, T)  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
453  | 
val vars = Term.add_vars (prop_of thm) [] |> rev  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
454  | 
val varmap = AList.lookup (op =) (frees ~~ map fst vars)  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
455  | 
          #> the_default ("",0)
 | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
456  | 
in  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
457  | 
fold_rev (fn Free (n, T) =>  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
458  | 
forall_intr_rename (n, cert (Var (varmap (n, T), T)))) qs thm  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
459  | 
end  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
460  | 
in  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
461  | 
((Rdef, map2 requantify intrs intrs_gen, forall_intr_vars elim_gen, induct), lthy)  | 
| 
33348
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
462  | 
end  | 
| 
 
bb65583ab70d
absorbed inductive_wrap function into Function_Core; more conventional argument order; tuned
 
krauss 
parents: 
33278 
diff
changeset
 | 
463  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
464  | 
fun define_graph Gname fvar domT ranT clauses RCss lthy =  | 
| 33349 | 465  | 
let  | 
466  | 
val GT = domT --> ranT --> boolT  | 
|
467  | 
val (Gvar as (n, T)) = singleton (Variable.variant_frees lthy []) (Gname, GT)  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
468  | 
|
| 33349 | 469  | 
    fun mk_GIntro (ClauseContext {qs, gs, lhs, rhs, ...}) RCs =
 | 
470  | 
let  | 
|
471  | 
fun mk_h_assm (rcfix, rcassm, rcarg) =  | 
|
472  | 
HOLogic.mk_Trueprop (Free Gvar $ rcarg $ (fvar $ rcarg))  | 
|
473  | 
|> fold_rev (curry Logic.mk_implies o prop_of) rcassm  | 
|
474  | 
|> fold_rev (Logic.all o Free) rcfix  | 
|
475  | 
in  | 
|
476  | 
HOLogic.mk_Trueprop (Free Gvar $ lhs $ rhs)  | 
|
477  | 
|> fold_rev (curry Logic.mk_implies o mk_h_assm) RCs  | 
|
478  | 
|> fold_rev (curry Logic.mk_implies) gs  | 
|
479  | 
|> fold_rev Logic.all (fvar :: qs)  | 
|
480  | 
end  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
481  | 
|
| 33349 | 482  | 
val G_intros = map2 mk_GIntro clauses RCss  | 
483  | 
in  | 
|
484  | 
inductive_def ((Binding.name n, T), NoSyn) G_intros lthy  | 
|
485  | 
end  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
486  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
487  | 
fun define_function fdefname (fname, mixfix) domT ranT G default lthy =  | 
| 33349 | 488  | 
let  | 
489  | 
val f_def =  | 
|
490  | 
      Abs ("x", domT, Const (@{const_name FunDef.THE_default}, ranT --> (ranT --> boolT) --> ranT) 
 | 
|
491  | 
        $ (default $ Bound 0) $ Abs ("y", ranT, G $ Bound 1 $ Bound 0))
 | 
|
492  | 
|> Syntax.check_term lthy  | 
|
493  | 
in  | 
|
| 
33766
 
c679f05600cd
adapted Local_Theory.define -- eliminated odd thm kind;
 
wenzelm 
parents: 
33671 
diff
changeset
 | 
494  | 
Local_Theory.define  | 
| 33349 | 495  | 
((Binding.name (function_name fname), mixfix),  | 
496  | 
((Binding.conceal (Binding.name fdefname), []), f_def)) lthy  | 
|
497  | 
end  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
498  | 
|
| 
33855
 
cd8acf137c9c
eliminated dead code and some unused bindings, reported by polyml
 
krauss 
parents: 
33766 
diff
changeset
 | 
499  | 
fun define_recursion_relation Rname domT qglrs clauses RCss lthy =  | 
| 33349 | 500  | 
let  | 
501  | 
val RT = domT --> domT --> boolT  | 
|
502  | 
val (Rvar as (n, T)) = singleton (Variable.variant_frees lthy []) (Rname, RT)  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
503  | 
|
| 33349 | 504  | 
    fun mk_RIntro (ClauseContext {qs, gs, lhs, ...}, (oqs, _, _, _)) (rcfix, rcassm, rcarg) =
 | 
505  | 
HOLogic.mk_Trueprop (Free Rvar $ rcarg $ lhs)  | 
|
506  | 
|> fold_rev (curry Logic.mk_implies o prop_of) rcassm  | 
|
507  | 
|> fold_rev (curry Logic.mk_implies) gs  | 
|
508  | 
|> fold_rev (Logic.all o Free) rcfix  | 
|
509  | 
|> fold_rev mk_forall_rename (map fst oqs ~~ qs)  | 
|
510  | 
(* "!!qs xs. CS ==> G => (r, lhs) : R" *)  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
511  | 
|
| 33349 | 512  | 
val R_intross = map2 (map o mk_RIntro) (clauses ~~ qglrs) RCss  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
513  | 
|
| 33349 | 514  | 
val ((R, RIntro_thms, R_elim, _), lthy) =  | 
515  | 
inductive_def ((Binding.name n, T), NoSyn) (flat R_intross) lthy  | 
|
516  | 
in  | 
|
517  | 
((R, Library.unflat R_intross RIntro_thms, R_elim), lthy)  | 
|
518  | 
end  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
519  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
520  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
521  | 
fun fix_globals domT ranT fvar ctxt =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
522  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
523  | 
val ([h, y, x, z, a, D, P, Pbool],ctxt') = Variable.variant_fixes  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
524  | 
["h_fd", "y_fd", "x_fd", "z_fd", "a_fd", "D_fd", "P_fd", "Pb_fd"] ctxt  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
525  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
526  | 
    (Globals {h = Free (h, domT --> ranT),
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
527  | 
y = Free (y, ranT),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
528  | 
x = Free (x, domT),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
529  | 
z = Free (z, domT),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
530  | 
a = Free (a, domT),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
531  | 
D = Free (D, domT --> boolT),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
532  | 
P = Free (P, domT --> boolT),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
533  | 
Pbool = Free (Pbool, boolT),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
534  | 
fvar = fvar,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
535  | 
domT = domT,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
536  | 
ranT = ranT},  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
537  | 
ctxt')  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
538  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
539  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
540  | 
fun inst_RC thy fvar f (rcfix, rcassm, rcarg) =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
541  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
542  | 
fun inst_term t = subst_bound(f, abstract_over (fvar, t))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
543  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
544  | 
(rcfix, map (assume o cterm_of thy o inst_term o prop_of) rcassm, inst_term rcarg)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
545  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
546  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
547  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
548  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
549  | 
(**********************************************************  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
550  | 
* PROVING THE RULES  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
551  | 
**********************************************************)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
552  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
553  | 
fun mk_psimps thy globals R clauses valthms f_iff graph_is_function =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
554  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
555  | 
    val Globals {domT, z, ...} = globals
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
556  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
557  | 
    fun mk_psimp (ClauseInfo {qglr = (oqs, _, _, _), cdata = ClauseContext {cqs, lhs, ags, ...}, ...}) valthm =
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
558  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
559  | 
val lhs_acc = cterm_of thy (HOLogic.mk_Trueprop (mk_acc domT R $ lhs)) (* "acc R lhs" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
560  | 
val z_smaller = cterm_of thy (HOLogic.mk_Trueprop (R $ z $ lhs)) (* "R z lhs" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
561  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
562  | 
((assume z_smaller) RS ((assume lhs_acc) RS acc_downward))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
563  | 
|> (fn it => it COMP graph_is_function)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
564  | 
|> implies_intr z_smaller  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
565  | 
|> forall_intr (cterm_of thy z)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
566  | 
|> (fn it => it COMP valthm)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
567  | 
|> implies_intr lhs_acc  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
568  | 
|> asm_simplify (HOL_basic_ss addsimps [f_iff])  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
569  | 
|> fold_rev (implies_intr o cprop_of) ags  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
570  | 
|> fold_rev forall_intr_rename (map fst oqs ~~ cqs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
571  | 
end  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
572  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
573  | 
map2 mk_psimp clauses valthms  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
574  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
575  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
576  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
577  | 
(** Induction rule **)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
578  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
579  | 
|
| 
34065
 
6f8f9835e219
moved predicate rules to Predicate.thy; weakened default dest rule predicate1D (is not that reliable wrt. sets)
 
haftmann 
parents: 
33855 
diff
changeset
 | 
580  | 
val acc_subset_induct = @{thm predicate1I} RS @{thm accp_subset_induct}
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
581  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
582  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
583  | 
fun mk_partial_induct_rule thy globals R complete_thm clauses =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
584  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
585  | 
    val Globals {domT, x, z, a, P, D, ...} = globals
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
586  | 
val acc_R = mk_acc domT R  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
587  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
588  | 
val x_D = assume (cterm_of thy (HOLogic.mk_Trueprop (D $ x)))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
589  | 
val a_D = cterm_of thy (HOLogic.mk_Trueprop (D $ a))  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
590  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
591  | 
val D_subset = cterm_of thy (Logic.all x  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
592  | 
(Logic.mk_implies (HOLogic.mk_Trueprop (D $ x), HOLogic.mk_Trueprop (acc_R $ x))))  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
593  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
594  | 
val D_dcl = (* "!!x z. [| x: D; (z,x):R |] ==> z:D" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
595  | 
Logic.all x (Logic.all z (Logic.mk_implies (HOLogic.mk_Trueprop (D $ x),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
596  | 
Logic.mk_implies (HOLogic.mk_Trueprop (R $ z $ x),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
597  | 
HOLogic.mk_Trueprop (D $ z)))))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
598  | 
|> cterm_of thy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
599  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
600  | 
(* Inductive Hypothesis: !!z. (z,x):R ==> P z *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
601  | 
    val ihyp = Term.all domT $ Abs ("z", domT,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
602  | 
Logic.mk_implies (HOLogic.mk_Trueprop (R $ Bound 0 $ x),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
603  | 
HOLogic.mk_Trueprop (P $ Bound 0)))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
604  | 
|> cterm_of thy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
605  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
606  | 
val aihyp = assume ihyp  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
607  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
608  | 
fun prove_case clause =  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
609  | 
let  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
610  | 
        val ClauseInfo {cdata = ClauseContext {ctxt, qs, cqs, ags, gs, lhs, case_hyp, ...},
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
611  | 
RCs, qglr = (oqs, _, _, _), ...} = clause  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
612  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
613  | 
val case_hyp_conv = K (case_hyp RS eq_reflection)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
614  | 
local open Conv in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
615  | 
val lhs_D = fconv_rule (arg_conv (arg_conv (case_hyp_conv))) x_D  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
616  | 
val sih =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
617  | 
fconv_rule (More_Conv.binder_conv  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
618  | 
(K (arg1_conv (arg_conv (arg_conv case_hyp_conv)))) ctxt) aihyp  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
619  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
620  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
621  | 
        fun mk_Prec (RCInfo {llRI, RIvs, CCas, rcarg, ...}) = sih
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
622  | 
|> forall_elim (cterm_of thy rcarg)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
623  | 
|> Thm.elim_implies llRI  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
624  | 
|> fold_rev (implies_intr o cprop_of) CCas  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
625  | 
|> fold_rev (forall_intr o cterm_of thy o Free) RIvs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
626  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
627  | 
val P_recs = map mk_Prec RCs (* [P rec1, P rec2, ... ] *)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
628  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
629  | 
val step = HOLogic.mk_Trueprop (P $ lhs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
630  | 
|> fold_rev (curry Logic.mk_implies o prop_of) P_recs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
631  | 
|> fold_rev (curry Logic.mk_implies) gs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
632  | 
|> curry Logic.mk_implies (HOLogic.mk_Trueprop (D $ lhs))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
633  | 
|> fold_rev mk_forall_rename (map fst oqs ~~ qs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
634  | 
|> cterm_of thy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
635  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
636  | 
val P_lhs = assume step  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
637  | 
|> fold forall_elim cqs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
638  | 
|> Thm.elim_implies lhs_D  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
639  | 
|> fold Thm.elim_implies ags  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
640  | 
|> fold Thm.elim_implies P_recs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
641  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
642  | 
val res = cterm_of thy (HOLogic.mk_Trueprop (P $ x))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
643  | 
|> Conv.arg_conv (Conv.arg_conv case_hyp_conv)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
644  | 
|> symmetric (* P lhs == P x *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
645  | 
|> (fn eql => equal_elim eql P_lhs) (* "P x" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
646  | 
|> implies_intr (cprop_of case_hyp)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
647  | 
|> fold_rev (implies_intr o cprop_of) ags  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
648  | 
|> fold_rev forall_intr cqs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
649  | 
in  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
650  | 
(res, step)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
651  | 
end  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
652  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
653  | 
val (cases, steps) = split_list (map prove_case clauses)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
654  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
655  | 
val istep = complete_thm  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
656  | 
|> Thm.forall_elim_vars 0  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
657  | 
|> fold (curry op COMP) cases (* P x *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
658  | 
|> implies_intr ihyp  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
659  | 
|> implies_intr (cprop_of x_D)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
660  | 
|> forall_intr (cterm_of thy x)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
661  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
662  | 
val subset_induct_rule =  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
663  | 
acc_subset_induct  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
664  | 
|> (curry op COMP) (assume D_subset)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
665  | 
|> (curry op COMP) (assume D_dcl)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
666  | 
|> (curry op COMP) (assume a_D)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
667  | 
|> (curry op COMP) istep  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
668  | 
|> fold_rev implies_intr steps  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
669  | 
|> implies_intr a_D  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
670  | 
|> implies_intr D_dcl  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
671  | 
|> implies_intr D_subset  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
672  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
673  | 
val simple_induct_rule =  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
674  | 
subset_induct_rule  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
675  | 
|> forall_intr (cterm_of thy D)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
676  | 
|> forall_elim (cterm_of thy acc_R)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
677  | 
|> assume_tac 1 |> Seq.hd  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
678  | 
|> (curry op COMP) (acc_downward  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
679  | 
|> (instantiate' [SOME (ctyp_of thy domT)]  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
680  | 
(map (SOME o cterm_of thy) [R, x, z]))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
681  | 
|> forall_intr (cterm_of thy z)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
682  | 
|> forall_intr (cterm_of thy x))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
683  | 
|> forall_intr (cterm_of thy a)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
684  | 
|> forall_intr (cterm_of thy P)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
685  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
686  | 
simple_induct_rule  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
687  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
688  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
689  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
690  | 
(* FIXME: broken by design *)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
691  | 
fun mk_domain_intro ctxt (Globals {domT, ...}) R R_cases clause =
 | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
692  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
693  | 
val thy = ProofContext.theory_of ctxt  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
694  | 
    val ClauseInfo {cdata = ClauseContext {gs, lhs, cqs, ...},
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
695  | 
qglr = (oqs, _, _, _), ...} = clause  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
696  | 
val goal = HOLogic.mk_Trueprop (mk_acc domT R $ lhs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
697  | 
|> fold_rev (curry Logic.mk_implies) gs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
698  | 
|> cterm_of thy  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
699  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
700  | 
Goal.init goal  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
701  | 
|> (SINGLE (resolve_tac [accI] 1)) |> the  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
702  | 
|> (SINGLE (eresolve_tac [Thm.forall_elim_vars 0 R_cases] 1)) |> the  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
703  | 
|> (SINGLE (auto_tac (clasimpset_of ctxt))) |> the  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
704  | 
|> Goal.conclude  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
705  | 
|> fold_rev forall_intr_rename (map fst oqs ~~ cqs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
706  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
707  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
708  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
709  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
710  | 
(** Termination rule **)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
711  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
712  | 
val wf_induct_rule = @{thm Wellfounded.wfP_induct_rule}
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
713  | 
val wf_in_rel = @{thm FunDef.wf_in_rel}
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
714  | 
val in_rel_def = @{thm FunDef.in_rel_def}
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
715  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
716  | 
fun mk_nest_term_case thy globals R' ihyp clause =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
717  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
718  | 
    val Globals {z, ...} = globals
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
719  | 
    val ClauseInfo {cdata = ClauseContext {qs, cqs, ags, lhs, case_hyp, ...}, tree,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
720  | 
qglr=(oqs, _, _, _), ...} = clause  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
721  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
722  | 
val ih_case = full_simplify (HOL_basic_ss addsimps [case_hyp]) ihyp  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
723  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
724  | 
fun step (fixes, assumes) (_ $ arg) u (sub,(hyps,thms)) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
725  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
726  | 
val used = (u @ sub)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
727  | 
|> map (fn (ctx,thm) => Function_Ctx_Tree.export_thm thy ctx thm)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
728  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
729  | 
val hyp = HOLogic.mk_Trueprop (R' $ arg $ lhs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
730  | 
|> fold_rev (curry Logic.mk_implies o prop_of) used (* additional hyps *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
731  | 
|> Function_Ctx_Tree.export_term (fixes, assumes)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
732  | 
|> fold_rev (curry Logic.mk_implies o prop_of) ags  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
733  | 
|> fold_rev mk_forall_rename (map fst oqs ~~ qs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
734  | 
|> cterm_of thy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
735  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
736  | 
val thm = assume hyp  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
737  | 
|> fold forall_elim cqs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
738  | 
|> fold Thm.elim_implies ags  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
739  | 
|> Function_Ctx_Tree.import_thm thy (fixes, assumes)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
740  | 
|> fold Thm.elim_implies used (* "(arg, lhs) : R'" *)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
741  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
742  | 
val z_eq_arg = HOLogic.mk_Trueprop (mk_eq (z, arg))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
743  | 
|> cterm_of thy |> assume  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
744  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
745  | 
val acc = thm COMP ih_case  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
746  | 
val z_acc_local = acc  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
747  | 
|> Conv.fconv_rule (Conv.arg_conv (Conv.arg_conv (K (symmetric (z_eq_arg RS eq_reflection)))))  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
748  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
749  | 
val ethm = z_acc_local  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
750  | 
|> Function_Ctx_Tree.export_thm thy (fixes,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
751  | 
z_eq_arg :: case_hyp :: ags @ assumes)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
752  | 
|> fold_rev forall_intr_rename (map fst oqs ~~ cqs)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
753  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
754  | 
val sub' = sub @ [(([],[]), acc)]  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
755  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
756  | 
(sub', (hyp :: hyps, ethm :: thms))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
757  | 
end  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
758  | 
| step _ _ _ _ = raise Match  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
759  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
760  | 
Function_Ctx_Tree.traverse_tree step tree  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
761  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
762  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
763  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
764  | 
fun mk_nest_term_rule thy globals R R_cases clauses =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
765  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
766  | 
    val Globals { domT, x, z, ... } = globals
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
767  | 
val acc_R = mk_acc domT R  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
768  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
769  | 
    val R' = Free ("R", fastype_of R)
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
770  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
771  | 
    val Rrel = Free ("R", HOLogic.mk_setT (HOLogic.mk_prodT (domT, domT)))
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
772  | 
    val inrel_R = Const (@{const_name FunDef.in_rel},
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
773  | 
HOLogic.mk_setT (HOLogic.mk_prodT (domT, domT)) --> fastype_of R) $ Rrel  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
774  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
775  | 
    val wfR' = HOLogic.mk_Trueprop (Const (@{const_name Wellfounded.wfP},
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
776  | 
(domT --> domT --> boolT) --> boolT) $ R')  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
777  | 
|> cterm_of thy (* "wf R'" *)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
778  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
779  | 
(* Inductive Hypothesis: !!z. (z,x):R' ==> z : acc R *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
780  | 
    val ihyp = Term.all domT $ Abs ("z", domT,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
781  | 
Logic.mk_implies (HOLogic.mk_Trueprop (R' $ Bound 0 $ x),  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
782  | 
HOLogic.mk_Trueprop (acc_R $ Bound 0)))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
783  | 
|> cterm_of thy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
784  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
785  | 
val ihyp_a = assume ihyp |> Thm.forall_elim_vars 0  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
786  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
787  | 
val R_z_x = cterm_of thy (HOLogic.mk_Trueprop (R $ z $ x))  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
788  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
789  | 
val (hyps, cases) = fold (mk_nest_term_case thy globals R' ihyp_a) clauses ([], [])  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
790  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
791  | 
R_cases  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
792  | 
|> forall_elim (cterm_of thy z)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
793  | 
|> forall_elim (cterm_of thy x)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
794  | 
|> forall_elim (cterm_of thy (acc_R $ z))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
795  | 
|> curry op COMP (assume R_z_x)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
796  | 
|> fold_rev (curry op COMP) cases  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
797  | 
|> implies_intr R_z_x  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
798  | 
|> forall_intr (cterm_of thy z)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
799  | 
|> (fn it => it COMP accI)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
800  | 
|> implies_intr ihyp  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
801  | 
|> forall_intr (cterm_of thy x)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
802  | 
|> (fn it => Drule.compose_single(it,2,wf_induct_rule))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
803  | 
|> curry op RS (assume wfR')  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
804  | 
|> forall_intr_vars  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
805  | 
|> (fn it => it COMP allI)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
806  | 
|> fold implies_intr hyps  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
807  | 
|> implies_intr wfR'  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
808  | 
|> forall_intr (cterm_of thy R')  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
809  | 
|> forall_elim (cterm_of thy (inrel_R))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
810  | 
|> curry op RS wf_in_rel  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
811  | 
|> full_simplify (HOL_basic_ss addsimps [in_rel_def])  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
812  | 
|> forall_intr (cterm_of thy Rrel)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
813  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
814  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
815  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
816  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
817  | 
(* Tail recursion (probably very fragile)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
818  | 
*  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
819  | 
* FIXME:  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
820  | 
* - Need to do forall_elim_vars on psimps: Unneccesary, if psimps would be taken from the same context.  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
821  | 
* - Must we really replace the fvar by f here?  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
822  | 
* - Splitting is not configured automatically: Problems with case?  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
823  | 
*)  | 
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
824  | 
fun mk_trsimps octxt globals f G R f_def R_cases G_induct clauses psimps =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
825  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
826  | 
    val Globals {domT, ranT, fvar, ...} = globals
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
827  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
828  | 
val R_cases = Thm.forall_elim_vars 0 R_cases (* FIXME: Should be already in standard form. *)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
829  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
830  | 
val graph_implies_dom = (* "G ?x ?y ==> dom ?x" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
831  | 
      Goal.prove octxt ["x", "y"] [HOLogic.mk_Trueprop (G $ Free ("x", domT) $ Free ("y", ranT))]
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
832  | 
        (HOLogic.mk_Trueprop (mk_acc domT R $ Free ("x", domT)))
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
833  | 
        (fn {prems=[a], ...} =>
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
834  | 
((rtac (G_induct OF [a]))  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
835  | 
THEN_ALL_NEW rtac accI  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
836  | 
THEN_ALL_NEW etac R_cases  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
837  | 
THEN_ALL_NEW asm_full_simp_tac (simpset_of octxt)) 1)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
838  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
839  | 
val default_thm =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
840  | 
forall_intr_vars graph_implies_dom COMP (f_def COMP fundef_default_value)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
841  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
842  | 
fun mk_trsimp clause psimp =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
843  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
844  | 
        val ClauseInfo {qglr = (oqs, _, _, _), cdata =
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
845  | 
          ClauseContext {ctxt, cqs, gs, lhs, rhs, ...}, ...} = clause
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
846  | 
val thy = ProofContext.theory_of ctxt  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
847  | 
val rhs_f = Pattern.rewrite_term thy [(fvar, f)] [] rhs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
848  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
849  | 
val trsimp = Logic.list_implies(gs,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
850  | 
HOLogic.mk_Trueprop (HOLogic.mk_eq(f $ lhs, rhs_f))) (* "f lhs = rhs" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
851  | 
val lhs_acc = (mk_acc domT R $ lhs) (* "acc R lhs" *)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
852  | 
fun simp_default_tac ss =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
853  | 
asm_full_simp_tac (ss addsimps [default_thm, Let_def])  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
854  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
855  | 
Goal.prove ctxt [] [] trsimp (fn _ =>  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
856  | 
rtac (instantiate' [] [SOME (cterm_of thy lhs_acc)] case_split) 1  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
857  | 
THEN (rtac (Thm.forall_elim_vars 0 psimp) THEN_ALL_NEW assume_tac) 1  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
858  | 
THEN (simp_default_tac (simpset_of ctxt) 1)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
859  | 
THEN (etac not_acc_down 1)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
860  | 
THEN ((etac R_cases)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
861  | 
THEN_ALL_NEW (simp_default_tac (simpset_of ctxt))) 1)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
862  | 
|> fold_rev forall_intr_rename (map fst oqs ~~ cqs)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
863  | 
end  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
864  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
865  | 
map2 mk_trsimp clauses psimps  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
866  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
867  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
868  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
869  | 
fun prepare_function config defname [((fname, fT), mixfix)] abstract_qglrs lthy =  | 
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
870  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
871  | 
    val FunctionConfig {domintros, tailrec, default=default_str, ...} = config
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
872  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
873  | 
val fvar = Free (fname, fT)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
874  | 
val domT = domain_type fT  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
875  | 
val ranT = range_type fT  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
876  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
877  | 
val default = Syntax.parse_term lthy default_str  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
878  | 
|> TypeInfer.constrain fT |> Syntax.check_term lthy  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
879  | 
|
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
880  | 
val (globals, ctxt') = fix_globals domT ranT fvar lthy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
881  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
882  | 
    val Globals { x, h, ... } = globals
 | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
883  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
884  | 
val clauses = map (mk_clause_context x ctxt') abstract_qglrs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
885  | 
|
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
886  | 
val n = length abstract_qglrs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
887  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
888  | 
    fun build_tree (ClauseContext { ctxt, rhs, ...}) =
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
889  | 
Function_Ctx_Tree.mk_tree (fname, fT) h ctxt rhs  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
890  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
891  | 
val trees = map build_tree clauses  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
892  | 
val RCss = map find_calls trees  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
893  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
894  | 
val ((G, GIntro_thms, G_elim, G_induct), lthy) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
895  | 
PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
896  | 
|
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
897  | 
val ((f, (_, f_defthm)), lthy) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
898  | 
PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
899  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
900  | 
val RCss = map (map (inst_RC (ProofContext.theory_of lthy) fvar f)) RCss  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
901  | 
val trees = map (Function_Ctx_Tree.inst_tree (ProofContext.theory_of lthy) fvar f) trees  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
902  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
903  | 
val ((R, RIntro_thmss, R_elim), lthy) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
904  | 
PROFILE "def_rel" (define_recursion_relation (rel_name defname) domT abstract_qglrs clauses RCss) lthy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
905  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
906  | 
val (_, lthy) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
907  | 
Local_Theory.abbrev Syntax.mode_default ((Binding.name (dom_name defname), NoSyn), mk_acc domT R) lthy  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
908  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
909  | 
val newthy = ProofContext.theory_of lthy  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
910  | 
val clauses = map (transfer_clause_ctx newthy) clauses  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
911  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
912  | 
val cert = cterm_of (ProofContext.theory_of lthy)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
913  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
914  | 
val xclauses = PROFILE "xclauses"  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
915  | 
(map7 (mk_clause_info globals G f) (1 upto n) clauses abstract_qglrs trees  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
916  | 
RCss GIntro_thms) RIntro_thmss  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
917  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
918  | 
val complete =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
919  | 
mk_completeness globals clauses abstract_qglrs |> cert |> assume  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
920  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
921  | 
val compat =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
922  | 
mk_compat_proof_obligations domT ranT fvar f abstract_qglrs  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
923  | 
|> map (cert #> assume)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
924  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
925  | 
val compat_store = store_compat_thms n compat  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
926  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
927  | 
val (goalstate, values) = PROFILE "prove_stuff"  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
928  | 
(prove_stuff lthy globals G f R xclauses complete compat  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
929  | 
compat_store G_elim) f_defthm  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
930  | 
|
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
931  | 
val mk_trsimps =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
932  | 
mk_trsimps lthy globals f G R f_defthm R_elim G_induct xclauses  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
933  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
934  | 
fun mk_partial_rules provedgoal =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
935  | 
let  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
936  | 
val newthy = theory_of_thm provedgoal (*FIXME*)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
937  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
938  | 
val (graph_is_function, complete_thm) =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
939  | 
provedgoal  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
940  | 
|> Conjunction.elim  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
941  | 
|> apfst (Thm.forall_elim_vars 0)  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
942  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
943  | 
val f_iff = graph_is_function RS (f_defthm RS ex1_implies_iff)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
944  | 
|
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
945  | 
val psimps = PROFILE "Proving simplification rules"  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
946  | 
(mk_psimps newthy globals R xclauses values f_iff) graph_is_function  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
947  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
948  | 
val simple_pinduct = PROFILE "Proving partial induction rule"  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
949  | 
(mk_partial_induct_rule newthy globals R complete_thm) xclauses  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
950  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
951  | 
val total_intro = PROFILE "Proving nested termination rule"  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
952  | 
(mk_nest_term_rule newthy globals R R_elim) xclauses  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
953  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
954  | 
val dom_intros =  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
955  | 
if domintros then SOME (PROFILE "Proving domain introduction rules"  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
956  | 
(map (mk_domain_intro lthy globals R R_elim)) xclauses)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
957  | 
else NONE  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
958  | 
val trsimps = if tailrec then SOME (mk_trsimps psimps) else NONE  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
959  | 
|
| 
34232
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
960  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
961  | 
        FunctionResult {fs=[f], G=G, R=R, cases=complete_thm,
 | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
962  | 
psimps=psimps, simple_pinducts=[simple_pinduct],  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
963  | 
termination=total_intro, trsimps=trsimps,  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
964  | 
domintros=dom_intros}  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
965  | 
end  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
966  | 
in  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
967  | 
((f, goalstate, mk_partial_rules), lthy)  | 
| 
 
36a2a3029fd3
new year's resolution: reindented code in function package
 
krauss 
parents: 
34065 
diff
changeset
 | 
968  | 
end  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
969  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
970  | 
|
| 
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents:  
diff
changeset
 | 
971  | 
end  |