Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Predicative programming

From Wikipedia, the free encyclopedia
Method of computer program specification
Not to be confused withList of conspiracy theories § Predictive programming.
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 arex{\displaystyle x},y{\displaystyle y}, andz{\displaystyle z}, the commandx{\displaystyle x}:=y{\displaystyle y}+1 is equivalent to the specification (binary expression)x{\displaystyle x'}=y{\displaystyle y}+1 ∧y{\displaystyle y'}=y{\displaystyle y}z{\displaystyle z'}=z{\displaystyle z} in whichx{\displaystyle x},y{\displaystyle y}, andz{\displaystyle z} represent the values of the program variables before the assignment, andx{\displaystyle x'},y{\displaystyle y'}, andz{\displaystyle z'} represent the values of the program variables after the assignment. If the specification isx{\displaystyle x'}>y{\displaystyle y}, we easily prove (x{\displaystyle x}:=y{\displaystyle y}+1) ⇒ (x{\displaystyle x'}>y{\displaystyle y}), which says thatx{\displaystyle x}:=y{\displaystyle y}+1 implies, or refines, or implementsx{\displaystyle x'}>y{\displaystyle y}.

Loop proofs are greatly simplified. For example, ifx{\displaystyle x} is an integer variable, to prove that

whilex{\displaystyle x}>0dox{\displaystyle x}:=x{\displaystyle x}–1od

refines, or implements the specificationx{\displaystyle x}≥0 ⇒x{\displaystyle x'}=0, prove

ifx{\displaystyle x}>0thenx{\displaystyle x}:=x{\displaystyle x}–1; (x{\displaystyle x}≥0 ⇒x{\displaystyle x'}=0)elseok{\displaystyle ok}fi ⇒ (x{\displaystyle x}≥0 ⇒x{\displaystyle x'}=0)

whereok{\displaystyle ok} = (x{\displaystyle x'}=x{\displaystyle x}) 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 ist{\displaystyle t}, and time is measured by counting iterations, then to prove that execution of the previouswhile-loop takes timex{\displaystyle x} whenx{\displaystyle x} is initially nonnegative, and takes forever whenx{\displaystyle x} is initially negative, prove

ifx{\displaystyle x}>0thenx{\displaystyle x}:=x{\displaystyle x}–1;t{\displaystyle t}:=t{\displaystyle t}+1; (x{\displaystyle x}≥0 ⇒t{\displaystyle t'}=t{\displaystyle t}+x{\displaystyle x}) ∧ (x{\displaystyle x}<0 ⇒t{\displaystyle t'}=∞)elseok{\displaystyle ok}fi⇒ (x{\displaystyle x}≥0 ⇒t{\displaystyle t'}=t{\displaystyle t}+x{\displaystyle x}) ∧ (x{\displaystyle x}<0 ⇒t{\displaystyle t'}=∞)

whereok{\displaystyle ok} = (x{\displaystyle x'}=x{\displaystyle x}t{\displaystyle t'}=t{\displaystyle t}).

References

[edit]

External links

[edit]


Stub icon

Thisformal methods-related article is astub. You can help Wikipedia byexpanding it.

Retrieved from "https://en.wikipedia.org/w/index.php?title=Predicative_programming&oldid=1295483151"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp