isabelle - 使用 zip、map 和 products 终止递归函数的问题
问题描述
我在尝试定义使用 map over zip 的递归函数时遇到了问题。
这是我的代码的简化版本,第一个可以使用
datatype bar = Bar "bar list"
function (sequential) bar_lub :: "[bar,bar] ⇒ bar" ("_⊔b_" [30,60] 60)
where
"(Bar ts) ⊔b (Bar us) = Bar (map (λ(t1,t2). t1 ⊔b t2) (zip ts us))"
by pat_completeness auto
这很好,并导致终止目标
1. ⋀ts us a b. (a, b) ∈ set (zip ts us) ⟹ P (a, b) ~ P (Bar ts, Bar us)
这很容易证明给定一个适当的P
和~
。
当我将列表更改为对列表时,我的问题就来了,如下
数据类型 'a foo = Foo "('a foo × 'a) 列表"
function (sequential) foo_lub1 :: "['a foo, 'a foo] ⇒ 'a foo" ("_⊔_" [30,60] 60)
where
"(Foo ts) ⊔ (Foo us) = Foo (map (λ((t1,_), (t2,_)). (t1 ⊔ t2, undefined)) (zip ts us))"
by pat_completeness auto
现在,我们得到终止目标
1. ⋀ts us t1 b1 t2 b2 xc. ((t1, b1), t2, b2) ∈ set (zip ts us) ⟹ P (t1, xc) ~ P (Foo ts, Foo us)
变量xc
已经出现,并且与任何事物无关。理想情况下,我希望有这个假设xc = t2
,并且证明会很简单。
有谁知道为什么会发生这种情况,以及任何解决方法?
解决方案
这些function
包使用一致性规则来确定递归调用的上下文。不幸的是,全等规则不能捕获所有类型的上下文,元组上的深度模式匹配就是这样一种失败的情况。幸运的是,有一个简单的解决方法:使用投影fst
而snd
不是元组抽象:
function (sequential) foo_lub1 :: "['a foo, 'a foo] ⇒ 'a foo" ("_⊔_" [30,60] 60)
where
"(Foo ts) ⊔ (Foo us) = Foo (map (λx. (fst (fst x) ⊔ fst (snd x), undefined)) (zip ts us))"
推荐阅读
- java - Java 应用程序 - 摆动 - 右键单击弹出更改背景颜色
- javascript - 如何在每个月建立我的许可条件?
- reactjs - 函数中的 reactJS fetch 执行但时间已关闭
- javascript - A-frame.js a-sky 偶尔在连续嵌入负载上使用立方体几何而不是球体
- apache-zookeeper - 如何让 Zookeeper 为 Druid 提供 IP 而不是主机名
- javascript - 如何使用户能够在我的聊天网站中发送和接收消息?
- ios - 创建可供整个 iOS 应用程序访问的网络侦听器
- windows - Rode NT-USB 麦克风升级到 Windows 10 18.09 后音质不佳(10 月更新)
- docker - AM572x - 使用 docker 在 A15 和 M4 之间访问 IPC
- c# - Unity - 无法让物体振动/悬停在原地?