了解 Agda 中的分配解决方案

Understanding Assignment Solution in Agda

考虑以下提取的代码片段,用于证明 Agda 中变量的 "Unicity of Typing":

unicity : ∀ {Γ₁ Γ₂ e τ₁ τ₂} →  (Γ₁ ⊢ e ∷ τ₁) → (Γ₂ ⊢ e ∷ τ₂) → (Γ₁ ≈ Γ₂) → (τ₁ ∼ τ₂)
unicity   (VarT here) (VarT here) (_ , ( τ∼ , _ ))   = τ∼ 
unicity (VarT here) (VarT (ski`p {α = α} lk2)) (s≡s' , ( _ , _ )) = ⊥-elim (toWitnessFalse α (toWitness` s≡s'))
unicity (VarT (skip {α = α} lk1)) (VarT here) (s'≡s , ( _ , _ )) = ⊥-elim (toWitnessFalse α (toWitness s'≡s))
unicity (VarT (skip lk1)) (VarT (skip lk2)) (_ ,( _ , Γ≈ ))     = unicity (VarT lk1) (VarT lk2) Γ≈

我需要有关 ⊥-elimtoWitnessFalsetoWitness 工作原理的解释。另外,表达式 mean/stand 的作用是什么?

is the empty type, so (in a total, consistent language) you can never construct a value of type . But this also means你能想到的任何命题,都来自。这就是 ⊥-elim 目击者:

⊥-elim : ∀ {w} {Whatever : Set w} → ⊥ → Whatever

这在实践中非常有用,因为您可能在某些假设下编写证明,其中一些假设可能是 ,或者它们可能是否定陈述(A → ⊥ 对于某些 A) 并且你也可以证明 A 等等。然后,你发现实际上你不必再关心那个特定的分支了,因为这是不可能的;但是,仅仅因为您不在乎,您仍然必须以某种方式正式满足结果类型。这就是 ⊥-elim 给你的。

toWitness的类型及相关定义如下:

T : Bool → Set
T true  = ⊤
T false = ⊥

⌊_⌋ : ∀ {p} {P : Set p} → Dec P → Bool
⌊ yes _ ⌋ = true
⌊ no  _ ⌋ = false

True : ∀ {p} {P : Set p} → Dec P → Set
True Q = T ⌊ Q ⌋

toWitness : ∀ {p} {P : Set p} {Q : Dec P} → True Q → P

给定 Q : Dec PTrue Q(如果 Q = yes _)或 (如果 Q = no _)。调用 toWitness 的唯一方法是让 QP 为真并传递普通单元构造函数 tt : ⊤;唯一的另一种可能性是让 QP 为假,并将 作为参数传递,但正如我们所见,这是不可能的。总之,toWitness 说如果 Q 告诉我们 P 成立的决定,那么我们可以从 Q.[=48 得到 P 的证明=]

toWitnessFalse完全一样,角色互换:如果Q告诉我们P不成立的决定,那么我们可以得到[=43的证明=] 来自 Q.