logoalt Hacker News

smj-edison • yesterday at 3:48 PM • 7 replies • view on HN

I think there's a pretty big conceptual difference between programming and math, which is that in programming we think about building up something over time by applying successive steps. In math though we have to think about the whole thing simultaneously, forwards and backwards. So when we prove a program, we're actually proving it forwards and backwards, with all possible inputs and outputs, at the same time. And either it's all true, or it blows up in your face.

Another difficulty is with programming, we succeed by making abstractions that don't leak, where with math we're constantly opening up mathematical objects and messing around with their internals, chaining together the internals with theorems to get to our desired outcome.

Since we so often need access to the guts of the objects we're working with to prove facts, it makes it really hard to interoperate with other systems, because either we have to make assumptions about those systems which can compromise correctness or we have to be able to plug in all the way.

Signed, an undergrad in math with decent coding experience.


Replies

NatKarmios • today at 2:03 AM

Interestingly, for the kinds of proofs on programs I'm familiar with (as someone who works in the separation logic world), the notion of proving a program backwards and forwards are two different things; we generally use a forward proof (hoare logic / separation logic) for correctness (this program doesn't deviate from the spec / has no bugs) and a backward proof (incorrectness logic) for incorrectness (this program can exhibit a certain bug)

somethingsome • yesterday at 7:21 PM

While I like your dichotomy, I find more similarity between maths and programming.

you usually define the internals of your mathematical object based on the requirements of the 'rest of the system' and then you study the objects a lot to see it they even make sense or collapse.

As soon as you have an object that does not collapse, you know you can use it.

Take for example measure theory, you start with the basics axioms that are there to make the measure useful to others, then, based on the axioms you derive everything that you need to ensure that it's well defined, and then some more theorems that are like glue code to be able to use that measure for particular cases.

In this view, the axioms are your basic API, and the 'glue' theorems for an application are your frameworks.

Now a big difference between maths and programming is that maths is way bigger and more complex though

kccqzy • yesterday at 11:26 PM

I disagree. In writing a proof in math you also apply successive steps. This is clear in a proof written in English, and even clearer in a Lean proof where you literally list the steps (tactics) in order. The forward and backward thing you are talking about is probably about proving A if and only if B; that’s a small category of proofs. A small category of programming tasks (like parsing and pretty printing) also need the programmer to think forwards and backwards.

The idea of making abstractions comes from mathematics. The entire field of algebra is just abstractions. Algebraists think about the group, the ring, the field rather than the underlying objects. These abstractions absolutely don’t leak. These are some of the most elegant abstractions available, and this style of abstractions is known as type classes (in Haskell) or traits (in Rust), and is far superior to programmer-derived object-oriented abstractions. Why do most programmers create abstractions that leak? Because they are only taught object-oriented programming and yet without even learning about the Liskov substitution principle.

kenferry • yesterday at 9:57 PM

I think you're not wrong about the situation today, but that doesn't mean we cannot change things. Verifiability is an exciting possibility that may be enabled by LLMs.

I also somewhat disagree with you about abstraction. In programming as well we move "up and down the ladder of abstraction", which means opening up objects and revisiting how we've built their abstractions. If you're doing performance work or debugging, while you don't exactly IGNORE abstractions, you're definitely opening them up.

Signed, professional software engineer with math degrees. :)

random3 • yesterday at 5:36 PM

As a computer scientist with 20 years experience in software and last 3 shifting on math, I think I agree with how you describe the approach in SWE. I collected a ton of notes on the same process myself.

I'd sum it up as starting to code before/without trying to get a proper* understanding of the end-to-end problem, and then incrementally adjusting along the way. This often solves a chicken and egg problem, of not being able to advance understanding before building. The problem is not rewriting or fully refactoring the code once your understanding persist. Often this is too late (aka "shipping the prototype"). Then everything expands into more complexity over more or less** time.

I think this whole process can actually be described formally. I'm not sure how much it matters anymore, but I suspect agent generated code suffers from the same issue, just with different measures due to speed/memory advantages agents have.

----

* I say "proper" assuming "full" is likely unachievable in most settings

** the difference between many software projects can be reduced to how fast they become dead ends based on how fast complexity explodes.

yehoshuapw • yesterday at 11:56 PM

Have you programmed in haskell? Because I disagree in general, and haskell takes it furthur: you program declaratively

➕ show 1 reply
latentsea • yesterday at 7:02 PM

> Another difficulty is with programming, we succeed by making abstractions that don't leak

So, we basically fail then.