The tactic apply
tries to fill in the blanks to match the type of the provided term with the goal. In this case, the goal (when the tactic is used) is probably something along the lines of a = b
(based on your followup, it's actually Equal a b
). The type of Equal_Trans
(when all the arguments are used) is x = z
(Equal x z
), so to unify these two types, we should have x := a
and z := b
. That only leaves y
as ambiguous, so we have to provide it.
To address your followup, no, Equal_Trans
does not take just one argument. It takes a type (Nat
in your case) three elements of that type (y
, x
and z
) and two equality proofs. However, remember that functions in Coq are curried, which means that you can call them with fewer arguments, but the result will be a function of the remaining arguments.
So really, when we say apply (Equal_Trans Nat (S (Add x' x)).
, we're saying "take this thing that has type forall (x z: Nat), Equal x (S (Add x' x)) -> Equal (S (Add x' x)) z -> Equal x z
and try to fill in some of the arguments to match it with my goal".
Coq looks at that type and realizes that the goal already looks like Equal x z
, so it's able to deduce what x
and z
have to be. Equal_Trans
still takes two more arguments that Coq can't figure out on its own (the proofs of Equal x y
and Equal y z
), so that's what the rest of the proof is doing.
We use transitivity with y := S (Add x' x)
because we can prove Equal (S (Add x x')) (S (Add x' x))
using the inductive hypothesis (IHx
). We can also prove Equal (S (Add x' x)) (Add x' (S x))
by using the definition of Add
. Hence, it's natural to route the proof of equality through S (Add x' x)
.
Now, we don't have to use transitivity with y := S (Add x' x)
. We could prove that (S (Add x x'))
and (Add x' (S x))
are both equal to some other element of Nat
. But the easiest and most direct route is through S (Add x' x)
.