Back to Program Verification Index | Previous: (y-01) Introduction to Program Verification | Next: (y-03) First-Order Logic

Mental Model for Propositional Logic

  • Propositional Logic is the simplest “language” of logic. It deals with statements that are either true or false.
  • A satisfiable formula is one that can be true; a valid formula is one that must be true (no matter what).
  • SMT Solvers (like Z3) are our robotic assistants. They take a complex formula and either find a way to make it true or prove it’s impossible.
  • Proof Systems are a set of mechanical rules for deriving truth. They allow us to move from premises to conclusions without making mistakes.

Introduction to Propositional Logic

Propositional logic (PL) is the foundation of program verification. We use it to describe the state of a program and the conditions that must hold at each point in the code.


Syntax of Propositional Logic

A PL formula is built from:

  • Variables:
  • Constants: false, true
  • Connectives: (not), (and), (or), (implication), (equivalence)

🧠 Deep Dive: Precedence

Just like math has PEMDAS, logic has its own order:

  1. (Highest)
  2. (Lowest)

Example: is .


Semantics: What do formulas mean?

A variable assignment () maps every variable to a truth value (true or false).

  • Satisfiable: There exists at least one assignment that makes the formula true.
  • Valid (Tautology): Every possible assignment makes the formula true.
  • Unsatisfiable (Contradiction): No assignment makes it true.

Key Theorem: A formula is valid if and only if is unsatisfiable.


Truth Tables

Truth tables are the “brute force” way to check logic. You list every possible combination of inputs and calculate the output.

Example: Truth Table for

Let .

FFTFTF
FTTTFF
TFFTTF
TTTTFF

Conclusion: Since the final column is false for every possible assignment, is unsatisfiable.

Limitation: For variables, you need rows. If you have 100 variables (common in program verification), the table would have more rows than atoms in the universe!


Using SMT Solvers (Z3) for SAT

Instead of truth tables, we use SMT Solvers. They use clever algorithms (like CDCL) to solve formulas with thousands of variables in milliseconds.

In SMT-LIB notation, we write formulas in prefix notation (like Lisp).

Example for :

(declare-fun P () Bool)
(declare-fun Q () Bool)
(assert (and (=> P Q) (or P Q)))
(check-sat)
(get-model)

Proof Systems: NPL

A Proof System is a set of rules for deriving implications (meaning “if all formulas in are true, then must be true”).

Rules of NPL

Rules are written as .

RuleNameFormula
Axiom(Ax)
RAA(RAA) (Reductio ad Absurdum)
Intro ()
Elim () (for )
Intro () (for )
Elim ()
Intro ()
Elim () (Modus Ponens)
Intro ()
Elim () (Ex Falso Quodlibet)

🧠 Deep Dive: A Derivation Example

Goal: Prove . Let .

  1. Bottom-up: We want to prove .
  2. Use (I): This splits the proof into two branches: and .
  3. Left branch: . Since , this is finished by (Ax).
  4. Right branch: . Since , we use (E) (Modus Ponens).
  5. This requires proving and . Both are finished by (Ax) as they are in .

💡 Intuition: Formal Proofs

A formal proof is like a game of LEGO. You start with your base blocks (axioms) and use the connection rules to build the final shape (the conclusion). If you follow the rules, the final shape is guaranteed to be stable.

Guide for Finding a Derivation

  1. Start at the bottom: Write the goal implication as the root of your tree.
  2. Look at the Top-Level Operator: If the RHS is , use () to split the problem.
  3. Use (Ax) ASAP: As soon as the formula on the right is in the set on the left, you’ve finished that branch.
  4. No replacements: You cannot swap for without a specific rule; the proof system is purely mechanical/syntactic.

Summary

  1. Syntax: The “grammar” of logic (atoms and connectives).
  2. Semantics: The “meaning” (truth values and assignments).
  3. Satisfiability: Can it be true? Validity: Must it be true?
  4. SMT Solvers: Automated tools for solving logic.
  5. Proof Systems: Mechanical rules for human (or machine) reasoning.

Self-Check

  1. State the relationship between validity and unsatisfiability used to reduce checking validity to a SAT query.
  1. Given , what does a truth table show about its satisfiability?
  1. Why are truth tables impractical for real verification problems, and what replaces them?
  1. What is the difference between the (I) rule and the (E) rule in NPL?
  1. Sketch how to derive in NPL.

Back to Program Verification Index | Previous: (y-01) Introduction to Program Verification | Next: (y-03) First-Order Logic | (y) Return to Notes | (y) Return to Home