src/HOL/Nominal/Examples/Fsub.thy
author urbanc
Thu, 15 Dec 2005 21:51:31 +0100
changeset 18417 149cc4126997
parent 18416 32833aae901f
child 18424 a37f06555c07
permissions -rw-r--r--
there was a small error in the last commit - fixed now
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18266
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
     1
(* $Id$ *)
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
     2
18269
3f36e2165e51 some small tuning
urbanc
parents: 18266
diff changeset
     3
theory fsub
3f36e2165e51 some small tuning
urbanc
parents: 18266
diff changeset
     4
imports "../nominal" 
3f36e2165e51 some small tuning
urbanc
parents: 18266
diff changeset
     5
begin
3f36e2165e51 some small tuning
urbanc
parents: 18266
diff changeset
     6
18266
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
     7
text {* Authors: Christian Urban
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
     8
                 Benjamin Pierce
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
     9
                 Steve Zdancewic
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
    10
                 Stephanie Weihrich
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
    11
                 Dimitrios Vytiniotis
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
    12
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
    13
                 with help from Stefan Berghofer, Markus Wenzel
18266
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
    14
      *}
55c201fe4c95 added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents: 18263
diff changeset
    15
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    16
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    17
atom_decl tyvrs vrs
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    18
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    19
section {* Types *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    20
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    21
nominal_datatype ty = TyVar "tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    22
                    | Top
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    23
                    | Arrow  "ty" "ty"          ("_ \<rightarrow> _" [900,900] 900)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    24
                    | TAll  "\<guillemotleft>tyvrs\<guillemotright>ty" "ty" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    25
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    26
syntax
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    27
  TAll_syn  :: "tyvrs \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty" ("\<forall> [_<:_]._" [900,900,900] 900)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    28
translations 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    29
  "(\<forall>[a<:ty1].ty2)" \<rightleftharpoons> "TAll a ty2 ty1"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    30
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    31
section {* typing contexts and their domains *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    32
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    33
types ty_context = "(tyvrs\<times>ty) list"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    34
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    35
text {* domain of a context --- (the name "dom" is already used elsewhere) *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    36
consts
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    37
  "domain" :: "ty_context \<Rightarrow> tyvrs set"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    38
primrec
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    39
  "domain [] = {}"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    40
  "domain (X#\<Gamma>) = {fst X}\<union>(domain \<Gamma>)" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    41
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    42
lemma domain_eqvt:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    43
  fixes pi::"tyvrs prm"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    44
  shows "pi\<bullet>(domain \<Gamma>) = domain (pi\<bullet>\<Gamma>)" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    45
  by (induct \<Gamma>, auto simp add: perm_set_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    46
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    47
lemma finite_domain:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    48
  fixes \<Gamma>::"ty_context"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    49
  shows "finite (domain \<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    50
  by (induct \<Gamma>, auto)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    51
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    52
lemma domain_inclusion[rule_format]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    53
  shows "(X,T)\<in>set \<Gamma> \<longrightarrow> X\<in>(domain \<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    54
  by (induct \<Gamma>, auto)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    55
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    56
lemma domain_existence[rule_format]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    57
  shows "X\<in>(domain \<Gamma>) \<longrightarrow> (\<exists>T.(X,T)\<in>set \<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    58
  by (induct \<Gamma>, auto)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    59
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    60
lemma domain_append:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    61
  shows "domain (\<Gamma>@\<Delta>) = ((domain \<Gamma>) \<union> (domain \<Delta>))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    62
  by (induct \<Gamma>, auto)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    63
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    64
section {* Two functions over types *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    65
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    66
text {* they cannot yet be defined conveniently unless we have a recursion combinator *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    67
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    68
consts size_ty :: "ty \<Rightarrow> nat"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    69
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    70
lemma size_ty[simp]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    71
  shows "size_ty (TyVar X) = 1"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    72
  and   "size_ty (Top) = 1"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    73
  and   "\<lbrakk>size_ty t1 = m ; size_ty t2 = n\<rbrakk> \<Longrightarrow> size_ty (t1 \<rightarrow> t2) = m + n + 1"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    74
  and   "\<lbrakk>size_ty t1 = m ; size_ty t2 = n\<rbrakk> \<Longrightarrow> size_ty (\<forall> [a<:t1].t2) = m + n + 1"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    75
sorry
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    76
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    77
consts subst_ty :: "ty \<Rightarrow> tyvrs \<Rightarrow> ty \<Rightarrow> ty"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    78
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    79
lemma subst_ty[simp]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    80
  shows "subst_ty (TyVar X) Y T = (if X=Y then T else (TyVar X))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    81
  and   "subst_ty Top Y T = Top"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    82
  and   "subst_ty (T1 \<rightarrow> T2) Y T = (subst_ty T1 Y T) \<rightarrow> (subst_ty T2 Y T)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    83
  and   "X\<sharp>(Y,T) \<Longrightarrow> subst_ty (\<forall>[X<:T1].T2) Y T = (\<forall>[X<:(subst_ty T1 Y T)].(subst_ty T2 Y T))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    84
  and   "\<lbrakk>X\<sharp>Y; X\<sharp>T\<rbrakk> \<Longrightarrow> subst_ty (\<forall>[X<:T1].T2) Y T = (\<forall>[X<:(subst_ty T1 Y T)].(subst_ty T2 Y T))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    85
sorry
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    86
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    87
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    88
consts subst_ctxt :: "ty_context \<Rightarrow> tyvrs \<Rightarrow> ty \<Rightarrow> ty_context"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    89
primrec
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    90
"subst_ctxt [] Y T = []"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    91
"subst_ctxt (XT#Xs) Y T = (fst XT, subst_ty (snd XT) Y T)#(subst_ctxt Xs Y T)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    92
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    93
text {* valid contexts *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    94
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    95
constdefs
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    96
  "closed_in" :: "ty \<Rightarrow> ty_context \<Rightarrow> bool" ("_ closed'_in _" [100,100] 100)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    97
  "S closed_in \<Gamma> \<equiv> (supp S)\<subseteq>(domain \<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    98
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
    99
lemma closed_in_def2:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   100
  shows "(S closed_in \<Gamma>) = ((supp S)\<subseteq>((supp (domain \<Gamma>)):: tyvrs set))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   101
apply(simp add: closed_in_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   102
apply(simp add: at_fin_set_supp[OF at_tyvrs_inst, OF finite_domain])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   103
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   104
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   105
lemma closed_in_eqvt:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   106
  fixes pi::"tyvrs prm"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   107
  assumes a: "S closed_in \<Gamma>" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   108
  shows "(pi\<bullet>S) closed_in (pi\<bullet>\<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   109
  using a
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   110
proof (unfold "closed_in_def")
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   111
  assume "supp S \<subseteq> (domain \<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   112
  hence "pi\<bullet>(supp S) \<subseteq> pi\<bullet>(domain \<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   113
    by (simp add: pt_subseteq_eqvt[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   114
  thus "(supp (pi\<bullet>S)) \<subseteq> (domain (pi\<bullet>\<Gamma>))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   115
    by (simp add: domain_eqvt pt_perm_supp[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   116
qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   117
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   118
consts
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   119
  valid_rel :: "ty_context set" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   120
  valid_sym :: "ty_context \<Rightarrow> bool" ("\<turnstile> _ ok" [100] 100)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   121
translations
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   122
  "\<turnstile> \<Gamma> ok" \<rightleftharpoons> "\<Gamma> \<in> valid_rel"  
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   123
inductive valid_rel
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   124
intros
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   125
v1[intro]: "\<turnstile> [] ok"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   126
v2[intro]: "\<lbrakk>\<turnstile> \<Gamma> ok; X\<sharp>\<Gamma>; T closed_in \<Gamma>\<rbrakk>  \<Longrightarrow>  \<turnstile> ((X,T)#\<Gamma>) ok"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   127
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   128
lemma valid_eqvt:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   129
  fixes pi::"tyvrs prm"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   130
  assumes a: "\<turnstile> \<Gamma> ok" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   131
  shows "\<turnstile> (pi\<bullet>\<Gamma>) ok"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   132
  using a
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   133
proof (induct)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   134
  case v1
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   135
  show ?case by force
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   136
next
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   137
  case (v2 T X \<Gamma>)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   138
  have a1: "\<turnstile> (pi \<bullet> \<Gamma>) ok" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   139
  have a2: "X\<sharp>\<Gamma>" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   140
  have a3: "T closed_in \<Gamma>" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   141
  show ?case
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   142
  proof (simp, rule valid_rel.v2)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   143
    show "\<turnstile> (pi \<bullet> \<Gamma>) ok" using a1 by simp
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   144
  next 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   145
    show "(pi\<bullet>X)\<sharp>(pi\<bullet>\<Gamma>)" using a2 by (simp add: pt_fresh_bij[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   146
  next
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   147
    show "(pi\<bullet>T) closed_in (pi\<bullet>\<Gamma>)" using a3 by (rule closed_in_eqvt)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   148
  qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   149
qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   150
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   151
lemma validE:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   152
  assumes a: "\<turnstile> ((X,T)#\<Gamma>) ok"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   153
  shows "\<turnstile> \<Gamma> ok \<and> X\<sharp>\<Gamma> \<and> T closed_in \<Gamma>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   154
using a by (cases, auto)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   155
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   156
lemma validE_append[rule_format]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   157
  shows "\<turnstile> (\<Delta>@\<Gamma>) ok \<longrightarrow> \<turnstile> \<Gamma> ok"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   158
  by (induct \<Delta>, auto dest: validE)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   159
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   160
lemma domain_fresh[rule_format]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   161
  fixes X::"tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   162
  shows "\<turnstile> \<Gamma> ok \<longrightarrow> (X\<sharp>(domain \<Gamma>) = X\<sharp>\<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   163
apply(induct \<Gamma>)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   164
apply(simp add: fresh_list_nil fresh_set_empty)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   165
apply(simp add: fresh_list_cons fresh_prod 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   166
   fresh_fin_insert[OF pt_tyvrs_inst, OF at_tyvrs_inst, OF fs_tyvrs_inst, OF finite_domain])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   167
apply(rule impI)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   168
apply(clarify)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   169
apply(simp add: fresh_prod)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   170
apply(drule validE)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   171
apply(simp)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   172
apply(simp add: closed_in_def2 fresh_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   173
apply(force)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   174
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   175
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   176
lemma closed_in_fresh:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   177
  fixes X::"tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   178
  assumes a1: "S closed_in \<Gamma>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   179
  and     a2: "X\<sharp>\<Gamma>" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   180
  and     a3: "\<turnstile> \<Gamma> ok"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   181
  shows "X\<sharp>S"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   182
using a1 a2 a3
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   183
apply(simp add: closed_in_def2)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   184
apply(simp add: domain_fresh[symmetric])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   185
apply(simp add: fresh_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   186
apply(force)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   187
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   188
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   189
lemma replace_type[rule_format]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   190
  shows "\<turnstile> (\<Delta>@(X,T)#\<Gamma>) ok \<longrightarrow> S closed_in \<Gamma> \<longrightarrow> \<turnstile> (\<Delta>@(X,S)#\<Gamma>) ok"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   191
apply(induct \<Delta>)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   192
apply(auto dest!: validE intro!: v2 simp add: fresh_list_append fresh_list_cons fresh_prod)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   193
apply(drule validE_append)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   194
apply(drule validE)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   195
apply(drule_tac S="S" in closed_in_fresh)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   196
apply(simp)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   197
apply(force)+
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   198
apply(simp add: closed_in_def2)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   199
apply(simp add: domain_append)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   200
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   201
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   202
lemma fresh_implies_not_member[rule_format]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   203
  fixes \<Gamma>::"ty_context"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   204
  shows "X\<sharp>\<Gamma> \<longrightarrow> \<not>(\<exists>T.(X,T)\<in>(set \<Gamma>))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   205
  apply (induct \<Gamma>)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   206
  apply (auto dest: validE simp add: fresh_list_cons fresh_prod fresh_atm)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   207
  done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   208
 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   209
lemma uniqueness_of_ctxt:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   210
  fixes \<Gamma>::"ty_context"
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   211
  assumes a: "\<turnstile> \<Gamma> ok"
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   212
  and     b: "(X,T)\<in>set \<Gamma>"
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   213
  and     c: "(X,S)\<in>set \<Gamma>"
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   214
  shows "T=S"
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   215
using a b c
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   216
apply (induct \<Gamma>)
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   217
apply (auto dest!: validE fresh_implies_not_member)
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   218
done
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   219
 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   220
section {* Subtyping *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   221
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   222
consts
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   223
  subtype_of_rel :: "(ty_context \<times> ty \<times> ty) set"   
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   224
  subtype_of_sym :: "ty_context \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> bool"   ("_ \<turnstile> _ <: _" [100,100,100] 100)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   225
translations
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   226
  "\<Gamma> \<turnstile> S <: T" \<rightleftharpoons> "(\<Gamma>,S,T) \<in> subtype_of_rel"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   227
inductive subtype_of_rel
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   228
intros
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   229
S_Top[intro]:   "\<lbrakk>\<turnstile> \<Gamma> ok; S closed_in \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> S <: Top"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   230
S_Var[intro]:   "\<lbrakk>\<turnstile> \<Gamma> ok; (X,S) \<in> (set \<Gamma>); \<Gamma> \<turnstile> S <: T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> (TyVar X) <: T"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   231
S_Refl[intro]:  "\<lbrakk>\<turnstile> \<Gamma> ok; X \<in> (domain \<Gamma>)\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> TyVar X <: TyVar X"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   232
S_Arrow[intro]: "\<lbrakk>\<Gamma> \<turnstile> T1 <: S1; \<Gamma> \<turnstile> S2 <: T2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> (S1 \<rightarrow> S2) <: (T1 \<rightarrow> T2)" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   233
S_All[intro]:   "\<lbrakk>\<Gamma> \<turnstile> T1 <: S1; X\<sharp>\<Gamma>; ((X,T1)#\<Gamma>) \<turnstile> S2 <: T2\<rbrakk> 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   234
                  \<Longrightarrow> \<Gamma> \<turnstile> \<forall> [X<:S1].S2 <: \<forall> [X<:T1].T2"  
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   235
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   236
lemma subtype_implies_closed:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   237
  assumes a: "\<Gamma> \<turnstile> S <: T"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   238
  shows "S closed_in \<Gamma> \<and> T closed_in \<Gamma>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   239
using a
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   240
proof (induct)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   241
  case (S_Top S \<Gamma>)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   242
  have "Top closed_in \<Gamma>" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   243
    by (simp add: closed_in_def ty.supp)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   244
  moreover
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   245
  have "S closed_in \<Gamma>" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   246
  ultimately show "S closed_in \<Gamma> \<and> Top closed_in \<Gamma>" by simp
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   247
next
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   248
  case (S_Var S T X \<Gamma>)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   249
  have "(X,S)\<in>set \<Gamma>" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   250
  hence "X\<in>(domain \<Gamma>)" by (rule domain_inclusion)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   251
  hence "(TyVar X) closed_in \<Gamma>" by (simp add: closed_in_def ty.supp supp_atm)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   252
  moreover
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   253
  have "S closed_in \<Gamma> \<and> T closed_in \<Gamma>" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   254
  hence "T closed_in \<Gamma>" by force
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   255
  ultimately show "(TyVar X) closed_in \<Gamma> \<and> T closed_in \<Gamma>" by simp
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   256
next
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   257
  case S_Refl thus ?case 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   258
    by (simp add: closed_in_def ty.supp supp_atm) 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   259
next
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   260
  case S_Arrow thus ?case by (force simp add: closed_in_def ty.supp)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   261
next 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   262
  case S_All thus ?case by (auto simp add: closed_in_def ty.supp abs_supp)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   263
qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   264
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   265
text {* a completely automated proof *}
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   266
lemma subtype_implies_closed:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   267
  assumes a: "\<Gamma> \<turnstile> S <: T"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   268
  shows "S closed_in \<Gamma> \<and> T closed_in \<Gamma>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   269
using a
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   270
apply (induct) 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   271
apply (auto simp add: closed_in_def ty.supp abs_supp domain_inclusion supp_atm)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   272
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   273
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   274
lemma subtype_implies_ok:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   275
  fixes X::"tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   276
  assumes a1: "\<Gamma> \<turnstile> S <: T"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   277
  shows "\<turnstile> \<Gamma> ok"  
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   278
using a1 by (induct, auto)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   279
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   280
lemma subtype_implies_fresh:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   281
  fixes X::"tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   282
  assumes a1: "\<Gamma> \<turnstile> S <: T"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   283
  and     a2: "X\<sharp>\<Gamma>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   284
  shows "X\<sharp>(S,T)"  
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   285
proof -
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   286
  from a1 have "\<turnstile> \<Gamma> ok" by (rule subtype_implies_ok)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   287
  with a2 have b0: "X\<sharp>domain(\<Gamma>)" by (simp add: domain_fresh)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   288
  from a1 have "S closed_in \<Gamma> \<and> T closed_in \<Gamma>" by (rule subtype_implies_closed)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   289
  hence b1: "supp S \<subseteq> ((supp (domain \<Gamma>))::tyvrs set)" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   290
    and b2: "supp T \<subseteq> ((supp (domain \<Gamma>))::tyvrs set)" by (simp_all add: closed_in_def2)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   291
  thus "X\<sharp>(S,T)" using b0 b1 b2 by (force simp add: supp_prod fresh_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   292
qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   293
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   294
lemma silly_eqvt1:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   295
  fixes X::"'a::pt_tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   296
  and   S::"'b::pt_tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   297
  and   pi::"tyvrs prm"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   298
 shows "(X,S) \<in> set \<Gamma> \<Longrightarrow> (pi\<bullet>X,pi\<bullet>S) \<in> set (pi\<bullet>\<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   299
apply(drule_tac pi="pi" in pt_set_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   300
apply(simp add: pt_list_set_pi[OF pt_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   301
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   302
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   303
lemma silly_eqvt2:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   304
  fixes X::"tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   305
  and   pi::"tyvrs prm"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   306
 shows "X \<in> (domain \<Gamma>) \<Longrightarrow> (pi\<bullet>X) \<in> (domain (pi\<bullet>\<Gamma>))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   307
apply(drule_tac pi="pi" in pt_set_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   308
apply(simp add: domain_eqvt pt_list_set_pi[OF pt_tyvrs_inst] )
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   309
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   310
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   311
lemma subtype_eqvt:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   312
  fixes pi::"tyvrs prm"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   313
  shows "\<Gamma> \<turnstile> S <: T \<Longrightarrow> (pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>S) <: (pi\<bullet>T)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   314
apply(erule subtype_of_rel.induct)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   315
apply(force intro: valid_eqvt closed_in_eqvt)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   316
apply(force intro: closed_in_eqvt valid_eqvt silly_eqvt1)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   317
apply(force intro: valid_eqvt silly_eqvt2)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   318
apply(force)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   319
apply(force intro!: S_All simp add: fresh_prod pt_fresh_bij1[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   320
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   321
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   322
lemma subtype_of_rel_induct[consumes 1, case_names S_Top S_Var S_Refl S_Arrow S_All]:
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   323
  fixes  P :: "'a::fs_tyvrs\<Rightarrow>ty_context \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow>bool"
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   324
  assumes a: "\<Gamma> \<turnstile> S <: T"
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   325
  and a1:    "\<And>\<Gamma> S x. (\<turnstile> \<Gamma> ok) \<Longrightarrow> (S closed_in \<Gamma>) \<Longrightarrow> P x \<Gamma> S Top"
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   326
  and a2:    "\<And>\<Gamma> X S T x. (\<turnstile> \<Gamma> ok) \<Longrightarrow> ((X,S)\<in>set \<Gamma>) \<Longrightarrow> (\<Gamma> \<turnstile> S <: T) \<Longrightarrow> (\<And>z. P z \<Gamma> S T)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   327
              \<Longrightarrow> P x \<Gamma> (TyVar X) T"
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   328
  and a3:    "\<And>\<Gamma> X x. (\<turnstile> \<Gamma> ok) \<Longrightarrow> X\<in>domain \<Gamma> \<Longrightarrow> P x \<Gamma> (TyVar X) (TyVar X)"  
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   329
  and a4:    "\<And>\<Gamma> S1 S2 T1 T2 x. \<Gamma> \<turnstile> T1 <: S1 \<Longrightarrow> (\<And>z. P z \<Gamma> T1 S1) \<Longrightarrow> \<Gamma> \<turnstile> S2 <: T2 \<Longrightarrow> 
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   330
              (\<And>z. P z \<Gamma> S2 T2) \<Longrightarrow> P x \<Gamma> (S1 \<rightarrow> S2) (T1 \<rightarrow> T2)"
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   331
  and a5:    "\<And>\<Gamma> X S1 S2 T1 T2 x. 
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   332
              X\<sharp>x \<Longrightarrow> X\<sharp>(\<Gamma>,S1,T1) \<Longrightarrow> \<Gamma> \<turnstile> T1 <: S1 \<Longrightarrow> (\<And>z. P z \<Gamma> T1 S1) \<Longrightarrow> ((X,T1)#\<Gamma>) \<turnstile> S2 <: T2 
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   333
              \<Longrightarrow> (\<And>z. P z ((X,T1)#\<Gamma>) S2 T2) \<Longrightarrow> P x \<Gamma> (\<forall> [X<:S1].S2) (\<forall> [X<:T1].T2)"
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   334
  shows "P x \<Gamma> S T"
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   335
proof -
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   336
  from a have "\<And>(pi::tyvrs prm) (x::'a::fs_tyvrs). P x (pi\<bullet>\<Gamma>) (pi\<bullet>S) (pi\<bullet>T)"
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   337
  proof (induct)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   338
    case (S_Top S \<Gamma>)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   339
    have b1: "\<turnstile> \<Gamma> ok" by fact 
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   340
    have b2: "S closed_in \<Gamma>" by fact
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   341
    from b1 have "\<turnstile> (pi\<bullet>\<Gamma>) ok" by (rule valid_eqvt)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   342
    moreover
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   343
    from b2 have "(pi\<bullet>S) closed_in (pi\<bullet>\<Gamma>)" by (rule closed_in_eqvt)
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   344
    ultimately show "P x (pi \<bullet> \<Gamma>) (pi \<bullet> S) (pi\<bullet>Top)" by (simp add: a1)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   345
  next
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   346
    case (S_Var S T X \<Gamma>)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   347
    have b1: "\<turnstile> \<Gamma> ok" by fact 
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   348
    have b2: "(X,S) \<in> set \<Gamma>" by fact
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   349
    have b3: "\<Gamma> \<turnstile> S <: T" by fact
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   350
    have b4: "\<And>(pi::tyvrs prm) x. P x (pi\<bullet>\<Gamma>) (pi\<bullet>S) (pi\<bullet>T)" by fact
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   351
    from b1 have "\<turnstile> (pi\<bullet>\<Gamma>) ok" by (rule valid_eqvt)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   352
    moreover
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   353
    from b2 have "pi\<bullet>(X,S)\<in>pi\<bullet>(set \<Gamma>)" by (rule pt_set_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   354
    hence "(pi\<bullet>X,pi\<bullet>S)\<in>set (pi\<bullet>\<Gamma>)" by (simp add: pt_list_set_pi[OF pt_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   355
    moreover 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   356
    from b3 have "(pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>S) <: (pi\<bullet>T)" by (rule subtype_eqvt)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   357
    moreover 
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   358
    from b4 have "\<And>x. P x (pi\<bullet>\<Gamma>) (pi\<bullet>S) (pi\<bullet>T)" by simp
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   359
    ultimately 
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   360
    show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(TyVar X)) (pi\<bullet>T)" by (simp add: a2)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   361
  next
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   362
    case (S_Refl X \<Gamma>)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   363
    have b1: "\<turnstile> \<Gamma> ok" by fact
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   364
    have b2: "X \<in> domain \<Gamma>" by fact
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   365
    from b1 have "\<turnstile> (pi\<bullet>\<Gamma>) ok" by (rule valid_eqvt)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   366
    moreover
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   367
    from b2 have "(pi\<bullet>X)\<in>pi\<bullet>domain \<Gamma>" by (rule pt_set_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   368
    hence "(pi\<bullet>X)\<in>domain (pi\<bullet>\<Gamma>)" by (simp add: domain_eqvt pt_list_set_pi[OF pt_tyvrs_inst])
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   369
    ultimately show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(TyVar X)) (pi\<bullet>(TyVar X))" by (simp add: a3)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   370
  next
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   371
    case S_Arrow thus ?case by (simp, auto intro!: a4 subtype_eqvt)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   372
  next
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   373
    case (S_All S1 S2 T1 T2 X \<Gamma>)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   374
    have b1: "\<Gamma> \<turnstile> T1 <: S1" by fact 
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   375
    have b2: "\<And>(pi::tyvrs prm) x. P x (pi\<bullet>\<Gamma>) (pi\<bullet>T1) (pi\<bullet>S1)" by fact
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   376
    have b4: "((X,T1)#\<Gamma>) \<turnstile> S2 <: T2" by fact
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   377
    have b5: "\<And>(pi::tyvrs prm) x. P x (pi\<bullet>((X,T1)#\<Gamma>)) (pi\<bullet>S2) (pi\<bullet>T2)" by fact
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   378
    have b3': "X\<sharp>\<Gamma>" by fact
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   379
    have b3'': "X\<sharp>(T1,S1)" using b1 b3' by (rule subtype_implies_fresh)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   380
    have b3: "X\<sharp>(\<Gamma>,S1,T1)" using b3' b3'' by (simp add: fresh_prod)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   381
    have "\<exists>C::tyvrs. C\<sharp>(pi\<bullet>X,pi\<bullet>S2,pi\<bullet>T2,pi\<bullet>S1,pi\<bullet>T1,pi\<bullet>\<Gamma>,x)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   382
      by (rule at_exists_fresh[OF at_tyvrs_inst], simp add: fs_tyvrs1)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   383
    then obtain C::"tyvrs" where  f1: "C\<noteq>(pi\<bullet>X)" and f2: "C\<sharp>(pi\<bullet>S1)" and f3: "C\<sharp>(pi\<bullet>T1)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   384
      and f4: "C\<sharp>(pi\<bullet>S2)" and f5: "C\<sharp>(pi\<bullet>T2)" and f6: "C\<sharp>(pi\<bullet>\<Gamma>)" and f7: "C\<sharp>x"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   385
      by (auto simp add: fresh_prod fresh_atm)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   386
    let ?pi' = "[(C,pi\<bullet>X)]@pi"
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   387
    from b2 have c1: "\<And>x. P x (?pi'\<bullet>\<Gamma>) (?pi'\<bullet>T1) (?pi'\<bullet>S1)" by simp
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   388
    from b5 have "\<And>x. P x (?pi'\<bullet>((X,T1)#\<Gamma>)) (?pi'\<bullet>S2) (?pi'\<bullet>T2)" by simp
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   389
    hence "\<And>x. P x ((?pi'\<bullet>X,?pi'\<bullet>T1)#(?pi'\<bullet>\<Gamma>)) (?pi'\<bullet>S2) (?pi'\<bullet>T2)" by simp
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   390
    hence c2: "\<And>x. P x ((C,?pi'\<bullet>T1)#(?pi'\<bullet>\<Gamma>)) (?pi'\<bullet>S2) (?pi'\<bullet>T2)" using f1
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   391
      by (simp only: pt_tyvrs2 calc_atm, simp)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   392
    from b3 have "(pi\<bullet>X)\<sharp>(pi\<bullet>\<Gamma>)" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   393
      by (simp add: fresh_prod pt_fresh_bij[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   394
    with f6 have f6a: "?pi'\<bullet>\<Gamma>=pi\<bullet>\<Gamma>" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   395
      by (simp only: pt_tyvrs2 pt_fresh_fresh[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   396
    hence f6': "C\<sharp>(?pi'\<bullet>\<Gamma>)" using f6 by simp
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   397
    from b3 have "(pi\<bullet>X)\<sharp>(pi\<bullet>S1)" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   398
      by (simp add: fresh_prod pt_fresh_bij[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   399
    with f2 have f2a: "?pi'\<bullet>S1=pi\<bullet>S1" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   400
      by (simp only: pt_tyvrs2 pt_fresh_fresh[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   401
    hence f2': "C\<sharp>(?pi'\<bullet>S1)" using f2 by simp
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   402
    from b3 have "(pi\<bullet>X)\<sharp>(pi\<bullet>T1)" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   403
      by (simp add: fresh_prod pt_fresh_bij[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   404
    with f3 have f3a: "?pi'\<bullet>T1=pi\<bullet>T1" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   405
      by (simp only: pt_tyvrs2 pt_fresh_fresh[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   406
    hence f3': "C\<sharp>(?pi'\<bullet>T1)" using f3 by simp
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   407
    from b1 have e1: "(?pi'\<bullet>\<Gamma>) \<turnstile> (?pi'\<bullet>T1) <: (?pi'\<bullet>S1)" by (rule subtype_eqvt)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   408
    from b4 have "(?pi'\<bullet>((X,T1)#\<Gamma>)) \<turnstile> (?pi'\<bullet>S2) <: (?pi'\<bullet>T2)" by (rule subtype_eqvt)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   409
    hence "((?pi'\<bullet>X,?pi'\<bullet>T1)#(?pi'\<bullet>\<Gamma>)) \<turnstile> (?pi'\<bullet>S2) <: (?pi'\<bullet>T2)" by simp
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   410
    hence e2: "((C,?pi'\<bullet>T1)#(?pi'\<bullet>\<Gamma>)) \<turnstile> (?pi'\<bullet>S2) <: (?pi'\<bullet>T2)" using f1
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   411
      by (simp only: pt_tyvrs2 calc_atm, simp)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   412
    have fnew: "C\<sharp>(?pi'\<bullet>\<Gamma>,?pi'\<bullet>S1,?pi'\<bullet>T1)" using f6' f2' f3' by (simp add: fresh_prod)
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   413
    have main: "P x (?pi'\<bullet>\<Gamma>) (\<forall> [C<:(?pi'\<bullet>S1)].(?pi'\<bullet>S2)) (\<forall> [C<:(?pi'\<bullet>T1)].(?pi'\<bullet>T2))"
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   414
      using f7 fnew e1 c1 e2 c2 by (rule a5)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   415
    have alpha1: "(\<forall> [C<:(?pi'\<bullet>S1)].(?pi'\<bullet>S2)) = (pi\<bullet>(\<forall> [X<:S1].S2))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   416
      using f1 f4 f2a[symmetric] by (simp add: ty.inject alpha pt_tyvrs2[symmetric])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   417
    have alpha2: "(\<forall> [C<:(?pi'\<bullet>T1)].(?pi'\<bullet>T2)) = (pi\<bullet>(\<forall> [X<:T1].T2))"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   418
      using f1 f5 f3a[symmetric] by (simp add: ty.inject alpha pt_tyvrs2[symmetric])
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   419
    show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(\<forall> [X<:S1].S2)) (pi\<bullet>(\<forall> [X<:T1].T2))"
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   420
      using alpha1 alpha2 f6a main by simp  
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   421
  qed
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   422
  hence "P x (([]::tyvrs prm)\<bullet>\<Gamma>) (([]::tyvrs prm)\<bullet>S) (([]::tyvrs prm)\<bullet>T)" by blast
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   423
  thus ?thesis by simp
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   424
qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   425
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   426
section {* Two proofs for reflexivity of subtyping *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   427
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   428
lemma subtype_reflexivity:
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   429
  assumes a: "\<turnstile> \<Gamma> ok"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   430
  and     b: "T closed_in \<Gamma>"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   431
  shows "\<Gamma> \<turnstile> T <: T"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   432
using a b
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   433
proof(nominal_induct T avoiding: \<Gamma> rule: ty.induct_unsafe)
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   434
  case (TAll X T1 T2)
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   435
  have i1: "\<And>\<Gamma>. \<turnstile> \<Gamma> ok \<Longrightarrow> T1 closed_in \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> T1 <: T1" by fact 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   436
  have i2: "\<And>\<Gamma>. \<turnstile> \<Gamma> ok \<Longrightarrow> T2 closed_in \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> T2 <: T2" by fact
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   437
  have f: "X\<sharp>\<Gamma>" by fact
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   438
  have "(\<forall>[X<:T2].T1) closed_in \<Gamma>" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   439
  hence b1: "T2 closed_in \<Gamma>" and b2: "T1 closed_in ((X,T2)#\<Gamma>)" 
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   440
      by (auto simp add: closed_in_def ty.supp abs_supp)
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   441
  have c1: "\<turnstile> \<Gamma> ok" by fact  
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   442
  hence c2: "\<turnstile> ((X,T2)#\<Gamma>) ok" using b1 f by force
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   443
  have "\<Gamma> \<turnstile> T2 <: T2" using i2 b1 c1 by simp
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   444
  moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   445
  have "((X,T2)#\<Gamma>) \<turnstile> T1 <: T1" using i1 b2 c2 by simp
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   446
  ultimately show "\<Gamma> \<turnstile> \<forall>[X<:T2].T1 <: \<forall>[X<:T2].T1" using f by force
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   447
qed (auto simp add: closed_in_def ty.supp supp_atm)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   448
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   449
lemma subtype_reflexivity:
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   450
  assumes a: "\<turnstile> \<Gamma> ok"
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   451
  and     b: "T closed_in \<Gamma>"
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   452
  shows "\<Gamma> \<turnstile> T <: T"
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   453
using a b
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   454
apply(nominal_induct T avoiding: \<Gamma> rule: ty.induct_unsafe)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   455
apply(auto simp add: ty.supp abs_supp closed_in_def supp_atm)
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   456
(* too bad that this cannot be found automatically *)
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   457
apply(drule_tac x="(tyvrs, ty2)#\<Gamma>" in meta_spec)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   458
apply(force simp add: closed_in_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   459
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   460
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   461
text {* Inversion lemmas. . .  *}
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   462
lemma S_TopE:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   463
 shows "\<Gamma> \<turnstile> Top <: T \<Longrightarrow> T = Top" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   464
apply(ind_cases "\<Gamma> \<turnstile> Top <: T", auto)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   465
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   466
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   467
lemma S_ArrowE_left:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   468
  assumes a: "\<Gamma> \<turnstile> S1 \<rightarrow> S2 <: T" 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   469
  shows "T = Top \<or> (\<exists>T1 T2. T = T1 \<rightarrow> T2 \<and> \<Gamma> \<turnstile> T1 <: S1 \<and> \<Gamma> \<turnstile> S2 <: T2)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   470
using  a by (cases, auto simp add: ty.inject)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   471
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   472
lemma S_AllE_left:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   473
  shows "\<lbrakk>\<Gamma> \<turnstile> \<forall>[X<:S1].S2 <: T; X\<sharp>(\<Gamma>,S1)\<rbrakk>
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   474
         \<Longrightarrow> T = Top \<or> (\<exists>T1 T2. T = \<forall>[X<:T1].T2 \<and> \<Gamma> \<turnstile> T1 <: S1 \<and> ((X,T1)#\<Gamma>) \<turnstile> S2 <: T2)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   475
  apply(frule subtype_implies_ok)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   476
  apply(ind_cases "\<Gamma> \<turnstile> \<forall>[X<:S1].S2 <: T")
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   477
  apply(auto simp add: ty.inject alpha)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   478
  apply(rule_tac x="[(X,Xa)]\<bullet>T2" in exI)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   479
  (* term *)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   480
  apply(rule conjI)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   481
  apply(rule sym)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   482
  apply(rule pt_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   483
  apply(rule pt_tyvrs3)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   484
  apply(simp)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   485
  apply(rule at_ds5[OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   486
  (* 1st conjunct *)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   487
  apply(rule conjI)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   488
  apply(simp add: pt_fresh_left[OF pt_tyvrs_inst, OF at_tyvrs_inst] calc_atm)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   489
  apply(simp add: fresh_prod)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   490
  apply(drule_tac \<Gamma>="((Xa,T1)#\<Gamma>)" in  subtype_implies_closed)+
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   491
  apply(simp add: closed_in_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   492
  apply(auto simp add: domain_fresh[of "\<Gamma>" "X", symmetric])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   493
  apply(simp add: fresh_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   494
  apply(subgoal_tac "X \<notin> (insert Xa (domain \<Gamma>))")(*A*)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   495
  apply(force)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   496
  (*A*)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   497
  apply(simp add: at_fin_set_supp[OF at_tyvrs_inst, OF finite_domain])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   498
  (* 2nd conjunct *)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   499
  apply(frule_tac X="X" in subtype_implies_fresh)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   500
  apply(simp add: fresh_prod)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   501
  apply(drule_tac X="Xa" in subtype_implies_fresh)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   502
  apply(assumption)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   503
  apply(simp add: fresh_prod)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   504
  apply(drule_tac pi="[(X,Xa)]" in subtype_eqvt)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   505
  apply(simp add: calc_atm)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   506
  apply(simp add: pt_fresh_fresh[OF pt_tyvrs_inst, OF at_tyvrs_inst])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   507
  done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   508
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   509
section {* Type substitution *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   510
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   511
lemma subst_ty_fresh[rule_format]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   512
  fixes P :: "ty"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   513
  and   X :: "tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   514
  shows "X\<sharp>(T,P) \<longrightarrow> X\<sharp>(subst_ty T Y P)"
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   515
  apply (nominal_induct T avoiding : T Y P rule: ty.induct_unsafe)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   516
  apply (auto simp add: fresh_prod abs_fresh)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   517
  done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   518
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   519
lemma subst_ctxt_fresh[rule_format]:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   520
  fixes X::"tyvrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   521
  shows "X\<sharp>(\<Gamma>,P) \<longrightarrow> X\<sharp>(subst_ctxt \<Gamma> Y P)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   522
  apply (induct \<Gamma>)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   523
  apply (auto intro: subst_ty_fresh simp add: fresh_prod fresh_list_cons)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   524
  done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   525
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   526
(*
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   527
lemma subst_ctxt_closed:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   528
  shows  "subst_ty b X P closed_in (subst_ctxt \<Delta> X P @ \<Gamma>)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   529
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   530
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   531
lemma substitution_ok:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   532
  shows "\<turnstile> (\<Delta>@(X,Q)#\<Gamma>) ok \<longrightarrow> \<Gamma> \<turnstile> P <: Q \<longrightarrow> \<turnstile> ((subst_ctxt \<Delta> X P)@\<Gamma>)  ok"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   533
  apply (induct \<Delta>)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   534
  apply (auto dest: validE)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   535
  apply (rule v2)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   536
  apply assumption
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   537
  apply (drule validE)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   538
  apply (auto simp add: fresh_list_append)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   539
  apply (rule subst_ctxt_fresh)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   540
  apply (simp add: fresh_prod)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   541
  apply (drule_tac X = "a" in subtype_implies_fresh)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   542
  apply (simp add: fresh_list_cons)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   543
  apply (simp add: fresh_prod)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   544
  apply (simp add: fresh_list_cons)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   545
  apply (drule validE)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   546
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   547
done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   548
*)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   549
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   550
(* note: What should nominal induct do if the context is compound? *)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   551
(*
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   552
lemma type_substitution:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   553
  assumes a0: "(\<Delta>@(X,Q)#\<Gamma>) \<turnstile> S <: T"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   554
  shows "\<turnstile> (\<Delta>@(X,Q)#\<Gamma>) ok \<longrightarrow> \<Gamma> \<turnstile> P <: Q 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   555
         \<longrightarrow> ((subst_ctxt \<Delta> X P)@\<Gamma>) \<turnstile> (subst_ty S X P) <: (subst_ty T X P)"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   556
  using a0 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   557
  thm subtype_of_rel_induct
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   558
  apply(rule subtype_of_rel_induct[of "\<Delta>@(X,Q)#\<Gamma>" "S" "T" _ "P"])
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   559
  apply(auto)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   560
  apply(rule S_Top)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   561
  defer
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   562
  defer
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   563
  defer
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   564
  apply(rule S_Var)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   565
  defer
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   566
  defer
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   567
  defer
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   568
  defer
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   569
  apply(rule S_Refl)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   570
  defer
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   571
  defer
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   572
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   573
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   574
apply (nominal_induct \<Delta> X Q \<Gamma> S T rule: subtype_of_rel_induct)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   575
*)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   576
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   577
section {* Weakening *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   578
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   579
constdefs 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   580
  extends :: "ty_context \<Rightarrow> ty_context \<Rightarrow> bool" ("_ extends _" [100,100] 100)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   581
  "\<Delta> extends \<Gamma> \<equiv> \<forall>X Q. (X,Q)\<in>set \<Gamma> \<longrightarrow> (X,Q)\<in>set \<Delta>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   582
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   583
lemma extends_domain:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   584
  assumes a: "\<Delta> extends \<Gamma>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   585
  shows "domain \<Gamma> \<subseteq> domain \<Delta>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   586
  using a 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   587
  apply (auto simp add: extends_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   588
  apply (drule domain_existence)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   589
  apply (force simp add: domain_inclusion)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   590
  done
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   591
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   592
lemma extends_closed:
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   593
  assumes a1: "T closed_in \<Gamma>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   594
  and     a2: "\<Delta> extends \<Gamma>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   595
  shows "T closed_in \<Delta>"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   596
  using a1 a2
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   597
  by (auto dest: extends_domain simp add: closed_in_def)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   598
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   599
lemma weakening:
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   600
  assumes a: "\<Gamma> \<turnstile> S <: T"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   601
  and     b: "\<turnstile> \<Delta> ok"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   602
  and     c: "\<Delta> extends \<Gamma>"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   603
  shows "\<Delta> \<turnstile> S <: T"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   604
  using a b c 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   605
proof (nominal_induct \<Gamma> S T avoiding: \<Delta> rule: subtype_of_rel_induct)
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   606
  case (S_Top \<Gamma> S) 
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   607
  have lh_drv_prem: "S closed_in \<Gamma>" by fact
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   608
  have "\<turnstile> \<Delta> ok" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   609
  moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   610
  have "\<Delta> extends \<Gamma>" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   611
  hence "S closed_in \<Delta>" using lh_drv_prem by (rule_tac extends_closed)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   612
  ultimately show "\<Delta> \<turnstile> S <: Top" by force
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   613
next 
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   614
  case (S_Var \<Gamma> X S T)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   615
  have lh_drv_prem: "(X,S) \<in> set \<Gamma>" by fact
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   616
  have ih: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends \<Gamma> \<Longrightarrow> \<Delta> \<turnstile> S <: T" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   617
  have ok: "\<turnstile> \<Delta> ok" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   618
  have extends: "\<Delta> extends \<Gamma>" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   619
  have "(X,S) \<in> set \<Delta>" using lh_drv_prem extends by (simp add: extends_def)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   620
  moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   621
  have "\<Delta> \<turnstile> S <: T" using ok extends ih by simp
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   622
  ultimately show "\<Delta> \<turnstile> TyVar X <: T" using ok by force
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   623
next
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   624
  case (S_Refl \<Gamma> X)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   625
  have lh_drv_prem: "X \<in> domain \<Gamma>" by fact
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   626
  have "\<turnstile> \<Delta> ok" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   627
  moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   628
  have "\<Delta> extends \<Gamma>" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   629
  hence "X \<in> domain \<Delta>" using lh_drv_prem by (force dest: extends_domain)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   630
  ultimately show "\<Delta> \<turnstile> TyVar X <: TyVar X" by force
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   631
next 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   632
  case S_Arrow thus ?case by force
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   633
next
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   634
  case (S_All \<Gamma> X S1 S2 T1 T2)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   635
  have fresh: "X\<sharp>\<Delta>" by fact
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   636
  have ih1: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends \<Gamma> \<Longrightarrow> \<Delta> \<turnstile> T1 <: S1" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   637
  have ih2: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends ((X,T1)#\<Gamma>) \<Longrightarrow> \<Delta> \<turnstile> S2 <: T2" by fact
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   638
  have lh_drv_prem: "\<Gamma> \<turnstile> T1 <: S1" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   639
  hence b5: "T1 closed_in \<Gamma>" by (simp add: subtype_implies_closed) 
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   640
  have ok: "\<turnstile> \<Delta> ok" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   641
  have extends: "\<Delta> extends \<Gamma>" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   642
  have "T1 closed_in \<Delta>" using extends b5 by (simp only: extends_closed)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   643
  hence "\<turnstile> ((X,T1)#\<Delta>) ok" using fresh ok by force   
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   644
  moreover 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   645
  have "((X,T1)#\<Delta>) extends ((X,T1)#\<Gamma>)" using extends by (force simp add: extends_def)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   646
  ultimately have "((X,T1)#\<Delta>) \<turnstile> S2 <: T2" using ih2 by simp
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   647
  moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   648
  have "\<Delta> \<turnstile> T1 <: S1" using ok extends ih1 by simp 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   649
  ultimately show "\<Delta> \<turnstile> \<forall> [X<:S1].S2 <: \<forall> [X<:T1].T2" using ok by (force intro: S_All) 
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   650
qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   651
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   652
text {* more automated proof *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   653
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   654
lemma weakening:
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   655
  assumes a: "\<Gamma> \<turnstile> S <: T"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   656
  and     b: "\<turnstile> \<Delta> ok"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   657
  and     c: "\<Delta> extends \<Gamma>"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   658
  shows "\<Delta> \<turnstile> S <: T"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   659
  using a b c 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   660
proof (nominal_induct \<Gamma> S T avoiding: \<Delta> rule: subtype_of_rel_induct)
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   661
  case (S_Top \<Gamma> S) thus ?case by (force intro: extends_closed)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   662
next 
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   663
  case (S_Var \<Gamma> X S T) thus ?case by (force simp add: extends_def)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   664
next
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   665
  case (S_Refl \<Gamma> X) thus ?case by (force dest: extends_domain)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   666
next 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   667
  case S_Arrow thus ?case by force
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   668
next
18305
a780f9c1538b changed everything until the interesting transitivity_narrowing
urbanc
parents: 18269
diff changeset
   669
  case (S_All \<Gamma> X S1 S2 T1 T2)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   670
  have fresh: "X\<sharp>\<Delta>" by fact
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   671
  have ih1: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends \<Gamma> \<Longrightarrow> \<Delta> \<turnstile> T1 <: S1" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   672
  have ih2: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends ((X,T1)#\<Gamma>) \<Longrightarrow> \<Delta> \<turnstile> S2 <: T2" by fact
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   673
  have lh_drv_prem: "\<Gamma> \<turnstile> T1 <: S1" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   674
  hence b5: "T1 closed_in \<Gamma>" by (simp add: subtype_implies_closed) 
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   675
  have ok: "\<turnstile> \<Delta> ok" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   676
  have extends: "\<Delta> extends \<Gamma>" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   677
  have "T1 closed_in \<Delta>" using extends b5 by (simp only: extends_closed)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   678
  hence "\<turnstile> ((X,T1)#\<Delta>) ok" using fresh ok by force   
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   679
  moreover 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   680
  have "((X,T1)#\<Delta>) extends ((X,T1)#\<Gamma>)" using extends by (force simp add: extends_def)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   681
  ultimately have "((X,T1)#\<Delta>) \<turnstile> S2 <: T2" using ih2 by simp
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   682
  moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   683
  have "\<Delta> \<turnstile> T1 <: S1" using ok extends ih1 by simp 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   684
  ultimately show "\<Delta> \<turnstile> \<forall> [X<:S1].S2 <: \<forall> [X<:T1].T2" using ok by (force intro: S_All) 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   685
qed
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   686
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   687
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   688
lemma transitivity_and_narrowing:
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   689
  shows "\<Gamma> \<turnstile> S <: Q \<Longrightarrow> \<Gamma> \<turnstile> Q <: T \<Longrightarrow> \<Gamma> \<turnstile> S <: T"
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   690
  and   "(\<Delta>@(X,Q)#\<Gamma>) \<turnstile> M <: N \<Longrightarrow> \<Gamma> \<turnstile> P <: Q \<Longrightarrow> (\<Delta>@(X,P)#\<Gamma>) \<turnstile> M <: N"
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   691
proof (induct Q fixing: \<Gamma> S T and \<Delta> \<Gamma> X P M N taking: "size_ty" rule: measure_induct_rule)
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   692
  case (less Q)
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   693
  note  IH1_outer = less[THEN conjunct1, rule_format]
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   694
    and IH2_outer = less[THEN conjunct2, THEN spec, of _ "[]", simplified, rule_format]
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   695
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   696
  have transitivity: 
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   697
    "\<And>\<Gamma> S T. \<Gamma> \<turnstile> S <: Q \<Longrightarrow> \<Gamma> \<turnstile> Q <: T \<Longrightarrow> \<Gamma> \<turnstile> S <: T"
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   698
  proof - 
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   699
    
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   700
  -- {* We first handle the case where T = Top once and for all; this saves some 
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   701
        repeated argument below (just like on paper :-).  We establish a little lemma
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   702
        that is invoked where needed in each case of the induction. *} 
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   703
    have top_case: 
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   704
      "\<And>\<Gamma> S T' P. \<lbrakk>\<turnstile> \<Gamma> ok; S closed_in \<Gamma>; P \<Longrightarrow> \<Gamma> \<turnstile> S <: T'; T'=Top \<or> P\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> S <: T'"
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   705
    proof - 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   706
      fix \<Gamma> S T' P
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   707
      assume S_Top_prem1: "S closed_in \<Gamma>"
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   708
	and  S_Top_prem2: "\<turnstile> \<Gamma> ok"
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   709
	and  alternative: "P \<Longrightarrow> \<Gamma> \<turnstile> S <: T'" 
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   710
	and  "T'=Top \<or> P" 
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   711
      moreover
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   712
      { assume "T'=Top"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   713
	hence "\<Gamma> \<turnstile> S <: T'" using S_Top_prem1 S_Top_prem2 by (simp add: S_Top)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   714
      } 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   715
      moreover 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   716
      { assume P 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   717
	with alternative have "\<Gamma> \<turnstile> S <: T'" by simp 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   718
      }
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   719
      ultimately show "\<Gamma> \<turnstile> S <: T'" by blast
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   720
    qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   721
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   722
    (* Now proceed by induction on the left-hand derivation *)
18306
a28269045ff0 started to change the transitivity/narrowing case:
urbanc
parents: 18305
diff changeset
   723
    fix \<Gamma> S T
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   724
    assume a: "\<Gamma> \<turnstile> S <: Q" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   725
    assume b: "\<Gamma> \<turnstile> Q <: T"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   726
    from a b show "\<Gamma> \<turnstile> S <: T"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   727
    proof(nominal_induct \<Gamma> S Q\<equiv>Q avoiding: \<Gamma> S T rule: subtype_of_rel_induct)
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   728
      case (S_Top \<Gamma>1 S1) --{* lh drv.: @{term "\<Gamma> \<turnstile> S <: Q \<equiv> \<Gamma>1 \<turnstile> S1 <: Top"} *}
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   729
      have lh_drv_prem1: "\<turnstile> \<Gamma>1 ok" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   730
      have lh_drv_prem2: "S1 closed_in \<Gamma>1" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   731
      have Q_inst: "Top=Q" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   732
      have rh_drv: "\<Gamma>1 \<turnstile> Q <: T" --"rh drv." by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   733
      hence "T = Top" using Q_inst by (simp add: S_TopE)
18417
149cc4126997 there was a small error in the last commit - fixed now
urbanc
parents: 18416
diff changeset
   734
      thus "\<Gamma>1 \<turnstile> S1 <: T" using top_case[of "\<Gamma>1" "S1" "False" "T"] lh_drv_prem1 lh_drv_prem2 by blast
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   735
    next
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   736
      case (S_Var \<Gamma>1 X1 S1 T1) --{* lh drv.: @{term "\<Gamma> \<turnstile> S <: Q \<equiv> \<Gamma>1 \<turnstile> TVar(X1) <: S1"} *}
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   737
      have lh_drv_prem1: "\<turnstile> \<Gamma>1 ok" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   738
      have lh_drv_prem2: "(X1,S1)\<in>set \<Gamma>1" by fact
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   739
      have IH_inner: "\<And>T. \<Gamma>1 \<turnstile> Q <: T \<Longrightarrow> T1=Q \<Longrightarrow> \<Gamma>1 \<turnstile> S1 <: T" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   740
      have Q_inst: "T1=Q" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   741
      have rh_drv: "\<Gamma>1 \<turnstile> Q <: T" by fact 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   742
      with IH_inner have "\<Gamma>1 \<turnstile> S1 <: T" using Q_inst by simp
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   743
      thus "\<Gamma>1 \<turnstile> TyVar X1 <: T" using lh_drv_prem1 lh_drv_prem2 by (simp add: subtype_of_rel.S_Var)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   744
    next
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   745
      case S_Refl --{* @{text S_Refl} case *} 
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   746
	thus ?case by simp
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   747
    next
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   748
      case (S_Arrow \<Gamma>1 S1 S2 T1 T2) --{* lh drv.: @{term "\<Gamma> \<turnstile> S <: Q \<equiv> \<Gamma>1 \<turnstile> S1 \<rightarrow> S2 <: T1 \<rightarrow> T2"} *}
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   749
      have lh_drv_prem1: "\<Gamma>1 \<turnstile> T1 <: S1" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   750
      have lh_drv_prem2: "\<Gamma>1 \<turnstile> S2 <: T2" by fact
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   751
      have rh_deriv: "\<Gamma>1 \<turnstile> Q <: T" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   752
      have Q_inst: "T1 \<rightarrow> T2 = Q" by fact
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   753
      have measure: "size_ty T1 < size_ty Q" "size_ty T2 < size_ty Q " using Q_inst by force+
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   754
      have "S1 closed_in \<Gamma>1" and "S2 closed_in \<Gamma>1" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   755
	using lh_drv_prem1 lh_drv_prem2 by (simp_all add: subtype_implies_closed)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   756
      hence "(S1 \<rightarrow> S2) closed_in \<Gamma>1" by (simp add: closed_in_def ty.supp)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   757
      moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   758
      have "\<turnstile> \<Gamma>1 ok" using rh_deriv by (rule subtype_implies_ok)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   759
      moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   760
      have "T = Top \<or> (\<exists>T3 T4.  T= T3 \<rightarrow> T4 \<and> \<Gamma>1 \<turnstile> T3 <: T1 \<and> \<Gamma>1 \<turnstile> T2 <: T4)" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   761
	using rh_deriv Q_inst by (simp add:S_ArrowE_left)  
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   762
      moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   763
      { assume "\<exists>T3 T4. T= T3 \<rightarrow> T4 \<and> \<Gamma>1 \<turnstile> T3 <: T1 \<and> \<Gamma>1 \<turnstile> T2 <: T4"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   764
	then obtain T3 T4 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   765
	  where T_inst: "T= T3 \<rightarrow> T4" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   766
	  and   rh_drv_prem1: "\<Gamma>1 \<turnstile> T3 <: T1"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   767
	  and   rh_drv_prem2: "\<Gamma>1 \<turnstile> T2 <: T4" by force
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   768
        from IH1_outer[of "T1"] have "\<Gamma>1 \<turnstile> T3 <: S1" using measure rh_drv_prem1 lh_drv_prem1 by blast
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   769
	moreover
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   770
	from IH1_outer[of "T2"] have "\<Gamma>1 \<turnstile> S2 <: T4" using measure rh_drv_prem2 lh_drv_prem2 by blast
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   771
	ultimately have "\<Gamma>1 \<turnstile> S1 \<rightarrow> S2 <: T" using T_inst by force
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   772
      }
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   773
      ultimately show "\<Gamma>1 \<turnstile> S1 \<rightarrow> S2 <: T" using top_case[of "\<Gamma>1" "S1\<rightarrow>S2" _ "T'"] by blast
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   774
    next
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   775
      case (S_All \<Gamma>1 X S1 S2 T1 T2) --{* lh drv.: @{term "\<Gamma>\<turnstile>S<:Q \<equiv> \<Gamma>1\<turnstile>\<forall>[X<:S1].S2 <: \<forall>[X<:T1].T2"} *} 
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   776
      have lh_drv_prem1: "\<Gamma>1 \<turnstile> T1 <: S1" by fact
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   777
      have lh_drv_prem2: "((X,T1)#\<Gamma>1) \<turnstile> S2 <: T2" by fact
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   778
      have rh_deriv: "\<Gamma>1 \<turnstile> Q <: T" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   779
      have fresh_cond: "X\<sharp>\<Gamma>1" "X\<sharp>S1" "X\<sharp>T1" by fact
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   780
      have Q_inst: "\<forall>[X<:T1].T2 = Q" by fact
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   781
      have measure: "size_ty T1 < size_ty Q" "size_ty T2 < size_ty Q " using Q_inst by force+
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   782
      have "S1 closed_in \<Gamma>1" and "S2 closed_in ((X,T1)#\<Gamma>1)" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   783
	using lh_drv_prem1 lh_drv_prem2 by (simp_all add: subtype_implies_closed)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   784
      hence "(\<forall>[X<:S1].S2) closed_in \<Gamma>1" by (force simp add: closed_in_def ty.supp abs_supp)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   785
      moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   786
      have "\<turnstile> \<Gamma>1 ok" using rh_deriv by (rule subtype_implies_ok)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   787
      moreover
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   788
        (* FIX: Maybe T3,T4 could be T1',T2' *)
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   789
      have "T = Top \<or> (\<exists>T3 T4. T=\<forall>[X<:T3].T4 \<and> \<Gamma>1 \<turnstile> T3 <: T1 \<and> ((X,T3)#\<Gamma>1) \<turnstile> T2 <: T4)" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   790
	using rh_deriv fresh_cond Q_inst by (auto dest: S_AllE_left simp add: fresh_prod)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   791
      moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   792
      { assume "\<exists>T3 T4. T=\<forall>[X<:T3].T4 \<and> \<Gamma>1 \<turnstile> T3 <: T1 \<and> ((X,T3)#\<Gamma>1) \<turnstile> T2 <: T4"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   793
	then obtain T3 T4 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   794
	  where T_inst: "T= \<forall>[X<:T3].T4" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   795
	  and   rh_drv_prem1: "\<Gamma>1 \<turnstile> T3 <: T1" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   796
	  and   rh_drv_prem2:"((X,T3)#\<Gamma>1) \<turnstile> T2 <: T4" by force
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   797
        from IH1_outer[of "T1"] have "\<Gamma>1 \<turnstile> T3 <: S1" 
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   798
	  using lh_drv_prem1 rh_drv_prem1 measure by blast
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   799
        moreover
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   800
	from IH2_outer[of "T1"] have "((X,T3)#\<Gamma>1) \<turnstile> S2 <: T2" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   801
	  using measure lh_drv_prem2 rh_drv_prem1 by force
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   802
	with IH1_outer[of "T2"] have "((X,T3)#\<Gamma>1) \<turnstile> S2 <: T4" 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   803
	  using measure rh_drv_prem2 by force
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   804
        moreover
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   805
	ultimately have "\<Gamma>1 \<turnstile> \<forall>[X<:S1].S2 <: T"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   806
	  using fresh_cond T_inst by (simp add: fresh_prod subtype_of_rel.S_All)
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   807
      }
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   808
      ultimately show "\<Gamma>1 \<turnstile> \<forall>[X<:S1].S2 <: T" using Q_inst top_case[of "\<Gamma>1" "\<forall>[X<:S1].S2" _ "T'"] 
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   809
	by auto
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   810
    qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   811
  qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   812
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   813
  have narrowing:
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   814
    "\<And>\<Delta> \<Gamma> X M N P. (\<Delta>@(X,Q)#\<Gamma>) \<turnstile> M <: N \<Longrightarrow> \<Gamma> \<turnstile> P<:Q \<Longrightarrow> (\<Delta>@(X,P)#\<Gamma>) \<turnstile> M <: N"
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   815
  proof -
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   816
    fix \<Delta> \<Gamma> X M N P
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   817
    assume a: "(\<Delta>@(X,Q)#\<Gamma>) \<turnstile> M <: N"
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   818
    assume b: "\<Gamma> \<turnstile> P<:Q"
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   819
    show "(\<Delta>@(X,P)#\<Gamma>) \<turnstile> M <: N"
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   820
      using a b 
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   821
    proof (nominal_induct \<Gamma>\<equiv>"\<Delta>@(X,Q)#\<Gamma>" M N avoiding: \<Delta> \<Gamma> X rule: subtype_of_rel_induct) 
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   822
      case (S_Top \<Gamma>1 S1 \<Delta> \<Gamma>2 X)
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   823
      then have lh_drv_prem1: "\<turnstile> (\<Delta>@(X,Q)#\<Gamma>2) ok" 
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   824
           and  lh_drv_prem2: "S1 closed_in (\<Delta>@(X,Q)#\<Gamma>2)" by (simp_all only:)
18353
4dd468ccfdf7 transitivity should be now in a reasonable state. But
urbanc
parents: 18306
diff changeset
   825
      have rh_drv: "\<Gamma>2 \<turnstile> P <: Q" by fact
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   826
      hence "P closed_in \<Gamma>2" by (simp add: subtype_implies_closed)
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   827
      with lh_drv_prem1 have "\<turnstile> (\<Delta>@(X,P)#\<Gamma>2) ok" by (simp only: replace_type)
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   828
      moreover
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   829
      from lh_drv_prem2 have "S1 closed_in (\<Delta>@(X,P)#\<Gamma>2)" by (simp add: closed_in_def domain_append)
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   830
      ultimately show "(\<Delta>@(X,P)#\<Gamma>2) \<turnstile> S1 <: Top" by (rule subtype_of_rel.S_Top)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   831
    next
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   832
      case (S_Var \<Gamma>1 X1 S1 T1 \<Delta> \<Gamma>2 X)
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   833
      then have lh_drv_prem1: "\<turnstile> (\<Delta>@(X,Q)#\<Gamma>2) ok" 
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   834
           and  lh_drv_prem2: "(X1,S1)\<in>set (\<Delta>@(X,Q)#\<Gamma>2)" 
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   835
           and  lh_drv_prem3: "(\<Delta>@(X,Q)#\<Gamma>2) \<turnstile> S1 <: T1" 
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   836
           and  IH_inner: "\<Gamma>2 \<turnstile> P <: Q \<Longrightarrow> (\<Delta>@(X,P)#\<Gamma>2) \<turnstile> S1 <: T1" by (simp_all only:)
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   837
      have rh_drv: "\<Gamma>2 \<turnstile> P <: Q" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   838
      hence "P closed_in \<Gamma>2" by (simp add: subtype_implies_closed)
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   839
      hence a3: "\<turnstile> (\<Delta>@(X,P)#\<Gamma>2) ok" using lh_drv_prem1 by (simp only: replace_type)
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   840
      show "(\<Delta>@(X,P)#\<Gamma>2) \<turnstile> TyVar X1 <: T1"
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   841
      proof (cases "X=X1")
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   842
	case False
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   843
	have b0: "X\<noteq>X1" by fact
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   844
	from lh_drv_prem3 rh_drv IH_inner 
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   845
	have b1: "(\<Delta>@(X,P)#\<Gamma>2) \<turnstile> S1 <: T1" by simp
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   846
	from lh_drv_prem2 b0 have b2: "(X1,S1)\<in>set (\<Delta>@(X,P)#\<Gamma>2)" by simp
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   847
	show "(\<Delta>@(X,P)#\<Gamma>2) \<turnstile> TyVar X1 <: T1" using a3 b2 b1 by (rule subtype_of_rel.S_Var)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   848
      next 
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   849
	case True
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   850
	have b0: "X=X1" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   851
	have a4: "S1=Q"
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   852
	proof -
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   853
	  have "(X1,Q)\<in>set (\<Delta>@(X,Q)#\<Gamma>2)" using b0 by simp
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   854
	  with lh_drv_prem1 lh_drv_prem2 show "S1=Q" by (blast intro: uniqueness_of_ctxt)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   855
	qed
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   856
	have a5: "(\<Delta>@(X,P)#\<Gamma>2) extends \<Gamma>2" by (force simp add: extends_def)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   857
	have a6: "(\<Delta>@(X1,P)#\<Gamma>2) \<turnstile> P <: Q" using b0 a5 rh_drv a3 by (simp add: weakening)	
18412
9f6b3e1da352 tuned the proof of transitivity/narrowing
urbanc
parents: 18410
diff changeset
   858
	have a7: "(\<Delta>@(X1,P)#\<Gamma>2) \<turnstile> Q <: T1" using b0 IH_inner lh_drv_prem3 rh_drv a4 by simp
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   859
	have a8: "(\<Delta>@(X1,P)#\<Gamma>2) \<turnstile> P <: T1" using a6 a7 transitivity by blast
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   860
	have a9: "(X1,P)\<in>set (\<Delta>@(X,P)#\<Gamma>2)" using b0 by simp
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   861
	show "(\<Delta>@(X,P)#\<Gamma>2) \<turnstile> TyVar X1 <: T1" using a3 b0 a8 a9 by force
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   862
      qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   863
    next
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   864
      case (S_Refl \<Gamma>1 X1 \<Delta> \<Gamma>2 X)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   865
      have lh_drv_prem1: "\<turnstile> \<Gamma>1 ok" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   866
      have lh_drv_prem2: "X1 \<in> domain \<Gamma>1" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   867
      have \<Gamma>1_inst: "\<Gamma>1 = \<Delta>@(X,Q)#\<Gamma>2" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   868
      have "\<Gamma>2 \<turnstile> P <: Q" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   869
      hence "P closed_in \<Gamma>2" by (simp add: subtype_implies_closed)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   870
      hence a3: "\<turnstile> (\<Delta>@(X,P)#\<Gamma>2) ok" using lh_drv_prem1 \<Gamma>1_inst by (simp add: replace_type)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   871
      have b0: "X1 \<in> domain (\<Delta>@(X,P)#\<Gamma>2)" using lh_drv_prem2 \<Gamma>1_inst by (simp add: domain_append)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   872
      show "(\<Delta>@(X,P)#\<Gamma>2) \<turnstile> TyVar X1 <: TyVar X1" using a3 b0 by (rule subtype_of_rel.S_Refl)
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   873
    next
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   874
      case S_Arrow thus ?case by blast
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   875
    next
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   876
      case (S_All \<Gamma>1 X1 S1 S2 T1 T2 \<Delta> \<Gamma>2 X)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   877
      have IH_inner1: "\<And>\<Delta> \<Gamma> X. \<Gamma> \<turnstile> P <: Q \<Longrightarrow> \<Gamma>1 = \<Delta>@(X,Q)#\<Gamma> \<Longrightarrow> (\<Delta>@(X,P)#\<Gamma>) \<turnstile> T1 <: S1" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   878
      have IH_inner2: "\<And>\<Delta> \<Gamma> X. \<Gamma> \<turnstile> P <: Q \<Longrightarrow> (X1,T1)#\<Gamma>1 = \<Delta>@(X,Q)#\<Gamma> \<Longrightarrow> (\<Delta>@(X,P)#\<Gamma>) \<turnstile> S2 <: T2" 
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   879
	by fact
18410
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   880
      have lh_drv_prem1: "\<Gamma>1 \<turnstile> T1 <: S1" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   881
      have lh_drv_prem2: "X1\<sharp>\<Gamma>1" "X1\<sharp>S1" "X1\<sharp>T1" by fact (* check this whether this is the lh_drv_p2 *)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   882
      have lh_drv_prem3: "((X1,T1)#\<Gamma>1) \<turnstile> S2 <: T2" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   883
      have \<Gamma>1_inst: "\<Gamma>1 = \<Delta>@(X,Q)#\<Gamma>2" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   884
      have a2: "\<Gamma>2 \<turnstile> P <: Q" by fact
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   885
      have b0: "(\<Delta>@(X,P)#\<Gamma>2) \<turnstile> T1 <: S1" using \<Gamma>1_inst a2 lh_drv_prem1 IH_inner1 by simp
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   886
      have b1: "(((X1,T1)#\<Delta>)@(X,P)#\<Gamma>2) \<turnstile> S2 <: T2" using \<Gamma>1_inst a2 lh_drv_prem3 IH_inner2
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   887
	apply(auto)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   888
	apply(drule_tac x="\<Gamma>2" in meta_spec)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   889
	apply(drule_tac x="(X1,T1)#\<Delta>" in meta_spec)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   890
	apply(auto)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   891
	done
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   892
      have b3: "X1\<sharp>(\<Delta>@(X,P)#\<Gamma>2)" using lh_drv_prem2 \<Gamma>1_inst a2
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   893
	by (auto simp add: fresh_prod fresh_list_append fresh_list_cons dest: subtype_implies_fresh)
73bb08d2823c made further tunings
urbanc
parents: 18353
diff changeset
   894
      show "(\<Delta>@(X,P)#\<Gamma>2) \<turnstile> \<forall> [X1<:S1].S2 <: \<forall> [X1<:T1].T2" using b0 b3 b1 by force 
18246
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   895
    qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   896
  qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   897
  from transitivity narrowing show ?case by blast 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   898
qed
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   899
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   900
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   901
 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   902
section {* Terms *}
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   903
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   904
nominal_datatype trm = Var   "vrs"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   905
                     | Lam   "\<guillemotleft>vrs\<guillemotright>trm" "ty"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   906
                     | TAbs  "\<guillemotleft>tyvrs\<guillemotright>trm" "ty"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   907
                     | App   "trm" "trm"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   908
                     | TApp  "trm" "ty"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   909
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   910
consts
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   911
  Lam_syn   :: "vrs \<Rightarrow> ty \<Rightarrow> trm \<Rightarrow> trm"   ("Lam [_:_]._" [100,100,100] 100)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   912
  TAbs_syn  :: "tyvrs \<Rightarrow> ty \<Rightarrow> trm \<Rightarrow> trm" ("TAbs [_<:_]._" [100,100,100] 100)
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   913
translations 
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   914
  "Lam  [a:tys].t" \<rightleftharpoons> "trm.Lam a t tys"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   915
  "TAbs [a<:tys].t" \<rightleftharpoons> "trm.TAbs a t tys"
676d2e625d98 added fsub.thy (poplmark challenge) to the examples
urbanc
parents:
diff changeset
   916
18416
32833aae901f tuned more proof and added in-file documentation
urbanc
parents: 18412
diff changeset
   917
end