如何证明Coq中的a * b * c = a *(b * c)?

问题描述 投票:1回答:1

我正在尝试证明上述问题。给我一个归纳的定义:

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.

这是我的尝试,但不知道如何完成

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. 
coq induction coqide
1个回答
1
投票

第一次调用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

这里发生的事情是它猜测了您的动机p,并决定将其与fun (_ : nat) => <YOUR_WHOLE_GOAL>统一,给定nat的函数将给您目标……是的,这很愚蠢!] >

将其推向a的归纳的一种方法是通过显式强制它这样做:

apply nat_ind with (n := a)

((n与您在nat_ind定义中使用的名称匹配)

此后,您将获得更合理的目标:

______________________________________(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)

实际上a已分别由0S n代替。

[[编辑:我想这还不能完全回答您的问题,因为您已经通过第二次上岗电话到达了同一点...]

为了解决您的目标,拥有关于乘法加法的分布性的特性将大有帮助:

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

所有这些,以及您要证明的,已经在Coq中存在。这是作业吗?您只是在训练吗?

© www.soinside.com 2019 - 2024. All rights reserved.