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