4 ms·
I'd like if this were the norm. I found the pseudocode much more readable than the mathematical description of what it was supposed to do. I'm (obviously) bias
by aljungberg 10y ago
I'd like if this were the norm. I found the pseudocode much more readable than the mathematical description of what it was supposed to do.
I'm (obviously) biased as a programmer rather than a mathematician but sometimes I think the study of mathematics would benefit tremendously from the same kind of "readability is more important than conciseness" thinking we have in software development.
Here's my proposal for a "contributing style" for mathematics:
Don't use short cryptic variable names like "wt". Do use informative full variable names like "weight" and "step".
Don't use a subscript for something like "step": it's just tiny and hard to read, especially once you start doing math in it. You have a series and you want to talk about the nth element? Use programming like array indexing, "weight[step]". It has the added benefit of being writable in pure ASCII without a math formula editor.
Don't omit your binary operators, e.g. "wt(1 + G)". Write it out: "weight[step] * (1 + reward)". You only write your formula once, but it will be read many times. Saving 1 character is not a win in total, especially not when it creates an ambiguous reading (are you using the function wt on 1 + G or are you multiplying? No way to know without resolving wt which can involve backtracking in the text for your reader.) Optimise for reading, not for writing.
Don't use sigma for sums. Again readability trumps terseness. Instead of "S" with a little "t from 1 to T" and a formula like "Rt/B" on the right, just write it out: "sum(R[t] / B for t in range(1, T))".
Actually it would be neat if there existed a Chrome or Safari extension that converted math notation to pseudo-Python. It wouldn't be able to assign sensible variable names automatically but at least it'd save me so much time and leaning in to stare at tiny subscripts.
I might be exceptionally lazy but sometimes when I read a math paper and the dense piles of tiny script formulas begin to pile up my eyes just glaze over even that in theory I understand every component. It's just so much effort to mentally parse it. Like reading sample code in assembly. If readability was improved I'm certain me and others like me would finish reading many more papers and we'd all get a little smarter.
- j2kun 10y agoProblem is you can't efficiently do everything math needs to do if you write out everything like that. Notation is designed for the efficiency of reasoning after you've fully absorbed the ideas being expressed.
- aljungberg 10y agoRight. You could define functions. The function itself is stated in a readable form yet it is concise when later called upon. And just like you desire, this gives the reader a chance to first absorb the idea being expressed by the function (in clear pseudo-code), without making your expressions later overly verbose. The counterargument might be "but then it's harder to break it down again into components when doing algebra". But that's no different from substituting in identities as needed. Substitute in the function body whenever you need to. As long as you don't need to, don't and you both have concise writing and reduced cognitive overhead. Each time the user sees a function they have previously mentally absorbed and understood they don't need to re-read it in detail to confirm it's still the same idea.
- j2kun 10y ago> And just like you desire, this gives the reader a chance to first absorb the idea being expressed by the function (in clear pseudo-code), without making your expressions later overly verbose. This is already the case in math, just with a combination of English and algebraic notation and pictures, whatever is best to convey the idea. Either way, it seems orthogonal to your complaints about notation. I'm saying that pseudocode (as I think you mean it, pythonesque) is not nearly expressive enough to convey the ideas that mathematical notation conveys. It really does help reduce cognitive overload to distinguish two parameters, say one depending on time and one depending on position, by putting one in a subscript. (And that's still at the base of the ladder of abstraction) Sigma notation is one particularly helpful example, far more compact and easier to analyze than a for/while loop. (And, for what it's worth, list comprehensions come from mathematical set-builder notation) I'm not saying math is perfect, but having spent a lot of time doing both math and software, I like to think I understand the reasons for the pitfalls of both fields relatively well.
- Jtsummers 10y agoMath notations allow for many transformations and operations on the expressions that pseudocode and most programming languages simply don't permit, or render as clearly. Even within programming languages, consider the matlab notation for summation versus the (prototypical) algol-esque language notation: sum(vec) vs Python's (naive approach) sum = 0 for val in vec: sum += val or in C sum = 0 for(int i = 0; i < vec_length; i++) sum += vec[i]; Where vec_length has to be independently passed around since C's arrays don't have a notion of length. The first is a clear expression of the fact of what is happening (like sigma in typical math notation), but the second and third are only clear due to being 3-lines long each. A more complex kernel or stepping function and the reasonability of these expressions disappears. Even those in Python-land have recognized the flaws in the naive approach and developed numpy and other solutions that allow for a closer semantic connection between the language (python) and the desired expression (mathematics). See http://wiki.c2.com/?ArraySumInManyProgrammingLanguages http://wiki.c2.com/?ArraySumInManyProgrammingLanguages for even more examples from numerous programming languages. Few of these lend themselves (as the expressions grow in complexity) to the manipulability and reasonability [0] of mathematical notation. Languages of all sorts allow for different tradeoffs of expressibility, conciseness, manipulability, ease of acquisition, and other features. Mathematics has, predominantly, chosen conciseness and manipulability over ease of acquisition. But it would be nearly impossible to write a computer algebra system that took a textual version of math expressed in python and conducted the sort of automated manipulation and analysis that can be done to textualized forms of mathematical expressions. [0] Reasonability: Here I do not mean that python is more or less reasonable than math in the typical sense. I mean in the ability to consume the information expressed in either form and then reason about it. A page (or pages) of code needed to express the computations on geographic datasets here at work, versus the 20 lines of math we have on the whiteboard.
- BuuQu9hu 10y agoYou only found the pseudocode readable because you know Python and don't know maths notation. It's not unreasonable to have to learn maths notation in order to read maths papers and blogs. You aren't exceptionally lazy. You are normally lazy, and additionally not used to reading maths notation.
- aljungberg 10y agoI agree and this was my first thought too. Yet I feel like I do know the mathematical notation. I know what each "thing" does and yet the whole feels needlessly dense. I definitely agree that once you are "used" to reading the notation it will be faster. That said, just because it's possible to get faster at it, does that mean it's the best possible notation for the job? In creating programming languages and using them for tens of thousands of man hours per day we have envisioned and tested a multitude of different ways to express logical ideas, formulas and algorithms. By contrast, how many kinds of mathematical notation has humankind tried and actively used? If the latter number is substantially higher than the former, how can we be so certain that academic mathematical notation is the best, most clear way to express algorithms and formulas? I would wager that the amount of logic expressed in programming languages vastly exceeds the amount of logic expressed in mathematical notation, every day. More logic is both written and read in the field of programming, so the medium we express the logic in is more rapidly iterated on. Again, I'm not a mathematician. I'm a programmer and so of course my opinion about what is easy to read and write is subjective and biased. Yet even thinking about it objectively in terms of "what did we work harder on refining", I think there's some food for thought here. Wouldn't the rapidly iterated and widely used form seen in programming languages be more finely honed and at a higher stage of evolution in terms of understandability and writability?
- emn13 10y agoSo I'm not a mathemetician, certainly not anymore. But for a while I did read a lot of this stuff, and wrote things like it. Aaand... to some extent you get used to it. But it really is simply a worse syntax. It's not just habit. For one thing, there does not exist such a thing as "mathematical notation". There are a bunch of different, semi-overlapping conventions. You can't trivially read something someone wrote if the math was for another field. In fact, I'm pretty sure the variance is even larger than for most (seriously used) computer languages. It's easier for a pythonista to grok C++ templates than it is to read physics-inspired math with a modal-logic background. This is particularly true when it comes to conventional symbols; there just aren't enough, or perhaps it's history, but there are different symbols for the same concept, and different concepts for the same symbol. Another pet peeve is subscripts - are those formally meaningless tags to distinguish variations the author talks about? are they arguments of some other class (think type arguments vs. value arguments)? Are they something elses? It's quite common for articles to use various forms, and sometimes even on the same symbols; for an example (albeit with superscripts) you probably know: X^T as a transpose, but X^2 as a power. Then there are things like context sensitivity. It's not uncommon for some notation not to be self-contained in the sense that an expression depends on some variable, but that that variable is never specified in the expression itself. It's taken for granted you know which those are, and that can get quite tricky. It's the mutable global state of programming. Mathematics could definitely benefit from a more disciplined and rigorous approach when it comes to notation, at least, IMNSHO.