Floor, Ceiling, Bracket
johndcook.com
johndcook.com
I suppose it's a result of being developed on a chalk board, but math seems be value _terseness_ above all else. Rather than a handful of primitives and simple named functions, it's single greek characters and invented symbols. Those kind of shenanigans would never pass a code review, but somehow when we're talking about math they're "elegant" and "powerful".
I call bullshit. Math syntax is bad.
https://en.wikipedia.org/wiki/List_of_algorithms - many of the items in this list are named after people.
It happens in all fields. For that matter, the Hebrew word for masturbation is named after Onan, who was described in the bible as having done so.
Ooh, good idea! I'm getting sick and tired of foo(), it's time for walter().
[1] https://www.cs.utexas.edu/users/EWD/transcriptions/EWD13xx/E...
However I'd like to add that often in mathematics, we are discussing very generic situations. For instance, we are not talking about the radius of some specific circle, which perhaps should be named `wheelRadius`, but about the radius of an arbitrary circle or even an arbitrary number.
I wouldn't really know a better name for an arbitrary number than `x`. The alternative `arbitraryNumber` gets old soon, especially as soon as a second number needs to be considered -- should it be called `arbitraryNumber2`? I'll take `y` over that any day :-)
Also there are contextually dependent but generally adhered to naming conventions which help to quickly gauge the types of the involved objects. For instance, `x` is usually a real number, `z` is a complex number, `C` is a constant, `n` and `m` are natural numbers, `i` is a natural number used as an array index, `f` and `g` are functions, and so on.
My favorite symbol is by the way `よ` which denotes the Yoneda embedding and is slowly catching on. All the other commonly symbols for the Yoneda embedding clashed with other common names. This has been a real nuisance when studying category theory.
So you're sort of arguing against a straw man there, almost no programmer would expect you to name such a concept 'arbitraryNumber2', we would also name it x or y if it made sense in the code.
"My favorite symbol is by the way `よ` which denotes the Yoneda embedding" which was named after its mathematician inventor/discoverer Yoneda [1]
The character is the syllable "Yo" in Japanese katakana, and although not everyone knows katakana, still it is mnemonic for "Yoneda" rather than being wholly arbitrary. [2]
sometimes the terseness, and leaving certain details implicit, does actually add to clarity rather than hurting it. the eye can only take in so much at one time.
> Those kind of shenanigans would never pass a code review
Yes, because code is used in very different ways to a mathematical expression. When you see code in a repository or a textbook, I doubt you find yourself copying it out over and over again in your own work.
It might be awful from the outsider's perspective but so is a foreign language if you never learned it. Hard to complain about it though and if you want to know what others are taking about there is no other way around but to learn it - it won't change in order to make it easier for you, it will change to make it easier for the speakers
I think saying programming languages are better than Mathematics is just due to your familiarity.
Anyways, programming languages generally follow math notation, and use radians for trig functions and so on. Usually that's not too much of a problem, but when applied to file formats like VRML which were meant to be human readable, the results are ugly.
For the most part though, I think math notation is pretty good. At least when compared to something like standard music notation, which is full of weird rules and historical accidents.
> I think that the most sensible universal angle unit is "rotations". So, 360 degrees is 1, 45 degrees is 1/8, and so forth.
It was a bit confusing because most of the post was about radians, then switched to degrees. It could have instead read:
> 2pi radians becomes 1 rotation. pi radians becomes 1/2 rotations. pi/2 becomes 1/4 rotations.
Calculus is generally worse with degrees. The derivative of sin(pi/180 x) is pi/180 cos(pi/180 x). That's pretty inconvenient, especially if you're writing any sort of models that need to solve differential equations. Same reason base e is preferred for exponents.
On the other hand, in a typical math textbook, the kind that will take you a full year to read through, the list of "all the symbols ever used in this book" usually fits in a single page.
There's no point in writing "CircumferenceRatio" when π does the job. Imagine solving a partial differential equation with CircumferenceRatio appearing five times each line.
At least with programming, you generally don't see different semantics depending on the value of something! With math, there's sin^2 as in: sin^2 theta + cos^2 theta = 1, which reads the square of the sin of theta, etc. But then there's sin^-1 which means the inverse sine AKA arcsine, and NOT 1 / sine, which would be consistent with previous usage.
Reverse around last axis: ⌽
Reverse around first axis: ⊖
The grade operators (indices by which one could index to sort ascending or descending) are likewise easy to remember-
Grade up: ⍋
Grade down: ⍒
I suspect that the reason only a handful of APL's notational ideas made it into mainstream mathematics is because few mathematicians felt the need to describe algorithmic processes, and those who did were willing to settle for big sigma/pi, set builder notation, piecewise function notation, or a handwave at ALGOL, Pascal, or whatever else was in vogue at the time.
Their loss, I'm afraid.
Of course, that also begs the question of "do we need characters for all operations?" But, I'm not entirely sure we do. What is the advantage? There are plenty of operations that are just fine with their symbol being a word. (As evidenced by programming, in general, right?)
Before Iverson added the celing and floor symbols, those weren't known either, even though you had a better chance of guessing them.
And w.r.t to "characters for all operators" - this is, of course, subjective. But I've never met a programmer who prefers COBOL's "ADD 1 TO X GIVING X" to C's "++x"; Anything that's common enough deserves a symbol, both because it's shorter and easier to recognize visually, and because it reduces the language barrier (in the same way that "3+4" is easy for a 6-year old Thai in the way that "3 plus 4" in English letters isn't)
In my opinion Arthur Whitney's refinements of Iverson's ideas (called "K", an APL-related-language) is the right way to go. He mostly converged on ~50 operations that deserve symbols. Many algorithms end up as orthogonal combinations of those, e.g. |/0(0|+)\ which is a complete, efficient O(n) solution of the maximum-subarray-sum problem; or ",//:" which is a complete, though not very efficient, implementation of "flatten".
That is to say, I was not intending to contradict you. Just trying to shine light on the ambiguous part.
⌈e⌉ = ⌊π⌋
This is … evil.
I'm sure there's some amount of font twiddling and changing to a different terminal that'll fix this, but using these characters out of the box is problematic.
https://utio.net/demos/box_drawing.png
I only mention this because I've used these to decorate tables in my own notes in the past. It's not really worth the trouble, but I remembered being impressed with how nice these characters looked at the time.
If anyone else wants to try it, paste this into a python REPL:
print("\u250f\u2501\u2513\n\u2503 \u2503\n\u2517\u2501\u251b")Eg, I get:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhAAAABQAQMAAAByCd6PAAAABlBM
VEX///8AAABVwtN+AAABc0lEQVRYw+2YwWrEIBCGR5EyhR6k5LCHsvUx9iQ6t30n6dL3LmxnHDdx
IadmoUtwAr/5M+OHRIUYgKeLJPKSlnvWBCu21yU8wJQgXuJrVRTFKH3YxdaoxUtXkiYIITAAKyJA
Tvm16kn0lANUl1ujVh7PJYzw3s+jCGBSxkXRSB92pjVq5fFcwghEhFIOpQBNnmw6x6ooisaX6gxo
oxZtV1ImcM4BEZIH4jr3JZmb4tFTdUdNNYuuKyEAa+2MQEJzxkX5ouqMpprFvoQR/ShYa+amivCK
8A3hK2IuYYS8C0qKcBRMxkXROKrOaKpZ7EsYITMiiPeK4InDRTFLH3ZZU81iX8IIWRclRXqDCFaW
z6FqbErawp3FrqTA3Uq1K2phxfYKq4v9r9trxH7i8/qzD8QHXwMxEAMxEAMxEAPxFIjdfF+M2Glc
tyO+94CQc+pGhJyWNyLkzL4RIX8ONiLk/8X/j+IB7+IBM/KAdfE8e2TbZv8FgJZ8r2PE1j8AAAAA
SUVORK5CYII=
Edit: how do I force HN to turn URLs into links? It usually does that automatically. Code-blocked for now.mildly amusing, but also a demonstration/reminder of how both functions work.
Assuming you have approximations of both in easy memory, which probably covers most of HN readership.
⌈e⌉ 0
——— = i
⌊π⌋[1] https://www.cs.utexas.edu/users/EWD/transcriptions/EWD13xx/E...
At the risk of flippancy, who would think that the creator of APL was also the source of such intuitive notations? Perhaps you have to be willing to explore crazy out-there notation to be able to find these occasional gems.
Besides notation, APL introduced some ideas about vector computing that have been adopted in languages like R and Python (NumPy).
At an undergrad math course, we were allowed to state our proofs in english without any notation. This was the only course that did this. I found it easier to write and reason about my proofs, it was incredibly easy to read my peers', and the professor had no issues with my work while he did have some trouble with some of the notation.
When I first started, the question I had was if there existed an encyclopedia or an OED for mathematical notation. I was told there wasn't. I then enquired how I would go about deciphering something I didn't understand, and was told that I should ask my professors and peers. I brought one of the papers I had found online to him, and he asked me to write to the author because he couldn't understand it either.
Meanwhile I can download any old piece of code, and given enough time with the compiler and myself, I can understand what it means to express. I shudder to think 9f the sheer body of work that relies on a vague understanding of the notations in the underlying proofs.
For a science that believes in precision of logic, I ask: how is this still a thing?
1. The small Perl special vars $/ $. etc ... are mostly quite mnemonic.
2. Amiga called the left and right brackets 'bra' and 'ket' which I always thought was clever.
Wouldn’t know about Amiga, but this is standard notation in quantum mechanics (though you may be aware of this already). <φ| is a ‘bra’, and |ψ> is a ket — the two are adjoints of each other. Naturally, <φ|ψ> is a ‘braket’. (As my QM lecturer is fond of saying, ‘Dirac invented both the notation, and the pun’.)
The concepts behind are the hard thing. If you can't figure out the concept, the notation doesn't make much sense - and it is the notation that you meet first, so it seems to be the culprit.
Which is not to say that all notation is equally good - some is exceptionally bad, and other just confusing. The article mentions [x] which was i use for almost 200 years despite being confusing - but was then fixed into something non-confusing.
Similarly, for most uses, Leibniz's differential notation (dy/dx) is superior to Newton's (y with a dot on top) - and is now universally used in those uses - but for a long time Newton's dominated, mostly for political reasons (yes, over 250 years later).
But these are the exceptions: Usually, like in the floor/ceil case, when a better notation comes along, it is quicky (30-40 years...) adopted.
If you can find it.
But there is no way to look up any given dumb-ass notation, or even to know how to pronounce it. Most notations are used to mean a dozen different things, so you can't even be sure, if you read about it, you are reading about the right one, if you do find it. And if you find the right one, it still won't say how to pronounce it, so you can't even ask without sounding like a dummy.
It is all very insular. Or, maybe, was, before Youtube.