0

I'm just beginning to learn Coq via software foundations. One of the homework Theorems (with my successful proof elided) in Induction.v is:

Theorem plus_n_Sm : forall n m : nat,
  S (n + m) = n + (S m).
Proof.
  (* elided per request of authors *)
Qed.

Later, I noticed that the following similar "leftward" statement comes for free with the built-in tactic .simpl:

Example left_extract : forall n m : nat, S n + m = S (n + m).
Proof.
    intros. simpl. reflexivity.
Qed.

I've perused the documentation and haven't been able to figure out why .simpl gives us one direction "for free" but the other direction requires a user-supplied proof. The documentation is over my head at this very early point in my learning.

I guess it has something to do with left-ness being built-in and right-ness being not, but the propositions seem to my childlike eyes to be of equal complexity and subtlety. Would someone be so kind as to explain why, and perhaps give me some guidance about what is going on with .simpl?

Why should I NOT be surprised by my finding?

What other good things can I expect from .simpl, so it surprises me less and so I can eventually predict what it's going to do and rely on it?

What's the best way to wade through the theory -- unfolding of iota reductions and what not -- to focus on the relevant bits for this phenomenon? Or do I have to learn all the theory before I can understand this one bit?

Reb.Cabin
  • 5,426
  • 3
  • 35
  • 64

1 Answers1

1

I believe your surprise stems from the fact that you are accustomed to think of addition as a primitive concept. It is not, it is a function that has been defined and other primitive concepts are used to explain its behavior.

The addition function is defined by a function with a name written with letters (not the + symbol) in a way that looks like this:

Fixpoint add (n m : nat) : nat :=
match n with
| 0 => 
| S p => S (add p)
end.

You can find this information by typing

Locate "_ + _".

The + notation is used for two functions, only one of them can be applied on numbers.

Coming back to the add function, its very description explains that add 0 m computes to m and add (S n) m computes to S (add m n), but it does not say anything when the second argument has the form S m, it is just not written anywhere. Still the theory of Coq makes it possible to prove the fact.

So the equality that is given for free comes directly from the definition of addition. There are a few other equality statements that are natural to the human eye, but not given for free. They can just be proved by induction.

Would it be possible to design the Coq system in such a way that both equality statements would be given for free? The answer is probably yes, but the theory must be designed carefully for that.

Yves
  • 3,808
  • 12
  • 12