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