src/HOL/Wellfounded.thy
author paulson <lp15@cam.ac.uk>
Mon, 17 Aug 2020 15:42:38 +0100
changeset 72164 b7c54ff7f2dd
parent 71935 82b00b8f1871
child 72168 721a05da8fe7
permissions -rw-r--r--
S Holub's proposed generalisation of the lexicographic product of two orderings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32704
diff changeset
     1
(*  Title:      HOL/Wellfounded.thy
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32704
diff changeset
     2
    Author:     Tobias Nipkow
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32704
diff changeset
     3
    Author:     Lawrence C Paulson
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32704
diff changeset
     4
    Author:     Konrad Slind
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32704
diff changeset
     5
    Author:     Alexander Krauss
55027
a74ea6d75571 folded 'Wellfounded_More_FP' into 'Wellfounded'
blanchet
parents: 54295
diff changeset
     6
    Author:     Andrei Popescu, TU Muenchen
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
     7
*)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
     8
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
     9
section \<open>Well-founded Recursion\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    10
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    11
theory Wellfounded
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
    12
  imports Transitive_Closure
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    13
begin
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    14
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
    15
subsection \<open>Basic Definitions\<close>
26976
cf147f69b3df rearranged subsections
krauss
parents: 26803
diff changeset
    16
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    17
definition wf :: "('a \<times> 'a) set \<Rightarrow> bool"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    18
  where "wf r \<longleftrightarrow> (\<forall>P. (\<forall>x. (\<forall>y. (y, x) \<in> r \<longrightarrow> P y) \<longrightarrow> P x) \<longrightarrow> (\<forall>x. P x))"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    19
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    20
definition wfP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    21
  where "wfP r \<longleftrightarrow> wf {(x, y). r x y}"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    22
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    23
lemma wfP_wf_eq [pred_set_conv]: "wfP (\<lambda>x y. (x, y) \<in> r) = wf r"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    24
  by (simp add: wfP_def)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    25
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    26
lemma wfUNIVI: "(\<And>P x. (\<forall>x. (\<forall>y. (y, x) \<in> r \<longrightarrow> P y) \<longrightarrow> P x) \<Longrightarrow> P x) \<Longrightarrow> wf r"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    27
  unfolding wf_def by blast
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    28
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    29
lemmas wfPUNIVI = wfUNIVI [to_pred]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    30
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    31
text \<open>Restriction to domain \<open>A\<close> and range \<open>B\<close>.
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    32
  If \<open>r\<close> is well-founded over their intersection, then \<open>wf r\<close>.\<close>
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    33
lemma wfI:
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    34
  assumes "r \<subseteq> A \<times> B"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    35
    and "\<And>x P. \<lbrakk>\<forall>x. (\<forall>y. (y, x) \<in> r \<longrightarrow> P y) \<longrightarrow> P x;  x \<in> A; x \<in> B\<rbrakk> \<Longrightarrow> P x"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    36
  shows "wf r"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    37
  using assms unfolding wf_def by blast
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    38
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    39
lemma wf_induct:
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    40
  assumes "wf r"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    41
    and "\<And>x. \<forall>y. (y, x) \<in> r \<longrightarrow> P y \<Longrightarrow> P x"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    42
  shows "P a"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    43
  using assms unfolding wf_def by blast
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    44
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    45
lemmas wfP_induct = wf_induct [to_pred]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    46
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    47
lemmas wf_induct_rule = wf_induct [rule_format, consumes 1, case_names less, induct set: wf]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    48
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    49
lemmas wfP_induct_rule = wf_induct_rule [to_pred, induct set: wfP]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    50
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    51
lemma wf_not_sym: "wf r \<Longrightarrow> (a, x) \<in> r \<Longrightarrow> (x, a) \<notin> r"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    52
  by (induct a arbitrary: x set: wf) blast
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    53
33215
6fd85372981e replaced (outdated) comments by explicit statements
krauss
parents: 32960
diff changeset
    54
lemma wf_asym:
6fd85372981e replaced (outdated) comments by explicit statements
krauss
parents: 32960
diff changeset
    55
  assumes "wf r" "(a, x) \<in> r"
6fd85372981e replaced (outdated) comments by explicit statements
krauss
parents: 32960
diff changeset
    56
  obtains "(x, a) \<notin> r"
6fd85372981e replaced (outdated) comments by explicit statements
krauss
parents: 32960
diff changeset
    57
  by (drule wf_not_sym[OF assms])
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    58
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    59
lemma wf_not_refl [simp]: "wf r \<Longrightarrow> (a, a) \<notin> r"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    60
  by (blast elim: wf_asym)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    61
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
    62
lemma wf_irrefl:
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
    63
  assumes "wf r"
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
    64
  obtains "(a, a) \<notin> r"
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    65
  by (drule wf_not_refl[OF assms])
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
    66
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 26976
diff changeset
    67
lemma wf_wellorderI:
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 26976
diff changeset
    68
  assumes wf: "wf {(x::'a::ord, y). x < y}"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
    69
    and lin: "OFCLASS('a::ord, linorder_class)"
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 26976
diff changeset
    70
  shows "OFCLASS('a::ord, wellorder_class)"
71410
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
    71
  apply (rule wellorder_class.intro [OF lin])
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
    72
  apply (simp add: wellorder_class.intro class.wellorder_axioms.intro wf_induct_rule [OF wf])
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    73
  done
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 26976
diff changeset
    74
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    75
lemma (in wellorder) wf: "wf {(x, y). x < y}"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    76
  unfolding wf_def by (blast intro: less_induct)
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 26976
diff changeset
    77
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 26976
diff changeset
    78
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
    79
subsection \<open>Basic Results\<close>
26976
cf147f69b3df rearranged subsections
krauss
parents: 26803
diff changeset
    80
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
    81
text \<open>Point-free characterization of well-foundedness\<close>
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    82
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    83
lemma wfE_pf:
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    84
  assumes wf: "wf R"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
    85
    and a: "A \<subseteq> R `` A"
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    86
  shows "A = {}"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    87
proof -
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    88
  from wf have "x \<notin> A" for x
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    89
  proof induct
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    90
    fix x assume "\<And>y. (y, x) \<in> R \<Longrightarrow> y \<notin> A"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    91
    then have "x \<notin> R `` A" by blast
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    92
    with a show "x \<notin> A" by blast
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    93
  qed
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    94
  then show ?thesis by auto
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    95
qed
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    96
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    97
lemma wfI_pf:
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    98
  assumes a: "\<And>A. A \<subseteq> R `` A \<Longrightarrow> A = {}"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
    99
  shows "wf R"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   100
proof (rule wfUNIVI)
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   101
  fix P :: "'a \<Rightarrow> bool" and x
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   102
  let ?A = "{x. \<not> P x}"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   103
  assume "\<forall>x. (\<forall>y. (y, x) \<in> R \<longrightarrow> P y) \<longrightarrow> P x"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   104
  then have "?A \<subseteq> R `` ?A" by blast
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   105
  with a show "P x" by blast
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   106
qed
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   107
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   109
subsubsection \<open>Minimal-element characterization of well-foundedness\<close>
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   110
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   111
lemma wfE_min:
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   112
  assumes wf: "wf R" and Q: "x \<in> Q"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   113
  obtains z where "z \<in> Q" "\<And>y. (y, z) \<in> R \<Longrightarrow> y \<notin> Q"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   114
  using Q wfE_pf[OF wf, of Q] by blast
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   115
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 63088
diff changeset
   116
lemma wfE_min':
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 63088
diff changeset
   117
  "wf R \<Longrightarrow> Q \<noteq> {} \<Longrightarrow> (\<And>z. z \<in> Q \<Longrightarrow> (\<And>y. (y, z) \<in> R \<Longrightarrow> y \<notin> Q) \<Longrightarrow> thesis) \<Longrightarrow> thesis"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 63088
diff changeset
   118
  using wfE_min[of R _ Q] by blast
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 63088
diff changeset
   119
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   120
lemma wfI_min:
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   121
  assumes a: "\<And>x Q. x \<in> Q \<Longrightarrow> \<exists>z\<in>Q. \<forall>y. (y, z) \<in> R \<longrightarrow> y \<notin> Q"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   122
  shows "wf R"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   123
proof (rule wfI_pf)
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   124
  fix A
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   125
  assume b: "A \<subseteq> R `` A"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   126
  have False if "x \<in> A" for x
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   127
    using a[OF that] b by blast
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   128
  then show "A = {}" by blast
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   129
qed
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   130
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   131
lemma wf_eq_minimal: "wf r \<longleftrightarrow> (\<forall>Q x. x \<in> Q \<longrightarrow> (\<exists>z\<in>Q. \<forall>y. (y, z) \<in> r \<longrightarrow> y \<notin> Q))"
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   132
  apply (rule iffI)
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   133
   apply (blast intro:  elim!: wfE_min)
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   134
  by (rule wfI_min) auto
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   135
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   136
lemmas wfP_eq_minimal = wf_eq_minimal [to_pred]
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   137
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   138
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   139
subsubsection \<open>Well-foundedness of transitive closure\<close>
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   140
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   141
lemma wf_trancl:
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   142
  assumes "wf r"
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   143
  shows "wf (r\<^sup>+)"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   144
proof -
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   145
  have "P x" if induct_step: "\<And>x. (\<And>y. (y, x) \<in> r\<^sup>+ \<Longrightarrow> P y) \<Longrightarrow> P x" for P x
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   146
  proof (rule induct_step)
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   147
    show "P y" if "(y, x) \<in> r\<^sup>+" for y
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   148
      using \<open>wf r\<close> and that
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   149
    proof (induct x arbitrary: y)
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   150
      case (less x)
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   151
      note hyp = \<open>\<And>x' y'. (x', x) \<in> r \<Longrightarrow> (y', x') \<in> r\<^sup>+ \<Longrightarrow> P y'\<close>
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   152
      from \<open>(y, x) \<in> r\<^sup>+\<close> show "P y"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   153
      proof cases
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   154
        case base
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   155
        show "P y"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   156
        proof (rule induct_step)
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   157
          fix y'
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   158
          assume "(y', y) \<in> r\<^sup>+"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   159
          with \<open>(y, x) \<in> r\<close> show "P y'"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   160
            by (rule hyp [of y y'])
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32704
diff changeset
   161
        qed
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   162
      next
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   163
        case step
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   164
        then obtain x' where "(x', x) \<in> r" and "(y, x') \<in> r\<^sup>+"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   165
          by simp
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   166
        then show "P y" by (rule hyp [of x' y])
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   167
      qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   168
    qed
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   169
  qed
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   170
  then show ?thesis unfolding wf_def by blast
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   171
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   172
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   173
lemmas wfP_trancl = wf_trancl [to_pred]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   174
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   175
lemma wf_converse_trancl: "wf (r\<inverse>) \<Longrightarrow> wf ((r\<^sup>+)\<inverse>)"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   176
  apply (subst trancl_converse [symmetric])
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   177
  apply (erule wf_trancl)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   178
  done
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   179
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   180
text \<open>Well-foundedness of subsets\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   181
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   182
lemma wf_subset: "wf r \<Longrightarrow> p \<subseteq> r \<Longrightarrow> wf p"
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   183
  by (simp add: wf_eq_minimal) fast
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   184
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   185
lemmas wfP_subset = wf_subset [to_pred]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   186
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   187
text \<open>Well-foundedness of the empty relation\<close>
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   188
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   189
lemma wf_empty [iff]: "wf {}"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   190
  by (simp add: wf_def)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   191
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   192
lemma wfP_empty [iff]: "wfP (\<lambda>x y. False)"
32205
49db434c157f explicit is better than implicit
haftmann
parents: 31775
diff changeset
   193
proof -
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   194
  have "wfP bot"
66952
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   195
    by (fact wf_empty[to_pred bot_empty_eq2])
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   196
  then show ?thesis
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   197
    by (simp add: bot_fun_def)
32205
49db434c157f explicit is better than implicit
haftmann
parents: 31775
diff changeset
   198
qed
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   199
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   200
lemma wf_Int1: "wf r \<Longrightarrow> wf (r \<inter> r')"
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   201
  by (erule wf_subset) (rule Int_lower1)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   202
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   203
lemma wf_Int2: "wf r \<Longrightarrow> wf (r' \<inter> r)"
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   204
  by (erule wf_subset) (rule Int_lower2)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   205
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   206
text \<open>Exponentiation.\<close>
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   207
lemma wf_exp:
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   208
  assumes "wf (R ^^ n)"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   209
  shows "wf R"
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   210
proof (rule wfI_pf)
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   211
  fix A assume "A \<subseteq> R `` A"
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   212
  then have "A \<subseteq> (R ^^ n) `` A"
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   213
    by (induct n) force+
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   214
  with \<open>wf (R ^^ n)\<close> show "A = {}"
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   215
    by (rule wfE_pf)
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   216
qed
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   217
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   218
text \<open>Well-foundedness of \<open>insert\<close>.\<close>
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   219
lemma wf_insert [iff]: "wf (insert (y,x) r) \<longleftrightarrow> wf r \<and> (x,y) \<notin> r\<^sup>*" (is "?lhs = ?rhs")
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   220
proof
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   221
  assume ?lhs then show ?rhs
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   222
    by (blast elim: wf_trancl [THEN wf_irrefl]
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   223
        intro: rtrancl_into_trancl1 wf_subset rtrancl_mono [THEN subsetD])
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   224
next
71410
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   225
  assume R: ?rhs
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   226
  then have R': "Q \<noteq> {} \<Longrightarrow> (\<exists>z\<in>Q. \<forall>y. (y, z) \<in> r \<longrightarrow> y \<notin> Q)" for Q
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   227
    by (auto simp: wf_eq_minimal)
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   228
  show ?lhs
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   229
    unfolding wf_eq_minimal
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   230
  proof clarify
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   231
    fix Q :: "'a set" and q
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   232
    assume "q \<in> Q"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   233
    then obtain a where "a \<in> Q" and a: "\<And>y. (y, a) \<in> r \<Longrightarrow> y \<notin> Q"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   234
      using R by (auto simp: wf_eq_minimal)
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   235
    show "\<exists>z\<in>Q. \<forall>y'. (y', z) \<in> insert (y, x) r \<longrightarrow> y' \<notin> Q"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   236
    proof (cases "a=x")
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   237
      case True
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   238
      show ?thesis
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   239
      proof (cases "y \<in> Q")
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   240
        case True
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   241
        then obtain z where "z \<in> Q" "(z, y) \<in> r\<^sup>*"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   242
                            "\<And>z'. (z', z) \<in> r \<longrightarrow> z' \<in> Q \<longrightarrow> (z', y) \<notin> r\<^sup>*"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   243
          using R' [of "{z \<in> Q. (z,y) \<in> r\<^sup>*}"] by auto
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   244
        with R show ?thesis
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   245
          by (rule_tac x="z" in bexI) (blast intro: rtrancl_trans)
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   246
      next
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   247
        case False
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   248
        then show ?thesis
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   249
          using a \<open>a \<in> Q\<close> by blast
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   250
      qed
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   251
    next
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   252
      case False
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   253
      with a \<open>a \<in> Q\<close> show ?thesis
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   254
        by blast
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   255
    qed
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   256
  qed
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   257
qed
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   258
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   259
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   260
subsubsection \<open>Well-foundedness of image\<close>
33216
7c61bc5d7310 point-free characterization of well-foundedness
krauss
parents: 33215
diff changeset
   261
68259
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   262
lemma wf_map_prod_image_Dom_Ran:
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   263
  fixes r:: "('a \<times> 'a) set"
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   264
    and f:: "'a \<Rightarrow> 'b"
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   265
  assumes wf_r: "wf r"
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   266
    and inj: "\<And> a a'. a \<in> Domain r \<Longrightarrow> a' \<in> Range r \<Longrightarrow> f a = f a' \<Longrightarrow> a = a'"
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   267
  shows "wf (map_prod f f ` r)"
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   268
proof (unfold wf_eq_minimal, clarify)
68262
nipkow
parents: 68259
diff changeset
   269
  fix B :: "'b set" and b::"'b"
nipkow
parents: 68259
diff changeset
   270
  assume "b \<in> B"
nipkow
parents: 68259
diff changeset
   271
  define A where "A = f -` B \<inter> Domain r"
nipkow
parents: 68259
diff changeset
   272
  show "\<exists>z\<in>B. \<forall>y. (y, z) \<in> map_prod f f ` r \<longrightarrow> y \<notin> B"
nipkow
parents: 68259
diff changeset
   273
  proof (cases "A = {}")
68259
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   274
    case False
68262
nipkow
parents: 68259
diff changeset
   275
    then obtain a0 where "a0 \<in> A" and "\<forall>a. (a, a0) \<in> r \<longrightarrow> a \<notin> A"
68259
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   276
      using wfE_min[OF wf_r] by auto
71410
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   277
    thus ?thesis
68262
nipkow
parents: 68259
diff changeset
   278
      using inj unfolding A_def
nipkow
parents: 68259
diff changeset
   279
      by (intro bexI[of _ "f a0"]) auto
71410
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   280
  qed (insert \<open>b \<in> B\<close>, unfold A_def, auto)
68259
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   281
qed
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   282
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   283
lemma wf_map_prod_image: "wf r \<Longrightarrow> inj f \<Longrightarrow> wf (map_prod f f ` r)"
68259
80df7c90e315 By Andrei Popescu based on an initial version by Kasper F. Brandt
nipkow
parents: 67399
diff changeset
   284
by(rule wf_map_prod_image_Dom_Ran) (auto dest: inj_onD)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   285
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   286
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   287
subsection \<open>Well-Foundedness Results for Unions\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   288
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   289
lemma wf_union_compatible:
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   290
  assumes "wf R" "wf S"
32235
8f9b8d14fc9f "more standard" argument order of relation composition (op O)
krauss
parents: 32205
diff changeset
   291
  assumes "R O S \<subseteq> R"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   292
  shows "wf (R \<union> S)"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   293
proof (rule wfI_min)
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   294
  fix x :: 'a and Q
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   295
  let ?Q' = "{x \<in> Q. \<forall>y. (y, x) \<in> R \<longrightarrow> y \<notin> Q}"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   296
  assume "x \<in> Q"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   297
  obtain a where "a \<in> ?Q'"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   298
    by (rule wfE_min [OF \<open>wf R\<close> \<open>x \<in> Q\<close>]) blast
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   299
  with \<open>wf S\<close> obtain z where "z \<in> ?Q'" and zmin: "\<And>y. (y, z) \<in> S \<Longrightarrow> y \<notin> ?Q'"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   300
    by (erule wfE_min)
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   301
  have "y \<notin> Q" if "(y, z) \<in> S" for y
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   302
  proof
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   303
    from that have "y \<notin> ?Q'" by (rule zmin)
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   304
    assume "y \<in> Q"
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   305
    with \<open>y \<notin> ?Q'\<close> obtain w where "(w, y) \<in> R" and "w \<in> Q" by auto
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   306
    from \<open>(w, y) \<in> R\<close> \<open>(y, z) \<in> S\<close> have "(w, z) \<in> R O S" by (rule relcompI)
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   307
    with \<open>R O S \<subseteq> R\<close> have "(w, z) \<in> R" ..
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   308
    with \<open>z \<in> ?Q'\<close> have "w \<notin> Q" by blast
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   309
    with \<open>w \<in> Q\<close> show False by contradiction
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   310
  qed
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   311
  with \<open>z \<in> ?Q'\<close> show "\<exists>z\<in>Q. \<forall>y. (y, z) \<in> R \<union> S \<longrightarrow> y \<notin> Q" by blast
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   312
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   313
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   314
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   315
text \<open>Well-foundedness of indexed union with disjoint domains and ranges.\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   316
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   317
lemma wf_UN:
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   318
  assumes r: "\<And>i. i \<in> I \<Longrightarrow> wf (r i)"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   319
    and disj: "\<And>i j. \<lbrakk>i \<in> I; j \<in> I; r i \<noteq> r j\<rbrakk> \<Longrightarrow> Domain (r i) \<inter> Range (r j) = {}"
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   320
  shows "wf (\<Union>i\<in>I. r i)"
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   321
  unfolding wf_eq_minimal
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   322
proof clarify
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   323
  fix A and a :: "'b"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   324
  assume "a \<in> A"
69275
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 68646
diff changeset
   325
  show "\<exists>z\<in>A. \<forall>y. (y, z) \<in> \<Union>(r ` I) \<longrightarrow> y \<notin> A"
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   326
  proof (cases "\<exists>i\<in>I. \<exists>a\<in>A. \<exists>b\<in>A. (b, a) \<in> r i")
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   327
    case True
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   328
    then obtain i b c where ibc: "i \<in> I" "b \<in> A" "c \<in> A" "(c,b) \<in> r i"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   329
      by blast
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   330
    have ri: "\<And>Q. Q \<noteq> {} \<Longrightarrow> \<exists>z\<in>Q. \<forall>y. (y, z) \<in> r i \<longrightarrow> y \<notin> Q"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   331
      using r [OF \<open>i \<in> I\<close>] unfolding wf_eq_minimal by auto
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   332
    show ?thesis
71410
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   333
      using ri [of "{a. a \<in> A \<and> (\<exists>b\<in>A. (b, a) \<in> r i) }"] ibc disj
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   334
      by blast
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   335
  next
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   336
    case False
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   337
    with \<open>a \<in> A\<close> show ?thesis
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   338
      by blast
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   339
  qed
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   340
qed
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   341
32263
8bc0fd4a23a0 explicit is better than implicit
haftmann
parents: 32244
diff changeset
   342
lemma wfP_SUP:
64632
9df24b8b6c0a dropped aliasses
haftmann
parents: 63982
diff changeset
   343
  "\<forall>i. wfP (r i) \<Longrightarrow> \<forall>i j. r i \<noteq> r j \<longrightarrow> inf (Domainp (r i)) (Rangep (r j)) = bot \<Longrightarrow>
69275
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 68646
diff changeset
   344
    wfP (\<Squnion>(range r))"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   345
  by (rule wf_UN[to_pred]) simp_all
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   346
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   347
lemma wf_Union:
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   348
  assumes "\<forall>r\<in>R. wf r"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   349
    and "\<forall>r\<in>R. \<forall>s\<in>R. r \<noteq> s \<longrightarrow> Domain r \<inter> Range s = {}"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   350
  shows "wf (\<Union>R)"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   351
  using assms wf_UN[of R "\<lambda>i. i"] by simp
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   352
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   353
text \<open>
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   354
  Intuition: We find an \<open>R \<union> S\<close>-min element of a nonempty subset \<open>A\<close> by case distinction.
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   355
  \<^enum> There is a step \<open>a \<midarrow>R\<rightarrow> b\<close> with \<open>a, b \<in> A\<close>.
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   356
    Pick an \<open>R\<close>-min element \<open>z\<close> of the (nonempty) set \<open>{a\<in>A | \<exists>b\<in>A. a \<midarrow>R\<rightarrow> b}\<close>.
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   357
    By definition, there is \<open>z' \<in> A\<close> s.t. \<open>z \<midarrow>R\<rightarrow> z'\<close>. Because \<open>z\<close> is \<open>R\<close>-min in the
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   358
    subset, \<open>z'\<close> must be \<open>R\<close>-min in \<open>A\<close>. Because \<open>z'\<close> has an \<open>R\<close>-predecessor, it cannot
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   359
    have an \<open>S\<close>-successor and is thus \<open>S\<close>-min in \<open>A\<close> as well.
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   360
  \<^enum> There is no such step.
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   361
    Pick an \<open>S\<close>-min element of \<open>A\<close>. In this case it must be an \<open>R\<close>-min
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   362
    element of \<open>A\<close> as well.
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   363
\<close>
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   364
lemma wf_Un: "wf r \<Longrightarrow> wf s \<Longrightarrow> Domain r \<inter> Range s = {} \<Longrightarrow> wf (r \<union> s)"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   365
  using wf_union_compatible[of s r]
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   366
  by (auto simp: Un_ac)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   367
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   368
lemma wf_union_merge: "wf (R \<union> S) = wf (R O R \<union> S O R \<union> S)"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   369
  (is "wf ?A = wf ?B")
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   370
proof
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   371
  assume "wf ?A"
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   372
  with wf_trancl have wfT: "wf (?A\<^sup>+)" .
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   373
  moreover have "?B \<subseteq> ?A\<^sup>+"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   374
    by (subst trancl_unfold, subst trancl_unfold) blast
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   375
  ultimately show "wf ?B" by (rule wf_subset)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   376
next
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   377
  assume "wf ?B"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   378
  show "wf ?A"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   379
  proof (rule wfI_min)
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   380
    fix Q :: "'a set" and x
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   381
    assume "x \<in> Q"
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   382
    with \<open>wf ?B\<close> obtain z where "z \<in> Q" and "\<And>y. (y, z) \<in> ?B \<Longrightarrow> y \<notin> Q"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   383
      by (erule wfE_min)
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   384
    then have 1: "\<And>y. (y, z) \<in> R O R \<Longrightarrow> y \<notin> Q"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   385
      and 2: "\<And>y. (y, z) \<in> S O R \<Longrightarrow> y \<notin> Q"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   386
      and 3: "\<And>y. (y, z) \<in> S \<Longrightarrow> y \<notin> Q"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   387
      by auto
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   388
    show "\<exists>z\<in>Q. \<forall>y. (y, z) \<in> ?A \<longrightarrow> y \<notin> Q"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   389
    proof (cases "\<forall>y. (y, z) \<in> R \<longrightarrow> y \<notin> Q")
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   390
      case True
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   391
      with \<open>z \<in> Q\<close> 3 show ?thesis by blast
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   392
    next
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   393
      case False
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   394
      then obtain z' where "z'\<in>Q" "(z', z) \<in> R" by blast
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   395
      have "\<forall>y. (y, z') \<in> ?A \<longrightarrow> y \<notin> Q"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   396
      proof (intro allI impI)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   397
        fix y assume "(y, z') \<in> ?A"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   398
        then show "y \<notin> Q"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   399
        proof
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   400
          assume "(y, z') \<in> R"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   401
          then have "(y, z) \<in> R O R" using \<open>(z', z) \<in> R\<close> ..
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   402
          with 1 show "y \<notin> Q" .
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   403
        next
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   404
          assume "(y, z') \<in> S"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   405
          then have "(y, z) \<in> S O R" using  \<open>(z', z) \<in> R\<close> ..
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   406
          with 2 show "y \<notin> Q" .
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   407
        qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   408
      qed
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   409
      with \<open>z' \<in> Q\<close> show ?thesis ..
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   410
    qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   411
  qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   412
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   413
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   414
lemma wf_comp_self: "wf R \<longleftrightarrow> wf (R O R)"  \<comment> \<open>special case\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   415
  by (rule wf_union_merge [where S = "{}", simplified])
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   416
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   417
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   418
subsection \<open>Well-Foundedness of Composition\<close>
60148
f0fc2378a479 new lemma
nipkow
parents: 59807
diff changeset
   419
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   420
text \<open>Bachmair and Dershowitz 1986, Lemma 2. [Provided by Tjark Weber]\<close>
60148
f0fc2378a479 new lemma
nipkow
parents: 59807
diff changeset
   421
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   422
lemma qc_wf_relto_iff:
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61424
diff changeset
   423
  assumes "R O S \<subseteq> (R \<union> S)\<^sup>* O R" \<comment> \<open>R quasi-commutes over S\<close>
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   424
  shows "wf (S\<^sup>* O R O S\<^sup>*) \<longleftrightarrow> wf R"
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   425
    (is "wf ?S \<longleftrightarrow> _")
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   426
proof
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   427
  show "wf R" if "wf ?S"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   428
  proof -
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   429
    have "R \<subseteq> ?S" by auto
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   430
    with wf_subset [of ?S] that show "wf R"
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   431
      by auto
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   432
  qed
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   433
next
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   434
  show "wf ?S" if "wf R"
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   435
  proof (rule wfI_pf)
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   436
    fix A
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   437
    assume A: "A \<subseteq> ?S `` A"
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   438
    let ?X = "(R \<union> S)\<^sup>* `` A"
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   439
    have *: "R O (R \<union> S)\<^sup>* \<subseteq> (R \<union> S)\<^sup>* O R"
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   440
    proof -
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   441
      have "(x, z) \<in> (R \<union> S)\<^sup>* O R" if "(y, z) \<in> (R \<union> S)\<^sup>*" and "(x, y) \<in> R" for x y z
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   442
        using that
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   443
      proof (induct y z)
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   444
        case rtrancl_refl
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   445
        then show ?case by auto
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   446
      next
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   447
        case (rtrancl_into_rtrancl a b c)
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   448
        then have "(x, c) \<in> ((R \<union> S)\<^sup>* O (R \<union> S)\<^sup>*) O R"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   449
          using assms by blast
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   450
        then show ?case by simp
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   451
      qed
63109
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   452
      then show ?thesis by auto
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   453
    qed
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   454
    then have "R O S\<^sup>* \<subseteq> (R \<union> S)\<^sup>* O R"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   455
      using rtrancl_Un_subset by blast
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   456
    then have "?S \<subseteq> (R \<union> S)\<^sup>* O (R \<union> S)\<^sup>* O R"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   457
      by (simp add: relcomp_mono rtrancl_mono)
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   458
    also have "\<dots> = (R \<union> S)\<^sup>* O R"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   459
      by (simp add: O_assoc[symmetric])
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   460
    finally have "?S O (R \<union> S)\<^sup>* \<subseteq> (R \<union> S)\<^sup>* O R O (R \<union> S)\<^sup>*"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   461
      by (simp add: O_assoc[symmetric] relcomp_mono)
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   462
    also have "\<dots> \<subseteq> (R \<union> S)\<^sup>* O (R \<union> S)\<^sup>* O R"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   463
      using * by (simp add: relcomp_mono)
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   464
    finally have "?S O (R \<union> S)\<^sup>* \<subseteq> (R \<union> S)\<^sup>* O R"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   465
      by (simp add: O_assoc[symmetric])
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   466
    then have "(?S O (R \<union> S)\<^sup>*) `` A \<subseteq> ((R \<union> S)\<^sup>* O R) `` A"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   467
      by (simp add: Image_mono)
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   468
    moreover have "?X \<subseteq> (?S O (R \<union> S)\<^sup>*) `` A"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   469
      using A by (auto simp: relcomp_Image)
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   470
    ultimately have "?X \<subseteq> R `` ?X"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   471
      by (auto simp: relcomp_Image)
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   472
    then have "?X = {}"
87a4283537e4 proper document source;
wenzelm
parents: 63108
diff changeset
   473
      using \<open>wf R\<close> by (simp add: wfE_pf)
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   474
    moreover have "A \<subseteq> ?X" by auto
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   475
    ultimately show "A = {}" by simp
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   476
  qed
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   477
qed
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   478
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   479
corollary wf_relcomp_compatible:
60148
f0fc2378a479 new lemma
nipkow
parents: 59807
diff changeset
   480
  assumes "wf R" and "R O S \<subseteq> S O R"
f0fc2378a479 new lemma
nipkow
parents: 59807
diff changeset
   481
  shows "wf (S O R)"
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   482
proof -
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   483
  have "R O S \<subseteq> (R \<union> S)\<^sup>* O R"
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   484
    using assms by blast
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   485
  then have "wf (S\<^sup>* O R O S\<^sup>*)"
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   486
    by (simp add: assms qc_wf_relto_iff)
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   487
  then show ?thesis
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   488
    by (rule Wellfounded.wf_subset) blast
60148
f0fc2378a479 new lemma
nipkow
parents: 59807
diff changeset
   489
qed
f0fc2378a479 new lemma
nipkow
parents: 59807
diff changeset
   490
f0fc2378a479 new lemma
nipkow
parents: 59807
diff changeset
   491
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   492
subsection \<open>Acyclic relations\<close>
33217
ab979f6e99f4 authentic constants; moved "acyclic" further down
krauss
parents: 33216
diff changeset
   493
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   494
lemma wf_acyclic: "wf r \<Longrightarrow> acyclic r"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   495
  by (simp add: acyclic_def) (blast elim: wf_trancl [THEN wf_irrefl])
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   496
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   497
lemmas wfP_acyclicP = wf_acyclic [to_pred]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   498
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   499
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   500
subsubsection \<open>Wellfoundedness of finite acyclic relations\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   501
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   502
lemma finite_acyclic_wf:
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   503
  assumes "finite r" "acyclic r" shows "wf r"
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   504
  using assms
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   505
proof (induction r rule: finite_induct)
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   506
  case (insert x r)
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   507
  then show ?case
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   508
    by (cases x) simp
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   509
qed simp
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   510
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   511
lemma finite_acyclic_wf_converse: "finite r \<Longrightarrow> acyclic r \<Longrightarrow> wf (r\<inverse>)"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   512
  apply (erule finite_converse [THEN iffD2, THEN finite_acyclic_wf])
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   513
  apply (erule acyclic_converse [THEN iffD2])
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   514
  done
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   515
63088
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   516
text \<open>
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   517
  Observe that the converse of an irreflexive, transitive,
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   518
  and finite relation is again well-founded. Thus, we may
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   519
  employ it for well-founded induction.
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   520
\<close>
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   521
lemma wf_converse:
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   522
  assumes "irrefl r" and "trans r" and "finite r"
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   523
  shows "wf (r\<inverse>)"
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   524
proof -
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   525
  have "acyclic r"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   526
    using \<open>irrefl r\<close> and \<open>trans r\<close>
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   527
    by (simp add: irrefl_def acyclic_irrefl)
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   528
  with \<open>finite r\<close> show ?thesis
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   529
    by (rule finite_acyclic_wf_converse)
63088
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   530
qed
f2177f5d2aed a quasi-recursive characterization of the multiset order (by Christian Sternagel)
haftmann
parents: 61952
diff changeset
   531
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   532
lemma wf_iff_acyclic_if_finite: "finite r \<Longrightarrow> wf r = acyclic r"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   533
  by (blast intro: finite_acyclic_wf wf_acyclic)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   534
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   535
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69275
diff changeset
   536
subsection \<open>\<^typ>\<open>nat\<close> is well-founded\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   537
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66952
diff changeset
   538
lemma less_nat_rel: "(<) = (\<lambda>m n. n = Suc m)\<^sup>+\<^sup>+"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   539
proof (rule ext, rule ext, rule iffI)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   540
  fix n m :: nat
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   541
  show "(\<lambda>m n. n = Suc m)\<^sup>+\<^sup>+ m n" if "m < n"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   542
    using that
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   543
  proof (induct n)
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   544
    case 0
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   545
    then show ?case by auto
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   546
  next
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   547
    case (Suc n)
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   548
    then show ?case
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   549
      by (auto simp add: less_Suc_eq_le le_less intro: tranclp.trancl_into_trancl)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   550
  qed
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   551
  show "m < n" if "(\<lambda>m n. n = Suc m)\<^sup>+\<^sup>+ m n"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   552
    using that by (induct n) (simp_all add: less_Suc_eq_le reflexive le_less)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   553
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   554
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   555
definition pred_nat :: "(nat \<times> nat) set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   556
  where "pred_nat = {(m, n). n = Suc m}"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   557
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   558
definition less_than :: "(nat \<times> nat) set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   559
  where "less_than = pred_nat\<^sup>+"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   560
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   561
lemma less_eq: "(m, n) \<in> pred_nat\<^sup>+ \<longleftrightarrow> m < n"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   562
  unfolding less_nat_rel pred_nat_def trancl_def by simp
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   563
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   564
lemma pred_nat_trancl_eq_le: "(m, n) \<in> pred_nat\<^sup>* \<longleftrightarrow> m \<le> n"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   565
  unfolding less_eq rtrancl_eq_or_trancl by auto
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   566
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   567
lemma wf_pred_nat: "wf pred_nat"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   568
  apply (unfold wf_def pred_nat_def)
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   569
  apply clarify
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   570
  apply (induct_tac x)
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   571
   apply blast+
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   572
  done
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   573
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   574
lemma wf_less_than [iff]: "wf less_than"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   575
  by (simp add: less_than_def wf_pred_nat [THEN wf_trancl])
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   576
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   577
lemma trans_less_than [iff]: "trans less_than"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 33217
diff changeset
   578
  by (simp add: less_than_def)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   579
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   580
lemma less_than_iff [iff]: "((x,y) \<in> less_than) = (x<y)"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   581
  by (simp add: less_than_def less_eq)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   582
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
   583
lemma irrefl_less_than: "irrefl less_than"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
   584
  using irrefl_def by blast
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
   585
71935
82b00b8f1871 fixed the utterly weird definitions of asym / asymp, and added many asym lemmas
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   586
lemma asym_less_than: "asym less_than"
82b00b8f1871 fixed the utterly weird definitions of asym / asymp, and added many asym lemmas
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   587
  by (simp add: asym.simps irrefl_less_than)
82b00b8f1871 fixed the utterly weird definitions of asym / asymp, and added many asym lemmas
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   588
71766
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents: 71544
diff changeset
   589
lemma total_less_than: "total less_than" and total_on_less_than [simp]: "total_on A less_than"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents: 71544
diff changeset
   590
  using total_on_def by force+
71404
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   591
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   592
lemma wf_less: "wf {(x, y::nat). x < y}"
60493
866f41a869e6 New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
paulson <lp15@cam.ac.uk>
parents: 60148
diff changeset
   593
  by (rule Wellfounded.wellorder_class.wf)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   594
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   595
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   596
subsection \<open>Accessible Part\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   597
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   598
text \<open>
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   599
  Inductive definition of the accessible part \<open>acc r\<close> of a
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   600
  relation; see also @{cite "paulin-tlca"}.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   601
\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   602
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   603
inductive_set acc :: "('a \<times> 'a) set \<Rightarrow> 'a set" for r :: "('a \<times> 'a) set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   604
  where accI: "(\<And>y. (y, x) \<in> r \<Longrightarrow> y \<in> acc r) \<Longrightarrow> x \<in> acc r"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   605
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   606
abbreviation termip :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   607
  where "termip r \<equiv> accp (r\<inverse>\<inverse>)"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   608
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   609
abbreviation termi :: "('a \<times> 'a) set \<Rightarrow> 'a set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   610
  where "termi r \<equiv> acc (r\<inverse>)"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   611
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   612
lemmas accpI = accp.accI
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   613
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   614
lemma accp_eq_acc [code]: "accp r = (\<lambda>x. x \<in> Wellfounded.acc {(x, y). r x y})"
54295
45a5523d4a63 qualifed popular user space names
haftmann
parents: 49945
diff changeset
   615
  by (simp add: acc_def)
45a5523d4a63 qualifed popular user space names
haftmann
parents: 49945
diff changeset
   616
45a5523d4a63 qualifed popular user space names
haftmann
parents: 49945
diff changeset
   617
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   618
text \<open>Induction rules\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   619
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   620
theorem accp_induct:
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   621
  assumes major: "accp r a"
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   622
  assumes hyp: "\<And>x. accp r x \<Longrightarrow> \<forall>y. r y x \<longrightarrow> P y \<Longrightarrow> P x"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   623
  shows "P a"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   624
  apply (rule major [THEN accp.induct])
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   625
  apply (rule hyp)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   626
   apply (rule accp.accI)
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   627
   apply auto
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   628
  done
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   629
61337
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 60758
diff changeset
   630
lemmas accp_induct_rule = accp_induct [rule_format, induct set: accp]
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   631
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   632
theorem accp_downward: "accp r b \<Longrightarrow> r a b \<Longrightarrow> accp r a"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   633
  by (cases rule: accp.cases)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   634
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   635
lemma not_accp_down:
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   636
  assumes na: "\<not> accp R x"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   637
  obtains z where "R z x" and "\<not> accp R z"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   638
proof -
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   639
  assume a: "\<And>z. R z x \<Longrightarrow> \<not> accp R z \<Longrightarrow> thesis"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   640
  show thesis
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   641
  proof (cases "\<forall>z. R z x \<longrightarrow> accp R z")
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   642
    case True
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   643
    then have "\<And>z. R z x \<Longrightarrow> accp R z" by auto
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   644
    then have "accp R x" by (rule accp.accI)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   645
    with na show thesis ..
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   646
  next
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   647
    case False then obtain z where "R z x" and "\<not> accp R z"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   648
      by auto
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   649
    with a show thesis .
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   650
  qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   651
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   652
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   653
lemma accp_downwards_aux: "r\<^sup>*\<^sup>* b a \<Longrightarrow> accp r a \<longrightarrow> accp r b"
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   654
  by (erule rtranclp_induct) (blast dest: accp_downward)+
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   655
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   656
theorem accp_downwards: "accp r a \<Longrightarrow> r\<^sup>*\<^sup>* b a \<Longrightarrow> accp r b"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   657
  by (blast dest: accp_downwards_aux)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   658
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   659
theorem accp_wfPI: "\<forall>x. accp r x \<Longrightarrow> wfP r"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   660
  apply (rule wfPUNIVI)
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   661
  apply (rule_tac P = P in accp_induct)
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   662
   apply blast+
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   663
  done
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   664
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   665
theorem accp_wfPD: "wfP r \<Longrightarrow> accp r x"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   666
  apply (erule wfP_induct_rule)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   667
  apply (rule accp.accI)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   668
  apply blast
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   669
  done
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   670
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   671
theorem wfP_accp_iff: "wfP r = (\<forall>x. accp r x)"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   672
  by (blast intro: accp_wfPI dest: accp_wfPD)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   673
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   674
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   675
text \<open>Smaller relations have bigger accessible parts:\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   676
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   677
lemma accp_subset:
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   678
  assumes "R1 \<le> R2"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   679
  shows "accp R2 \<le> accp R1"
26803
0af0f674845d - Explicitely passed pred_subset_eq and pred_equals_eq as an argument to the
berghofe
parents: 26748
diff changeset
   680
proof (rule predicate1I)
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   681
  fix x
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   682
  assume "accp R2 x"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   683
  then show "accp R1 x"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   684
  proof (induct x)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   685
    fix x
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   686
    assume "\<And>y. R2 y x \<Longrightarrow> accp R1 y"
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   687
    with assms show "accp R1 x"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   688
      by (blast intro: accp.accI)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   689
  qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   690
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   691
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   692
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   693
text \<open>This is a generalized induction theorem that works on
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   694
  subsets of the accessible part.\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   695
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   696
lemma accp_subset_induct:
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   697
  assumes subset: "D \<le> accp R"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   698
    and dcl: "\<And>x z. D x \<Longrightarrow> R z x \<Longrightarrow> D z"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   699
    and "D x"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   700
    and istep: "\<And>x. D x \<Longrightarrow> (\<And>z. R z x \<Longrightarrow> P z) \<Longrightarrow> P x"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   701
  shows "P x"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   702
proof -
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   703
  from subset and \<open>D x\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   704
  have "accp R x" ..
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   705
  then show "P x" using \<open>D x\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   706
  proof (induct x)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   707
    fix x
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   708
    assume "D x" and "\<And>y. R y x \<Longrightarrow> D y \<Longrightarrow> P y"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   709
    with dcl and istep show "P x" by blast
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   710
  qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   711
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   712
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   713
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   714
text \<open>Set versions of the above theorems\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   715
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   716
lemmas acc_induct = accp_induct [to_set]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   717
lemmas acc_induct_rule = acc_induct [rule_format, induct set: acc]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   718
lemmas acc_downward = accp_downward [to_set]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   719
lemmas not_acc_down = not_accp_down [to_set]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   720
lemmas acc_downwards_aux = accp_downwards_aux [to_set]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   721
lemmas acc_downwards = accp_downwards [to_set]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   722
lemmas acc_wfI = accp_wfPI [to_set]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   723
lemmas acc_wfD = accp_wfPD [to_set]
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   724
lemmas wf_acc_iff = wfP_accp_iff [to_set]
46177
adac34829e10 pred_subset_eq and SUP_UN_eq2 are now standard pred_set_conv rules
berghofe
parents: 45970
diff changeset
   725
lemmas acc_subset = accp_subset [to_set]
adac34829e10 pred_subset_eq and SUP_UN_eq2 are now standard pred_set_conv rules
berghofe
parents: 45970
diff changeset
   726
lemmas acc_subset_induct = accp_subset_induct [to_set]
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   727
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   728
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   729
subsection \<open>Tools for building wellfounded relations\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   730
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   731
text \<open>Inverse Image\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   732
71544
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   733
lemma wf_inv_image [simp,intro!]: 
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   734
  fixes f :: "'a \<Rightarrow> 'b"
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   735
  assumes "wf r"
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   736
  shows "wf (inv_image r f)"
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   737
proof (clarsimp simp: inv_image_def wf_eq_minimal)
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   738
  fix P and x::'a
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   739
  assume "x \<in> P"
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   740
  then obtain w where w: "w \<in> {w. \<exists>x::'a. x \<in> P \<and> f x = w}"
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   741
    by auto
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   742
  have *: "\<And>Q u. u \<in> Q \<Longrightarrow> \<exists>z\<in>Q. \<forall>y. (y, z) \<in> r \<longrightarrow> y \<notin> Q"
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   743
    using assms by (auto simp add: wf_eq_minimal)
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   744
  show "\<exists>z\<in>P. \<forall>y. (f y, f z) \<in> r \<longrightarrow> y \<notin> P"
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   745
    using * [OF w] by auto
66bc4b668d6e tidied up a few little proofs
paulson <lp15@cam.ac.uk>
parents: 71410
diff changeset
   746
qed
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   747
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69275
diff changeset
   748
text \<open>Measure functions into \<^typ>\<open>nat\<close>\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   749
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   750
definition measure :: "('a \<Rightarrow> nat) \<Rightarrow> ('a \<times> 'a) set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   751
  where "measure = inv_image less_than"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   752
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   753
lemma in_measure[simp, code_unfold]: "(x, y) \<in> measure f \<longleftrightarrow> f x < f y"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   754
  by (simp add:measure_def)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   755
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   756
lemma wf_measure [iff]: "wf (measure f)"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   757
  unfolding measure_def by (rule wf_less_than [THEN wf_inv_image])
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   758
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   759
lemma wf_if_measure: "(\<And>x. P x \<Longrightarrow> f(g x) < f x) \<Longrightarrow> wf {(y,x). P x \<and> y = g x}"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   760
  for f :: "'a \<Rightarrow> nat"
68646
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   761
  using wf_measure[of f] unfolding measure_def inv_image_def less_than_def less_eq
7dc9fe795dae more de-applying
paulson <lp15@cam.ac.uk>
parents: 68262
diff changeset
   762
  by (rule wf_subset) auto
41720
f749155883d7 added termination lemmas
nipkow
parents: 41075
diff changeset
   763
f749155883d7 added termination lemmas
nipkow
parents: 41075
diff changeset
   764
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   765
subsubsection \<open>Lexicographic combinations\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   766
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   767
definition lex_prod :: "('a \<times>'a) set \<Rightarrow> ('b \<times> 'b) set \<Rightarrow> (('a \<times> 'b) \<times> ('a \<times> 'b)) set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   768
    (infixr "<*lex*>" 80)
72164
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71935
diff changeset
   769
    where "ra <*lex*> rb = {((a, b), (a', b')). a \<noteq> a' \<and> (a, a') \<in> ra \<or> a = a' \<and> (b, b') \<in> rb}"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   770
72164
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71935
diff changeset
   771
lemma in_lex_prod[simp]: "((a, b), (a', b')) \<in> r <*lex*> s \<longleftrightarrow> a \<noteq> a' \<and> (a, a') \<in> r \<or> a = a' \<and> (b, b') \<in> s"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   772
  by (auto simp:lex_prod_def)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   773
71410
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   774
lemma wf_lex_prod [intro!]:
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   775
  assumes "wf ra" "wf rb"
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   776
  shows "wf (ra <*lex*> rb)"
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   777
proof (rule wfI)
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   778
  fix z :: "'a \<times> 'b" and P
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   779
  assume * [rule_format]: "\<forall>u. (\<forall>v. (v, u) \<in> ra <*lex*> rb \<longrightarrow> P v) \<longrightarrow> P u"
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   780
  obtain x y where zeq: "z = (x,y)"
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   781
    by fastforce
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   782
  have "P(x,y)" using \<open>wf ra\<close>
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   783
  proof (induction x arbitrary: y rule: wf_induct_rule)
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   784
    case (less x)
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   785
    note lessx = less
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   786
    show ?case using \<open>wf rb\<close> less
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   787
    proof (induction y rule: wf_induct_rule)
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   788
      case (less y)
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   789
      show ?case
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   790
        by (force intro: * less.IH lessx)
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   791
    qed
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   792
  qed
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   793
  then show "P z"
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   794
    by (simp add: zeq)
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   795
qed auto
5385de42f9f4 Tidied up some messy proofs
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   796
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   797
text \<open>\<open><*lex*>\<close> preserves transitivity\<close>
72164
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71935
diff changeset
   798
lemma trans_lex_prod [simp,intro!]: "\<lbrakk>trans R1; trans R2; antisym R1\<rbrakk> \<Longrightarrow> trans (R1 <*lex*> R2)"
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71935
diff changeset
   799
  unfolding trans_def antisym_def lex_prod_def by blast
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71935
diff changeset
   800
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   801
71404
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   802
lemma total_on_lex_prod [simp]: "total_on A r \<Longrightarrow> total_on B s \<Longrightarrow> total_on (A \<times> B) (r <*lex*> s)"
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   803
  by (auto simp: total_on_def)
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   804
71935
82b00b8f1871 fixed the utterly weird definitions of asym / asymp, and added many asym lemmas
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   805
lemma asym_lex_prod: "\<lbrakk>asym R; asym S\<rbrakk> \<Longrightarrow> asym (R <*lex*> S)"
82b00b8f1871 fixed the utterly weird definitions of asym / asymp, and added many asym lemmas
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   806
  by (auto simp add: asym_iff lex_prod_def)
82b00b8f1871 fixed the utterly weird definitions of asym / asymp, and added many asym lemmas
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   807
71404
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   808
lemma total_lex_prod [simp]: "total r \<Longrightarrow> total s \<Longrightarrow> total (r <*lex*> s)"
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   809
  by (auto simp: total_on_def)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   810
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   811
text \<open>lexicographic combinations with measure functions\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   812
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   813
definition mlex_prod :: "('a \<Rightarrow> nat) \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set" (infixr "<*mlex*>" 80)
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   814
  where "f <*mlex*> R = inv_image (less_than <*lex*> R) (\<lambda>x. (f x, x))"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   815
66952
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   816
lemma
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   817
  wf_mlex: "wf R \<Longrightarrow> wf (f <*mlex*> R)" and
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   818
  mlex_less: "f x < f y \<Longrightarrow> (x, y) \<in> f <*mlex*> R" and
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   819
  mlex_leq: "f x \<le> f y \<Longrightarrow> (x, y) \<in> R \<Longrightarrow> (x, y) \<in> f <*mlex*> R" and
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   820
  mlex_iff: "(x, y) \<in> f <*mlex*> R \<longleftrightarrow> f x < f y \<or> f x = f y \<and> (x, y) \<in> R"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   821
  by (auto simp: mlex_prod_def)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   822
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   823
text \<open>Proper subset relation on finite sets.\<close>
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   824
definition finite_psubset :: "('a set \<times> 'a set) set"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   825
  where "finite_psubset = {(A, B). A \<subset> B \<and> finite B}"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   826
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   827
lemma wf_finite_psubset[simp]: "wf finite_psubset"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   828
  apply (unfold finite_psubset_def)
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   829
  apply (rule wf_measure [THEN wf_subset])
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   830
  apply (simp add: measure_def inv_image_def less_than_def less_eq)
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   831
  apply (fast elim!: psubset_card_mono)
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   832
  done
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   833
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   834
lemma trans_finite_psubset: "trans finite_psubset"
63612
7195acc2fe93 misc tuning and modernization;
wenzelm
parents: 63572
diff changeset
   835
  by (auto simp: finite_psubset_def less_le trans_def)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   836
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   837
lemma in_finite_psubset[simp]: "(A, B) \<in> finite_psubset \<longleftrightarrow> A \<subset> B \<and> finite B"
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   838
  unfolding finite_psubset_def by auto
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   839
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60493
diff changeset
   840
text \<open>max- and min-extension of order to finite sets\<close>
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   841
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   842
inductive_set max_ext :: "('a \<times> 'a) set \<Rightarrow> ('a set \<times> 'a set) set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   843
  for R :: "('a \<times> 'a) set"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   844
  where max_extI[intro]:
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   845
    "finite X \<Longrightarrow> finite Y \<Longrightarrow> Y \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> \<exists>y\<in>Y. (x, y) \<in> R) \<Longrightarrow> (X, Y) \<in> max_ext R"
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   846
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   847
lemma max_ext_wf:
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   848
  assumes wf: "wf r"
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   849
  shows "wf (max_ext r)"
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   850
proof (rule acc_wfI, intro allI)
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   851
  show "M \<in> acc (max_ext r)" (is "_ \<in> ?W") for M
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   852
  proof (induct M rule: infinite_finite_induct)
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   853
    case empty
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   854
    show ?case
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   855
      by (rule accI) (auto elim: max_ext.cases)
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   856
  next
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   857
    case (insert a M)
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   858
    from wf \<open>M \<in> ?W\<close> \<open>finite M\<close> show "insert a M \<in> ?W"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   859
    proof (induct arbitrary: M)
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   860
      fix M a
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   861
      assume "M \<in> ?W"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   862
      assume [intro]: "finite M"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   863
      assume hyp: "\<And>b M. (b, a) \<in> r \<Longrightarrow> M \<in> ?W \<Longrightarrow> finite M \<Longrightarrow> insert b M \<in> ?W"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   864
      have add_less: "M \<in> ?W \<Longrightarrow> (\<And>y. y \<in> N \<Longrightarrow> (y, a) \<in> r) \<Longrightarrow> N \<union> M \<in> ?W"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   865
        if "finite N" "finite M" for N M :: "'a set"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   866
        using that by (induct N arbitrary: M) (auto simp: hyp)
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   867
      show "insert a M \<in> ?W"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   868
      proof (rule accI)
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   869
        fix N
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   870
        assume Nless: "(N, insert a M) \<in> max_ext r"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   871
        then have *: "\<And>x. x \<in> N \<Longrightarrow> (x, a) \<in> r \<or> (\<exists>y \<in> M. (x, y) \<in> r)"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   872
          by (auto elim!: max_ext.cases)
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   873
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   874
        let ?N1 = "{n \<in> N. (n, a) \<in> r}"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   875
        let ?N2 = "{n \<in> N. (n, a) \<notin> r}"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   876
        have N: "?N1 \<union> ?N2 = N" by (rule set_eqI) auto
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   877
        from Nless have "finite N" by (auto elim: max_ext.cases)
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   878
        then have finites: "finite ?N1" "finite ?N2" by auto
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   879
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   880
        have "?N2 \<in> ?W"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   881
        proof (cases "M = {}")
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   882
          case [simp]: True
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   883
          have Mw: "{} \<in> ?W" by (rule accI) (auto elim: max_ext.cases)
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   884
          from * have "?N2 = {}" by auto
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   885
          with Mw show "?N2 \<in> ?W" by (simp only:)
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   886
        next
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   887
          case False
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   888
          from * finites have N2: "(?N2, M) \<in> max_ext r"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   889
            by (rule_tac max_extI[OF _ _ \<open>M \<noteq> {}\<close>]) auto
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   890
          with \<open>M \<in> ?W\<close> show "?N2 \<in> ?W" by (rule acc_downward)
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   891
        qed
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   892
        with finites have "?N1 \<union> ?N2 \<in> ?W"
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   893
          by (rule add_less) simp
bab633745c7f tuned proofs;
wenzelm
parents: 63612
diff changeset
   894
        then show "N \<in> ?W" by (simp only: N)
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   895
      qed
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   896
    qed
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   897
  next
63982
wenzelm
parents: 63915
diff changeset
   898
    case infinite
wenzelm
parents: 63915
diff changeset
   899
    show ?case
wenzelm
parents: 63915
diff changeset
   900
      by (rule accI) (auto elim: max_ext.cases simp: infinite)
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   901
  qed
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   902
qed
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   903
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   904
lemma max_ext_additive: "(A, B) \<in> max_ext R \<Longrightarrow> (C, D) \<in> max_ext R \<Longrightarrow> (A \<union> C, B \<union> D) \<in> max_ext R"
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   905
  by (force elim!: max_ext.cases)
29125
d41182a8135c method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents: 28845
diff changeset
   906
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   907
definition min_ext :: "('a \<times> 'a) set \<Rightarrow> ('a set \<times> 'a set) set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   908
  where "min_ext r = {(X, Y) | X Y. X \<noteq> {} \<and> (\<forall>y \<in> Y. (\<exists>x \<in> X. (x, y) \<in> r))}"
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   909
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   910
lemma min_ext_wf:
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   911
  assumes "wf r"
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   912
  shows "wf (min_ext r)"
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   913
proof (rule wfI_min)
66952
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   914
  show "\<exists>m \<in> Q. (\<forall>n. (n, m) \<in> min_ext r \<longrightarrow> n \<notin> Q)" if nonempty: "x \<in> Q"
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   915
    for Q :: "'a set set" and x
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   916
  proof (cases "Q = {{}}")
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   917
    case True
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   918
    then show ?thesis by (simp add: min_ext_def)
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   919
  next
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   920
    case False
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   921
    with nonempty obtain e x where "x \<in> Q" "e \<in> x" by force
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   922
    then have eU: "e \<in> \<Union>Q" by auto
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   923
    with \<open>wf r\<close>
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   924
    obtain z where z: "z \<in> \<Union>Q" "\<And>y. (y, z) \<in> r \<Longrightarrow> y \<notin> \<Union>Q"
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   925
      by (erule wfE_min)
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   926
    from z obtain m where "m \<in> Q" "z \<in> m" by auto
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   927
    from \<open>m \<in> Q\<close> show ?thesis
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   928
    proof (intro rev_bexI allI impI)
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   929
      fix n
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   930
      assume smaller: "(n, m) \<in> min_ext r"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   931
      with \<open>z \<in> m\<close> obtain y where "y \<in> n" "(y, z) \<in> r"
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   932
        by (auto simp: min_ext_def)
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   933
      with z(2) show "n \<notin> Q" by auto
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   934
    qed
28735
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   935
  qed
bed31381e6b6 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
krauss
parents: 28562
diff changeset
   936
qed
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   937
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   938
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   939
subsubsection \<open>Bounded increase must terminate\<close>
43137
32b888e1a170 new lemmas
nipkow
parents: 41720
diff changeset
   940
32b888e1a170 new lemmas
nipkow
parents: 41720
diff changeset
   941
lemma wf_bounded_measure:
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   942
  fixes ub :: "'a \<Rightarrow> nat"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   943
    and f :: "'a \<Rightarrow> nat"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   944
  assumes "\<And>a b. (b, a) \<in> r \<Longrightarrow> ub b \<le> ub a \<and> ub a \<ge> f b \<and> f b > f a"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   945
  shows "wf r"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   946
  by (rule wf_subset[OF wf_measure[of "\<lambda>a. ub a - f a"]]) (auto dest: assms)
43137
32b888e1a170 new lemmas
nipkow
parents: 41720
diff changeset
   947
32b888e1a170 new lemmas
nipkow
parents: 41720
diff changeset
   948
lemma wf_bounded_set:
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   949
  fixes ub :: "'a \<Rightarrow> 'b set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   950
    and f :: "'a \<Rightarrow> 'b set"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   951
  assumes "\<And>a b. (b,a) \<in> r \<Longrightarrow> finite (ub a) \<and> ub b \<subseteq> ub a \<and> ub a \<supseteq> f b \<and> f b \<supset> f a"
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   952
  shows "wf r"
63572
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   953
  apply (rule wf_bounded_measure[of r "\<lambda>a. card (ub a)" "\<lambda>a. card (f a)"])
c0cbfd2b5a45 misc tuning and modernization;
wenzelm
parents: 63109
diff changeset
   954
  apply (drule assms)
63108
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   955
  apply (blast intro: card_mono finite_subset psubset_card_mono dest: psubset_eq[THEN iffD2])
02b885591735 misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   956
  done
43137
32b888e1a170 new lemmas
nipkow
parents: 41720
diff changeset
   957
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 63088
diff changeset
   958
lemma finite_subset_wf:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 63088
diff changeset
   959
  assumes "finite A"
66952
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   960
  shows "wf {(X, Y). X \<subset> Y \<and> Y \<subseteq> A}"
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   961
  by (rule wf_subset[OF wf_finite_psubset[unfolded finite_psubset_def]])
80985b62029d added 'mlex_iff' lemma and simplified proof
blanchet
parents: 64632
diff changeset
   962
    (auto intro: finite_subset[OF _ assms])
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   963
54295
45a5523d4a63 qualifed popular user space names
haftmann
parents: 49945
diff changeset
   964
hide_const (open) acc accp
45a5523d4a63 qualifed popular user space names
haftmann
parents: 49945
diff changeset
   965
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
diff changeset
   966
end