Lossless compression implementations typically contain two programs, an encoder and a decoder, which are required to be inverse to one another. Maintaining consistency between two such programs during development requires care, and incorrect data decoding can be costly and difficult to debug. We observe that a significant class of compression methods, based on asymmetric numeral systems (ANS), have shared structure between the encoder and decoder -- the decoder program is the 'reverse' of the encoder program -- allowing both to be simultaneously specified by a single, reversible, 'codec' function. To exploit this, we have implemented a small reversible language, embedded in Agda, which we call 'Flipper'. Agda supports formal verification of program properties, and the compiler for our reversible language (which is implemented as an Agda macro), produces not just an encoder/decoder pair of functions but also a proof that they are inverse to one another. Thus users of the language get formal verification 'for free'. We give a small example use-case of Flipper in this paper, and plan to publish a full compression implementation soon.
翻译:无损压缩执行通常包含两个程序, 一个编码器和一个解码器, 它们需要相互反向。 在开发过程中, 要保持这两个程序的一致性, 需要小心谨慎, 不正确的数据解码可能成本高, 难以调试 。 我们观察到, 基于对称数字系统( ANS ) 的大量压缩方法在编码器和解码器之间有共同的结构 -- 解码器程序是编码器程序的“ 反向”, 允许这两个程序同时由单一的、 可逆的“ 代码” 功能来指定 。 为了利用这个功能, 我们已经在 Agda 中安装了一个小的可逆语言, 我们称之为“ Flipper ” 。 Agda 支持正式验证程序属性, 以及我们可变语言的编译器( 作为 Agda 宏执行), 不仅产生一个编码器/ decoder 双功能, 而且证明它们与另一个功能相反 。 因此语言的用户可以免费获得正式的“ codecodec” 。 我们给该文件中的用户一个小示例使用 Flipper 。