\documentclass[12pt]{article}
\usepackage{amssymb, amsmath}

\textheight 23cm
\textwidth 6.5in
\oddsidemargin -.1in
\evensidemargin -.1in
\topmargin -1.5cm

\input{prooftree}

\renewcommand{\theenumi}{\arabic{enumi}}
\renewcommand{\labelenumi}{\theenumi)}
\newtheorem{exer}{Exercise}

\newcommand{\eqsyn}{=_{syn}}
\newcommand{\ra}{\rightarrow}
\newcommand{\SL}{{\cal L}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\underN}{\underline{\mathbb{N}}}
\newcommand{\calM}{{\cal M}}

\def\Equiv{\Longleftrightarrow}

\def\Konig{K\"{o}nig}

\parskip 2ex
\parindent 0ex

\setcounter{page}{18}

\begin{document}

{\large\bf CS 4995}\hspace{.8in}{\large\bf Notes} (S. Cook and T. Pitassi)
\hfill {\large\bf Fall, 2022}

\begin{center}
{\Large\bf Predicate Calculus}\\
(First-Order Logic)
\end{center}

\bigskip

{\large\bf Syntax}

\bigskip

A {\em first-order vocabulary} (or just {\em vocabulary} or {\em language})
$\cal L$ is specified by the following:
\begin{enumerate}
\item
For each $n \in {\mathbb N}$ a set of $n$-ary function symbols (possibly empty).
We use $f,g,h,...$ and also $+,\cdot, s$
as metasymbols for function symbols. A zero-ary
function symbol is called a constant symbol.
\item
For each $n \geq 0$, a set of $n$-ary predicate symbols (must be non-empty
for some $n$).  We use $P,Q,R,...$ and also $<, \le, =$
as metasymbols for predicate symbols.
A zero-ary predicate symbol is the same as a propositional atom.
\end{enumerate}

In addition, the following symbols are available to build first-order
formulas:
\begin{enumerate}
\item
An infinite set of variables.  We use $x,y,z,...$ and sometimes
$a,b,c,...$ as metasymbols for variables.  (Generally distinct letters
$x,y,z$ stand for distinct variables.)
\item
connectives $\neg, \wedge,\vee $   (not, and, or)
\item
quantifiers $\forall, \exists$  (for all,  there exists)
\item
(,)    (parentheses)
\end{enumerate}
Terms and Formulas are built from these together with the function
and predicate symbols from ${\cal L}$, as described below.

The standard vocabulary of arithmetic is
$${\cal L}_A = [0, s, +, \cdot \ ; =]$$
\begin{tabbing}
$+, \ast$ \=  binary function symbol \kill
0 \>  constant (zero-ary function symbol)\\
$s$ \>  unary function symbol\\
$+, \cdot$ \>  binary function symbols\\
$=$ \>  binary predicate symbol
\end{tabbing}

\newpage

{\em Terms} (or {\em expressions})
are certain strings built from variables and function symbols, and
are intended to represent objects in the universe of discourse.

{\bf Definition of an ${\cal L}$-term} \label{Lterm}
(Here ${\cal L}$ is a first-order
vocabulary):
\begin{enumerate}
\item
Every variable is a term.
\item
If $f$ is an $n$-ary function symbol of ${\cal L}$
and $t_1, \ldots, t_n$ are $\SL$-terms then $ft_1 \dots t_n$ is an $\SL$-term.
\end{enumerate}

We will drop mention of $\SL$ when it is not important, or clear from
context.

Recall that a 0-ary function symbol is called a constant symbol
(or sometimes just a {\em constant}).  We use $e$ as a metasymbol
for constants.  Also 0 and 1 are constants.
Note that all constants in $\SL$ are $\SL$-terms.

{\bf Examples} of ${\cal L}$-terms (where $f$ is binary and $g$ is unary):\\
$fgex, fxy, gfege$.  These are parsed $f(g(e),x), f(x,y), g(f(e,g(e))$
respectively.

{\bf Unique Readability Theorem for Terms:}  If terms
$ft_1\cdots t_k$ and $fu_1\cdots u_\ell$ are syntactically equal,
then $k=\ell$ and $t_i =_{syn} u_i$, $1\le i\le k$.

{\bf Proof:} Similar to the Unique Readability Theorem for propositional
formulas (see page 2).   To prove the lemma
on weights, we assign a weight of $n-1$ to each $n$-ary function
symbol, and -1 to each variable. \hfill $\Box$

\begin{exer}
Carry out the details in the above argument.
\end{exer}

{\bf Notation:}  We use $r,s,t,...$ to denote terms.

In the vocabulary for arithmetic ${\cal L}_A$, in practice we
write $+, \cdot$ as though they were infix operators, even though
officially they are prefix operators.  Thus

{\bf Notation}
$(t_1 \cdot t_2) =_{syn} \cdot t_1 t_2$\\
$\mbox{}\hspace{.51in}(t_1 + t_2) =_{syn} + t_1 t_2$

Thus examples of our way of writing ${\cal L}_A$ terms are 
$sss0, ((x+sy)\cdot(ssz+s0))$

{\bf Definition of first-order formula in the vocabulary $\SL$ }
(or $\SL$-{\em formula}, or just {\em formula}):
\begin{enumerate}
\item
$Pt_1 \cdots t_n$ is an {\em atomic} $\SL$-formula, where 
$P$ is an $n$-ary predicate symbol in $\SL$ and $t_1, \cdots, t_n$ are $\SL$-terms.
\item
If $A$ and $B$ are $\SL$-formulas, so are $\neg A$,
$(A \wedge B)$, and $(A \vee B)$
\item
If $A$ is an $\SL$-formula and $x$ is a variable, then
$\forall x A$ and $\exists x A$ are $\SL$-formulas.
\end{enumerate}

As in the case of propositional formulas, we use the notation\\
$(A \supset B)$ for $(\neg A \vee B)$\\
$(A \leftrightarrow B)$ for
$(A \supset B)\wedge (B \supset A)$

Examples of formulas: 
$(\neg \forall x Px \vee \exists x \neg Px)$ (Here $P$ is a unary predicate
symbol.)\\
$(\forall x \neg Qxy \wedge \neg \forall z Q fyz)$.
(Here $Q$ is a binary predicate symbol and $f$ is a unary function symbol.)

The Unique Readability Theorem holds for first-order formulas.

{\bf Notation}
$r=s$ stands for   $= rs$\\
$\mbox{}\hspace{.51in}r \neq s$ stands for $  \neg(r=s) $

\bigskip

{\bf Example:} Goldbach's conjecture:
Every even integer greater than 2 is the sum of two primes.

$\forall x ((\mbox{Even}(x) \wedge x>2) \supset \exists y \exists z 
(\mbox{Prime}(y) \wedge \mbox{Prime}(z) \wedge x=y+z))$

Here Even, Prime are unary predicate symbols. \\
$>$ is a binary predicate symbol (we use infix notation).\\
2 is a constant symbol.\\
+ is a binary function symbol.

This can also be stated as a formula in the vocabulary ${\cal L}_A$,
since the predicates Even, Prime, and $>$ can be defined in terms
of $s,+,\cdot,$ and =.   For example, Even$(x)$ can be defined by
the formula $\exists y(x=y+y)$.

{\bf Free and Bound Variables}

{\bf Definition}:
An occurrence of $x$ in $A$ is {\em bound} iff it is in a subformula of
$A$ of the form $\forall x B$ or $\exists x B$.
Otherwise the occurrence is {\em free}.

For example, in the formula $ \exists y(x=y+y)$ (which defines
Even$(x)$ as above) the occurrence of $x$
is free, while the occurrences of $y$ are bound.  Intuitively
the meaning of a formula depends on the values assigned to its
free variables, but no value need be assigned to a bound variable
to give the formula meaning.

Notice that a variable can have both free and bound occurrences in
one formula.   For example, in $Px \wedge \forall x Qx$, the first
occurrence of $x$ is free, and the second occurrence is bound.

{\bf Definition}:
A formula $A$ or a term $t$ is {\em closed} if it contains no free
occurrence of a variable.
A closed formula is called a {\em sentence}.



\bigskip

{\large\bf Semantics of Predicate Calculus}

\bigskip

In the propositional calculus, a truth assignment provides meaning
to a formula.  In the predicate calculus, we need a more complicated
object, called a {\em structure} (or {\em interpretation}) to
give meaning to formulas and terms.   If $\cal L$ is a first-order
vocabulary, then an $\cal L$-structure $\cal M$ consists of the
following:

\begin{enumerate}
\item
A nonempty set $M$ called the {\em universe of discourse}
(or just {\em universe}).  Variables
in an $\cal L$-formula range over $M$.
\item
For each $n$-ary function symbol $f$ in $\cal L$, an associated
function $f^{\cal M} : M^n \mapsto  M$.
\item
For each $n$-ary predicate symbol in $\cal L$, an associated
relation $P^{\cal M} \subseteq  M^n$.  If $\cal L$ contains =,
then $=^{\cal M}$ must be the true equality relation on $M$.
\end{enumerate}

Notice that the predicate symbol = gets special treatment in the
above definition, in that $=^{\cal M}$ must always be the true
equality relation.  Other predicate symbols may be interpreted by
arbitrary relations of the appropriate arity.  For example, if
$\cal L$ contains the binary predicate symbol $<$, then $<^{\cal M}$
can be any binary relation on the universe $M$, and is not necessarily
an order relation.

Every $\cal L$-sentence becomes either true or false when interpreted
by an $\cal L$-structure $\cal M$, as explained below.  If a sentence
$A$ becomes true under $\cal M$, then we say $\cal M$ {\em satisfies}
$A$, or $\cal M$ is a {\em model} for $A$, and write
${\cal M} \models A$.

{\bf Definition:}  We say that a structure $\cal M$ is {\em finite}
if the universe $M$ of $\cal M$ is finite.  Otherwise $\cal M$
is infinite.

If $A$ has free variables, then these variables must be interpreted
as specific elements in the universe $M$ before $A$ gets a truth
value under the structure $\cal M$.  For this we need the following:

{\bf Definition:} An {\em object assignment} $\sigma$ for a
structure ${\cal M}$ is a mapping from variables
to the universe $M$.

Below we give the formal definition of notion
$\cal M \models A[\sigma]$, which is intended to mean that the
structure $\cal M$ satisfies the formula $A$ when the free variables
of $A$ are interpreted according to the object assignment $\sigma$.
First it is necessary to define the notation $t^{\cal M}[\sigma]$,
which is the element of universe $M$ assigned to the term $t$
by the structure $\cal M$ when the variables of $t$ are interpreted
according to $\sigma$.

\newpage

{\large\bf Basic Semantic Definition}

Let $\cal L$ be a vocabulary, let $\cal M$ be an
$\cal L$-structure, and let $\sigma$ be an object assignment for $\cal M$.

Each $\cal L$-term $t$ is assigned an element
$t^{\cal M}[\sigma]$ in $M$, defined by structural induction on terms $t$,
as follows  (refer to the definition of $\cal L$-term, page \pageref{Lterm}):
\begin{itemize}
\item[a)]
$x^{\cal M}[\sigma]$ is $\sigma(x)$, for each variable $x$
\item[b)]
$(ft_1 \cdots t_n)^{\cal M}[\sigma]  = f^{\cal M}(t_1^{\cal M}[\sigma],
\ldots, t_n^{\cal M}[\sigma])$
\end{itemize}

{\em Notation}: If $x$ is a variable and $m\in M$, then the object
assignment $\sigma(m/x)$ is the same as $\sigma$ except
$\sigma(m/x)(x)=m$.

For $A$ an $\cal L$-formula, the notion $\cal M \models A[\sigma]$
($\cal M$ {\em satisfies} $A$ {\em under} $\sigma$)
is defined by structural induction
on formulas $A$ as follows (refer to the definition of formula):
\begin{itemize}
\item[a)]
${\cal M} \models (Pt_1 \cdots t_n)[\sigma]$ iff
$\langle t_1^{\cal M}[\sigma], \ldots, t_n^{\cal M}[\sigma] \rangle \in P^{\cal M}$
\item[b)]
${\cal M} \models (s=t)[\sigma]$ iff $s^{\cal M}[\sigma] = t^{\cal M}[\sigma]$
\item[c)]
$\calM\models\neg A[\sigma]$ iff not $\calM\models A[\sigma]$.
\item[d)]
$\calM\models (A\vee B)[\sigma]$ iff $\calM\models A[\sigma]$
or $\calM\models B[\sigma]$.
\item[e)]
$\calM\models (A\wedge B)[\sigma]$ iff $\calM\models A[\sigma]$
and $\calM\models B[\sigma]$.
\item[f)]
${\cal M} \models (\forall x A)[\sigma]$ iff $\calM \models A[\sigma(m/x)]$
for all $m \in M$
\item[g)]
$\calM \models (\exists x A)[\sigma]$ iff $\calM \models A[\sigma(m/x)]$
for some $m \in M$
\end{itemize}

This method of giving meaning is sometimes called Tarski semantics,
named after the important logician Alfred Tarski.

Note that item b) in the definition of $\calM \models A[\sigma]$
follows from a) and the fact that $=^{\cal M}$ is always the equality
relation.

If $t$ is a closed term (i.e. contains no variables), then
$t^{\cal M}[\sigma]$ is independent of $\sigma$, and so we sometimes just
write $t^{\cal M}$.  Similarly, if $A$ is a sentence, then we sometimes
write $\calM \models A$ instead of $\calM\models A[\sigma]$,
since $\sigma$ does not matter.  (See the Corollary on the next page.)

{\bf Example:}  Let $\SL$ be the vocabulary $\{;R,=\}$ and let ${\cal M}$
be the $\SL$-structure whose universe $M=\N$ and such that
$R^{\cal M}(m,n)$ holds iff $m\leq n$.  Then
$ {\cal M} \models \exists x\forall y R(x,y)$ (since 0 is the least
element of $\N$) but ${\cal M} \not\models \exists y\forall x R(x,y)$
since there is no largest natural number.

{\bf Standard Structure:}  The {\em standard structure}
$\underN$ for the vocabulary ${\cal L}_A$ has
universe $M = \N$ = $\{ 0,1,2,...,\}$, $s^{\underN}(n)=n+1$,
and $0,+,\cdot, =$ get their usual meanings on the natural numbers.

{\bf Example:}  $\underN \models \forall x\forall y \exists z(x+z=y\vee y+z=x)$
(since either $y-x$ or $x-y$ exists) but
$\underN \not\models \forall x \exists y(y+y=x)$ since not all natural
numbers are even.

In the future we sometimes assume that there is some first-order
vocabulary $\cal L$ in the background, and do not necessarily mention
it explicitly.

{\bf Notation:}  In general, $\Phi$ denotes a set of formulas,
$A,B,C,...$ denote formulas, $\cal M$ denotes a structure, and
$\sigma$ denotes an object assignment.

{\bf Lemma:}  If $\sigma$ and $\sigma'$ agree on the free variables of
$A$, then $\calM\models A[\sigma]$ iff $\calM\models A[\sigma']$.

{\bf Proof:}  Structural induction on formulas $A$.

{\bf Corollary:}  If $A$ is a sentence, then for any object
assignments $\sigma,\sigma'$,  $\calM\models A[\sigma]$ iff
$\calM\models A[\sigma']$.

In view of the Corollary, if $A$ is a sentence, then $\sigma$ is
irrelevant, so we omit
mention of $\sigma$ and simply write $\calM \models A$.

{\bf Definition:}
\begin{itemize}
\item[a)]
$A$ is {\em satisfiable} iff $\calM\models A[\sigma]$ for some
$\cal M$ and $\sigma$.
\item[b)]
$\calM \models \Phi[\sigma]$ iff
$\calM\models A[\sigma]$ for all $A \in \Phi$.  (We may omit mention
of $\sigma$ if $\Phi$ is a set of sentences.)  We say
$\Phi$ is {\em satisfiable} if $\calM \models \Phi[\sigma]$ for some
$\cal M$ and $\sigma$.
\item[c)]
$\Phi \models A$ iff for all $\cal M$ and all $\sigma$, if
$\calM \models \Phi[\sigma]$ then $\calM\models A[\sigma]$.
\item[d)]
$\models A$ ($A$ is {\em valid}) iff $\calM\models A[\sigma]$
for all $\cal M$ and $\sigma$.
\item[e)]
$A\Longleftrightarrow B$  ($A$ and $B$ are {\em logically equivalent},
or just {\em equivalent})
iff for all $\cal M$ and all $\sigma$, $\calM\models A[\sigma]$
iff $\calM\models B[\sigma]$.
\end{itemize}

$\Phi \models A$ is read ``$A$ is a logical consequence of $\Phi$''.
This relation is of FUNDAMENTAL IMPORTANCE.  Do not confuse this
with our other use of the symbol $\models$, as in $\calM\models A$
($\calM$ satisfies $A$).
In the latter, $\cal M$ is a structure, rather than a set of formulas.

Note that $\models$ is a symbol of the ``meta language'' (English), as opposed 
to $\neg,\vee,\wedge,\forall,\exists$, which are symbols of the ``object
language''.

As in the propositional case, if $\Phi=\{B_1,\ldots,B_n\}$,
then we sometimes write $B_1,\ldots,B_n\models A$ instead of
$\{B_1,\ldots,B_n\}\models A$.


\bigskip

{\bf Examples:}
\begin{itemize}
\item[1]
$ (\forall x A \vee \forall x B) \models \forall x (A \vee B)$,
for all formulas $A$ and $B$.

Proof:  We follow the definition of $\Phi\models A$ above.
Let $\calM$ be any structure and let $\sigma$ be any object assignment.
Assume L.H.S. is true, i.e.
$\calM \models (\forall x A \vee \forall x B)[\sigma]$.
Then following the Basic Semantic Definition,
$\calM\models(\forall x A)[\sigma]$ or $\calM\models(\forall x B)[\sigma]$.
Say $\calM\models(\forall x A)[\sigma]$.
Then $\calM\models A[\sigma(m/x)] $ for all $m \in M$.
Then $\calM\models(A \vee B)[\sigma(m/x)]$ for all $m \in M$.
Therefore $\calM\models\forall x (A \vee B)[\sigma] $.

Similarly for the case $\calM\models(\forall x B)[\sigma]$. $\Box$

\item[2]
$\forall x (A \vee B) \models (\forall x A \vee \forall x B)$?
No, not necessarily.

Take $A =_{syn} Px$, $B =_{syn} Qx$, define the structure $\calM$
to have universe $M = \N$, define $P^\calM$ to be the set of even
natural numbers, and $Q^\calM$ to be the set of odd natural numbers.
Then $\calM\models\forall x(Px\vee Qx)$ (every number is even or odd),
but not $\calM\models (\forall x Px \vee \forall x Qx)$ (it is not
the case that either all numbers are even or
all numbers are odd).

\item[3]
$\neg \forall x A \Equiv \exists x\neg A$, for all formulas $A$.

$\neg \exists xA\Equiv\forall x\neg A$, for all formulas $A$.

$(\forall x A \wedge \forall x B) \Longleftrightarrow
\forall x(A \wedge B)$, for all formulas $A$, $B$.

$ \exists x (A \vee B) \Longleftrightarrow
(\exists x A \vee \exists x B)$, for all formulas $A$, $B$.

$\exists x (A \wedge B) \models
(\exists x A \wedge \exists x B)$, for all formulas $A$, $B$.

NOT $(\exists x A \wedge \exists x B) \models
\exists x(A \wedge B)$ in general

$\forall x\forall yA \Equiv \forall y\forall x A$

$\exists x\exists yA \Equiv \exists y\exists x A$

$ \exists y \forall x A \models \forall x \exists y A$, for all formulas $A$.

NOT $\forall x \exists y A \models \exists y \forall x A$ in general

$ \forall x A \models \exists x A$, because of our
requirement that every universe $M$ must be nonempty.

$\forall x\forall y(x=y\supset fx=fy)$ is valid.

$\forall x\forall y(fx=fy\supset x=y)$ is NOT valid.
\end{itemize}

\begin{exer}
Verify each line in item 3 above.  For the two lines beginning NOT
give specific formulas $A$ (and $B$) for which the relation is false,
and show it is false by giving a specific structure which satisfies
the left hand side but not the right hand side.
For the last line, give a structure which does not satisfy the formula.
\end{exer}
\begin{exer}
Show that $\{P0,Ps0,Pss0,...\} \not\models \forall xPx$
by giving a specific structure.
\end{exer}
\begin{exer}
Consider the following four formulas over the vocabulary ${\cal L}_A$:

P1: $\forall x(sx \ne 0)$ \\
P2:  $\forall x\forall y (sx=sy \supset x=y)$\\
P3: $\forall x(x+0 = x)$ \\
P4: $\forall x\forall y(x+sy = s(x+y))$

Prove from the definition of $\models$ that
$$
   \mbox{P1,P2,P3,P4 $\not\models \forall x\forall y (x+y = y+x)$}
$$
{\bf Hint:} Think of + as string concatenation.
\end{exer}
\begin{exer}
Show that $\forall x(gfx=x)$ is NOT a logical consequence of
$\forall x(fgx=x)$.
\end{exer}
\begin{exer}
Let ${\cal M}$ be a structure and let $\Phi$ be the set of all sentences
$A$ satisfied by ${\cal M}$.  Show that $\Phi$ is closed under
$\models$.  That is, show that if $\Phi\models A$ then $A\in\Phi$.
\end{exer}
\begin{exer}
Give a sentence in the vocabulary ${\cal L} = \{;=\}$ which is satisfied
by a structure iff the universe has exactly three elements.
\end{exer}
\begin{exer}
Give a satisfiable sentence $A$ in the vocabulary ${\cal L} = \{;R\}$, where $R$
is a binary predicate symbol, such that $A$ has no finite model.
(Hint:  Think of $R$ as an order relation.)
\end{exer}
\begin{exer}
Give a sentence $A$ in the vocabulary ${\cal L} = \{;R,=\}$, where
$R$ is a binary predicate symbol, such that
for all $n\in \N, n>0$, $A$ has a model whose universe has $n$ elements
iff $n$ is even.  (Hint:  Think of $R$ as a pairing relation.)
\end{exer}
\begin{exer}
Give a sentence $A$ of the predicate calculus with the vocabulary
${\cal{L}}=\{;R,=\}$, where $R$ is a binary predicate symbol, such that a
finite $\cal{L}$-structure (thought of as a directed graph with
edge relation $R$) is a model for $A$ iff it is a disjoint union of
directed cycles.  Now give an infinite model for $A$.
\end{exer}


\bigskip

Recall that a sentence is a formula with no free variables.
Each sentence in the vocabulary $\cal L_A$ (the vocabulary of arithmetic)
is either true or false
in the standard structure $\underline{\Bbb N}$.
Thus $\forall x \forall y(x+y=y+x)$ and
Fermat's Last Theorem are true, while $\forall x \neg (0 = x+x)$ is
false, and no one knows the truth value of Goldbach's conjecture.
On the other hand, a formula such as $\forall y \neg(x=y+y)$
(``$x$ is odd'')  has no truth value under any structure, since it
has a free variable.  Of course it gets a truth value in a
structure when an object assignment $\sigma$ is specified.

\bigskip

{\large\bf Substitution}

{\bf Syntactic Definition:} ($s, t$ are terms)\\
\mbox{}\hspace{.5in}$t(s/x)$ is the result of replacing all occurrences
of $x$ in $t$ by $s$.\\
\mbox{}\hspace{.5in}$A(s/x)$ is the result of replacing all
{\em free} occurrences of $x$ in $A$ by $s$.

{\bf Semantics}:

{\bf Lemma}
For each structure $\calM$ and each object assignment $\sigma$,
$$(t(s/x))^\calM[\sigma] = t^\calM[\sigma(m/x)]$$
where $m=s^\calM[\sigma]$.

{\bf Example:}  Let $\cal M$ be the standard structure $\underN$
for the vocabulary $\SL_A$ of arithmetic.  Suppose $\sigma(x)=5$
and $\sigma(y)=7$.  Let $s$ be the term $x+y$ and let $t$ be
the term $ss0$ (here $s$ is the successor function in $\SL$).
Then $s(t/x))$ is $ss0+y$ and so
$(s(t/x))^{\underN}[\sigma]=2+7=9$.  On the other hand,
$m=t^{\underN}=2$, so $s^{\underN}[\sigma(m/x)]=2+7=9$, and the Lemma
is verified for this case.

{\bf Proof if the Lemma}:  Structural induction on $t$.

Base case: $t$ is a variable.  If the variable is $x$, then both
sides of the equation are the same, namely $s^\calM[\sigma]$.
If $t$ is a variable $y$ other than $x$, then again both sides
are the same, namely $\sigma(y)$.

The induction step is straightforward from the Basic Semantic
Definition.  $\Box$

\begin{exer}
Carry out the induction step in detail.
\end{exer}

Question: Does the above lemma apply to formulas $A$?
I.e. can we say $\calM\models A(t/x)[\sigma]$ iff 
$\calM\models A[\sigma(m/x)]$, where $m=t^\calM[\sigma]$?
Something can go wrong.

Example: Suppose $A$ is $\forall y \neg (x=y+y)$.
This says ``$x$ is odd''.
But $A(x+y/x)$ is
$\forall y \neg (x+y=y+y)$, which does not say ``$x+y$ is odd''
as desired, but instead it is always false.
The problem is that $y$ in the term $x+y$ got ``caught'' by the
quantifier $\forall y$.

{\bf Definition}
A term $t$ is {\em freely substitutable  for $x$ in} $A$
iff no free occurrence of $x$ in $A$
is in a subformula of $A$ of the form $\forall y B$
or $\exists y B$, where $y$ occurs in $t$.

{\bf Substitution Theorem}:
If $t$ is freely substitutable for $x$ in $A$ then 
for all structures $\calM$ and all object assignments $\sigma$,
$\calM\models A(t/x)[\sigma]$ iff $\calM\models A[\sigma(m/x)]$,
where $m=t^\calM[\sigma]$.

{\bf Proof:} Structural induction on $A$.
The interesting case is when $A$ is $\forall y B$.  (The case
when $A$ is $\exists yB$ is similar).  Then we
are to prove
\begin{equation}
\label{subst}
\calM\models (\forall y B)(t/x)[\sigma] \mbox{ iff }
          \calM\models (\forall y B)[\sigma(m/x)]
\end{equation}
where $m=t^\calM[\sigma]$.

If $x$ does not occur free in $\forall yB$, then no substitution is done,
so the result is easy.  
(If $x,y$ are the same variable, then $x$ does not occur free in $\forall yB$.)

Hence we may assume that
$x,y$ are distinct variables and $x$ occurs free in $B$.
Since $t$ is freely substitutible for $x$ in $\forall y B$,
$y$ does not occur in $t$.

Following the Basic Semantic Definition, the LHS of (\ref{subst}) holds iff
$\calM\models B(t/x)[\sigma(n/y)]$ for all $n \in M$.
Apply the induction hypothesis to $B$ to obtain
$$\calM\models  B(t/x)[\sigma(n/y)] \mbox{ iff }
          \calM\models  B[\sigma(n/y)(m'/x)]$$
where now $m'=t^\calM[\sigma(n/y)]$.
But note that $m'=t^\calM[\sigma(n/y)]=t^\calM[\sigma] = m$
because $y$ does not occur in $t $.  Hence
    $$\calM\models  B(t/x)[\sigma(n/y)] \mbox{ iff }
          \calM\models  B[\sigma(n/y)(m/x)]$$

Now the RHS of (\ref{subst}) holds iff
$\calM\models B[\sigma(m/x)(n/y)]$ for all $n\in M$.  But
$\sigma(n/y)(m/x)=\sigma(m/x)(n/y)$, since $x$ and $y$ are distinct.
Hence the LHS holds iff the RHS holds.   $\Box$

{\bf Change of Bound Variable}

If a term $t$ is not freely substitutible for $x$ in $A$, it is
because some variable $y$ in $t$ gets caught by a quantifier
$\forall y$ or $\exists y$ in $A$.  One way to fix this is simply
rename the bound variable $y$ in $A$ to some new variable $z$.
It should be intuitively clear that this renaming does not change
the meaning of $A$.  The definition and lemmas below formalize
this process.

{\bf Definition}:  $\forall z A(z/y)$ results from $\forall y A$ by
{\em change of bound variable} provided $z$ does not occur in $A$.
Similarly for $\exists z A(z/y)$.

{\bf Lemma}: If $z$ does not occur in $A$, then
 $\forall z A(z/y)$ and $\forall y A$ are logically equivalent.
Also $\exists zA(z/y)$ and $\exists y A$ are equivalent.

{\bf Proof}:  This follows from the Basic Semantic Definition
and the Substitution Theorem.  (Verify this).  $\Box$

{\bf Definition}
$A'$ is a {\em variant} of $A$ if $A'$ results by a sequence of
changes of bound variables to subformulas of $A$.

{\bf Theorem}:
If $A'$ is a variant of $A$ then $A$ and $A'$ are equivalent.

This follows from the preceding Lemma and the following general result:

{\bf Replacement Theorem}:
If $B$ and $B'$ are equivalent formulas and $A'$ results from $A$
by replacing some occurrence of $B$ in $A$ by $B'$, then $A$
and $A'$ are equivalent.

\begin{exer}
Prove the Replacement Theorem, by structural induction on $A$ (relative
to $B$).  The base case is when $A$ and $B$ coincide.
\end{exer}

{\bf Example:}
$B$ is $\neg \forall xPxy$,
$B'$ is $\exists z\neg Pzy$,
$A$ is $\forall y (\neg\forall x Pxy\supset Qy)$.
Note that $B$ has a free variable that is bound in $A$.
$A'$ is $\forall y (\exists z\neg Pzy \supset Qy)$.
By the Replacement Theorem,
$A$ and $A'$ are equivalent, even though the quantifier $\forall y$ in $A$
catches a variable in $B$.

{\large\bf A First-Order Gentzen System}

We now extend the propositional proof system $PK$ to the first-order
sequent proof system $LK$.  For this it is convenient to introduce two
kinds of variables: 
\begin{itemize}
\item
type ``free'':  $a,b,c,...$
\item
type ``bound'': $x,y,z,...$
\end{itemize}
A first-order formula $A$ is
called a {\em proper formula} if it satisfies the restriction
that every variable that occurs free has type free, and every
variable that occurs bound has type bound.
Similarly a {\em proper term} has no variable of type bound.
Notice that a subformula of a proper formula is not necessarily proper,
and a proper formula may contain terms which are not proper.

The sequent system $LK$ is an extension of the propositional system
$PK$, where now all formulas $A_1,...,A_k,B_1,...,B_\ell$
in a sequent $A_1,...,A_k\ra B_1,...,B_\ell$ must be proper
formulas.  In addition to the rules given
for $PK$, the system $LK$ has four rules for introducing the
quantifiers.

{\bf Notation}:  In the rules below, $t$ is any proper term
and $A(t)$ is the result of
substituting $t$ for all free occurrences of $x$ in $A(x)$.
Similarly $A(b)$ is the result of substituting $b$ for all
free occurrences of $x$ in $A(x)$.  Note that
$t$ and $b$ can always be freely substituted for $x$ in $A(x)$
because $\forall x A(x)$ and $\exists xA(x)$ are proper formulas.

$\forall$ introduction rules
$$  {\mbox{\bf left}} \; {\large \frac{A(t),\Gamma\ra\Delta}
       {\forall xA(x),\Gamma\ra\Delta}} \hspace{2cm}
  {\mbox{\bf right}}\;  {\large \frac{\Gamma\ra\Delta,A(b)}
               {\Gamma\ra\Delta,\forall xA(x)}}
$$
$\exists$ introduction rules
$$  {\mbox{\bf left}} \; {\large \frac{A(b),\Gamma\ra\Delta}
       {\exists xA(x),\Gamma\ra\Delta}} \hspace{2cm}
  {\mbox{\bf right}}\;  {\large \frac{\Gamma\ra\Delta,A(t)}
               {\Gamma\ra\Delta,\exists xA(x)}}
$$
{\bf Restriction}:  The free variable $b$ must not occur in
the conclusion in $\forall$ {\bf right} and $\exists$ {\bf left}.

{\bf Example:}  An instance of $\forall$-{\bf left} is
$$
        {\large \frac{Pbb\ra Pbb} {\forall yPby\ra Pbb}}
$$
What is the formula $A(y)$ in this case?

{\bf Semantics of first-order sequents}

The semantics of first-order sequents is a natural generalization
of the semantics of propositional sequents given on page 10.
Again a sequent $S =_{syn}$
$$
 A_1,...,A_k\ra B_1,...,B_\ell
$$
has the same meaning as its associated formula $A_S =_{syn}$
\begin{equation}\label{e:meaning}
 (A_1\wedge A_2\wedge ... \wedge A_k)\supset
                          (B_1\vee B_2\vee...\vee B_\ell)
\end{equation}
In particular, we say that
the sequent is {\em valid} iff its associated formula is valid.

{\bf Definition:} [Universal Closure]
Suppose that $A$ is a formula whose free variables comprise the list
$a_1,...,a_n$.  Then the {\em universal closure} of $A$, written
$\forall A$, is the sentence
$\forall x_1...\forall x_n A(x_1/a_1,...,x_n/a_n)$, where
$x_1,...,x_n$ are new (bound) variables.  If
$\Phi$ is a set of formulas, then $\forall \Phi$ is the set of all
sentences $\forall A$, for $A$ in $\Phi$.

Note that every formula $A$ is valid iff its universal closure $\forall A$
is valid.  Also $A$ is a logical consequence of its
universal closure $\forall A$, but $\forall A$ is not necessarily
a logical consequence of $A$ (for example take $A =_{syn} Pa$).

Recall that for the propositional system $PK$, for each rule the
bottom sequent is a logical consequence of the top sequent(s).
This remains true for $LK$, with the exception of the rules
$\forall$-{\bf right} and $\exists$-{\bf left}.  For these rules
we can make a weaker statement:  the universal closure of
(the meaning of) the bottom sequent is a logical consequence of
the universal closure of (the meaning of) the top sequent.
The following proposition makes this weaker statement for all the
$PK$ rules.  (The statement is weaker, because for any formulas
$A$ and $B$, if $A\models B$, then $\forall A\models \forall B$).

{\bf Lemma}  For each $PK$ rule, the universal closure of the meaning
of the bottom sequent is a logical consequence of the universal
closure(s) of the meaning(s) of the top sequent(s).  Here the
{\em meaning} of a sequent $S$ is the formula $A_S$ given in
(\ref{e:meaning}).

{\bf Proof:}  The argument for the propositional rules is essentially
the same as for the system $PK$.  The arguments for $\forall$-{\bf left}
and $\exists$-{\bf right} are easy; and in fact in these cases
it is not necessary to take universal closures.  

We illustrate the remaining two rules by considering the case of
of $\forall$-{\bf right}.  Note that because of the {\bf Restriction}
for this rule, the variable $b$ cannot occur in $\Gamma$ or $\Delta$.
Hence it suffices to verify that
$$
\forall x(\bigwedge\Gamma\supset (\bigvee \Delta \vee A(x))) \ \ \models \ \
  \bigwedge\Gamma\supset(\bigvee\Delta\vee\forall xA(x))
$$
To see that this logical consequence holds, suppose that $\calM$
is a structure and $\sigma$ is an object assignment.  Suppose that
$\calM$ satisfies the left hand side under $\sigma$, i.e.
$$
    \calM \models \forall x(\bigwedge\Gamma\supset (\bigvee \Delta \vee A(x)))
[\sigma]
$$
Either $\calM$ satisfies $\forall xA(x)$ under $\sigma$ or not.
In the first case it follows immediately that $\calM$ satisfies
the right hand side under $\sigma$.  In the second case, it must
be that 
$$
   \calM \models \forall x(\bigwedge\Gamma\supset \bigvee \Delta )
[\sigma]
$$
and hence again $\calM$ satisfies the right hand side under $\sigma$.
\hfill $\Box$

\begin{exer}
Give the argument for the other three quantifier rules.
\end{exer}
   

{\bf Soundness Theorem for $LK$}:  Every sequent provable in $LK$
is valid.

{\bf Proof:}  This is proved by induction on the number of sequents
in the $LK$ proof.  For the base case, obviously each axiom $A\ra A$ is valid.
For the induction step, it follows from the above lemma that for each rule, if
all sequents on top are valid, then the sequent on the bottom is valid.
\hfill $\Box$

\begin{exer}
Give a specific example of a sequent $\Gamma\ra\Delta,A(b)$ which
is valid, but the bottom sequent $\Gamma\ra\Delta,\forall xA(x)$ is
not valid, because the restriction for the $\forall$ {\bf right}
rule is violated (i.e. $b$ occurs in $\Gamma$ or $\Delta$ or $\forall xA(x)$).
Do the same for the $\exists$ {\bf left} rule.
\end{exer}

An $LK$ proof of a valid first-order sequent can be obtained using
the same method as in the propositional case:  Write the goal
sequent at at the bottom, and move up by using the introduction
rules in reverse.  A good heuristic is: if there is a choice
about which quantifier to remove next, choose $\forall$ {\bf right}
and $\exists$ {\bf left} first (working backwards), since these
rules carry a restriction.

Here is an $LK$ proof of the sequent 
$(\forall xPx\vee \forall xQx)\ra\forall x(Px\vee Qx)$.

$$
\begin{prooftree}
  \[ \[ \[ \[  Pb\ra Pb \justifies Pb\ra Pb, Qb \using (weakening) \]
      \justifies Pb\ra (Pb\vee Qb) \using (\vee \  right) \]
      \justifies \forall xPx\ra (Pb\vee Qb)  \using (\forall \  left) \]
    \qquad
    \[ \[ \[  Qb\ra Qb\
       \justifies Qb\ra Pb,Qb \using (weakening) \]
       \justifies Qb \ra (Pb\vee Qb) \using (\vee \  right) \]
       \justifies  \forall xQx \ra (Pb\vee Qb) \using (\forall \  left) \]
 \justifies (\forall xPx\vee\forall xQx)\ra (Pb\vee Qb)
                                      \using (\vee \ left) \]
 \justifies (\forall xPx\vee\forall xQx)\ra \forall x(Px\vee Qx)
                                              \using (\forall \  right)
\end{prooftree}
$$

\begin{exer}
Give $LK$ proofs for the following valid sequents:

$\forall xPx\wedge\forall xQx \ra \forall x(Px\wedge Qx)$\\
$\forall x(Px\wedge Qx)\ra \forall xPx\wedge \forall xQx$\\
$\exists x (Px\vee Qx)\ra \exists xPx\vee \exists xQx$\\
$\exists x Px\vee \exists xQx\ra \exists x(Px\vee  Qx)$\\
$\exists x(Px\wedge Qx)\ra \exists xPx\wedge\exists xQx$\\
$\exists y\forall xPxy\ra\forall x\exists yPxy$\\
$\forall xPx\ra \exists xPx$

Check that the rule restrictions seem to prevent generating $LK$
proofs for the following invalid sequents:

$\exists xPx\wedge\exists xQx\ra\exists x(Px\wedge Qx)$\\
$\forall x\exists yPxy\ra \exists y\forall xPxy$
\end{exer}





\end{document}
