ArticleslgStudy

science

Predicative programming

Predicative programming is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Predicative programming rather than just read about it. In short: Predicative programming is the original name of a formal method for program specification and refinement, more recently called a Practical Theory of Programming, invented by Eric 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.

Key takeaways

  • Predicative programming belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Predicative programming to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Predicative programming from memory before moving on to harder problems.

Reference excerpt

Predicative programming is the original name of a formal method for program specification and refinement, more recently called a Practical Theory of Programming, invented by Eric 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 just implication. This is the simplest formal method, and the most general, applying to sequential, parallel, stand-alone, communicating, terminating, nonterminating, natural-time, real-time, deterministic, and probabilistic programs, and includes time and space bounds. Commands in a programming language are considered to be a special case of specification—those specifications that are compilable. For example, if the program variables are x {\displaystyle x} , y {\displaystyle y} , and z {\displaystyle z} , the command x {\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 which x {\displaystyle x} , y {\displaystyle y} , and z {\displaystyle z} represent the values of the program variables before the assignment, and x ′ {\displaystyle x'} , y ′ {\displaystyle y'} , and z ′ {\displaystyle z'} represent the values of the program variables after the assignment. If the specification is x ′ {\displaystyle x'} > y {\displaystyle y} , we easily prove ( x {\displaystyle x} := y {\displaystyle y} +1) ⇒ ( x ′ {\displaystyle x'} > y {\displaystyle y} ), which says that x {\displaystyle x} := y {\displaystyle y} +1 implies, or refines, or implements x ′ {\displaystyle x'} > y {\displaystyle y} . Loop proofs are greatly simplified. For example, if x {\displaystyle x} is an integer variable, to prove that while x {\displaystyle x} >0 do x {\displaystyle x} := x {\displaystyle x} –1 od refines, or implements the specification x {\displaystyle x} ≥0 ⇒ x ′ {\displaystyle x'} =0, prove if x {\displaystyle x} >0 then x {\displaystyle x} := x {\displaystyle x} –1; ( x {\displaystyle x} ≥0 ⇒ x ′ {\displaystyle x'} =0) else o k {\displaystyle ok} fi ⇒ ( x {\displaystyle x} ≥0 ⇒ x ′ {\displaystyle x'} =0) where o k {\displaystyle ok} = ( x ′ {\displaystyle x'} = x {\displaystyle x} ) is the empty, or do-nothing command. There is no need for a loop invariant or least 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 t {\displaystyle t} , and time is measured by counting iterations, then to prove that execution of the previous while-loop takes time x {\displaystyle x} when x {\displaystyle x} is initially nonnegative, and takes forever when x {\displaystyle x} is initially negative, prove if x {\displaystyle x} >0 then x {\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'} =∞) else o k {\displaystyle ok} fi ⇒ ( x {\displaystyle x} ≥0 ⇒ t ′ {\displaystyle t'} = t {\displaystyle t} + x {\displaystyle x} ) ∧ ( x {\displaystyle x} <0 ⇒ t ′ {\displaystyle t'} =∞) where o k {\displaystyle ok} = ( x ′ {\displaystyle x'} = x {\displaystyle x} ∧ t ′ {\displaystyle t'} = t {\displaystyle t} ).

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Predicative programming

Start with the simplest possible case. Write down what Predicative programming claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Predicative programming before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Predicative programming ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Predicative programming

In research
Predicative programming appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Predicative programming in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Predicative programming is common in secondary-school and first-year university syllabi. It links to neighbouring topics Formal methods, Formal methods stubs, Formal specification languages, so understanding it makes those chapters shorter.
In everyday life
Look for Predicative programming outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Predicative programming in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Predicative programming means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Predicative programming out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Predicative programming in simple terms?

Predicative programming is the original name of a formal method for program specification and refinement, more recently called a Practical Theory of Programming, invented by Eric Hehner. The central idea is that each specification is a binary (boolean) expression that is true of acceptable computer…

Why does Predicative programming matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Predicative programming?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Predicative programming.

Tags

  • Formal methods
  • Formal methods stubs
  • Formal specification languages
  • Logical calculi

Keep exploring