Live data from Hacker News

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

matt.might.net

51–60 of 95 posts

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

#51
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…

https://projecteuler.net/

Some problems with solutions in different languages. Each problem leads to the next one.

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

#52
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…

There used to be a Coursera course called Coding the Matrix. It covered many linear algebra topics using Python. The course isn't available anymore on Coursera anymore, but you can still buy the textbook:

https://www.amazon.com/Coding-Matrix-Algebra-Applications-Co...

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

#53
post #28

> Mathematics is a purely functional language. It is not. E.g. x ∈ ℕ ∧ x > 2 ∧ x This is just one of the many mathy myths that plague the FP community. Yes, there are some similarities between FP and mathematical notation, but FP and imperative are much closer to one another than either is to mathematics.

I'm not sure what point you're trying to make. You can certainly express those statements in both FP and imperative languages, and you can prove the equivalences you mention in FP languages like Agda, Coq, and F*.

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

#54
post #28

> Mathematics is a purely functional language. It is not. E.g. x ∈ ℕ ∧ x > 2 ∧ x This is just one of the many mathy myths that plague the FP community. Yes, there are some similarities between FP and mathematical notation, but FP and imperative are much closer to one another than either is to mathematics.

[deleted]

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

#55
post #28

> Mathematics is a purely functional language. It is not. E.g. x ∈ ℕ ∧ x > 2 ∧ x This is just one of the many mathy myths that plague the FP community. Yes, there are some similarities between FP and mathematical notation, but FP and imperative are much closer to one another than either is to mathematics.

I don't know much about this area. What about "x ∈ ℕ ∧ x > 2 ∧ x < 5 ∧ x % 2 = 0 implies x = 4." can't be expressed in common languages? Don't lots of solver systems have support for sets, and deriving facts from statements about them?

Just in case somebody might benefit from finding out how easy it is in python with z3

  >>> from z3 import Int, solve
  >>> x = Int('x')
  >>> solve([x > 2, x 

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

#56
post #28

> Mathematics is a purely functional language. It is not. E.g. x ∈ ℕ ∧ x > 2 ∧ x This is just one of the many mathy myths that plague the FP community. Yes, there are some similarities between FP and mathematical notation, but FP and imperative are much closer to one another than either is to mathematics.

Yes, well said. Math is not any form of programming, and programming is not math. Studying the relations between the two can be very helpful, and the difference itself is interesting. One may have specific reasons to us FP to cleanly decouple from certain kinds of side-effects, but there’s nothing un-mathy about mutability, and there are times when it’s a fine choice.

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

#57

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…

Don't forget the Internet Archive! The first version is from Nov. 14: https://web.archive.org/web/20111114185849/http://matt.might... The article index from Nov. 8 does not include the article: https://web.archive.org/web/20111108003034/http://matt.might... So we can say with confidence that this should have a [2011] tag and was published sometime Nov 8 - Nov 14 in 2011.

It's frustrating when Internet articles don't include publication dates. It's not like it's paper where someone didn't think to record the date. The date certainly exists in the database, filesystem, etc, the author just chooses not to show it, forcing forensics to figure out when it's from.

(I was reading another article from his site yesterday after it was linked on lobste.rs and was also trying to figure out how old it was.)

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

#58
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 wrote a blog post describing the tensor product in terms of functional programming techniques in python https://jwkennington.com/blog/tensor-product-for-programmers...

I would also be interested in a "math for programmers" approach to deciphering formalism. I've studied a fair amount of linear algebra / differential geometry and could see how Python-definitions might help. I'm less familiar with other areas of mathematics

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

#59
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…

Gerry Sussman had the same idea and wrote a paper on it: https://www.researchgate.net/publication/37597511_The_Role_o...

His SICP coauthor Hal Abelson also cowrote Turtle Geometry, which explores stuff like topology and the basics of general relativity in Logo. An underappreciated old book I'd like to see more like.

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

#60
APL is an executable mathematical notation - in fact, it was designed by Iverson for describing algorithms on paper (in 1958 IIrC), and then the team working on it implemented it in software, because ... it was a well specified way to describe algorithms.

I highly recommend reading [0], which contains the simplest (IMO) description of the simplex algorithm, which is both mathematical and executable. If you find that inspiring, [1] is also worth a read.

[0] https://www.jsoftware.com/papers/DFSP.htm

[1] http://www.eecg.toronto.edu/~jzhu/csc326/readings/iverson.pd...

Post reply on HN