-
Optimization under uncertainty
Authors:
Nicola Botta,
Patrik Jansson,
Tim Richter
Abstract:
One of the most ubiquitous problems in optimization is that of finding all the elements of a finite set at which a function $f$ attains its minimum (or maximum) on that set. When the codomain of $f$ is equipped with a reflexive, anti-symmetric and transitive relation, it is easy to specify, implement and verify generic solutions for this problem. But what if $f$ is affected by uncertainties? What…
▽ More
One of the most ubiquitous problems in optimization is that of finding all the elements of a finite set at which a function $f$ attains its minimum (or maximum) on that set. When the codomain of $f$ is equipped with a reflexive, anti-symmetric and transitive relation, it is easy to specify, implement and verify generic solutions for this problem. But what if $f$ is affected by uncertainties? What if one seeks values that minimize more than one $f$ or if $f$ does not return a single result but a set of ``possible results'' or perhaps a probability distribution on possible results? This situation is very common in integrated assessment and optimal design and developing trustable solution methods for optimization under uncertainty requires one to formulate the above questions rigorously. We show how functional programming can help formulating such questions and apply it to specify and test solution methods for the case in which optimization is affected by two conceptually different kinds of uncertainty: \it{value} and \it{functorial} uncertainty.
△ Less
Submitted 24 March, 2025;
originally announced March 2025.
-
Domain-Specific Tensor Languages
Authors:
Jean-Philippe Bernardy,
Patrik Jansson
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…
▽ More
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.
△ Less
Submitted 20 January, 2025; v1 submitted 5 December, 2023;
originally announced December 2023.
-
Types, equations, dimensions and the Pi theorem
Authors:
Nicola Botta,
Patrik Jansson,
Guilherme Horta Alvares Da Silva
Abstract:
The languages of mathematical physics and modelling are endowed with a rich "grammar of dimensions" that common abstractions of programming languages fail to represent. We propose a dependently typed domain-specific language (embedded in Idris) that captures this grammar. We apply it to explain basic notions of dimensional analysis and Buckingham's Pi theorem. We hope that the language makes mathe…
▽ More
The languages of mathematical physics and modelling are endowed with a rich "grammar of dimensions" that common abstractions of programming languages fail to represent. We propose a dependently typed domain-specific language (embedded in Idris) that captures this grammar. We apply it to explain basic notions of dimensional analysis and Buckingham's Pi theorem. We hope that the language makes mathematical physics more accessible to computer scientists and functional programming more palatable to modelers and physicists.
△ Less
Submitted 4 September, 2023; v1 submitted 16 August, 2023;
originally announced August 2023.
-
Level-p-complexity of Boolean Functions using Thinning, Memoization, and Polynomials
Authors:
Julia Jansson,
Patrik Jansson
Abstract:
This paper describes a purely functional library for computing level-$p$-complexity of Boolean functions, and applies it to two-level iterated majority. Boolean functions are simply functions from $n$ bits to one bit, and they can describe digital circuits, voting systems, etc. An example of a Boolean function is majority, which returns the value that has majority among the $n$ input bits for odd…
▽ More
This paper describes a purely functional library for computing level-$p$-complexity of Boolean functions, and applies it to two-level iterated majority. Boolean functions are simply functions from $n$ bits to one bit, and they can describe digital circuits, voting systems, etc. An example of a Boolean function is majority, which returns the value that has majority among the $n$ input bits for odd $n$. The complexity of a Boolean function $f$ measures the cost of evaluating it: how many bits of the input are needed to be certain about the result of $f$. There are many competing complexity measures but we focus on level-$p$-complexity -- a function of the probability $p$ that a bit is 1. The level-$p$-complexity $D_p(f)$ is the minimum expected cost when the input bits are independent and identically distributed with Bernoulli($p$) distribution. We specify the problem as choosing the minimum expected cost of all possible decision trees -- which directly translates to a clearly correct, but very inefficient implementation. The library uses thinning and memoization for efficiency and type classes for separation of concerns. The complexity is represented using (sets of) polynomials, and the order relation used for thinning is implemented using polynomial factorisation and root-counting. Finally we compute the complexity for two-level iterated majority and improve on an earlier result by J.~Jansson.
△ Less
Submitted 2 November, 2023; v1 submitted 5 February, 2023;
originally announced February 2023.
-
Extensional equality preservation and verified generic programming
Authors:
Nicola Botta,
Nuria Brede,
Patrik Jansson,
Tim Richter
Abstract:
In verified generic programming, one cannot exploit the structure of concrete data types but has to rely on well chosen sets of specifications or abstract data types (ADTs). Functors and monads are at the core of many applications of functional programming. This raises the question of what useful ADTs for verified functors and monads could look like. The functorial map of many important monads pre…
▽ More
In verified generic programming, one cannot exploit the structure of concrete data types but has to rely on well chosen sets of specifications or abstract data types (ADTs). Functors and monads are at the core of many applications of functional programming. This raises the question of what useful ADTs for verified functors and monads could look like. The functorial map of many important monads preserves extensional equality. For instance, if $f, g : A \rightarrow B$ are extensionally equal, that is, $\forall x \in A, \ f \ x = g \ x$, then $map \ f : List \ A \rightarrow List \ B$ and $map \ g$ are also extensionally equal. This suggests that preservation of extensional equality could be a useful principle in verified generic programming. We explore this possibility with a minimalist approach: we deal with (the lack of) extensional equality in Martin-Löf's intensional type theories without extending the theories or using full-fledged setoids. Perhaps surprisingly, this minimal approach turns out to be extremely useful. It allows one to derive simple generic proofs of monadic laws but also verified, generic results in dynamical systems and control theory. In turn, these results avoid tedious code duplication and ad-hoc proofs. Thus, our work is a contribution towards pragmatic, verified generic programming.
△ Less
Submitted 10 September, 2021; v1 submitted 5 August, 2020;
originally announced August 2020.
-
Examples and Results from a BSc-level Course on Domain Specific Languages of Mathematics
Authors:
Patrik Jansson,
Sólrún Halla Einarsdóttir,
Cezar Ionescu
Abstract:
At the workshop on Trends in Functional Programming in Education (TFPIE) in 2015 Ionescu and Jansson presented the approach underlying the "Domain Specific Languages of Mathematics" (DSLsofMath) course even before the first course instance. We were then encouraged to come back to present our experience and the student results. Now, three years later, we have seen three groups of learners attend th…
▽ More
At the workshop on Trends in Functional Programming in Education (TFPIE) in 2015 Ionescu and Jansson presented the approach underlying the "Domain Specific Languages of Mathematics" (DSLsofMath) course even before the first course instance. We were then encouraged to come back to present our experience and the student results. Now, three years later, we have seen three groups of learners attend the course, and the first two groups have also continued on to take challenging courses in the subsequent year. In this paper we present three examples from the course material to set the scene, and we present an evaluation of the student results showing improvements in the pass rates and grades in later courses.
△ Less
Submitted 26 June, 2019;
originally announced August 2019.
-
Domain-Specific Languages of Mathematics: Presenting Mathematical Analysis Using Functional Programming
Authors:
Cezar Ionescu,
Patrik Jansson
Abstract:
We present the approach underlying a course on "Domain-Specific Languages of Mathematics", currently being developed at Chalmers in response to difficulties faced by third-year students in learning and applying classical mathematics (mainly real and complex analysis). The main idea is to encourage the students to approach mathematical domains from a functional programming perspective: to identify…
▽ More
We present the approach underlying a course on "Domain-Specific Languages of Mathematics", currently being developed at Chalmers in response to difficulties faced by third-year students in learning and applying classical mathematics (mainly real and complex analysis). The main idea is to encourage the students to approach mathematical domains from a functional programming perspective: to identify the main functions and types involved and, when necessary, to introduce new abstractions; to give calculational proofs; to pay attention to the syntax of the mathematical expressions; and, finally, to organise the resulting functions and types in domain-specific languages.
△ Less
Submitted 28 November, 2016;
originally announced November 2016.
-
Sequential decision problems, dependent types and generic solutions
Authors:
Nicola Botta,
Patrik Jansson,
Cezar Ionescu,
David R. Christiansen,
Edwin Brady
Abstract:
We present a computer-checked generic implementation for solving finite-horizon sequential decision problems. This is a wide class of problems, including inter-temporal optimizations, knapsack, optimal bracketing, scheduling, etc. The implementation can handle time-step dependent control and state spaces, and monadic representations of uncertainty (such as stochastic, non-deterministic, fuzzy, or…
▽ More
We present a computer-checked generic implementation for solving finite-horizon sequential decision problems. This is a wide class of problems, including inter-temporal optimizations, knapsack, optimal bracketing, scheduling, etc. The implementation can handle time-step dependent control and state spaces, and monadic representations of uncertainty (such as stochastic, non-deterministic, fuzzy, or combinations thereof). This level of genericity is achievable in a programming language with dependent types (we have used both Idris and Agda). Dependent types are also the means that allow us to obtain a formalization and computer-checked proof of the central component of our implementation: Bellman's principle of optimality and the associated backwards induction algorithm. The formalization clarifies certain aspects of backwards induction and, by making explicit notions such as viability and reachability, can serve as a starting point for a theory of controllability of monadic dynamical systems, commonly encountered in, e.g., climate impact research.
△ Less
Submitted 22 March, 2017; v1 submitted 23 October, 2016;
originally announced October 2016.
-
Certified Context-Free Parsing: A formalisation of Valiant's Algorithm in Agda
Authors:
Jean-Philippe Bernardy,
Patrik Jansson
Abstract:
Valiant (1975) has developed an algorithm for recognition of context free languages. As of today, it remains the algorithm with the best asymptotic complexity for this purpose. In this paper, we present an algebraic specification, implementation, and proof of correctness of a generalisation of Valiant's algorithm. The generalisation can be used for recognition, parsing or generic calculation of th…
▽ More
Valiant (1975) has developed an algorithm for recognition of context free languages. As of today, it remains the algorithm with the best asymptotic complexity for this purpose. In this paper, we present an algebraic specification, implementation, and proof of correctness of a generalisation of Valiant's algorithm. The generalisation can be used for recognition, parsing or generic calculation of the transitive closure of upper triangular matrices. The proof is certified by the Agda proof assistant. The certification is representative of state-of-the-art methods for specification and proofs in proof assistants based on type-theory. As such, this paper can be read as a tutorial for the Agda system.
△ Less
Submitted 12 June, 2016; v1 submitted 28 January, 2016;
originally announced January 2016.