Form of logic that allows quantification over predicates
In logic and mathematics, second-order logic is an extension of first-order logic, which itself is an extension of propositional logic. Second-order logic is in turn extended by higher-order logic and type theory.
First-order logic quantifies only variables that range over individuals (elements of the domain of discourse); second-order logic, in addition, quantifies over relations. For example, the second-order sentence formula_1 says that for every formula "P", and every individual "x", either "Px" is true or not("Px") is true (this is the law of excluded middle). Second-order logic also includes quantification over sets, functions, and other variables (see section below). Both first-order and second-order logic use the idea of a domain of discourse (often called simply the "domain" or the "universe"). The domain is a set over which individual elements may be quantified.
Examples.
First-order logic can quantify over individuals, but not over properties. That is, we can take an atomic sentence like Cube("b") and obtain a quantified sentence by replacing the name with a variable and attaching a quantifier:
 ∃"x" Cube("x")
However, we cannot do the same with the predicate. That is, the following expression:
 ∃P P("b")
is not a sentence of first-order logic, but this is a legitimate sentence of second-order logic. Here, "P" is a predicate variable and is semantically a set of individuals.
As a result, second-order logic has greater expressive power than first-order logic. For example, there is no way in first-order logic to identify the set of all cubes and tetrahedrons. But the existence of this set can be asserted in second-order logic as:
 ∃P ∀"x" (Px ↔ (Cube("x") ∨ Tet("x"))).
We can then assert properties of this set. For instance, the following says that the set of all cubes and tetrahedrons does not contain any dodecahedrons:
 ∀P (∀"x" (Px ↔ (Cube("x") ∨ Tet("x"))) → ¬ ∃"x" (Px ∧ Dodec("x"))).
Second-order quantification is especially useful because it gives the ability to express reachability properties. For example, if Parent("x", "y") denotes that "x" is a parent of "y", then first-order logic cannot express the property that "x" is an ancestor of "y". In second-order logic we can express this by saying that every set of people containing "y" and closed under the Parent relation contains "x":
 ∀P ((P"y" ∧ ∀"a" ∀"b" ((P"b" ∧ Parent("a", "b")) → P"a")) → P"x").
It is notable that while we have variables for predicates in second-order-logic, we don't have variables for properties of predicates. We cannot say, for example, that there is a property Shape("P") that is true for the predicates "P" Cube, Tet, and Dodec. This would require third-order logic.
Syntax and fragments.
The syntax of second-order logic tells which expressions are well formed formulas. In addition to the syntax of first-order logic, second-order logic includes many new "sorts" (sometimes called "types") of variables. These are:
Each of the variables just defined may be universally and/or existentially quantified over, to build up formulas. Thus there are many kinds of quantifiers, two for each sort of variables. A "sentence" in second-order logic, as in first-order logic, is a well-formed formula with no free variables (of any sort).
It's possible to forgo the introduction of function variables in the definition given above (and some authors do this) because an "n"-ary function variable can be represented by a relation variable of arity "n"+1 and an appropriate formula for the uniqueness of the "result" in the "n"+1 argument of the relation. (Shapiro 2000, p. 63)
Monadic second-order logic (MSO) is a restriction of second-order logic in which only quantification over unary relations (i.e. sets) is allowed. Quantification over functions, owing to the equivalence to relations as described above, is thus also not allowed. The second-order logic without these restrictions is sometimes called "full second-order logic" to distinguish it from the monadic version. Monadic second-order logic is particularly used in the context of Courcelle's theorem, an algorithmic meta-theorem in graph theory. The MSO theory of the complete infinite binary tree (S2S) is decidable. By contrast, full second order logic over any infinite set (or MSO logic over for example (formula_2,+)) can interpret the true second-order arithmetic.
Just as in first-order logic, second-order logic may include non-logical symbols in a particular second-order language. These are restricted, however, in that all terms that they form must be either first-order terms (which can be substituted for a first-order variable) or second-order terms (which can be substituted for a second-order variable of an appropriate sort).
A formula in second-order logic is said to be of first-order (and sometimes denoted formula_3 or formula_4) if its quantifiers (which may be universal or existential) range only over variables of first order, although it may have free variables of second order. A formula_5 (existential second-order) formula is one additionally having some existential quantifiers over second order variables, i.e. formula_6, where formula_7 is a first-order formula. The fragment of second-order logic consisting only of existential second-order formulas is called existential second-order logic and abbreviated as ESO, as formula_5, or even as ∃SO. The fragment of formula_9 formulas is defined dually, it is called universal second-order logic. More expressive fragments are defined for any "k" ; 0 by mutual recursion: formula_10 has the form formula_6, where formula_7 is a formula_13 formula, and similar, formula_14 has the form formula_15, where formula_7 is a formula_17 formula. (See analytical hierarchy for the analogous construction of second-order arithmetic.)
Semantics.
The semantics of second-order logic establish the meaning of each sentence. Unlike first-order logic, which has only one standard semantics, there are two different semantics that are commonly used for second-order logic: standard semantics and Henkin semantics. In each of these semantics, the interpretations of the first-order quantifiers and the logical connectives are the same as in first-order logic. Only the ranges of quantifiers over second-order variables differ in the two types of semantics.
In standard semantics, also called full semantics, the quantifiers range over "all" sets or functions of the appropriate sort. A model with this condition is called a full model, and these are the same as models in which the range of the second-order quantifiers is the powerset of the model's first-order part. Thus once the domain of the first-order variables is established, the meaning of the remaining quantifiers is fixed. It is these semantics that give second-order logic its expressive power, and they will be assumed for the remainder of this article.
Leon Henkin (1950) defined an alternative kind of semantics for second-order and higher-order theories, in which the meaning of the higher-order domains is partly determined by an explicit axiomatisation, drawing on type theory, of the properties of the sets or functions ranged over. Henkin semantics is a kind of many-sorted first-order semantics, where there are a class of models of the axioms, instead of the semantics being fixed to just the standard model as in the standard semantics. A model in Henkin semantics will provide a set of sets or set of functions as the interpretation of higher-order domains, which may be a proper subset of all sets or functions of that sort. For his axiomatisation, Henkin proved that Gödel's completeness theorem and compactness theorem, which hold for first-order logic, carry over to second-order logic with Henkin semantics. Since also the Skolem–Löwenheim theorems hold for Henkin semantics, Lindström's theorem imports that Henkin models are just "disguised first-order models".
For theories such as second-order arithmetic, the existence of non-standard interpretations of higher-order domains isn't just a deficiency of the particular axiomatisation derived from type theory that Henkin used, but a necessary consequence of Gödel's incompleteness theorem: Henkin's axioms can't be supplemented further to ensure the standard interpretation is the only possible model. Henkin semantics are commonly used in the study of second-order arithmetic.
Jouko Väänänen argued that the distinction between Henkin semantics and full semantics for second-order logic is analogous to the distinction between provability in ZFC and truth in "V", in that the former obeys model-theoretic properties like the Lowenheim-Skolem theorem and compactness, and the latter has categoricity phenomena. For example, "we cannot meaningfully ask whether the formula_18 as defined in formula_19 is the real formula_18 . But if we reformalize formula_19 inside formula_19, then we can note that the reformalized formula_19 ... has countable models and hence cannot be categorical."
Expressive power.
Second-order logic is more expressive than first-order logic. For example, if the domain is the set of all real numbers, one can assert in first-order logic the existence of an additive inverse of each real number by writing ∀"x" ∃"y" ("x" + "y" = 0) but one needs second-order logic to assert the least-upper-bound property for sets of real numbers, which states that every bounded, nonempty set of real numbers has a supremum. If the domain is the set of all real numbers, the following second-order sentence (split over two lines) expresses the least upper bound property:
 (∀ A) ([(∃ "w") ("w" ∈ A) ∧ (∃ "z")(∀ "u")("u" ∈ A → "u" ≤ "z")]
 → (∃ "x")(∀ "y")([(∀ "w")("w" ∈ A → "w" ≤ "x")] ∧ [(∀ "u")("u" ∈ A → "u" ≤ "y")] → "x" ≤ "y"))
This formula is a direct formalization of "every nonempty, bounded set A has a least upper bound." It can be shown that any ordered field that satisfies this property is isomorphic to the real number field. On the other hand, the set of first-order sentences valid in the reals has arbitrarily large models due to the compactness theorem. Thus the least-upper-bound property cannot be expressed by any set of sentences in first-order logic. (In fact, every real-closed field satisfies the same first-order sentences in the signature formula_24 as the real numbers.)
In second-order logic, it is possible to write formal sentences that say "the domain is finite" or "the domain is of countable cardinality." To say that the domain is finite, use the sentence that says that every surjective function from the domain to itself is injective. To say that the domain has countable cardinality, use the sentence that says that there is a bijection between every two infinite subsets of the domain. It follows from the compactness theorem and the upward Löwenheim–Skolem theorem that it is not possible to characterize finiteness or countability, respectively, in first-order logic.
Certain fragments of second-order logic like ESO are also more expressive than first-order logic even though they are strictly less expressive than the full second-order logic. ESO also enjoys translation equivalence with some extensions of first-order logic that allow non-linear ordering of quantifier dependencies, like first-order logic extended with Henkin quantifiers, Hintikka and Sandu's independence-friendly logic, and Väänänen's dependence logic.
Deductive systems.
A deductive system for a logic is a set of inference rules and logical axioms that determine which sequences of formulas constitute valid proofs. Several deductive systems can be used for second-order logic, although none can be complete for the standard semantics (see below). Each of these systems is sound, which means any sentence they can be used to prove is logically valid in the appropriate semantics.
The weakest deductive system that can be used consists of a standard deductive system for first-order logic (such as natural deduction) augmented with substitution rules for second-order terms. This deductive system is commonly used in the study of second-order arithmetic.
The deductive systems considered by and add to the augmented first-order deductive scheme both comprehension axioms and choice axioms. These axioms are sound for standard second-order semantics. They are sound for Henkin semantics restricted to Henkin models satisfying the comprehension and choice axioms.
Non-reducibility to first-order logic.
One might attempt to reduce the second-order theory of the real numbers, with full second-order semantics, to the first-order theory in the following way. First expand the domain from the set of all real numbers to a two-sorted domain, with the second sort containing all "sets of" real numbers. Add a new binary predicate to the language: the membership relation. Then sentences that were second-order become first-order, with the formerly second-order quantifiers ranging over the second sort instead. This reduction can be attempted in a one-sorted theory by adding unary predicates that tell whether an element is a number or a set, and taking the domain to be the union of the set of real numbers and the power set of the real numbers.
But notice that the domain was asserted to include "all" sets of real numbers. That requirement cannot be reduced to a first-order sentence, as the Löwenheim–Skolem theorem shows. That theorem implies that there is some countably infinite subset of the