[Phil 151, First-Order Logic](http://web.pacuit.org/classes/phil151winter09.html), is the second term of Stanford's undergraduate logic sequence. [First-order logic (FOL)](first_order_logic) refers to a logical system which includes the propositional connectives, variables, functions, predicates, and quantifiers. In a sense, FOL is powerful enough to describe all of mathematics, yet its syntax and semantics can be defined precisely enough to say quite a lot about it.
While the course is listed in the philosophy department, it's really more like a math course. It formally defines the syntax and semantics of FOL, and most of the class is concerned with proving things about the logical system itself. It's a required course for the [symbolic systems](https://symsys.stanford.edu/) major, and has a reputation as a weeder course because, for a lot of students, it is their first course that requires writing rigorous mathematical proofs. The class roughly follows the first two chapters of Enderton's [A Mathematical Introduction to Logic](http://www.amazon.com/Mathematical-Introduction-Logic-Second-Edition/dp/0122384520).
This roadmap roughly corresponds to the course as it was taught in 2005.
## Background: logical languages, proof techniques
The course assumes that students are already comfortable working with [propositional logic](propositional_logic) and [first-order logic](first_order_logic), at the level of understanding what the symbols mean, being able to express statements in those languages, and being able to write [formal proofs](propositional_proofs) (in some formal system).
It also assumes knowledge of a few concepts in set theory:
* basic [operations on sets](set_operations)
* how to [represent functions and relations as sets](functions_and_relations_as_sets)
* the distinction between [countable and uncountable sets](countable_sets)
* [Russell's Paradox](russells_paradox), and why it justifies the need for a system of axioms for set theory (e.g. the [Zermelo-Frankl axioms](zermelo_frankl_axioms)).
Finally, it requires a certain level of comfort with several mathematical proof strategies: [direct proof](http://en.wikipedia.org/wiki/Direct_proof), [proof by contradiction](http://en.wikipedia.org/wiki/Proof_by_contradiction), and [mathematical induction](http://en.wikipedia.org/wiki/Mathematical_induction).
## Weeks 1-3: propositional logic
The first three weeks focus on [propositional logic (PL)](propositional_logic), and correspond to Chapter 1 of Enderton. This part of the course is essentially a warm-up for the second part, since it asks the same questions about PL that are later asked about FOL. (The questions are much easier in the propositional case.) The results from this part are also needed mathematically, since some of the proofs for FOL assume the corresponding results for PL (PL essentially being a subset of FOL).
The syntax and sematics of PL are both defined rigorously. Analyzing the syntax requires showing that every PL formula has a unique parse tree. The semantics of first-order sentences is defined in terms of _truth conditions_, or mappings from truth assignments to truth values. (These mappings can be represented as [truth tables](http://en.wikipedia.org/wiki/Truth_table)). Defining the semantics requires two mathematical results which allow one to formulate and reason about recursive definitions: [structural induction](structural_induction), and the [Recursion Theorem](recursion_theorem). An important result is that PL is complete, in the sense that any truth condition can be represented with some sentence in PL.
One important result about PL is that consistency is [decidable](decidability): there is a computational procedure which always halts, and which correctly determines if a set of statements is consistent. Another result is the [compactness of PL](compactness_of_propositional_logic): given any (potentially infinite) set of sentences S, if S is contradictory, then some finite subset of S is contradictory.
## Weeks 4-9: first-order logic
- The rest of the course analyzes FOL, starting with rigorous definitions of the syntax and semantics. For the syntax, just as in the propositional case, one needs to show that every sentence has a unique parse tree. Furthermore, one can define a [deductive calculus](proofs_in_first_order_logic), or formal proof system, for FOL. Even though each of the allowed proof steps is justified intuitively in terms of the semantics, the mathematical definition is purely syntactic. This is important, as one would like the proofs to be checkable by a relatively simple automated procedure.
The [semantics of FOL](semantics_of_first_order_logic) is defined in terms of possible worlds. More precisely, a first-order structure consists of a collection of things, together with sets corresponding to the functions and predicates of the language. One defines the semantics of FOL by defining the truth or falsehood of a sentence of FOL, evaluated on any particular structure.
The syntax and semantics of FOL give two different ways in which a set of hypotheses S can imply a conclusion T:
* The syntactic notion: there is some formal proof which assumes S and proves T
* The semantic notion: S logically implies T if any first-order structure satisfying S must also satisfy T
The most basic requirement is [soundness](http://en.wikipedia.org/wiki/Soundness): if you can prove T from S, then S had better logically imply T. Fortunately, this can be proved of the deductive system used in this course.
What about the other direction? [Godel's Completeness Theorem](completeness_of_first_order_logic) is a powerful result showing that any semantic entailment can be proved. More precisely, either there is a proof of T starting from S, or there is some first-order structure which satisfies S but doesn't satisfy T. Together with soundness, this result shows that the semantic and syntactic notions given above are equivalent.
The rest of the course then focuses on some interesting consequences of Godel's Completeness Theorem:
* The consistency of a set S of FOL sentences is [semi-decidable](http://en.wikipedia.org/wiki/Decidability_(logic)#Semidecidability), in that there exists a computational procedure which halts if S is inconsistent, but doesn't halt otherwise. (In particular, it exhaustively enumerates all strings, and halts as soon as it encounters a proof of contradiction starting from S.) This is in contrast with PL, which is actually decidable.
* [FOL is compact](compactness_of_first_order_logic), meaning that if a set S of FOL sentences is inconsistent, then there is a finite subset of S which is inconsistent. (This results from the fact that a proof of contradiction can have only finitely many steps.) This allows us, for instance, to extend a proof of the [Four Color Theorem](http://en.wikipedia.org/wiki/Four_color_theorem) for finite maps to the case of infinite maps. It also lets us define [nonstandard analysis](http://en.wikipedia.org/wiki/Non-standard_analysis), a rigorous notion of infinitesimals in calculus.
* The [Lowenheim-Skolem Theorems](lowenheim_skolem_theorems) show that if a first-order theory with a finite alphabet has an infinite model, then it has models of all infinite [cardinalities](cardinality). This leads to a number of bizarre results: one one hand, the [Peano axioms](peano_axioms) (which define the natural numbers) must have an uncountable model. On the other hand, the [Zermelo-Frankl axioms](zermelo_frankl_axioms) of set theory must have a countable model, despite the fact that Z-F can express [Cantor's diagonalization argument](http://en.wikipedia.org/wiki/Cantor%27s_diagonal_argument), which proves the existence of uncountable sets! Both of these results hint at inherent limits in our ability to formalize mathematical theories.