ArticleslgStudy

computer science

Formal methods

Formal methods is a computer 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 Formal methods rather than just read about it. In short: In computer science, formal methods are mathematically rigorous techniques for the specification, development, analysis, and verification of software and hardware systems. The use of formal methods for software and hardware design is motivated by the expectation that, as in other engineering disciplines, performing appropriate mathematical analysis can contribute to the reliability and robustness of a design.

Key takeaways

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

Reference excerpt

In computer science, formal methods are mathematically rigorous techniques for the specification, development, analysis, and verification of software and hardware systems. The use of formal methods for software and hardware design is motivated by the expectation that, as in other engineering disciplines, performing appropriate mathematical analysis can contribute to the reliability and robustness of a design. Formal methods employ a variety of theoretical computer science fundamentals, including logic calculi, formal languages, automata theory, control theory, program semantics, type systems, and type theory.

History Reasoning mathematically about programs predates the discipline's name. Alan Turing sketched a correctness argument for a routine in 1949, and in the late 1960s Robert W. Floyd and Tony Hoare established the axiomatic tradition of program proof that became Hoare logic. Edsger W. Dijkstra's weakest-precondition calculus gave a systematic way to derive programs from specifications, and model-oriented specification languages such as VDM and the Z notation were developed during the 1970s. A second tradition grew out of temporal logic. Amir Pnueli proposed it in 1977 as a language for specifying the behaviour of reactive programs, and model checking was introduced independently by Edmund M. Clarke and E. Allen Emerson and by Jean-Pierre Queille and Joseph Sifakis in the early 1980s, work for which the three shared the 2007 Turing Award. Symbolic model checking with binary decision diagrams raised the size of systems that could be analysed by orders of magnitude, and bounded model checking built on SAT solvers extended it further. Industrial interest was sharpened by costly defects such as the 1994 Pentium FDIV bug, which prompted processor vendors to invest heavily in hardware verification. From the 2000s onwards, maturing SMT solvers and proof assistants made it practical to verify complete systems rather than isolated components. In the 2020s, formal methods have been used to eliminate "hallucinations" from large language models in "neural-symbolic" reasoning systems.

Uses Formal methods can be applied at various points through the development process.

Specification

Formal methods may be used to give a formal description of the system to be developed, at whatever level of detail desired. Further formal methods may depend on this specification to synthesize a program or to verify the correctness of a system with respect to its specification. Alternatively, specification may be the only stage in which formal methods are used. By writing a specification and attempting to prove properties that should follow, ambiguities in the informal requirements can be discovered and resolved. Additionally, engineers can use a formal specification as a reference to guide their development processes. The need for formal specification systems has been noted for years. In the ALGOL 58 report, John Backus presented a formal notation for describing programming language syntax, later named Backus normal form then renamed Backus–Naur form (BNF). Backus also wrote that a formal description of the meaning of syntactically valid ALGOL programs was not completed in time for inclusion in the report, stating that it "will be included in a subsequent paper." However, no paper describing the formal semantics was ever released.

Synthesis

Program synthesis is the process of automatically creating a program that conforms to a specification. Deductive synthesis approaches rely on a complete formal specification of the program, whereas inductive approaches infer the specification from examples. Synthesizers perform a search over the space of possible programs to find a program consistent with the specification. Because of the size of this search space, developing efficient search algorithms is one of the major challenges in program synthesis.

Verification

Formal verification is the use of software tools to prove properties of a formal specification, or to prove that a formal model of a system implementation satisfies its specification. Once a formal specification has been developed, the specification may be used as the basis for proving properties of the specification, and by inference, properties of the system implementation.

Sign-off verification Sign-off verification is the use of a formal verification tool that is highly trusted. Such a tool can replace traditional verification methods (the tool may even be certified).

Human-directed proof Sometimes, the motivation for proving the correctness of a system is not the obvious need for reassurance of the correctness of the system, but a desire to understand the system better. Consequently, some proofs of correctness are produced in the style of mathematical proof: handwritten (or typeset) using natural language, using a level of informality common to such proofs. A "good" proof is one that is readable and understandable by other human readers. Critics of such approaches point out that the ambiguity inherent in natural language allows errors to be undetected in such proofs; often, subtle errors can be present in the low-level details typically overlooked by such proofs. Additionally, the work involved in producing such a good proof requires a high level of mathematical sophistication and expertise.

Interactive theorem proving Proof assistants occupy a middle ground between wholly human-directed and wholly automated proof. The user directs the argument, typically by applying tactics, while the tool records each step and mechanically checks the resulting proof. Because the finished proof is checked by a comparatively small and stable kernel, the much larger body of search and automation surrounding it need not itself be trusted. Systems in common use include Isabelle/HOL, the Rocq Prover (named Coq until 2025), Lean, Agda, HOL4, PVS and ACL2. Interactive proof underlies most of the largest verified software artifacts, including the seL4 microkernel and the CompCert compiler, and is increasingly combined with automated back ends so that routine obligations are discharged by solvers while difficult ones are proved by hand.

Automated proof In contrast, there is increasing interest in producing proofs of correctness of such systems by automated means. Automated techniques fall into four general categories:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Formal methods

Start with the simplest possible case. Write down what Formal methods claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer 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 Formal methods 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 Formal methods 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 Formal methods

In research
Formal methods appears in computer 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 Formal methods 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
Formal methods is common in secondary-school and first-year university syllabi. It links to neighbouring topics Formal methods, Software development philosophies, Specification languages, so understanding it makes those chapters shorter.
In everyday life
Look for Formal methods 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.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Formal methods” →

How to study Formal methods in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Formal methods 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 Formal methods out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Formal methods in simple terms?

In computer science, formal methods are mathematically rigorous techniques for the specification, development, analysis, and verification of software and hardware systems. The use of formal methods for software and hardware design is motivated by the expectation that, as in other engineering discip…

Why does Formal methods matter?

Because it connects several computer 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 Formal methods?

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 Formal methods.

Tags

  • Formal methods
  • Software development philosophies
  • Specification languages
  • Theoretical computer science

Keep exploring