Table of Contents
Fetching ...

Domain-Specific Tensor Languages

Jean-Philippe Bernardy, Patrik Jansson

TL;DR

Bridging the gap between algebraic tensor theory and functional programming, this paper argues that tensor notation is not well supported in FP DSLs. It presents two embedded DSLs, Roger (point-free, diagram-oriented) and Albert (index-based, Einstein-style), both embedded in Haskell and grounded in tensor-catgory structures such as $\mathrm{SMC}$ and compact-closed categories, with executable semantics. The key contributions are (i) formalizing the semantics that connect algebraic tensor representations with coordinate-based and diagrammatic notations, (ii) implementing a practical library that can render to Einstein notation, string diagrams, or matrix computations, and (iii) demonstrating tensor-field calculus and general relativity computations (covariant derivatives, Christoffel symbols, $R^l{}_{i j k}$, Schwarzschild metric). This enables scientific computing and pedagogy by providing a unified, type-safe framework for expressing and manipulating tensors.

Abstract

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.

Domain-Specific Tensor Languages

TL;DR

Bridging the gap between algebraic tensor theory and functional programming, this paper argues that tensor notation is not well supported in FP DSLs. It presents two embedded DSLs, Roger (point-free, diagram-oriented) and Albert (index-based, Einstein-style), both embedded in Haskell and grounded in tensor-catgory structures such as and compact-closed categories, with executable semantics. The key contributions are (i) formalizing the semantics that connect algebraic tensor representations with coordinate-based and diagrammatic notations, (ii) implementing a practical library that can render to Einstein notation, string diagrams, or matrix computations, and (iii) demonstrating tensor-field calculus and general relativity computations (covariant derivatives, Christoffel symbols, , Schwarzschild metric). This enables scientific computing and pedagogy by providing a unified, type-safe framework for expressing and manipulating tensors.

Abstract

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.
Paper Structure (2 sections, 8 equations, 1 figure)

This paper contains 2 sections, 8 equations, 1 figure.