Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在coq中,如何做;诱导n方程:Hn“;以一种不';不要搞乱归纳假设?_Coq - Fatal编程技术网

在coq中,如何做;诱导n方程:Hn“;以一种不';不要搞乱归纳假设?

在coq中,如何做;诱导n方程:Hn“;以一种不';不要搞乱归纳假设?,coq,Coq,在使用归纳法时,我希望使用假设n=0和n=sn'来区分案例 Section x. Variable P : nat -> Prop. Axiom P0: P 0. Axiom PSn : forall n, P n -> P (S n). Theorem Pn: forall n:nat, P n. Proof. intros n. induction n. - (* = 0 *) apply P0. - (* = S n *)

在使用归纳法时,我希望使用假设
n=0
n=sn'
来区分案例

Section x.
  Variable P : nat -> Prop.
  Axiom P0: P 0.
  Axiom PSn : forall n, P n -> P (S n).

  Theorem Pn: forall n:nat, P n.
  Proof. intros n. induction n.
   - (* = 0 *) 
     apply P0. 
   - (* = S n *)
     apply PSn. assumption.
  Qed.
理论上,我可以用归纳法n eqn:Hn来实现这一点,但这似乎打乱了归纳假设:

  Theorem Pn2: forall n:nat, P n.
  Proof. intros n. induction n eqn: Hn.
   - (* Hn : n = 0 *) 
     apply P0. 
   - (* Hn : n = S n0 *)
     (*** 1 subgoals
      P : nat -> Prop
      n : nat
      n0 : nat
      Hn : n = S n0
      IHn0 : n = n0 -> P n0
      ______________________________________(1/1)
      P (S n0)
     ****)
  Abort.
End x.

有没有一种简单的方法可以得到我想要的东西?

我不确定这是否比你在第二次尝试中所做的更容易,但你可以先“记住”
n

 Theorem Pn: forall n:nat, P n.
 Proof. intro n. remember n. induction n.
 - (*P : nat -> Prop
     n0 : nat
     Heqn0 : n0 = 0
     ============================
     P n0
    *)
    subst. apply P0.
 - (* P : nat -> Prop
      n : nat
      n0 : nat
      Heqn0 : n0 = S n
      IHn : n0 = n -> P n0
      ============================
      P n0
    *)

哦,我想我知道了

应用归纳假设将你的目标从(pn)改为(p(构造器n'),因此我认为一般来说,你可以根据目标来创建方程n=构造器n'

我认为有一种策略可以做到这一点:

(* like set (a:=b) except introduces a name and hypothesis *)
Tactic Notation 
    "provide_name" ident(n) "=" constr(v)
       "as" simple_intropattern(H) :=
    assert (exists n, n = v) as [n H] by (exists v; reflexivity).

Tactic Notation
  "induction_eqn" ident(n) "as" simple_intropattern(HNS)
    "eqn:" ident(Hn) :=
  let PROP := fresh in (
    pattern n;
    match goal with [ |- ?FP _ ] => set ( PROP := FP ) end;
    induction n as HNS;
    match goal with [ |- PROP ?nnn ] => provide_name n = nnn as Hn end;
    unfold PROP in *; clear PROP
  ).
它适用于我的示例:

Theorem Pn_3: forall n:nat, P n.
Proof.
  intros n.
  induction_eqn n as [|n'] eqn: Hn.
  - (* n: nat, Hn: n = 0; Goal: P 0 *)
    apply P0.
  - (* n': nat, IHn': P n';
       n: nat, Hn: n = S n'
       Goal: P (S n') *)
    apply PSn. exact IHn'.
Qed.

马特几乎是对的,你只是忘记了通过还原记忆中的
n
来概括一下你的目标:

Theorem Pn2: forall n:nat, P n.
  Proof. intros n. remember n. revert n0 Heqn0.
  induction n as [ | p hi]; intros m heq.
  - (* heq : n = 0 *)  subst. apply P0. 
  - (* heq : n = S n0 *)
    (* 
  1 subgoal
  P : nat -> Prop
  p : nat
  hi : forall n0 : nat, n0 = p -> P n0
  m : nat
  heq : m = S p
  ______________________________________(1/1)
  P m
  *) subst; apply (PSn p). apply hi. reflexivity.

谷歌搜索“coq感应eqn”的结果表明,这一点已被打破,而且“eqn:”一词似乎最近已从参考手册中删除。链接:,在这种情况下,Heqn0仍然被归纳假设捕获,使其无法使用(因为n0=sn/\n0=n是一个矛盾)。