Hacker News new | past | comments | ask | show | jobs | submit login
Translating math into code with examples in Java, Racket, Haskell, Python (2011) (might.net)
66 points by ddtaylor on May 28, 2022 | hide | past | favorite | 13 comments



> Mathematics has no side effects.

Dijkstra and Scholten would beg to differ. Mathematics is the science of describing patterns, and mutable state falls well within its purview.


> Mathematics is the science of describing patterns ...

Ah, but mathematics doesn't require the scientific method.


Of course you’re correct in one sense. However, science is an old word and like many others in the English language it has multiple senses. In the context I used it in, it means a systematic body of knowledge. I’m sure you’d agree mathematics meets that criterion. Other examples include ethics and aesthetics.


Absolutely. State Machines are easily modelled in pure math. TLA+ is but one example of this.


> Math cannot modify the value of a variable--either global or local. It cannot mutate an element in an array.

Computer scientists do this all the time. You most definitely can model state, side effects, non-determinism, IO, random acts of God etc. using pure math. TLA+, Coq, Isabell/HOL, LEAN etc. are proof assistants that are routinely used to do exactly that.


I'm not sure you're disagreeing?

My interpretation is that he's stating that you can't base fundamental mathematical formalism's on mutation, you have to model them using immutable structures.

You can then model mutation on top of that.

Then in key areas, when you know bringing back in mutation for performance reasons, you can do so with a really nice test case to validate your implementation is correct. IE does the mutable one match the immutable one.

You can also make sure your mutation is local.


Aside from streams, infinite sequences can also be represented as functions from the natural numbers to the element type.


Or, better yet if your language supports it, coroutines/generators/continuations.


I was disappointed to see that this article did not mention python generators (`yield`) with respect to infinite series. They were introduced in 2001 by PEP 255 - well before this article was written. Perhaps they were excluded because of the implicit statefulness?


This is the way.


We've banned this account for repeatedly posting unsubstantive and flamebait comments. Please don't create accounts to do that with.

https://news.ycombinator.com/newsguidelines.html


Was the account given warning? I agree there are lots of throwaway comments but there are also some incredibly great ones.

While I understand the time-value for any effort on this is questionable, it would be a pity to throw the baby out with the bathwater.


A couple general points, not specifically about the GP account:

(1) moderation unfortunately has to go by the worst things an account does, not the best things;

(2) we do give warnings, but there are exceptions, such as when there's evidence that the user has been banned in the past.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: