Why can't programs be proven?

前端 未结 30 2344
礼貌的吻别
礼貌的吻别 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 18:12

    Let us assume a purely functional language (ie Haskell). Side effects can be taken quite cleanly into account in such languages.

    Proving that a program produces the right result requires you to specify:

    1. a correspondance between data types and mathematical sets
    2. a correspondance between Haskell functions and mathematical functions
    3. a set of axioms specifying what functions you are allowed to build from others, and the corresponding contruction on the mathematical side.

    This set of specifications is called denotational semantics. They allow you to prove the reason about programs using mathematics.

    The good news is that the "structure of programs" (point 3 above) and the "structure of mathematical sets" are quite similar (the buzzword is topos, or cartesian closed category), so 1/ the proofs you do on the math side will easily be transferred into programmatic constructions 2/ the programs you write are easily shown to be mathematically correct.

提交回复
热议问题