src/HOL/Predicate_Compile_Examples/Specialisation_Examples.thy
author wenzelm
Sat Nov 04 15:24:40 2017 +0100 (20 months ago)
changeset 67003 49850a679c2c
parent 66453 cc19f7ca2ed6
child 67479 31d04ba28893
permissions -rw-r--r--
more robust sorted_entries;
bulwahn@36033
     1
theory Specialisation_Examples
wenzelm@66453
     2
imports Main "HOL-Library.Predicate_Compile_Alternative_Defs"
bulwahn@36033
     3
begin
bulwahn@36033
     4
bulwahn@45125
     5
declare [[values_timeout = 960.0]]
krauss@42142
     6
wenzelm@63167
     7
section \<open>Specialisation Examples\<close>
bulwahn@36033
     8
haftmann@39919
     9
primrec nth_el'
bulwahn@36033
    10
where
bulwahn@36033
    11
  "nth_el' [] i = None"
bulwahn@36033
    12
| "nth_el' (x # xs) i = (case i of 0 => Some x | Suc j => nth_el' xs j)"
bulwahn@36033
    13
bulwahn@36033
    14
definition
bulwahn@36033
    15
  "greater_than_index xs = (\<forall>i x. nth_el' xs i = Some x --> x > i)"
bulwahn@36033
    16
bulwahn@36257
    17
code_pred (expected_modes: i => bool) [inductify, skip_proof, specialise] greater_than_index .
wenzelm@63167
    18
ML_val \<open>Core_Data.intros_of @{context} @{const_name specialised_nth_el'P}\<close>
bulwahn@36033
    19
bulwahn@36033
    20
thm greater_than_index.equation
bulwahn@36033
    21
bulwahn@36033
    22
values [expected "{()}"] "{x. greater_than_index [1,2,4,6]}"
bulwahn@36033
    23
values [expected "{}"] "{x. greater_than_index [0,2,3,2]}"
bulwahn@36033
    24
wenzelm@63167
    25
subsection \<open>Common subterms\<close>
bulwahn@36033
    26
wenzelm@63167
    27
text \<open>If a predicate is called with common subterms as arguments,
bulwahn@36033
    28
  this predicate should be specialised. 
wenzelm@63167
    29
\<close>
bulwahn@36033
    30
bulwahn@36033
    31
definition max_nat :: "nat => nat => nat"
bulwahn@36033
    32
  where "max_nat a b = (if a <= b then b else a)"
bulwahn@36033
    33
bulwahn@36033
    34
lemma [code_pred_inline]:
bulwahn@36033
    35
  "max = max_nat"
nipkow@39302
    36
by (simp add: fun_eq_iff max_def max_nat_def)
bulwahn@36033
    37
bulwahn@36033
    38
definition
bulwahn@36033
    39
  "max_of_my_Suc x = max x (Suc x)"
bulwahn@36033
    40
wenzelm@63167
    41
text \<open>In this example, max is specialised, hence the mode o => i => bool is possible\<close>
bulwahn@36033
    42
bulwahn@36257
    43
code_pred (modes: o => i => bool) [inductify, specialise, skip_proof] max_of_my_Suc .
bulwahn@36033
    44
bulwahn@36033
    45
thm max_of_my_SucP.equation
bulwahn@36033
    46
wenzelm@63167
    47
ML_val \<open>Core_Data.intros_of @{context} @{const_name specialised_max_natP}\<close>
bulwahn@36033
    48
bulwahn@36033
    49
values "{x. max_of_my_SucP x 6}"
bulwahn@36033
    50
wenzelm@63167
    51
subsection \<open>Sorts\<close>
bulwahn@36033
    52
haftmann@39919
    53
declare sorted.Nil [code_pred_intro]
haftmann@39919
    54
  sorted_single [code_pred_intro]
haftmann@39919
    55
  sorted_many [code_pred_intro]
haftmann@39919
    56
wenzelm@53374
    57
code_pred sorted
wenzelm@53374
    58
proof -
haftmann@39919
    59
  assume "sorted xa"
haftmann@39919
    60
  assume 1: "xa = [] \<Longrightarrow> thesis"
haftmann@39919
    61
  assume 2: "\<And>x. xa = [x] \<Longrightarrow> thesis"
haftmann@39919
    62
  assume 3: "\<And>x y zs. xa = x # y # zs \<Longrightarrow> x \<le> y \<Longrightarrow> sorted (y # zs) \<Longrightarrow> thesis"
haftmann@39919
    63
  show thesis proof (cases xa)
haftmann@39919
    64
    case Nil with 1 show ?thesis .
haftmann@39919
    65
  next
haftmann@39919
    66
    case (Cons x xs) show ?thesis proof (cases xs)
haftmann@39919
    67
      case Nil with Cons 2 show ?thesis by simp
haftmann@39919
    68
    next
wenzelm@53374
    69
      case (Cons y zs)
wenzelm@53374
    70
      show ?thesis
wenzelm@53374
    71
      proof (rule 3)
wenzelm@63167
    72
        from Cons \<open>xa = x # xs\<close> show "xa = x # y # zs" by simp
wenzelm@63167
    73
        with \<open>sorted xa\<close> show "x \<le> y" and "sorted (y # zs)" by simp_all
wenzelm@53374
    74
      qed
haftmann@39919
    75
    qed
haftmann@39919
    76
  qed
haftmann@39919
    77
qed
bulwahn@36033
    78
thm sorted.equation
bulwahn@36033
    79
wenzelm@63167
    80
section \<open>Specialisation in POPLmark theory\<close>
bulwahn@36033
    81
bulwahn@36033
    82
notation
bulwahn@36033
    83
  Some ("\<lfloor>_\<rfloor>")
bulwahn@36033
    84
bulwahn@36033
    85
notation
bulwahn@36033
    86
  None ("\<bottom>")
bulwahn@36033
    87
bulwahn@36033
    88
notation
bulwahn@36033
    89
  length ("\<parallel>_\<parallel>")
bulwahn@36033
    90
bulwahn@36033
    91
notation
bulwahn@36033
    92
  Cons ("_ \<Colon>/ _" [66, 65] 65)
bulwahn@36033
    93
bulwahn@36033
    94
primrec
bulwahn@36033
    95
  nth_el :: "'a list \<Rightarrow> nat \<Rightarrow> 'a option" ("_\<langle>_\<rangle>" [90, 0] 91)
bulwahn@36033
    96
where
bulwahn@36033
    97
  "[]\<langle>i\<rangle> = \<bottom>"
bulwahn@36033
    98
| "(x # xs)\<langle>i\<rangle> = (case i of 0 \<Rightarrow> \<lfloor>x\<rfloor> | Suc j \<Rightarrow> xs \<langle>j\<rangle>)"
bulwahn@36033
    99
wenzelm@53015
   100
primrec assoc :: "('a \<times> 'b) list \<Rightarrow> 'a \<Rightarrow> 'b option" ("_\<langle>_\<rangle>\<^sub>?" [90, 0] 91)
bulwahn@36033
   101
where
wenzelm@53015
   102
  "[]\<langle>a\<rangle>\<^sub>? = \<bottom>"
wenzelm@53015
   103
| "(x # xs)\<langle>a\<rangle>\<^sub>? = (if fst x = a then \<lfloor>snd x\<rfloor> else xs\<langle>a\<rangle>\<^sub>?)"
bulwahn@36033
   104
bulwahn@36033
   105
primrec unique :: "('a \<times> 'b) list \<Rightarrow> bool"
bulwahn@36033
   106
where
bulwahn@36033
   107
  "unique [] = True"
wenzelm@53015
   108
| "unique (x # xs) = (xs\<langle>fst x\<rangle>\<^sub>? = \<bottom> \<and> unique xs)"
bulwahn@36033
   109
blanchet@58310
   110
datatype type =
bulwahn@36033
   111
    TVar nat
bulwahn@36033
   112
  | Top
bulwahn@36033
   113
  | Fun type type    (infixr "\<rightarrow>" 200)
bulwahn@36033
   114
  | TyAll type type  ("(3\<forall><:_./ _)" [0, 10] 10)
bulwahn@36033
   115
blanchet@58310
   116
datatype binding = VarB type | TVarB type
wenzelm@42463
   117
type_synonym env = "binding list"
bulwahn@36033
   118
bulwahn@36033
   119
primrec is_TVarB :: "binding \<Rightarrow> bool"
bulwahn@36033
   120
where
bulwahn@36033
   121
  "is_TVarB (VarB T) = False"
bulwahn@36033
   122
| "is_TVarB (TVarB T) = True"
bulwahn@36033
   123
bulwahn@36033
   124
primrec type_ofB :: "binding \<Rightarrow> type"
bulwahn@36033
   125
where
bulwahn@36033
   126
  "type_ofB (VarB T) = T"
bulwahn@36033
   127
| "type_ofB (TVarB T) = T"
bulwahn@36033
   128
bulwahn@36033
   129
primrec mapB :: "(type \<Rightarrow> type) \<Rightarrow> binding \<Rightarrow> binding"
bulwahn@36033
   130
where
bulwahn@36033
   131
  "mapB f (VarB T) = VarB (f T)"
bulwahn@36033
   132
| "mapB f (TVarB T) = TVarB (f T)"
bulwahn@36033
   133
blanchet@58310
   134
datatype trm =
bulwahn@36033
   135
    Var nat
bulwahn@36033
   136
  | Abs type trm   ("(3\<lambda>:_./ _)" [0, 10] 10)
bulwahn@36033
   137
  | TAbs type trm  ("(3\<lambda><:_./ _)" [0, 10] 10)
bulwahn@36033
   138
  | App trm trm    (infixl "\<bullet>" 200)
wenzelm@53015
   139
  | TApp trm type  (infixl "\<bullet>\<^sub>\<tau>" 200)
bulwahn@36033
   140
wenzelm@53015
   141
primrec liftT :: "nat \<Rightarrow> nat \<Rightarrow> type \<Rightarrow> type" ("\<up>\<^sub>\<tau>")
bulwahn@36033
   142
where
wenzelm@53015
   143
  "\<up>\<^sub>\<tau> n k (TVar i) = (if i < k then TVar i else TVar (i + n))"
wenzelm@53015
   144
| "\<up>\<^sub>\<tau> n k Top = Top"
wenzelm@53015
   145
| "\<up>\<^sub>\<tau> n k (T \<rightarrow> U) = \<up>\<^sub>\<tau> n k T \<rightarrow> \<up>\<^sub>\<tau> n k U"
wenzelm@53015
   146
| "\<up>\<^sub>\<tau> n k (\<forall><:T. U) = (\<forall><:\<up>\<^sub>\<tau> n k T. \<up>\<^sub>\<tau> n (k + 1) U)"
bulwahn@36033
   147
bulwahn@36033
   148
primrec lift :: "nat \<Rightarrow> nat \<Rightarrow> trm \<Rightarrow> trm" ("\<up>")
bulwahn@36033
   149
where
bulwahn@36033
   150
  "\<up> n k (Var i) = (if i < k then Var i else Var (i + n))"
wenzelm@53015
   151
| "\<up> n k (\<lambda>:T. t) = (\<lambda>:\<up>\<^sub>\<tau> n k T. \<up> n (k + 1) t)"
wenzelm@53015
   152
| "\<up> n k (\<lambda><:T. t) = (\<lambda><:\<up>\<^sub>\<tau> n k T. \<up> n (k + 1) t)"
bulwahn@36033
   153
| "\<up> n k (s \<bullet> t) = \<up> n k s \<bullet> \<up> n k t"
wenzelm@53015
   154
| "\<up> n k (t \<bullet>\<^sub>\<tau> T) = \<up> n k t \<bullet>\<^sub>\<tau> \<up>\<^sub>\<tau> n k T"
bulwahn@36033
   155
wenzelm@53015
   156
primrec substTT :: "type \<Rightarrow> nat \<Rightarrow> type \<Rightarrow> type"  ("_[_ \<mapsto>\<^sub>\<tau> _]\<^sub>\<tau>" [300, 0, 0] 300)
bulwahn@36033
   157
where
wenzelm@53015
   158
  "(TVar i)[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau> =
wenzelm@53015
   159
     (if k < i then TVar (i - 1) else if i = k then \<up>\<^sub>\<tau> k 0 S else TVar i)"
wenzelm@53015
   160
| "Top[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau> = Top"
wenzelm@53015
   161
| "(T \<rightarrow> U)[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau> = T[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau> \<rightarrow> U[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau>"
wenzelm@53015
   162
| "(\<forall><:T. U)[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau> = (\<forall><:T[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau>. U[k+1 \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau>)"
bulwahn@36033
   163
wenzelm@53015
   164
primrec decT :: "nat \<Rightarrow> nat \<Rightarrow> type \<Rightarrow> type"  ("\<down>\<^sub>\<tau>")
bulwahn@36033
   165
where
wenzelm@53015
   166
  "\<down>\<^sub>\<tau> 0 k T = T"
wenzelm@53015
   167
| "\<down>\<^sub>\<tau> (Suc n) k T = \<down>\<^sub>\<tau> n k (T[k \<mapsto>\<^sub>\<tau> Top]\<^sub>\<tau>)"
bulwahn@36033
   168
bulwahn@36033
   169
primrec subst :: "trm \<Rightarrow> nat \<Rightarrow> trm \<Rightarrow> trm"  ("_[_ \<mapsto> _]" [300, 0, 0] 300)
bulwahn@36033
   170
where
bulwahn@36033
   171
  "(Var i)[k \<mapsto> s] = (if k < i then Var (i - 1) else if i = k then \<up> k 0 s else Var i)"
bulwahn@36033
   172
| "(t \<bullet> u)[k \<mapsto> s] = t[k \<mapsto> s] \<bullet> u[k \<mapsto> s]"
wenzelm@53015
   173
| "(t \<bullet>\<^sub>\<tau> T)[k \<mapsto> s] = t[k \<mapsto> s] \<bullet>\<^sub>\<tau> \<down>\<^sub>\<tau> 1 k T"
wenzelm@53015
   174
| "(\<lambda>:T. t)[k \<mapsto> s] = (\<lambda>:\<down>\<^sub>\<tau> 1 k T. t[k+1 \<mapsto> s])"
wenzelm@53015
   175
| "(\<lambda><:T. t)[k \<mapsto> s] = (\<lambda><:\<down>\<^sub>\<tau> 1 k T. t[k+1 \<mapsto> s])"
bulwahn@36033
   176
wenzelm@53015
   177
primrec substT :: "trm \<Rightarrow> nat \<Rightarrow> type \<Rightarrow> trm"    ("_[_ \<mapsto>\<^sub>\<tau> _]" [300, 0, 0] 300)
bulwahn@36033
   178
where
wenzelm@53015
   179
  "(Var i)[k \<mapsto>\<^sub>\<tau> S] = (if k < i then Var (i - 1) else Var i)"
wenzelm@53015
   180
| "(t \<bullet> u)[k \<mapsto>\<^sub>\<tau> S] = t[k \<mapsto>\<^sub>\<tau> S] \<bullet> u[k \<mapsto>\<^sub>\<tau> S]"
wenzelm@53015
   181
| "(t \<bullet>\<^sub>\<tau> T)[k \<mapsto>\<^sub>\<tau> S] = t[k \<mapsto>\<^sub>\<tau> S] \<bullet>\<^sub>\<tau> T[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau>"
wenzelm@53015
   182
| "(\<lambda>:T. t)[k \<mapsto>\<^sub>\<tau> S] = (\<lambda>:T[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau>. t[k+1 \<mapsto>\<^sub>\<tau> S])"
wenzelm@53015
   183
| "(\<lambda><:T. t)[k \<mapsto>\<^sub>\<tau> S] = (\<lambda><:T[k \<mapsto>\<^sub>\<tau> S]\<^sub>\<tau>. t[k+1 \<mapsto>\<^sub>\<tau> S])"
bulwahn@36033
   184
wenzelm@53015
   185
primrec liftE :: "nat \<Rightarrow> nat \<Rightarrow> env \<Rightarrow> env" ("\<up>\<^sub>e")
bulwahn@36033
   186
where
wenzelm@53015
   187
  "\<up>\<^sub>e n k [] = []"
wenzelm@53015
   188
| "\<up>\<^sub>e n k (B \<Colon> \<Gamma>) = mapB (\<up>\<^sub>\<tau> n (k + \<parallel>\<Gamma>\<parallel>)) B \<Colon> \<up>\<^sub>e n k \<Gamma>"
bulwahn@36033
   189
wenzelm@53015
   190
primrec substE :: "env \<Rightarrow> nat \<Rightarrow> type \<Rightarrow> env"  ("_[_ \<mapsto>\<^sub>\<tau> _]\<^sub>e" [300, 0, 0] 300)
bulwahn@36033
   191
where
wenzelm@53015
   192
  "[][k \<mapsto>\<^sub>\<tau> T]\<^sub>e = []"
wenzelm@53015
   193
| "(B \<Colon> \<Gamma>)[k \<mapsto>\<^sub>\<tau> T]\<^sub>e = mapB (\<lambda>U. U[k + \<parallel>\<Gamma>\<parallel> \<mapsto>\<^sub>\<tau> T]\<^sub>\<tau>) B \<Colon> \<Gamma>[k \<mapsto>\<^sub>\<tau> T]\<^sub>e"
bulwahn@36033
   194
wenzelm@53015
   195
primrec decE :: "nat \<Rightarrow> nat \<Rightarrow> env \<Rightarrow> env"  ("\<down>\<^sub>e")
bulwahn@36033
   196
where
wenzelm@53015
   197
  "\<down>\<^sub>e 0 k \<Gamma> = \<Gamma>"
wenzelm@53015
   198
| "\<down>\<^sub>e (Suc n) k \<Gamma> = \<down>\<^sub>e n k (\<Gamma>[k \<mapsto>\<^sub>\<tau> Top]\<^sub>e)"
bulwahn@36033
   199
bulwahn@36033
   200
inductive
wenzelm@53072
   201
  well_formed :: "env \<Rightarrow> type \<Rightarrow> bool"  ("_ \<turnstile>\<^sub>w\<^sub>f _" [50, 50] 50)
bulwahn@36033
   202
where
wenzelm@53072
   203
  wf_TVar: "\<Gamma>\<langle>i\<rangle> = \<lfloor>TVarB T\<rfloor> \<Longrightarrow> \<Gamma> \<turnstile>\<^sub>w\<^sub>f TVar i"
wenzelm@53072
   204
| wf_Top: "\<Gamma> \<turnstile>\<^sub>w\<^sub>f Top"
wenzelm@53072
   205
| wf_arrow: "\<Gamma> \<turnstile>\<^sub>w\<^sub>f T \<Longrightarrow> \<Gamma> \<turnstile>\<^sub>w\<^sub>f U \<Longrightarrow> \<Gamma> \<turnstile>\<^sub>w\<^sub>f T \<rightarrow> U"
wenzelm@53072
   206
| wf_all: "\<Gamma> \<turnstile>\<^sub>w\<^sub>f T \<Longrightarrow> TVarB T \<Colon> \<Gamma> \<turnstile>\<^sub>w\<^sub>f U \<Longrightarrow> \<Gamma> \<turnstile>\<^sub>w\<^sub>f (\<forall><:T. U)"
bulwahn@36033
   207
bulwahn@36033
   208
inductive
wenzelm@53072
   209
  well_formedE :: "env \<Rightarrow> bool"  ("_ \<turnstile>\<^sub>w\<^sub>f" [50] 50)
wenzelm@53072
   210
  and well_formedB :: "env \<Rightarrow> binding \<Rightarrow> bool"  ("_ \<turnstile>\<^sub>w\<^sub>f\<^sub>B _" [50, 50] 50)
bulwahn@36033
   211
where
wenzelm@53072
   212
  "\<Gamma> \<turnstile>\<^sub>w\<^sub>f\<^sub>B B \<equiv> \<Gamma> \<turnstile>\<^sub>w\<^sub>f type_ofB B"
wenzelm@53072
   213
| wf_Nil: "[] \<turnstile>\<^sub>w\<^sub>f"
wenzelm@53072
   214
| wf_Cons: "\<Gamma> \<turnstile>\<^sub>w\<^sub>f\<^sub>B B \<Longrightarrow> \<Gamma> \<turnstile>\<^sub>w\<^sub>f \<Longrightarrow> B \<Colon> \<Gamma> \<turnstile>\<^sub>w\<^sub>f"
bulwahn@36033
   215
bulwahn@36033
   216
inductive_cases well_formed_cases:
wenzelm@53072
   217
  "\<Gamma> \<turnstile>\<^sub>w\<^sub>f TVar i"
wenzelm@53072
   218
  "\<Gamma> \<turnstile>\<^sub>w\<^sub>f Top"
wenzelm@53072
   219
  "\<Gamma> \<turnstile>\<^sub>w\<^sub>f T \<rightarrow> U"
wenzelm@53072
   220
  "\<Gamma> \<turnstile>\<^sub>w\<^sub>f (\<forall><:T. U)"
bulwahn@36033
   221
bulwahn@36033
   222
inductive_cases well_formedE_cases:
wenzelm@53072
   223
  "B \<Colon> \<Gamma> \<turnstile>\<^sub>w\<^sub>f"
bulwahn@36033
   224
bulwahn@36033
   225
inductive
bulwahn@36033
   226
  subtyping :: "env \<Rightarrow> type \<Rightarrow> type \<Rightarrow> bool"  ("_ \<turnstile> _ <: _" [50, 50, 50] 50)
bulwahn@36033
   227
where
wenzelm@53072
   228
  SA_Top: "\<Gamma> \<turnstile>\<^sub>w\<^sub>f \<Longrightarrow> \<Gamma> \<turnstile>\<^sub>w\<^sub>f S \<Longrightarrow> \<Gamma> \<turnstile> S <: Top"
wenzelm@53072
   229
| SA_refl_TVar: "\<Gamma> \<turnstile>\<^sub>w\<^sub>f \<Longrightarrow> \<Gamma> \<turnstile>\<^sub>w\<^sub>f TVar i \<Longrightarrow> \<Gamma> \<turnstile> TVar i <: TVar i"
bulwahn@36033
   230
| SA_trans_TVar: "\<Gamma>\<langle>i\<rangle> = \<lfloor>TVarB U\<rfloor> \<Longrightarrow>
wenzelm@53015
   231
    \<Gamma> \<turnstile> \<up>\<^sub>\<tau> (Suc i) 0 U <: T \<Longrightarrow> \<Gamma> \<turnstile> TVar i <: T"
wenzelm@53015
   232
| SA_arrow: "\<Gamma> \<turnstile> T\<^sub>1 <: S\<^sub>1 \<Longrightarrow> \<Gamma> \<turnstile> S\<^sub>2 <: T\<^sub>2 \<Longrightarrow> \<Gamma> \<turnstile> S\<^sub>1 \<rightarrow> S\<^sub>2 <: T\<^sub>1 \<rightarrow> T\<^sub>2"
wenzelm@53015
   233
| SA_all: "\<Gamma> \<turnstile> T\<^sub>1 <: S\<^sub>1 \<Longrightarrow> TVarB T\<^sub>1 \<Colon> \<Gamma> \<turnstile> S\<^sub>2 <: T\<^sub>2 \<Longrightarrow>
wenzelm@53015
   234
    \<Gamma> \<turnstile> (\<forall><:S\<^sub>1. S\<^sub>2) <: (\<forall><:T\<^sub>1. T\<^sub>2)"
bulwahn@36033
   235
bulwahn@36033
   236
inductive
bulwahn@36033
   237
  typing :: "env \<Rightarrow> trm \<Rightarrow> type \<Rightarrow> bool"    ("_ \<turnstile> _ : _" [50, 50, 50] 50)
bulwahn@36033
   238
where
wenzelm@53072
   239
  T_Var: "\<Gamma> \<turnstile>\<^sub>w\<^sub>f \<Longrightarrow> \<Gamma>\<langle>i\<rangle> = \<lfloor>VarB U\<rfloor> \<Longrightarrow> T = \<up>\<^sub>\<tau> (Suc i) 0 U \<Longrightarrow> \<Gamma> \<turnstile> Var i : T"
wenzelm@53015
   240
| T_Abs: "VarB T\<^sub>1 \<Colon> \<Gamma> \<turnstile> t\<^sub>2 : T\<^sub>2 \<Longrightarrow> \<Gamma> \<turnstile> (\<lambda>:T\<^sub>1. t\<^sub>2) : T\<^sub>1 \<rightarrow> \<down>\<^sub>\<tau> 1 0 T\<^sub>2"
wenzelm@53015
   241
| T_App: "\<Gamma> \<turnstile> t\<^sub>1 : T\<^sub>11 \<rightarrow> T\<^sub>12 \<Longrightarrow> \<Gamma> \<turnstile> t\<^sub>2 : T\<^sub>11 \<Longrightarrow> \<Gamma> \<turnstile> t\<^sub>1 \<bullet> t\<^sub>2 : T\<^sub>12"
wenzelm@53015
   242
| T_TAbs: "TVarB T\<^sub>1 \<Colon> \<Gamma> \<turnstile> t\<^sub>2 : T\<^sub>2 \<Longrightarrow> \<Gamma> \<turnstile> (\<lambda><:T\<^sub>1. t\<^sub>2) : (\<forall><:T\<^sub>1. T\<^sub>2)"
wenzelm@53015
   243
| T_TApp: "\<Gamma> \<turnstile> t\<^sub>1 : (\<forall><:T\<^sub>11. T\<^sub>12) \<Longrightarrow> \<Gamma> \<turnstile> T\<^sub>2 <: T\<^sub>11 \<Longrightarrow>
wenzelm@53015
   244
    \<Gamma> \<turnstile> t\<^sub>1 \<bullet>\<^sub>\<tau> T\<^sub>2 : T\<^sub>12[0 \<mapsto>\<^sub>\<tau> T\<^sub>2]\<^sub>\<tau>"
bulwahn@36033
   245
| T_Sub: "\<Gamma> \<turnstile> t : S \<Longrightarrow> \<Gamma> \<turnstile> S <: T \<Longrightarrow> \<Gamma> \<turnstile> t : T"
bulwahn@36033
   246
bulwahn@36257
   247
code_pred [inductify, skip_proof, specialise] typing .
bulwahn@36033
   248
bulwahn@36033
   249
thm typing.equation
bulwahn@36033
   250
bulwahn@36033
   251
values 6 "{(E, t, T). typing E t T}"
bulwahn@36033
   252
wenzelm@63167
   253
subsection \<open>Higher-order predicate\<close>
bulwahn@36033
   254
bulwahn@36033
   255
code_pred [inductify] mapB .
bulwahn@36033
   256
wenzelm@63167
   257
subsection \<open>Multiple instances\<close>
bulwahn@36033
   258
bulwahn@36033
   259
inductive subtype_refl' where
bulwahn@36033
   260
  "\<Gamma> \<turnstile> t : T ==> \<not> (\<Gamma> \<turnstile> T <: T) ==> subtype_refl' t T"
bulwahn@36033
   261
bulwahn@36033
   262
code_pred (modes: i => i => bool, o => i => bool, i => o => bool, o => o => bool) [inductify] subtype_refl' .
bulwahn@36033
   263
bulwahn@36033
   264
thm subtype_refl'.equation
bulwahn@36033
   265
bulwahn@36033
   266
bulwahn@45125
   267
end