完成CIS 500软件基础课程CIS 500 Software Foundations course。目前正在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.
答案 0 :(得分: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)
中的IHl1
。同样适用于l2
。