coq - 证明在两个列表中找到相同元素的属性
问题描述
我是 Coq 的新手。我有一个函数findshare
可以在两个列表中找到相同的元素。引理sameElements
证明了函数findshare
在两个列表的连接上的结果等于函数在每个列表上的结果的连接。我有点坚持证明 lemma sameElements
。
Require Import List .
Fixpoint findshare(s1 s2: list nat): list nat:=
match s1 with
| nil => nil
| v :: tl =>
if ( existsb (Nat.eqb v) s2)
then v :: findshare tl s2
else findshare tl s2
end.
Lemma sameElements l1 l2 tl :
(findshare tl (l1++l2)) =
(findshare tl (l1))++ (findshare tl (l2)).
Proof.
解决方案
您遇到了麻烦,因为您的陈述并不完全正确:它包含矛盾。更准确地说,它意味着[1; 2] = [2; 1]
:
Require Import List .
Fixpoint findshare(s1 s2: list nat): list nat:=
match s1 with
| nil => nil
| v :: tl =>
if ( existsb (Nat.eqb v) s2)
then v :: findshare tl s2
else findshare tl s2
end.
Lemma sameElements l1 l2 tl :
(findshare tl (l1++l2)) =
(findshare tl (l1))++ (findshare tl (l2)).
Admitted.
Import ListNotations.
Lemma contra : False.
Proof.
pose proof (sameElements [1] [2] [2;1]).
simpl in H.
discriminate.
Qed.
您应该能够通过tl
与和交换来证明引理l1
,并通过归纳继续进行。l2
l1 ++ l2
l1
推荐阅读
- java - 由于 Git 中不相关的冲突,无法提取原始开发人员
- events - 如何在 rabbitmq 中组织交换和队列以与异步 CQRS 总线一起使用
- java - 如何使用 BigDecimal 来提高此方法的准确性?
- python - PuLP - 为什么不能对 UpBounds 使用生成器/列表表达式?“TypeError:必须是实数,不是列表”
- javascript - 从承诺的 Postgres 查询中检查数据库的列中是否存在值
- java - 如何将条带支付网关添加到 android studio 应用程序中?
- python - numpy.einsum 对 cv2 加载的数组的作用是否不同?
- sql-server - 尝试访问 WCF 服务的 SQL Server CLR 函数,我不断收到“System.Security.HostProtectionException”错误返回
- design-patterns - 如何构建我的所有数据源共享相同结构的管道架构?
- recursion - 如何向此方案功能添加计数器