| author | wenzelm |
| Tue, 21 Nov 2006 18:07:32 +0100 | |
| changeset 21436 | 5313a4cc3823 |
| parent 21319 | cf814e36f788 |
| child 22166 | 0a50d4db234a |
| permissions | -rw-r--r-- |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
1 |
(* Title: HOL/Tools/function_package/mutual.ML |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
2 |
ID: $Id$ |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
3 |
Author: Alexander Krauss, TU Muenchen |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
4 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
5 |
A package for general recursive function definitions. |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
6 |
Tools for mutual recursive definitions. |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
7 |
*) |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
8 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
9 |
signature FUNDEF_MUTUAL = |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
10 |
sig |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
11 |
|
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
12 |
val prepare_fundef_mutual : ((string * typ) * mixfix) list |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
13 |
-> term list |
|
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20534
diff
changeset
|
14 |
-> string (* default, unparsed term *) |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
15 |
-> local_theory |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
16 |
-> ((FundefCommon.mutual_info * string * FundefCommon.prep_result) * local_theory) |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
17 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
18 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
19 |
val mk_partial_rules_mutual : Proof.context -> FundefCommon.mutual_info -> FundefCommon.prep_result -> thm -> |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
20 |
FundefCommon.fundef_mresult |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
21 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
22 |
val sort_by_function : FundefCommon.mutual_info -> string list -> 'a list -> 'a list list |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
23 |
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
24 |
end |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
25 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
26 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
27 |
structure FundefMutual: FUNDEF_MUTUAL = |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
28 |
struct |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
29 |
|
|
21051
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20949
diff
changeset
|
30 |
open FundefLib |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
31 |
open FundefCommon |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
32 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
33 |
(* Theory dependencies *) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
34 |
val sum_case_rules = thms "Datatype.sum.cases" |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
35 |
val split_apply = thm "Product_Type.split" |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
36 |
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
37 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
38 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
39 |
fun mutual_induct_Pnames n = |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
40 |
if n < 5 then fst (chop n ["P","Q","R","S"]) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
41 |
else map (fn i => "P" ^ string_of_int i) (1 upto n) |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
42 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
43 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
44 |
fun open_all_all (Const ("all", _) $ Abs (n, T, b)) = apfst (cons (n, T)) (open_all_all b)
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
45 |
| open_all_all t = ([], t) |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
46 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
47 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
48 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
49 |
(* Builds a curried clause description in abstracted form *) |
| 20851 | 50 |
fun split_def ctxt fnames geq arities = |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
51 |
let |
|
21319
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
52 |
fun input_error msg = cat_lines [msg, ProofContext.string_of_term ctxt geq] |
| 21237 | 53 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
54 |
val (qs, imp) = open_all_all geq |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
55 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
56 |
val gs = Logic.strip_imp_prems imp |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
57 |
val eq = Logic.strip_imp_concl imp |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
58 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
59 |
val (f_args, rhs) = HOLogic.dest_eq (HOLogic.dest_Trueprop eq) |
| 20851 | 60 |
val (head, args) = strip_comb f_args |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
61 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
62 |
val invalid_head_msg = "Head symbol of left hand side must be " ^ plural "" "one out of " fnames ^ commas_quote fnames |
| 20851 | 63 |
val fname = fst (dest_Free head) |
|
21319
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
64 |
handle TERM _ => error (input_error invalid_head_msg) |
| 20851 | 65 |
|
|
21319
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
66 |
val _ = assert (fname mem fnames) (input_error invalid_head_msg) |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
67 |
|
|
20534
b147d0c13f6e
Fixed Subscript Exception occurring with Higher-Order recursion
krauss
parents:
20523
diff
changeset
|
68 |
fun add_bvs t is = add_loose_bnos (t, 0, is) |
| 20851 | 69 |
val rvs = (add_bvs rhs [] \\ fold add_bvs args []) |
70 |
|> map (fst o nth (rev qs)) |
|
| 21237 | 71 |
|
|
21319
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
72 |
val _ = assert (null rvs) (input_error ("Variable" ^ plural " " "s " rvs ^ commas_quote rvs
|
|
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
73 |
^ " occur" ^ plural "s" "" rvs ^ " on right hand side only:")) |
| 20851 | 74 |
|
|
21319
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
75 |
val _ = assert (forall (forall_aterms (fn Free (n, _) => not (n mem fnames) | _ => true)) gs) |
|
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
76 |
(input_error "Recursive Calls not allowed in premises") |
|
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20534
diff
changeset
|
77 |
|
|
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20534
diff
changeset
|
78 |
val k = length args |
|
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20534
diff
changeset
|
79 |
|
|
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20534
diff
changeset
|
80 |
val arities' = case Symtab.lookup arities fname of |
| 21237 | 81 |
NONE => Symtab.update (fname, k) arities |
|
21319
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
82 |
| SOME i => (assert (i = k) |
|
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
83 |
(input_error ("Function " ^ quote fname ^ " has different numbers of arguments in different equations"));
|
|
cf814e36f788
replaced "auto_term" by the simpler method "relation", which does not try
krauss
parents:
21255
diff
changeset
|
84 |
arities) |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
85 |
in |
| 21237 | 86 |
((fname, qs, gs, args, rhs), arities') |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
87 |
end |
| 21237 | 88 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
89 |
fun get_part fname = |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
90 |
the o find_first (fn (MutualPart {fvar=(n,_), ...}) => n = fname)
|
| 21237 | 91 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
92 |
(* FIXME *) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
93 |
fun mk_prod_abs e (t1, t2) = |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
94 |
let |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
95 |
val bTs = rev (map snd e) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
96 |
val T1 = fastype_of1 (bTs, t1) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
97 |
val T2 = fastype_of1 (bTs, t2) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
98 |
in |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
99 |
HOLogic.pair_const T1 T2 $ t1 $ t2 |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
100 |
end; |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
101 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
102 |
|
|
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20534
diff
changeset
|
103 |
fun analyze_eqs ctxt fs eqs = |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
104 |
let |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
105 |
val fnames = map fst fs |
| 20851 | 106 |
val (fqgars, arities) = fold_map (split_def ctxt fnames) eqs Symtab.empty |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
107 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
108 |
fun curried_types (fname, fT) = |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
109 |
let |
|
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20534
diff
changeset
|
110 |
val k = the_default 1 (Symtab.lookup arities fname) |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
111 |
val (caTs, uaTs) = chop k (binder_types fT) |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
112 |
in |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
113 |
(caTs, uaTs ---> body_type fT) |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
114 |
end |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
115 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
116 |
val (caTss, resultTs) = split_list (map curried_types fs) |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
117 |
val argTs = map (foldr1 HOLogic.mk_prodT) caTss |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
118 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
119 |
val (RST,streeR, pthsR) = SumTools.mk_tree_distinct resultTs |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
120 |
val (ST, streeA, pthsA) = SumTools.mk_tree argTs |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
121 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
122 |
val def_name = foldr1 (fn (a,b) => a ^ "_" ^ b) (map Sign.base_name fnames) |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
123 |
val fsum_type = ST --> RST |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
124 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
125 |
val ([fsum_var_name], _) = Variable.add_fixes [ def_name ^ "_sum" ] ctxt |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
126 |
val fsum_var = (fsum_var_name, fsum_type) |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
127 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
128 |
fun define (fvar as (n, T)) caTs pthA pthR = |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
129 |
let |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
130 |
val vars = map_index (fn (i,T) => Free ("x" ^ string_of_int i, T)) caTs (* FIXME: Bind xs properly *)
|
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
131 |
|
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
132 |
val f_exp = SumTools.mk_proj streeR pthR (Free fsum_var $ SumTools.mk_inj streeA pthA (foldr1 HOLogic.mk_prod vars)) |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
133 |
val def = Term.abstract_over (Free fsum_var, fold_rev lambda vars f_exp) |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
134 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
135 |
val rew = (n, fold_rev lambda vars f_exp) |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
136 |
in |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
137 |
(MutualPart {fvar=fvar,cargTs=caTs,pthA=pthA,pthR=pthR,f_def=def,f=NONE,f_defthm=NONE}, rew)
|
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
138 |
end |
| 21237 | 139 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
140 |
val (parts, rews) = split_list (map4 define fs caTss pthsA pthsR) |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
141 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
142 |
fun convert_eqs (f, qs, gs, args, rhs) = |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
143 |
let |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
144 |
val MutualPart {pthA, pthR, ...} = get_part f parts
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
145 |
in |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
146 |
(qs, gs, SumTools.mk_inj streeA pthA (foldr1 (mk_prod_abs qs) args), |
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
147 |
SumTools.mk_inj streeR pthR (replace_frees rews rhs) |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
148 |
|> Envir.norm_term (Envir.empty 0)) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
149 |
end |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
150 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
151 |
val qglrs = map convert_eqs fqgars |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
152 |
in |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
153 |
Mutual {defname=def_name,fsum_var=fsum_var, ST=ST, RST=RST, streeA=streeA, streeR=streeR,
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
154 |
parts=parts, fqgars=fqgars, qglrs=qglrs, fsum=NONE} |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
155 |
end |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
156 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
157 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
158 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
159 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
160 |
fun define_projections fixes mutual fsum lthy = |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
161 |
let |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
162 |
fun def ((MutualPart {fvar=(fname, fT), cargTs, pthA, pthR, f_def, ...}), (_, mixfix)) lthy =
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
163 |
let |
| 21436 | 164 |
val ((f, (_, f_defthm)), lthy') = |
165 |
LocalTheory.def Thm.internalK ((fname, mixfix), |
|
166 |
((fname ^ "_def", []), Term.subst_bound (fsum, f_def))) |
|
167 |
lthy |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
168 |
in |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
169 |
(MutualPart {fvar=(fname, fT), cargTs=cargTs, pthA=pthA, pthR=pthR, f_def=f_def,
|
| 21237 | 170 |
f=SOME f, f_defthm=SOME f_defthm }, |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
171 |
lthy') |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
172 |
end |
| 21237 | 173 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
174 |
val Mutual { defname, fsum_var, ST, RST, streeA, streeR, parts, fqgars, qglrs, ... } = mutual
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
175 |
val (parts', lthy') = fold_map def (parts ~~ fixes) lthy |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
176 |
in |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
177 |
(Mutual { defname=defname, fsum_var=fsum_var, ST=ST, RST=RST, streeA=streeA, streeR=streeR, parts=parts',
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
178 |
fqgars=fqgars, qglrs=qglrs, fsum=SOME fsum }, |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
179 |
lthy') |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
180 |
end |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
181 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
182 |
|
|
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20534
diff
changeset
|
183 |
fun prepare_fundef_mutual fixes eqss default lthy = |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
184 |
let |
| 21237 | 185 |
val mutual = analyze_eqs lthy (map fst fixes) eqss |
186 |
val Mutual {defname, fsum_var=(n, T), qglrs, ...} = mutual
|
|
187 |
||
188 |
val (prep_result, fsum, lthy') = |
|
189 |
FundefPrep.prepare_fundef defname (n, T, NoSyn) qglrs default lthy |
|
190 |
||
191 |
val (mutual', lthy'') = define_projections fixes mutual fsum lthy' |
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
192 |
in |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
193 |
((mutual', defname, prep_result), lthy'') |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
194 |
end |
| 21237 | 195 |
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
196 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
197 |
(* Beta-reduce both sides of a meta-equality *) |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
198 |
fun beta_norm_eq thm = |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
199 |
let |
| 21237 | 200 |
val (lhs, rhs) = dest_equals (cprop_of thm) |
201 |
val lhs_conv = beta_conversion false lhs |
|
202 |
val rhs_conv = beta_conversion false rhs |
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
203 |
in |
| 21237 | 204 |
transitive (symmetric lhs_conv) (transitive thm rhs_conv) |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
205 |
end |
| 21237 | 206 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
207 |
fun beta_reduce thm = Thm.equal_elim (Thm.beta_conversion true (cprop_of thm)) thm |
| 21237 | 208 |
|
209 |
||
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
210 |
fun in_context ctxt (f, pre_qs, pre_gs, pre_args, pre_rhs) F = |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
211 |
let |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
212 |
val thy = ProofContext.theory_of ctxt |
| 21237 | 213 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
214 |
val oqnames = map fst pre_qs |
|
20797
c1f0bc7e7d80
renamed Variable.invent_fixes to Variable.variant_fixes;
wenzelm
parents:
20654
diff
changeset
|
215 |
val (qs, ctxt') = Variable.variant_fixes oqnames ctxt |
| 21237 | 216 |
|>> map2 (fn (_, T) => fn n => Free (n, T)) pre_qs |
217 |
||
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
218 |
fun inst t = subst_bounds (rev qs, t) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
219 |
val gs = map inst pre_gs |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
220 |
val args = map inst pre_args |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
221 |
val rhs = inst pre_rhs |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
222 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
223 |
val cqs = map (cterm_of thy) qs |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
224 |
val ags = map (assume o cterm_of thy) gs |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
225 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
226 |
val import = fold forall_elim cqs |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
227 |
#> fold implies_elim_swp ags |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
228 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
229 |
val export = fold_rev (implies_intr o cprop_of) ags |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
230 |
#> fold_rev forall_intr_rename (oqnames ~~ cqs) |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
231 |
in |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
232 |
F (f, qs, gs, args, rhs) import export |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
233 |
end |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
234 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
235 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
236 |
fun recover_mutual_psimp thy RST streeR all_f_defs parts (f, _, _, args, _) import (export : thm -> thm) sum_psimp_eq = |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
237 |
let |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
238 |
val (MutualPart {f_defthm=SOME f_def, pthR, ...}) = get_part f parts
|
| 21237 | 239 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
240 |
val psimp = import sum_psimp_eq |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
241 |
val (simp, restore_cond) = case cprems_of psimp of |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
242 |
[] => (psimp, I) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
243 |
| [cond] => (implies_elim psimp (assume cond), implies_intr cond) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
244 |
| _ => sys_error "Too many conditions" |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
245 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
246 |
val x = Free ("x", RST)
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
247 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
248 |
val f_def_inst = fold (fn arg => fn thm => combination thm (reflexive (cterm_of thy arg))) args (Thm.freezeT f_def) (* FIXME *) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
249 |
|> beta_reduce |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
250 |
in |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
251 |
reflexive (cterm_of thy (lambda x (SumTools.mk_proj streeR pthR x))) (* PR(x) == PR(x) *) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
252 |
|> (fn it => combination it (simp RS eq_reflection)) |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
253 |
|> beta_norm_eq (* PR(S(I(as))) == PR(IR(...)) *) |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
254 |
|> transitive f_def_inst (* f ... == PR(IR(...)) *) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
255 |
|> simplify (HOL_basic_ss addsimps [SumTools.projl_inl, SumTools.projr_inr]) (* f ... == ... *) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
256 |
|> simplify (HOL_basic_ss addsimps all_f_defs) (* f ... == ... *) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
257 |
|> (fn it => it RS meta_eq_to_obj_eq) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
258 |
|> restore_cond |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
259 |
|> export |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
260 |
end |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
261 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
262 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
263 |
(* FIXME HACK *) |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
264 |
fun mk_applied_form ctxt caTs thm = |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
265 |
let |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
266 |
val thy = ProofContext.theory_of ctxt |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
267 |
val xs = map_index (fn (i,T) => cterm_of thy (Free ("x" ^ string_of_int i, T))) caTs (* FIXME: Bind xs properly *)
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
268 |
in |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
269 |
fold (fn x => fn thm => combination thm (reflexive x)) xs thm |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
270 |
|> beta_reduce |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
271 |
|> fold_rev forall_intr xs |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
272 |
|> forall_elim_vars 0 |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
273 |
end |
| 21237 | 274 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
275 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
276 |
fun mutual_induct_rules thy induct all_f_defs (Mutual {RST, parts, streeA, ...}) =
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
277 |
let |
| 20949 | 278 |
val newPs = map2 (fn Pname => fn MutualPart {cargTs, ...} =>
|
| 21237 | 279 |
Free (Pname, cargTs ---> HOLogic.boolT)) |
| 20949 | 280 |
(mutual_induct_Pnames (length parts)) |
281 |
parts |
|
| 21237 | 282 |
|
283 |
fun mk_P (MutualPart {cargTs, ...}) P =
|
|
284 |
let |
|
285 |
val avars = map_index (fn (i,T) => Var (("a", i), T)) cargTs
|
|
286 |
val atup = foldr1 HOLogic.mk_prod avars |
|
287 |
in |
|
288 |
tupled_lambda atup (list_comb (P, avars)) |
|
289 |
end |
|
290 |
||
291 |
val Ps = map2 mk_P parts newPs |
|
292 |
val case_exp = SumTools.mk_sumcases streeA HOLogic.boolT Ps |
|
293 |
||
294 |
val induct_inst = |
|
295 |
forall_elim (cterm_of thy case_exp) induct |
|
296 |
|> full_simplify (HOL_basic_ss addsimps (split_apply :: sum_case_rules)) |
|
297 |
|> full_simplify (HOL_basic_ss addsimps all_f_defs) |
|
298 |
||
299 |
fun mk_proj rule (MutualPart {cargTs, pthA, ...}) =
|
|
300 |
let |
|
301 |
val afs = map_index (fn (i,T) => Free ("a" ^ string_of_int i, T)) cargTs
|
|
302 |
val inj = SumTools.mk_inj streeA pthA (foldr1 HOLogic.mk_prod afs) |
|
303 |
in |
|
304 |
rule |
|
305 |
|> forall_elim (cterm_of thy inj) |
|
306 |
|> full_simplify (HOL_basic_ss addsimps (split_apply :: sum_case_rules)) |
|
307 |
|> fold_rev (forall_intr o cterm_of thy) (afs @ newPs) |
|
308 |
end |
|
309 |
||
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
310 |
in |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
311 |
map (mk_proj induct_inst) parts |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
312 |
end |
| 21237 | 313 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
314 |
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
315 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
316 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
317 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
318 |
fun mk_partial_rules_mutual lthy (m as Mutual {RST, parts, streeR, fqgars, ...}) data prep_result =
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
319 |
let |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
320 |
val thy = ProofContext.theory_of lthy |
| 21237 | 321 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
322 |
(* FIXME !? *) |
| 21237 | 323 |
val expand = Assumption.export false lthy (LocalTheory.target_of lthy) |
324 |
val expand_term = Drule.term_rule thy expand |
|
325 |
||
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
326 |
val result = FundefProof.mk_partial_rules thy data prep_result |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
327 |
val FundefResult {f, G, R, completeness, psimps, subset_pinduct,simple_pinduct,total_intro,dom_intros} = result
|
| 21237 | 328 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
329 |
val all_f_defs = map (fn MutualPart {f_defthm = SOME f_def, cargTs, ...} =>
|
|
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
330 |
mk_applied_form lthy cargTs (symmetric (Thm.freezeT f_def))) |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
331 |
parts |
| 21237 | 332 |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
333 |
fun mk_mpsimp fqgar sum_psimp = |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
334 |
in_context lthy fqgar (recover_mutual_psimp thy RST streeR all_f_defs parts) sum_psimp |
| 21237 | 335 |
|
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
336 |
val mpsimps = PROFILE "making mpsimps" (map2 mk_mpsimp fqgars) psimps |
|
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
337 |
val minducts = PROFILE "making mpinduct" (mutual_induct_rules thy simple_pinduct all_f_defs) m |
|
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
338 |
val termination = PROFILE "making mtermination" (full_simplify (HOL_basic_ss addsimps all_f_defs)) total_intro |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
339 |
in |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
340 |
FundefMResult { f=expand_term f, G=expand_term G, R=expand_term R,
|
| 21237 | 341 |
psimps=map expand mpsimps, subset_pinducts=[expand subset_pinduct], simple_pinducts=map expand minducts, |
342 |
cases=expand completeness, termination=expand termination, |
|
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
343 |
domintros=map expand dom_intros } |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
344 |
end |
| 21237 | 345 |
|
346 |
||
347 |
||
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
348 |
(* puts an object in the "right bucket" *) |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
349 |
fun store_grouped P x [] = [] |
|
20878
384c5bb713b2
mk_partial_rules_mutual: expand result terms/thms;
wenzelm
parents:
20851
diff
changeset
|
350 |
| store_grouped P x ((l, xs)::bs) = |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
351 |
if P (x, l) then ((l, x::xs)::bs) else ((l, xs)::store_grouped P x bs) |
| 21237 | 352 |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19922
diff
changeset
|
353 |
fun sort_by_function (Mutual {fqgars, ...}) names xs =
|
| 21237 | 354 |
fold_rev (store_grouped (eq_str o apfst fst)) (* fill *) |
355 |
(map name_of_fqgar fqgars ~~ xs) (* the name-thm pairs *) |
|
356 |
(map (rpair []) names) (* in the empty buckets labeled with names *) |
|
357 |
||
358 |
|> map (snd #> map snd) (* and remove the labels afterwards *) |
|
359 |
||
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
diff
changeset
|
360 |
end |