author | krauss |
Fri, 23 Oct 2009 14:33:07 +0200 | |
changeset 33083 | 1fad3160d873 |
parent 32235 | 8f9b8d14fc9f |
child 33098 | 3e9ae9032273 |
permissions | -rw-r--r-- |
20324 | 1 |
(* Title: HOL/FunDef.thy |
2 |
Author: Alexander Krauss, TU Muenchen |
|
22816 | 3 |
*) |
20324 | 4 |
|
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
5 |
header {* Function Definitions and Termination Proofs *} |
20324 | 6 |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
7 |
theory FunDef |
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
25567
diff
changeset
|
8 |
imports Wellfounded |
22816 | 9 |
uses |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
10 |
"Tools/prop_logic.ML" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
11 |
"Tools/sat_solver.ML" |
31775 | 12 |
("Tools/Function/fundef_lib.ML") |
13 |
("Tools/Function/fundef_common.ML") |
|
14 |
("Tools/Function/inductive_wrap.ML") |
|
15 |
("Tools/Function/context_tree.ML") |
|
16 |
("Tools/Function/fundef_core.ML") |
|
17 |
("Tools/Function/sum_tree.ML") |
|
18 |
("Tools/Function/mutual.ML") |
|
19 |
("Tools/Function/pattern_split.ML") |
|
20 |
("Tools/Function/fundef.ML") |
|
21 |
("Tools/Function/auto_term.ML") |
|
22 |
("Tools/Function/measure_functions.ML") |
|
23 |
("Tools/Function/lexicographic_order.ML") |
|
33083 | 24 |
("Tools/Function/pat_completeness.ML") |
31775 | 25 |
("Tools/Function/fundef_datatype.ML") |
26 |
("Tools/Function/induction_scheme.ML") |
|
27 |
("Tools/Function/termination.ML") |
|
28 |
("Tools/Function/decompose.ML") |
|
29 |
("Tools/Function/descent.ML") |
|
30 |
("Tools/Function/scnp_solve.ML") |
|
31 |
("Tools/Function/scnp_reconstruct.ML") |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
32 |
begin |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
33 |
|
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
34 |
subsection {* Definitions with default value. *} |
20536
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
35 |
|
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
36 |
definition |
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21364
diff
changeset
|
37 |
THE_default :: "'a \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a" where |
20536
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
38 |
"THE_default d P = (if (\<exists>!x. P x) then (THE x. P x) else d)" |
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
39 |
|
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
40 |
lemma THE_defaultI': "\<exists>!x. P x \<Longrightarrow> P (THE_default d P)" |
22816 | 41 |
by (simp add: theI' THE_default_def) |
20536
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
42 |
|
22816 | 43 |
lemma THE_default1_equality: |
44 |
"\<lbrakk>\<exists>!x. P x; P a\<rbrakk> \<Longrightarrow> THE_default d P = a" |
|
45 |
by (simp add: the1_equality THE_default_def) |
|
20536
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
46 |
|
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
47 |
lemma THE_default_none: |
22816 | 48 |
"\<not>(\<exists>!x. P x) \<Longrightarrow> THE_default d P = d" |
49 |
by (simp add:THE_default_def) |
|
20536
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
50 |
|
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
51 |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
52 |
lemma fundef_ex1_existence: |
22816 | 53 |
assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))" |
54 |
assumes ex1: "\<exists>!y. G x y" |
|
55 |
shows "G x (f x)" |
|
56 |
apply (simp only: f_def) |
|
57 |
apply (rule THE_defaultI') |
|
58 |
apply (rule ex1) |
|
59 |
done |
|
21051
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20654
diff
changeset
|
60 |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
61 |
lemma fundef_ex1_uniqueness: |
22816 | 62 |
assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))" |
63 |
assumes ex1: "\<exists>!y. G x y" |
|
64 |
assumes elm: "G x (h x)" |
|
65 |
shows "h x = f x" |
|
66 |
apply (simp only: f_def) |
|
67 |
apply (rule THE_default1_equality [symmetric]) |
|
68 |
apply (rule ex1) |
|
69 |
apply (rule elm) |
|
70 |
done |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
71 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
72 |
lemma fundef_ex1_iff: |
22816 | 73 |
assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))" |
74 |
assumes ex1: "\<exists>!y. G x y" |
|
75 |
shows "(G x y) = (f x = y)" |
|
20536
f088edff8af8
Function package: Outside their domain functions now return "arbitrary".
krauss
parents:
20523
diff
changeset
|
76 |
apply (auto simp:ex1 f_def THE_default1_equality) |
22816 | 77 |
apply (rule THE_defaultI') |
78 |
apply (rule ex1) |
|
79 |
done |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
80 |
|
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20536
diff
changeset
|
81 |
lemma fundef_default_value: |
22816 | 82 |
assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))" |
83 |
assumes graph: "\<And>x y. G x y \<Longrightarrow> D x" |
|
84 |
assumes "\<not> D x" |
|
85 |
shows "f x = d x" |
|
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20536
diff
changeset
|
86 |
proof - |
21051
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20654
diff
changeset
|
87 |
have "\<not>(\<exists>y. G x y)" |
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20536
diff
changeset
|
88 |
proof |
21512
3786eb1b69d6
Lemma "fundef_default_value" uses predicate instead of set.
krauss
parents:
21404
diff
changeset
|
89 |
assume "\<exists>y. G x y" |
3786eb1b69d6
Lemma "fundef_default_value" uses predicate instead of set.
krauss
parents:
21404
diff
changeset
|
90 |
hence "D x" using graph .. |
3786eb1b69d6
Lemma "fundef_default_value" uses predicate instead of set.
krauss
parents:
21404
diff
changeset
|
91 |
with `\<not> D x` show False .. |
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20536
diff
changeset
|
92 |
qed |
21051
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20654
diff
changeset
|
93 |
hence "\<not>(\<exists>!y. G x y)" by blast |
22816 | 94 |
|
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20536
diff
changeset
|
95 |
thus ?thesis |
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20536
diff
changeset
|
96 |
unfolding f_def |
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20536
diff
changeset
|
97 |
by (rule THE_default_none) |
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20536
diff
changeset
|
98 |
qed |
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20536
diff
changeset
|
99 |
|
23739
c5ead5df7f35
Inserted definition of in_rel again (since member2 was removed).
berghofe
parents:
23494
diff
changeset
|
100 |
definition in_rel_def[simp]: |
c5ead5df7f35
Inserted definition of in_rel again (since member2 was removed).
berghofe
parents:
23494
diff
changeset
|
101 |
"in_rel R x y == (x, y) \<in> R" |
c5ead5df7f35
Inserted definition of in_rel again (since member2 was removed).
berghofe
parents:
23494
diff
changeset
|
102 |
|
c5ead5df7f35
Inserted definition of in_rel again (since member2 was removed).
berghofe
parents:
23494
diff
changeset
|
103 |
lemma wf_in_rel: |
c5ead5df7f35
Inserted definition of in_rel again (since member2 was removed).
berghofe
parents:
23494
diff
changeset
|
104 |
"wf R \<Longrightarrow> wfP (in_rel R)" |
c5ead5df7f35
Inserted definition of in_rel again (since member2 was removed).
berghofe
parents:
23494
diff
changeset
|
105 |
by (simp add: wfP_def) |
c5ead5df7f35
Inserted definition of in_rel again (since member2 was removed).
berghofe
parents:
23494
diff
changeset
|
106 |
|
31775 | 107 |
use "Tools/Function/fundef_lib.ML" |
108 |
use "Tools/Function/fundef_common.ML" |
|
109 |
use "Tools/Function/inductive_wrap.ML" |
|
110 |
use "Tools/Function/context_tree.ML" |
|
111 |
use "Tools/Function/fundef_core.ML" |
|
112 |
use "Tools/Function/sum_tree.ML" |
|
113 |
use "Tools/Function/mutual.ML" |
|
114 |
use "Tools/Function/pattern_split.ML" |
|
115 |
use "Tools/Function/auto_term.ML" |
|
116 |
use "Tools/Function/fundef.ML" |
|
33083 | 117 |
use "Tools/Function/pat_completeness.ML" |
31775 | 118 |
use "Tools/Function/fundef_datatype.ML" |
119 |
use "Tools/Function/induction_scheme.ML" |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
120 |
|
25567
5720345ea689
experimental version of automated induction scheme generator (cf. HOL/ex/Induction_Scheme.thy)
krauss
parents:
25556
diff
changeset
|
121 |
setup {* |
33083 | 122 |
Fundef.setup |
123 |
#> Pat_Completeness.setup |
|
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
124 |
#> FundefDatatype.setup |
25567
5720345ea689
experimental version of automated induction scheme generator (cf. HOL/ex/Induction_Scheme.thy)
krauss
parents:
25556
diff
changeset
|
125 |
#> InductionScheme.setup |
5720345ea689
experimental version of automated induction scheme generator (cf. HOL/ex/Induction_Scheme.thy)
krauss
parents:
25556
diff
changeset
|
126 |
*} |
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19564
diff
changeset
|
127 |
|
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
128 |
subsection {* Measure Functions *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
129 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
130 |
inductive is_measure :: "('a \<Rightarrow> nat) \<Rightarrow> bool" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
131 |
where is_measure_trivial: "is_measure f" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
132 |
|
31775 | 133 |
use "Tools/Function/measure_functions.ML" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
134 |
setup MeasureFunctions.setup |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
135 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
136 |
lemma measure_size[measure_function]: "is_measure size" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
137 |
by (rule is_measure_trivial) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
138 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
139 |
lemma measure_fst[measure_function]: "is_measure f \<Longrightarrow> is_measure (\<lambda>p. f (fst p))" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
140 |
by (rule is_measure_trivial) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
141 |
lemma measure_snd[measure_function]: "is_measure f \<Longrightarrow> is_measure (\<lambda>p. f (snd p))" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
142 |
by (rule is_measure_trivial) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
143 |
|
31775 | 144 |
use "Tools/Function/lexicographic_order.ML" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
145 |
setup LexicographicOrder.setup |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
146 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
147 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
148 |
subsection {* Congruence Rules *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
149 |
|
22838 | 150 |
lemma let_cong [fundef_cong]: |
151 |
"M = N \<Longrightarrow> (\<And>x. x = N \<Longrightarrow> f x = g x) \<Longrightarrow> Let M f = Let N g" |
|
22816 | 152 |
unfolding Let_def by blast |
22622
25693088396b
Moving "FunDef" up in the HOL development graph, since it is independent from "Recdef" and "Datatype" now.
krauss
parents:
22325
diff
changeset
|
153 |
|
22816 | 154 |
lemmas [fundef_cong] = |
22838 | 155 |
if_cong image_cong INT_cong UN_cong |
156 |
bex_cong ball_cong imp_cong |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
157 |
|
22816 | 158 |
lemma split_cong [fundef_cong]: |
22838 | 159 |
"(\<And>x y. (x, y) = q \<Longrightarrow> f x y = g x y) \<Longrightarrow> p = q |
22816 | 160 |
\<Longrightarrow> split f p = split g q" |
161 |
by (auto simp: split_def) |
|
19934 | 162 |
|
22816 | 163 |
lemma comp_cong [fundef_cong]: |
22838 | 164 |
"f (g x) = f' (g' x') \<Longrightarrow> (f o g) x = (f' o g') x'" |
22816 | 165 |
unfolding o_apply . |
19934 | 166 |
|
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
167 |
subsection {* Simp rules for termination proofs *} |
26875
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
168 |
|
26749
397a1aeede7d
* New attribute "termination_simp": Simp rules for termination proofs
krauss
parents:
26748
diff
changeset
|
169 |
lemma termination_basic_simps[termination_simp]: |
397a1aeede7d
* New attribute "termination_simp": Simp rules for termination proofs
krauss
parents:
26748
diff
changeset
|
170 |
"x < (y::nat) \<Longrightarrow> x < y + z" |
397a1aeede7d
* New attribute "termination_simp": Simp rules for termination proofs
krauss
parents:
26748
diff
changeset
|
171 |
"x < z \<Longrightarrow> x < y + z" |
26875
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
172 |
"x \<le> y \<Longrightarrow> x \<le> y + (z::nat)" |
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
173 |
"x \<le> z \<Longrightarrow> x \<le> y + (z::nat)" |
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
174 |
"x < y \<Longrightarrow> x \<le> (y::nat)" |
26749
397a1aeede7d
* New attribute "termination_simp": Simp rules for termination proofs
krauss
parents:
26748
diff
changeset
|
175 |
by arith+ |
397a1aeede7d
* New attribute "termination_simp": Simp rules for termination proofs
krauss
parents:
26748
diff
changeset
|
176 |
|
26875
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
177 |
declare le_imp_less_Suc[termination_simp] |
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
178 |
|
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
179 |
lemma prod_size_simp[termination_simp]: |
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
180 |
"prod_size f g p = f (fst p) + g (snd p) + Suc 0" |
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
181 |
by (induct p) auto |
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
182 |
|
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
183 |
subsection {* Decomposition *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
184 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
185 |
lemma less_by_empty: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
186 |
"A = {} \<Longrightarrow> A \<subseteq> B" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
187 |
and union_comp_emptyL: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
188 |
"\<lbrakk> A O C = {}; B O C = {} \<rbrakk> \<Longrightarrow> (A \<union> B) O C = {}" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
189 |
and union_comp_emptyR: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
190 |
"\<lbrakk> A O B = {}; A O C = {} \<rbrakk> \<Longrightarrow> A O (B \<union> C) = {}" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
191 |
and wf_no_loop: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
192 |
"R O R = {} \<Longrightarrow> wf R" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
193 |
by (auto simp add: wf_comp_self[of R]) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
194 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
195 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
196 |
subsection {* Reduction Pairs *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
197 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
198 |
definition |
32235
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
krauss
parents:
31775
diff
changeset
|
199 |
"reduction_pair P = (wf (fst P) \<and> fst P O snd P \<subseteq> fst P)" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
200 |
|
32235
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
krauss
parents:
31775
diff
changeset
|
201 |
lemma reduction_pairI[intro]: "wf R \<Longrightarrow> R O S \<subseteq> R \<Longrightarrow> reduction_pair (R, S)" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
202 |
unfolding reduction_pair_def by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
203 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
204 |
lemma reduction_pair_lemma: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
205 |
assumes rp: "reduction_pair P" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
206 |
assumes "R \<subseteq> fst P" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
207 |
assumes "S \<subseteq> snd P" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
208 |
assumes "wf S" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
209 |
shows "wf (R \<union> S)" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
210 |
proof - |
32235
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
krauss
parents:
31775
diff
changeset
|
211 |
from rp `S \<subseteq> snd P` have "wf (fst P)" "fst P O S \<subseteq> fst P" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
212 |
unfolding reduction_pair_def by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
213 |
with `wf S` have "wf (fst P \<union> S)" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
214 |
by (auto intro: wf_union_compatible) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
215 |
moreover from `R \<subseteq> fst P` have "R \<union> S \<subseteq> fst P \<union> S" by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
216 |
ultimately show ?thesis by (rule wf_subset) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
217 |
qed |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
218 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
219 |
definition |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
220 |
"rp_inv_image = (\<lambda>(R,S) f. (inv_image R f, inv_image S f))" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
221 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
222 |
lemma rp_inv_image_rp: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
223 |
"reduction_pair P \<Longrightarrow> reduction_pair (rp_inv_image P f)" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
224 |
unfolding reduction_pair_def rp_inv_image_def split_def |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
225 |
by force |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
226 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
227 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
228 |
subsection {* Concrete orders for SCNP termination proofs *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
229 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
230 |
definition "pair_less = less_than <*lex*> less_than" |
30428 | 231 |
definition [code del]: "pair_leq = pair_less^=" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
232 |
definition "max_strict = max_ext pair_less" |
30428 | 233 |
definition [code del]: "max_weak = max_ext pair_leq \<union> {({}, {})}" |
234 |
definition [code del]: "min_strict = min_ext pair_less" |
|
30446 | 235 |
definition [code del]: "min_weak = min_ext pair_leq \<union> {({}, {})}" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
236 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
237 |
lemma wf_pair_less[simp]: "wf pair_less" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
238 |
by (auto simp: pair_less_def) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
239 |
|
29127 | 240 |
text {* Introduction rules for @{text pair_less}/@{text pair_leq} *} |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
241 |
lemma pair_leqI1: "a < b \<Longrightarrow> ((a, s), (b, t)) \<in> pair_leq" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
242 |
and pair_leqI2: "a \<le> b \<Longrightarrow> s \<le> t \<Longrightarrow> ((a, s), (b, t)) \<in> pair_leq" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
243 |
and pair_lessI1: "a < b \<Longrightarrow> ((a, s), (b, t)) \<in> pair_less" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
244 |
and pair_lessI2: "a \<le> b \<Longrightarrow> s < t \<Longrightarrow> ((a, s), (b, t)) \<in> pair_less" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
245 |
unfolding pair_leq_def pair_less_def by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
246 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
247 |
text {* Introduction rules for max *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
248 |
lemma smax_emptyI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
249 |
"finite Y \<Longrightarrow> Y \<noteq> {} \<Longrightarrow> ({}, Y) \<in> max_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
250 |
and smax_insertI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
251 |
"\<lbrakk>y \<in> Y; (x, y) \<in> pair_less; (X, Y) \<in> max_strict\<rbrakk> \<Longrightarrow> (insert x X, Y) \<in> max_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
252 |
and wmax_emptyI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
253 |
"finite X \<Longrightarrow> ({}, X) \<in> max_weak" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
254 |
and wmax_insertI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
255 |
"\<lbrakk>y \<in> YS; (x, y) \<in> pair_leq; (XS, YS) \<in> max_weak\<rbrakk> \<Longrightarrow> (insert x XS, YS) \<in> max_weak" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
256 |
unfolding max_strict_def max_weak_def by (auto elim!: max_ext.cases) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
257 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
258 |
text {* Introduction rules for min *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
259 |
lemma smin_emptyI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
260 |
"X \<noteq> {} \<Longrightarrow> (X, {}) \<in> min_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
261 |
and smin_insertI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
262 |
"\<lbrakk>x \<in> XS; (x, y) \<in> pair_less; (XS, YS) \<in> min_strict\<rbrakk> \<Longrightarrow> (XS, insert y YS) \<in> min_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
263 |
and wmin_emptyI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
264 |
"(X, {}) \<in> min_weak" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
265 |
and wmin_insertI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
266 |
"\<lbrakk>x \<in> XS; (x, y) \<in> pair_leq; (XS, YS) \<in> min_weak\<rbrakk> \<Longrightarrow> (XS, insert y YS) \<in> min_weak" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
267 |
by (auto simp: min_strict_def min_weak_def min_ext_def) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
268 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
269 |
text {* Reduction Pairs *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
270 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
271 |
lemma max_ext_compat: |
32235
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
krauss
parents:
31775
diff
changeset
|
272 |
assumes "R O S \<subseteq> R" |
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
krauss
parents:
31775
diff
changeset
|
273 |
shows "max_ext R O (max_ext S \<union> {({},{})}) \<subseteq> max_ext R" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
274 |
using assms |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
275 |
apply auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
276 |
apply (elim max_ext.cases) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
277 |
apply rule |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
278 |
apply auto[3] |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
279 |
apply (drule_tac x=xa in meta_spec) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
280 |
apply simp |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
281 |
apply (erule bexE) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
282 |
apply (drule_tac x=xb in meta_spec) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
283 |
by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
284 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
285 |
lemma max_rpair_set: "reduction_pair (max_strict, max_weak)" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
286 |
unfolding max_strict_def max_weak_def |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
287 |
apply (intro reduction_pairI max_ext_wf) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
288 |
apply simp |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
289 |
apply (rule max_ext_compat) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
290 |
by (auto simp: pair_less_def pair_leq_def) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
291 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
292 |
lemma min_ext_compat: |
32235
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
krauss
parents:
31775
diff
changeset
|
293 |
assumes "R O S \<subseteq> R" |
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
krauss
parents:
31775
diff
changeset
|
294 |
shows "min_ext R O (min_ext S \<union> {({},{})}) \<subseteq> min_ext R" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
295 |
using assms |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
296 |
apply (auto simp: min_ext_def) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
297 |
apply (drule_tac x=ya in bspec, assumption) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
298 |
apply (erule bexE) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
299 |
apply (drule_tac x=xc in bspec) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
300 |
apply assumption |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
301 |
by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
302 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
303 |
lemma min_rpair_set: "reduction_pair (min_strict, min_weak)" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
304 |
unfolding min_strict_def min_weak_def |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
305 |
apply (intro reduction_pairI min_ext_wf) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
306 |
apply simp |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
307 |
apply (rule min_ext_compat) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
308 |
by (auto simp: pair_less_def pair_leq_def) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
309 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
310 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
311 |
subsection {* Tool setup *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
312 |
|
31775 | 313 |
use "Tools/Function/termination.ML" |
314 |
use "Tools/Function/decompose.ML" |
|
315 |
use "Tools/Function/descent.ML" |
|
316 |
use "Tools/Function/scnp_solve.ML" |
|
317 |
use "Tools/Function/scnp_reconstruct.ML" |
|
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
318 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
319 |
setup {* ScnpReconstruct.setup *} |
30480 | 320 |
|
321 |
ML_val -- "setup inactive" |
|
322 |
{* |
|
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
323 |
Context.theory_map (FundefCommon.set_termination_prover (ScnpReconstruct.decomp_scnp |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
324 |
[ScnpSolve.MAX, ScnpSolve.MIN, ScnpSolve.MS])) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
27271
diff
changeset
|
325 |
*} |
26875
e18574413bc4
Measure functions can now be declared via special rules, allowing for a
krauss
parents:
26749
diff
changeset
|
326 |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
327 |
end |