Interface:First-order logic

Formulas, objects, and quantification
We build on Interface:Classical propositional calculus:  param (CLASSICAL Interface:Classical_propositional_calculus ) 

By convention we use φ, ψ, χ, and θ to represent formulas:  var (formula φ ψ χ θ) 

We also define some variables which suggest which variables are likely to occur in a formula. For example,  is likely to include the variable   (of course, it is the distinct variable constraints which really specify what variables are allowed). This is similar in intent to the notation  which is sometimes used in treatments of predicate logic.  var (formula φx φy ψy) 

We use the term object to refer to something which is subject to quantification or equality. From an axiomatic point of view, what is a valid object is defined implicitly, by axioms such as those of ZFC set theory or Peano arithmetic.

 kind (object) var (object s t u s0 s1 t0 t1) 

A variable is something we can quantify over.

 kind (variable) var (variable x y z x0 x1 y0 y1) 

A variable can be used where an object is expected, although it needs to be converted via the following explicit conversion. When we are writing informally (rather than in JHilbert proofs themselves), we may omit the conversion (it should be understood whereever we use a variable in a context where an object is expected).  term (object (value variable)) 

The reverse is not possible. Examples of objects which are not variables might be  for Peano arithmetic, or   for set theory.

We extend the available formulas with universal quantification and existential quantification:  term (formula (∀ variable formula)) term (formula (∃ variable formula)) 

Order of operations
In informal discussion, we omit some parentheses, building on the precedence from Interface:Classical propositional calculus. The precedence, from tightest to loosest, is:


 * ∀, ∃, is-not-free-in
 * ∀, ∃, is-not-free-in

For example,  means. We do not supply a precedence for  because we simply omit it in informal discussion.

Relationship between universal and existential quantification
 stmt (NotForAll  ((¬ (∀ x φ)) ↔ (∃ x (¬ φ)))) stmt (NotThereExists  ((¬ (∃ x φ)) ↔ (∀ x (¬ φ)))) 

Builders for quantifiers
As with propositional calculus, we need to build up formulas explicitly, and these rules let us do it. We provide them for both quantifiers, for implication and the biconditional.  stmt (addForAll ((φ → ψ)) ((∀ x φ) → (∀ x ψ))) stmt (addThereExists ((φ → ψ)) ((∃ x φ) → (∃ x ψ)))

stmt (buildForAll ((φ ↔ ψ)) ((∀ x φ) ↔ (∀ x ψ))) stmt (buildThereExists ((φ ↔ ψ)) ((∃ x φ) ↔ (∃ x ψ))) </jh>

Additional builders
Some of these builders rely on theorems we haven't presented yet, but they are similar to the simple ones above in terms of general intent.  stmt (buildThereExistsInConsequent ((x φ))  ((φ → (ψ ↔ χ)))  (φ → ((∃ x ψ) ↔ (∃ x χ)))) stmt (buildForAllInConsequent ((x φ)) ((φ → (ψ ↔ χ)))  (φ → ((∀ x ψ) ↔ (∀ x χ)))) </jh>

Order
The order of adjacent quantifiers of the same type can be exchanged:  stmt (ForAllCommutation  ((∀ x (∀ y φ)) ↔ (∀ y (∀ x φ)))) stmt (ThereExistsCommutation  ((∃ x (∃ y φ)) ↔ (∃ y (∃ x φ)))) </jh>

∃ followed by ∀ can be switched,  stmt (ThereExistsForAllCommutation  ((∃ x (∀ y φ)) → (∀ y (∃ x φ)))) </jh>

but the converse does not in general hold.

Combining quantified statements
Quantifiers of the same variable can sometimes be combined or split:  stmt (ForAllConjunction  ((∀ x (φ ∧ ψ)) ↔ ((∀ x φ) ∧ (∀ x ψ)))) stmt (ThereExistsDisjunction  ((∃ x (φ ∨ ψ)) ↔ ((∃ x φ) ∨ (∃ x ψ)))) stmt (ThereExistsImplication  ((∃ x (φ → ψ)) ↔ ((∀ x φ) → (∃ x ψ)))) stmt (ForAllImplication  ((∀ x (φ → ψ)) → ((∀ x φ) → (∀ x ψ)))) stmt (ThereExistsConjunction  ((∃ x (φ ∧ ψ)) → ((∃ x φ) ∧ (∃ x ψ)))) </jh>

Biconditional
 stmt (ForAllBiconditional  ((∀ x (φ ↔ ψ)) → ((∀ x φ) ↔ (∀ x ψ)))) </jh>

Other kinds of splits and combinations
 stmt (ForAllImplicationThereExists  ((∀ x (φ → ψ)) → ((∃ x φ) → (∃ x ψ)))) stmt (ForAllBiconditionalThereExists  ((∀ x (φ ↔ ψ)) → ((∃ x φ) ↔ (∃ x ψ))))

stmt (ThereExistsConjunctionCombining   (((∀ x φ) ∧ (∃ x ψ)) → (∃ x (φ ∧ ψ)))) stmt (ThereExistsConjunctionRightCombining   (((∃ x φ) ∧ (∀ x ψ)) → (∃ x (φ ∧ ψ))))

stmt (combineThereExistsForAll ((∃ x φ) (∀ x ψ)) (∃ x (φ ∧ ψ))) </jh>

Generalization and specialization
We can remove a universal quantifier:  stmt (Specialization  ((∀ x φ) → φ)) stmt (specialize ((∀ x φ)) φ) </jh>

The converse is sometimes possible, but only with some restrictions. Either the variable does not occur in the formula, or the formula is unconditionally true:  stmt (Generalization ((x φ)) (φ → (∀ x φ))) stmt (generalize (φ) (∀ x φ)) </jh>

An existential quantifier can be added unconditionally,  stmt (ThereExistsIntroduction  (φ → (∃ x φ))) </jh>

and can be removed if the variable does not occur in the formula.  stmt (NullThereExists ((x φ)) ((∃ x φ) ↔ φ)) stmt (removeThereExists ((x φ)) ((∃ x φ)) φ) var (formula antecedent) stmt (removeThereExistsInConsequent ((x φ)) ((antecedent → (∃ x φ))) (antecedent → φ)) </jh>

Equality
Here we are concerned with equality between variables. Equality between terms is treated in Interface:First-order logic with quantifiability.

Equality is reflexive, symmetry, and transitive.  term (formula (= object object)) stmt (VariableEqualityReflexivity  ((value x) = (value x)))

stmt (VariableEqualitySymmetry  (((value x) = (value y)) ↔ ((value y) = (value x)))) stmt (swapVariableEquality (((value x) = (value y))) ((value y) = (value x)))

stmt (VariableEqualityTransitivity   ((((value x) = (value y)) ∧ ((value y) = (value z))) → ((value x) = (value z)))) stmt (applyVariableEqualityTransitivity  (((value x) = (value y)) ((value y) = (value z))) ((value x) = (value z))) </jh>

We also define, which is just an abbreviation for negation and equality.

 def ((≠ s t) (¬ (s = t))) </jh>

Free variables
We provide a variety of ways to prove that a variable is not free in a formula, and a variety of conclusions that follow from this. These theorems do not depend on the details of how  is defined, and there is no theorem that implies the negation of   for cases not covered here. In other words,  need not correspond exactly to the conventional definition of freeness, as long as it corresponds for the cases we need.

 term (formula (is-not-free-in variable formula)) </jh>

Showing a variable is free
A variable is not free in a formula if it does not occur in the formula:  stmt (DistinctNotFree ((x φ)) (x is-not-free-in φ)) </jh>

A variable is not free in a formula if it is bound by a quantifier:  stmt (BoundForAllNotFree  (x is-not-free-in (∀ x φ))) stmt (BoundThereExistsNotFree  (x is-not-free-in (∃ x φ))) </jh>

If a variable is not free in a formula it is not free in a formula which adds another quantifier (possibly to a different variable) at the start: <jh> stmt (addForAllNotFree ((x is-not-free-in φ)) (x is-not-free-in (∀ y φ))) stmt (addThereExistsNotFree ((x is-not-free-in φ)) (x is-not-free-in (∃ y φ))) </jh>

If a variable is not free in any of the parts of a formula it is not free in the formula which joins them with connectives:

<jh> stmt (negateNotFree ((x is-not-free-in φ)) (x is-not-free-in (¬ φ)))

stmt (implicationNotFree   ((x is-not-free-in φ) (x is-not-free-in ψ))  (x is-not-free-in (φ → ψ)) )

stmt (disjunctionNotFree   ((x is-not-free-in φ) (x is-not-free-in ψ))  (x is-not-free-in (φ ∨ ψ)))

stmt (conjunctionNotFree  ((x is-not-free-in φ) (x is-not-free-in ψ))  (x is-not-free-in (φ ∧ ψ)))

stmt (biconditionalNotFree  ((x is-not-free-in φ) (x is-not-free-in ψ))  (x is-not-free-in (φ ↔ ψ))) </jh>

And we supply a builder for :

<jh> stmt (buildNotFree ((φ ↔ ψ)) ((x is-not-free-in φ) ↔ (x is-not-free-in ψ))) </jh>

Adding or removing quantifiers
If a variable is not free in a formula, it is legitimate to add or remove quantifiers from that formula: <jh> stmt (ForAllAddRemoveNotFree ((x is-not-free-in φ)) ((∀ x φ) ↔ φ)) stmt (ThereExistsAddRemoveNotFree ((x is-not-free-in φ)) ((∃ x φ) ↔ φ)) </jh>

Moving formulas in and out of quantification
The results in this section all have to do with being able to move around formulas relative to quantifiers, given that the quantified variable is not free in the formula being moved.

Implication
<jh> stmt (ForAllImplicationAntecedentMovement ((x is-not-free-in φ)) ((∀ x (φ → ψ)) ↔ (φ → (∀ x ψ)))) stmt (moveAntecedentOutOfForAll ((∀ x (φ → ψ)) (x is-not-free-in φ)) (φ → (∀ x ψ))) stmt (moveAntecedentIntoForAll   ((φ → (∀ x ψ)) (x is-not-free-in φ))   (∀ x (φ → ψ)))

stmt (ThereExistsAntecedentMovementNotFree ((x is-not-free-in φ)) ((∃ x (φ → ψ)) ↔ (φ → (∃ x ψ)))) stmt (ForAllImplicationConsequentMovement ((x is-not-free-in ψ)) ((∀ x (φ → ψ)) ↔ ((∃ x φ) → ψ))) stmt (ThereExistsImplicationConsequentMovement ((x is-not-free-in ψ)) ((∃ x (φ → ψ)) ↔ ((∀ x φ) → ψ)))

stmt (ThereExistsConjunctionMovementNotFree ((x is-not-free-in φ)) ((∃ x (φ ∧ ψ)) ↔ (φ ∧ (∃ x ψ)))) </jh>

Versions with distinct variables
<jh> stmt (ThereExistsConjunctionMovement ((x φ)) ((∃ x (φ ∧ ψ)) ↔ (φ ∧ (∃ x ψ)))) stmt (ThereExistsConjunctionRightMovement ((x ψ)) ((∃ x (φ ∧ ψ)) ↔ ((∃ x φ) ∧ ψ)))

stmt (ThereExistsDisjunctionMovement ((x φ)) ((∃ x (φ ∨ ψ)) ↔ (φ ∨ (∃ x ψ)))) stmt (ThereExistsDisjunctionRightMovement ((x ψ)) ((∃ x (φ ∨ ψ)) ↔ ((∃ x φ) ∨ ψ)) )

stmt (ThereExistsAntecedentMovement ((x φ)) ((∃ x (φ → ψ)) ↔ (φ → (∃ x ψ)))) </jh>

Here are a few rules based on these: <jh> stmt (moveLeftConjunctIntoThereExistsInConsequent ((x φ)) ((antecedent → (φ ∧ (∃ x ψ))))  (antecedent → (∃ x (φ ∧ ψ)))) stmt (moveRightConjunctIntoThereExistsInConsequent ((x ψ)) ((antecedent → ((∃ x φ) ∧ ψ)))  (antecedent → (∃ x (φ ∧ ψ)))) stmt (repeatAntecedentThereExists ((x antecedent)) ((antecedent → (∃ x ψ)))  (antecedent → (∃ x (antecedent ∧ ψ)))) </jh>

Scattering and gathering
If we have two formulas joined by a conjunction, one quantified over one variable and the other quantified over another, we can express the quantifiers either at the beginning or with the formulas they apply to. We refer to this process as gathering (that is, gathering the quantifiers together at the start of the formula) or scattering (the opposite). <jh> stmt (ThereExistsScattering ((φx y) (ψy x))  ((∃ x (∃ y (φx ∧ ψy))) ↔ ((∃ x φx) ∧ (∃ y ψy)))) stmt (gatherThereExistsInConsequent ((φx y) (ψy x)) ((antecedent → ((∃ x φx) ∧ (∃ y ψy)))) (antecedent → (∃ x (∃ y (φx ∧ ψy))))) </jh>

Adding quantifiers to theorems which are implications
These variants on moving formulas turn out to be used particularly often: <jh> stmt (addThereExistsToAntecedent ((x ψ)) ((φ → ψ))  ((∃ x φ) → ψ)) stmt (addForAllToConsequent ((x φ)) ((φ → ψ))  (φ → (∀ x ψ)))

stmt (addForAllToConsequentNotFree ((x is-not-free-in φ) (φ → ψ)) (φ → (∀ x ψ))) </jh>

Changing the quantified variable
We can transform a quantified formula by substituting each of the occurences of the variable we are quantifying over to another variable, and changing the variable in the quantifier accordingly. Here is a version with implicit substitution. <jh> stmt (ChangeVariableThereExistsNotFree ((x y))  ((x is-not-free-in φy) (y is-not-free-in φx) (((value x) = (value y)) → (φx ↔ φy))) ((∃ x φx) ↔ (∃ y φy))) stmt (ChangeVariableForAllNotFree ((x y)) ((x is-not-free-in φy) (y is-not-free-in φx) (((value x) = (value y)) → (φx ↔ φy))) ((∀ x φx) ↔ (∀ y φy)))

stmt (ChangeVariableThereExists ((y φx) (x φy) (x y))  ((((value x) = (value y)) → (φx ↔ φy)))  ((∃ x φx) ↔ (∃ y φy))) stmt (ChangeVariableForAll ((y φx) (x φy) (x y)) ((((value x) = (value y)) → (φx ↔ φy)))  ((∀ x φx) ↔ (∀ y φy))) </jh>

Other theorems related to substitution
<jh> stmt (equs3    ((∃ x (((value x) = s) ∧ φ)) ↔ (¬ (∀ x (((value x) = s) → (¬ φ)))))) stmt (VariableSubstitution ((x y))   (((value x) = (value y)) → (φ → (∀ x (((value x) = (value y)) → φ)))) ) </jh>