src/HOL/WF.ML
author nipkow
Fri, 23 May 1997 18:17:53 +0200
changeset 3320 3a5e4930fb77
parent 3198 295287618e30
child 3413 c1f63cc3a768
permissions -rw-r--r--
Added `arbitrary'
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
     1
(*  Title:      HOL/wf.ML
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
     3
    Author:     Tobias Nipkow, with minor changes by Konrad Slind
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
     4
    Copyright   1992  University of Cambridge/1995 TU Munich
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
3198
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
     6
Wellfoundedness, induction, and  recursion
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
open WF;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
950
323f8ca4587a Removed superfluous type constraint
nipkow
parents: 923
diff changeset
    11
val H_cong = read_instantiate [("f","H")] (standard(refl RS cong RS cong));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
val H_cong1 = refl RS H_cong;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
(*Restriction to domain A.  If r is well-founded over A then wf(r)*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
val [prem1,prem2] = goalw WF.thy [wf_def]
1642
21db0cf9a1a4 Using new "Times" infix
paulson
parents: 1618
diff changeset
    16
 "[| r <= A Times A;  \
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 950
diff changeset
    17
\    !!x P. [| ! x. (! y. (y,x) : r --> P(y)) --> P(x);  x:A |] ==> P(x) |]  \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
\ ==>  wf(r)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
by (strip_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
by (rtac allE 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
by (assume_tac 1);
1786
8a31d85d27b8 best_tac, deepen_tac and safe_tac now also use default claset.
berghofe
parents: 1771
diff changeset
    22
by (best_tac (!claset addSEs [prem1 RS subsetD RS SigmaE2] addIs [prem2]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
qed "wfI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    25
val major::prems = goalw WF.thy [wf_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
    "[| wf(r);          \
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 950
diff changeset
    27
\       !!x.[| ! y. (y,x): r --> P(y) |] ==> P(x) \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
\    |]  ==>  P(a)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
by (rtac (major RS spec RS mp RS spec) 1);
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2637
diff changeset
    30
by (blast_tac (!claset addIs prems) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
qed "wf_induct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
(*Perform induction on i, then prove the wf(r) subgoal using prems. *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
fun wf_ind_tac a prems i = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
    EVERY [res_inst_tac [("a",a)] wf_induct i,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    36
           rename_last_tac a ["1"] (i+1),
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    37
           ares_tac prems i];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 950
diff changeset
    39
val prems = goal WF.thy "[| wf(r);  (a,x):r;  (x,a):r |] ==> P";
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 950
diff changeset
    40
by (subgoal_tac "! x. (a,x):r --> (x,a):r --> P" 1);
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2637
diff changeset
    41
by (blast_tac (!claset addIs prems) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
by (wf_ind_tac "a" prems 1);
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2637
diff changeset
    43
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
qed "wf_asym";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 950
diff changeset
    46
val prems = goal WF.thy "[| wf(r);  (a,a): r |] ==> P";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
by (rtac wf_asym 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
by (REPEAT (resolve_tac prems 1));
1618
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
    49
qed "wf_irrefl";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
    51
(*transitive closure of a wf relation is wf! *)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
val [prem] = goal WF.thy "wf(r) ==> wf(r^+)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
by (rewtac wf_def);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
by (strip_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
(*must retain the universal formula for later use!*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
by (rtac allE 1 THEN assume_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
by (etac mp 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
by (res_inst_tac [("a","x")] (prem RS wf_induct) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
by (rtac (impI RS allI) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
by (etac tranclE 1);
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2637
diff changeset
    61
by (Blast_tac 1);
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2637
diff changeset
    62
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
qed "wf_trancl";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
3198
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    66
(*----------------------------------------------------------------------------
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    67
 * Minimal-element characterization of well-foundedness
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    68
 *---------------------------------------------------------------------------*)
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    69
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    70
val wfr::_ = goalw WF.thy [wf_def]
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    71
    "wf r ==> x:Q --> (? z:Q. ! y. (y,z):r --> y~:Q)";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    72
by (rtac (wfr RS spec RS mp RS spec) 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    73
by (Blast_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    74
val lemma1 = result();
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    75
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    76
goalw WF.thy [wf_def]
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    77
    "!!r. (! Q x. x:Q --> (? z:Q. ! y. (y,z):r --> y~:Q)) ==> wf r";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    78
by (strip_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    79
by (dres_inst_tac [("x", "{x. ~ P x}")] spec 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    80
by (Blast_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    81
val lemma2 = result();
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    82
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    83
goal WF.thy "wf r = (! Q x. x:Q --> (? z:Q. ! y. (y,z):r --> y~:Q))";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    84
by (blast_tac (!claset addSIs [lemma1, lemma2]) 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    85
qed "wf_eq_minimal";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    86
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
    87
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
(** cut **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
(*This rewrite rule works upon formulae; thus it requires explicit use of
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    91
  H_cong to expose the equality*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
goalw WF.thy [cut_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 950
diff changeset
    93
    "(cut f r x = cut g r x) = (!y. (y,x):r --> f(y)=g(y))";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1485
diff changeset
    94
by (simp_tac (HOL_ss addsimps [expand_fun_eq]
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
    95
                    setloop (split_tac [expand_if])) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
    96
qed "cuts_eq";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 950
diff changeset
    98
goalw WF.thy [cut_def] "!!x. (x,a):r ==> (cut f r a)(x) = f(x)";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1485
diff changeset
    99
by (asm_simp_tac HOL_ss 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
qed "cut_apply";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   102
(*** is_recfun ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   103
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   104
goalw WF.thy [is_recfun_def,cut_def]
3320
3a5e4930fb77 Added `arbitrary'
nipkow
parents: 3198
diff changeset
   105
    "!!f. [| is_recfun r H a f;  ~(b,a):r |] ==> f(b) = arbitrary";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
by (etac ssubst 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1485
diff changeset
   107
by (asm_simp_tac HOL_ss 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   108
qed "is_recfun_undef";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   109
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   110
(*** NOTE! some simplifications need a different finish_tac!! ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
fun indhyp_tac hyps =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   112
    (cut_facts_tac hyps THEN'
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   113
       DEPTH_SOLVE_1 o (ares_tac [TrueI] ORELSE'
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
   114
                        eresolve_tac [transD, mp, allE]));
2637
e9b203f854ae reflecting my recent changes of the simplifier and classical reasoner
oheimb
parents: 2031
diff changeset
   115
val wf_super_ss = HOL_ss addSolver indhyp_tac;
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   116
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   117
val prems = goalw WF.thy [is_recfun_def,cut_def]
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   118
    "[| wf(r);  trans(r);  is_recfun r H a f;  is_recfun r H b g |] ==> \
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 950
diff changeset
   119
    \ (x,a):r --> (x,b):r --> f(x)=g(x)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   120
by (cut_facts_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   121
by (etac wf_induct 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   122
by (REPEAT (rtac impI 1 ORELSE etac ssubst 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   123
by (asm_simp_tac (wf_super_ss addcongs [if_cong]) 1);
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   124
qed_spec_mp "is_recfun_equal";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   125
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   126
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   127
val prems as [wfr,transr,recfa,recgb,_] = goalw WF.thy [cut_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   128
    "[| wf(r);  trans(r); \
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   129
\       is_recfun r H a f;  is_recfun r H b g;  (b,a):r |] ==> \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   130
\    cut f r b = g";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   131
val gundef = recgb RS is_recfun_undef
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   132
and fisg   = recgb RS (recfa RS (transr RS (wfr RS is_recfun_equal)));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   133
by (cut_facts_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   134
by (rtac ext 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
by (asm_simp_tac (wf_super_ss addsimps [gundef,fisg]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   136
                              setloop (split_tac [expand_if])) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
qed "is_recfun_cut";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
(*** Main Existence Lemma -- Basic Properties of the_recfun ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   140
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
val prems = goalw WF.thy [the_recfun_def]
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   142
    "is_recfun r H a f ==> is_recfun r H a (the_recfun r H a)";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   143
by (res_inst_tac [("P", "is_recfun r H a")] selectI 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   144
by (resolve_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   145
qed "is_the_recfun";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   146
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   147
val prems = goal WF.thy
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   148
 "[| wf(r);  trans(r) |] ==> is_recfun r H a (the_recfun r H a)";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   149
  by (cut_facts_tac prems 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   150
  by (wf_ind_tac "a" prems 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   151
  by (res_inst_tac [("f","cut (%y. H (the_recfun r H y) y) r a1")]
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   152
                   is_the_recfun 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1485
diff changeset
   153
  by (rewtac is_recfun_def);
2031
03a843f0f447 Ran expandshort
paulson
parents: 1786
diff changeset
   154
  by (stac cuts_eq 1);
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   155
  by (rtac allI 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   156
  by (rtac impI 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   157
  by (res_inst_tac [("f1","H"),("x","y")](arg_cong RS fun_cong) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   158
  by (subgoal_tac
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   159
         "the_recfun r H y = cut(%x. H(cut(the_recfun r H y) r x) x) r y" 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   160
  by (etac allE 2);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   161
  by (dtac impE 2);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   162
  by (atac 2);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   163
  by (atac 3);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   164
  by (atac 2);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   165
  by (etac ssubst 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   166
  by (simp_tac (HOL_ss addsimps [cuts_eq]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   167
  by (rtac allI 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   168
  by (rtac impI 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   169
  by (asm_simp_tac (wf_super_ss addsimps[cut_apply,is_recfun_cut,cuts_eq]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   170
  by (res_inst_tac [("f1","H"),("x","ya")](arg_cong RS fun_cong) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   171
  by (fold_tac [is_recfun_def]);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   172
  by (asm_simp_tac (wf_super_ss addsimps[cut_apply,is_recfun_cut,cuts_eq]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   173
qed "unfold_the_recfun";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   174
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   175
val unwind1_the_recfun = rewrite_rule[is_recfun_def] unfold_the_recfun;
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   176
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   177
(*--------------Old proof-----------------------------------------------------
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   178
val prems = goal WF.thy
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   179
    "[| wf(r);  trans(r) |] ==> is_recfun r H a (the_recfun r H a)";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   180
by (cut_facts_tac prems 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   181
by (wf_ind_tac "a" prems 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   182
by (res_inst_tac [("f", "cut (%y. wftrec r H y) r a1")] is_the_recfun 1); 
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   183
by (rewrite_goals_tac [is_recfun_def, wftrec_def]);
2031
03a843f0f447 Ran expandshort
paulson
parents: 1786
diff changeset
   184
by (stac cuts_eq 1);
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   185
(*Applying the substitution: must keep the quantified assumption!!*)
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   186
by (EVERY1 [strip_tac, rtac H_cong1, rtac allE, atac,
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   187
            etac (mp RS ssubst), atac]); 
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   188
by (fold_tac [is_recfun_def]);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   189
by (asm_simp_tac (wf_super_ss addsimps[cut_apply,is_recfun_cut,cuts_eq]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   190
qed "unfold_the_recfun";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   191
---------------------------------------------------------------------------*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   192
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   193
(** Removal of the premise trans(r) **)
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   194
val th = rewrite_rule[is_recfun_def]
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   195
                     (trans_trancl RSN (2,(wf_trancl RS unfold_the_recfun)));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   196
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   197
goalw WF.thy [wfrec_def]
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   198
    "!!r. wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   199
by (rtac H_cong 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   200
by (rtac refl 2);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   201
by (simp_tac (HOL_ss addsimps [cuts_eq]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   202
by (rtac allI 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   203
by (rtac impI 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   204
by (simp_tac(HOL_ss addsimps [wfrec_def]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   205
by (res_inst_tac [("a1","a")] (th RS ssubst) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   206
by (atac 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   207
by (forward_tac[wf_trancl] 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   208
by (forward_tac[r_into_trancl] 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   209
by (asm_simp_tac (HOL_ss addsimps [cut_apply]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   210
by (rtac H_cong 1);    (*expose the equality of cuts*)
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   211
by (rtac refl 2);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   212
by (simp_tac (HOL_ss addsimps [cuts_eq, cut_apply, r_into_trancl]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   213
by (strip_tac 1);
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   214
by (res_inst_tac [("r","r^+")] is_recfun_equal 1);
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   215
by (atac 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   216
by (rtac trans_trancl 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   217
by (rtac unfold_the_recfun 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   218
by (atac 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   219
by (rtac trans_trancl 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   220
by (rtac unfold_the_recfun 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   221
by (atac 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   222
by (rtac trans_trancl 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   223
by (rtac transD 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   224
by (rtac trans_trancl 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   225
by (forw_inst_tac [("a","ya")] r_into_trancl 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   226
by (atac 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   227
by (atac 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   228
by (forw_inst_tac [("a","ya")] r_into_trancl 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   229
by (atac 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   230
qed "wfrec";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   231
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   232
(*--------------Old proof-----------------------------------------------------
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   233
goalw WF.thy [wfrec_def]
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   234
    "!!r. wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   235
by (etac (wf_trancl RS wftrec RS ssubst) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   236
by (rtac trans_trancl 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   237
by (rtac (refl RS H_cong) 1);    (*expose the equality of cuts*)
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   238
by (simp_tac (HOL_ss addsimps [cuts_eq, cut_apply, r_into_trancl]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   239
qed "wfrec";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   240
---------------------------------------------------------------------------*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   241
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   242
(*---------------------------------------------------------------------------
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   243
 * This form avoids giant explosions in proofs.  NOTE USE OF == 
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   244
 *---------------------------------------------------------------------------*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   245
val rew::prems = goal WF.thy
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   246
    "[| f==wfrec r H;  wf(r) |] ==> f(a) = H (cut f r a) a";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   247
by (rewtac rew);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   248
by (REPEAT (resolve_tac (prems@[wfrec]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   249
qed "def_wfrec";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   250
3198
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   251
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   252
(**** TFL variants ****)
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   253
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   254
goal WF.thy
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   255
    "!R. wf R --> (!P. (!x. (!y. (y,x):R --> P y) --> P x) --> (!x. P x))";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   256
by (strip_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   257
by (res_inst_tac [("r","R"),("P","P"), ("a","x")] wf_induct 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   258
by (assume_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   259
by (Blast_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   260
qed"tfl_wf_induct";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   261
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   262
goal WF.thy "!f R. (x,a):R --> (cut f R a)(x) = f(x)";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   263
by (strip_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   264
by (rtac cut_apply 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   265
by (assume_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   266
qed"tfl_cut_apply";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   267
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   268
goal WF.thy "!M R f. (f=wfrec R M) --> wf R --> (!x. f x = M (cut f R x) x)";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   269
by (strip_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   270
by (res_inst_tac [("r","R"), ("H","M"),
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   271
                  ("a","x"), ("f","f")] (eq_reflection RS def_wfrec) 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   272
by (assume_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   273
by (assume_tac 1);
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   274
qed "tfl_wfrec";
295287618e30 New proofs for TFL
paulson
parents: 2935
diff changeset
   275