Legible Mathematics: Sketches of interactive arithmetic for programming (2014)
glench.com
glench.com
Unfortunately, this does work very badly for long fractions, iterated fractions or, well, anything more complicated than toy examples.
This pops up from time to time with latex and how a/b should give you a fraction instead of having to write \frac{a}{b}. Problem is, this makes one easy case marginally shorter, but something like \frac{a+b}{c+\frac{d}{3}} much harder.
Still looks much better
Mathematics notation is basically completely determined by consensus and people come up with new notation all the time whenever they need it. In particular, in order to convince someone that your notation is better you have to show previously how hard stuff becomes easy and not how easy stuff becomes even easier.
https://tex.stackexchange.com/questions/73822/what-is-the-di...
Another reason is that the notation is mostly a tool for __oneself__ to think in, but is fairly bad at communicating (think about the level of expertise required to read a math paper vs reading someone’s code).
Here’s a concrete difference to support these claims. Using math notation we often write large expressions which include many meaningful subexpressions and complex operations. In code we prefer to use lots of names (variables) and simple expressions.
There's likely to be some survivorship bias at play here.
Inventing new notation does not help with existing material - and that material is what makes mathematicians. People who can put up with old notation, especially if it is bad, are much more likely to become mathematicians: that gives a survivorship bias.
Besides which, you are welcome to invent your own notation, but good luck trying to get anyone to adopt it, particularly if the mathematical field involved is studied enough. Inertia is very strong, even in very abstract disciplines - aren't physicists still treating current as flowing the wrong direction?
But yeah, when working something mathematical out for the first time, picking / making up the right notation is crucial.
Having said that, I personally have never had issues with notation in mathematics nor did I have the impression others I helped had. IMO, abstraction is the main stumbling block, not notation.
But my papers need to follow the consensus, as I'm already trying to get a hard idea across to my reader who decides to spend 15 minutes to try and understand me, maybe.
So yes, then I need to introduce 15 symbols, half of them greek, and a number of operations between them using whatever line/subscript/superscript/brace is fashionable.
The biggest difference is in slides. In slides I try and can usually avoid the math notation. Because I am there talking it through, which makes notation less important and gives me an opportunity to switch to long variable names and everything a function, more akin to the software notation.
Consider einteinian notation, with implicit summation. Very terse, and very powerful when you know what you’re doing.
I’m sure CS notation is great for CS but trust me, math notation is pretty damn near optimal for math. Second only to theoretical physicists, mathematicians are probably the smartest of scientists.
Associativity and operator precedence are ideas that made sense as a shorthand in written mathematics (and have deep roots in the structure of arithmetic) but don't actually add a lot of value in programming languages, except to put a huge mental burden on developers to unpack the precedence.
My thought is just to remove precedence and associativity entirely -- instead of "a + b + c/2" you have to make it explicit -- "a + (b + (c/2))". The only problem that I see is that there are two ways of writing this, you could also write "(a + b) + (c/2)". In my experience, though, especially in programming (though not always in financial programming), there are almost always semantics associated with those intermediate values which makes one of the two groupings preferable.
Taking numeric constants and adding internal separators makes a lot of sense as well (both before and after the decimal point). Ideally this would be enforced at some arbitrary cultural level, (e.g. using the US-standard groupings of three with comma), and would be required -- "2000" is invalid and "20,00" is invalid (so python3's approach of allowing arbitrary _'s in numbers is not really great, because it doesn't protect against typos). The right-of-the-decimal-point separators are not really common, but it would be nice to take advantage of this to make a sensible arbitrary enforced designation, like using "," to the left and "_" to the right, once again mandatory and required to support groupings of three.
Would probably also be desirable to have a convention for hexadecimal numbers and other supported bases -- in particular binary is not supported by many languages, but is very natural for most programming languages, if we had a way of using delimiters -- 0b0100_0000 is more readable and meaningful than 0x40, but 0b0010_0100_0011_0010_0000_0010_0010 is not so good (quick, how many bytes did I just type?).
Or how about... (+ a b (/ c 2))
On thing that I think imperative languages bring to the table is naming intermediate values through assignment, so we can do things like
base_index = root_index + offset
midpoint = length / 2
final_index = base_index + midpoint
It's rarely useful to be so verbose, but it's nice to have the ability.a b + c 2 /
or even
/ 2 c + b a
is the more efficient, unambiguous notation.
a b + c 2 / +
or + a + b / c 21. I've yet to see any automatically formatting system that's not extremely painful to work with.
2. Mathematical notation hasn't just been developed over 100s of years it is continuing to do so.
3. Units aren't labels.
This looks like it does substitutions but I didn't see reductions.
If you're not familiar, it uses a CAS called derive which handles algebraic simplification (including trigonometry), differentiation and integration. Oh, and a function called "rref" (reduced row echelon form; familiar to matlab users), which solves a linear system (including symbolically), with absolutely minimal overhead in the "CLI".
Now that I say that, I want an actual CLI tool called rref that works in the same way.
> PRESS (PRolog Equation Solving System) is a system for solving symbolic, transcendental, non-differential equations. The methods used for solving equations are described, together with the service facilities. The principal technique, meta-level inference, appears to have applications in the broader field of symbolic and algebraic manipulation.
https://dream.inf.ed.ac.uk/software/press/
And: https://github.com/maths/PRESS
> This directory contains a copy of the PRESS ... modified to run on SWI Prolog
At the very least, typing / automatically makes a fraction with separate top and bottom input areas - which means that brackets for numerator and denominator aren't necessary.
Although, perhaps it's deliberate as a canary test for those that intend to defend non-traditional mathematical notation in programming.
a = 100_000 b = 1_000_000
Traditional FORTRAN ignores all spaces, so one can write a million as 1 000 000 there, C++14 allows apostrophes (https://en.wikipedia.org/wiki/Decimal_separator#Data_versus_...)
for(i=0;i<N;++i){
for(j=0;j<N;++j){
force = G*mass1[i]*mass2[j]/radius(i,j)^2
// do something with the force
}
}