- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在理解 Coq 中强规范和弱规范之间的区别时遇到了一些麻烦。例如,如果我想使用强规范方式编写复制函数(给定一个数字 n 和一个值 x,它会创建一个长度为 n 的列表,其中所有元素都等于 x),我将如何做到这一点?显然我必须编写函数的归纳“版本”,但如何编写?
Haskell 中的定义:
myReplicate :: Int -> a -> [a]
myReplicate 0 _ = []
myReplicate n x | n > 0 = x:myReplicate (n-1) x
| otherwise = []
弱规范定义 :
Inductive RelLength (A:Type) : nat -> list A -> Prop :=
| len_nil : RelLength 0 nil
| len_cons : forall l x n, RelLength n l -> RelLength (S n) (x::l) .
Theorem len_corr : forall (A:Type) (l:list A), {n | RelLength n l}.
Proof.
…
Qed.
Recursive Extraction len_corr.
用于证明的函数必须直接使用列表“recursor”(这就是修复点不会出现的原因——它隐藏在 list_rect 中)。
最佳答案
只是为了好玩,这里是 Haskell 中的样子,在那里所有依赖的东西都更烦人。这段代码使用了一些非常新的 GHC 特性,主要是为了使类型更加明确,但可以很容易地修改它以使用旧的 GHC 版本。
{-# language GADTs, TypeFamilies, PolyKinds, DataKinds, ScopedTypeVariables,
TypeOperators, TypeApplications, StandaloneKindSignatures #-}
{-# OPTIONS_GHC -Wincomplete-patterns #-}
module RelRepl where
import Data.Kind (Type)
import Data.Type.Equality ((:~:)(..))
-- | Singletons (borrowed from the `singletons` package).
type Sing :: forall (k :: Type). k -> Type
type family Sing
type instance Sing @Nat = SNat
type instance Sing @[a] = SList @a
-- The version of Sing in the singletons package has many more instances;
-- in any case, more can be added anywhere as needed.
-- Natural numbers, used at the type level
data Nat = Z | S Nat
-- Singleton representations of natural numbers, used
-- at the term level.
data SNat :: Nat -> Type where
SZ :: SNat 'Z
SS :: SNat n -> SNat ('S n)
-- Singleton lists
data SList :: forall (a :: Type). [a] -> Type where
SNil :: SList '[]
SCons :: Sing a -> SList as -> SList (a ': as)
-- The relation representing the `replicate` function.
data RelRepl :: forall (a :: Type). Nat -> a -> [a] -> Type where
Repl_Z :: forall x. RelRepl 'Z x '[]
Repl_S :: forall n x l. RelRepl n x l -> RelRepl ('S n) x (x ': l)
-- Dependent pairs, because those aren't natively supported.
data DPair :: forall (a :: Type). (a -> Type) -> Type where
MkDPair :: forall {a :: Type} (x :: a) (p :: a -> Type).
Sing x -> p x -> DPair @a p
-- Proof that every natural number and value produce a list
-- satisfying the relation.
repl_corr :: forall {a :: Type} (n :: Nat) (x :: a).
SNat n -> Sing x -> DPair @[a] (RelRepl n x)
repl_corr SZ _x = MkDPair SNil Repl_Z
repl_corr (SS n) x
| MkDPair l pf <- repl_corr n x
= MkDPair (SCons x l) (Repl_S pf)
-- Here's a proof that the relation indeed specifies
-- a *unique* function.
replUnique :: forall {a :: Type} (n :: Nat) (x :: a) (xs :: [a]) (ys :: [a]).
RelRepl n x xs -> RelRepl n x ys -> xs :~: ys
replUnique Repl_Z Repl_Z = Refl
replUnique (Repl_S pf1) (Repl_S pf2)
| Refl <- replUnique pf1 pf2
= Refl
关于haskell - Coq:haskell 的 Replicate 函数的强规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67661349/
LMAX Disruptor 通常使用以下方法实现: 如本例所示,Replicator 负责将输入事件\命令复制到从节点。跨一组节点进行复制需要我们应用共识算法,以防我们希望系统在出现网络故障、主故障
我对这两个概念感到困惑:In-graph replication和 Between-graph replication阅读 Replicated training 时在 tensorflow 的官方
我对这两个概念感到困惑:In-graph replication和 Between-graph replication阅读 Replicated training 时在 tensorflow 的官方
我在事件监视器中收到以下错误, The row was not found at the Subscriber when applying the replicated command. (Sourc
我正在尝试设置 mysql 复制。我看到了在不同地方使用的两个提到的选项。我觉得replicate-rewrite-db是在master和slave中的数据库名称不同的情况下使用的。这是这两个选项之间
我正在关注 Realm Postgres Connector 引用,用于将我们的 Realm 数据库与我们的 Heroku PostgreSQL 数据库同步:https://docs.realm.io
我很难找到数据同步和复制之间的差异。 据我所知,复制使 2 个数据库之间的所有数据都相同。同步不一定使两个数据库之间的所有数据都相同。复制是一次传输,同步可以是小更新以保持数据一致吗?我不太确定,请在
我们刚刚成功地将一个主服务器备份到了一个热备服务器上。但是,当我们尝试查询热备时,会出现以下错误: ERROR: cannot assign TransactionIds during recover
有两个进程访问共享变量x,y和z。每个进程访问用于保存这些变量的存储的不同副本。 x,y和z的初始值是0。 流程1: x = 1; if (y == 0) z++; 和过程2: y = 1; if
我需要一个图形数据库,该数据库需要备份并可能在较低的抽象级别上访问。为了负载平衡,它也必须分布,(单主复制就可以了)。 我知道可以使用自引用键值存储来实现图形数据库。 Git 对象数据库就是这种模式的
我正在构建一个解决方案,该解决方案将部署在全局多个地区的多个数据中心,每个数据中心都有一个在每个地区主动更新的数据副本。我将在每个数据中心有多个数据库和文件系统的组合,它们的状态必须保持一致(在一个数
我有 2 个数据库 X“生产”和 Y“测试” 数据库 X 的结构应与 Y 相同。但是,他们并不是因为我的疯狂而对制作进行了很多改动。现在,我需要以某种方式导出 X 并将其导入 Y 而不会破坏任何复制。
使用REPLICATE(以指定的次数重复字符表达式)函数 REPLICATE函数用于以指定的次数重复字符表达式。 语法: REPLICATE (character_expression,int
我的理解在这里可能有误。据我了解,Couchbase 使用智能客户端来自动选择要在集群中写入或读取的节点。我不明白的是,当这些数据被写入/读取时,它是否也立即写入所有其他节点?如果是这样,在节点发生故
我目前正在处理 Crystal Reports 中的一个项目,该项目拒绝使用 Oracle 10g 中允许的未记录函数 WM_CONCAT。 这是WM_CONCAT头信息 WM_CONCAT(p1 I
我有一个在防火墙后面运行的 SOLR 实例。我即将建立另一个不会被防火墙保护的实例。但是,SOLR 似乎只支持拉复制而不支持推送复制。 为了保持相同的安全级别,我有哪些选择?我宁愿不要在防火墙中打开太
有人可以解释为 RavenDB 设置复制的基本步骤吗?我正在使用 build 888。根据我在网上找到的内容,我可以猜测可能需要做什么,但我宁愿确定。 我相信这是复制的官方文档: http://rav
我想在SQL Server和MySQL之间设置复制,其中SQL Server是主数据库服务器,而MySQL是从属服务器(在Linux上)。 有没有办法设置这种情况?帮我 。 最佳答案 我的答案可能来不
我想了解以下 Lotus-Domino 服务器到服务器复制场景中会发生什么: 服务器 A 有 A 数据库的副本。 服务器 B 具有相同数据库的副本。 两台服务器都对数据库具有管理员访问权限,包括删除文
我有一个 2 节点的 cassandra 集群,复制因子为 2,AutoBootStrap=true。启动期间一切正常,两个节点都能看到对方。让我们称这些节点为 A 和 B。 通过节点 A 向 cas
我是一名优秀的程序员,十分优秀!