| author | bulwahn | 
| Mon, 19 Sep 2011 16:18:21 +0200 | |
| changeset 44999 | 04b794da039e | 
| parent 42795 | 66fcc9882784 | 
| child 51717 | 9e7d1c139569 | 
| permissions | -rw-r--r-- | 
| 31775 | 1  | 
(* Title: HOL/Tools/Function/scnp_reconstruct.ML  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
2  | 
Author: Armin Heller, TU Muenchen  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
3  | 
Author: Alexander Krauss, TU Muenchen  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
4  | 
|
| 41114 | 5  | 
Proof reconstruction for SCNP termination.  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
6  | 
*)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
7  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
8  | 
signature SCNP_RECONSTRUCT =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
9  | 
sig  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
10  | 
|
| 29877 | 11  | 
val sizechange_tac : Proof.context -> tactic -> tactic  | 
12  | 
||
| 36521 | 13  | 
val decomp_scnp_tac : ScnpSolve.label list -> Proof.context -> tactic  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
14  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
15  | 
val setup : theory -> theory  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
16  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
17  | 
datatype multiset_setup =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
18  | 
Multiset of  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
19  | 
    {
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
20  | 
msetT : typ -> typ,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
21  | 
mk_mset : typ -> term list -> term,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
22  | 
mset_regroup_conv : int list -> conv,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
23  | 
mset_member_tac : int -> int -> tactic,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
24  | 
mset_nonempty_tac : int -> tactic,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
25  | 
mset_pwleq_tac : int -> tactic,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
26  | 
set_of_simps : thm list,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
27  | 
smsI' : thm,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
28  | 
wmsI2'' : thm,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
29  | 
wmsI1 : thm,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
30  | 
reduction_pair : thm  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
31  | 
}  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
32  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
33  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
34  | 
val multiset_setup : multiset_setup -> theory -> theory  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
35  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
36  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
37  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
38  | 
structure ScnpReconstruct : SCNP_RECONSTRUCT =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
39  | 
struct  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
40  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents: 
33063 
diff
changeset
 | 
41  | 
val PROFILE = Function_Common.PROFILE  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
42  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
43  | 
open ScnpSolve  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
44  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
45  | 
val natT = HOLogic.natT  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
46  | 
val nat_pairT = HOLogic.mk_prodT (natT, natT)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
47  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
48  | 
(* Theory dependencies *)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
49  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
50  | 
datatype multiset_setup =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
51  | 
Multiset of  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
52  | 
  {
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
53  | 
msetT : typ -> typ,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
54  | 
mk_mset : typ -> term list -> term,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
55  | 
mset_regroup_conv : int list -> conv,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
56  | 
mset_member_tac : int -> int -> tactic,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
57  | 
mset_nonempty_tac : int -> tactic,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
58  | 
mset_pwleq_tac : int -> tactic,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
59  | 
set_of_simps : thm list,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
60  | 
smsI' : thm,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
61  | 
wmsI2'' : thm,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
62  | 
wmsI1 : thm,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
63  | 
reduction_pair : thm  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
64  | 
}  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
65  | 
|
| 33522 | 66  | 
structure Multiset_Setup = Theory_Data  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
67  | 
(  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
68  | 
type T = multiset_setup option  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
69  | 
val empty = NONE  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
70  | 
val extend = I;  | 
| 41493 | 71  | 
val merge = merge_options  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
72  | 
)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
73  | 
|
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents: 
33063 
diff
changeset
 | 
74  | 
val multiset_setup = Multiset_Setup.put o SOME  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
75  | 
|
| 
33855
 
cd8acf137c9c
eliminated dead code and some unused bindings, reported by polyml
 
krauss 
parents: 
33583 
diff
changeset
 | 
76  | 
fun undef _ = error "undef"  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents: 
33063 
diff
changeset
 | 
77  | 
fun get_multiset_setup thy = Multiset_Setup.get thy  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
78  | 
|> the_default (Multiset  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
79  | 
{ msetT = undef, mk_mset=undef,
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
80  | 
mset_regroup_conv=undef, mset_member_tac = undef,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
81  | 
mset_nonempty_tac = undef, mset_pwleq_tac = undef,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
82  | 
set_of_simps = [],reduction_pair = refl,  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
83  | 
smsI'=refl, wmsI2''=refl, wmsI1=refl })  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
84  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
85  | 
fun order_rpair _ MAX = @{thm max_rpair_set}
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
86  | 
| order_rpair msrp MS = msrp  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
87  | 
  | order_rpair _ MIN = @{thm min_rpair_set}
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
88  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
89  | 
fun ord_intros_max true =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
90  | 
    (@{thm smax_emptyI}, @{thm smax_insertI})
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
91  | 
| ord_intros_max false =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
92  | 
    (@{thm wmax_emptyI}, @{thm wmax_insertI})
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
93  | 
fun ord_intros_min true =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
94  | 
    (@{thm smin_emptyI}, @{thm smin_insertI})
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
95  | 
| ord_intros_min false =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
96  | 
    (@{thm wmin_emptyI}, @{thm wmin_insertI})
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
97  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
98  | 
fun gen_probl D cs =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
99  | 
let  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
100  | 
val n = Termination.get_num_points D  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
101  | 
val arity = length o Termination.get_measures D  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
102  | 
fun measure p i = nth (Termination.get_measures D p) i  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
103  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
104  | 
fun mk_graph c =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
105  | 
let  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
106  | 
val (_, p, _, q, _, _) = Termination.dest_call D c  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
107  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
108  | 
fun add_edge i j =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
109  | 
case Termination.get_descent D c (measure p i) (measure q j)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
110  | 
of SOME (Termination.Less _) => cons (i, GTR, j)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
111  | 
| SOME (Termination.LessEq _) => cons (i, GEQ, j)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
112  | 
| _ => I  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
113  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
114  | 
val edges =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
115  | 
fold_product add_edge (0 upto arity p - 1) (0 upto arity q - 1) []  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
116  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
117  | 
G (p, q, edges)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
118  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
119  | 
in  | 
| 33063 | 120  | 
GP (map_range arity n, map mk_graph cs)  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
121  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
122  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
123  | 
(* General reduction pair application *)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
124  | 
fun rem_inv_img ctxt =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
125  | 
let  | 
| 35624 | 126  | 
val unfold_tac = Local_Defs.unfold_tac ctxt  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
127  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
128  | 
    rtac @{thm subsetI} 1
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
129  | 
    THEN etac @{thm CollectE} 1
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
130  | 
    THEN REPEAT (etac @{thm exE} 1)
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
131  | 
    THEN unfold_tac @{thms inv_image_def}
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
132  | 
    THEN rtac @{thm CollectI} 1
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
133  | 
    THEN etac @{thm conjE} 1
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
134  | 
    THEN etac @{thm ssubst} 1
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
135  | 
    THEN unfold_tac (@{thms split_conv} @ @{thms triv_forall_equality}
 | 
| 
29183
 
f1648e009dc1
removed duplicate sum_case used only by function package;
 
krauss 
parents: 
29125 
diff
changeset
 | 
136  | 
                     @ @{thms sum.cases})
 | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
137  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
138  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
139  | 
(* Sets *)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
140  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
141  | 
val setT = HOLogic.mk_setT  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
142  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
143  | 
fun set_member_tac m i =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
144  | 
  if m = 0 then rtac @{thm insertI1} i
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
145  | 
  else rtac @{thm insertI2} i THEN set_member_tac (m - 1) i
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
146  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
147  | 
val set_nonempty_tac = rtac @{thm insert_not_empty}
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
148  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
149  | 
fun set_finite_tac i =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
150  | 
  rtac @{thm finite.emptyI} i
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
151  | 
  ORELSE (rtac @{thm finite.insertI} i THEN (fn st => set_finite_tac i st))
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
152  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
153  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
154  | 
(* Reconstruction *)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
155  | 
|
| 
33855
 
cd8acf137c9c
eliminated dead code and some unused bindings, reported by polyml
 
krauss 
parents: 
33583 
diff
changeset
 | 
156  | 
fun reconstruct_tac ctxt D cs (GP (_, gs)) certificate =  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
157  | 
let  | 
| 42361 | 158  | 
val thy = Proof_Context.theory_of ctxt  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
159  | 
val Multiset  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
160  | 
          { msetT, mk_mset,
 | 
| 
33855
 
cd8acf137c9c
eliminated dead code and some unused bindings, reported by polyml
 
krauss 
parents: 
33583 
diff
changeset
 | 
161  | 
mset_regroup_conv, mset_pwleq_tac, set_of_simps,  | 
| 
 
cd8acf137c9c
eliminated dead code and some unused bindings, reported by polyml
 
krauss 
parents: 
33583 
diff
changeset
 | 
162  | 
smsI', wmsI2'', wmsI1, reduction_pair=ms_rp, ...}  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
163  | 
= get_multiset_setup thy  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
164  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
165  | 
fun measure_fn p = nth (Termination.get_measures D p)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
166  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
167  | 
fun get_desc_thm cidx m1 m2 bStrict =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
168  | 
case Termination.get_descent D (nth cs cidx) m1 m2  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
169  | 
of SOME (Termination.Less thm) =>  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
170  | 
if bStrict then thm  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
171  | 
          else (thm COMP (Thm.lift_rule (cprop_of thm) @{thm less_imp_le}))
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
172  | 
| SOME (Termination.LessEq (thm, _)) =>  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
173  | 
if not bStrict then thm  | 
| 
40317
 
1eac228c52b3
replaced ancient sys_error by raise Fail, assuming that the latter is not handled specifically by the environment;
 
wenzelm 
parents: 
39925 
diff
changeset
 | 
174  | 
else raise Fail "get_desc_thm"  | 
| 
 
1eac228c52b3
replaced ancient sys_error by raise Fail, assuming that the latter is not handled specifically by the environment;
 
wenzelm 
parents: 
39925 
diff
changeset
 | 
175  | 
| _ => raise Fail "get_desc_thm"  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
176  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
177  | 
val (label, lev, sl, covering) = certificate  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
178  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
179  | 
fun prove_lev strict g =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
180  | 
let  | 
| 
33855
 
cd8acf137c9c
eliminated dead code and some unused bindings, reported by polyml
 
krauss 
parents: 
33583 
diff
changeset
 | 
181  | 
val G (p, q, _) = nth gs g  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
182  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
183  | 
fun less_proof strict (j, b) (i, a) =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
184  | 
let  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
185  | 
val tag_flag = b < a orelse (not strict andalso b <= a)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
186  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
187  | 
val stored_thm =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
188  | 
get_desc_thm g (measure_fn p i) (measure_fn q j)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
189  | 
(not tag_flag)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
190  | 
|> Conv.fconv_rule (Thm.beta_conversion true)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
191  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
192  | 
val rule = if strict  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
193  | 
              then if b < a then @{thm pair_lessI2} else @{thm pair_lessI1}
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
194  | 
              else if b <= a then @{thm pair_leqI2} else @{thm pair_leqI1}
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
195  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
196  | 
rtac rule 1 THEN PRIMITIVE (Thm.elim_implies stored_thm)  | 
| 33569 | 197  | 
THEN (if tag_flag then Arith_Data.arith_tac ctxt 1 else all_tac)  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
198  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
199  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
200  | 
fun steps_tac MAX strict lq lp =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
201  | 
let  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
202  | 
val (empty, step) = ord_intros_max strict  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
203  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
204  | 
if length lq = 0  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
205  | 
then rtac empty 1 THEN set_finite_tac 1  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
206  | 
THEN (if strict then set_nonempty_tac 1 else all_tac)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
207  | 
else  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
208  | 
let  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
209  | 
val (j, b) :: rest = lq  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
210  | 
val (i, a) = the (covering g strict j)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
211  | 
fun choose xs = set_member_tac (Library.find_index (curry op = (i, a)) xs) 1  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
212  | 
val solve_tac = choose lp THEN less_proof strict (j, b) (i, a)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
213  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
214  | 
rtac step 1 THEN solve_tac THEN steps_tac MAX strict rest lp  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
215  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
216  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
217  | 
| steps_tac MIN strict lq lp =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
218  | 
let  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
219  | 
val (empty, step) = ord_intros_min strict  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
220  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
221  | 
if length lp = 0  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
222  | 
then rtac empty 1  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
223  | 
THEN (if strict then set_nonempty_tac 1 else all_tac)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
224  | 
else  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
225  | 
let  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
226  | 
val (i, a) :: rest = lp  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
227  | 
val (j, b) = the (covering g strict i)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
228  | 
fun choose xs = set_member_tac (Library.find_index (curry op = (j, b)) xs) 1  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
229  | 
val solve_tac = choose lq THEN less_proof strict (j, b) (i, a)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
230  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
231  | 
rtac step 1 THEN solve_tac THEN steps_tac MIN strict lq rest  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
232  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
233  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
234  | 
| steps_tac MS strict lq lp =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
235  | 
let  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
236  | 
fun get_str_cover (j, b) =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
237  | 
if is_some (covering g true j) then SOME (j, b) else NONE  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
238  | 
fun get_wk_cover (j, b) = the (covering g false j)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
239  | 
|
| 33040 | 240  | 
val qs = subtract (op =) (map_filter get_str_cover lq) lq  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
241  | 
val ps = map get_wk_cover qs  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
242  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
243  | 
fun indices xs ys = map (fn y => Library.find_index (curry op = y) xs) ys  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
244  | 
val iqs = indices lq qs  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
245  | 
val ips = indices lp ps  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
246  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
247  | 
local open Conv in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
248  | 
fun t_conv a C =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
249  | 
params_conv ~1 (K ((concl_conv ~1 o arg_conv o arg1_conv o a) C)) ctxt  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
250  | 
val goal_rewrite =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
251  | 
t_conv arg1_conv (mset_regroup_conv iqs)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
252  | 
then_conv t_conv arg_conv (mset_regroup_conv ips)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
253  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
254  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
255  | 
CONVERSION goal_rewrite 1  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
256  | 
THEN (if strict then rtac smsI' 1  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
257  | 
else if qs = lq then rtac wmsI2'' 1  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
258  | 
else rtac wmsI1 1)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
259  | 
THEN mset_pwleq_tac 1  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
260  | 
THEN EVERY (map2 (less_proof false) qs ps)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
261  | 
THEN (if strict orelse qs <> lq  | 
| 35624 | 262  | 
then Local_Defs.unfold_tac ctxt set_of_simps  | 
| 33040 | 263  | 
THEN steps_tac MAX true  | 
264  | 
(subtract (op =) qs lq) (subtract (op =) ps lp)  | 
|
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
265  | 
else all_tac)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
266  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
267  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
268  | 
rem_inv_img ctxt  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
269  | 
THEN steps_tac label strict (nth lev q) (nth lev p)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
270  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
271  | 
|
| 30450 | 272  | 
val (mk_set, setT) = if label = MS then (mk_mset, msetT) else (HOLogic.mk_set, setT)  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
273  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
274  | 
fun tag_pair p (i, tag) =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
275  | 
HOLogic.pair_const natT natT $  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
276  | 
(measure_fn p i $ Bound 0) $ HOLogic.mk_number natT tag  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
277  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
278  | 
    fun pt_lev (p, lm) = Abs ("x", Termination.get_types D p,
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
279  | 
mk_set nat_pairT (map (tag_pair p) lm))  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
280  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
281  | 
val level_mapping =  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
282  | 
map_index pt_lev lev  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
283  | 
|> Termination.mk_sumcases D (setT nat_pairT)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
284  | 
|> cterm_of thy  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
285  | 
in  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
286  | 
PROFILE "Proof Reconstruction"  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents: 
33063 
diff
changeset
 | 
287  | 
(CONVERSION (Conv.arg_conv (Conv.arg_conv (Function_Lib.regroup_union_conv sl))) 1  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
288  | 
         THEN (rtac @{thm reduction_pair_lemma} 1)
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
289  | 
         THEN (rtac @{thm rp_inv_image_rp} 1)
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
290  | 
THEN (rtac (order_rpair ms_rp label) 1)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
291  | 
THEN PRIMITIVE (instantiate' [] [SOME level_mapping])  | 
| 
32149
 
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
 
wenzelm 
parents: 
31902 
diff
changeset
 | 
292  | 
         THEN unfold_tac @{thms rp_inv_image_def} (simpset_of ctxt)
 | 
| 35624 | 293  | 
THEN Local_Defs.unfold_tac ctxt  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
294  | 
           (@{thms split_conv} @ @{thms fst_conv} @ @{thms snd_conv})
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
295  | 
         THEN REPEAT (SOMEGOAL (resolve_tac [@{thm Un_least}, @{thm empty_subsetI}]))
 | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
296  | 
THEN EVERY (map (prove_lev true) sl)  | 
| 33040 | 297  | 
THEN EVERY (map (prove_lev false) (subtract (op =) sl (0 upto length cs - 1))))  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
298  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
299  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
300  | 
|
| 
39924
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
301  | 
fun single_scnp_tac use_tags orders ctxt D = Termination.CALLS (fn (cs, i) =>  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
302  | 
let  | 
| 42361 | 303  | 
val ms_configured = is_some (Multiset_Setup.get (Proof_Context.theory_of ctxt))  | 
| 29877 | 304  | 
val orders' = if ms_configured then orders  | 
305  | 
else filter_out (curry op = MS) orders  | 
|
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
306  | 
val gp = gen_probl D cs  | 
| 29877 | 307  | 
val certificate = generate_certificate use_tags orders' gp  | 
308  | 
in  | 
|
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
309  | 
case certificate  | 
| 
39924
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
310  | 
of NONE => no_tac  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
311  | 
| SOME cert =>  | 
| 29877 | 312  | 
SELECT_GOAL (reconstruct_tac ctxt D cs gp cert) i  | 
| 
39924
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
313  | 
          THEN TRY (rtac @{thm wf_empty} i)
 | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
314  | 
end)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
315  | 
|
| 
39924
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
316  | 
local open Termination in  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
317  | 
|
| 
39924
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
318  | 
fun gen_decomp_scnp_tac orders autom_tac ctxt =  | 
| 
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
319  | 
TERMINATION ctxt autom_tac (fn D =>  | 
| 
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
320  | 
let  | 
| 
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
321  | 
val decompose = decompose_tac D  | 
| 
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
322  | 
val scnp_full = single_scnp_tac true orders ctxt D  | 
| 
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
323  | 
in  | 
| 
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
324  | 
REPEAT_ALL_NEW (scnp_full ORELSE' decompose)  | 
| 
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
325  | 
end)  | 
| 
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
326  | 
end  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
327  | 
|
| 
39924
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
328  | 
fun gen_sizechange_tac orders autom_tac ctxt =  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents: 
33063 
diff
changeset
 | 
329  | 
TRY (Function_Common.apply_termination_rule ctxt 1)  | 
| 
30607
 
c3d1590debd8
eliminated global SIMPSET, CLASET etc. -- refer to explicit context;
 
wenzelm 
parents: 
30510 
diff
changeset
 | 
330  | 
THEN TRY (Termination.wf_union_tac ctxt)  | 
| 29877 | 331  | 
THEN  | 
332  | 
   (rtac @{thm wf_empty} 1
 | 
|
| 
39924
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
333  | 
ORELSE gen_decomp_scnp_tac orders autom_tac ctxt 1)  | 
| 29877 | 334  | 
|
335  | 
fun sizechange_tac ctxt autom_tac =  | 
|
| 
39924
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
336  | 
gen_sizechange_tac [MAX, MS, MIN] autom_tac ctxt  | 
| 29877 | 337  | 
|
| 36521 | 338  | 
fun decomp_scnp_tac orders ctxt =  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
339  | 
let  | 
| 
33099
 
b8cdd3d73022
function package: more standard names for structures and files
 
krauss 
parents: 
33063 
diff
changeset
 | 
340  | 
val extra_simps = Function_Common.Termination_Simps.get ctxt  | 
| 
42795
 
66fcc9882784
clarified map_simpset versus Simplifier.map_simpset_global;
 
wenzelm 
parents: 
42793 
diff
changeset
 | 
341  | 
val autom_tac = auto_tac (map_simpset (fn ss => ss addsimps extra_simps) ctxt)  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
342  | 
in  | 
| 
39924
 
f4d3e70ed3a8
discontinued continuations to simplify control flow; dropped optimization in scnp
 
krauss 
parents: 
39923 
diff
changeset
 | 
343  | 
gen_sizechange_tac orders autom_tac ctxt  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
344  | 
end  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
345  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
346  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
347  | 
(* Method setup *)  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
348  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
349  | 
val orders =  | 
| 31242 | 350  | 
Scan.repeat1  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
351  | 
((Args.$$$ "max" >> K MAX) ||  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
352  | 
(Args.$$$ "min" >> K MIN) ||  | 
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
353  | 
(Args.$$$ "ms" >> K MS))  | 
| 31242 | 354  | 
|| Scan.succeed [MAX, MS, MIN]  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
355  | 
|
| 33468 | 356  | 
val setup = Method.setup @{binding size_change}
 | 
| 36521 | 357  | 
(Scan.lift orders --| Method.sections clasimp_modifiers >>  | 
358  | 
(fn orders => SIMPLE_METHOD o decomp_scnp_tac orders))  | 
|
| 31242 | 359  | 
"termination prover with graph decomposition and the NP subset of size change termination"  | 
| 
29125
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
360  | 
|
| 
 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 
krauss 
parents:  
diff
changeset
 | 
361  | 
end  |