arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.18242cs.PL
收藏

使用数组进行编译

Compiling with Arrays

David Richter, Timon Böhler, Pascal Weisenburger, Mira Mezini

AI总结:

本文通过将数组视为正类型,提出索引管理范式(AiNF),实现类型化部分求值与公共子表达式消除的结合,产生最大分裂的项,以优化线性代数计算。

摘要:

线性代数计算是神经网络和机器学习的基础,通常通过数组来处理。虽然许多函数式编程语言具有列表和递归的特性,但线性代数中的数组需要常数时间的访问和批量操作。为了弥合这一差距,一些语言将数组表示为(急切的)函数而不是列表。在本文中,我们通过将函数解释为极化类型论中通常的负类型,并将数组解释为函数类型对应的对偶正版本,将这一想法与形式逻辑基础联系起来。正类型被定义为具有单一消去形式,其计算解释是模式匹配。正如(正的)乘积类型在模式匹配期间绑定两个变量一样,(正的)数组类型在模式匹配期间绑定具有多重性的变量。我们对布尔值采用类似的方法,引入条件定义的变量。\n 数组类型的正形式使我们能够将类型化部分求值和公共子表达式消除组合成一个优雅的算法,其结果具有我们称为最大分裂的性质,我们认为这对进一步的优化是有益的。为此,我们提出了新颖的中间表示索引管理范式(AiNF),它依赖于数组类型的正形式的形式逻辑基础,以促进最大循环分裂和后续优化。AiNF对于let绑定和for循环的交换转换都是规范的,从而产生扁平且最大分裂的项。我们将从简单表面语言到AiNF的翻译和规范化机械化,确定该过程终止、保持类型并产生最大分裂的项。

英文摘要:

Linear algebra computations are foundational for neural networks and machine learning, often handled through arrays. While many functional programming languages feature lists and recursion, arrays in linear algebra demand constant-time access and bulk operations. To bridge this gap, some languages represent arrays as (eager) functions instead of lists. In this paper, we connect this idea to a formal logical foundation by interpreting functions as the usual negative types from polarized type theory, and arrays as the corresponding dual positive version of the function type. Positive types are defined to have a single elimination form whose computational interpretation is pattern matching. Just like (positive) product types bind two variables during pattern matching, (positive) array types bind variables with multiplicity during pattern matching. We follow a similar approach for Booleans by introducing conditionally-defined variables. The positive formulation for the array type enables us to combine typed partial evaluation and common subexpression elimination into an elegant algorithm whose result enjoys a property we call maximal fission, which we argue can be beneficial for further optimizations. For this purpose, we present the novel intermediate representation indexed administrative normal form (AiNF), which relies on the formal logical foundation of the positive formulation for the array type to facilitate maximal loop fission and subsequent optimizations. AiNF is normal with regard to commuting conversion for both let-bindings and for-loops, leading to flat and maximally fissioned terms. We mechanize the translation and normalization from a simple surface language to AiNF, establishing that the process terminates, preserves types, and produces maximally fissioned terms.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑