Live data from Hacker News

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

matt.might.net

71–80 of 95 posts

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

#71

Earlier quoted context omitted.

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

The argument here is that you used a program to solve an equation. You did not write your program in that way. Indeed, you are using operator overloading/fancy syntax to make this work.

If anything, this seems to support the original claim.

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

#72
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*.

First, while you can express those statements in programming languages, they will either be expressed differently in order to have the same meaning or, if expressed in a similar way, have a different meaning (even ignoring that many such statements are not computable at all). This merely shows that math is not an FP language.

Second, you can prove those equivalences in any language that allows you to directly express relations, be it the type-level language of Agda, Coq or F*, or the contract language of an imperative language -- this is nothing to do with FP, but with a language that can express relations.

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

#73

Earlier quoted context omitted.

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*.

An example of > E.g. x ∈ ℕ ∧ x > 2 ∧ x in Agda would be this, I think: _ : ∀ { x : ℕ } → x > 2 → x

The type level of dependently typed languages or other languages that allow directly expressing relations (including Java's JML) can do that. That's little to do with pure FP.

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

#74
post #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...

All of the course's video lectures are still available at:

https://www.youtube.com/channel/UCGVa4wp8SWGFtMe6hcdpHlg/pla...

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

#75
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...

To be fair, when you actually look at Structure and Interpretation of Classical Mechanics (which is a great book), it's still math that a physicist recognizes, not so much an ALGOL-esque program. The Scheme system was extended to handle the math rather than the math brought to the language.

What they did was make all the math explicit, mostly by inserting all the necessary pieces of differential geometry that were glossed over in all other treatments.

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

#76
post #52

Earlier quoted context omitted.

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...

All of the course's video lectures are still available at: https://www.youtube.com/channel/UCGVa4wp8SWGFtMe6hcdpHlg/pla...

slides https://codingthematrix.com/

code http://resources.codingthematrix.com/

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

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

>infinity itself is something that cannot be embedded in a finite program

I am not sure what you mean by infinity here, but there are many ways in programming to handle infinite streams in an otherwise finite program. Python's itrrtools.count and the ability to map and filter over it would be a basic example.

Indeed I could argue that every game's or webserver's event loop is embedding infinity in a finite program.

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

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

>> completely inaccessible to finite computational mechanisms.

I assume you have already proven we ourselves are an infinite computational mechanism?

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

#79
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 try to achieve this goal with "Thinking in Tensors, Writing in PyTorch" project: https://github.com/stared/thinking-in-tensors-writing-in-pyt... (very much a Work in Progress).

The idea is to have equations (in LaTeX) and code (in PyTorch) line-by-line, so it is easy to see how to use it in practice.

I think it may help to bridge the gaps between coders (but not experienced in maths) and mathematicians (but with little experience in practical programming).

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

#80
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.

I mean, that’s exactly what the Curry-Howard Isomorphism says: that math and programming are equivalent.

Both can express and are equivalent to Turing machines.

Post reply on HN