2

完成 CIS 500 软件基础课程CIS 500 软件基础课程。目前在MoreCoq上。我不明白这rewrite IHl1部分。它是如何工作的?为什么这在以前使用时不起作用simpl

Definition split_combine_statement : Prop := forall X Y (l1 : list X) (l2 : list Y),
  length l1 = length l2 -> split (combine l1 l2) = (l1,l2).

Theorem split_combine : split_combine_statement.
Proof. unfold split_combine_statement. intros. generalize dependent Y. induction l1. 
 Case "l = []". simpl. intros. destruct l2. 
  SCase "l2 = []". reflexivity. 
  SCase "l2 = y :: l2". inversion H.
 Case "l = x :: l1". intros.  destruct l2. 
  SCase "l2 = []". inversion H.
  SCase "l2 = y :: l2". simpl. rewrite IHl1.
4

1 回答 1

4

你的假设IHl1是:

IHl1 : forall (Y : Type) (l2 : list Y),
       length l1 = length l2 -> split (combine l1 l2) = (l1, l2)

所以为了重写它,你需要实例化Y类型和l2列表。接下来,您需要提供相等性length l1 = length l2来重写 split (combine l1 l2) = (l1,l2)。整个解决方案是:

Definition split_combine_statement : Prop := forall X Y (l1 : list X) (l2 : list Y),
  length l1 = length l2 -> split (combine l1 l2) = (l1,l2).

Theorem split_combine : split_combine_statement.
Proof. 
  unfold split_combine_statement. 
  intros. generalize dependent Y. induction l1. 
  simpl. intros. destruct l2. 
  reflexivity. 
  inversion H.
  intros.  destruct l2. 
  inversion H.
  simpl. inversion H. rewrite (IHl1 Y l2 H1). reflexivity.
Qed.

请注意,要重写IHl1,我们需要实例化全称量词(为其变量传递足够的值)并为蕴涵提供左侧。用 Coq 的话来说:rewrite (IHl1 Y l2 H1)是传递类型Y来实例化forall (Y : Type)in IHl1。对于l2.

于 2015-12-29T11:39:48.747 回答