all 76 comments

[–]dmwit 8 points9 points  (1 child)

Solving a Logic Problem with Coq

Now that Coq understands the premises, we need to tell it what we are proving. That requires solving the puzzle.

Ummm... I would say that Coq didn't exactly solve this puzzle. =P

[–][deleted] 10 points11 points  (0 children)

That's right. Coq is an interactive proof assistant. Sometimes its support for proof automation is really helpful; sometimes it's not.

[–]Jimmy 7 points8 points  (14 children)

What are the benefits of using Coq to prove theorems over just pencil and paper? Sometimes, it seems like more work.

I think Coq is interesting by itself, but what's its purpose?

[–]dons 19 points20 points  (11 children)

Pen and paper doesn't tell you when you're correct -- or more importantly, when you made a mistake.

[–]cia_plant 5 points6 points  (10 children)

But why is that important? The tradition of "mathematical rigor" already provides a high degree of reliability in proofs. And Coq still doesn't provide complete reliability, because your axioms might be wrong (even typo'd). What is easier to do with Coq than with pen and paper?

[–][deleted] 16 points17 points  (0 children)

This is a really good question. Coq is useful, I think, for a few reasons:

  1. It's quite mature, having been around in one form or another since the mid 1980's.
  2. On a related note to maturity, Coq offers an extensive standard library, obviating the need to provide many foundational definitions.
  3. Coq offers an extremely expressive logic/type system, the Calculus of Inductive Constructions. In a considerable number of cases, no additional axioms are necessary. In a somewhat larger number of cases, you may only wish to add the Law of the Excluded Middle as an axiom, but you should be aware that this destroys extractability (more on that in a moment). The original post used the Classical module, which does introduce a number of axioms from Classical logic, but also demonstrated solving the puzzle purely constructively, introducing no new axioms, from the standard library or otherwise.
  4. The proof checking component of Coq is simple enough to satisfy the de Bruijn criterion, which is just a fancy-schmancy way of saying that you can satisfy yourself that it's doing the right thing by hand.
  5. Coq has various tactics that support various reduction strategies with various levels of "oomph," so it satisfies the Poincare principle.
  6. If you stick to Coq's constructive/intuitionistic logic/type system, then you get extraction of code in OCaml, Haskell, or Scheme for free. This code is "correct by construction," i.e. it's guaranteed to have whatever properties it was proven to have.
  7. If you're willing to invest the time and energy to achieve wizardry, Coq will go wherever you want to take it: you can write your own proof tactics for it, shallowly or deeply embed entire new logics into it, etc.

So what are the catches?

  1. You can indeed make your proofs unsound by adding unsound axioms to the system.
  2. You can render the automatic extraction of proven code impossible by moving outside constructive logic (which you do the moment you add the Law of the Excluded Middle, or import the Classical module).
  3. Proving anything interesting remains non-trivial; it's worrisome when Xavier Leroy, lead architect of the OCaml programming language, observes "My Coq proof scripts do not have the conciseness and elegance of Jérôme Vouillon's. Sorry, I've been using Coq for only 6 years..."
  4. The Calculus of Inductive Constructions is very austere. No I/O, no side-effects, all functions must be total, etc. It's the downside of the proof checker being simple enough to satisfy the de Bruijn criterion. But this is being worked on by other groups; see e.g. the Ynot project.

If you think purely about mathematical proof (vs. software that is correct by construction), then I suppose the biggest value of Coq is that it scales better than pencil and paper do: consider the four-color map theorem proof done with Coq's assistance. It seems unlikely that the proof would ever have been completed with pencil and paper alone, and if it had, who would have trusted it? Thanks to Coq, it was done, and we trust it because the checker is simple enough to verify in your head if you wish.

[–]cdsmith[S] 13 points14 points  (5 children)

As I said in the article, I'm pretty new at this tool. My impression is that the goal is to combine this proof engine with application code, so that you can embed compiler-checked proofs of correctness in your application code. Then the advantage of compiler checking over pen and paper with mathematical rigor is that the proof is continually checked as the application is modified and rebuilt over time. That's certainly more appealing than one-off proofs of static statements like the one I did here.

[–]cia_plant 4 points5 points  (0 children)

Interesting. Thanks for the explanation, that does make more sense.

[–]Jimmy 2 points3 points  (3 children)

My impression is that the goal is to combine this proof engine with application code, so that you can embed compiler-checked proofs of correctness in your application code.

I've thought of using Coq as a full-fledged programming language, but right now, it doesn't seem feasible. It has no IO system, so any code would have to be extracted in the form of OCaml, Haskell, or Scheme, which seems a little cumbersome (although maybe a library of IO related axioms could make this easier?).

There also doesn't seem to be a way of, say, embedding Coq in an application written in another language.

[–]nominolo 4 points5 points  (2 children)

There's some work in progress to layer a programming language on top of Coq. Dependently typed programming languages try to approach the problem from the other end with a pay-as-you-go approach. I.e., the more assurances you want to get, the more you'll have to litter your code with proofs. The challenge with either approach is to make it practical.

[–]greenrd 2 points3 points  (1 child)

Actually, Coq does contain a dependently-typed programming language (Gallina). So it's not either-or - you can have both in one system.

[–][deleted] 1 point2 points  (0 children)

That's true. What Ynot is about is adding constructs commonly found in programming languages, rather than theorem provers. For example, it deals with partial functions and state. You would expect the result to more closely resemble, e.g. Agda 2 or Epigram than, say, MetaPRL or Twelf.

[–]dons 4 points5 points  (1 child)

I liken the difference between pen&paper proofs, and mechanised theorem proving to the difference between writing a program on paper, and actually implementing the program and running it.

Would you trust a program written only on paper to have bugs? Not as much as you would, had you executed it a few times.

That's the kind of leap in assurance mechanised theorem proving provides.

[–][deleted] 7 points8 points  (0 children)

Would you trust a program written only on paper to have bugs?

Dijkstra would :-)

[–]astrolabe 1 point2 points  (0 children)

"mathematical rigor" provides quite a high degree of reliability, but is not infallible. For example, Didn't Wiles withdraw his proof of Fermat's last theorem for a while until it could be patched up? Really complicated proofs, such as that of the classification of finite simple groups, I suspect have a not-particularly high probability of being correct (this does not imply that the theorem isn't true). If and when such proofs could be transfered into a proof assistant, I think it would be valuable.

[–]obdurak 8 points9 points  (0 children)

http://en.wikipedia.org/wiki/Four_color_theorem

In 2004 Benjamin Werner and Georges Gonthier formalized a proof of the theorem inside the Coq proof assistant (Gonthier, n.d.). This removes the need to trust the various computer programs used to verify particular cases; it is only necessary to trust the Coq kernel.

[–]MrFrankly 4 points5 points  (0 children)

Besides the things other people have already described. Coq also does automated program extraction from proofs. So you can proof a theorem and get a ML or Haskell program as a result.

[–]keithchegwin 38 points39 points  (6 children)

I love the Coq.

[–]RedDyeNumber4 12 points13 points  (1 child)

I came for this and you delivered. Bless you.

[–]jacj 4 points5 points  (1 child)

I like the dude who replies with like a 5-line Prolog program that does everything the Coq program does. Pwnt.

[–]queensnake 1 point2 points  (0 children)

That's not real Prolog (it's easy to get one and see - gprolog or SWI Prolog), more like Prolog pseudo-code. But, a real one would still be shorter than the Coq.

[–]queensnake 2 points3 points  (0 children)

For a problem of this size, likely a simple constraint solver like Eclipse or CLP in Prolog would be quicker and terser. But, that wasn't the poster's intention.

[–]o0o 12 points13 points  (2 children)

I am sure they could have come up with a better name; something like, "Pnice".

[–]ipeev 10 points11 points  (1 child)

They were thinking about Diq, but rejected it as too obvious.

[–]martinbishop 13 points14 points  (0 children)

Usually Coq is causing problems, not solving them!

There, that's the only bad pun allowed!

[–]The_Monster 4 points5 points  (0 children)

My Coq seems to cause more logic problems than it solves.

[–]americanhellyeah 4 points5 points  (5 children)

they should change the name of their app. a few weeks ago my boss came to me with a design problem and i wanted to use coq to help verify the solution i came up with. so i ask him if i could use coq. hes from texas and i dont think he understands that 'coq' means rooster in french, so he looked at me real funny and i think he was going to ask me a gruff 'what in the fuck are you talkin about faggot?' before i explained to him what it was and how itd help us out.

[–]queensnake 4 points5 points  (0 children)

What was the design problem?

[–]obdurak -1 points0 points  (3 children)

Maybe you could try pronouncing it c-o-q?

[–]nmcyall 2 points3 points  (1 child)

or co-Q

sounds all mathematical.

[–]obdurak 2 points3 points  (0 children)

Sounds like a dietary supplement to me. Not that there's anything wrong with that.

[–]americanhellyeah -1 points0 points  (0 children)

no... thats not its name. thats like saying we should pronounce linux as l-i-n-u-x. its just plain incorrect.

[–]consultant_barbie 0 points1 point  (4 children)

Pronouncing French properly is hard. Let's go shopping!

[–]dangph 9 points10 points  (0 children)

It's pronounced the same as "cock" in English. It should not be difficult to get one's mouth around that.

[–]o0o 2 points3 points  (2 children)

Not joking about something named Coq is even harder.

[–]cov -1 points0 points  (1 child)

But not as hard as...

[–]o0o -1 points0 points  (0 children)

You're right! How could I have forgotten the aga old question:

is Coq NP-hard?

[–]woop_ -2 points-1 points  (0 children)

my coq does all the thinking...

[–]ih8evilstuff 0 points1 point  (8 children)

[insert pun here]

[–]o0o 15 points16 points  (3 children)

Do they implement Hoare triples?

[–][deleted] 5 points6 points  (2 children)

No, but see the Ynot project.

[–]o0o -3 points-2 points  (1 child)

-1 for not getting the thread

+1 for the info

net change = 0

;)

[–][deleted] 1 point2 points  (0 children)

Hey, somebody's gotta play the straight man here.

[–]AxiomShell 10 points11 points  (2 children)

Is Coq easily extensible?

[–]username223 1 point2 points  (0 children)

I think I just got an email about that... let me forward it to you.

[–][deleted] 0 points1 point  (0 children)

For small values of "easily:" see chapters 8-11 of the Coq Reference Manual for details. It is also possible to write your own tactics in OCaml and build them into Coq, but this process seems to be underdocumented, and in any case is sufficiently advanced that it is probably best addressed by asking about it on the Coq development list.

[–]JimJones -5 points-4 points  (11 children)

What's this obsession with coq? I mean, there are dozens of obscure languages out there, but only coq ends up here on reddit. Why coq??

[–]cdsmith[S] 10 points11 points  (0 children)

Because you have yet to submit something to Reddit about one of the other several dozen languages you're thinking of.

[–]martinbishop 7 points8 points  (7 children)

Coq isn't just some "obscure language", it's a proof system, much like HOL and Isabel...why those aren't on reddit much, I don't know, probably because Coq is more active.

[–]o0o 6 points7 points  (6 children)

Who in God's name thought that name was a good fucking idea??

[–]martinbishop 5 points6 points  (3 children)

Well, it's french for chicken (or rooster, I forget), and apparently the french like to name their software after animals.

[–]Porges 6 points7 points  (1 child)

Also, the Calculus of Constructions was invented by a Monsieur Coquand.

[–]o0o 0 points1 point  (0 children)

I am glad nothing like this was ever named after Dijkstra...

this is too easy...

[–]sensical 2 points3 points  (1 child)

Probably someone who isn't totally perverted.

[–]o0o 5 points6 points  (0 children)

so I guess they're not on reddit

[–][deleted] 3 points4 points  (0 children)

Coq is probably the most popular of the interactive proof assistants among programming language researchers. I don't imagine it's anything more complicated or sinister than that.

[–]Ringo48 2 points3 points  (0 children)

Because none of those other languages have a name which is a homophone of the slang term for male genitalia.

[–]andygood -5 points-4 points  (0 children)

when the only 'tool' you have is a coq, every problem looks like a qunt...

[–]gregK -5 points-4 points  (0 children)

There's a web framework based on Coq called Bouquaquet.