∀∃
A Complete Interactive Course · with GNU Octave

Predicate
Logic ∀∃

First-order logic — the language of objects, properties, relations, and quantity. Learn it by evaluating real quantified formulas against a visible model you can see and change.

Chapter 00

§0Why We Need Predicate Logic

Propositional logic treats each statement as an indivisible atom — P, Q, R. That's powerful for reasoning about how whole statements combine, but it is blind to internal structure. Consider the most famous argument in logic:

The argument propositional logic cannot validate All humans are mortal. Socrates is human. Therefore, Socrates is mortal.

In propositional logic this is just three unrelated atoms, P, Q, R, and the inference P, Q ∴ R is plainly invalid. Yet the argument is obviously, undeniably valid. The validity lives inside the sentences — in the objects (Socrates), the properties (being human, being mortal), and the word "all."

Predicate logic (also first-order logic, FOL, or the predicate calculus) opens the atom. It can name individuals, ascribe properties and relations to them, and — crucially — quantify: say things about all objects or some object. It is expressive enough to formalize essentially all of mathematics, and it is the backbone of databases, AI knowledge representation, program verification, and automated theorem proving.

What you'll be able to do Translate ordinary English into precise formulas; define a model and compute whether a formula is true in it; recognize when two quantified statements are equivalent; and run valid quantifier inferences — all checked live by the engine in Chapter 05.
Chapter 01

§1The Vocabulary of First-Order Logic

FOL adds several new kinds of symbol to the propositional connectives you already know.

The building blocks

Constants — names for specific individuals: a, b, c, or socrates. Each denotes one fixed object.

Variables — placeholders ranging over the domain: x, y, z. They have no fixed meaning until bound by a quantifier.

Predicates — express properties (one argument) or relations (two or more). Human(x) is a unary predicate; Loves(x, y) is a binary relation; Between(x, y, z) is ternary. We write predicates with a capital letter.

Functions (optional) — map objects to objects: father(x), x + y. A function applied to terms yields another term, not a truth value.

Quantifiers (for all) and (there exists).

Identity — the special two-place relation =, meaning "is the very same object as."

Terms vs. formulas

A term names an object: a constant, a variable, or a function applied to terms. A formula says something true or false: a predicate applied to terms (an atomic formula), or such atoms combined with connectives and quantifiers. The litmus test: a term refers; a formula asserts.

ExpressionKindWhy
socratesterm (constant)names an object
father(x)termnames the father of x
Mortal(socrates)atomic formulaasserts a property; T or F
∀x (Human(x) → Mortal(x))formulaa quantified assertion
Chapter 02

§2Quantifiers, Scope & Binding

The two quantifiers are the heart of FOL.

The two quantifiers

Universal — "for all", "every", "each". ∀x P(x) is true exactly when P holds of every object in the domain.

Existential — "there exists", "some", "at least one". ∃x P(x) is true exactly when P holds of at least one object.

Over a finite domain the quantifiers are just iterated connectives. If the domain is {a, b, c}, then:

∀x P(x)P(a) ∧ P(b) ∧ P(c) — a grand conjunction
∃x P(x)P(a) ∨ P(b) ∨ P(c) — a grand disjunction

This is precisely why becomes all() and becomes any() when we model logic in Octave.

Scope, free & bound variables

The scope of a quantifier is the sub-formula it governs. A variable occurrence is bound if it lies in the scope of a quantifier using that variable, and free otherwise. A formula with no free variables is a sentence — only sentences have a definite truth value in a model.

Bound vs. free In ∀x (P(x) → Q(x, y)), every x is bound by ∀x, but y is free. The formula is an open formula, not a sentence; its truth depends on what y is assigned. The engine below will reject free variables with a clear message.
Scope convention used by this course's engine To keep parsing unambiguous, , , and ¬ bind tightly — each governs only the next atom or parenthesized group. So ∀x P(x) ∧ Q(x) reads as (∀x P(x)) ∧ Q(x). To give a quantifier wide scope, parenthesize: ∀x (P(x) ∧ Q(x)). When in doubt, add parentheses.
Chapter 03

§3Translating English into FOL

Translation is the skill that takes the most practice. Master four canonical patterns and most sentences fall into place.

The four canonical patterns

All A are B:  ∀x (A(x) → B(x))  — universal pairs with the conditional.

Some A is B:  ∃x (A(x) ∧ B(x))  — existential pairs with conjunction.

No A is B:  ∀x (A(x) → ¬B(x))  or equivalently ¬∃x (A(x) ∧ B(x)).

Some A is not B:  ∃x (A(x) ∧ ¬B(x)).

The single most common mistake Never write "all A are B" as ∀x (A(x) ∧ B(x)) — that says everything is both an A and a B. And never write "some A is B" as ∃x (A(x) → B(x)) — that's vacuously true the moment any non-A exists. Universals take ; existentials take .

Practice — tap a card to reveal the formula

Chapter 04

§4Models, Interpretations & Truth

A propositional formula's truth depends only on a row of T/F values. A first-order formula's truth depends on a richer thing: a model (or structure, or interpretation).

What a model supplies

1. A domain (universe) D — the non-empty set of objects we are talking about. Quantifiers range over exactly this set.

2. An interpretation of each constant — which object in D each name picks out.

3. An interpretation of each predicate — its extension: the set of objects (or tuples) of which it is true.

For example, let D = {1, 2, 3, 4, 5}, interpret Even as {2, 4} and Prime as {2, 3, 5}. Then ∃x (Even(x) ∧ Prime(x)) is true (witness: 2), while ∀x (Even(x) → Prime(x)) is false (4 is even but not prime).

Truth is model-relative There is no such thing as a first-order sentence being "true" full stop — only true in a model. The same sentence flips truth value across different models. A sentence true in every model is logically valid; one true in at least one is satisfiable. The evaluator below lets you switch between two worlds and watch sentences change.
Chapter 05 · Interactive Tool

The World Evaluator

Below is a visible model — a little universe of five objects, a through e, each with a shape, size, and colour, arranged left to right. Type any first-order sentence and the engine evaluates it against this world, showing the verdict plus which objects act as witnesses or counterexamples. Switch worlds to see truth values change.

Available vocabulary Unary: Cube Tet Sphere Small Large Red Blue Green · Binary: Larger Smaller LeftOf RightOf SameShape SameColor SameSize · Constants: a b c d e · Identity: x = y, x != y. Quantifiers: ∀ ∃ or type forall x / exists x.
First-Order Model Evaluator
Model: World I
¬
(
)
∃ red cube all tets small everything has a bigger a leftmost object colour fixes shape no large sphere
Chapter 06

§6Multiple Quantifiers & Why Order Matters

The real expressive power — and the real subtlety — of FOL appears when quantifiers nest. Reading order is everything: ∀x ∃y and ∃y ∀x say genuinely different things.

The classic contrast ∀x ∃y Loves(x, y) — "everyone loves someone" (each person may love a different someone).
∃y ∀x Loves(x, y) — "there is someone whom everyone loves" (one universally-beloved person).
The second implies the first, but not the reverse. Swapping two quantifiers of the same type is harmless; swapping with changes meaning.

You can witness this directly in the evaluator. Try ∀x ∃y Larger(y, x) ("everything has something larger") versus ∃y ∀x Larger(y, x) ("something is larger than everything"). Both are false in our worlds, but for different reasons — and the per-object breakdown shows you exactly which object breaks each one.

PatternReads as
∀x ∀y R(x,y)R holds of every ordered pair
∃x ∃y R(x,y)R holds of at least one pair
∀x ∃y R(x,y)each x relates to some (possibly different) y
∃y ∀x R(x,y)one fixed y is related to by every x
Chapter 07

§7Quantifier Negation & Equivalences

The quantifiers are duals: each is the negation of the other with a flipped inner negation. This is De Morgan's law lifted to predicate logic.

Quantifier negation (De Morgan for ∀/∃)

¬∀x P(x) ≡ ∃x ¬P(x)  — "not everything is P" = "something is not P".

¬∃x P(x) ≡ ∀x ¬P(x)  — "nothing is P" = "everything is not P".

To push a negation through a string of quantifiers, flip every quantifier and move the negation inward:

Worked drive-through ¬∀x ∃y Loves(x, y)  ≡  ∃x ¬∃y Loves(x, y)  ≡  ∃x ∀y ¬Loves(x, y)
"It's not the case that everyone loves someone" = "someone loves no one."

Other useful first-order equivalences (provided the swapped variable does not occur free in the displaced part):

∀x (P(x) ∧ Q(x))∀x P(x) ∧ ∀x Q(x)  (∀ distributes over ∧)
∃x (P(x) ∨ Q(x))∃x P(x) ∨ ∃x Q(x)  (∃ distributes over ∨)
∀x ∀y P∀y ∀x P  (like quantifiers commute)

⚠ Caution: does not distribute over , and does not distribute over . "Everyone is rich or poor" ≠ "everyone is rich, or everyone is poor."

Chapter 08

§8Properties of Relations

Binary predicates let us define the structural properties that pervade mathematics. Each is a one-line first-order sentence about a relation R.

PropertyFirst-order definitionIdea
Reflexive∀x R(x, x)everything relates to itself
Irreflexive∀x ¬R(x, x)nothing relates to itself
Symmetric∀x ∀y (R(x,y) → R(y,x))relation runs both ways
Antisymmetric∀x ∀y (R(x,y) ∧ R(y,x) → x = y)both ways only if identical
Transitive∀x ∀y ∀z (R(x,y) ∧ R(y,z) → R(x,z))chains collapse
Total / connected∀x ∀y (R(x,y) ∨ R(y,x) ∨ x = y)any two are comparable
Equivalence relations & orderings A relation that is reflexive, symmetric, and transitive is an equivalence relation (it carves the domain into classes) — our SameColor is one. A relation that is reflexive, antisymmetric, and transitive is a partial order. These three-line definitions are doing the work that pages of prose would otherwise require.

In the Octave lab you'll test all three properties of a relation by simple matrix operations.

Chapter 09

§9Identity & Counting

Adding the identity relation = (true exactly when both terms denote the same object) lets first-order logic count — something no predicate alone can do.

Numerical quantifiers built from identity

At least two: ∃x ∃y (P(x) ∧ P(y) ∧ x ≠ y)

At most one: ∀x ∀y (P(x) ∧ P(y) → x = y)

Exactly one (written ∃!x P(x)): ∃x (P(x) ∧ ∀y (P(y) → y = x)) — "there is a P, and anything that is P is that same one."

Identity also formalizes definite descriptions. Russell analyzed "the present King of France is bald" as: there exists exactly one king of France, and he is bald — ∃x (King(x) ∧ ∀y(King(y) → y = x) ∧ Bald(x)). Since no such king exists, the sentence is simply false, dissolving a famous puzzle.

Try counting in the evaluator "There are at least two cubes": ∃x ∃y (Cube(x) ∧ Cube(y) ∧ x != y). "There is exactly one green thing": ∃x (Green(x) ∧ ∀y (Green(y) → y = x)).
Chapter 10

§10Quantifier Rules of Inference

Natural deduction extends to predicate logic with four rules for introducing and eliminating quantifiers. Each comes with a restriction that prevents fallacies.

RuleFrom → inferRestriction
Universal Instantiation (UI)∀x P(x)P(a)none — true of all, so true of any named a
Universal Generalization (UG)P(a)∀x P(x)a must be arbitrary: it appears in no premise/assumption
Existential Generalization (EG)P(a)∃x P(x)none — a specific case proves existence
Existential Instantiation (EI)∃x P(x)P(c)c must be a fresh name, not used before
Why the restrictions matter Without the "arbitrary" restriction on UG, you could prove ∀x Even(x) from Even(2). Without the "fresh name" restriction on EI, from ∃x Dog(x) and ∃x Cat(x) you could wrongly conclude one object is both a dog and a cat by reusing the same name.

The Socrates argument, finally proved

derivation
1.  ∀x (Human(x) → Mortal(x))     (premise)
2.  Human(socrates)               (premise)
3.  Human(socrates) → Mortal(socrates)   (1, Universal Instantiation)
4.  Mortal(socrates)              (2, 3, Modus Ponens)    ∴ proved

This is the argument propositional logic could not touch. Predicate logic validates it in four lines.

Chapter 11

§11Proof Strategy, Prenex Form & Decidability

A typical first-order proof strips quantifiers off the premises (UI / EI), works in propositional logic on the instances, then re-attaches quantifiers on the conclusion (UG / EG). A second worked example — proving ∃x R(x) from ∀x (S(x) → R(x)) and ∃x S(x):

derivation
1.  ∀x (S(x) → R(x))     (premise)
2.  ∃x S(x)              (premise)
3.  S(c)                 (2, Existential Instantiation — c fresh)
4.  S(c) → R(c)          (1, Universal Instantiation)
5.  R(c)                 (3, 4, Modus Ponens)
6.  ∃x R(x)              (5, Existential Generalization)   ∴ proved

Prenex normal form

Every first-order formula is equivalent to one in prenex normal form: all quantifiers pulled to the front, followed by a quantifier-free matrix, e.g. ∀x ∃y ∀z (… ). The recipe: rename variables apart, push negations in with quantifier-negation laws, then migrate quantifiers outward. Skolemization goes further, replacing each existential with a function of the universals before it — the key preprocessing step for automated theorem provers.

A profound limit Propositional logic is decidable: a truth table always settles validity. First-order logic is only semi-decidable — Church and Turing proved (1936) there is no algorithm that decides validity for every FOL sentence. A prover can confirm every valid sentence eventually, but may run forever on an invalid one. Gödel's completeness theorem (1930) guarantees that every valid sentence has a proof; his incompleteness theorems (1931) show no consistent system rich enough for arithmetic can prove all arithmetical truths. These results are landmarks of twentieth-century thought.
Chapter 12 · Computational Lab

§12The GNU Octave Predicate-Logic Lab

GNU Octave models first-order logic beautifully over a finite domain. Unary predicates become logical vectors; binary relations become logical matrices. The universal quantifier is all(), the existential is any(), and the conditional is ~A | B. Copy any block into Octave (or the free sandbox at octave-online.net) and run it.

Lab 1 — Predicates as vectors; ∀ and ∃

predicates.m
% Domain = {1,2,3,4,5}. Predicates are logical vectors over the domain.
domain = 1:5;
Cube  = logical([1 1 0 0 0]);   % objects 1,2 are cubes
Small = logical([0 1 0 1 1]);

printf('∃x Cube(x)            : %d\n', any(Cube));      % exists a cube
printf('∀x Small(x)           : %d\n', all(Small));     % all are small
printf('∀x (Cube(x)->Small(x)): %d\n', all(~Cube | Small));   % all cubes small?
printf('∃x (Cube(x)&Small(x)) : %d\n', any(Cube & Small));   % some small cube?

Lab 2 — Quantifier negation (the duals)

negation.m
P = logical([1 1 0 1 1]);
printf('¬∀x P(x)  ==  ∃x ¬P(x) ?  %d\n', (~all(P)) == any(~P));
printf('¬∃x P(x)  ==  ∀x ¬P(x) ?  %d\n', (~any(P)) == all(~P));

Lab 3 — Binary relations & nested quantifiers

A relation is a matrix: R(i,j)=1 means object i relates to object j. Watch ∀x∃y and ∃y∀x come apart.

relations.m
% sizes of objects 1..5 (2 = large, 1 = small)
sz = [2 1 2 1 1];
R  = bsxfun(@gt, sz', sz);       % R(i,j) = Larger(i,j) = sz(i) > sz(j)

printf('∀x∀y Larger(x,y) : %d\n', all(all(R)));
printf('∃x∃y Larger(x,y) : %d\n', any(any(R)));
% ∀x ∃y R(x,y): every object is larger than something? (each ROW has a 1)
printf('∀x∃y Larger(x,y) : %d\n', all(any(R, 2)));
% ∃y ∀x R(x,y): something larger than EVERY object? (some COLUMN all 1s)
printf('∃y∀x Larger(x,y) : %d\n', any(all(R, 1)));

Lab 4 — Reflexive, symmetric, transitive

properties.m
% colour codes for objects 1..5 (1=red, 2=blue, 3=green)
col = [1 2 2 1 3];
S = bsxfun(@eq, col', col);     % SameColor(i,j)

reflexive  = all(diag(S));            % ∀x R(x,x)
symmetric  = isequal(S, S');           % ∀x∀y (R(x,y)->R(y,x))
twostep    = (double(S) * double(S)) > 0;   % reachable in 2 steps
transitive = all(all(~twostep | S));   % ∀x∀y∀z chain rule

printf('SameColor:  reflexive=%d  symmetric=%d  transitive=%d\n', ...
        reflexive, symmetric, transitive);
% all three true => SameColor is an equivalence relation

Lab 5 — Identity & numerical quantifiers

counting.m
Cube  = logical([1 1 0 0 0]);
Green = logical([0 0 0 0 1]);

printf('∃x P(x)  at least one cube : %d\n', sum(Cube) >= 1);
printf('at least TWO cubes         : %d\n', sum(Cube) >= 2);
printf('∃!x exactly one green      : %d\n', sum(Green) == 1);
% Uniqueness as identity:  ∃x(P(x) & ∀y(P(y) -> y=x))  <=>  sum(P)==1
The bridge to remember all = · any = · ~A | B = · row-wise any(R,2) = inner ∃y · column-wise all(R,1) = inner ∀x · sum(P) counts witnesses. Finite-domain logic is linear algebra over the booleans.
Chapter 13 · Interactive Tool

Self-Test Quiz

Ten questions across the whole course. Click an answer for instant feedback and an explanation.

Score: 0 / 10
Chapter 14

§Symbol & Syntax Reference

SymbolNameReads asEngine input / Octave
Universalfor all / every or forall x / all()
Existentialthere exists / some or exists x / any()
∃!Unique existentialthere is exactly onebuilt from = / sum(P)==1
¬Negationnot~ ¬ / ~
Conjunctionand& ∧ / &
Disjunctionor| ∨ / |
Conditionalif … then-> → / ~A | B
Biconditionaliff<-> ↔ / ==
=Identityis the same as= / ==
Non-identityis not!= ≠ / ~=
P(x)Predicatex has property Plogical vector
R(x,y)Relationx stands in R to ylogical matrix
Where to go next Beyond first-order: second-order logic (quantify over predicates and sets), modal & temporal logics (necessity, time, knowledge), type theory and the Curry–Howard correspondence, and the metatheory — soundness, completeness, compactness, and Löwenheim–Skolem.