src/HOL/Wellfounded_Relations.thy
author haftmann
Tue, 22 Apr 2008 10:31:15 +0200
changeset 26737 3d46c55f03af
parent 26072 f65a7fa2da6c
permissions -rw-r--r--
dropped theory PreList
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
     1
(*  ID:   $Id$
10213
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     2
    Author:     Konrad Slind
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     3
    Copyright   1995 TU Munich
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     4
*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     5
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
     6
header {*Well-founded Relations*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
     7
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
     8
theory Wellfounded_Relations
25517
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
     9
imports Finite_Set FunDef
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
    10
uses
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
    11
  ("Tools/function_package/lexicographic_order.ML")
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
    12
  ("Tools/function_package/fundef_datatype.ML")
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    13
begin
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    14
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    15
text{*Derived WF relations such as inverse image, lexicographic product and
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    16
measure. The simple relational product, in which @{term "(x',y')"} precedes
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    17
@{term "(x,y)"} if @{term "x'<x"} and @{term "y'<y"}, is a subset of the
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    18
lexicographic product, and therefore does not need to be defined separately.*}
10213
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    19
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    20
constdefs
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    21
 measure   :: "('a => nat) => ('a * 'a)set"
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    22
    "measure == inv_image less_than"
10213
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    23
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    24
 lex_prod  :: "[('a*'a)set, ('b*'b)set] => (('a*'b)*('a*'b))set"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    25
               (infixr "<*lex*>" 80)
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    26
    "ra <*lex*> rb == {((a,b),(a',b')). (a,a') : ra | a=a' & (b,b') : rb}"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    27
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    28
 finite_psubset  :: "('a set * 'a set) set"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    29
   --{* finite proper subset*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    30
    "finite_psubset == {(A,B). A < B & finite B}"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    31
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    32
 same_fst :: "('a => bool) => ('a => ('b * 'b)set) => (('a*'b)*('a*'b))set"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    33
    "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    34
   --{*For @{text rec_def} declarations where the first n parameters
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    35
       stay unchanged in the recursive call. 
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    36
       See @{text "Library/While_Combinator.thy"} for an application.*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    37
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    38
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    39
subsection{*Measure Functions make Wellfounded Relations*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    40
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    41
subsubsection{*`Less than' on the natural numbers*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    42
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    43
lemma full_nat_induct:
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    44
  assumes ih: "(!!n. (ALL m. Suc m <= n --> P m) ==> P n)"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    45
  shows "P n"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    46
apply (rule wf_less_than [THEN wf_induct])
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    47
apply (rule ih, auto)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    48
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    49
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    50
subsubsection{*The Inverse Image into a Wellfounded Relation is Wellfounded.*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    51
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    52
lemma wf_inv_image [simp,intro!]: "wf(r) ==> wf(inv_image r (f::'a=>'b))"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    53
apply (simp (no_asm_use) add: inv_image_def wf_eq_minimal)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    54
apply clarify
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    55
apply (subgoal_tac "EX (w::'b) . w : {w. EX (x::'a) . x: Q & (f x = w) }")
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    56
prefer 2 apply (blast del: allE)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    57
apply (erule allE)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    58
apply (erule (1) notE impE)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    59
apply blast
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    60
done
10213
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    61
19769
c40ce2de2020 Added [simp]-lemmas "in_inv_image" and "in_lex_prod" in the spirit of "in_measure".
krauss
parents: 19623
diff changeset
    62
lemma in_inv_image[simp]: "((x,y) : inv_image r f) = ((f x, f y) : r)"
c40ce2de2020 Added [simp]-lemmas "in_inv_image" and "in_lex_prod" in the spirit of "in_measure".
krauss
parents: 19623
diff changeset
    63
  by (auto simp:inv_image_def)
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    64
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    65
subsubsection{*Finally, All Measures are Wellfounded.*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    66
19623
12e6cc4382ae added lemma in_measure
nipkow
parents: 19404
diff changeset
    67
lemma in_measure[simp]: "((x,y) : measure f) = (f x < f y)"
19769
c40ce2de2020 Added [simp]-lemmas "in_inv_image" and "in_lex_prod" in the spirit of "in_measure".
krauss
parents: 19623
diff changeset
    68
  by (simp add:measure_def)
19623
12e6cc4382ae added lemma in_measure
nipkow
parents: 19404
diff changeset
    69
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    70
lemma wf_measure [iff]: "wf (measure f)"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    71
apply (unfold measure_def)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    72
apply (rule wf_less_than [THEN wf_inv_image])
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    73
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    74
18277
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    75
lemma measure_induct_rule [case_names less]:
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    76
  fixes f :: "'a \<Rightarrow> nat"
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    77
  assumes step: "\<And>x. (\<And>y. f y < f x \<Longrightarrow> P y) \<Longrightarrow> P x"
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    78
  shows "P a"
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    79
proof -
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    80
  have "wf (measure f)" ..
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    81
  then show ?thesis
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    82
  proof induct
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    83
    case (less x)
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    84
    show ?case
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    85
    proof (rule step)
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    86
      fix y
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    87
      assume "f y < f x"
19623
12e6cc4382ae added lemma in_measure
nipkow
parents: 19404
diff changeset
    88
      hence "(y, x) \<in> measure f" by simp
12e6cc4382ae added lemma in_measure
nipkow
parents: 19404
diff changeset
    89
      thus "P y" by (rule less)
18277
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    90
    qed
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    91
  qed
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    92
qed
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    93
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    94
lemma measure_induct:
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    95
  fixes f :: "'a \<Rightarrow> nat"
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    96
  shows "(\<And>x. \<forall>y. f y < f x \<longrightarrow> P y \<Longrightarrow> P x) \<Longrightarrow> P a"
6c2b039b4847 added proof of measure_induct_rule;
wenzelm
parents: 15352
diff changeset
    97
  by (rule measure_induct_rule [of f P a]) iprover
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
    98
24853
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
    99
(* Should go into Finite_Set, but needs measure.
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   100
   Maybe move Wf_Rel before Finite_Set and finite_psubset to Finite_set?
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   101
*)
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   102
lemma (in linorder)
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   103
  finite_linorder_induct[consumes 1, case_names empty insert]:
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   104
 "finite A \<Longrightarrow> P {} \<Longrightarrow>
25062
af5ef0d4d655 global class syntax
haftmann
parents: 24853
diff changeset
   105
  (!!A b. finite A \<Longrightarrow> ALL a:A. a < b \<Longrightarrow> P A \<Longrightarrow> P(insert b A))
24853
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   106
  \<Longrightarrow> P A"
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   107
proof (induct A rule: measure_induct[where f=card])
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   108
  fix A :: "'a set"
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   109
  assume IH: "ALL B. card B < card A \<longrightarrow> finite B \<longrightarrow> P {} \<longrightarrow>
25062
af5ef0d4d655 global class syntax
haftmann
parents: 24853
diff changeset
   110
                 (\<forall>A b. finite A \<longrightarrow> (\<forall>a\<in>A. a<b) \<longrightarrow> P A \<longrightarrow> P (insert b A))
24853
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   111
                  \<longrightarrow> P B"
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   112
  and "finite A" and "P {}"
25062
af5ef0d4d655 global class syntax
haftmann
parents: 24853
diff changeset
   113
  and step: "!!A b. \<lbrakk>finite A; \<forall>a\<in>A. a < b; P A\<rbrakk> \<Longrightarrow> P (insert b A)"
24853
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   114
  show "P A"
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   115
  proof cases
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   116
    assume "A = {}" thus "P A" using `P {}` by simp
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   117
  next
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   118
    let ?B = "A - {Max A}" let ?A = "insert (Max A) ?B"
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   119
    assume "A \<noteq> {}"
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   120
    with `finite A` have "Max A : A" by auto
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   121
    hence A: "?A = A" using insert_Diff_single insert_absorb by auto
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   122
    note card_Diff1_less[OF `finite A` `Max A : A`]
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   123
    moreover have "finite ?B" using `finite A` by simp
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   124
    ultimately have "P ?B" using `P {}` step IH by blast
25062
af5ef0d4d655 global class syntax
haftmann
parents: 24853
diff changeset
   125
    moreover have "\<forall>a\<in>?B. a < Max A"
24853
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   126
      using Max_ge[OF `finite A` `A \<noteq> {}`] by fastsimp
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   127
    ultimately show "P A"
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   128
      using A insert_Diff_single step[OF `finite ?B`] by fastsimp
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   129
  qed
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   130
qed
aab5798e5a33 added lemmas
nipkow
parents: 24575
diff changeset
   131
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   132
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   133
subsection{*Other Ways of Constructing Wellfounded Relations*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   134
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   135
text{*Wellfoundedness of lexicographic combinations*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   136
lemma wf_lex_prod [intro!]: "[| wf(ra); wf(rb) |] ==> wf(ra <*lex*> rb)"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   137
apply (unfold wf_def lex_prod_def) 
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   138
apply (rule allI, rule impI)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   139
apply (simp (no_asm_use) only: split_paired_All)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   140
apply (drule spec, erule mp) 
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   141
apply (rule allI, rule impI)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   142
apply (drule spec, erule mp, blast) 
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   143
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   144
19769
c40ce2de2020 Added [simp]-lemmas "in_inv_image" and "in_lex_prod" in the spirit of "in_measure".
krauss
parents: 19623
diff changeset
   145
lemma in_lex_prod[simp]: 
c40ce2de2020 Added [simp]-lemmas "in_inv_image" and "in_lex_prod" in the spirit of "in_measure".
krauss
parents: 19623
diff changeset
   146
  "(((a,b),(a',b')): r <*lex*> s) = ((a,a'): r \<or> (a = a' \<and> (b, b') : s))"
c40ce2de2020 Added [simp]-lemmas "in_inv_image" and "in_lex_prod" in the spirit of "in_measure".
krauss
parents: 19623
diff changeset
   147
  by (auto simp:lex_prod_def)
c40ce2de2020 Added [simp]-lemmas "in_inv_image" and "in_lex_prod" in the spirit of "in_measure".
krauss
parents: 19623
diff changeset
   148
24575
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   149
text {* lexicographic combinations with measure functions *}
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   150
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   151
definition 
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   152
  mlex_prod :: "('a \<Rightarrow> nat) \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set" (infixr "<*mlex*>" 80)
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   153
where
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   154
  "f <*mlex*> R = inv_image (less_than <*lex*> R) (%x. (f x, x))"
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   155
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   156
lemma wf_mlex: "wf R \<Longrightarrow> wf (f <*mlex*> R)"
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   157
unfolding mlex_prod_def
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   158
by auto
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   159
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   160
lemma mlex_less: "f x < f y \<Longrightarrow> (x, y) \<in> f <*mlex*> R"
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   161
unfolding mlex_prod_def by simp
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   162
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   163
lemma mlex_leq: "f x \<le> f y \<Longrightarrow> (x, y) \<in> R \<Longrightarrow> (x, y) \<in> f <*mlex*> R"
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   164
unfolding mlex_prod_def by auto
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   165
8b5c5eb7df87 added "<*mlex*>" which lexicographically combines a measure function with a relation
krauss
parents: 22261
diff changeset
   166
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   167
text{*Transitivity of WF combinators.*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   168
lemma trans_lex_prod [intro!]: 
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   169
    "[| trans R1; trans R2 |] ==> trans (R1 <*lex*> R2)"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   170
by (unfold trans_def lex_prod_def, blast) 
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   171
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   172
subsubsection{*Wellfoundedness of proper subset on finite sets.*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   173
lemma wf_finite_psubset: "wf(finite_psubset)"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   174
apply (unfold finite_psubset_def)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   175
apply (rule wf_measure [THEN wf_subset])
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25517
diff changeset
   176
apply (simp add: measure_def inv_image_def less_than_def less_eq)
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   177
apply (fast elim!: psubset_card_mono)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   178
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   179
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   180
lemma trans_finite_psubset: "trans finite_psubset"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   181
by (simp add: finite_psubset_def psubset_def trans_def, blast)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   182
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   183
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   184
subsubsection{*Wellfoundedness of finite acyclic relations*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   185
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   186
text{*This proof belongs in this theory because it needs Finite.*}
10213
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
   187
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   188
lemma finite_acyclic_wf [rule_format]: "finite r ==> acyclic r --> wf r"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   189
apply (erule finite_induct, blast)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   190
apply (simp (no_asm_simp) only: split_tupled_all)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   191
apply simp
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   192
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   193
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   194
lemma finite_acyclic_wf_converse: "[|finite r; acyclic r|] ==> wf (r^-1)"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   195
apply (erule finite_converse [THEN iffD2, THEN finite_acyclic_wf])
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   196
apply (erule acyclic_converse [THEN iffD2])
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   197
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   198
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   199
lemma wf_iff_acyclic_if_finite: "finite r ==> wf r = acyclic r"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   200
by (blast intro: finite_acyclic_wf wf_acyclic)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   201
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   202
15352
cba05842bd7a fixed presentation
paulson
parents: 15348
diff changeset
   203
subsubsection{*Wellfoundedness of @{term same_fst}*}
15346
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   204
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   205
lemma same_fstI [intro!]:
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   206
     "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   207
by (simp add: same_fst_def)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   208
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   209
lemma wf_same_fst:
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   210
  assumes prem: "(!!x. P x ==> wf(R x))"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   211
  shows "wf(same_fst P R)"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   212
apply (simp cong del: imp_cong add: wf_def same_fst_def)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   213
apply (intro strip)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   214
apply (rename_tac a b)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   215
apply (case_tac "wf (R a)")
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   216
 apply (erule_tac a = b in wf_induct, blast)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   217
apply (blast intro: prem)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   218
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   219
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   220
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   221
subsection{*Weakly decreasing sequences (w.r.t. some well-founded order) 
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   222
   stabilize.*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   223
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   224
text{*This material does not appear to be used any longer.*}
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   225
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   226
lemma lemma1: "[| ALL i. (f (Suc i), f i) : r^* |] ==> (f (i+k), f i) : r^*"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   227
apply (induct_tac "k", simp_all)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   228
apply (blast intro: rtrancl_trans)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   229
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   230
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   231
lemma lemma2: "[| ALL i. (f (Suc i), f i) : r^*; wf (r^+) |]  
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   232
      ==> ALL m. f m = x --> (EX i. ALL k. f (m+i+k) = f (m+i))"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   233
apply (erule wf_induct, clarify)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   234
apply (case_tac "EX j. (f (m+j), f m) : r^+")
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   235
 apply clarify
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   236
 apply (subgoal_tac "EX i. ALL k. f ((m+j) +i+k) = f ( (m+j) +i) ")
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   237
  apply clarify
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   238
  apply (rule_tac x = "j+i" in exI)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   239
  apply (simp add: add_ac, blast)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   240
apply (rule_tac x = 0 in exI, clarsimp)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   241
apply (drule_tac i = m and k = k in lemma1)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   242
apply (blast elim: rtranclE dest: rtrancl_into_trancl1)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   243
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   244
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   245
lemma wf_weak_decr_stable: "[| ALL i. (f (Suc i), f i) : r^*; wf (r^+) |]  
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   246
      ==> EX i. ALL k. f (i+k) = f i"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   247
apply (drule_tac x = 0 in lemma2 [THEN spec], auto)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   248
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   249
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   250
(* special case of the theorem above: <= *)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   251
lemma weak_decr_stable:
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   252
     "ALL i. f (Suc i) <= ((f i)::nat) ==> EX i. ALL k. f (i+k) = f i"
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   253
apply (rule_tac r = pred_nat in wf_weak_decr_stable)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   254
apply (simp add: pred_nat_trancl_eq_le)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   255
apply (intro wf_trancl wf_pred_nat)
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   256
done
ac272926fb77 converted Wellfounded_Relations to Isar script
paulson
parents: 12398
diff changeset
   257
25517
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   258
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   259
text {*
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   260
  Setup of @{text lexicographic_order} method
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   261
  and @{text fun} command
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   262
*}
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   263
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   264
use "Tools/function_package/lexicographic_order.ML"
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   265
use "Tools/function_package/fundef_datatype.ML"
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   266
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   267
setup "LexicographicOrder.setup #> FundefDatatype.setup"
36d710d1dbce shifted "fun" command to Wellfounded_Relations
haftmann
parents: 25481
diff changeset
   268
10213
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
   269
end