- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
关于 list 1,需要类型级公理
(t a) = (t (getUI(t a)))
应该作为每个特定类型类实例的定理可推导。
test
函数的编译是否证明类型级公理适用于程序中的特定类型?编译是否提供了Theorems for free!的例子?
list 1
{-# LANGUAGE MultiParamTypeClasses #-}
data Continuant a = Continuant a deriving (Show,Eq)
class UI a where
instance UI Int where
class Category t a where
getUI :: (UI a) => (t a) -> a
instance Category Continuant Int where
getUI (Continuant a) = a
-- axiom (t a) = (t (getUI(t a))) holds for given types?
test :: Int -> Bool
test x = (Continuant x) == (Continuant (getUI (Continuant x)))
其他上下文
代码基于 paper声明的地方:
For all implementations of getUI one may require that the axiom (t a) = (t (getUI (t a))) holds. This must be proven to hold for every specific type class instance declaration. For finite types this can be done by a program that enumerates all possibilities. For infinite types this must be done manually via proofs by induction.
list 1 是我的证明尝试。根据解决方案 1,也许我错误地认为这需要 Theorems for free!
最佳答案
不,它是一个类的事实给了你太多的回旋余地来单独保证该公理。例如,以下替代实例类型检查但违反了您的公理:
instance Category Continuant Int where
getUI _ = 42
(完全明确地说,我们的对手可以选择例如 t=Continuant
和 a=6*9
来违反公理。)这滥用了类的事实实例化器开始选择包含的类型。我们可以通过删除该类的参数来删除该功能:
class Category t where
getUI :: UI a => t a -> a
唉,这还不够。我们可以写
data Pair a = Pair a a
然后自由定理告诉我们,对于instance Category Pair
,我们必须编写以下两个定义之一:
getUI (Pair x y) = x
-- OR
getUI (Pair x y) = y
无论我们选择哪个,我们的对手都可以选择一个 t
来告诉我们我们的公理是错误的。
Our choice Adversary's choice
getUI (Pair x y) = x t y = Pair 42 y; a = 6*9
getUI (Pair x y) = y t x = Pair x 42; a = 6*9
好吧,这滥用了类实例化器选择 t
的事实。如果我们移除该能力会怎样...?
class Category where
getUI :: UI a => t a -> a
这极大地限制了Category
的实例化器。太多了,事实上:getUI
只能作为无限循环之类的实现。
我怀疑将您希望的公理编码为只能由满足它的事物所居住的类型来编码是非常困难的。
关于haskell - 这个 Haskell 程序是否提供 "Theorems for free!"的示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54253762/
分布式系统如何保持一致和可用-CA。因为当分区发生时,CA是不可能的。如果我们说不会发生分区,那么只有它们是CA,那么如果分区不会发生,那么所有CP或AP系统也将是CA。 最佳答案 不可以 如常提到的
考虑以下片段: import Data.List %default total x : Elem 1 [1, 2] x = Here type : Type type = Elem 1 [1, 2]
我有以下目标: ∀x ∈ {0,1,2,3,4,5}. P x 我想将这个目标分解为六个子目标 P 0、P 1、P 2、P 3、P 4 和 P 5。这可以通过 apply auto 轻松完成。但是 a
我有以下目标: ∀x ∈ {0,1,2,3,4,5}. P x 我想将这个目标分解为六个子目标 P 0、P 1、P 2、P 3、P 4 和 P 5。这可以通过 apply auto 轻松完成。但是 a
主定理可用于求解递归关系,例如T(n)= aT(n/b)+f(n)。 那么,如果 f(n)=O(n) 或 f(n)=cn 两者的值是否相同?我也可以对 f(n)=cn 使用主定理吗? 最佳答案 假设
我是一个绝对的初学者,不是程序员,正在尝试使用 Logic and Proof 学习形式验证.我无法在精益中导入任何东西。 我将二进制文件的 tar 文件提取到 /tmp 然后执行 /tmp/lean
如果我理解正确(主要来自 applyTactic 函数的存在),则可以为 Idris 中的定理证明器编写自定义策略。我可以用什么(或哪里)的例子来学习如何做到这一点? 最佳答案 在 Idris 中有两
如何导出该类型的自由定理: data F a = C1 Nat | C2 Bool Nat a Nat 就是 data Nat = Z | S Nat? 原则上,Haskell 的“free-theo
我正在尝试使用 Kowalski 图算法来求解定理证明。算法的描述位于 http://www.doc.ic.ac.uk/~rak/对于如何处理大事件却保持沉默它生成的重复子句的数量。我想知道是否有处理
我对此很沮丧。 在 CLRS 第 3 版第 95 页(第 4.5 章)中,它提到像 T(n) = 2T(n/2) + n lg n 不能用主定理解决,因为差异 f(n)/n^(log_b(a)) =
沿着 The Haskell Road to Logic, Maths and Programming,你可以找到第 48 页 定理 2.12.1 ¬ ⊤ ≡ ⊥和它的反面 ¬ ⊥ ≡ ⊤ 本书使用
在我的网页上,我展示了数学定理,页面设计与学术数学论文 (LaTeX) 中使用的风格非常接近。标题结构可能如下: 几何 平面几何 定理。 我们有 a²+b²=c²。 问题:我应该使用 吗?标签附上
我(错误地)学习了关于验证并发程序的类(class),到目前为止我们已经介绍了这种称为“Owicki-Gries 方法”的方法。显然,可以通过将断言与每个语句相关联来证明有关程序的各种结果,并表明这些
我正在做一个 bookdown 项目,遇到了定理环境的问题。当我编译为 gitbook、epub_book 或 tufte_html_book 时它可以工作,但是 不是 到 pdf_book。以下是我
我从 Isabelle 的维基百科页面获得了以下代码: theorem sqrt2_not_rational: "sqrt (real 2) ∉ ℚ" proof assume "sqrt (
问题: 我的碰撞函数的某些输入似乎没有给出正确的结果。我实现了 SAT 算法来测试边界框和三角形的碰撞。当边界框处于负坐标并且三角形的 1 个点伸入其中时,输入不起作用。 示例输入: 这个输入没有发生
我一般看过两个版本的大师定理。 版本 1: (来自 Tim Roughgarden's course) 对于形式的递归关系, T(n) = 1, b > 1, and d >= 0 有3种情况, ca
我正在尝试证明在Agda中的简单引理,我认为这是对的。 If a vector has more than two elements, taking its head following taking
关于 list 1,需要类型级公理 (t a) = (t (getUI(t a))) 应该作为每个特定类型类实例的定理可推导。 test 函数的编译是否证明类型级公理适用于程序中的特定类型?编译是否提
根据Automating Induction with an SMT Solver以下应该适用于 Dafny: ghost method AdjacentImpliesTransitive(s: se
我是一名优秀的程序员,十分优秀!