【问题标题】:De Morgan's Laws in Haskell via the Curry-Howard Correspondence德摩根在 Haskell 中的定律通过 Curry-Howard 通信
【发布时间】:2016-08-29 05:44:00
【问题描述】:

我在 Haskell 中实现了四个德摩根定律中的三个:

notAandNotB :: (a -> c, b -> c) -> Either a b -> c
notAandNotB (f, g) (Left x)  = f x
notAandNotB (f, g) (Right y) = g y

notAorB :: (Either a b -> c) -> (a -> c, b -> c)
notAorB f = (f . Left, f . Right)

notAorNotB :: Either (a -> c) (b -> c) -> (a, b) -> c
notAorNotB (Left f)  (x, y) = f x
notAorNotB (Right g) (x, y) = g y

但是,我不认为有可能实施最后一条法律(有两个居民):

notAandBLeft  :: ((a, b) -> c) -> Either (a -> c) (b -> c)
notAandBLeft  f = Left  (\a -> f (a, ?))

notAandBRight :: ((a, b) -> c) -> Either (a -> c) (b -> c)
notAandBRight f = Right (\b -> f (?, b))

在我看来,有两种可能的解决方案:

  1. 使用undefined 代替?。这不是一个好的解决方案,因为它是作弊。
  2. 使用单态类型或有界多态类型来编码默认值。

    notAandBLeft  :: Monoid b => ((a, b) -> c) -> Either (a -> c) (b -> c)
    notAandBLeft  f = Left  (\a -> f (a, mempty))
    
    notAandBRight :: Monoid a => ((a, b) -> c) -> Either (a -> c) (b -> c)
    notAandBRight f = Right (\b -> f (mempty, b))
    

    这不是一个好的解决方案,因为它比德摩根定律更弱。

我们知道德摩根定律是正确的,但我认为最后一条定律不能用 Haskell 编码是否正确?这对 Curry-Howard 同构有什么看法?如果不能将每个证明都转换为等效的计算机程序,这并不是真正的同构,对吧?

【问题讨论】:

  • 我倾向于怀疑您错误地应用了同构。
  • 我认为我没有错误地应用同构。你能详细说明一下吗?
  • 请注意,这些公式纯粹是命题(周围没有量词)。由于命题直觉逻辑是可判定的,因此您可以使用定理证明器(例如 Djinn)来解决这些问题。如果证明者失败了,那么它肯定是一个非直觉的重言式。
  • 想一想这个“定律”在计算上可能意味着什么。它说,“只要一个连词是假的,你就可以找出哪个连词是假的”。例如,我们知道(a, a -> c) -> c,所以 de Morgan 告诉我们,我们可以决定任何命题a,解决停机问题,随便你说。即使 Haskell 的多态性不是参数化的,那也是一个相当大的问题。但是对于参数多态性,这个“定律”必须在不知道命题是什么的情况下决定任意命题。

标签: haskell functional-programming demorgans-law curry-howard


【解决方案1】:

第四定律是not intuitionistic。你需要排中公理:

lem :: Either a (a -> c)

或皮尔斯定律:

pierce :: ((a -> c) -> c) -> a

证明它。

【讨论】:

    【解决方案2】:

    让我印象深刻的一件事是,您似乎没有在任何地方使用否定的定义或任何属性。

    阅读Haskell Wikibooks article on the CHI 后,这里有一个假设你有一个排中定律作为定理的证明:

    exc_middle :: Either a (a -> Void)
    

    notAandB de Morgan 定律的证明如下:

    notAandB' :: Either a (a -> Void) -> ((a,b) -> Void) -> Either (a -> Void) (b -> Void)
    notAandB' (Right notA) _ = Left notA
    notAandB' (Left a)     f = Right (\b -> f (a,b))
    
    notAandB = notAandB' exc_middle
    

    【讨论】:

    • 唯一的问题是你无法构造排中律的证明。您只能构造排中律不为假的证明。我想这在建设性类型理论中是做不到的。
    • 很高兴发现有一篇关于我自己的 wikibook 文章。最重要的是,它是关于我发现的最酷的话题之一! ;-P
    猜你喜欢
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 2016-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 2016-01-12
    相关资源
    最近更新 更多