src/HOL/WF_Rel.ML
author wenzelm
Mon, 22 Jun 1998 17:26:46 +0200
changeset 5069 3ea049f7979d
parent 4751 6fbd9838ccae
child 5143 b94cd208f073
permissions -rw-r--r--
isatool fixgoal;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
     1
(*  Title: 	HOL/WF_Rel
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
     2
    ID:         $Id$
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
     3
    Author: 	Konrad Slind
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
     4
    Copyright   1996  TU Munich
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
     5
3296
2ee6c397003d Deleted rprod: lex_prod is (usually?) enough
paulson
parents: 3237
diff changeset
     6
Derived WF relations: inverse image, lexicographic product, measure, ...
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
     7
*)
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
     8
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
     9
open WF_Rel;
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    10
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    11
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    12
(*----------------------------------------------------------------------------
3237
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    13
 * "Less than" on the natural numbers
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    14
 *---------------------------------------------------------------------------*)
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    15
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
    16
Goalw [less_than_def] "wf less_than"; 
3237
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    17
by (rtac (wf_pred_nat RS wf_trancl) 1);
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    18
qed "wf_less_than";
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    19
AddIffs [wf_less_than];
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    20
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
    21
Goalw [less_than_def] "trans less_than"; 
3237
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    22
by (rtac trans_trancl 1);
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    23
qed "trans_less_than";
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    24
AddIffs [trans_less_than];
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    25
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
    26
Goalw [less_than_def, less_def] "((x,y): less_than) = (x<y)"; 
3237
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    27
by (Simp_tac 1);
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    28
qed "less_than_iff";
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    29
AddIffs [less_than_iff];
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    30
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    31
(*----------------------------------------------------------------------------
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    32
 * The inverse image into a wellfounded relation is wellfounded.
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    33
 *---------------------------------------------------------------------------*)
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    34
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
    35
Goal "!!r. wf(r) ==> wf(inv_image r (f::'a=>'b))"; 
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3718
diff changeset
    36
by (full_simp_tac (simpset() addsimps [inv_image_def, wf_eq_minimal]) 1);
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3484
diff changeset
    37
by (Clarify_tac 1);
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    38
by (subgoal_tac "? (w::'b). w : {w. ? (x::'a). x: Q & (f x = w)}" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3718
diff changeset
    39
by (blast_tac (claset() delrules [allE]) 2);
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    40
by (etac allE 1);
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    41
by (mp_tac 1);
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    42
by (Blast_tac 1);
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    43
qed "wf_inv_image";
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    44
AddSIs [wf_inv_image];
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    45
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
    46
Goalw [trans_def,inv_image_def]
3237
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    47
    "!!r. trans r ==> trans (inv_image r f)";
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    48
by (Simp_tac 1);
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    49
by (Blast_tac 1);
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    50
qed "trans_inv_image";
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    51
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    52
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    53
(*----------------------------------------------------------------------------
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    54
 * All measures are wellfounded.
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    55
 *---------------------------------------------------------------------------*)
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    56
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
    57
Goalw [measure_def] "wf (measure f)";
3237
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    58
by (rtac (wf_less_than RS wf_inv_image) 1);
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    59
qed "wf_measure";
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    60
AddIffs [wf_measure];
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    61
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4089
diff changeset
    62
val measure_induct = standard
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4089
diff changeset
    63
    (asm_full_simplify (simpset() addsimps [measure_def,inv_image_def])
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4089
diff changeset
    64
      (wf_measure RS wf_induct));
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4089
diff changeset
    65
store_thm("measure_induct",measure_induct);
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4089
diff changeset
    66
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    67
(*----------------------------------------------------------------------------
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    68
 * Wellfoundedness of lexicographic combinations
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    69
 *---------------------------------------------------------------------------*)
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    70
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    71
val [wfa,wfb] = goalw thy [wf_def,lex_prod_def]
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    72
 "[| wf(ra); wf(rb) |] ==> wf(ra**rb)";
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
    73
by (EVERY1 [rtac allI,rtac impI]);
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
    74
by (simp_tac (HOL_basic_ss addsimps [split_paired_All]) 1);
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    75
by (rtac (wfa RS spec RS mp) 1);
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    76
by (EVERY1 [rtac allI,rtac impI]);
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    77
by (rtac (wfb RS spec RS mp) 1);
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    78
by (Blast_tac 1);
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    79
qed "wf_lex_prod";
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    80
AddSIs [wf_lex_prod];
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    81
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    82
(*---------------------------------------------------------------------------
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    83
 * Transitivity of WF combinators.
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    84
 *---------------------------------------------------------------------------*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
    85
Goalw [trans_def, lex_prod_def]
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    86
    "!!R1 R2. [| trans R1; trans R2 |] ==> trans (R1 ** R2)";
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    87
by (Simp_tac 1);
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    88
by (Blast_tac 1);
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    89
qed "trans_lex_prod";
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    90
AddSIs [trans_lex_prod];
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    91
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    92
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    93
(*---------------------------------------------------------------------------
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    94
 * Wellfoundedness of proper subset on finite sets.
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    95
 *---------------------------------------------------------------------------*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
    96
Goalw [finite_psubset_def] "wf(finite_psubset)";
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
    97
by (rtac (wf_measure RS wf_subset) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3718
diff changeset
    98
by (simp_tac (simpset() addsimps [measure_def, inv_image_def, less_than_def,
3237
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
    99
				 symmetric less_def])1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3718
diff changeset
   100
by (fast_tac (claset() addSIs [psubset_card]) 1);
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
   101
qed "wf_finite_psubset";
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
   102
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
   103
Goalw [finite_psubset_def, trans_def] "trans finite_psubset";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3718
diff changeset
   104
by (simp_tac (simpset() addsimps [psubset_def]) 1);
3237
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
   105
by (Blast_tac 1);
4da86d44de33 Relation "less_than" internalizes "<" for easy use of TFL
paulson
parents: 3193
diff changeset
   106
qed "trans_finite_psubset";
3193
fafc7e815b70 New theories used by TFL
paulson
parents:
diff changeset
   107
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   108
(*---------------------------------------------------------------------------
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   109
 * Wellfoundedness of finite acyclic relations
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   110
 * Cannot go into WF because it needs Finite
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   111
 *---------------------------------------------------------------------------*)
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   112
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
   113
Goal "!!r. finite r ==> acyclic r --> wf r";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   114
by (etac finite_induct 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   115
 by (Blast_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   116
by (split_all_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   117
by (Asm_full_simp_tac 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   118
qed_spec_mp "finite_acyclic_wf";
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   119
4749
35b47e36e615 added finite_acyclic_wf_converse
oheimb
parents: 4643
diff changeset
   120
qed_goal "finite_acyclic_wf_converse" thy 
4751
6fbd9838ccae added finite_acyclic_wf_converse: corrected 8bit chars
oheimb
parents: 4749
diff changeset
   121
 "!!X. [|finite r; acyclic r|] ==> wf (r^-1)" (K [
4749
35b47e36e615 added finite_acyclic_wf_converse
oheimb
parents: 4643
diff changeset
   122
	etac (finite_converse RS iffD2 RS finite_acyclic_wf) 1,
35b47e36e615 added finite_acyclic_wf_converse
oheimb
parents: 4643
diff changeset
   123
	etac (acyclic_converse RS iffD2) 1]);
35b47e36e615 added finite_acyclic_wf_converse
oheimb
parents: 4643
diff changeset
   124
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
   125
Goal "!!r. finite r ==> wf r = acyclic r";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3718
diff changeset
   126
by (blast_tac (claset() addIs [finite_acyclic_wf,wf_acyclic]) 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   127
qed "wf_iff_acyclic_if_finite";
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   128
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   129
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   130
(*---------------------------------------------------------------------------
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   131
 * A relation is wellfounded iff it has no infinite descending chain
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   132
 *---------------------------------------------------------------------------*)
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   133
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4751
diff changeset
   134
Goalw [wf_eq_minimal RS eq_reflection]
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   135
  "wf r = (~(? f. !i. (f(Suc i),f i) : r))";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   136
by (rtac iffI 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   137
 by (rtac notI 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   138
 by (etac exE 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   139
 by (eres_inst_tac [("x","{w. ? i. w=f i}")] allE 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   140
 by (Blast_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   141
by (etac swap 1);
3446
a14e5451f613 Addition of not_imp (which pushes negation into implication) as a default
paulson
parents: 3436
diff changeset
   142
by (Asm_full_simp_tac 1);
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3484
diff changeset
   143
by (Clarify_tac 1);
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   144
by (subgoal_tac "!n. nat_rec x (%i y. @z. z:Q & (z,y):r) n : Q" 1);
3436
d68dbb8f22d3 Tuned wf_iff_no_infinite_down_chain proof, based on Konrads ideas.
nipkow
parents: 3413
diff changeset
   145
 by (res_inst_tac[("x","nat_rec x (%i y. @z. z:Q & (z,y):r)")]exI 1);
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   146
 by (rtac allI 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   147
 by (Simp_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   148
 by (rtac selectI2EX 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   149
  by (Blast_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   150
 by (Blast_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   151
by (rtac allI 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   152
by (induct_tac "n" 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   153
 by (Asm_simp_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   154
by (Simp_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   155
by (rtac selectI2EX 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   156
 by (Blast_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3446
diff changeset
   157
by (Blast_tac 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3296
diff changeset
   158
qed "wf_iff_no_infinite_down_chain";