
Advent of Code 2018, in Coq - szemet
https://github.com/Lysxia/advent-of-coq-2018
======
syrak
Hello there. I'm the author of this repo.

Not as much has been going on in that project as I would have liked. It
certainly doesn't help that:

\- The standard library is actually quite poor. A lot of basic functions must
be implemented from scratch, and then you'll also want to write proofs about
them.

\- I had to reinvent IO in Coq.

\- Most AOC problems are actually not that well-suited for formal
verification. (It's certainly no fault of the AOC organizer!)

In particular, a lot of them basically ask you to simulate some system which
doesn't have particularly interesting properties, so the implementation itself
is often the best specification of the problem, and the main point of using a
language like Coq is lost.

I did find some interesting problems though. For example, day 5 was a simple
rewriting system and the question was to find the normal form of some starting
string. Well, who's to say that the answer is unique? In this case it's easy
enough to convince oneself that the given system actually is confluent, but I
set out to prove it formally (and (re)learned a few things about rewriting
systems on the way). (c.f., Confluent_react_steps, react_steps_injective, in
day_05_common.v)

------
tombert
I never liked Coq's name because I'm immature, but it really is magic software
in my eyes. The level of downright _objectivity_ that you get with it makes it
feel so bulletproof.

I know functional languages are slowly starting to adopt dependent types, and
you can get reasonable certainty of correctness with property-based testing,
but Coq just feels kind of universal. If the proof passes, so will your code.

I really wish I could get my employer to sign off on me using it for a real
project.

~~~
OnlyOneCannolo
It's pronounced closer to "coke".

~~~
tom_mellior
No. The software Coq is pronounced like the French word "coq", which has a
short o like the English "cock" and unlike the long o in the English "coke".
[https://forvo.com/word/coq/#fr](https://forvo.com/word/coq/#fr)

This is certainly the only pronounciation in the French formal methods
community, where Coq comes from. It is also the standard pronounciation in the
international formal methods community. I have never heard anyone pronounce it
like "coke".

See for example Adam Chlipala at about 5:40 here:
[https://www.youtube.com/watch?v=4DYVJdHMV5k](https://www.youtube.com/watch?v=4DYVJdHMV5k)
Benjamin Pierce has a slightly longer o here, but it doesn't sound to me like
it's deliberately pronounced differently from "cock":
[https://www.youtube.com/watch?v=KKrD4JcfW90](https://www.youtube.com/watch?v=KKrD4JcfW90)
And here is Andrej Bauer:
[https://www.youtube.com/watch?v=COe0VTNF2EA](https://www.youtube.com/watch?v=COe0VTNF2EA)

I know from rare comments like yours that some prudish Americans pronounce it
"coke", some deliberately, others apparently because they have been fooled by
the first group. But this seems to be a very small minority.

~~~
dragonwriter
> The software Coq is pronounced like the French word "coq",

Yes, but...

> which has a short o like the English "cock"

No, it doesn't. The sound it has isn't a common English vowel sound at all; it
is closer to the vowel sounds in “cuck” and “cook” than the one in “cock”, but
not exactly either of those, either. In fact of the four (those two, plus coke
and cock), the “o” in “cock” is the one most Americans would find it most
distinct from, I would think.

> [https://forvo.com/word/coq/#fr](https://forvo.com/word/coq/#fr)

Yeah, none of those pronounce it with the vowel sound in English “cock”.

> I know from rare comments like yours that some prudish Americans pronounce
> it "coke",

It's not prudish, its a common way Americans that haven't mastered French
pronunciation approximate the unaccented French “o” irrespective of context.

~~~
tom_mellior
> Yeah, none of those pronounce it with the vowel sound in English “cock”.

I was mainly talking about the vowel length. However:

> the “o” in “cock” is the one most Americans would find it most distinct
> from, I would think.

Really? More distinct than from the "oʊ" sound in American "coke"? (IPA from
[https://en.wiktionary.org/wiki/coke](https://en.wiktionary.org/wiki/coke))

~~~
thardus
Trying to have this discussion without IPA for multiple dialects is pretty
tough with "long o" and "short o." I've only ever heard Coq pronounced like
/kɑk/, but I'm from the Western US. I know Brits and Americans from the NE
have the round low back vowel for /kɔk/. Coke sounds like /kouk/.

------
keithnz
Looking at the code, and having done AOC2018 and having looked at a lot of
solutions in various languages, I don't really like the code, the solutions
are really not obvious and it all seems like a syntactic mess.

~~~
0xADEADBEE
I don't know that that's necessarily a fair characterisation. I've never seen
any Coq syntax before a moment ago but it doesn't look wildly dissimilar to
Haskell or Idris.

~~~
keithnz
Hard to make any kind of fair comparison, but given the context, AOC2018, and
the many many solutions in many languages, I think its reasonably fair to
compare it to all of those and make a judgement on how it stacks up. It seems
like it's being offered up for that specific comparison.

Just for reference, another HNer offered up the following in python for
inspection

[https://www.michaelfogleman.com/aoc18](https://www.michaelfogleman.com/aoc18)

There are other posted solution sets on HN if you search... Now of course,
lots of very different languages with different goals and philosophies. Hard
to make a fair comparison, but, still I'm making a subjective comparison. The
Coq code just does not seem compelling.

~~~
intertextuality
How can you make a comparison from a glance when 1) python was explicitly made
to be easy to read (English like) and 2) it’s absurdly common to see python
code as opposed to Coq?

Of course it’s possible it won’t make sense if you’re unfamiliar with the
syntax or style. That’s like saying Haskell or Erlang are uncompelling from a
brief glance, which ignores the benefits of using those languages.

~~~
keithnz
well, I gave the python as an example, there are more examples in most
languages.... including Haskell. I have been programming ~40 years and have
tried a lot of different languages in that time (not coq, but I have read
about it and am curious about practical uses of it). There is no article with
this repo, no explanations, I'm just saying I see nothing compelling... I'm
completely willing to listen to a compelling argument for why I'd write Coq
code and how theorem proving capabilities are worthwhile and how this code
demonstrate it.

~~~
jolux
Functional programming languages, Gallina included, are far simpler and more
regular in their grammars than imperative and object-oriented languages. It
seems a bit off-the-wall to suggest that the Coq implementation isn't
"compelling" without knowledge of how the language works or its design goals.
To be clear, these design goals are not identical to Python's, which could be
stated crudely as clarity and readability.

As a brief aside, I've often encountered the claim that these goals make
Python "English-like." For the grand failures achieved by pursuing such a
mistake, one need look no further than COBOL and AppleScript. Python is clear
and readable because it is relatively consistent, concise, and reads like how
we are taught to expect pseudo-code to read, not because it reads like an
English sentence.

It could be argued that Coq's goal in the syntax and semantics department is
mathematical clarity, which is somewhat different than the kind of clarity
Python pursues. Mathematical clarity favors terseness, simplicity, and
consistency above all else, because these features are necessary to express
complicated ideas succinctly and unambiguously. As an argument in favor of
this definition of clarity over Python's, I submit that programming
_correctly_ in a formal sense is quite difficult to do without tools that
encourage it as Coq and other languages operating at the level of generality
of the calculus of constructions do. Most statically typed languages do not
have type systems powerful enough to express the properties that Coq can, and
among those that do, I'm not sure any are syntactically simpler.

Coq indeed sacrifices what is for a lot of traditionally trained programmers
(myself included) the immediate familiarity of imperative pseudocode that
Python expresses so well. What is gained is a highly general yet simple set of
tools which can prove things about programs that are simply impossible with
other tools. I would also argue that once the syntax is learned and the
terseness adjusted to that Coq code is easy to read as well, and that the
tradeoff for me is worth the learning period, but you may have different needs
and priorities. I am intrinsically interested in rigorous formulations of
software correctness, and I realize that makes me a bit more odd than the
average programmer.

