HACKER Q&A
📣 redtea

Is there a programming language with pure math notation?


As example I write in LaTeX

\prod _{i=1}^{6}i

Or even by ASCII symbols https://latex.codecogs.com/png.image?\dpi{110}%20\prod%20_{i=1}^{6}i

Instead of code like

var value = 1 for (var i = 1; i <= 6; i++) { value *= i }


  👤 db48x Accepted Answer ✓
There is no single unified math notation. Different fields of mathematics use the same notation to mean different things, and many mathematicians use different notations to mean the same things. Worse, the notations that most mathematicians use are ambiguous; they often leave out critical information merely because the writer can assume that the reader is human, and can puzzle those things out from the context. When we are programming, we do not have that luxury.

The book Structure and Interpretation of Classical Mechanics uses both a modified traditional notation as well as runnable Scheme throughout. I recommend reading at least the preface:

https://mitpress.mit.edu/sites/default/files/titles/content/...


👤 yesenadam
I guess not, how would that even work?... I guess if you like the LaTeX version, in TeX you could write new commands that evaluate the expression instead of/as well as displaying it.

I don't know APL, but it seems the most condensed language for doing mathematical stuff. In APL (I looked it up) you'd write "!6". Try/learn APL online here https://tryapl.org/

In Julia you can use Unicode characters as variable names, write e.g. "2π" instead of "2*PI", and it's easy to "operator overload", so that e.g. "+" adds/combines together 2 or more of whatever things you want to add/combine, whatever they are, in whatever way you like. Or add new operators. Thus lines of code in Julia can get a lot closer to looking like mathsy/sciency expressions than in most languages.


👤 Jtsummers
Fortress aimed for that, but it didn't survive in the end. Julia is probably the nearest language to this idea today, using notation that is closer to how a lot of math is written. Since you can use symbols for variables, functions, and operations you can write something that looks an awful lot like the mathematical paper/text description.

👤 logankilpatrick
I would check out https://julialang.org, the closest thing to the pure math I have seen.

👤 ChrisRackauckas
Julia is rather close, and you can use a combination of Latexify.jl + Symbolics.jl to automatically generate Latex representations of programs.