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