% This is a TeX file
% It is essentially a programming language for mathematics documents
% You can ignore this first portion of the file, as it is essentially a bunch of "include" statements.
\documentclass[10pt]{article}

\usepackage{pictex, latexsym, graphicx,amsmath,amssymb,amsbsy,amsfonts,amsthm,verbatim}
\usepackage{graphics}
\usepackage{hyperref}
\usepackage{fullpage}
\usepackage{fancyhdr}
\usepackage{array}

\usepackage{algorithm,algorithmic}
\usepackage{multirow}

\setlength{\parskip}{0.5em}
\setlength{\parindent}{0em}
\setlength{\voffset}{-0.5in}
\setlength{\headsep}{0.25in}

% The following denotes a counter for the problems.
\newcounter{problem}
\newcommand{\problem}{\textbf{Problem \refstepcounter{problem}.}}

% These are macro shortcuts! Helpful!
\def\vu{\mathbf{u}}
\def\vx{\mathbf{x}}
\def\vb{\mathbf{b}}
\def\vv{\mathbf{v}}
\def\vw{\mathbf{w}}

\renewcommand{\implies}{\rightarrow}
%\newcommand{\lnot}{\neg}
\renewcommand{\lor}{\vee}
\renewcommand{\land}{\wedge}
\newcommand{\xor}{\oplus}
\renewcommand{\iff}{\leftrightarrow}
\newcommand{\TRUE}{\mathbf{T}}
\newcommand{\FALSE}{\mathbf{F}}
\newcommand{\universe}{\mathcal{U}}


\begin{document}
\pagestyle{fancyplain}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NOW you can start typing your text that will appear in the PDF!!!

% Note that anything after a '%' is a comment!

% Anything immediately after a '\' is a command. 
% Some denote formatting, some are for special characters.
% The '$' symbol starts and ends "math mode". Use this only for mathematical statements
% In math mode, any sequence of letters is meant to be a list of variables, so use "\sin x" for the sine of x, which will look much different from "sin x"

\lhead{}
\rhead{}
\chead{COM S 330 --- Lecture Notes --- Week of Jan 21--23}

\renewcommand{\arraystretch}{1.25}

\section{Wednesday, January 21}

\textbf{Reading:} Rosen: 1.4, 1.5

\subsection{Rosen 1.4 --- Predicates and Quantifiers}

Suppose that we know the proposition ``All cellphones have GPS antennae.'' We can then rule out the proposition ``My cell phone does not have a GPS antenna.'' and we can also verify ``Your cellphone has a GPS antenna.'' We can be sure of these \emph{specific} propositions, because we know a \emph{universal} proposition. Keyword: \emph{all}.

\textbf{Def:} A \emph{predicate} is  a statement about the subject of a proposition. If a proposition has a \emph{variable}, say $x$, as a subject, then the proposition is a \emph{propositional function} $P$ on the variable $x$, whose truth value $P(x)$ depends on the value of $x$.

\textbf{Ex:} ``$x \geq 3$'' (with $x = 6$: ``$6 \geq 3$'') ``$x$ is a hamster.'' (with $x = $``Harry'', ``Harry is a hamster.'') ``Cell phone model $x$ has a GPS antenna.'' (with $x = $``iPhone 6'', ``Cell phone model iPhone 6 has a GPS antenna.'') ``$x + y = 4$'' (with $x = 3$ and $y = 2$, ``$3 + 2 = 4$'')

We can use variables to split propositions into parts: ``For all cellphones $x$, $x$ has a GPS antenna.'' If this statement is true, then no matter what cell phone we use for $x$, the sentence ``$x$ has a GPS antenna.'' will evaluate to true.

\textbf{Def:} When using multiple variables, such as ``$x_1 + x_2 + x_3 \geq 0$,'' we can use the propositional function $P(x_1,x_2,x_3)$ to denote the multi-variate sentence. $P$ is also called a \emph{$n$-place predicate} or \emph{$n$-ary predicate} when using $n$ variables.


Sometimes we want to know how ``often'' a proposition is satisfied. That is: is it always true? is it true at least once? or is it never true? This is the concept of \emph{quantification}. We wish to ``quantify'' how often the propositional function is true. However, we must first identify the possible values the variables can take. The \emph{domain of discourse} (or \emph{universe of discourse}) is the collection of all values for a certain variable. Frequently this will only be implied, not explicit.

\textbf{Def:} The \emph{universal quantification} of $P(x)$ is the statement ``$P(x)$ for all values of $x$ in the domain.'' This is denoted by the symbolic sentence $\forall x P(x)$. An element for which $P(x)$ is false is a \emph{counterexample} to $\forall x P(x)$.

\textbf{Example:} Let $P(x)$ denote ``$x \cdot 1 = x$'' where the domain for $x$ is the integers. Then $\forall x P(x)$ denotes ``For all integers $x$, $x \cdot 1 = x$,'' which is true. If $Q(x)$ denotes ``$x$ is even,'' then $\forall x Q(x)$'' denotes ``For all integers $x$, $x$ is even,'' which is false. A counterexample to $\forall x Q(x)$ is $x = 3$, since $3$ is an integer and ``3 is even'' is false. 

\textbf{Def:} The \emph{existential quantification} of $P(x)$ is the statement ``$P(x)$ for some value of $x$ in the domain.'' This is denoted by the symbolic sentence $\exists x P(x)$. An element for which $P(x)$ is true is an \emph{example} to $\exists x P(x)$.

\textbf{Example:} If $Q(x)$ denotes ``$x$ is even,''  where the domain for $x$ is the integers, then $\exists x Q(x)$'' denotes ``There exists an integer $x$ where $x$ is even,'' which is true. Let $P(x)$ denote ``$x \cdot 1 = -x$''. Then $\exists x P(x)$ denotes ``There exists an integer $x$ such that $x \cdot 1 = -x$,'' which is true.  An example to $\exists x P(x)$ is $x = 0$, since $0 = -0$.

\begin{center}
\begin{tabular}[h]{|c|l|l|}
\hline
\textbf{Statement} & \textbf{When True?} & \textbf{When False?} \\
\hline
$\forall x P(x)$ & $P(x)$ is true for every $x$ & There is an $x$ for which $P(x)$ is false\\
$\exists x P(x)$ & There is an $x$ for which $P(x)$ is true & $P(x)$ is false for every $x$\\
\hline
\end{tabular}
\end{center}

\textbf{Restricted Domains:} Some times we want to specify our universe of discourse inside our proposition. So, immediately after our quantifier, we can put int a \emph{restricted domain}, as in ``$\forall x \geq 0 (\sqrt{x^2} = x)$.'' This sentence reads as ``For all (real numbers) $x$ where $x \geq 0$, the square root of $x^2$ is equal to $x$.''


\textbf{Note:} Quantifiers have precedence over all other operators, so the sentence ``$\forall x P(x) \land Q(x)$'' is properly parenthesized as $(\forall x P(x))\land Q(x)$.  However, this rarely occurs, as when using a quantifier, you should not use the same variable outside of the quantified statement. Instead, we could have a propositional function $P(y) = ``(\forall x Q(x,y)) \land R(y)$'' where $y$ is the only ``global'' variable, and the variable $x$ has scope only within the quantified statement. An example of such a phrase is: $P(y) = ``(\forall x (y^x > 0)) \land (y < 1).''$ Here, $Q(x,y) = (y^x > 0)$ and $R(y) = (y < 1)$. [Observe $P(y)$ is true exactly when $0 < y < 1$.]

\textbf{Def:} When a variable appears next to a quantifier, (such as $\forall x$ or $\exists y$) then the variable is \emph{bounded}. Otherwise, the variable is \emph{free} and is part of the input to the propositional function. In the example $P(y)$ above, $x$ is bounded and $y$ is free.

\subsubsection{Logical Equivalences Involving Quantifiers}

There are a few logical equivalences to remember:

\begin{center}
\begin{tabular}[h]{|p{2.5in}|p{1.4in}|}
\hline
\multicolumn{2}{|l|}{{\sc Table:} \textbf{Logical Equivalences Using Quantifiers}}\\
\hline
\textit{Equivalence} & \textit{Name}\\
\hline
$\forall x (P(x) \land Q(x)) \equiv (\forall x P(x))\land (\forall xQ(x))$ & Distributive Laws  \\
$\exists x(P(x)\lor Q(x)) \equiv (\exists x P(x)) \lor (\exists xQ(x))$ & \\
\hline
$\lnot (\forall x P(x)) \equiv \exists x \lnot P(x)$ & DeMorgan's Laws \\
$\lnot (\exists x P(x)) \equiv \forall x \lnot P(x)$ & \\
\hline
\end{tabular}
\end{center}

\subsubsection{Suggested Homework}

Rosen 1.4: 1-10, 11--20, 35--36, 43--45, 50--51.



\subsection{Rosen 1.5 --- Nested Quantifiers}

When using multiple quantifiers, we need to understand how the order matters. 
Consider the following quantified propositions where the domain is \emph{real numbers}.
\begin{quote}
$P(x,y) = ``x + y > 0''$\\
$Q(x,y) = ``x^y \geq 0''$
\end{quote}
And then consider the following propositions:
\begin{quote}
1. $\forall x \exists y P(x,y).$ :: ``For all numbers $x$ there exists a number $y$ such that $x + y > 0$.''\\
2. $\exists y \forall x P(x,y).$ :: ``There exists a number $y$ where for all numbers $x$ we have $x + y > 0$.''\\
3. $\forall x \exists y Q(x,y).$ :: ``For all numbers $x$ there exists a number $y$ such that $x^y \geq 0$.''\\
4. $\exists y \forall x Q(x,y)$. :: ``There exists a number $y$ where for all numbers $x$ we have $x^y \geq 0$.''
\end{quote}
Observe that (1) is true (given any $x$, let $y = 1 - x$ and $y$ is an example for $\exists y P(x,y)$) but (2) is false (given any $y$, let $x = -1-y$ and observe this $x$ is a counterexample  for $\forall x P(x,y)$).
Also observe that (3) and (4) are both true (let $y$ be an even integer), but the sentences have different meaning (in (3) we can select our choice of $y$ depending on the value of $x$ (such as $y = 1$ when $x \geq 0$), but in (4) we must select a single number $y$ (such as $y = 2$) where $x^y \geq 0$ for all numbers $x$.)

This shifting of meaning does not matter when talking about the same \emph{type} of quantifier, for instance:
\[
	\forall x \forall y (x+y=y+x), \quad \text{vs.} \quad \forall y \forall x (x + y = y+x).
\]

The issue arises when the quantifiers \emph{alternate}.

\begin{center}
\begin{tabular}[h]{|p{0.7in}|p{2.5in}|p{3.1in}|}
\hline
\textbf{Statement} & \textbf{When True?} & \textbf{When False?}\\
\hline
$\forall x \forall y P(x,y)$ & \multirow{2}{*}{$P(x,y)$ is true for every pair $(x,y)$.} &  \multirow{2}{*}{There is a pair $(x,y)$ where $P(x,y)$ is false.} \\
$\forall y \forall x P(x,y)$ & & \\
\hline
$\forall x \exists y P(x,y)$ & For every $x$ there is a $y$ for which $P(x,y)$ is true. & There is an $x$ such that $P(x,y)$ is false for every $y$.\\
\hline
$\exists x \forall y P(x,y)$ & There is an $x$ for which $P(x,y)$ is true for every $y$. & For every $x$ there is a $y$ such that $P(x,y)$ is false.\\
\hline
$\exists x \exists y P(x,y)$ &  \multirow{2}{*}{There  a pair $(x,y)$ where $P(x,y)$ is true.} &   \multirow{2}{*}{$P(x,y)$ is false for all pairs $(x,y)$.} \\
$\exists y \exists x P(x,y)$ & & \\
\hline
\end{tabular}
\end{center}

\textbf{DeMorgan's Law for Nested Quantifiers}

When using nested quantifiers, keep in mind that we can parenthesize as in the following:
\[
	\forall x \exists y \forall z P(x,y,z) \equiv \forall x (\exists y (\forall z (P(x,y,z)))).
\]
Thus, we can treat each interior proposition as a propositional function of the outer variables and apply DeMorgan's law.
\begin{align*}
	\lnot(\forall x (\exists y ( \forall z (P(x,y,z))))) &\equiv \exists x \lnot(\exists y (\forall z (P(x,y,z))))\\
		& \equiv \exists x (\forall y \lnot (\forall z (P(x,y,z))))\\
		& \equiv \exists x (\forall y (\exists z (\lnot P(x,y,z)))).
\end{align*}

\subsubsection{Recommended Homework}

Rosen 1.5: 1--10, 18--23, 24-28, 30--33, 36--38, 39--40, 48--49.




\clearpage
\section{Friday, January 23}

\subsection{Rosen 1.6: Rules of Inference}

We will now study a very restricted form of proof.
We demonstrate \emph{true propositions} given a collection of other \emph{true propositions}.
That is, we will reach certain \emph{conclusions} given certain \emph{premises}. 

Our proofs will follow a collection of steps, called \emph{rules of inference}, that allows us to present certain true statements from others.
Steps that appear to be rules of inference, but are flawed, are called \emph{fallacies}. We will try to look out for these!

\textbf{Def:} An \emph{argument} (in propositional logic) is a sequence of propositions.
These propositions are either \emph{premises} or \emph{conclusions}. 
The final proposition is the \emph{final conclusion}.

Here is a breakdown of these things:
\begin{enumerate}
\item \emph{premises} are propositions that are assumed to be true.
\item \emph{conclusions} are propositions that are true when all previous propositions are true. These are demonstrated by applying a \emph{rule of inference} on some number of previous propositions.
\item the \emph{final conclusion} is the last conclusion, usually the statement you are trying to prove. If $p_1, \dots,p_n$ are the premises and $q$ is the conclusion, your argument demonstrates $(p_1\land p_2\land \dots \land p_n)\implies q$ is a tautology (understanding that $p_1,\dots,p_n,q$ are  placeholders for compound propositions).
\end{enumerate}

Consider the table of Rules of Inference (next page). Observe that they are all true! How would they be described using English sentences? 
Describe some using Truth Tables.


\begin{table}[htp]
Here is a list of \emph{rules of inference} that we can use in order to create an argument.

\vspace{0.5in}

\centering
{
{
\renewcommand{\arraystretch}{1.0}
\begin{tabular}[h]{|p{1.1in}|p{1.9in}|p{1.4in}|}
\hline
\textit{ Rule of Inference} & \textit{Tautology} & \textit{Name} \\
\hline
$\begin{array}{rl}
&p\\\cline{2-2}
\therefore & p \lor q
\end{array}$
& $p \implies (p \lor q)$ & Addition\\
\hline
$\begin{array}{rl}
&p \land q \\\cline{2-2}
\therefore & p 
\end{array}$
& $(p\land q) \implies p$ & Simplification\\
\hline
$\begin{array}{rl}
&p \\
&q \\\cline{2-2}
\therefore & p \land q
\end{array}$
& $((p) \land (q)) \implies (p \land q)$ & Conjunction\\
\hline
$\begin{array}{rl}
&p \\
&p\implies q \\\cline{2-2}
\therefore & q 
\end{array}$
& $(p \land (p \implies q)) \implies q$ & Modus ponens\\
\hline
$\begin{array}{rl}
&\lnot q\\
&p\implies q \\\cline{2-2}
\therefore & \lnot p 
\end{array}$
& $(\lnot q \land (p\implies q)) \implies \lnot p$ & Modus tollens\\
\hline
$\begin{array}{rl}
&p \\
&p\iff q \\\cline{2-2}
\therefore & q 
\end{array}$
& $(p \land (p \iff q)) \implies q$ & Modus ponens (Alt.)\\
\hline
$\begin{array}{rl}
&\lnot q\\
&p\iff q \\\cline{2-2}
\therefore & \lnot p 
\end{array}$
& $(\lnot q \land (p\iff q)) \implies \lnot p$ & Modus tollens (Alt.)\\
\hline
$\begin{array}{rl}
&p \implies q\\
& q\implies r \\\cline{2-2}
\therefore & p \implies r 
\end{array}$
& $[(p \implies q) \land (q \implies r)] \implies (p \implies r)$ & Hypothetical syllogism\\
\hline
$\begin{array}{rl}
&p \lor q \\
& \lnot p \\\cline{2-2}
\therefore & q 
\end{array}$
& $[(p \lor q) \land \lnot p] \implies q$ & Disjunctive syllogism\\
\hline
$\begin{array}{rl}
&p \lor q \\
&\lnot p \lor r \\\cline{2-2}
\therefore & q \lor r 
\end{array}$
& $[(p \lor q) \land (\lnot p \lor r)] \implies (q \lor r)$ & Resolution\\
\hline
$\begin{array}{rl}
&p \iff q \\\cline{2-2}
\therefore & p \implies q
\end{array}$
& $[(p\iff q)] \implies (p \implies q)$ & Biconditional Simplification\\
\hline
\end{tabular}}

\textbf{Table.} Rules of inference.

\vspace{0.5in}
{
\renewcommand{\arraystretch}{1.0}
\begin{tabular}[h]{|p{1.6in}|p{1.8in}|}
\hline
\textit{ Rule of Inference} & \textit{Name} \\
\hline
$\begin{array}{rl}
&\forall xP(x)\\\cline{2-2}
\therefore & P(c) 
\end{array}$
& Universal instantiation\\
\hline
$\begin{array}{rl}
&P(c) \text{ for arbitrary $c$}\\\cline{2-2}
\therefore &\forall x P(x)
\end{array}$
& Universal generalization\\
\hline
$\begin{array}{rl}
&\exists xP(x)\\\cline{2-2}
\therefore & P(c) \text{ for some $c$}
\end{array}$
& Existential instantiation\\
\hline
$\begin{array}{rl}
&P(c)\text{ for some $c$}\\\cline{2-2}
\therefore & \exists x P(x)
\end{array}$
& Existential generalization\\
\hline
\end{tabular}
}

\textbf{Table.} Rules of inference using quantifiers.
}
\end{table}


\textbf{Ex:} Demonstrate that if $p \implies q$, $\lnot p \implies r$, and $r \implies s$, then $q\lor s$.

\begin{tabular}[h]{rp{1.5in}p{3in}}
\multicolumn{2}{l}{\textbf{Step}} & \textbf{Reason} \\
\hline
1. & $p\implies q$ & Premise.\\
2. & $\lnot p \implies r$ & Premise.\\
3. & $r \implies s$ & Premise.\\
4. & $\lnot p \implies s$ & Hypothetical syllogism of (2) and (3).\\
5. & $p \lor s$ & Logical equivalence using conditionals from (4).\\
6. & $\lnot p \lor q$ & Logical equivalence using conditionals from (1).\\
\hline
$\therefore$ & $q \lor s$ & Resolution using (5) and (6).
\end{tabular}

The way I like to think about this process is that you have a ``Bag of Truth'' containing all of your premises. 
That is, you have a list of compound propositions that you accept as truth.
At every step, you take one or two propositions out of the Bag of Truth, apply a Rule of Inference to create a new proposition, then put all of the propositions back in the bag.
As your bag gets bigger and bigger, hopefully your propositions look more and more like the proposition you \emph{want} to have in your bag.
Your final conclusion is your goal proposition, and the last thing to put in the bag!

Other examples:

\textbf{Ex:} Demonstrate that if $p \implies \lnot q$, $q \implies \lnot r$, $r \implies \lnot p$, then $\lnot (p \land r \land q)$.


\textbf{Rules of Inference Using Quantifiers}

When using quantified statements, we want to be able to \emph{instantiate} statements, as well as \emph{generalize} statements.


\textbf{Ex:} Let $P(x,y)$ be a propositional function. Demonstrate that if $\exists x \forall y P(x,y)$, then $\forall y \exists x P(x,y)$.


\begin{tabular}[h]{rp{2in}p{3in}}
\multicolumn{2}{l}{\textbf{Step}} & \textbf{Reason} \\
\hline
1. & $\exists x \forall y P(x,y)$ & Premise.\\
2. & $\forall y P(c,y)$ for some $c$ & Existential instantiation of (1).\\
3. & $P(c,d)$ for some $c$ and arbitrary $d$ & Universal instantiation of (2).\\
4. & $\exists x P(x,d)$ for arbitrary $d$ & Existential generalization of (3).\\
\hline
$\therefore$ & $\forall y \exists x P(x,y)$ & Universal generalization of (4).
\end{tabular}


\textbf{Ex:} Demonstrate that if $\forall x(P(x)\implies Q(x)$, $\forall x (Q(x)\implies R(x))$, and $\lnot R(a)$ for some $a$ in the domain, then $\lnot P(a)$.



\textbf{Recommended Homework:} Rosen 1.6: 3--16, 19--22, 23--24, 25--26\footnote{These two are really good problems to try!}, 27--29, 33.

\clearpage
\emph{Using rules of inference can be boring and complicated, and make proofs longer than they need to be. Here is an example of a problem we have seen before, and its evaluation using rules of inference (including shortcuts not in the book) makes it very complicated and uninteresting!}

\textbf{Big Example:} 
Consider the statement ``$A$ and $B$ are either Knights or Knaves. Knights always tell the truth. Knaves always lie. $A$ says ``We are both knights.'' $B$ says ``$A$ is a Knave.'' Therefore, $A$ is a Knave and $B$ is a Knight.''

Let us demonstrate this using rules of inference. Use the following propositional functions:
\begin{enumerate}
\item $k(x)$ : ``$x$ is a Knight.''
\item $n(x)$ : ``$x$ is a Knave.''
\item $t(x)$ : ``$x$ told the truth.''
\end{enumerate}

\scalebox{0.85}{
\begin{tabular}[h]{rp{1.5in}p{3in}}
\multicolumn{2}{l}{\textbf{Step}} & \textbf{Reason} \\
\hline
1. & $\forall x (k(x) \lor n(x))$ & Premise ``$A$ and $B$ are either Knights or Knaves.'' \\
2. & $\forall x (k(x) \implies t(x))$ &Premise  ``Knights always tell the truth.''\\
3. & $\forall x (n(x) \implies \lnot t(x))$ &Premise  ``Knaves always lie.''\\
4. & $t(A) \iff (k(A) \land k(B))$ &Premise  ``$A$ says ``We are both Knights.''''\\
5. & $t(B) \iff n(A)$ &Premise  ``$B$ says ``$A$ is a Knave.''''\\
6. & $t(A) \implies (k(A) \land k(B))$ & Biconditional simplification from (4).\\
7. & $t(A) \implies k(B)$ & Simplification from (6).\\
8. & $k(B) \implies t(B)$ & Universal instantiation from (2).\\
9. & $t(A) \implies t(B)$ & Hypothetical syllogism of (8) and (7).\\
10. & $t(B) \implies n(A)$ & Biconditional simplification from (5).\\
11. & $n(A) \implies \lnot t(A)$ & Universal instantiation from (3).\\
12. & $t(A) \implies \lnot t(A)$ & Hypothetical syllogism of (10) and (11).\\
13. & $\lnot t(A) \lor \lnot t(A)$ & Logical equivalence using conditional from (12).\\
14. & $\lnot t(A)$ & Idempotent law from (13).\\
15. & $k(A) \implies t(A)$ & Universal Instantiation from (2).\\
16. & $\lnot k(A)$ & Modus tollens from (15) and (14). \\
17. & $k(A) \lor n(A)$ & Universal instantiation from (1).\\
18. & $n(A)$ & Disjunctive syllogism from (16) and (17).\\
19. & $n(A) \implies t(B)$ & Biconditional simplification from (5).\\
20. & $t(B)$ & Modus ponens from (19) and (18).\\
21. & $n(B) \implies \lnot t(B)$ & Universal instantiation from (3).\\
22. & $\lnot n(B)$ & Modus tollens from (21) and (20).\\
23. & $k(B) \lor n(B)$ & Universal instantiation from (1).\\
24. & $k(B)$ & Disjunctive syllogism from (23) and (22).\\
\hline
$\therefore$ & $n(A) \land k(B)$ & Addition from (18) and (24).
\end{tabular}}

Here is a way to argue the same thing, using English sentences. We use numbers to indicate how the statements above connect to this argument:

(6) If $A$ tells the truth, then $A$ and $B$ are both Knights; (7) Specifically, if $A$ tells the truth, then $B$ is a Knight.
(8) If $B$ is a Knight, then $B$ tells the truth.
(9) Hence if $A$ tells the truth, then $B$ tells the truth.
(10) If $B$ tells the truth, then $A$ is a Knave.
(11) If $A$ is a Knave, then $A$ always lies.
(12) Thus, if $A$ tells the truth, then $A$ lies.
(13) This is equivalent to either $A$ lies or $A$ lies; (14) hence $A$ lies.
(15--16) Since $A$ lies, $A$ is not a Knight.
(17--18) $A$ is either a Knight or a Knave, and hence $A$ is a Knave.
(19--20) Since $A$ is a Knave, $B$ told the truth.
(21--22) Since $B$ told the truth, $B$ is not a Knave.
(23--24) Since $B$ is not a Knave, $B$ is a Knight.
Therefore, $A$ is a Knave and $B$ is a Knight.











\end{document} 