简体   繁体   中英

How to prove a*b*c=a*(b*c) in Coq?

Im trying to prove the above question. I have been given a definition of an induction:

Definition nat_ind 
  (p : nat -> Prop)
  (basis : p 0)
  (step : forall n, p n -> p (S n)) :
    forall n, p n := fix f n :=
      match n return p n with
      | 0 => basis
      | S n => step n (f n)
      end.

This is my attempt, but don't know how to finish

Goal forall a b c, a * b * c = a * (b * c).
Proof. 
 apply nat_ind.
  - intros a b c. revert a.
    apply (nat_ind (fun a => a * b * c = a * (b * c))); simpl.
    + reflexivity.
    + intros. f_equal. intros. 

After your very first nat_ind invocation, if you look at your goal, you see that Coq did not do the right thing at all!

______________________________________(1/3)
forall a b c : nat, a * b * c = a * (b * c)
______________________________________(2/3)
nat ->
(forall a b c : nat, a * b * c = a * (b * c)) ->
forall a b c : nat, a * b * c = a * (b * c)
______________________________________(3/3)
nat

What happened here is that it made a guess for your motive p , and decided to unify it with fun (_: nat) => <YOUR_WHOLE_GOAL> , a function which given any nat would give your goal... Yes, this is silly!

One way to nudge it into doing the induction on a is by explicitly forcing it to do so, with:

apply nat_ind with (n:= a)

(where the n matches the name used in your definition of nat_ind )

After this, you get the much more reasonable goals:

______________________________________(1/2)
forall b c : nat, 0 * b * c = 0 * (b * c)
______________________________________(2/2)
forall n : nat,
(forall b c : nat, n * b * c = n * (b * c)) ->
forall b c : nat, S n * b * c = S n * (b * c)

where indeed a has been replaced by 0 and S n respectively.

[EDIT: I guess this does not quite answer your question as you had gotten your way to the same point with the second induction call...]

To solve your goal, it will help a lot to have a property about distributivity of multiplication over addition:

forall n m p, (n + m) * p = n * p + m * p

All of these, as well as what you're trying to prove, already exists in Coq. Is this homework? Are you just training?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM