Waste less time on Facebook — follow Brilliant.
×

\(2 + 2 = 4\) in Coq

Inspiration: Another Test Problem from Kelly's Group.

Coq is an interactive proof assistant. What this means is that Coq helps you prove theorems in a way that can be mechanically checked by Coq itself. This technology could be used to prove mathematical theorems, or develop formally correct software.

A famous example of a notorious theorem whose formal proof was developed in Coq is the four color theorem (download the proof here). Also, it has been used to generate a formally correct C compiler, which is pretty cool, if you think about it.

Behold we prove \[ 2 + 2 = 4 \] in Coq as a teaser


To run the proof below, you'll need Coq. You can read more about the Coq Proof Assistant on Wikipedia

We shall begin by defining the natural numbers along with two and four.

1
2
3
4
5
6
Inductive nat : Type :=
  | O : nat
  | S : nat -> nat.

Definition two : nat := S (S O). 
Definition four : nat := S (S (S (S O))).

We then, define plus

1
2
3
4
5
6
7
8
Fixpoint plus (n : nat) (m : nat) : nat :=
  match n with
    | O => m
    | S n' => S (plus n' m)
  end.

Notation "x + y" := (plus x y)
                       (at level 50, left associativity).

Now, we can prove the theorem we desire.

1
2
3
Theorem two_plus_two_four :
 two + two = four.
Proof. simpl. reflexivity. Qed.

And we are done!

Alternately, you could also use this:

1
2
Theorem two_plus_two_four : two + two = four.
Proof. trivial. Qed.

Note by Agnishom Chattopadhyay
1 month, 1 week ago

No vote yet
1 vote

Comments

Sort by:

Top Newest

Another marvelous proof, you couldn't have eludicated any clearer!

I was thinking of proving 2+2=4 using accelerated course, but yours is definitely far superior to mine. Pi Han Goh · 1 month, 1 week ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...