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既能作为科学计算工具,也可成为表达和呈现张量理论与应用的有效载体。