The tensor notation used in several areas of mathematics is a useful one, but it is not widely available to the functional programming community. In a practical sense, the (embedded) domain-specific languages (DSLs) that are currently in use for tensor algebra are either 1. array-oriented languages that do not enforce or take advantage of tensor properties and algebraic structure or 2. follow the categorical structure of tensors but require the programmer to manipulate tensors in an unwieldy point-free notation. A deeper issue is that for tensor calculus, the dominant pedagogical paradigm assumes an audience which is either comfortable with notational liberties which programmers cannot afford, or focus on the applied mathematics of tensors, largely leaving their linguistic aspects (behaviour of variable binding, syntax and semantics, etc.) for the reader to figure out by themselves. This state of affairs is hardly surprising, because, as we highlight, several properties of standard tensor notation are somewhat exotic from the perspective of lambda calculi. We bridge the gap by defining a DSL, embedded in Haskell, whose syntax closely captures the index notation for tensors in wide use in the literature. The semantics of this EDSL is defined in terms of the algebraic structures which define tensors in their full generality. This way, we believe that our EDSL can be used both as a tool for scientific computing, but also as a vehicle to express and present the theory and applications of tensors.
翻译:数学多个领域中使用的张量符号虽然实用,但在函数式编程社区中并未得到广泛应用。从实践角度看,当前用于张量代数的(嵌入式)领域特定语言(DSL)要么是:1. 不强制利用张量属性和代数结构的面向数组语言,要么是2. 遵循张量的范畴结构,却要求程序员以笨拙的无点式符号操作张量。更深层的问题在于:在张量演算领域,主流教学范式假定受众能容忍程序员无法接受的符号自由度,或者聚焦于张量应用数学,而将其语言特性(变量绑定行为、语法和语义等)留给读者自行领悟。这种现状并不令人意外——正如我们所强调的,标准张量符号的若干特性从λ演算视角看略显异质。我们通过定义一种嵌入在Haskell中的DSL来弥合这一鸿沟,其语法紧密复现了文献中广泛使用的张量索引符号。该嵌入式领域特定语言(EDSL)的语义定义基于能完整定义张量的一般代数结构。由此,我们相信该EDSL既能用作科学计算工具,也能成为表达和呈现张量理论及其应用的载体。