Containers conveniently represent a wide class of inductive data types. Their derivatives compute representations of types of one-hole contexts, useful for implementing tree-traversal algorithms. In the category of containers and cartesian morphisms, derivatives of discrete containers (whose positions have decidable equality) satisfy a universal property. Working in Univalent Foundations, we extend the derivative operation to untruncated containers (whose shapes and positions are arbitrary types). We prove that this derivative, defined in terms of a set of isolated positions, satisfies an appropriate universal property in the wild category of untruncated containers and cartesian morphisms, as well as basic laws with respect to constants, sums and products. A chain rule exists, but is in general non-invertible. In fact, a globally invertible chain rule is inconsistent in the presence of non-set types, and equivalent to a classical principle when restricted to set-truncated containers. We derive a rule for derivatives of smallest fixed points from the chain rule, and characterize its invertibility. All of our results are formalized in Cubical Agda.
翻译:容器为广泛类别的归纳数据类型提供了便捷的表示。其导数可计算单孔上下文类型的表示,这对于实现树遍历算法非常有用。在容器与笛卡尔态射的范畴中,离散容器(其位置具有可判定相等性)的导数满足一个泛性质。在单值基础框架下工作,我们将导数运算推广至非截断容器(其形状与位置为任意类型)。我们证明,该导数(基于一组孤立位置定义)在非截断容器与笛卡尔态射的野生范畴中满足一个恰当的泛性质,并且关于常数、和与积满足基本运算法则。链式法则存在,但通常不可逆。事实上,在存在非集合类型的情况下,全局可逆的链式法则是不一致的;而当限制在集合截断容器时,其等价于一个经典原理。我们从链式法则推导出最小不动点导数的计算规则,并刻画了其可逆性条件。我们的所有结果均在Cubical Agda中进行了形式化验证。