Math DSL Idea

By
Written

I'd like a programming environment, ideally an interactive environment that let me experiment and iterate on different model ideas. Be it a linear regression or some variation of OLS, WLS, GLS, etc. Or a strucutured economic model (like this one homelessness) or some statistical model infused with randomness of various distributions (normal or not). I'd like something that automatically transform y = 5 + 3x + 6x² into its intergral or derivative, I'd like to define a custom number type (field, group, ring, whatever) like some kind of polynomial where the interdeterminant resolves to something after a certain transform (like how i turns to -1 in complex numbers) and I'd like to use that number type interchangably with the standard float, int, etc. I'd like to be able to feed csvs, dataframes, database data or into any model, function, whatever as easily as I load a dataframe in python, query in to my model/function. I'd like to visualise the output as nicely as you would in ggplot in R. I'd like some kind of interactive environment on top like storybook where I can tweak a bunch of knobs and levels to tweak coefficents and constants. I'd like a piece of software that did all of this in one package. Is this too much to ask for?

A hypothetical language

I had an idea for a DSL to do all of the above and just compile it down to WASM stores stuff in arrays and has some GPU operations accelerated implemented in WebGPU, like ordingary least squares. So there would be some kind of runtime for the language, but it would work whereever there's a browser.

An important language feature would be polynomials, ideally you'd be able to implement complex numbers within the language. Although it probably makes sense for them to have an internal implementation, but the language itself should provide the functionality for users to define their own, and for the language to be able to generate GPU shaders to compute large operations on them.

Goal of the language

Despite my bucket list of advance lanaguage features, its needs to be accessible for those making statical, econometric, economic, whatever models. How to make that pleasant and ergonomic isn't immediately obvious to me. But I'd like to enable experimentation with stuff such as Ordinary Least Squares with swapping out real numbers for some custom defined polynomial.

High level features

Distinct Features

Uncertainty

Can it be a general purpose language

I think that would be nice, but at that point you need to get serious about many other things, like async behaviour, multi processing, etc. I just want to a better experince with writing mathematical models.

Can this just be a library?

I don't think so. Not without a highly unpleasant experince, but the runtime can probably be a library.

Basic Types

Serialisable Math Primatives

I am making a distinction here with other math primatives

  • Reals
  • Integers
  • Polynomials (1 + x)
  • Polynomials indeterminants:
  • Matrices
  • Vectors
  • Sets, different from the collections
    • I wonder if I need to make distinction between a finite set and infinite set

Data Structures

  • Array
  • List
  • Map
  • Set (collection)
  • Data Frames

Other types

These are types you'd come to expect in any other language

  • Functions (which can be defined anonymously).
    • I am wondering if there needs to be a certain treatment of them to make closer how they are in math, so they can be transformed and treated as data, so it would be possible to implement some first class derivative transform. I don't think all functions could work like this.
    • Maybe I need to make a distictions between a parameterised relations and functions. And in a function in math is what I have in mind here to a parameterised relation.

Type System Features