Why can't programs be proven?

前端 未结 30 2217
礼貌的吻别
礼貌的吻别 2020-12-22 17:06

Why can\'t a computer program be proven just as a mathematical statement can? A mathematical proof is built up on other proofs, which are built up from yet more proofs and

相关标签:
30条回答
  • 2020-12-22 17:46

    Godel's Theorems notwithstanding...What would be the point? What simplistic "truths" would you like to prove? What would you want to derive from those truths? While I may eat these words...where's the practicality?

    0 讨论(0)
  • 2020-12-22 17:46

    I haven't read all of the answers, but the way I see it, proving programs is pointless, that's why no one does it.

    If you have a relatively small/medium project (say, 10K lines of code), then the proof is probably gonna be also 10k lines, if not longer.

    Think about it, if the program can have bugs, the proof can also have "bugs". Maybe you'll need a proof for the proof!

    Another thing to consider, programs are very very formal and precise. You can't get any more rigorous and formal, because the program code has to be executed by a very dumb machine.

    While proofs are going to be read by humans, so they tend to be less rigorous than the actual code.

    The only things you'll want to prove are low-level algorithms that operate on specific data structures (e.g. quicksort, insertion to a binary tree, etc).

    These things are somewhat complicated, it's not immediately obvious why they work and/or whether they will always work. They're also basic building blocks for all other software.

    0 讨论(0)
  • 2020-12-22 17:49

    Some parts of programs can be proved. For example, the C# compiler that statically verify and guarantee type safety, if the the compilation succeeds. But I suspect the core of your question is to prove that a program performs correctly. Many (I do not dare say most) algorithms can be proved to be correct, but a whole program probably cannot be proved statically due to the following:

    • Verification requires all possible branches (calls, ifs and interupts) to be traversed, which in advanced program code has super-cubic time complexity (hence it will never complete within reasonable time).
    • Some programming techniques, either through making components or using reflection, makes it impossible to statically predict execution of code (i.e. you don't know how another programmer will use your library, and the compiler has a hard time predict how reflection in a consumer will invoke functionality.

    And those are just some...

    0 讨论(0)
  • 2020-12-22 17:50

    Proofs are programs.

    Formal verification of programs is a huge research area. (See, for example, the group at Carnegie Mellon.)

    Many complex programs have been verified; for example, see this kernel written in Haskell.

    0 讨论(0)
  • 2020-12-22 17:52

    If you're really interested in the topic, let me first recommend David Gries' "The Science of Programming", a classic introductory work on the topic.

    It actually is possible to prove programs correct to some extent. You can write preconditions and postconditions and then prove that given a state that meets the preconditions, the resulting state after execution will meet the postconditions.

    Where it gets tricky, however, is loops. For these, you additionally need to find a loop invariant and to show correct termination you need to find an upper bound function on the maximum possible number of iterations remaining after each loop. You also have to be able to show that this decreases by at least one after each iteration through the loop.

    Once you have all this for a program, the proof is mechanical. But unfortunately, there's no way to automatically derive the invariant and bound functions for loops. Human intuition suffices for trivial cases with small loops, but realistically, complex programs quickly become intractable.

    0 讨论(0)
  • 2020-12-22 17:52

    I don't come from a mathematical background, so forgive my ignorance, but what does "to prove a program" mean? What are you proving? The correctness? The correctness is a specification that the program must verify to be "correct". But this specification is decided by a human, and how do you verify that this specification is correct?

    To my mind, there are bugs in program because humans have difficulties expressing what they really want. alt text http://www.processdevelopers.com/images/PM_Build_Swing.gif

    So what are you proving? Bugs caused by lack of attention?

    0 讨论(0)
提交回复
热议问题