7 ms·
Understanding Mathematical Notation as Code
- refrigerator 11y agoI don't like being negative, but this seems really patronising and unhelpful. Just because someone is a 'self-taught game/graphics programmer' doesn't mean that describing maths concepts to them as code is at all intuitive, especially for things relating to geometric concepts like vectors, for which a simple diagram would speak volumes.
- SEMW 11y agoI agree, sadly. I'm not sure anyone who didn't already understand vector products is going to be helped by staring at "var rx = ay * bz - az * by; var ry = az * bx - ax * bz; var rz = ax * by - ay * bx" (as opposed to, say, [0]). Sure, it's precise and unambiguous, but it's missing the context that make it possible for a human to actually understand what it is as opposed to just calculating it (which the javascript interpreter is capable of doing fine on its own). To say nothing of "var determinant = require('gl-mat2/determinant'); determinant(matrix)"! I guess the point is to go read the source code of the library, but I can't imagine many worse ways of learning linear algebra than reading the source code of optimized linear algebra routines. [0] https://upload.wikimedia.org/wikipedia/commons/6/6e/Cross_product.gif https://upload.wikimedia.org/wikipedia/commons/6/6e/Cross_pr...
- mattdesl 11y agoThe point is not to understand linear algebra in a few lines of code. The point is to present the language of mathematics in another light; and hopefully demystify intimidating-looking equations that often appear in literature surrounding games, graphics and other fields of programming. The audience is hobbyists and self-taught developers with no formal background in mathematic notation. This audience might have no problem with a for loop, but the Summation symbol is (literally) just Greek to them.
- johnmw 11y agoI've found it helpful - not as someone trying to learn a new concept from scratch but as a coder who has struggled with maths in the past and needs a refresher.
- kowdermeister 11y agoAs someone from the target audience of this document I find it really helpful and descriptive. I was looking for such a resource for ages. Also keep in mind, that the whole thing is created maybe yesterday, so it's ok if it's not perfect yet.
- j2kun 11y agoThis is a nice little document, but you have to understand that mathematical notation is syntactically closer to spoken language than to code, and it's only expected to be semantically rigorous after context is taken into account.
- jwp729 11y agoSurprised there's no mention of the Curry-Howard correspondence between proofs and programs.
- mlitchard 11y agoMention? The title led me to believe that was the topic.
- hasenj 11y agoI've always thought (ever since university) that math notation should take inspiration from code. Instead of writing Xi, they should really write X[i]; because Xi is ambiguous. I find that dealing with all the ambiguity in syntax can be rather frustrating.
- mmarx 11y ago> Instead of writing Xi, they should really write X[i]; because Xi is ambiguous. How so, and in which cases would it be ambiguous to write X_i, but not X[i]?
- hasenj 11y agoX_i is a valid variable name. Although it seems in math you can only use single-letter variable names, which is kinda ridiculous (coming from a computer science background).
- Maken 11y agoUsing "ab" would lead to ambiguity, since it could mean "a*b". Also, there is no reason for using two letter variables when you can use any letter from the latin or greek alphabet, with any notation like ä or â or even create your new symbols like ∫, ℝ or ℕ when nothing matches the concept you want to express. Unlike programming languages, math notation evolved without being constrained by monospace ASCII characters and text lines.
- Retric 11y agoDraw a circle/oval/rectangle/cloud/whatever around your names and suddenly there is zero ambiguity. The only constraint was EGO. PS: For typesetting Just capitalize the first letter. Radious ^ 2 * Pi = Area is common and unambiguous.
- Retra 11y agoYou can use multiple letter variable names. Nobody is stopping you from doing that.
- kej 11y agoThe part about using = for definition doesn't seem to reflect the way that works in mathematics. The mathematical meaning of x = 2kj isn't var x = 2 * k * j but var x = function(k, j) { return 2 * k * j; };
- contravariant 11y agoI see it more as an "Assert(x==2kj)".
- mattdesl 11y agoI'm working on improving this part; feel free to add more discussion here: https://github.com/Jam3/math-as-code/issues/17 https://github.com/Jam3/math-as-code/issues/17
- contravariant 11y agoNot sure if I agree with the statement that "=" is used for definitions. It's true meaning is to simply state that two things are equal. I can see where the confusion comes from since mathematicians have a tendency to just state "Let x = 2kj", instead of the more explicit "Let us assume that the statement 'x = 2kj', is true". It's important to note the distinction though, since introducing a new variable by simply stating it's properties is more powerful than just defining it to be equal to something. For instance it's equally valid to define a symbol x by simply stating "Let x∈A". This is used quite a lot since anything you can then prove about "x" must automatically be true for all elements of A.
- arsenide 11y agoI like the idea of using the compound symbol ":=" for "is defined to be". So, you can say something like "For x∈A, y := 2x". When I take math notes, it helps a lot using this shorthand. I'm able to remove some ambiguity between what is and is not a definition.
- contravariant 11y agoI definitely agree with the use of ":=", but "=" simply doesn't mean the same thing. For example, the similar statement "For x∈A, y = 2x" could even be interpreted as using y to define x.
- mattdesl 11y agoI'm working on improving that section; would be great if you could chime in here: https://github.com/Jam3/math-as-code/issues/17 https://github.com/Jam3/math-as-code/issues/17
- arsenide 11y agoI don't understand -- you say "=" and ":=" are not the same thing, but give an example where they act the same? Practically speaking, using ":=" removes any doubt when quickly skimming over old notes. It is nice to be able to easily separate what is defined and what is asserted in each of dozens of statements.
- brudgers 11y agoKen Iverson's Turing essay was Notation as a Tool of Thought[1]. Both his languages, APL and J [2] were based on the idea of mapping mathematical and a programming language. Iverson's Math for the Layman presents that link explicitly despite being an enjoyable read. [3] [1]: http://www.jsoftware.com/papers/tot.htm http://www.jsoftware.com/papers/tot.htm [2]: http://www.jsoftware.com http://www.jsoftware.com [3]: http://www.cs.trinity.edu/About/The_Courses/cs301/math-for-the-layman/ http://www.cs.trinity.edu/About/The_Courses/cs301/math-for-t...
- aikah 11y agoNice, it would make a great book : "Math for coders: from code to math notation.". Seriously ;)
- rectangletangle 11y agoThis is amazing; It's always annoying having to Google arcane mathematical notation, in order to translate something into code.
- ilaksh 11y agoMath notation is just obfuscated code in a language that doesn't compile or run.
- paulmd 11y agoIt's not really code - more of a pseudocode, because it leaves the details of the implementation to the reader. Might be what you were getting at with "doesn't compile or run".
- bogomipz 11y agoThis is neat. I hope to see more!
- 32h8 11y agoMath is pure = not mutable, and that code is mutable. Damn barbarians try to desecrate math!