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