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