CS208 Logic & Algorithms

Semester 1: Logic

This page links to the interactive notes and exercises for Logic part of CS208 Logic & Algorithms, part of the Undergraduate BSc (Hons) and MEng Computer Science and BSc (Hons) Software Engineering degrees at the University of Strathclyde.

Please send any comments, queries, or corrections to Robert Atkey (Web page). The source code for these pages is available on Github.

Introduction

In the first semester of CS208, we will study Symbolic Logic. Symbolic Logic is a fundamental set of techniques for describing situations, reasoning, data, and processes. It is useful in computing for describing, building, and checking systems, and for solving complicated problems involving many interacting constraints. We will look at how to define logic (syntax and semantics), algorithms for computing with logic, and systems for deriving proofs in formal logic. We will also keep in mind the practical uses of logic in Computer Science.

This course follows on from CS103 and CS106 in first year.

Please see the MyPlace page (Strathclyde students only) for information on Lectures, Tutorials, and Assessment.

Learning Outcomes

By the end of semester 1 of the module you should be able to:

Topics

The course is split into 11 topics, numbered 0 to 10. Each topic corresponds to roughly a week's worth of the course.

The pages linked to below contain the lecture notes, covering the material introduced in the lectures. They also contain interactive exercises for you to do.

Further Reading

The following books and online resources may be useful if you wish to read more about the topics in this course. The links go to either the material itself if is available online, or the author's or the publisher's web pages. You might be able to find them cheaper at well-known online retailers, or in the University library.

Two books that are recommended:

  1. Logic in Computer Science by Michael Huth and Mark Ryan. The first two chapters cover Propositional Logic and Predicate Logic as we have done them in this course. They also give a natural deduction system for proof, but in a slightly different form to the one used here. Chapter 4 covers Hoare Logic for partial and total correctness. The book also contains chapters on Temporal Logic and Model checking, which we have not had time to cover in this course.

  2. Mechanizing Proof by Donald MacKenzie. This is not a technical book. It is a sociological history of the idea of doing proofs on computers and about computer hardware and software. Recommended to get a perspective on why the world of software is the way it is.

There are many software tools for doing interactive proofs with logic that are like the tool we have used in this course, but which allow much larger . The following links are to material for learning various provers and other logic tools. There are many more.

  1. The Rocq prover (formerly known as Coq) is an industrial strength interative theorem prover that has been used for proofs about software and for research in Computer Science and Mathematics. A major project in Rocq is the CompCert verified C compiler. The free online book Software Foundations is an introduction to using Rocq for verifying software.

  2. The Lean prover is an interactive theorem prover that is more tightly focused on mathematics. There is currently underway a project to prove Fermat's Last Theorem is Lean.

  3. The Agda prover is another interactive prover than is more like a programming language similar to Haskell that you will using in CS260. The CS410 Advanced Functional Programming course in 4th year uses Agda. There is an online introductory textbook Programming Language Foundations in Agda that serves as a gentle introduction.

  4. The Idris programming language is a programming language that has theorem proving features.

  5. Dafny is a programming language and verification environment that is a fully fleshed out version of the Hoare Logic tool that you have been using in this course.

  6. Why3 is another more capable version of the Hoare Logic tool, focused a bit more on research applications.

  7. The book Software Abstractions by Daniel Jackson describes the Alloy tool for building logical models of software systems. If can be used to build and model relatively complex software systems and find design bugs in them.

Formal Logic has its roots in Philosophy. There are many books aimed at Philosophy students that are interesting to read to learn about the assumptions underlying logic. Some good ones are:

  1. The Logic Manual by Volker Halbach. This is am introduction to formal logic, intended primarily for Philosophy students. It covers Propostiional and Predicate Logic with Natural Deduction proofs, but does not explore applications to Computer Science. It does discuss the connections between formal logic and natural language.

  2. Logical Methods by Greg Restall and Shawn Standefer. Also a textbook introduction to formal logic intended for Philosophy students. Covers more topics that The Logic Manual, including Modal Logic.

  3. Proofs and Models in Philosophical Logic by Greg Restall. More advanced than Logical Methods, and includes topics on “non-classical” logics that reject certain principles from the normal two-valued logic.

  4. forall x: Calgary by P. D. Magnus, Tim Button, Robert Trueman, and Richard Zach. This is an open textbook on formal logic, again primarily for Philosophy students. It uses the Carnap system for building proofs in a web browser, which is another tool for constructing proofs. See the Carnap book.

Finally, the study of logic itself is interesting in its own right, and leads to deep connections to computability and results like Gödel's Incompleteness Theorem. The main textbook for this material is:

  1. Computability and Logic by George S. Boolos, John P. Burgess, and Richard C. Jeffery.