coq - 检查自然数列表对的相等性
问题描述
我有两个自然数列表对,想检查它们是否相等。
Fixpoint beq_natlist (l1 l2 : list*list) : bool :=
match l1, l2 with
| (nil , nil) => true
| (h :: nil, nil) => false
| ( nil , h :: nil) => false
| h1 :: t1, h2 :: t2 => if beq_nat h1 h2 then beq_natlist t1 t2 else false
end.
解决方案
首先,s 的相等性list nat
如下所示。请注意,多重匹配模式a, b
和对表示法(a, b)
是两个完全不同的东西。前者匹配两个术语,而后者匹配一个术语,它是一对。
Fixpoint beq_natlist (l1 l2 : list nat) : bool :=
match l1, l2 with
| nil, nil => true
| h :: nil, nil => false
| nil, h :: nil => false
| h1 :: t1, h2 :: t2 => if beq_nat h1 h2 then beq_natlist t1 t2 else false
end.
然后你可以使用beq_natlist
来建立平等list nat * list nat
:
Fixpoint beq_natlist_pair (p1 p2 : list nat * list nat) : bool :=
match p1, p2 with
| (l1, l2), (l3, l4) => beq_natlist l1 l3 && beq_natlist l2 l4
end.
推荐阅读
- php - PHP mail.php 操作在连接到 cloudflare 时打开一个新选项卡
- odoo - 如何从 javascript 获取 odoo 模型?
- mysql - 创建连接配置文件时出现问题
- python - 将图像转换为 numpy 数组需要什么?
- django - 从views.py在数据库中创建模型对象时如何自动创建主键
- javascript - 为什么这个物体不动?
- ios - 如何阻止背景阻止 Swift 4 中的其他元素?
- r - 使用 lubridate 格式化多个日期样式时遇到问题
- javascript - 无法在三个js中查看对象
- botkit - 使用 Botkit CMS 和 Botkit Web 设置错误