Live data from Hacker News

Translating math into code with examples in Java, Racket, Haskell, Python (2011)

matt.might.net

31–40 of 95 posts

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#31
post #4

I dream of material that would explain some advanced (for a regular person understanding of the word) math concepts using Python. Maybe it's because I've programmed more in my life than did math, but the "language" we use to write it is absolutely crazy: one letter variables everywhere, no structure, thousands of custom notations etc. I'm not criticising it, I realise it exists this way for a reason and if I wasn't s…

The article covers quite a few topics in set theory so that suggests that it does provide for advanced topics.

If you mean advanced proofs, again the article may be the right place to start.

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#32
post #29

Not sure what the point of translating math into code is. Just because we represent something with code doesn't mean it is computable. It's also technically incorrect to say math is translated into code. The mathematical symbols are being swapped with codey things, but the underlying semantics are quite different. For example, we might say the symbol 'oo' is infinity, but infinity itself is something that cannot be e…

You and I read the article very differently. Based on your comment, it sounds like you interpreted the article as implicit advocation for the idea that mathematics should be represented in a programmatic (i.e. computable) way.

I didn't pick up any ideology in my reading. My interpretation of the article is that the author wanted to provide tips on how to implement mathematics, for two reasons:

1. People have to implement nontrivial mathematics from time to time, and

2. Most mathematics doesn't concern itself with obstacles to implementation, because it doesn't have to.

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#33
post #13

Julia is notably missing. Packages like this one are dope https://github.com/korsbo/Latexify.jl Or this https://github.com/qojulia/QuantumOptics.jl Or this https://www.juliahomotopycontinuation.org/

I like Julia for all of the libraries, the Lisp underneath, however, from the article: "Many of the encodings are as immutable, purely functional data structures (even in imperative languages), a topic unfortunately omitted from many computer science curricula." Julia and similar PLs don't express math like APL, J[1], Haskell[2], Scheme[3] or even Clojure can with immutable structures and function composition to name…

Can you explain it better? I do agree with Haskell due to laziness by default and arrow types for example, but against Scheme and Clojure the only aspect seels like it would be the more strict rebinding/shadowing rules (which doesn't limit what you can express, just that you can also express non-mathematical expressions).

Primitive types (like pretty much all languages) are immutable and structs in Julia are immutable by default (which includes pretty much every math type like complex numbers), and all math operators are non mutating (in fact mutating operators should have a ! in the name).

Function composition is just as simple in this scenario:

f(x) = x + 2

g(x) = 2x

h = g ∘ f

h(3) == 10

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#34
post #18

Earlier quoted context omitted.

Agreed, i'm not sure whether one letter (immutable) greek variables are better than proper named variables. Another consideration: A formal rule based math syntax could be checked by a computer (theorem prover).

Where widely understood, I consider a Greek variable to be vastly superior. The problem is how well it's understood. Delta is an example of a succinct variable which has a well defined meaning which to encapsulate in a named variable either requires a long name or leaving out some nuance (delta isn't 'change' which is ambiguous in English, but the difference between two measurable things.) Keep in mind we use special…

Single letter variables (including Greek ones) are great when they stand for something, or are well-known so they don't need to stand for anything.

If you stick to convention and use stuff like A for array, i for index, r for root, δ for small change (a delta), ε for error, Σ (Greek S) for sum, Π (Greek P) for product, etc.

It's only when you start using variable names as if they were free variables when they really aren't that you get into trouble with comprehension, especially from people not in your field.

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#35

Nice article, I was wondering why Julia wasn't featured considering its support for math syntax. I wondered whether this could have been an old article, but there is no date in the article. I checked the RSS feed and couldn't find the article in it. I cross-checked the oldest article in the feed with the index of articles on the site, this article seems to be written before Dec 2014. This makes sense for why Julia is…

Well, we are fortunate that the author covered four languages. That said, seeing the same in Julia and also Common Lisp would be great. I am coming up on my 36 year anniversary for using Common Lisp, so even though I really love Haskell and Racket, and I am enjoying learning Julia, I would vote for adding CL.

This might be a good community project - the article on github and allow people to do pull requests adding their favorite language.

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#36
post #19

Earlier quoted context omitted.

you will take single letter variables from my cold, dead, hands! I'm more used to math than to code, and I find multiple-letter variables ridiculous when not unreadable. In the ancient times, mathematicians used to write formulas using latin sentences. Even the simplest arithmetic result occupied a few lines of text. Are you proposing that we go back to that age?

" Even the simplest arithmetic result occupied a few lines of text. Are you proposing that we go back to that age? " What if students learned "Force = mass * acceleration", and only later moved to "F = ma" once they'd gotten tired of writing it, instead of smacking students in the face with "F = ma" right out of the gate, to say nothing of all the other stuff we smack them with right away?

Usually the problem is that the students don't understand the difference between force and energy, or the difference between mass and weight (or what is linear momentum). It is easy to remember that [in that class] a capital F means force.

Anyway, in sometimes it is useful to write more. For example teaching https://en.wikipedia.org/wiki/Consistent_and_inconsistent_eq... I try to write the full name of the classification at least for two clases. It is painful, but it is worth. I teach in Spanish, so we have also the problem that underdetermined is "indeterminado", so a capital "I" can mean "Inconsistent" or "[I]underdetermined" or in one of the following clases "Independent" (like in a linear independent set of vectors, yes they mix this too). So it is important to use the full name (or a long enough abbreviation) until you are sure that everyone can understand which "I" you are writing.

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#37
post #19

Earlier quoted context omitted.

" Even the simplest arithmetic result occupied a few lines of text. Are you proposing that we go back to that age? " What if students learned "Force = mass * acceleration", and only later moved to "F = ma" once they'd gotten tired of writing it, instead of smacking students in the face with "F = ma" right out of the gate, to say nothing of all the other stuff we smack them with right away?

but even "force = mass * acceleration" uses those sneaky single-letter symbols that are not even letters! In appropriate, user friendly notation it would be "force equals mass multiplied by acceleration". But this is not clear enough. What force? What acceleration? More precisely, what is the direction of the acceleration? The original statement of this law is less ambiguous: "Mutationem motus proportionalem esse vi…

I'm not seeking abstract philosophical purity, or trying to make the mistake of including a complete transitive concept closure in every equation [1]. I'm seeking pragmatic high-quality education that doesn't blow our student's cognitive resources on stupid shit instead of the stuff I want them to learn. By the time they get to physics, they know what multiplication and equality are. It's just the "force", "mass", and "acceleration" that they don't know yet, so we don't abbreviate them until they do.

[1]: AIUI, the actual problem the original "New Math" had. The original "New Math" tried to start students with set theory, because that was the foundations of mathematics, so obviously, the best place to start an education, right? (Hint: No.) This is why parents said they didn't understand "New Math". By comparison "Common Core" math is all-but-identical to what I learned in school 30 years ago.

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#38
post #37

Earlier quoted context omitted.

but even "force = mass * acceleration" uses those sneaky single-letter symbols that are not even letters! In appropriate, user friendly notation it would be "force equals mass multiplied by acceleration". But this is not clear enough. What force? What acceleration? More precisely, what is the direction of the acceleration? The original statement of this law is less ambiguous: "Mutationem motus proportionalem esse vi…

I'm not seeking abstract philosophical purity, or trying to make the mistake of including a complete transitive concept closure in every equation [1]. I'm seeking pragmatic high-quality education that doesn't blow our student's cognitive resources on stupid shit instead of the stuff I want them to learn. By the time they get to physics, they know what multiplication and equality are. It's just the "force", "mass", an…

I do not disagree with you. When you learn the stuff, it is perfectly OK to explain equations with words and even write equations with words. But this is akin to the comments of a program. Once you get down to work, in a professional setting, all mathematics uses single-letter variables

(and I may add that all programming should do the same).

I also agree with you that starting math with set theory is utterly ridiculous and even harmful. You should start with arithmetic and with geometry (obviously, using single-letter variables when needed).

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#39
Despite the title, this article does a real disservice to Python.

For the purpose of constructing a generator, the author wrote:

> In an object-oriented setting like Python or Java, streams can be constructed from an interface

Yikes. itertools was introduced in, let's see... 2003?

Re: Translating math into code with examples in Java, Racket, Haskell, Python (2011)

#40
post #4

I dream of material that would explain some advanced (for a regular person understanding of the word) math concepts using Python. Maybe it's because I've programmed more in my life than did math, but the "language" we use to write it is absolutely crazy: one letter variables everywhere, no structure, thousands of custom notations etc. I'm not criticising it, I realise it exists this way for a reason and if I wasn't s…

I suspect what's jarring is the difference between programming in an imperative sense, where you write down steps to be taken to get a computation, and equations, like declarative programming. I once dated, in math grad school, a hardcore differential equations student, and she took Java, which she thought so very different than a world of equations. Made sense, I thought, having been exposed to imperative and declarative programming myself.
Post reply on HN