[英]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!在您第一次调用nat_ind
之后,如果您查看您的目标,您会发现 Coq 根本没有做正确的事情!
______________________________________(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!这里发生的事情是它猜测了你的动机p
,并决定将它与fun (_: nat) => <YOUR_WHOLE_GOAL>
统一起来,一个 function 给出任何nat
都会给你的目标......是的,这很愚蠢!
One way to nudge it into doing the induction on a
is by explicitly forcing it to do so, with:推动它对 a 进行归纳的a
方法是明确地强制它这样做,其中:
apply nat_ind with (n:= a)
(where the n
matches the name used in your definition of nat_ind
) (其中n
与您的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.其中确实a
已分别被0
和S n
取代。
[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.所有这些,以及你想要证明的东西,都已经存在于 Coq 中了。 Is this homework?这是作业吗? Are you just training?你只是在训练吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.