Sub子类型化
Set Warnings "-notation-overridden,-parsing,-deprecated-hint-without-locality".
From Stdlib Require Import Strings.String.
From PLF Require Import Maps.
From PLF Require Import Types.
From PLF Require Import Smallstep.
Set Default Goal Selector "!".
From Stdlib Require Import Strings.String.
From PLF Require Import Maps.
From PLF Require Import Types.
From PLF Require Import Smallstep.
Set Default Goal Selector "!".
引子
Person = {name:String, age:Nat}
Student = {name:String, age:Nat, gpa:Nat}
(\r:Person, (r.age)+1) {name="Pat",age=21,gpa=1}
是不可定型的。它把一个想要两字段记录的函数,应用于一个实际
提供了三字段的实参。而 T_App 规则要求:被应用函数的
【定义域类型|Domain Type】必须与实参的类型精确匹配。
- S 是 T 的【子类型|Subtype】,记作 S <: T,如果 类型 S 的值可以安全地用于任何期望类型 T 的值的 上下文。
子类型化与面向对象语言
包含规则
- 定义类型之间的二元【子类型关系|Subtype Relation】。
- 丰富【定型关系|Typing Relation】,使其考虑子类型化。
| Gamma |-- t1 ∈ T1 T1 <: T2 | (T_Sub) |
| Gamma |-- t1 ∈ T2 |
子类型关系
结构规则
| S <: U U <: T | (S_Trans) |
| S <: T |
| (S_Refl) | |
| T <: T |
积类型
| S1 <: T1 S2 <: T2 | (S_Prod) |
| S1 * S2 <: T1 * T2 |
箭头类型
f : C → Student
g : (C→Person) → D f 是一个产生 Student 类型记录的函数。 g 是一个(高阶)函数,它期望实参是一个产生 Person 类型 记录的函数。 再假设 Student 是 Person 的子类型。 那么应用 g f 是安全的,尽管它们的类型并不精确匹配。 g 对 f 唯一能做的事,就是把它应用于某个(C 类型的) 实参。结果实际上会是一个 Student,而 g 期望的是 Person。 但这是安全的:g 接下来唯一能做的,就是投影出它知道的 两个字段(name 和 age)。这些字段当然会出现在实际的 字段之中。
| S2 <: T2 | (S_Arrow_Co) |
| S1 -> S2 <: S1 -> T2 |
| T1 <: S1 S2 <: T2 | (S_Arrow) |
| S1 -> S2 <: T1 -> T2 |
f : Person → C
g : (Student → C) → D 应用 g f 是安全的。g 的函数体对 f 唯一能做的, 就是把它应用于某个 Student 类型的实参。 由于 f 要求记录至少具有 Person 的字段,这总是行得通。 所以 Person → C 是 Student → C 的子类型, 因为 Student 是 Person 的子类型。
记录
{name:String, age:Nat, gpa:Nat} <: {name:String, age:Nat}
{name:String, age:Nat} <: {name:String}
{name:String} <: {} 这就是记录的所谓「宽度子类型化」。
{x:Student} <: {x:Person} 这就是所谓的「深度子类型化」。
{name:String,age:Nat} <: {age:Nat,name:String} 这就是所谓的「排列子类型化」。
| forall jk in j1..jn, | |
| exists ip in i1..im, such that | |
| jk=ip and Sp <: Tk | (S_Rcd) |
| {i1:S1...im:Sm} <: {j1:T1...jn:Tn} |
| n > m | (S_RcdWidth) |
| {i1:T1...in:Tn} <: {i1:T1...im:Tm} |
| S1 <: T1 ... Sn <: Tn | (S_RcdDepth) |
| {i1:S1...in:Sn} <: {i1:T1...in:Tn} |
| {i1:S1...in:Sn} is a permutation of {j1:T1...jn:Tn} | (S_RcdPerm) |
| {i1:S1...in:Sn} <: {j1:T1...jn:Tn} |
- 每个类成员(字段或方法)可以分配一个单一索引。
随着子类中添加更多成员,会在「右边」添加新索引
(即类不允许排列)。
- 一个类可以实现多个接口,即所谓的接口「多重继承」
(即接口允许排列)。
- 在早期版本的 Java 中,子类不能改变其超类方法的参数或 结果类型(即没有深度子类型化,或没有箭头子类型化, 取决于你怎么看)。
练习: 2 stars,高级,特别有用 (arrow_sub_wrong)
假设我们错误地把子类型化定义为在箭头类型左右两侧都是 协变的:| S1 <: T1 S2 <: T2 | (S_Arrow_wrong) |
| S1 -> S2 <: T1 -> T2 |
f : Student → Nat
g : (Person → Nat) → Nat ……使得应用 g f 在执行期间会卡住。(使用非形式化语法。 无需形式化地证明该应用会卡住。)
Top
| (S_Top) | |
| S <: Top |
小结
- 添加基类型 Top,
- 给定型关系添加包含规则
,以及Gamma |-- t1 ∈ T1 T1 <: T2 (T_Sub) Gamma |-- t1 ∈ T2 - 按如下方式定义子类型关系:
S <: U U <: T (S_Trans) S <: T (S_Refl) T <: T (S_Top) S <: Top S1 <: T1 S2 <: T2 (S_Prod) S1 * S2 <: T1 * T2 T1 <: S1 S2 <: T2 (S_Arrow) S1 -> S2 <: T1 -> T2 n > m (S_RcdWidth) {i1:T1...in:Tn} <: {i1:T1...im:Tm} S1 <: T1 ... Sn <: Tn (S_RcdDepth) {i1:S1...in:Sn} <: {i1:T1...in:Tn} {i1:S1...in:Sn} is a permutation of {j1:T1...jn:Tn} (S_RcdPerm) {i1:S1...in:Sn} <: {j1:T1...jn:Tn}
习题
练习: 1 star,标准,可选 (subtype_instances_tf_1)
假设我们有类型 S、T、U 和 V,满足 S <: T 和 U <: V。下列子类型断言哪些为真?在每条后面写 true 或 false。(这里的 A、B 和 C 是像 Bool、Nat 等 那样的基类型。)- T→S <: T→S
- Top→U <: S→Top
- (C→C) → (A×B) <: (C→C) → (Top×B)
- T→T→U <: S→S→V
- (T→T)->U <: (S→S)->V
- ((T→S)->T)->U <: ((S→T)->S)->V
- S×V <: T×U
练习: 2 stars,标准 (subtype_order)
下列类型关于子类型化恰好构成一个线性序:- Top
- Top → Student
- Student → Person
- Student → Top
- Person → Student
练习: 1 star,标准 (subtype_instances_tf_2)
下列语句哪些为真?在每条后面写 true 或 false。∀ S T,
S <: T →
S→S <: T→T
∀ S,
S <: A→A →
∃ T,
S = T→T ∧ T <: A
∀ S T1 T2,
(S <: T1 → T2) →
∃ S1 S2,
S = S1 → S2 ∧ T1 <: S1 ∧ S2 <: T2
∃ S,
S <: S→S
∃ S,
S→S <: S
∀ S T1 T2,
S <: T1×T2 →
∃ S1 S2,
S = S1×S2 ∧ S1 <: T1 ∧ S2 <: T2
练习: 1 star,标准 (subtype_concepts_tf)
下列语句哪些为真,哪些为假?- 存在一个类型,它是其它每个类型的超类型。
- 存在一个类型,它是其它每个类型的子类型。
- 存在一个序对类型,它是其它每个序对类型的超类型。
- 存在一个序对类型,它是其它每个序对类型的子类型。
- 存在一个箭头类型,它是其它每个箭头类型的超类型。
- 存在一个箭头类型,它是其它每个箭头类型的子类型。
- 在子类型关系中存在一条由互不相同的类型构成的无穷下降
链,即一列类型 S0、S1 等,使得所有 Si 互不相同,
且每个 S(i+1) 都是 Si 的子类型。
- 在子类型关系中存在一条由互不相同的类型构成的无穷【上升】 链,即一列类型 S0、S1 等,使得所有 Si 互不相同, 且每个 S(i+1) 都是 Si 的超类型。
练习: 2 stars,标准 (proper_subtypes)
下列语句是真的还是假的?简要解释你的答案。(这里 Base n 代表一个基类型,其中 n 是代表基类型名称的字符串。参见 下面的语法一节。)∀ T,
~(T = Bool ∨ ∃ n, T = Base n) →
∃ S,
S <: T ∧ S ≠ T
练习: 2 stars,标准 (small_large_1)
- 使下列断言为真的【最小】类型 T(「最小」指关于子类型
关系)是什么?(假设基类型中有 Unit,并有作为该类型
常量的 unit。)
empty |-- (\p:T×Top, p.fst) ((\z:A,z), unit) \in A→A - 使同一断言为真的【最大】类型 T 是什么?
练习: 2 stars,标准 (small_large_2)
- 使下列断言为真的【最小】类型 T 是什么?
empty |-- (\p:(A→A × B→B), p) ((\z:A,z), (\z:B,z)) \in T - 使同一断言为真的【最大】类型 T 是什么?
练习: 2 stars,标准,可选 (small_large_3)
- 使下列断言为真的【最小】类型 T 是什么?
a:A |-- (\p:(A×T), (p.snd) (p.fst)) (a, \z:A,z) \in A - 使同一断言为真的【最大】类型 T 是什么?
练习: 2 stars,标准 (small_large_4)
- 使下列断言为真的【最小】类型 T(如果存在)是什么?
∃ S,
empty |-- (\p:(A×T), (p.snd) (p.fst)) \in S - 使同一断言为真的【最大】类型 T 是什么?
练习: 2 stars,标准 (smallest_2)
使下列断言为真的【最小】类型 T 是什么?empty |-- (\x:Top, x) ((\z:A,z) , (\z:B,z)) \in T
练习: 3 stars,标准,可选 (count_supertypes)
记录类型 {x:A, y:C→C} 有多少个超类型? 也就是满足 {x:A, y:C→C} <: T 的不同类型 T 有多少个? (如果两个类型写法不同,即使它们互为子类型,我们也视为不同的。 例如 {x:A,y:B} 和 {y:B,x:A} 是不同的。)练习: 2 stars,标准 (pair_permutation)
积类型的子类型规则| S1 <: T1 S2 <: T2 | (S_Prod) |
| S1*S2 <: T1*T2 |
| T1*T2 <: T2*T1 |
形式化上面讨论所需的大部分定义,尤其是语言的语法和操作
语义,与上一章所见的完全相同。我们只需要用包含规则扩展
定型关系,并为子类型关系添加新的 Inductive 定义。
先做相同的部分。
我们把积纳入类型和项的语法,但暂时不纳入其它任何地方。
下面的 products 习题会要求你扩展值关系、操作语义、
子类型关系和定型关系的定义,并扩展【进展|Progress】与
【保持|Preservation】的证明,以完全支持积。
语法
Inductive ty : Type :=
| Ty_Top : ty
| Ty_Bool : ty
| Ty_Base : string → ty
| Ty_Arrow : ty → ty → ty
| Ty_Unit : ty
| Ty_Prod : ty → ty → ty
.
Inductive tm : Type :=
| tm_var : string → tm
| tm_app : tm → tm → tm
| tm_abs : string → ty → tm → tm
| tm_true : tm
| tm_false : tm
| tm_if : tm → tm → tm → tm
| tm_unit : tm
| tm_pair : tm → tm → tm
| tm_fst : tm → tm
| tm_snd : tm → tm
.
Declare Custom Entry stlc_ty.
Declare Custom Entry stlc_tm.
Declare Scope stlc_scope.
Open Scope stlc_scope.
Notation "x" := x (in custom stlc_ty at level 0, x global) : stlc_scope.
Notation "<{{ x }}>" := x (x custom stlc_ty).
Notation "( t )" := t (in custom stlc_ty at level 0, t custom stlc_ty) : stlc_scope.
Notation "S -> T" := (Ty_Arrow S T) (in custom stlc_ty at level 99, right associativity) : stlc_scope.
Notation "$( t )" := t (in custom stlc_ty at level 0, t constr) : stlc_scope.
Notation "$( x )" := x (in custom stlc_tm at level 0, x constr, only parsing) : stlc_scope.
Notation "x" := x (in custom stlc_tm at level 0, x constr at level 0) : stlc_scope.
Notation "<{ e }>" := e (e custom stlc_tm at level 200) : stlc_scope.
Notation "( x )" := x (in custom stlc_tm at level 0, x custom stlc_tm) : stlc_scope.
Notation "x y" := (tm_app x y) (in custom stlc_tm at level 10, left associativity) : stlc_scope.
Notation "\ x : t , y" :=
(tm_abs x t y) (in custom stlc_tm at level 200, x global,
t custom stlc_ty,
y custom stlc_tm at level 200,
left associativity).
Coercion tm_var : string >-> tm.
Arguments tm_var _%_string.
Notation "'Bool'" := Ty_Bool (in custom stlc_ty at level 0) : stlc_scope.
Notation "'if' x 'then' y 'else' z" :=
(tm_if x y z) (in custom stlc_tm at level 200,
x custom stlc_tm,
y custom stlc_tm,
z custom stlc_tm at level 200,
left associativity).
Notation "'true'" := true (at level 1).
Notation "'true'" := tm_true (in custom stlc_tm at level 0).
Notation "'false'" := false (at level 1).
Notation "'false'" := tm_false (in custom stlc_tm at level 0).
Notation "'Base' x" := (Ty_Base x) (in custom stlc_ty at level 0, x constr at level 0) : stlc_scope.
Notation "'Unit'" :=
(Ty_Unit) (in custom stlc_ty at level 0) : stlc_scope.
Notation "'unit'" := tm_unit (in custom stlc_tm at level 0) : stlc_scope.
Notation "X * Y" :=
(Ty_Prod X Y) (in custom stlc_ty at level 2, X custom stlc_ty, Y custom stlc_ty at level 0).
Notation "( x ',' y )" := (tm_pair x y) (in custom stlc_tm at level 0,
x custom stlc_tm,
y custom stlc_tm) : stlc_scope.
Notation "t '.fst'" := (tm_fst t) (in custom stlc_tm at level 1) : stlc_scope.
Notation "t '.snd'" := (tm_snd t) (in custom stlc_tm at level 1) : stlc_scope.
Notation "'Top'" := (Ty_Top) (in custom stlc_ty at level 0) : stlc_scope.
| Ty_Top : ty
| Ty_Bool : ty
| Ty_Base : string → ty
| Ty_Arrow : ty → ty → ty
| Ty_Unit : ty
| Ty_Prod : ty → ty → ty
.
Inductive tm : Type :=
| tm_var : string → tm
| tm_app : tm → tm → tm
| tm_abs : string → ty → tm → tm
| tm_true : tm
| tm_false : tm
| tm_if : tm → tm → tm → tm
| tm_unit : tm
| tm_pair : tm → tm → tm
| tm_fst : tm → tm
| tm_snd : tm → tm
.
Declare Custom Entry stlc_ty.
Declare Custom Entry stlc_tm.
Declare Scope stlc_scope.
Open Scope stlc_scope.
Notation "x" := x (in custom stlc_ty at level 0, x global) : stlc_scope.
Notation "<{{ x }}>" := x (x custom stlc_ty).
Notation "( t )" := t (in custom stlc_ty at level 0, t custom stlc_ty) : stlc_scope.
Notation "S -> T" := (Ty_Arrow S T) (in custom stlc_ty at level 99, right associativity) : stlc_scope.
Notation "$( t )" := t (in custom stlc_ty at level 0, t constr) : stlc_scope.
Notation "$( x )" := x (in custom stlc_tm at level 0, x constr, only parsing) : stlc_scope.
Notation "x" := x (in custom stlc_tm at level 0, x constr at level 0) : stlc_scope.
Notation "<{ e }>" := e (e custom stlc_tm at level 200) : stlc_scope.
Notation "( x )" := x (in custom stlc_tm at level 0, x custom stlc_tm) : stlc_scope.
Notation "x y" := (tm_app x y) (in custom stlc_tm at level 10, left associativity) : stlc_scope.
Notation "\ x : t , y" :=
(tm_abs x t y) (in custom stlc_tm at level 200, x global,
t custom stlc_ty,
y custom stlc_tm at level 200,
left associativity).
Coercion tm_var : string >-> tm.
Arguments tm_var _%_string.
Notation "'Bool'" := Ty_Bool (in custom stlc_ty at level 0) : stlc_scope.
Notation "'if' x 'then' y 'else' z" :=
(tm_if x y z) (in custom stlc_tm at level 200,
x custom stlc_tm,
y custom stlc_tm,
z custom stlc_tm at level 200,
left associativity).
Notation "'true'" := true (at level 1).
Notation "'true'" := tm_true (in custom stlc_tm at level 0).
Notation "'false'" := false (at level 1).
Notation "'false'" := tm_false (in custom stlc_tm at level 0).
Notation "'Base' x" := (Ty_Base x) (in custom stlc_ty at level 0, x constr at level 0) : stlc_scope.
Notation "'Unit'" :=
(Ty_Unit) (in custom stlc_ty at level 0) : stlc_scope.
Notation "'unit'" := tm_unit (in custom stlc_tm at level 0) : stlc_scope.
Notation "X * Y" :=
(Ty_Prod X Y) (in custom stlc_ty at level 2, X custom stlc_ty, Y custom stlc_ty at level 0).
Notation "( x ',' y )" := (tm_pair x y) (in custom stlc_tm at level 0,
x custom stlc_tm,
y custom stlc_tm) : stlc_scope.
Notation "t '.fst'" := (tm_fst t) (in custom stlc_tm at level 1) : stlc_scope.
Notation "t '.snd'" := (tm_snd t) (in custom stlc_tm at level 1) : stlc_scope.
Notation "'Top'" := (Ty_Top) (in custom stlc_ty at level 0) : stlc_scope.
Reserved Notation "'[' x ':=' s ']' t" (in custom stlc_tm at level 5, x global, s custom stlc_tm,
t custom stlc_tm at next level, right associativity).
Fixpoint subst (x : string) (s : tm) (t : tm) : tm :=
match t with
| tm_var y ⇒
if String.eqb x y then s else t
| <{\y:T, t1}> ⇒
if String.eqb x y then t else <{\y:T, [x:=s] t1}>
| <{t1 t2}> ⇒
<{([x:=s] t1) ([x:=s] t2)}>
| <{true}> ⇒
<{true}>
| <{false}> ⇒
<{false}>
| <{if t1 then t2 else t3}> ⇒
<{if ([x:=s] t1) then ([x:=s] t2) else ([x:=s] t3)}>
| <{unit}> ⇒
<{unit}>
| <{ (t1, t2) }> ⇒
<{( [x:=s] t1, [x:=s] t2 )}>
| <{t0.fst}> ⇒
<{ ([x:=s] t0).fst}>
| <{t0.snd}> ⇒
<{ ([x:=s] t0).snd}>
end
where "'[' x ':=' s ']' t" := (subst x s t) (in custom stlc_tm) : stlc_scope.
t custom stlc_tm at next level, right associativity).
Fixpoint subst (x : string) (s : tm) (t : tm) : tm :=
match t with
| tm_var y ⇒
if String.eqb x y then s else t
| <{\y:T, t1}> ⇒
if String.eqb x y then t else <{\y:T, [x:=s] t1}>
| <{t1 t2}> ⇒
<{([x:=s] t1) ([x:=s] t2)}>
| <{true}> ⇒
<{true}>
| <{false}> ⇒
<{false}>
| <{if t1 then t2 else t3}> ⇒
<{if ([x:=s] t1) then ([x:=s] t2) else ([x:=s] t3)}>
| <{unit}> ⇒
<{unit}>
| <{ (t1, t2) }> ⇒
<{( [x:=s] t1, [x:=s] t2 )}>
| <{t0.fst}> ⇒
<{ ([x:=s] t0).fst}>
| <{t0.snd}> ⇒
<{ ([x:=s] t0).snd}>
end
where "'[' x ':=' s ']' t" := (subst x s t) (in custom stlc_tm) : stlc_scope.
Inductive value : tm → Prop :=
| v_abs : ∀ x T2 t1,
value <{\x:T2, t1}>
| v_true :
value <{true}>
| v_false :
value <{false}>
| v_unit :
value <{unit}>
.
Hint Constructors value : core.
Reserved Notation "t '-->' t'" (at level 40).
Inductive step : tm → tm → Prop :=
| ST_AppAbs : ∀ x T2 t1 v2,
value v2 →
<{(\x:T2, t1) v2}> --> <{ [x:=v2]t1 }>
| ST_App1 : ∀ t1 t1' t2,
t1 --> t1' →
<{t1 t2}> --> <{t1' t2}>
| ST_App2 : ∀ v1 t2 t2',
value v1 →
t2 --> t2' →
<{v1 t2}> --> <{v1 t2'}>
| ST_IfTrue : ∀ t1 t2,
<{if true then t1 else t2}> --> t1
| ST_IfFalse : ∀ t1 t2,
<{if false then t1 else t2}> --> t2
| ST_If : ∀ t1 t1' t2 t3,
t1 --> t1' →
<{if t1 then t2 else t3}> --> <{if t1' then t2 else t3}>
where "t '-->' t'" := (step t t').
Hint Constructors step : core.
| v_abs : ∀ x T2 t1,
value <{\x:T2, t1}>
| v_true :
value <{true}>
| v_false :
value <{false}>
| v_unit :
value <{unit}>
.
Hint Constructors value : core.
Reserved Notation "t '-->' t'" (at level 40).
Inductive step : tm → tm → Prop :=
| ST_AppAbs : ∀ x T2 t1 v2,
value v2 →
<{(\x:T2, t1) v2}> --> <{ [x:=v2]t1 }>
| ST_App1 : ∀ t1 t1' t2,
t1 --> t1' →
<{t1 t2}> --> <{t1' t2}>
| ST_App2 : ∀ v1 t2 t2',
value v1 →
t2 --> t2' →
<{v1 t2}> --> <{v1 t2'}>
| ST_IfTrue : ∀ t1 t2,
<{if true then t1 else t2}> --> t1
| ST_IfFalse : ∀ t1 t2,
<{if false then t1 else t2}> --> t2
| ST_If : ∀ t1 t1' t2 t3,
t1 --> t1' →
<{if t1 then t2 else t3}> --> <{if t1' then t2 else t3}>
where "t '-->' t'" := (step t t').
Hint Constructors step : core.
Reserved Notation "T '<:' U" (at level 40).
Inductive subtype : ty → ty → Prop :=
| S_Refl : ∀ T,
T <: T
| S_Trans : ∀ S U T,
S <: U →
U <: T →
S <: T
| S_Top : ∀ S,
S <: <{{ Top }}>
| S_Arrow : ∀ S1 S2 T1 T2,
T1 <: S1 →
S2 <: T2 →
<{{ S1→S2 }}> <: <{{ T1→T2 }}>
where "T '<:' U" := (subtype T U).
Inductive subtype : ty → ty → Prop :=
| S_Refl : ∀ T,
T <: T
| S_Trans : ∀ S U T,
S <: U →
U <: T →
S <: T
| S_Top : ∀ S,
S <: <{{ Top }}>
| S_Arrow : ∀ S1 S2 T1 T2,
T1 <: S1 →
S2 <: T2 →
<{{ S1→S2 }}> <: <{{ T1→T2 }}>
where "T '<:' U" := (subtype T U).
注意,我们不需要为基类型(Bool 和 Base)添加任何特殊
规则:它们通过 S_Refl 自动是自身的子类型。
它们通过 S_Top 自动是 Top 的子类型。
这正是我们想要的全部。
Hint Constructors subtype : core.
Module Examples.
Open Scope string_scope.
Notation x := "x".
Notation y := "y".
Notation z := "z".
Notation A := <{{ Base "A" }}>.
Notation B := <{{ Base "B" }}>.
Notation C := <{{ Base "C" }}>.
Notation String := <{{ Base "String" }}>.
Notation Float := <{{ Base "Float" }}>.
Notation Integer := <{{ Base "Integer" }}>.
Example subtyping_example_0 :
<{{ C→Bool }}> <: <{{ C→Top }}>.
Proof. auto. Qed.
Module Examples.
Open Scope string_scope.
Notation x := "x".
Notation y := "y".
Notation z := "z".
Notation A := <{{ Base "A" }}>.
Notation B := <{{ Base "B" }}>.
Notation C := <{{ Base "C" }}>.
Notation String := <{{ Base "String" }}>.
Notation Float := <{{ Base "Float" }}>.
Notation Integer := <{{ Base "Integer" }}>.
Example subtyping_example_0 :
<{{ C→Bool }}> <: <{{ C→Top }}>.
Proof. auto. Qed.
练习: 2 stars,标准,可选 (subtyping_judgements)
(在你完成给语言添加积类型之前,把本习题留作 Admitted 。参见习题 products,至少到文件的这个位置为止。)Person := { name : String }
Student := { name : String ; gpa : Float }
Employee := { name : String ; ssn : Integer }
Definition Person : ty
(* 将本行替换成 ":= 【你的定义】 ." *). Admitted.
Definition Student : ty
(* 将本行替换成 ":= 【你的定义】 ." *). Admitted.
Definition Employee : ty
(* 将本行替换成 ":= 【你的定义】 ." *). Admitted.
(* 将本行替换成 ":= 【你的定义】 ." *). Admitted.
Definition Student : ty
(* 将本行替换成 ":= 【你的定义】 ." *). Admitted.
Definition Employee : ty
(* 将本行替换成 ":= 【你的定义】 ." *). Admitted.
现在使用子类型关系的定义证明下列事实:
Example sub_student_person :
Student <: Person.
Proof.
(* 在这里填写 *) Admitted.
Example sub_employee_person :
Employee <: Person.
Proof.
(* 在这里填写 *) Admitted.
☐
Student <: Person.
Proof.
(* 在这里填写 *) Admitted.
Example sub_employee_person :
Employee <: Person.
Proof.
(* 在这里填写 *) Admitted.
☐
Example subtyping_example_1 :
<{{ Top→Student }}> <: <{{ (C→C)→Person }}>.
Proof with eauto.
(* 在这里填写 *) Admitted.
☐
<{{ Top→Student }}> <: <{{ (C→C)→Person }}>.
Proof with eauto.
(* 在这里填写 *) Admitted.
☐
Example subtyping_example_2 :
<{{ Top→Person }}> <: <{{ Person→Top }}>.
Proof with eauto.
(* 在这里填写 *) Admitted.
☐
<{{ Top→Person }}> <: <{{ Person→Top }}>.
Proof with eauto.
(* 在这里填写 *) Admitted.
☐
Definition context := partial_map ty.
Inductive has_type : context → tm → ty → Prop :=
(* Pure STLC, same as before: *)
| T_Var : ∀ Gamma x T1,
Gamma x = Some T1 →
<{ Gamma |-- x \in T1 }>
| T_Abs : ∀ Gamma x T1 T2 t1,
<{ x ⊢> T2 ; Gamma |-- t1 \in T1 }> →
<{ Gamma |-- \x:T2, t1 \in T2 → T1 }>
| T_App : ∀ T1 T2 Gamma t1 t2,
<{ Gamma |-- t1 \in T2 → T1 }> →
<{ Gamma |-- t2 \in T2 }> →
<{ Gamma |-- t1 t2 \in T1 }>
| T_True : ∀ Gamma,
<{ Gamma |-- true \in Bool }>
| T_False : ∀ Gamma,
<{ Gamma |-- false \in Bool }>
| T_If : ∀ t1 t2 t3 T1 Gamma,
<{ Gamma |-- t1 \in Bool }> →
<{ Gamma |-- t2 \in T1 }> →
<{ Gamma |-- t3 \in T1 }> →
<{ Gamma |-- if t1 then t2 else t3 \in T1 }>
| T_Unit : ∀ Gamma,
<{ Gamma |-- unit \in Unit }>
(* New rule of subsumption: *)
| T_Sub : ∀ Gamma t1 T1 T2,
<{ Gamma |-- t1 \in T1 }> →
T1 <: T2 →
<{ Gamma |-- t1 \in T2 }>
where "<{ Gamma '|--' t '∈' T }>" := (has_type Gamma t T) : stlc_scope.
Hint Constructors has_type : core.
Module Examples2.
Import Examples.
Inductive has_type : context → tm → ty → Prop :=
(* Pure STLC, same as before: *)
| T_Var : ∀ Gamma x T1,
Gamma x = Some T1 →
<{ Gamma |-- x \in T1 }>
| T_Abs : ∀ Gamma x T1 T2 t1,
<{ x ⊢> T2 ; Gamma |-- t1 \in T1 }> →
<{ Gamma |-- \x:T2, t1 \in T2 → T1 }>
| T_App : ∀ T1 T2 Gamma t1 t2,
<{ Gamma |-- t1 \in T2 → T1 }> →
<{ Gamma |-- t2 \in T2 }> →
<{ Gamma |-- t1 t2 \in T1 }>
| T_True : ∀ Gamma,
<{ Gamma |-- true \in Bool }>
| T_False : ∀ Gamma,
<{ Gamma |-- false \in Bool }>
| T_If : ∀ t1 t2 t3 T1 Gamma,
<{ Gamma |-- t1 \in Bool }> →
<{ Gamma |-- t2 \in T1 }> →
<{ Gamma |-- t3 \in T1 }> →
<{ Gamma |-- if t1 then t2 else t3 \in T1 }>
| T_Unit : ∀ Gamma,
<{ Gamma |-- unit \in Unit }>
(* New rule of subsumption: *)
| T_Sub : ∀ Gamma t1 T1 T2,
<{ Gamma |-- t1 \in T1 }> →
T1 <: T2 →
<{ Gamma |-- t1 \in T2 }>
where "<{ Gamma '|--' t '∈' T }>" := (has_type Gamma t T) : stlc_scope.
Hint Constructors has_type : core.
Module Examples2.
Import Examples.
(* empty |-- ((\z:A,z), (\z:B,z)) ∈ (A->A * B->B) *)
(* 在这里填写 *)
☐
(* 在这里填写 *)
☐
(* empty |-- (\x:(Top * B->B), x.snd) ((\z:A,z), (\z:B,z))
∈ B->B *)
(* 在这里填写 *)
☐
∈ B->B *)
(* 在这里填写 *)
☐
(* empty |-- (\z:(C->C)->(Top * B->B), (z (\x:C,x)).snd)
(\z:C->C, ((\z:A,z), (\z:B,z)))
∈ B->B *)
(* 在这里填写 *)
☐
(\z:C->C, ((\z:A,z), (\z:B,z)))
∈ B->B *)
(* 在这里填写 *)
☐
性质
子类型化的反演引理
- Bool 是 Bool 的唯一子类型,且
- 箭头类型的每个子类型本身都是箭头类型。
练习: 2 stars,标准,可选 (sub_inversion_Bool)
Lemma sub_inversion_arrow : ∀ U V1 V2,
U <: <{{ V1→V2 }}> →
∃ U1 U2,
U = <{{ U1→U2 }}> ∧ V1 <: U1 ∧ U2 <: V2.
U <: <{{ V1→V2 }}> →
∃ U1 U2,
U = <{{ U1→U2 }}> ∧ V1 <: U1 ∧ U2 <: V2.
☐
对其它类型还有额外的【反演引理】:
- Unit 是 Unit 的唯一子类型,且
- Base n 是 Base n 的唯一子类型,且
- Top 是 Top 的唯一超类型。
练习: 2 stars,标准,可选 (sub_inversion_Unit)
☐
典范形式
练习: 3 stars,标准,可选 (canonical_forms_of_arrow_types)
Lemma canonical_forms_of_arrow_types : ∀ Gamma s T1 T2,
<{ Gamma |-- s \in T1→T2 }> →
value s →
∃ x S1 s2,
s = <{\x:S1,s2}>.
<{ Gamma |-- s \in T1→T2 }> →
value s →
∃ x S1 s2,
s = <{\x:S1,s2}>.
☐
类似地,类型 Bool 的典范形式是常量 tm_true 和
tm_false。
Lemma canonical_forms_of_Bool : ∀ Gamma s,
<{ Gamma |-- s \in Bool }> →
value s →
s = tm_true ∨ s = tm_false.
<{ Gamma |-- s \in Bool }> →
value s →
s = tm_true ∨ s = tm_false.
进展
- 如果定型导出式的最后一步使用规则 T_App,那么存在项
t1、t2 和类型 T1、T2,使得 t = t1 t2、
T = T2、empty |-- t1 ∈ T1 → T2 且
empty |-- t2 ∈ T1。此外,由归纳假设,t1 或者是值
或者能走一步,t2 或者是值或者能走一步。有三种可能
需要考虑:
- 首先,假设对某个项 t1' 有 t1 --> t1'。那么由
ST_App1 有 t1 t2 --> t1' t2。
- 其次,假设 t1 是值,且对某个项 t2' 有
t2 --> t2'。那么由规则 ST_App2 有
t1 t2 --> t1 t2',因为 t1 是值。
- 第三,假设 t1 和 t2 都是值。由箭头类型的典范形式
引理,我们知道 t1 对某个 x、S1 和 s2 具有形式
\x:S1,s2。但随后由 ST_AppAbs 有
(\x:S1,s2) t2 --> [x:=t2]s2,因为 t2 是值。
- 首先,假设对某个项 t1' 有 t1 --> t1'。那么由
ST_App1 有 t1 t2 --> t1' t2。
- 如果导出式的最后一步使用规则 T_If,那么存在项 t1、
t2 和 t3,使得 t = if t1 then t2 else t3,且
empty |-- t1 ∈ Bool、empty |-- t2 ∈ T 且
empty |-- t3 ∈ T。此外,由归纳假设,t1 或者是值
或者能走一步。
- 如果 t1 是值,那么由布尔值的典范形式引理,
t1 = true 或 t1 = false。无论哪种情况,t 都能
走一步,使用规则 ST_IfTrue 或 ST_IfFalse。
- 如果 t1 能走一步,那么由规则 ST_If,t 也能。
- 如果 t1 是值,那么由布尔值的典范形式引理,
t1 = true 或 t1 = false。无论哪种情况,t 都能
走一步,使用规则 ST_IfTrue 或 ST_IfFalse。
- 如果导出式的最后一步是 T_Sub,那么存在类型 T2,使得 T1 <: T2 且 empty |-- t1 ∈ T1。所需结果恰好是 定型子导出式的归纳假设。
Theorem progress : ∀ t T,
<{ empty |-- t \in T }> →
value t ∨ ∃ t', t --> t'.
<{ empty |-- t \in T }> →
value t ∨ ∃ t', t --> t'.
Proof with eauto.
intros t T Ht.
remember empty as Gamma.
induction Ht; subst Gamma; auto.
- (* T_Var *)
discriminate.
- (* T_App *)
right.
destruct IHHt1; subst...
+ (* t1 is a value *)
destruct IHHt2; subst...
× (* t2 is a value *)
eapply canonical_forms_of_arrow_types in Ht1; [|assumption].
destruct Ht1 as [x [S1 [s2 H1]]]. subst.
∃ (<{ [x:=t2]s2 }>)...
× (* t2 steps *)
destruct H0 as [t2' Hstp]. ∃ <{ t1 t2' }>...
+ (* t1 steps *)
destruct H as [t1' Hstp]. ∃ <{ t1' t2 }>...
- (* T_If *)
right.
destruct IHHt1.
+ (* t1 is a value *) eauto.
+ apply canonical_forms_of_Bool in Ht1; [|assumption].
destruct Ht1; subst...
+ destruct H. rename x into t1'. eauto.
Qed.
intros t T Ht.
remember empty as Gamma.
induction Ht; subst Gamma; auto.
- (* T_Var *)
discriminate.
- (* T_App *)
right.
destruct IHHt1; subst...
+ (* t1 is a value *)
destruct IHHt2; subst...
× (* t2 is a value *)
eapply canonical_forms_of_arrow_types in Ht1; [|assumption].
destruct Ht1 as [x [S1 [s2 H1]]]. subst.
∃ (<{ [x:=t2]s2 }>)...
× (* t2 steps *)
destruct H0 as [t2' Hstp]. ∃ <{ t1 t2' }>...
+ (* t1 steps *)
destruct H as [t1' Hstp]. ∃ <{ t1' t2 }>...
- (* T_If *)
right.
destruct IHHt1.
+ (* t1 is a value *) eauto.
+ apply canonical_forms_of_Bool in Ht1; [|assumption].
destruct Ht1; subst...
+ destruct H. rename x into t1'. eauto.
Qed.
定型的反演引理
- 如果导出式的最后一步是使用 T_Abs,那么存在类型
T12,使得 T = S1 → T12 且
x:S1; Gamma |-- t2 ∈ T12。取 T12 作为 S2
就给出我们所需,因为 S1 → T12 <: S1 → T12 由
S_Refl 得出。
- 如果导出式的最后一步是使用 T_Sub,那么存在类型 S,使得 S <: T 且 Gamma |-- \x:S1,t2 ∈ S。 定型子导出式的归纳假设告诉我们,存在某个类型 S2, 满足 S1 → S2 <: S 且 x:S1; Gamma |-- t2 ∈ S2。取类型 S2 就给出 我们所需,因为随后 S1 → S2 <: T 由 S_Trans 得出。
Lemma typing_inversion_abs : ∀ Gamma x S1 t2 T,
<{ Gamma |-- \x:S1,t2 \in T }> →
∃ S2,
<{{ S1→S2 }}> <: T
∧ <{ x ⊢> S1 ; Gamma |-- t2 \in S2 }>.
<{ Gamma |-- \x:S1,t2 \in T }> →
∃ S2,
<{{ S1→S2 }}> <: T
∧ <{ x ⊢> S1 ; Gamma |-- t2 \in S2 }>.
Lemma typing_inversion_var : ∀ Gamma (x:string) T,
<{ Gamma |-- x \in T }> →
∃ S,
Gamma x = Some S ∧ S <: T.
<{ Gamma |-- x \in T }> →
∃ S,
Gamma x = Some S ∧ S <: T.
Lemma typing_inversion_app : ∀ Gamma t1 t2 T2,
<{ Gamma |-- t1 t2 \in T2 }> →
∃ T1,
<{ Gamma |-- t1 \in T1→T2 }> ∧
<{ Gamma |-- t2 \in T1 }>.
Lemma typing_inversion_unit : ∀ Gamma T,
<{ Gamma |-- unit \in T }> →
<{{ Unit }}> <: T.
<{ Gamma |-- t1 t2 \in T2 }> →
∃ T1,
<{ Gamma |-- t1 \in T1→T2 }> ∧
<{ Gamma |-- t2 \in T1 }>.
Lemma typing_inversion_unit : ∀ Gamma T,
<{ Gamma |-- unit \in T }> →
<{{ Unit }}> <: T.
箭头类型之间定型与子类型的反演引理可以打包为一条有用的
「组合引理」,它准确地告诉我们下面实际需要什么。
Lemma abs_arrow : ∀ x S1 s2 T1 T2,
<{ empty |-- \x:S1,s2 \in T1→T2 }> →
T1 <: S1
∧ <{ x ⊢> S1 |-- s2 \in T2 }>.
<{ empty |-- \x:S1,s2 \in T1→T2 }> →
T1 <: S1
∧ <{ x ⊢> S1 |-- s2 \in T2 }>.
Lemma weakening : ∀ Gamma Gamma' t T,
includedin Gamma Gamma' →
<{ Gamma |-- t \in T }> →
<{ Gamma' |-- t \in T }>.
Corollary weakening_empty : ∀ Gamma t T,
<{ empty |-- t \in T }> →
<{ Gamma |-- t \in T }>.
includedin Gamma Gamma' →
<{ Gamma |-- t \in T }> →
<{ Gamma' |-- t \in T }>.
Proof.
intros Gamma Gamma' t T H Ht.
generalize dependent Gamma'.
induction Ht; eauto using includedin_update.
Qed.
intros Gamma Gamma' t T H Ht.
generalize dependent Gamma'.
induction Ht; eauto using includedin_update.
Qed.
Corollary weakening_empty : ∀ Gamma t T,
<{ empty |-- t \in T }> →
<{ Gamma |-- t \in T }>.
替换
Lemma substitution_preserves_typing : ∀ Gamma x U t v T,
<{ x ⊢> U ; Gamma |-- t \in T }> →
<{ empty |-- v \in U }> →
<{ Gamma |-- [x:=v]t \in T }>.
<{ x ⊢> U ; Gamma |-- t \in T }> →
<{ empty |-- v \in U }> →
<{ Gamma |-- [x:=v]t \in T }>.
保持
- 如果导出式的最后一步是 T_App,那么存在项 t1 和
t2 以及类型 T1 和 T2,使得 t = t1 t2、
T = T2、empty |-- t1 ∈ T1 → T2 且
empty |-- t2 ∈ T1。
由步进关系的定义,t1 t2 有三种走步方式。ST_App1 和 ST_App2 的情形由定型子导出式的归纳假设并使用 T_App 立即得出。假设 t1 t2 由 ST_AppAbs 走步。那么对某个类型 S 和项 t12,有 t1 = \x:S,t12,且 t' = [x:=t2]t12。由引理 abs_arrow,我们有 T1 <: S 和 x:S1 |-- s2 ∈ T2。随后由替换引理 (substitution_preserves_typing)得出 empty |-- [x:=t2] t12 ∈ T2,这正是所需。
- 如果导出式的最后一步使用规则 T_If,那么存在项
t1、t2 和 t3,使得 t = if t1 then t2 else t3,
且 empty |-- t1 ∈ Bool、empty |-- t2 ∈ T 且
empty |-- t3 ∈ T。此外,由归纳假设,若 t1 走步到
t1',则 empty |-- t1' : Bool。根据用哪条规则表明
t --> t',有三种情形要考虑。
- 若 t --> t' 由规则 ST_If,则
t' = if t1' then t2 else t3 且 t1 --> t1'。
由归纳假设 empty |-- t1' ∈ Bool,从而由
T_If 得 empty |-- t' ∈ T。
- 若 t --> t' 由规则 ST_IfTrue 或 ST_IfFalse,
则 t' = t2 或 t' = t3,且
empty |-- t' ∈ T 由假设得出。
- 若 t --> t' 由规则 ST_If,则
t' = if t1' then t2 else t3 且 t1 --> t1'。
由归纳假设 empty |-- t1' ∈ Bool,从而由
T_If 得 empty |-- t' ∈ T。
- 如果导出式的最后一步是 T_Sub,那么存在类型 S, 使得 S <: T 且 empty |-- t ∈ S。结果由定型子 导出式的归纳假设并应用 T_Sub 立即得出。☐
Theorem preservation : ∀ t t' T,
<{ empty |-- t \in T }> →
t --> t' →
<{ empty |-- t' \in T }>.
<{ empty |-- t \in T }> →
t --> t' →
<{ empty |-- t' \in T }>.
Proof with eauto.
intros t t' T HT. generalize dependent t'.
remember empty as Gamma.
induction HT;
intros t' HE; subst;
try solve [inversion HE; subst; eauto].
- (* T_App *)
inversion HE; subst...
(* Most of the cases are immediate by induction,
and eauto takes care of them *)
+ (* ST_AppAbs *)
destruct (abs_arrow _ _ _ _ _ HT1) as [HA1 HA2].
apply substitution_preserves_typing with T0...
Qed.
intros t t' T HT. generalize dependent t'.
remember empty as Gamma.
induction HT;
intros t' HE; subst;
try solve [inversion HE; subst; eauto].
- (* T_App *)
inversion HE; subst...
(* Most of the cases are immediate by induction,
and eauto takes care of them *)
+ (* ST_AppAbs *)
destruct (abs_arrow _ _ _ _ _ HT1) as [HA1 HA2].
apply substitution_preserves_typing with T0...
Qed.
经由积与 Top 的记录
{a:Nat, b:Nat} ----> {Nat,Nat} i.e., (Nat,(Nat,Top))
{c:Nat, a:Nat} ----> {Nat,Top,Nat} i.e., (Nat,(Top,(Nat,Top)))
记录值的编码完全不变。
检查上述子类型规则被该编码验证是容易的(也是有启发的)。
习题
练习: 2 stars,标准 (variations)
本题每一部分提出一种不同的方式来改变带 Unit 和子类型化的 STLC 的定义。(这些改变不是累积的:每部分都从原始语言出发。) 在每部分中,列出哪些性质(进展、保持、二者、或都不)变为 假。若某性质变为假,给出一个反例。- 假设我们添加下列定型规则:
<{ Gamma |-- t ∈ S1->S2 S1 <: T1 T1 <: S1 S2 <: T2 (T_Funny1) <{ Gamma |-- t ∈ T1->T2 - 假设我们添加下列归约规则:
(ST_Funny2) unit --> (\x:Top. x) - 假设我们添加下列子类型规则:
(S_Funny3) Unit <: Top->Top - 假设我们添加下列子类型规则:
(S_Funny4) Top->Top <: Unit - 假设我们添加下列归约规则:
(ST_Funny5) (unit t) --> (t unit) - 假设我们添加相同的归约规则【以及】一条新的定型规则:
(ST_Funny5) (unit t) --> (t unit) (T_Funny6) empty |-- unit ∈ Top->Top - 假设我们【改变】箭头子类型规则为:
S1 <: T1 S2 <: T2 (S_Arrow') S1->S2 <: T1->T2
习题:添加积
练习: 5 stars,标准 (products)
给我们已定义的系统添加序对、投影和积类型是相对直接的事。 通过修改上面的定义和证明来完成这一扩展:- 序对、第一和第二投影以及积类型的构造子已经添加到 ty
和 tm 的定义中。替换的定义也已扩展。
- 相应地扩展周围的定义(参见 MoreSTLC):
- 值关系
- 操作语义
- 定型关系
- 用下列规则扩展子类型关系:
S1 <: T1 S2 <: T2 (S_Prod) S1 * S2 <: T1 * T2 - 扩展进展、保持及所有辅助引理的证明以处理新构造。 (你还需要添加几个全新的引理。)
(* 在这里填写 *)
(* 不要修改下面这行: *)
Definition manual_grade_for_products_value_step : option (nat×string) := None.
(* 不要修改下面这行: *)
Definition manual_grade_for_products_subtype_has_type : option (nat×string) := None.
(* 不要修改下面这行: *)
Definition manual_grade_for_products_progress : option (nat×string) := None.
(* 不要修改下面这行: *)
Definition manual_grade_for_products_preservation : option (nat×string) := None.
☐
(* 不要修改下面这行: *)
Definition manual_grade_for_products_value_step : option (nat×string) := None.
(* 不要修改下面这行: *)
Definition manual_grade_for_products_subtype_has_type : option (nat×string) := None.
(* 不要修改下面这行: *)
Definition manual_grade_for_products_progress : option (nat×string) := None.
(* 不要修改下面这行: *)
Definition manual_grade_for_products_preservation : option (nat×string) := None.
☐
Module FormalThoughtExercises.
Import Examples.
Notation p := "p".
Notation a := "a".
Definition TF P := P ∨ ¬P.
Import Examples.
Notation p := "p".
Notation a := "a".
Definition TF P := P ∨ ¬P.
Theorem formal_subtype_instances_tf_1a:
TF (∀ S T U V, S <: T → U <: V →
<{{ T→S }}> <: <{{ T→S }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∀ S T U V, S <: T → U <: V →
<{{ T→S }}> <: <{{ T→S }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_instances_tf_1b:
TF (∀ S T U V, S <: T → U <: V →
<{{ Top→U }}> <: <{{ S→Top }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∀ S T U V, S <: T → U <: V →
<{{ Top→U }}> <: <{{ S→Top }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_instances_tf_1c:
TF (∀ S T U V, S <: T → U <: V →
<{{ (C→C)→(A×B) }}> <: <{{ (C→C)→(Top×B) }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∀ S T U V, S <: T → U <: V →
<{{ (C→C)→(A×B) }}> <: <{{ (C→C)→(Top×B) }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_instances_tf_1d:
TF (∀ S T U V, S <: T → U <: V →
<{{ T→(T→U) }}> <: <{{ S→(S→V) }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∀ S T U V, S <: T → U <: V →
<{{ T→(T→U) }}> <: <{{ S→(S→V) }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_instances_tf_1e:
TF (∀ S T U V, S <: T → U <: V →
<{{ (T→T)→U }}> <: <{{ (S→S)→V }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∀ S T U V, S <: T → U <: V →
<{{ (T→T)→U }}> <: <{{ (S→S)→V }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_instances_tf_1f:
TF (∀ S T U V, S <: T → U <: V →
<{{ ((T→S)→T)→U }}> <: <{{ ((S→T)→S)→V }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∀ S T U V, S <: T → U <: V →
<{{ ((T→S)→T)→U }}> <: <{{ ((S→T)→S)→V }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_instances_tf_1g:
TF (∀ S T U V, S <: T → U <: V →
<{{ S×V }}> <: <{{ T×U }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∀ S T U V, S <: T → U <: V →
<{{ S×V }}> <: <{{ T×U }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_instances_tf_2a:
TF (∀ S T,
S <: T →
<{{ S→S }}> <: <{{ T→T }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∀ S T,
S <: T →
<{{ S→S }}> <: <{{ T→T }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_instances_tf_2b:
TF (∀ S,
S <: <{{ A→A }}> →
∃ T,
S = <{{ T→T }}> ∧ T <: A).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∀ S,
S <: <{{ A→A }}> →
∃ T,
S = <{{ T→T }}> ∧ T <: A).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_concepts_tfc:
TF (∃ T1 T2, ∀ S1 S2, <{{ S1×S2 }}> <: <{{ T1×T2 }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∃ T1 T2, ∀ S1 S2, <{{ S1×S2 }}> <: <{{ T1×T2 }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_concepts_tfd:
TF (∃ T1 T2, ∀ S1 S2, <{{ T1×T2 }}> <: <{{ S1×S2 }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∃ T1 T2, ∀ S1 S2, <{{ T1×T2 }}> <: <{{ S1×S2 }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_concepts_tfe:
TF (∃ T1 T2, ∀ S1 S2, <{{ S1→S2 }}> <: <{{ T1→T2 }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∃ T1 T2, ∀ S1 S2, <{{ S1→S2 }}> <: <{{ T1→T2 }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_concepts_tff:
TF (∃ T1 T2, ∀ S1 S2, <{{ T1→T2 }}> <: <{{ S1→S2 }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∃ T1 T2, ∀ S1 S2, <{{ T1→T2 }}> <: <{{ S1→S2 }}>).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_concepts_tfg:
TF (∃ f : nat → ty,
(∀ i j, i ≠ j → f i ≠ f j) ∧
(∀ i, f (S i) <: f i)).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∃ f : nat → ty,
(∀ i j, i ≠ j → f i ≠ f j) ∧
(∀ i, f (S i) <: f i)).
Proof.
(* 在这里填写 *) Admitted.
☐
Theorem formal_subtype_concepts_tfh:
TF (∃ f : nat → ty,
(∀ i j, i ≠ j → f i ≠ f j) ∧
(∀ i, f i <: f (S i))).
Proof.
(* 在这里填写 *) Admitted.
☐
TF (∃ f : nat → ty,
(∀ i j, i ≠ j → f i ≠ f j) ∧
(∀ i, f i <: f (S i))).
Proof.
(* 在这里填写 *) Admitted.
☐
