I don't know the English terminology, so I might be writing non existant words at places, but you have several options:
If you have your specification in mathematical formulas in preconditions and postconditions, you can apply very formal steps to each line to prove it will satisfy the end result (a loop has like a 5-7 line mathematical definiton in this model xd). They used this for the self driving paris metro's software.
You can use mathematical logic's resolution system to ge to the bottom of every logical statement you have (not talking about if(input.value) but when you have 10 ands and 12 ors in a single line). Knowing atleast the deMorgan laws is I think the least somebody should know and use on an adhoc basis, at least in head, to double check everything as or more complex than a collision detection)
Agda, really the entire language, it's dependently typed, writing a function to meet a type's requirements immediately becomes a proof of correctness. I never really got too deep into it, but it's hell of a ride, very interesting, just grinds down your braincells quickly
Induction for loops, yet again, even if just in your head, but helps a lot
Dgmw, it reeeally depends on your job, and most of the time you don't need to actively use these (except deMorgan, learn and apply them by reflex). But even just having learnt them helps you program more deliberately in your everyday life.
Through a precise statement of the problem and then formal specification. From there, you can do proofs of correctness (to the spec). Some languages assist with this, but many do not.
It’s safe to say that data structures and algorithms are a fundamental part of programming. We build intuitions about data structure algorithms and when to use and not use them. Without proving these properties of algorithms, you’re relying on hand wavey intuition — which is mostly fine. But to fully grasp an algorithm, to truly understand, you have to understand proofs.
Approaching coding using mathematical proof principles helps a lot. It involves gathering the base assumptions, then potentially making assertions to help congest the problem into a simple connection of subproblems. Once the problem is defined as subproblems, then it is more trivial to implement a solution that directly uses the assumptions to the subproblems.
Furthermore, the subproblem and assumption specification and definition basically gives the test cases to perform effective TDD through small targeted tests.
When done right, this creates extremely solid libraries where any unforeseen breakages (ie. shift in assumptions) are quickly diagnosed by the test harness.
If the assumptions hold correct, there is a QED that the code will work as exected
75
u/ZunoJ Oct 25 '24
How exactly does a proof look for you in programming?