2

I implemented three of the four De Morgan's Laws in 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

However, I don't suppose that it's possible to implement the last law (which has two inhabitants):

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))

The way I see it, there are two possible solutions:

  1. Use undefined in place of ?. This is not a good solution because it's cheating.
  2. Either use monomorphic types or bounded polymorphic types to encode a default value.

    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))
    

    This is not a good solution because it's a weaker law than De Morgan's law.

We know that De Morgan's laws are correct but am I correct in assuming that the last law can't be encoded in Haskell? What does this say about the Curry-Howard Isomorphism? It's not really an isomorphism if every proof can't be converted into an equivalent computer program, right?

Cactus
  • 27,075
  • 9
  • 69
  • 149
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
  • 1
    I'd tend to suspect that you're applying the isomorphism incorrectly. – Louis Wasserman May 04 '16 at 00:54
  • 1
    I don't think I'm applying the isomorphism incorrectly. Could you elaborate? – Aadit M Shah May 04 '16 at 01:01
  • 1
    Note that these formulas are purely propositional (no quantifiers around). Since propositional intuitionistic logic is decidable, you can solve these problems using a theorem prover (e.g. Djinn). If the prover fails, then it surely is a non intuitionistic tautology. – chi May 04 '16 at 09:06
  • 1
    Think about what this "law" could possibly mean, computationally. It says, "whenever a conjunction is false, you can *find out* which conjunct is false". E.g., we know `(a, a -> c) -> c`, so de Morgan tells us we can decide any proposition `a`, solve the Halting Problem, you name it. Even if Haskell's polymorphism were not parametric, that would be a rather big ask. But with parametric polymorphism, this "law" has to decide an arbitrary proposition without knowing what the proposition is. – pigworker May 04 '16 at 23:11

2 Answers2

6

The fourth law is not intuitionistic. You'll need the axiom of excluded middle:

lem :: Either a (a -> c)

or Pierce's law:

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

to prove it.

Community
  • 1
  • 1
Cactus
  • 27,075
  • 9
  • 69
  • 149
5

One thing that stands out to me is that you don't seem to be using the definition or any property of negation anywhere.

After reading the Haskell Wikibooks article on the CHI here is a proof assuming that you have a law of the excluded middle as a theorem:

exc_middle :: Either a (a -> Void)

and the proof of the notAandB de Morgan law would go like:

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
Cactus
  • 27,075
  • 9
  • 69
  • 149
ErikR
  • 51,541
  • 9
  • 73
  • 124
  • 1
    The only problem is that you can't construct a proof for the law of the excluded middle. You can only construct a proof for the law of the excluded middle not being false. I guess this can't be done in constructive type theory. – Aadit M Shah May 04 '16 at 04:23
  • 2
    It's nice to discover that there's a wikibook article about myself. And on top of that, it's about one of the coolest topics I've ever found! ;-P – chi May 04 '16 at 09:03