src/CCL/Wfd.thy
author haftmann
Tue, 17 Aug 2010 19:36:39 +0200
changeset 38500 d5477ee35820
parent 36319 8feb2c4bef1a
child 41526 54b4686704af
permissions -rw-r--r--
more antiquotations
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     1
(*  Title:      CCL/Wfd.thy
1474
3f7d67927fe2 expanded tabs
clasohm
parents: 289
diff changeset
     2
    Author:     Martin Coen, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Copyright   1993  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     6
header {* Well-founded relations in CCL *}
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     7
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     8
theory Wfd
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     9
imports Trancl Type Hered
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    10
begin
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
consts
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
      (*** Predicates ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
  Wfd        ::       "[i set] => o"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
      (*** Relations ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
  wf         ::       "[i set] => i set"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
  wmap       ::       "[i=>i,i set] => i set"
24825
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 24034
diff changeset
    18
  lex        ::       "[i set,i set] => i set"      (infixl "**" 70)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
  NatPR      ::       "i set"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
  ListPR     ::       "i set => i set"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
24825
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 24034
diff changeset
    22
defs
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    24
  Wfd_def:
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1474
diff changeset
    25
  "Wfd(R) == ALL P.(ALL x.(ALL y.<y,x> : R --> y:P) --> x:P) --> (ALL a. a:P)"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    27
  wf_def:         "wf(R) == {x. x:R & Wfd(R)}"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    29
  wmap_def:       "wmap(f,R) == {p. EX x y. p=<x,y>  &  <f(x),f(y)> : R}"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    30
  lex_def:
3837
d7f033c74b38 fixed dots;
wenzelm
parents: 1474
diff changeset
    31
  "ra**rb == {p. EX a a' b b'. p = <<a,b>,<a',b'>> & (<a,a'> : ra | (a=a' & <b,b'> : rb))}"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    33
  NatPR_def:      "NatPR == {p. EX x:Nat. p=<x,succ(x)>}"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    34
  ListPR_def:     "ListPR(A) == {p. EX h:A. EX t:List(A). p=<t,h$t>}"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    35
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    36
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    37
lemma wfd_induct:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    38
  assumes 1: "Wfd(R)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    39
    and 2: "!!x.[| ALL y. <y,x>: R --> P(y) |] ==> P(x)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    40
  shows "P(a)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    41
  apply (rule 1 [unfolded Wfd_def, rule_format, THEN CollectD])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    42
  using 2 apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    43
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    44
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    45
lemma wfd_strengthen_lemma:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    46
  assumes 1: "!!x y.<x,y> : R ==> Q(x)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    47
    and 2: "ALL x. (ALL y. <y,x> : R --> y : P) --> x : P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    48
    and 3: "!!x. Q(x) ==> x:P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    49
  shows "a:P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    50
  apply (rule 2 [rule_format])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    51
  using 1 3
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    52
  apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    53
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    54
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    55
ML {*
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
    56
  fun wfd_strengthen_tac ctxt s i =
27239
f2f42f9fa09d pervasive RuleInsts;
wenzelm
parents: 27221
diff changeset
    57
    res_inst_tac ctxt [(("Q", 0), s)] @{thm wfd_strengthen_lemma} i THEN assume_tac (i+1)
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    58
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    59
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    60
lemma wf_anti_sym: "[| Wfd(r);  <a,x>:r;  <x,a>:r |] ==> P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    61
  apply (subgoal_tac "ALL x. <a,x>:r --> <x,a>:r --> P")
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    62
   apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    63
  apply (erule wfd_induct)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    64
  apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    65
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    66
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    67
lemma wf_anti_refl: "[| Wfd(r);  <a,a>: r |] ==> P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    68
  apply (rule wf_anti_sym)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    69
  apply assumption+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    70
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    71
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    72
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    73
subsection {* Irreflexive transitive closure *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    74
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    75
lemma trancl_wf:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    76
  assumes 1: "Wfd(R)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    77
  shows "Wfd(R^+)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    78
  apply (unfold Wfd_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    79
  apply (rule allI ballI impI)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    80
(*must retain the universal formula for later use!*)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    81
  apply (rule allE, assumption)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    82
  apply (erule mp)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    83
  apply (rule 1 [THEN wfd_induct])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    84
  apply (rule impI [THEN allI])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    85
  apply (erule tranclE)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    86
   apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    87
  apply (erule spec [THEN mp, THEN spec, THEN mp])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    88
   apply assumption+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    89
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    90
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    91
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    92
subsection {* Lexicographic Ordering *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    93
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    94
lemma lexXH:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    95
  "p : ra**rb <-> (EX a a' b b'. p = <<a,b>,<a',b'>> & (<a,a'> : ra | a=a' & <b,b'> : rb))"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    96
  unfolding lex_def by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    97
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    98
lemma lexI1: "<a,a'> : ra ==> <<a,b>,<a',b'>> : ra**rb"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    99
  by (blast intro!: lexXH [THEN iffD2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   100
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   101
lemma lexI2: "<b,b'> : rb ==> <<a,b>,<a,b'>> : ra**rb"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   102
  by (blast intro!: lexXH [THEN iffD2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   103
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   104
lemma lexE:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   105
  assumes 1: "p : ra**rb"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   106
    and 2: "!!a a' b b'.[| <a,a'> : ra; p=<<a,b>,<a',b'>> |] ==> R"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   107
    and 3: "!!a b b'.[| <b,b'> : rb;  p = <<a,b>,<a,b'>> |] ==> R"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   108
  shows R
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   109
  apply (rule 1 [THEN lexXH [THEN iffD1], THEN exE])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   110
  using 2 3
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   111
  apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   112
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   113
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   114
lemma lex_pair: "[| p : r**s;  !!a a' b b'. p = <<a,b>,<a',b'>> ==> P |] ==>P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   115
  apply (erule lexE)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   116
   apply blast+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   117
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   118
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   119
lemma lex_wf:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   120
  assumes 1: "Wfd(R)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   121
    and 2: "Wfd(S)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   122
  shows "Wfd(R**S)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   123
  apply (unfold Wfd_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   124
  apply safe
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   125
  apply (tactic {* wfd_strengthen_tac @{context} "%x. EX a b. x=<a,b>" 1 *})
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   126
   apply (blast elim!: lex_pair)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   127
  apply (subgoal_tac "ALL a b.<a,b>:P")
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   128
   apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   129
  apply (rule 1 [THEN wfd_induct, THEN allI])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   130
  apply (rule 2 [THEN wfd_induct, THEN allI]) back
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   131
  apply (fast elim!: lexE)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   132
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   133
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   134
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   135
subsection {* Mapping *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   136
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   137
lemma wmapXH: "p : wmap(f,r) <-> (EX x y. p=<x,y>  &  <f(x),f(y)> : r)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   138
  unfolding wmap_def by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   139
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   140
lemma wmapI: "<f(a),f(b)> : r ==> <a,b> : wmap(f,r)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   141
  by (blast intro!: wmapXH [THEN iffD2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   142
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   143
lemma wmapE: "[| p : wmap(f,r);  !!a b.[| <f(a),f(b)> : r;  p=<a,b> |] ==> R |] ==> R"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   144
  by (blast dest!: wmapXH [THEN iffD1])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   145
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   146
lemma wmap_wf:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   147
  assumes 1: "Wfd(r)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   148
  shows "Wfd(wmap(f,r))"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   149
  apply (unfold Wfd_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   150
  apply clarify
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   151
  apply (subgoal_tac "ALL b. ALL a. f (a) =b-->a:P")
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   152
   apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   153
  apply (rule 1 [THEN wfd_induct, THEN allI])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   154
  apply clarify
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   155
  apply (erule spec [THEN mp])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   156
  apply (safe elim!: wmapE)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   157
  apply (erule spec [THEN mp, THEN spec, THEN mp])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   158
   apply assumption
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   159
   apply (rule refl)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   160
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   161
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   162
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   163
subsection {* Projections *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   164
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   165
lemma wfstI: "<xa,ya> : r ==> <<xa,xb>,<ya,yb>> : wmap(fst,r)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   166
  apply (rule wmapI)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   167
  apply simp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   168
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   169
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   170
lemma wsndI: "<xb,yb> : r ==> <<xa,xb>,<ya,yb>> : wmap(snd,r)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   171
  apply (rule wmapI)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   172
  apply simp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   173
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   174
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   175
lemma wthdI: "<xc,yc> : r ==> <<xa,<xb,xc>>,<ya,<yb,yc>>> : wmap(thd,r)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   176
  apply (rule wmapI)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   177
  apply simp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   178
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   179
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   180
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   181
subsection {* Ground well-founded relations *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   182
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   183
lemma wfI: "[| Wfd(r);  a : r |] ==> a : wf(r)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   184
  unfolding wf_def by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   185
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   186
lemma Empty_wf: "Wfd({})"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   187
  unfolding Wfd_def by (blast elim: EmptyXH [THEN iffD1, THEN FalseE])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   188
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   189
lemma wf_wf: "Wfd(wf(R))"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   190
  unfolding wf_def
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   191
  apply (rule_tac Q = "Wfd(R)" in excluded_middle [THEN disjE])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   192
   apply simp_all
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   193
  apply (rule Empty_wf)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   194
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   195
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   196
lemma NatPRXH: "p : NatPR <-> (EX x:Nat. p=<x,succ(x)>)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   197
  unfolding NatPR_def by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   198
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   199
lemma ListPRXH: "p : ListPR(A) <-> (EX h:A. EX t:List(A).p=<t,h$t>)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   200
  unfolding ListPR_def by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   201
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   202
lemma NatPRI: "x : Nat ==> <x,succ(x)> : NatPR"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   203
  by (auto simp: NatPRXH)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   204
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   205
lemma ListPRI: "[| t : List(A); h : A |] ==> <t,h $ t> : ListPR(A)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   206
  by (auto simp: ListPRXH)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   207
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   208
lemma NatPR_wf: "Wfd(NatPR)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   209
  apply (unfold Wfd_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   210
  apply clarify
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   211
  apply (tactic {* wfd_strengthen_tac @{context} "%x. x:Nat" 1 *})
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   212
   apply (fastsimp iff: NatPRXH)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   213
  apply (erule Nat_ind)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   214
   apply (fastsimp iff: NatPRXH)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   215
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   216
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   217
lemma ListPR_wf: "Wfd(ListPR(A))"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   218
  apply (unfold Wfd_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   219
  apply clarify
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   220
  apply (tactic {* wfd_strengthen_tac @{context} "%x. x:List (A)" 1 *})
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   221
   apply (fastsimp iff: ListPRXH)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   222
  apply (erule List_ind)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   223
   apply (fastsimp iff: ListPRXH)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   224
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   225
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   226
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   227
subsection {* General Recursive Functions *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   228
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   229
lemma letrecT:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   230
  assumes 1: "a : A"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   231
    and 2: "!!p g.[| p:A; ALL x:{x: A. <x,p>:wf(R)}. g(x) : D(x) |] ==> h(p,g) : D(p)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   232
  shows "letrec g x be h(x,g) in g(a) : D(a)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   233
  apply (rule 1 [THEN rev_mp])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   234
  apply (rule wf_wf [THEN wfd_induct])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   235
  apply (subst letrecB)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   236
  apply (rule impI)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   237
  apply (erule 2)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   238
  apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   239
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   240
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   241
lemma SPLITB: "SPLIT(<a,b>,B) = B(a,b)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   242
  unfolding SPLIT_def
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   243
  apply (rule set_ext)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   244
  apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   245
  done
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
   246
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   247
lemma letrec2T:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   248
  assumes "a : A"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   249
    and "b : B"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   250
    and "!!p q g.[| p:A; q:B;
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   251
              ALL x:A. ALL y:{y: B. <<x,y>,<p,q>>:wf(R)}. g(x,y) : D(x,y) |] ==> 
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   252
                h(p,q,g) : D(p,q)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   253
  shows "letrec g x y be h(x,y,g) in g(a,b) : D(a,b)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   254
  apply (unfold letrec2_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   255
  apply (rule SPLITB [THEN subst])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   256
  apply (assumption | rule letrecT pairT splitT prems)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   257
  apply (subst SPLITB)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   258
  apply (assumption | rule ballI SubtypeI prems)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   259
  apply (rule SPLITB [THEN subst])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   260
  apply (assumption | rule letrecT SubtypeI pairT splitT prems |
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   261
    erule bspec SubtypeE sym [THEN subst])+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   262
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   263
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   264
lemma lem: "SPLIT(<a,<b,c>>,%x xs. SPLIT(xs,%y z. B(x,y,z))) = B(a,b,c)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   265
  by (simp add: SPLITB)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   266
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   267
lemma letrec3T:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   268
  assumes "a : A"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   269
    and "b : B"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   270
    and "c : C"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   271
    and "!!p q r g.[| p:A; q:B; r:C;
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   272
       ALL x:A. ALL y:B. ALL z:{z:C. <<x,<y,z>>,<p,<q,r>>> : wf(R)}.  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   273
                                                        g(x,y,z) : D(x,y,z) |] ==> 
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   274
                h(p,q,r,g) : D(p,q,r)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   275
  shows "letrec g x y z be h(x,y,z,g) in g(a,b,c) : D(a,b,c)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   276
  apply (unfold letrec3_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   277
  apply (rule lem [THEN subst])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   278
  apply (assumption | rule letrecT pairT splitT prems)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   279
  apply (simp add: SPLITB)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   280
  apply (assumption | rule ballI SubtypeI prems)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   281
  apply (rule lem [THEN subst])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   282
  apply (assumption | rule letrecT SubtypeI pairT splitT prems |
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   283
    erule bspec SubtypeE sym [THEN subst])+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   284
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   285
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   286
lemmas letrecTs = letrecT letrec2T letrec3T
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   287
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   288
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   289
subsection {* Type Checking for Recursive Calls *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   290
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   291
lemma rcallT:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   292
  "[| ALL x:{x:A.<x,p>:wf(R)}.g(x):D(x);  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   293
      g(a) : D(a) ==> g(a) : E;  a:A;  <a,p>:wf(R) |] ==>  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   294
  g(a) : E"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   295
  by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   296
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   297
lemma rcall2T:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   298
  "[| ALL x:A. ALL y:{y:B.<<x,y>,<p,q>>:wf(R)}.g(x,y):D(x,y);  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   299
      g(a,b) : D(a,b) ==> g(a,b) : E;  a:A;  b:B;  <<a,b>,<p,q>>:wf(R) |] ==>  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   300
  g(a,b) : E"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   301
  by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   302
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   303
lemma rcall3T:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   304
  "[| ALL x:A. ALL y:B. ALL z:{z:C.<<x,<y,z>>,<p,<q,r>>>:wf(R)}. g(x,y,z):D(x,y,z);  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   305
      g(a,b,c) : D(a,b,c) ==> g(a,b,c) : E;   
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   306
      a:A;  b:B;  c:C;  <<a,<b,c>>,<p,<q,r>>> : wf(R) |] ==>  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   307
  g(a,b,c) : E"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   308
  by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   309
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   310
lemmas rcallTs = rcallT rcall2T rcall3T
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   311
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   312
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   313
subsection {* Instantiating an induction hypothesis with an equality assumption *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   314
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   315
lemma hyprcallT:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   316
  assumes 1: "g(a) = b"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   317
    and 2: "ALL x:{x:A.<x,p>:wf(R)}.g(x):D(x)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   318
    and 3: "ALL x:{x:A.<x,p>:wf(R)}.g(x):D(x) ==> b=g(a) ==> g(a) : D(a) ==> P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   319
    and 4: "ALL x:{x:A.<x,p>:wf(R)}.g(x):D(x) ==> a:A"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   320
    and 5: "ALL x:{x:A.<x,p>:wf(R)}.g(x):D(x) ==> <a,p>:wf(R)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   321
  shows P
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   322
  apply (rule 3 [OF 2, OF 1 [symmetric]])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   323
  apply (rule rcallT [OF 2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   324
    apply assumption
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   325
   apply (rule 4 [OF 2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   326
  apply (rule 5 [OF 2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   327
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   328
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   329
lemma hyprcall2T:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   330
  assumes 1: "g(a,b) = c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   331
    and 2: "ALL x:A. ALL y:{y:B.<<x,y>,<p,q>>:wf(R)}.g(x,y):D(x,y)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   332
    and 3: "[| c=g(a,b);  g(a,b) : D(a,b) |] ==> P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   333
    and 4: "a:A"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   334
    and 5: "b:B"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   335
    and 6: "<<a,b>,<p,q>>:wf(R)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   336
  shows P
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   337
  apply (rule 3)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   338
    apply (rule 1 [symmetric])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   339
  apply (rule rcall2T)
23467
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   340
      apply (rule 2)
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   341
     apply assumption
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   342
    apply (rule 4)
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   343
   apply (rule 5)
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   344
  apply (rule 6)
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   345
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   346
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   347
lemma hyprcall3T:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   348
  assumes 1: "g(a,b,c) = d"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   349
    and 2: "ALL x:A. ALL y:B. ALL z:{z:C.<<x,<y,z>>,<p,<q,r>>>:wf(R)}.g(x,y,z):D(x,y,z)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   350
    and 3: "[| d=g(a,b,c);  g(a,b,c) : D(a,b,c) |] ==> P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   351
    and 4: "a:A"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   352
    and 5: "b:B"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   353
    and 6: "c:C"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   354
    and 7: "<<a,<b,c>>,<p,<q,r>>> : wf(R)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   355
  shows P
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   356
  apply (rule 3)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   357
   apply (rule 1 [symmetric])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   358
  apply (rule rcall3T)
23467
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   359
       apply (rule 2)
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   360
      apply assumption
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   361
     apply (rule 4)
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   362
    apply (rule 5)
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   363
   apply (rule 6)
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22846
diff changeset
   364
  apply (rule 7)
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   365
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   366
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   367
lemmas hyprcallTs = hyprcallT hyprcall2T hyprcall3T
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   368
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   369
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   370
subsection {* Rules to Remove Induction Hypotheses after Type Checking *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   371
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   372
lemma rmIH1: "[| ALL x:{x:A.<x,p>:wf(R)}.g(x):D(x); P |] ==> P" .
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   373
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   374
lemma rmIH2: "[| ALL x:A. ALL y:{y:B.<<x,y>,<p,q>>:wf(R)}.g(x,y):D(x,y); P |] ==> P" .
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   375
  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   376
lemma rmIH3:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   377
 "[| ALL x:A. ALL y:B. ALL z:{z:C.<<x,<y,z>>,<p,<q,r>>>:wf(R)}.g(x,y,z):D(x,y,z);  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   378
     P |] ==>  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   379
     P" .
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   380
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   381
lemmas rmIHs = rmIH1 rmIH2 rmIH3
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   382
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   383
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   384
subsection {* Lemmas for constructors and subtypes *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   385
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   386
(* 0-ary constructors do not need additional rules as they are handled *)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   387
(*                                      correctly by applying SubtypeI *)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   388
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   389
lemma Subtype_canTs:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   390
  "!!a b A B P. a : {x:A. b:{y:B(a).P(<x,y>)}} ==> <a,b> : {x:Sigma(A,B).P(x)}"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   391
  "!!a A B P. a : {x:A. P(inl(x))} ==> inl(a) : {x:A+B. P(x)}"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   392
  "!!b A B P. b : {x:B. P(inr(x))} ==> inr(b) : {x:A+B. P(x)}"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   393
  "!!a P. a : {x:Nat. P(succ(x))} ==> succ(a) : {x:Nat. P(x)}"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   394
  "!!h t A P. h : {x:A. t : {y:List(A).P(x$y)}} ==> h$t : {x:List(A).P(x)}"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   395
  by (assumption | rule SubtypeI canTs icanTs | erule SubtypeE)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   396
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   397
lemma letT: "[| f(t):B;  ~t=bot  |] ==> let x be t in f(x) : B"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   398
  apply (erule letB [THEN ssubst])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   399
  apply assumption
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   400
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   401
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   402
lemma applyT2: "[| a:A;  f : Pi(A,B)  |] ==> f ` a  : B(a)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   403
  apply (erule applyT)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   404
  apply assumption
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   405
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   406
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   407
lemma rcall_lemma1: "[| a:A;  a:A ==> P(a) |] ==> a : {x:A. P(x)}"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   408
  by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   409
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   410
lemma rcall_lemma2: "[| a:{x:A. Q(x)};  [| a:A; Q(a) |] ==> P(a) |] ==> a : {x:A. P(x)}"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   411
  by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   412
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   413
lemmas rcall_lemmas = asm_rl rcall_lemma1 SubtypeD1 rcall_lemma2
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   414
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   415
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   416
subsection {* Typechecking *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   417
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   418
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   419
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   420
local
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   421
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   422
val type_rls =
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   423
  @{thms canTs} @ @{thms icanTs} @ @{thms applyT2} @ @{thms ncanTs} @ @{thms incanTs} @
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   424
  @{thms precTs} @ @{thms letrecTs} @ @{thms letT} @ @{thms Subtype_canTs};
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   425
38500
d5477ee35820 more antiquotations
haftmann
parents: 36319
diff changeset
   426
fun bvars (Const(@{const_name all},_) $ Abs(s,_,t)) l = bvars t (s::l)
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   427
  | bvars _ l = l
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   428
38500
d5477ee35820 more antiquotations
haftmann
parents: 36319
diff changeset
   429
fun get_bno l n (Const(@{const_name all},_) $ Abs(s,_,t)) = get_bno (s::l) n t
d5477ee35820 more antiquotations
haftmann
parents: 36319
diff changeset
   430
  | get_bno l n (Const(@{const_name Trueprop},_) $ t) = get_bno l n t
d5477ee35820 more antiquotations
haftmann
parents: 36319
diff changeset
   431
  | get_bno l n (Const(@{const_name Ball},_) $ _ $ Abs(s,_,t)) = get_bno (s::l) (n+1) t
d5477ee35820 more antiquotations
haftmann
parents: 36319
diff changeset
   432
  | get_bno l n (Const(@{const_name mem},_) $ t $ _) = get_bno l n t
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   433
  | get_bno l n (t $ s) = get_bno l n t
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   434
  | get_bno l n (Bound m) = (m-length(l),n)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   435
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   436
(* Not a great way of identifying induction hypothesis! *)
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents: 29264
diff changeset
   437
fun could_IH x = Term.could_unify(x,hd (prems_of @{thm rcallT})) orelse
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents: 29264
diff changeset
   438
                 Term.could_unify(x,hd (prems_of @{thm rcall2T})) orelse
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents: 29264
diff changeset
   439
                 Term.could_unify(x,hd (prems_of @{thm rcall3T}))
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   440
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   441
fun IHinst tac rls = SUBGOAL (fn (Bi,i) =>
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   442
  let val bvs = bvars Bi []
33317
b4534348b8fd standardized filter/filter_out;
wenzelm
parents: 32283
diff changeset
   443
      val ihs = filter could_IH (Logic.strip_assums_hyp Bi)
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   444
      val rnames = map (fn x=>
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   445
                    let val (a,b) = get_bno [] 0 x
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   446
                    in (List.nth(bvs,a),b) end) ihs
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   447
      fun try_IHs [] = no_tac
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   448
        | try_IHs ((x,y)::xs) = tac [(("g", 0), x)] (List.nth(rls,y-1)) i ORELSE (try_IHs xs)
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   449
  in try_IHs rnames end)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   450
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   451
fun is_rigid_prog t =
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   452
     case (Logic.strip_assums_concl t) of
38500
d5477ee35820 more antiquotations
haftmann
parents: 36319
diff changeset
   453
        (Const(@{const_name Trueprop},_) $ (Const(@{const_name mem},_) $ a $ _)) => null (Term.add_vars a [])
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   454
       | _ => false
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   455
in
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   456
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   457
fun rcall_tac ctxt i =
27239
f2f42f9fa09d pervasive RuleInsts;
wenzelm
parents: 27221
diff changeset
   458
  let fun tac ps rl i = res_inst_tac ctxt ps rl i THEN atac i
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   459
  in IHinst tac @{thms rcallTs} i end
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   460
  THEN eresolve_tac @{thms rcall_lemmas} i
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   461
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   462
fun raw_step_tac ctxt prems i = ares_tac (prems@type_rls) i ORELSE
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   463
                           rcall_tac ctxt i ORELSE
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   464
                           ematch_tac [@{thm SubtypeE}] i ORELSE
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   465
                           match_tac [@{thm SubtypeI}] i
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   466
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   467
fun tc_step_tac ctxt prems = SUBGOAL (fn (Bi,i) =>
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   468
          if is_rigid_prog Bi then raw_step_tac ctxt prems i else no_tac)
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   469
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   470
fun typechk_tac ctxt rls i = SELECT_GOAL (REPEAT_FIRST (tc_step_tac ctxt rls)) i
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   471
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   472
fun tac ctxt = typechk_tac ctxt [] 1
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   473
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   474
(*** Clean up Correctness Condictions ***)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   475
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   476
val clean_ccs_tac = REPEAT_FIRST (eresolve_tac ([@{thm SubtypeE}] @ @{thms rmIHs}) ORELSE'
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   477
                                 hyp_subst_tac)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   478
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   479
fun clean_ccs_tac ctxt =
27239
f2f42f9fa09d pervasive RuleInsts;
wenzelm
parents: 27221
diff changeset
   480
  let fun tac ps rl i = eres_inst_tac ctxt ps rl i THEN atac i in
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   481
    TRY (REPEAT_FIRST (IHinst tac @{thms hyprcallTs} ORELSE'
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   482
    eresolve_tac ([asm_rl, @{thm SubtypeE}] @ @{thms rmIHs}) ORELSE'
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   483
    hyp_subst_tac))
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   484
  end
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   485
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   486
fun gen_ccs_tac ctxt rls i =
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27208
diff changeset
   487
  SELECT_GOAL (REPEAT_FIRST (tc_step_tac ctxt rls) THEN clean_ccs_tac ctxt) i
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
   488
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   489
end
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   490
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   491
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   492
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   493
subsection {* Evaluation *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   494
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   495
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   496
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   497
local
31902
862ae16a799d renamed NamedThmsFun to Named_Thms;
wenzelm
parents: 30515
diff changeset
   498
  structure Data = Named_Thms(val name = "eval" val description = "evaluation rules");
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   499
in
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   500
32282
853ef99c04cc FOCUS_PREMS as full replacement for METAHYPS, where the conclusion may still contain schematic variables;
wenzelm
parents: 32211
diff changeset
   501
fun eval_tac ths =
32283
3bebc195c124 qualified Subgoal.FOCUS;
wenzelm
parents: 32282
diff changeset
   502
  Subgoal.FOCUS_PREMS (fn {context, prems, ...} =>
32282
853ef99c04cc FOCUS_PREMS as full replacement for METAHYPS, where the conclusion may still contain schematic variables;
wenzelm
parents: 32211
diff changeset
   503
    DEPTH_SOLVE_1 (resolve_tac (ths @ prems @ Data.get context) 1));
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   504
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   505
val eval_setup =
24034
ef0789aa7cbe simplified "eval" setup via NamedThmsFun;
wenzelm
parents: 23467
diff changeset
   506
  Data.setup #>
30515
bca05b17b618 simplified method setup;
wenzelm
parents: 30510
diff changeset
   507
  Method.setup @{binding eval}
32282
853ef99c04cc FOCUS_PREMS as full replacement for METAHYPS, where the conclusion may still contain schematic variables;
wenzelm
parents: 32211
diff changeset
   508
    (Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD' (CHANGED o eval_tac ths ctxt)))
30515
bca05b17b618 simplified method setup;
wenzelm
parents: 30510
diff changeset
   509
    "evaluation";
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   510
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   511
end;
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   512
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   513
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   514
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   515
setup eval_setup
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   516
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   517
lemmas eval_rls [eval] = trueV falseV pairV lamV caseVtrue caseVfalse caseVpair caseVlam
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   518
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   519
lemma applyV [eval]:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   520
  assumes "f ---> lam x. b(x)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   521
    and "b(a) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   522
  shows "f ` a ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   523
  unfolding apply_def by (eval prems)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   524
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   525
lemma letV:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   526
  assumes 1: "t ---> a"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   527
    and 2: "f(a) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   528
  shows "let x be t in f(x) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   529
  apply (unfold let_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   530
  apply (rule 1 [THEN canonical])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   531
  apply (tactic {*
26391
6e8aa5a4eb82 more antiquotations;
wenzelm
parents: 24825
diff changeset
   532
    REPEAT (DEPTH_SOLVE_1 (resolve_tac (@{thms assms} @ @{thms eval_rls}) 1 ORELSE
6e8aa5a4eb82 more antiquotations;
wenzelm
parents: 24825
diff changeset
   533
      etac @{thm substitute} 1)) *})
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   534
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   535
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   536
lemma fixV: "f(fix(f)) ---> c ==> fix(f) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   537
  apply (unfold fix_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   538
  apply (rule applyV)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   539
   apply (rule lamV)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   540
  apply assumption
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   541
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   542
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   543
lemma letrecV:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   544
  "h(t,%y. letrec g x be h(x,g) in g(y)) ---> c ==>  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   545
                 letrec g x be h(x,g) in g(t) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   546
  apply (unfold letrec_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   547
  apply (assumption | rule fixV applyV  lamV)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   548
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   549
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   550
lemmas [eval] = letV letrecV fixV
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   551
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   552
lemma V_rls [eval]:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   553
  "true ---> true"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   554
  "false ---> false"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   555
  "!!b c t u. [| b--->true;  t--->c |] ==> if b then t else u ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   556
  "!!b c t u. [| b--->false;  u--->c |] ==> if b then t else u ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   557
  "!!a b. <a,b> ---> <a,b>"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   558
  "!!a b c t h. [| t ---> <a,b>;  h(a,b) ---> c |] ==> split(t,h) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   559
  "zero ---> zero"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   560
  "!!n. succ(n) ---> succ(n)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   561
  "!!c n t u. [| n ---> zero; t ---> c |] ==> ncase(n,t,u) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   562
  "!!c n t u x. [| n ---> succ(x); u(x) ---> c |] ==> ncase(n,t,u) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   563
  "!!c n t u. [| n ---> zero; t ---> c |] ==> nrec(n,t,u) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   564
  "!!c n t u x. [| n--->succ(x); u(x,nrec(x,t,u))--->c |] ==> nrec(n,t,u)--->c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   565
  "[] ---> []"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   566
  "!!h t. h$t ---> h$t"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   567
  "!!c l t u. [| l ---> []; t ---> c |] ==> lcase(l,t,u) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   568
  "!!c l t u x xs. [| l ---> x$xs; u(x,xs) ---> c |] ==> lcase(l,t,u) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   569
  "!!c l t u. [| l ---> []; t ---> c |] ==> lrec(l,t,u) ---> c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   570
  "!!c l t u x xs. [| l--->x$xs; u(x,xs,lrec(xs,t,u))--->c |] ==> lrec(l,t,u)--->c"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   571
  unfolding data_defs by eval+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   572
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   573
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   574
subsection {* Factorial *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   575
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 33317
diff changeset
   576
schematic_lemma
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   577
  "letrec f n be ncase(n,succ(zero),%x. nrec(n,zero,%y g. nrec(f(x),g,%z h. succ(h))))  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   578
   in f(succ(succ(zero))) ---> ?a"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   579
  by eval
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   580
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 33317
diff changeset
   581
schematic_lemma
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   582
  "letrec f n be ncase(n,succ(zero),%x. nrec(n,zero,%y g. nrec(f(x),g,%z h. succ(h))))  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   583
   in f(succ(succ(succ(zero)))) ---> ?a"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   584
  by eval
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   585
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   586
subsection {* Less Than Or Equal *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   587
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 33317
diff changeset
   588
schematic_lemma
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   589
  "letrec f p be split(p,%m n. ncase(m,true,%x. ncase(n,false,%y. f(<x,y>))))
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   590
   in f(<succ(zero), succ(zero)>) ---> ?a"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   591
  by eval
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   592
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 33317
diff changeset
   593
schematic_lemma
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   594
  "letrec f p be split(p,%m n. ncase(m,true,%x. ncase(n,false,%y. f(<x,y>))))
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   595
   in f(<succ(zero), succ(succ(succ(succ(zero))))>) ---> ?a"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   596
  by eval
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   597
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 33317
diff changeset
   598
schematic_lemma
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   599
  "letrec f p be split(p,%m n. ncase(m,true,%x. ncase(n,false,%y. f(<x,y>))))
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   600
   in f(<succ(succ(succ(succ(succ(zero))))), succ(succ(succ(succ(zero))))>) ---> ?a"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   601
  by eval
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   602
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   603
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   604
subsection {* Reverse *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   605
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 33317
diff changeset
   606
schematic_lemma
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   607
  "letrec id l be lcase(l,[],%x xs. x$id(xs))  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   608
   in id(zero$succ(zero)$[]) ---> ?a"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   609
  by eval
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   610
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 33317
diff changeset
   611
schematic_lemma
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   612
  "letrec rev l be lcase(l,[],%x xs. lrec(rev(xs),x$[],%y ys g. y$g))  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   613
   in rev(zero$succ(zero)$(succ((lam x. x)`succ(zero)))$([])) ---> ?a"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   614
  by eval
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   615
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   616
end