This articlerelies largely or entirely on asingle source. Relevant discussion may be found on thetalk page. Please helpimprove this article byintroducing citations to additional sources. Find sources: "Predicative programming" – news ·newspapers ·books ·scholar ·JSTOR(June 2024) |
This article includes alist of references,related reading, orexternal links,but its sources remain unclear because it lacksinline citations. Please helpimprove this article byintroducing more precise citations.(June 2024) (Learn how and when to remove this message) |
Predicative programming is the original name of a formal method for programspecification andrefinement, more recently called a Practical Theory of Programming, invented byEric Hehner. The central idea is that each specification is a binary (boolean) expression that is true of acceptable computer behaviors and false of unacceptable behaviors. It follows that refinement is justimplication. This is the simplest formal method, and the most general, applying to sequential, parallel, stand-alone, communicating, terminating, nonterminating, natural-time, real-time, deterministic, andprobabilistic programs, and includes time and space bounds.
Commands in aprogramming language are considered to be a special case of specification—those specifications that are compilable. For example, if the program variables are,, and, the command:=+1 is equivalent to the specification (binary expression)=+1 ∧= ∧= in which,, and represent the values of the program variables before the assignment, and,, and represent the values of the program variables after the assignment. If the specification is>, we easily prove (:=+1) ⇒ (>), which says that:=+1 implies, or refines, or implements>.
Loop proofs are greatly simplified. For example, if is an integer variable, to prove that
while>0do:=–1od
refines, or implements the specification≥0 ⇒=0, prove
if>0then:=–1; (≥0 ⇒=0)elsefi ⇒ (≥0 ⇒=0)
where = (=) is the empty, or do-nothing command. There is no need for aloop invariant orleast fixed point. Loops with multiple intermediate shallow and deep exits work the same way. This simplified form of proof is possible because program commands and specifications can be mixed together meaningfully.
Execution time (upper bounds, lower bounds, exact time) can be proven the same way, just by introducing a time variable. To prove termination, prove the execution time is finite. To prove nontermination, prove the execution time is infinite. For example, if the time variable is, and time is measured by counting iterations, then to prove that execution of the previouswhile-loop takes time when is initially nonnegative, and takes forever when is initially negative, prove
if>0then:=–1;:=+1; (≥0 ⇒=+) ∧ (<0 ⇒=∞)elsefi⇒ (≥0 ⇒=+) ∧ (<0 ⇒=∞)
where = (= ∧=).
Thisformal methods-related article is astub. You can help Wikipedia byexpanding it. |