functional-programming - Agda:我能证明具有不同构造函数的类型是不相交的吗?

标签 functional-programming agda dependent-type

如果我试图证明 Nat 和 Bool 在 Agda 中不相等:

open import Data.Nat
open import Data.Bool
open import Data.Empty
open import Relation.Binary.PropositionalEquality

noteq : ℕ ≡ Bool -> ⊥
noteq () 

我收到错误:
Failed to solve the following constraints:
  Is empty: ℕ ≡ Bool

我知道不可能对类型本身进行模式匹配,但我很惊讶编译器看不到 Nat 和 Bool 具有不同的(类型)构造函数。

有没有办法在 Agda 中证明这样的事情?或者只是不支持 Agda 中涉及类型的不等式?

最佳答案

在 Agda 中证明两个集合不同的唯一方法是利用它们的
基数方面的差异。如果他们有相同的红衣主教,那么你
不能证明任何事情:那将与立方体不相容。

这是Nat的证明和 Bool不相等:

open import Data.Nat.Base
open import Data.Bool.Base
open import Data.Sum.Base
open import Data.Empty
open import Relation.Binary.PropositionalEquality

-- Bool only has two elements
bool : (a b c : Bool) → a ≡ b ⊎ b ≡ c ⊎ c ≡ a
bool false false c = inj₁ refl
bool false b false = inj₂ (inj₂ refl)
bool a false false = inj₂ (inj₁ refl)
bool true true c = inj₁ refl
bool true b true = inj₂ (inj₂ refl)
bool a true true = inj₂ (inj₁ refl)


module _ (eq : ℕ ≡ Bool) where

  -- if Nat and Bool are the same then Nat also only has two elements
  nat : (a b c : ℕ) → a ≡ b ⊎ b ≡ c ⊎ c ≡ a
  nat rewrite eq = bool

  -- and that's obviously nonsense...
  noteq : ⊥
  noteq with nat 0 1 2
  ... | inj₁ ()
  ... | inj₂ (inj₁ ())
  ... | inj₂ (inj₂ ())

关于functional-programming - Agda:我能证明具有不同构造函数的类型是不相交的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59707418/

相关文章:

pattern-matching - 没有 K 的 Agda 是否不那么强大?

logic - 如何在 Agda 中证明 `theorem : ¬ ⊤ ≡ ⊥`?

coq - 如何在 Coq 中证明 "Type <> Set"(即 Type 不等于 Set)?

agda - 代表自由团体的好方法是什么?

recursion - 依赖参数的结构递归

functional-programming - Common Lisp 中具有默认值的可选函数参数

parsing - 基于 Agda 上的一篇论文在 Idris 中实现 Total Parser

scala - 用另一个列表中的单词过滤一个列表中的单词

python - 如何减少 lambda 表达式中辅助函数的使用?

functional-programming - LISP 中的未定义函数错误