Program transformation as alternative for Hoare logic or temporal logic - MathOverflow most recent 30 from http://mathoverflow.net2013-05-21T17:18:18Zhttp://mathoverflow.net/feeds/question/69914http://www.creativecommons.org/licenses/by-nc/2.5/rdfhttp://mathoverflow.net/questions/69914/program-transformation-as-alternative-for-hoare-logic-or-temporal-logicProgram transformation as alternative for Hoare logic or temporal logicLucas K.2011-07-09T22:27:38Z2011-08-01T23:11:24Z
<p>When trying to prove something about a program, the known techniques are Hoare logic and temporal logics.</p>
<p>An alternative is to transform a program in a mathematical (logical) expression. So, rather that mathematics is used to prove some properties of the program, the program itself is a piece of mathematics.</p>
<p>Loops become transitive reflexive closures. Example, if one has a program that calculates a Fibonacci number. If the program keeps the last two numbers of the Fibonacci sequence in variables, then this be converted by taking the transitive reflexive closure of the relation P, that is true (and only true) for the following situation:</p>
<p>$$ P((x,\space y, \space z), \space (x+1, \space z, \space y+z)) $$</p>
<p>In the original program, the right value is chosen within the loop. In the transitive reflexive closure, the right value must be selected outside the closure (loop). The transformed program is more like a non-deterministic program.</p>
<p>The transformation of a program in a logical expression, can be done automatically.</p>
<p>Although, this is not rocket science, I can not find any reference for this approach. I am busy with writing an article, where this is a part of (it is not the main subject). But I want to refer to the right articles and look if there is interesting material.</p>
<p>Does someone has interesting references?</p>
<p>Many thanks,</p>
<p>Lucas</p>
<p>Edit: Given the comment of Andreas, some clarification. The goal is to make formal reasoning about the program possible. So, transforming the program in a declarative language is insufficient, because the declarative language may not have means to make conclusions about a program, although the language itself might precisely defined. I was thinking in transforming the program in a FOL + PA expression. After such transformation, formal (that is why I tagged with lo.logic) reasoning can be done about the program. As far to my knowledge, I haven't seen this approach (the methods are always more in the direction of Hoare and temporal logics), although it is not very complicated. In my question I didn't want to restrict to FOL + PA.</p>
http://mathoverflow.net/questions/69914/program-transformation-as-alternative-for-hoare-logic-or-temporal-logic/70869#70869Answer by Vijay D for Program transformation as alternative for Hoare logic or temporal logicVijay D2011-07-21T01:32:51Z2011-08-01T23:11:24Z<p>It appears to me that the gist of your suggestion is to translate a program into a relation and reason about the transitive closure of that relation. It is orthogonal that this relation is definable in first order arithmetic. </p>
<p>The idea of translating a program into a relation is rather old and I doubt there is a unique reference for it. I will share what I know, but in each case, there are surely older papers. The first paper below suggests modelling programs as transition systems and reasoning about them. Plotkin's paper provides a way to inductively derive a transition system from program text (though the idea is much older, I'm sure).</p>
<ol>
<li>Robert Keller, 1976, <em>Formal verification of parallel programs</em>. </li>
<li>Gordon Plotkin, 1981. <em>Structural Operational Semantics.</em> </li>
</ol>
<p>The transition system is essentially the relation you describe. The transitive closure is a fixed point over this relation. It is one of several objects that can be defined by fixed points. Reasoning about properties of programs using fixed points is very old too.</p>
<ol>
<li>David M. R. Park, 1969, <em>Fixpoint induction and proofs of program properties</em>. </li>
<li>Lawrence Flon and Norihisa Suzuki, 1975, <em>Consistent and Complete Proof Rules for the Total Correctness of Parallel Programs</em>.</li>
<li>Patrick Cousot and Radhia Cousot, 1977, <em>Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints</em>.</li>
</ol>
<p>Finally, there is a precise mathematical sense in which the fixed point (or transitive closure) approach is not significantly different from Floyd/Hoare logic. </p>
<ol>
<li>Edmund M. Clarke Jr., 1977, <em>Program Invariants as Fixed Points</em>.</li>
</ol>
<p>To quote from the abstract of the paper:</p>
<blockquote>
<p>We argue that soundness and relative completeness theorems for Floyd-Hoare Axiom Systems ([3], [5], [18]) are really fixedpoint theorems. We give a characterization of program invariants as fixedpoints of functionals which may be obtained in a natural manner from the text of a program. We show that within the framework of this fixedpoint theory, soundness and relative completeness results have a particularly simple interpretation. Completeness of a Floyd-Hoare Axiom System is equivalent to the existence of a fixedpoint for an appropriate functional, and soundness follows from the maximality of this fixedpoint. </p>
</blockquote>
<p>Reasoning about programs by computing fixed points is extremely standard in practice. Rather than relations, we tend to deal with a transformer defined by a relation, such as a predicate or state transformer. If you are genuinely committed to reasoning over relations in a logic, you will require transitive closure logics because properties like graph reachability are not first order definable. I can point to this recent paper, but you will have to dig around for older ones.</p>
<ol>
<li>Neil Immerman, Alexander Rabinovich, Thomas W. Reps, Mooly Sagiv, and Greta Yorsh, 2004, <em>The Boundary Between Decidability and Undecidability for Transitive Closure Logics</em>.</li>
</ol>
<p>Edit: Adding a link.</p>
<p>You might want to try the following verifiers that use a combination of automated reasoning and fixed point techniques. Though they may fail on harder examples, they can still discover useful invariants and errors.</p>
<ol>
<li><a href="http://pop-art.inrialpes.fr/interproc/interprocweb.cgi" rel="nofollow">Interproc</a></li>
<li><a href="http://www.pexforfun.com/Default.aspx?language=CSharp&sample=AbsVerified" rel="nofollow">Pex</a></li>
</ol>
http://mathoverflow.net/questions/69914/program-transformation-as-alternative-for-hoare-logic-or-temporal-logic/70878#70878Answer by Andrej Bauer for Program transformation as alternative for Hoare logic or temporal logicAndrej Bauer2011-07-21T06:42:20Z2011-07-21T06:54:16Z<p>Hoare logic and temporal logic might be "the only known techniques for proving programs correct" to you, but there are certainly others!</p>
<p>For example, and this list is not exhaustive:</p>
<ul>
<li>equational reasoning about fixpoints, this works in languages like Haskell</li>
<li>properties of programs can be proved via denotational semantics, which in itself is a vast area including domain theory and game semantics, to name just two. </li>
<li>for certain kinds of programs, for example for parametrically polymorphic ones, there are techniques that go under the name "relational parametricity"</li>
<li>you can use various logical interpretations to get correctness of programs:
<ul>
<li>a program extracted as a realizer via the realizability interpretation of logic automatically satisfies a certain specification</li>
<li>with tools such as Coq you can use type theory to write programs as proofs, or construct programs and prove them correct all at once</li>
<li>there are other ways of extracting programs from logical statements, one family of which are variants of Gödel's Dialectica interpretation that extract programs from classical logic.</li>
</ul></li>
</ul>
<p>Now, regarding your specific question. I think you should look at realizability, type theory, and extraction of programs from proofs. All of these are "logical" methods for developing correct programs, or proving them correct. Some randomly chosen starting points:</p>
<ul>
<li><p>start with something fun and surprising, perhaps Paulo Oliva's tutorial on <a href="http://www.dcs.qmul.ac.uk/~pbo/away-talks/2011_05_28Pittsburgh.pdf" rel="nofollow">Programs from classical proofs via Gödel's dialectica interpretation</a></p></li>
<li><p>an accessible paper on realizability interpretation which uses logical methods in computable analysis might be Ulrich Berger's <a href="http://www.cs.swan.ac.uk/~csulrich/publications.html#REALICOINDANALYSIS" rel="nofollow">Realisability for Induction and Coinduction with Applications to Constructive Analysis</a> </p></li>
<li><p>if you want to use computers to actually show correctness of programs, you could learn <a href="http://coq.inria.fr/" rel="nofollow">Coq</a> and then proceed to <a href="http://ynot.cs.harvard.edu/Tutorial.pdf" rel="nofollow">Ynot</a> (Hoare logic on steorids) or go straight to Adam Chipala's <a href="http://adam.chlipala.net/cpdt/" rel="nofollow">Certified Programming with Dependent Types</a>.</p></li>
<li><p>cool people use <a href="http://wiki.portal.chalmers.se/agda/pmwiki.php" rel="nofollow">Agda</a> instead of Coq.</p></li>
<li><p>if you are first-order logic sort of person, you might find <a href="http://www.cs.swan.ac.uk/~csulrich/minlog.html" rel="nofollow">Minlog</a> more palatable than Coq and Agda, as it does not throw type theory in your face.</p></li>
</ul>
<p>See you in two years.</p>