\documentclass[main.tex]{subfiles}
\begin{document}
\chapter{Logic}
\label{chapter:logic}

\epigraph{All opinions are not equal. Some are a very great deal more robust, sophisticated and well supported in logic and argument than others.}{Douglas Adams}

\minitoc

\section{Introduction}

Let's spell out two logic puzzles:

\begin{center}
	\textit{Sam has 1 cow. If Sam has at least 2 cows, then Sam can breed the cows to make one more cow. Assuming Sam has access to infinite resources and time, how many cows can Sam make?}
\end{center}

\begin{center}
	\textit{Two givens: knights always tell the truth, and knaves always lie. On the island of knights and knaves, you are approached by two people. The first one says to you, ``we are both knaves." What are they actually?} (from Popular Mechanic's Riddle of the Week \#43: Knights and Knaves, Part 1 \cite{pop-mech})
\end{center}

Thinking logically about these puzzles will help you -- think about what can and cannot happen; what can and cannot be true. Solving these problems is left as an exercise. There are only two possibilities for Boolean\index{Boolean} statements -- True or False. Here's a formal definition of logic, from Merriam-Webster:

\begin{defn}[Logic\index{Logic}]
	A science that deals with the principles and criteria of validity of inference and demonstration : the science of the formal principles of reasoning \cite{logic}
\end{defn}

This chapter includes a wealth of topics. We will touch on propositional logic and its corollaries, as well as predicate logic and it's applications to the rest of this course. Thinking logically should be a natural process, so we hope this section is relatively straightforward.

\section{Propositional Logic}

Propositional logic is a branch of logic that deals with simple propositions and logical connectives. Sometimes propositional logic is referred to as \textbf{zeroth-order logic}, as it lays the foundations for \textit{predicate logic}, also known as \textit{first-order logic}.

\begin{defn}[Proposition]
	\index{Proposition}
	A statement that is exclusively either true or false. A proposition must \textit{have} a true or false value, and it cannot have \textit{both}. Propositions are usually represented as variables. These variables can represent a single statement, or large compound statements. We will see examples later
\end{defn}

\begin{defn}[Logical Connective]
	An operation that connects two propositions. We study these below
\end{defn}

The motivation behind propositional logic is that we want to represent basic logical statements as an expression of variables and operators.
Propositional logic also lays the groundwork for higher-order logic.

Before we start, let us motivate propositional logic and Boolean algebra by recalling the fundamental ideas of mathematical concepts we are already familiar with.
For standard arithmetic, we utilize real numbers \(\R\), binary (two inputs) operators \(+\),\(-\),\(\times\),\(\div\),\(\cdots\), and unary (one input) operators \(\exp(\cdot)\), \(\log(\cdot)\), \(\sqrt{\cdot}\), \(\text{abs}(\cdot)\), \((-1)(\cdot)\),\(\cdots\).
Note that our operators here take elements from our main set, and return an element back inside that set.
For example, \(4.01 + 3.99\) gives us 8.
We have a way to signal that those two quantities above are the same, namely the equals sign \(=\).
Finally, we have a way to abstract out elements as \textit{variables}, for example \(x+y=z\).
And if we fill in some of the variables, we can solve for the other ones.
For example \(x+3.99=8\) implies \(x=4.01\).
In a similar way, this whole mathematical system can be completely abstracted, and we can reason about those abstract structures.
Then, any specific example that holds the same inherent properties of our structures will also have any reasoned theorem apply.
This is quite an important idea in mathematics -- we can abstract concepts and reason about abstract structures that can apply to a variety of specific examples.

\begin{figure}[h]
	\centering
	\[(\hspace{2mm} \rule{0.5cm}{0.5pt} \hspace{2mm} \mathbin{\square} \hspace{2mm} \rule{0.5cm}{0.5pt} \hspace{2mm}) \mapsto \hspace{1mm} \rule{0.5cm}{0.5pt}\]
	\caption{
		In abstract mathematics, we care about \textit{operators} that \textit{map} elements from a set into another element in the same set.
		For addition in the reals, this would look like \((4.01+3.99) \mapsto 8\).
	}
\end{figure}

Why does this apply here?
Well, for propositional logic, we are, essentially, going to \textit{define} a new \textit{structure}.
Our new ``number set'' becomes \(\B = \{\mathbf{T},\mathbf{F}\}\) (analogous to \(\R\)).
Our new ``unary operators'' become \(\lnot\) (analogous to multiplying by \(-1\), etc).
Our new ``binary operators'' become \(\land,\lor,\Rightarrow,\cdots\) (analogous to \(+,-,\times,\div,\cdots\)).
Our new ``equality'' becomes \textit{logical equivalence} (\(\equiv\) versus \(=\)).
Our idea of \textit{variables} stays the same.
But, interestingly, because our input set \(\B\) is \textit{finite} (which is different from the countably infinite \(\Z\) and the uncountable \(\R\)).
This gives us nice ways to actually \textit{write out all possibilities} for inputs and outputs of our operators.
With this in mind, let us push onward to propositional logic.

\subsection{Truth Tables and Logical Connectives}

Before we dive into the logical connectives, let's study the notion of a truth table. This will help us fully understand the logical connectives.

\begin{defn}[Truth Table]
	\index{Truth Table}
	A table that shows us all truth-value possibilities. For example, with two propositions \(p\) and \(q\):

	\begin{center}
		\begin{tabular}{c|c|c}
			\(p\) & \(q\) & \textit{some compound proposition} \\
			\hline
			F & F & T/F \\
			F & T & T/F \\
			T & F & T/F \\
			T & T & T/F
		\end{tabular}
	\end{center}
\end{defn}

Now we can begin our study of the logical connectives. The following definitions explain the intuition behind the logical connectives, and present their associated truth tables.

\begin{defn}[And \(\land\)]
	Also known as the \textit{conjunction}. Logical connective that evaluates to true when the propositions that it connects are both true. If either proposition is false, then \textit{and} evaluates to false. To remember: \textit{prop 1} \textbf{and} \textit{prop 2} must \textit{both} be true. Truth table:
	\begin{center}
		\begin{tabular}{c|c|c}
			\(p\) & \(q\) & \(p \land q\) \\
			\hline
			F & F & F \\
			F & T & F \\
			T & F & F \\
			T & T & T
		\end{tabular}
	\end{center}

	\textit{Notice the only row that evaluates to true is when both propositions are true}
\end{defn}

\begin{defn}[Or \(\lor\)]
	Also known as the \textit{disjunction}. Logical connective that evaluates to true when either of the propositions that it connects are true (at least 1 of the connected propositions is true). If both propositions are false, then \textit{or} evaluates to false. \textbf{Note}: if both propositions are true, then \textit{or} still evaluates to true. To remember: either \textit{prop 1} \textbf{or} \textit{prop 2} must be true. Truth table:
	\begin{center}
		\begin{tabular}{c|c|c}
			\(p\) & \(q\) & \(p \lor q\) \\
			\hline
			F & F & F \\
			F & T & T \\
			T & F & T \\
			T & T & T
		\end{tabular}
	\end{center}

	\textit{Notice the only row that evaluates to false is when both propositions are false}
\end{defn}

\begin{defn}[Not \(\lnot\), \(\sim\)]
	Also known as the \textit{negation}. Logical connective that flips the truth value of the proposition to which it is connected. Unlike \textit{and} and \textit{or}, \textit{not} only affects 1 proposition. Truth table:
	\begin{center}
		\begin{tabular}{c|c}
			\(p\) & \(\lnot p\) \\
			\hline
			F & T \\
			T & F \\
		\end{tabular}
	\end{center}
\end{defn}

\begin{defn}[Implication/Conditional \(\Rightarrow\), \(\rightarrow\)]
	Logical connective that reads as an \textit{if-then} statement. The implication must be false if the first proposition is true and the implied (connected/second) proposition is false. Otherwise it is true. Truth table:
	\begin{center}
		\begin{tabular}{c|c|c}
			\(p\) & \(q\) & \(p \Rightarrow q\) \\
			\hline
			F & F & T \\
			F & T & T \\
			T & F & F \\
			T & T & T
		\end{tabular}
	\end{center}
	Note: the direction of an implication can be flipped: \(p \Leftarrow q\) is the same as \(q \Rightarrow p\)
\end{defn}

Let's try to understand the truth table for the implication statement before we continue. We present two examples that attempt to form an intuitive analogy to the implication.

\begin{example}
	Think of the implication as a vending machine. \(p\) is the statement \textit{we put money into the vending machine}, and \(q\) is the statement \textit{we received a snack from the vending machine}. Notice that the statements do not necessarily depend on each other. We examine the four cases and see when we are \textit{unhappy}:

	\begin{enumerate}
		\item \(p\) is \textbf{false} and \(q\) is \textbf{false} -- we did not put in money, and we did not get a snack, so we remain happy (normal operations)
		\item \(p\) is \textbf{false} and \(q\) is \textbf{true} -- we did not put in money, and we did get a snack, so we are very very happy (free snack!)
		\item \(p\) is \textbf{true} and \(q\) is \textbf{false} -- we did put in money, and we did not get a snack, so we are very very unhappy (we got robbed!)
		\item \(p\) is \textbf{true} and \(q\) is \textbf{true} -- we did put in money, and we did get a snack, so we are happy (normal operations)
	\end{enumerate}

	When we are unhappy, then the implication statement is false. Otherwise it is true (we are not \textit{unhappy}).
\end{example}

\begin{example}
	Think of the implication in the lens of a program. You want to evaluate whether your program \textit{makes sense}. Here is the example program from the statement \(p \Rightarrow q\):

	\begin{lstlisting}
	(...)
	if (p is true) {
		<run body code if q is true>
	}
	(...)
	\end{lstlisting}

	The body code is run only if \(q\) is true. Now let's examine the 4 cases and see whether the program makes sense:
	\begin{enumerate}
		\item \(p\) is \textbf{false} and \(q\) is \textbf{false} -- the program does not go into the body of the if-statement and hence makes sense
		\item \(p\) is \textbf{false} and \(q\) is \textbf{true} -- the program again does not go into the body of the if-statement and hence makes sense (regardless of the value of \(q\))
		\item \(p\) is \textbf{true} and \(q\) is \textbf{false} -- the program goes into the body of the if-statement but since \(q\) is false the program does not evaluate the body code. This does not make sense
		\item \(p\) is \textbf{true} and \(q\) is \textbf{true} -- the program goes into the body of the if-statement and evaluates the body code. This makes sense
	\end{enumerate}

	When the code evaluator makes sense, then the implication statement is true.
\end{example}

% todo add the 'promise' example?

\begin{defn}[Bi-conditional \(\Leftrightarrow\), \(\leftrightarrow\)]
	Logical connective that reads as an \textit{if and only if} statement. This means that both propositions must imply each other. For the bi-conditional to be true, both propositions must either be true or false. Truth table:
	\begin{center}
		\begin{tabular}{c|c|c}
			\(p\) & \(q\) & \(p \Leftrightarrow q\) \\
			\hline
			F & F & T \\
			F & T & F \\
			T & F & F \\
			T & T & T
		\end{tabular}
	\end{center}
\end{defn}

Some more complicated ones:

\begin{defn}[Exclusive Or (\textit{Xor}) \(\oplus\)]
	Logical connective that evaluates to true when \textit{only} one of the two propositions that it connects is true. If both propositions are true or false, then \textit{xor} evaluates to false. The exclusive part means we \textit{exclude} the \textit{or} case when both propositions are true. Truth table:
	\begin{center}
		\begin{tabular}{c|c|c}
			\(p\) & \(q\) & \(p \oplus q\) \\
			\hline
			F & F & F \\
			F & T & T \\
			T & F & T \\
			T & T & F
		\end{tabular}
	\end{center}
\end{defn}

\begin{defn}[Exclusive Nor (\textit{Xnor}) \(\otimes\)]
	Logical connective that negates the \textit{xor}. It is just an \textit{xor} connective appended with a \textit{not} connective. Truth table:
	\begin{center}
		\begin{tabular}{c|c|c}
			\(p\) & \(q\) & \(\lnot (p \oplus q) \equiv (p \otimes q)\) \\
			\hline
			F & F & T \\
			F & T & F \\
			T & F & F \\
			T & T & T
		\end{tabular}
	\end{center}
\end{defn}

Now an example:

\exsol{
	Translate the following statement into a propositional logic statement: \textit{exclusively either the weather rains or students wear rain jackets}.
}{
	Let \(r\) be the proposition \textit{the weather rains} and \(j\) be the proposition \textit{students wear rain jackets}. Then the statement becomes \(r \oplus j\)
}

\subsection{Boolean Algebra}

The motivation behind Boolean algebra is that we want to take complicated compound propositional statements and simplify them. If we notice that a variable does not affect the final output, then getting rid of that variable cuts the amount of truth-value possibilities (truth-table rows) in half.

\begin{defn}[Boolean Statement]
	\index{Boolean Statement}
	A statement that is exclusively either true or false
\end{defn}

Some handy notations:

\begin{defn}[Equivalence \(\equiv\)]
	Logical equivalence says that the two connected statements are logically the same. You can think of this notation as the \textit{equals} sign. Equality is poorly defined for Boolean expressions, so we use the equivalence notation instead
\end{defn}

\begin{defn}[Tautology \(t\) \textit{or} \(\mathbf{T}\)]
	A proposition that is always true
\end{defn}

\begin{defn}[Contradiction \(c\) \textit{or} \(\mathbf{F}\)]
	A proposition that is always false
\end{defn}

We provide a handful of helpful theorems to aid in your Boolean algebra simplifications. You do not need to memorize these theorems -- they will be given to you as a table.
\marginpar{See appendix \ref{appendix:tables}}

\begin{thm}[Commutativity]
	For any propositions \(p\) and \(q\) the \textbf{and} and \textbf{or} operations are commutative: \[p \lor q \equiv q \lor p\] \[p \land q \equiv q \land p\]
\end{thm}

\begin{thm}[Associativity]
	For any propositions \(p\), \(q\), and \(r\) the \textbf{and} and \textbf{or} operations are associative: \[(p \lor q) \lor r \equiv p \lor (q \lor r)\] \[(p \land q) \land r \equiv p \land (q \land r)\]
\end{thm}

\begin{thm}[Distributivity]
	For any propositions \(p\), \(q\), and \(r\) the \textbf{and} and \textbf{or} operations are distributive: \[p \land (q \lor r) \equiv (p \land q) \lor (p \land r)\] \[p \lor (q \land r) \equiv (p \lor q) \land (p \lor r)\]
\end{thm}

\begin{thm}[Identity]
	For any proposition \(p\) the following hold: \[p \lor c \equiv p\] \[p \land t \equiv p\]
\end{thm}

\begin{thm}[Negation]
	For any proposition \(p\) the following hold: \[p \lor \lnot p \equiv t\] \[p \land \lnot p \equiv c\]
\end{thm}

\begin{thm}[Double Negation]
	For any proposition \(p\) the following holds: \[\lnot (\lnot p) \equiv p\]
\end{thm}

\begin{thm}[Idempotence]
	For any proposition \(p\) the following hold: \[p \lor p = p\] \[p \land p = p\]
\end{thm}

\begin{thm}[De Morgan's]
	For any propositions \(p\) and \(q\) the following hold: \[\lnot (p \lor q) = \lnot p \land \lnot q\] \[\lnot (p \land q) = \lnot p \lor \lnot q\]
\end{thm}

\begin{thm}[Universal Bound]
	For any proposition \(p\) the following hold: \[p \lor t \equiv t\] \[p \land c \equiv c\]
\end{thm}

\begin{thm}[Absorption]
	For any propositions \(p\) and \(q\) the following hold: \[p \lor (p \land q) \equiv p\] \[p \land (p \lor q) \equiv p\]
\end{thm}

\begin{thm}[Negation of Tautology and Contradiction]
	The following hold: \[\lnot t \equiv c\] \[\lnot c \equiv t\]
\end{thm}

Here are two important theorems that you will use throughout your proofs in this course. The first theorem says that for a bi-conditional both propositions must imply each other. The second theorem gives an equivalence between the implication and \textit{or} connective. The proofs of these theorems are left as an exercise to the reader.

\begin{thm}[Bi-conditional to Implication]
	\label{bicond-to-imp}
	For any propositions \(p\) and \(q\) the following hold: \[p \Leftrightarrow q \equiv (p \Rightarrow q) \land (q \Rightarrow p)\]
\end{thm}

\begin{thm}[Implication to Disjunction]
	\label{imp-to-disj}
	For any propositions \(p\) and \(q\) the following holds: \[p \Rightarrow q \equiv \lnot p \lor q\]
\end{thm}

Now some examples of Boolean statement simplification.

% todo
\exsol{
	Simplify the following expression: \((p \Rightarrow q) \Rightarrow r\)
}{
	\begin{align*}
	(p \Rightarrow q) \Rightarrow r &\equiv \big(\lnot (p \Rightarrow q)\big) \lor r & \text{Implication to Disjunction} \\
	&\equiv \big(\lnot ((\lnot p) \lor q)\big) \lor r & \text{Implication to Disjunction} \\
	&\equiv ((\lnot (\lnot p)) \land (\lnot q)) \lor r & \text{De Morgan's} \\
	&\equiv (p \land (\lnot q)) \lor r & \text{Double Negation}
	\end{align*}
}

Notice how we reference a theorem in each step. This allows us to fully explain our equivalence, keeps us from making mistakes, and ensures our equivalence is valid.

\exsol{
	Simplify the following expression: \((p \otimes q) \land p\)
}{
	\begin{align*}
	(p \otimes q) \land p &\equiv \lnot (p \oplus q) \land p & \text{XNOR equivalence} \\
	&\equiv \lnot \big((p \land (\lnot q)) \lor ((\lnot p) \land q)\big) \land p & \text{XOR equivalence} \\
	&\equiv \big( \lnot (p \land (\lnot q)) \land \lnot ((\lnot p) \land q)\big) \land p & \text{De Morgan's} \\
	&\equiv \big( ((\lnot p) \lor \lnot(\lnot q)) \land (\lnot (\lnot p) \lor (\lnot q))\big) \land p & \text{De Morgan's} \\
	&\equiv \big( ((\lnot p) \lor q) \land (p \lor (\lnot q)) \big) \land p & \text{Double Negation} \\
	%
	&\equiv ((\lnot p) \lor q) \land \big( (p \lor (\lnot q)) \land p \big) & \text{Associativity} \\
	&\equiv ((\lnot p) \lor q) \land \big(p \land (p \lor (\lnot q)) \big) & \text{Commutativity} \\
	&\equiv ((\lnot p) \lor q) \land p & \text{Absorption} \\
	%
	&\equiv p \land ((\lnot p) \lor q) & \text{Commutativity} \\
	&\equiv (p \land (\lnot p)) \lor (p \land q) & \text{Distributivity} \\
	&\equiv c \lor (p \land q) & \text{Negation} \\
	&\equiv p \land q & \text{Identity}
	\end{align*}
}

Note in the preceding example that we used equivalences between the \textit{xnor} to the \textit{xor}, and the \textit{xor} to the \textit{or}. We will discuss later exactly how we deduced these equivalences.

Now that we understand some equivalences, we can motivate some definitions relating to the implication.

\begin{defn}[Converse]
	The converse of \(p \Rightarrow q\) is \(q \Rightarrow p\). Obtain this by reversing the arrow direction.
\end{defn}

\begin{defn}[Inverse]
	The inverse of \(p \Rightarrow q\) is \((\lnot p) \Rightarrow (\lnot q)\). Obtain this by negating both propositions.
\end{defn}

\begin{defn}[Contrapositive]
	The contrapositive of \(p \Rightarrow q\) is \((\lnot q) \Rightarrow (\lnot p)\). Obtain this by reversing the arrow direction, and negating both propositions. Or, take both the converse and inverse.
\end{defn}

\begin{defn}[Negation]
	The negation of \(p \Rightarrow q\) is \(\lnot (p \Rightarrow q)\). Obtain this by negating the entire implication.
\end{defn}

Now we can use our equivalencies to show some important facts about these definitions.

\begin{thm}[Contraposition Equivalence]
	\[p \Rightarrow q \equiv (\lnot q) \Rightarrow (\lnot p)\]
\end{thm}

We leave the proof as an exercise. This theorem will serve us well in our study of Number Theory. The contrapositive indirect proof technique relies on this fact.

\begin{thm}[The Converse Error]
	\[(p \Rightarrow q) \not\Rightarrow (q \Rightarrow p)\]
\end{thm}

\begin{proof}
	We want to show that if you have \(p \Rightarrow q\), then you do not necessarily have \(q \Rightarrow p\). There are many ways to show this, but we will start by simply examining cases of \(p\) and \(q\).

	Consider \(p \equiv \mathbf{F}\) and \(q \equiv \mathbf{T}\). Then
	\(p \Rightarrow q \equiv \mathbf{F} \Rightarrow \mathbf{T} \equiv \mathbf{T}\). But then
	\(q \Rightarrow p \equiv \mathbf{T} \Rightarrow \mathbf{F} \equiv \mathbf{F}\). Then overall we have
	\((p \Rightarrow q) \Rightarrow (q \Rightarrow p) \equiv \mathbf{T} \Rightarrow \mathbf{F} \equiv \mathbf{F}\).
	So we've shown that if you have \(p \Rightarrow q\), then you do not necessarily have \(q \Rightarrow p\).
\end{proof}

\begin{thm}[The Inverse Error]
	\[(p \Rightarrow q) \not\Rightarrow ((\lnot p) \Rightarrow (\lnot q))\]
\end{thm}

\begin{rem}
	A similar proof can be made for this theorem. Find one truth-value pairings for \(p\) and \(q\) such that \(p \Rightarrow q\) is true, but \((\lnot p) \Rightarrow (\lnot q)\) is false.
\end{rem}

\subsection{Circuits} %todo make better

Propositions have two possible values: true and false. If we set true to mean \textit{on} and false to mean \textit{off}, then we can translate our Boolean statements into logical circuits. To do this, think of each logical connective as a \textit{gate}. Similar to the logical connectives, a gate takes 2 (or more) inputs and returns some output. The inputs and outputs are all 1s and 0s (\textit{on}s and \textit{off}s -- true and false). Circuits are the bare-bones to computers, so it is necessary you understand the basics. For computer engineers, you must know circuits by heart.

\begin{defn}[Circuit]
	Representations of Boolean statements into electronic components
\end{defn}

Boolean variables can be exclusively either true or false; this is analogous to electric wires being exclusively either on or off. We let a tautology be equivalent to a \textit{power source}, which is a wire that is always \textbf{on}. Similarly we let a contradiction be equivalent to \textbf{off}, or a wire receiving no power.

The following gates are exactly equivalent to their logic counterparts. We thus only include the gate picture.

\begin{defn}[And Gate -- \textit{conjunction}]
	Picture:

	\begin{center}
		\begin{circuitikz}
			\draw
			(0,0) node[and port] () {};
		\end{circuitikz}
	\end{center}

	To remember the \textit{and} gate, note that the picture looks like a \textbf{D}, which corresponds to the D in AN\textbf{D}
\end{defn}

\begin{defn}[Or Gate -- \textit{Disjunction}]
	Picture:

	\begin{center}
		\begin{circuitikz}
			\draw
			(0,0) node[or port] () {};
		\end{circuitikz}
	\end{center}
\end{defn}

\begin{defn}[Not Gate -- \textit{Negation}]
	Picture:

	\begin{center}
		\begin{circuitikz}
			\draw
			(0,0) node[not port] () {};
		\end{circuitikz}
	\end{center}
\end{defn}

\begin{rem}
	When we have a gate that has a \textit{not} after it, we can simplify the gate by just adding a circle to the output. Example (the \textit{nand} gate is the negation of the \textit{and} gate):

	\begin{multicols}{3}
		\begin{center}
			\begin{circuitikz}
				\draw
				(0,0) node[and port] (and1) {}
				(1,0) node[not port] (not1) {}
				(and1.out) -- (not1.in);
			\end{circuitikz}
		\end{center}
		\begin{center}
			becomes
		\end{center}
		\begin{center}
			\begin{circuitikz}
				\draw
				(0,0) node[nand port] (and1) {};
			\end{circuitikz}
		\end{center}
	\end{multicols}
\end{rem}

\begin{defn}[Xor Gate (\textit{eXclusive Or gate})]
	Picture:

	\begin{center}
		\begin{circuitikz}
			\draw
			(0,0) node[xor port] () {};
		\end{circuitikz}
	\end{center}
\end{defn}

We can think of truth tables in an equivalent fashion, where 1 is true and 0 is false.

\exsol{
	Write the truth table for the \textit{nand} gate.
}{
	\mbox{}

	\begin{center}
		\begin{tabular}{c|c|c}
			\(p\) & \(q\) & \(\lnot (p \land q)\) \\
			\hline
			0 & 0 & 1 \\
			0 & 1 & 1 \\
			1 & 0 & 1 \\
			1 & 1 & 0
		\end{tabular}
	\end{center}
}

You can use 1/0 or T/F, whichever you prefer. If an assignment specifies you use a specific key, then use the one specified. Later when we discuss different number systems, you will notice a correlation between binary numbers and truth tables with 1/0s. This makes it easy to construct a truth table very quickly with a given amount of inputs.

\subsubsection{Circuit Addition}

We can also create circuits that add numbers.
For a discussion of different number bases, see section \ref{diff-num-bases}.

We can build a circuit that adds two single-digit binary numbers? There are only 4 possibilities for adding single-digit numbers, so let's examine what a truth table for this process might look like (all numbers are in base-2):

\begin{center}
	\begin{tabular}{cc|c}
		input \(a\) & input \(b\) & output \(a + b\) \\
		\midrule
		0 & 0 & 0 \\
		0 & 1 & 1 \\
		1 & 0 & 1 \\
		1 & 1 & 10 \\
	\end{tabular}
\end{center}

In the output, we can always append zeros to the beginning of the binary number without changing the actual number:

\begin{center}
	\begin{tabular}{cc|c}
		input \(a\) & input \(b\) & output \(a + b\) \\
		\midrule
		0 & 0 & 00 \\
		0 & 1 & 01 \\
		1 & 0 & 01 \\
		1 & 1 & 10 \\
	\end{tabular}
\end{center}

Now let's separate our output column into two columns -- the sum-bit (right) and the carry-bit (left):

\begin{center}
	\begin{tabular}{cc|cc}
		input \(a\) & input \(b\) & carry & sum \\
		\midrule
		0 & 0 & 0 & 0 \\
		0 & 1 & 0 & 1 \\
		1 & 0 & 0 & 1 \\
		1 & 1 & 1 & 0 \\
	\end{tabular}
\end{center}

We know how to generate Boolean expressions for the output columns:
\begin{align*}
	\text{sum} &\equiv a \oplus b \\
	\text{carry} &\equiv a \land b
\end{align*}

Which gives us the \textbf{half adder}:

\begin{boxx}
	Adding two bits \(a+b = cs\) is equivalent to the circuit
	\begin{center}
		\begin{circuitikz}
			\draw
			(0,0) node (xor1) [xor port] {}
			(0,1.5) node (and1) [and port] {}
			(and1.in 1) node (a) [anchor=east,xshift=-1cm] {\(a\)}
			(xor1.in 2) node (b) [anchor=east,xshift=-1cm] {\(b\)};

			\draw (and1.in 1) -- (a);
			\draw (and1.in 2) -- (b);
			\draw (xor1.in 1) -- (a);
			\draw (xor1.in 2) -- (b);

			\draw
			(and1.out) node (c) [anchor=west,xshift=1cm] {carry}
			(xor1.out) node (s) [anchor=west,xshift=1cm] {sum};

			\draw (and1.out) -- (c);
			\draw (xor1.out) -- (s);

			\node [xshift=.2cm] at (a) {\textbullet};
			\node [xshift=.2cm] at (b) {\textbullet};
			\node [xshift=-.5cm] at (c) {\textbullet};
			\node [xshift=-.5cm] at (s) {\textbullet};
		\end{circuitikz}
	\end{center}
\end{boxx}

Now we can add two 1-bit numbers together. What if we want to add multiple-bit numbers together? Consider adding two 2-bit numbers:
\begin{center}
	\begin{tabular}{ccc}
		& \(c\) & \\
		& \(x\) & \(y\) \\
		\(+\) & \(z\) & \(w\) \\
		\midrule
		\(o_2\) & \(o_1\) & \(s\)
	\end{tabular}
\end{center}

We see here that after adding \(y+w\) we are left with a carry bit \(c\) for our addition \(x+z\). How do we add three bits \(c+x+z\)? Well, we can separate it into two 1-bit additions: \(c+x\) which, via a half-adder, yields a sum bit \(s_1\) and carry bit \(c_1\), then \(s_1 + z\) which, via another half-adder, yields a sum bit \(s_2\) and carry bit \(c_2\). Then, we can let \(o_1 = s_2\). Unfortunately this leaves us two carry bits that somehow need to be combined into a final carry bit.

Consider now the truth-table for adding three bits:
\begin{center}
	\begin{tabular}{ccc|c|ccc}
		\(c\) & \(x\) & \(z\) & \(c+x+z\) & carry\((c+x)\)  & sum\((c+x) = s_1\) & carry\((s_1+z)\) \\
		\midrule
		0 & 0 & 0 & 00 & 0 & 0 & 0 \\
		0 & 0 & 1 & 01 & 0 & 0 & 0 \\
		0 & 1 & 0 & 01 & 0 & 1 & 0 \\
		0 & 1 & 1 & 10 & 0 & 1 & 1 \\
		1 & 0 & 0 & 01 & 0 & 1 & 0 \\
		1 & 0 & 1 & 10 & 0 & 1 & 1 \\
		1 & 1 & 0 & 10 & 1 & 0 & 0 \\
		1 & 1 & 1 & 11 & 1 & 0 & 0 \\
	\end{tabular}
\end{center}

Now notice the carry bit in the output column \(c+x+z\) is the same as OR-ing the two carry bits from \(c+x\) and \(s_1+z\). This completes our circuit for adding three bits. We call this the \textbf{full adder}:

\begin{boxx}
	Adding three bits \(a+b+c = os\) is equivalent to the circuit
	\begin{center}
		\begin{circuitikz}
			\draw
			(0,0.75) node[draw,minimum width=2cm,minimum height=1cm] (HA1) {Half Adder}
			(3.5,0) node[draw,minimum width=2cm,minimum height=1cm] (HA2) {Half Adder}
			($(HA1.west)!0.75!(HA1.north west)$) coordinate (ha1in1)
			($(HA1.west)!0.75!(HA1.south west)$) coordinate (ha1in2);
			\draw
			(ha1in1) node (a) [anchor=east,xshift=-0.5cm] {\(a\)}
			(ha1in2) node (b) [anchor=east,xshift=-0.5cm] {\(b\)}
			(ha1in1) -- (a)
			(ha1in2) -- (b);
			\node [xshift=.2cm] at (a) {\textbullet};
			\node [xshift=.2cm] at (b) {\textbullet};

			\draw
			($(HA1.east)!0.75!(HA1.north east)$) coordinate (ha1out1)
			($(HA1.east)!0.75!(HA1.south east)$) coordinate (ha1out2);
			\draw
			(ha1out1) node (c1) [anchor=west,xshift=4cm] {c\(_1\)}
			(ha1out2) node (s1) [anchor=west,xshift=0.35cm] {sum}
			(ha1out1) -- (c1)
			(ha1out2) -- (s1);
			%\node [xshift=-.2cm] at (c1) {\textbullet};

			\draw
			($(HA2.west)!0.75!(HA2.north west)$) coordinate (ha2in1)
			($(HA2.west)!0.75!(HA2.south west)$) coordinate (ha2in2);
			\draw
			(s1) -- (ha2in1)
			(ha2in2) node (c) [anchor=east,xshift=-4cm] {\(c\)}
			(ha2in2) -- (c);
			\node [xshift=.2cm] at (c) {\textbullet};

			\draw
			($(HA2.east)!0.75!(HA2.north east)$) coordinate (ha2out1)
			($(HA2.east)!0.75!(HA2.south east)$) coordinate (ha2out2);
			\draw
			(ha2out1) node (c2) [anchor=west,xshift=0.5cm] {c\(_2\)}
			(ha2out2) node (s) [anchor=west,xshift=2.65cm] {\(s\)}
			(ha2out1) -- (c2)
			(ha2out2) -- (s);
			\node [xshift=-.2cm] at (s) {\textbullet};

			\draw
			(7,0.75) node (or1) [or port] {}
			(or1.in 1) -- (c1)
			(or1.in 2) -- (c2)
			(or1.out) node (o) [anchor=west] {\(o\)};
			\node [xshift=-.2cm] at (o) {\textbullet};
		\end{circuitikz}
	\end{center}
\end{boxx}

Putting these two structures, the half adder and full adder, together, we can construct a 2-bit adder, which solves our previous problem of doing \(xy + zw = o_2o_1s\):

\begin{boxx}
	Adding three bits \(a+b+c = os\) is equivalent to the circuit
	\begin{center}
		\begin{circuitikz}
			\draw
			(0,0.75) node[draw,minimum width=2cm,minimum height=1cm] (HA1) {Half Adder}
			(3.75,-0.2) node[draw,minimum width=2cm,minimum height=1.5cm] (FA1) {Full Adder}
			($(HA1.west)!0.75!(HA1.north west)$) coordinate (ha1in1)
			($(HA1.west)!0.75!(HA1.south west)$) coordinate (ha1in2);
			\draw
			(ha1in1) node (y) [anchor=east,xshift=-0.5cm] {\(y\)}
			(ha1in2) node (w) [anchor=east,xshift=-0.5cm] {\(w\)}
			(ha1in1) -- (y)
			(ha1in2) -- (w);
			\node [xshift=.2cm] at (y) {\textbullet};
			\node [xshift=.2cm] at (w) {\textbullet};

			\draw
			($(HA1.east)!0.75!(HA1.north east)$) coordinate (ha1out1)
			($(HA1.east)!0.75!(HA1.south east)$) coordinate (ha1out2);
			\draw
			(ha1out1) node (s) [anchor=west,xshift=4.5cm] {\(s\)}
			(ha1out2) node (c1) [anchor=west,xshift=0.35cm] {carry}
			(ha1out1) -- (s)
			(ha1out2) -- (c1);
			\node [xshift=-.2cm] at (s) {\textbullet};

			\draw
			($(FA1.west)!0.75!(FA1.north west)$) coordinate (fa1in1)
			($(FA1.west)!0.75!(FA1.south west)$) coordinate (fa1in2)
			($(FA1.west)!0!(FA1.south west)$) coordinate (fa1in3);
			\draw
			(c1) -- (fa1in1)
			(fa1in2) node (x) [anchor=east,xshift=-4.25cm] {\(x\)}
			(fa1in2) -- (x)
			(fa1in3) node (z) [anchor=east,xshift=-4.25cm] {\(z\)}
			(fa1in3) -- (z);
			\node [xshift=.2cm] at (x) {\textbullet};
			\node [xshift=.2cm] at (z) {\textbullet};

			\draw
			($(FA1.east)!0.75!(FA1.north east)$) coordinate (fa1out1)
			($(FA1.east)!0.75!(FA1.south east)$) coordinate (fa1out2);
			\draw
			(fa1out1) node (o1) [anchor=west,xshift=0.75cm] { \(o_1\)}
			(fa1out2) node (o2) [anchor=west,xshift=0.75cm] { \(o_2\)}
			(fa1out1) -- (o1)
			(fa1out2) -- (o2);
			\node [xshift=-.3cm] at (o1) {\textbullet};
			\node [xshift=-.3cm] at (o2) {\textbullet};
		\end{circuitikz}
	\end{center}
\end{boxx}

This solves our 2-bit addition problem. What if we want to add 3-bit numbers? 4-bit numbers? \(n\)-bit numbers? Well, after the first bit column (adding two bits) we must add three bits. After this second column, we get a sum bit and a carry bit. If we tack on another column, which would make a 3-bit adder, then we add in the previous carry to the two new bits. This same process repeats for all further columns. So, tacking on another bit solely entails tacking on another full adder! \textit{Picture omitted}.

\exsol{
	How many half adders are required for an \(n\)-bit adder?
}{
	Note, here we implicitly assumed \(n > 0\).

	We need 1 half adder to start, and we need \(n-1\) full adders which each contain 2 half adders. This totals to \(2(n-1) + 1 = 2n-1\) half adders.
}

\subsection{Translations}

You must know how to translate between circuits, Boolean statements, and truth tables.

We start by motivating the translation between truth tables and Boolean statements. First, notice that we have already discussed how to make a truth table from a Boolean statement -- simply draw the truth table and fill in each row. Now we can focus on the reverse.

We attempt to first motivate a process for this translation by showing a few examples.

\begin{example}
	First recall the truth table for the conjunction:

	\begin{center}
		\begin{tabular}{cc|c}
			\(p\) & \(q\) & \(p \land q\) \\
			\hline
			F & F & F \\
			F & T & F \\
			T & F & F \\
			T & T & T
		\end{tabular}
	\end{center}

	Recall that we can extend the conjunction to take multiple inputs -- in this case, \textit{each} input \textit{must} be \textbf{True} for the output to be \textbf{True}.

	Now consider the following unknown table:

	\begin{center}
		\begin{tabular}{cc|c}
			\(p\) & \(q\) & unknown \\
			\hline
			F & F & F \\
			F & T & T \\
			T & F & F \\
			T & T & F
		\end{tabular}
	\end{center}

	This table is similar to the conjunction table in that it has \textit{one row} that outputs \textbf{True}. In the conjunction case, the assignments to \(p\) and \(q\) were both \textbf{True}. What are the assignments to the previous truth table? Well, the \(p\) input is \textbf{False} and the \(q\) input is \textbf{True}, as per the table. If we apply the conjunction to this row we have, we get the following table:

	\begin{center}
		\begin{tabular}{c|c|c|c}
			\(p\) & \(\lnot p\) & \(q\) & \((\lnot p) \land q\) \\
			\hline
			F & T & F & F \\
			F & T & T & T \\
			T & F & F & F \\
			T & F & T & F
		\end{tabular}
	\end{center}

	In the previous table, if we look at the middle two columns, we recover the conjunction with the \(p\) variable negated.
\end{example}

This is only half the story though.

\begin{example}
	First recall the truth table for the disjunction:

	\begin{center}
		\begin{tabular}{cc|c}
			\(p\) & \(q\) & \(p \lor q\) \\
			\hline
			F & F & F \\
			F & T & T \\
			T & F & T \\
			T & T & T
		\end{tabular}
	\end{center}

	For this example, we only care about the middle two rows where \textit{either} variable is \textbf{True}.

\end{example}

These bring light to a simple 3-step process to translate from truth tables to Boolean statements:

\begin{enumerate}
	\item Collect the rows whose \textit{output} is \textbf{True}
	\item For each of those rows
	\begin{enumerate}
		\item Look at the truth value assigned to the \textit{input}
		\item Construct a Boolean statement where, for each input
		\begin{itemize}
			\item If the assignment is \textbf{True} then use the variable itself
			\item If the assignment is \textbf{False} then use the \textit{negation} of the variable
		\end{itemize}
		\item Chain each input with \textbf{And} (\(\land\)) connectives
	\end{enumerate}
	\item Chain each row's statement with \textbf{Or} (\(\lor\)) connectives
\end{enumerate}

\exsol{
	Find the unknown Boolean formula corresponding to the following truth table:

	\begin{center}
		\begin{tabular}{cc|c}
			\(p\) & \(q\) & unknown \\
			\hline
			F & F & T \\
			F & T & F \\
			T & F & T \\
			T & T & F
		\end{tabular}
	\end{center}
}{
	We follow the algorithm as before. The first and third rows return true in the output. In the first row, we see neither input is true, so we AND the negation of each input: \((\lnot p) \land (\lnot q)\). In the third row, we see the first input is true, while the second input is false, thus we get: \(p \land (\lnot q)\). OR-ing each statement together thus yields our unknown formula: \[((\lnot p) \land (\lnot q)) \lor (p \land (\lnot q))\]
}

\begin{rem}
	In our Boolean formula algorithm, we only focus on the true rows. If we wanted to also include the false rows, then we would need the statement in each false row to return false. We know how to get a statement that returns true, so we can simply take that statement and negate it! What happens, though, if we include the false rows then?
\end{rem}

\exsol{
	Include the false rows in the Boolean formula from the previous example.
}{
	We negate the second and fourth row returned by the algorithm: \(\lnot ((\lnot p) \land q)\) and \(\lnot (p \land q)\)

	So our entire statement is now \[((\lnot p) \land (\lnot q)) \lor (p \land (\lnot q)) \lor (\lnot ((\lnot p) \land q)) \lor (\lnot (p \land q))\]

	Let's simplify this statement (rules omitted):
	\begin{align*}
	&\equiv ((\lnot p) \land (\lnot q)) \lor (p \land (\lnot q)) \lor (\lnot ((\lnot p) \land q)) \lor (\lnot (p \land q)) \\
	&\equiv ((\lnot p) \land (\lnot q)) \lor (p \land (\lnot q)) \lor (p \lor (\lnot q)) \lor ((\lnot p) \lor q) \\
	&\equiv ((\lnot p) \land (\lnot q)) \lor (p \land (\lnot q)) \lor (p \lor (\lnot p)) \lor ((\lnot q) \lor q) \\
	&\equiv ((\lnot p) \land (\lnot q)) \lor (p \land (\lnot q)) \lor t \lor t \\
	&\equiv ((\lnot p) \land (\lnot q)) \lor (p \land (\lnot q))
	\end{align*}

	Nice, we have recovered the original statement!
}

\begin{rem}
	Including each false row in the Boolean statement generated by the algorithm -- so long as their true versions are negated -- does not logically change the Boolean statement
\end{rem}

We have a name for the type of statement generated from our algorithm above:

\begin{defn}[Disjunctive Normal Form\index{Disjunctive Normal Form}]
	Describes a Boolean statement that is a conjunction of disjunctions -- abbreviated DNF
\end{defn}

If we flip each gate (AND goes to OR, OR goes to AND), then we get another important type of statement:

\begin{defn}[Conjunctive Normal Form\index{Conjunctive Normal Form}]
	Describes a Boolean statement that is a disjunction of conjunctions -- abbreviated CNF
\end{defn}

Interestingly, any Boolean statement can be translated to an equivalent statement in CNF. Namely, statements in DNF, which are easy to generate, can be translated into CNF. This is important for computational complexity theory -- specifically NP-completeness. There exists a problem in computer science which entails finding a set of truth-value assignments for \(n\) different Boolean variables which makes a Boolean statement in CNF return true (or, become \textit{satisfiable}).

\subsection{Reasoning/Deductions}
\label{section:reasoning}

Propositional logic also allows us to \textit{reason} about things.

\begin{defn}[Knowledge Base]
	A group of information that you know is true
\end{defn}

\begin{defn}[Reasoning]
	The process of deriving new information from a given knowledge base
\end{defn}

See the introduction of this chapter for an example.

\subsubsection{Classical Rules of Deduction}

We may refer to \textit{deductions} as \textit{inferences}. They are the same.

\begin{defn}[Deductions]
	Using previously-known knowledge in your knowledge base to obtain/create new knowledge
\end{defn}

We have a whole list of useful deductions that are provably valid. As with our Boolean algebra theorems, you do not need to memorize these theorems -- they will be given to you as a table.

\begin{thm}[Modus Ponens]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(p\) \\
			& \(p \Rightarrow q\) \\
			\cline{2-2}
			\(\therefore\) & \(q\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Modus Tollens]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(\lnot q\) \\
			& \(p \Rightarrow q\) \\
			\cline{2-2}
			\(\therefore\) & \(\lnot p\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Disjunctive Addition]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(p\) \\
			\cline{2-2}
			\(\therefore\) & \(p \lor q\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Conjunctive Addition]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(p,q\) \\
			\cline{2-2}
			\(\therefore\) & \(p \land q\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Conjunctive Simplification]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(p \land q\) \\
			\cline{2-2}
			\(\therefore\) & \(p,q\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Disjunctive Syllogism]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(p \lor q\) \\
			& \(\lnot p\) \\
			\cline{2-2}
			\(\therefore\) & \(q\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Hypothetical Syllogism]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(p \Rightarrow q\) \\
			& \(q \Rightarrow r\) \\
			\cline{2-2}
			\(\therefore\) & \(p \Rightarrow r\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Resolution]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(p \lor q\) \\
			& \((\lnot q) \lor r\) \\
			\cline{2-2}
			\(\therefore\) & \(p \lor r\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Division Into Cases]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(p \lor q\) \\
			& \(p \Rightarrow r\) \\
			& \(q \Rightarrow r\) \\
			\cline{2-2}
			\(\therefore\) & \(r\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Law of Contradiction]
	\mbox{}
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \((\lnot p) \Rightarrow \mathbf{c}\) \\
			\cline{2-2}
			\(\therefore\) & \(p\)
		\end{tabular}
	\end{center}
\end{thm}

You may be wondering how to prove these deductions are \textit{valid}. We have two equivalent methods:
\begin{enumerate}
	\item Tautological implication
	\item Critical-row identification
\end{enumerate}

Consider an arbitrary deduction:
\begin{center}
	\begin{tabular}{c@{\,}l@{}}
		& \(P_1\) \\
		& \(P_2\) \\
		& \(\cdots \cdots \cdots\) \\
		& \(P_n\) \\
		\cline{2-2}
		\(\therefore\) & \(Q\)
	\end{tabular}
\end{center}

To prove it valid,

\textbf{Tautological implication}
\begin{enumerate}
	\item Construct a new proposition \(A \Rightarrow B\) where \(A\) is a \textbf{conjunction of the premises} and \(B\) is the conclusion. For our arbitrary deduction, we would have \[\big( P_1 \land P_2 \land \cdots \land P_n \big) \Rightarrow Q\]
	\item Inspect this proposition in a truth-table. If the proposition is a tautology, then the deduction is valid. Otherwise, the deduction is invalid. So, to be valid we must have \[(A \Rightarrow B) \equiv \big( P_1 \land P_2 \land \cdots \land P_n \big) \Rightarrow Q \equiv t\]
\end{enumerate}

\textbf{Critical-row identification}
\begin{enumerate}
	\item Construct a truth-table with columns for each proposition and for the conclusion. \textit{You may need extra columns, that is fine}. For our arbitrary deduction, we would have
	\begin{center}
		\begin{tabular}{cccc|c}
			\(P_1\) & \(P_2\) & \(\cdots\) & \(P_n\) & \(Q\) \\
			\midrule
			F/T & F/T & \(\cdots\) & F/T & F/T \\
			&& \(\vdots\) && \\
			T/T & F/T & \(\cdots\) & F/T & F/T \\
		\end{tabular}
	\end{center}
	\item Identify the rows in which each \textbf{premise} is true. We call these rows \textbf{critical-rows}.
	\item For each critical-row, inspect the conclusion. If the conclusion is true in \textbf{every} critical-row, then the deduction is valid. Otherwise, the deduction is invalid.
\end{enumerate}

Examples following the above steps.

\exsol{
	Show that Modus Ponens is a valid rule of inference.
}{
	\textit{method 1 -- tautological implication}

	Our proposition we care about is \((p \land (p \Rightarrow q)) \Rightarrow q\), so we build the following truth-table with extraneous rows:
	\begin{center}
		\begin{tabular}{cc|cc|cc|c}
			\(p\) & \(q\) & \(p\) & \(p \Rightarrow q\) & \(p \land (p \Rightarrow q)\) & \(q\) & \((p \land (p \Rightarrow q)) \Rightarrow q\) \\
			\midrule
			F & F & F & T & F & F & T \\
			F & T & F & T & F & T & T \\
			T & F & T & F & F & F & T \\
			T & T & T & T & T & T & T \\
		\end{tabular}
	\end{center}

	Inspect the last column.
	\begin{center}
		\begin{tabular}{cc|cc|cc|c}
			\(p\) & \(q\) & \(p\) & \(p \Rightarrow q\) & \(p \land (p \Rightarrow q)\) & \(q\) & \((p \land (p \Rightarrow q)) \Rightarrow q\) \\
			\midrule
			F & F & F & T & F & F & \cellcolor{Melon}\color{green} \textbf{T} \\
			F & T & F & T & F & T & \cellcolor{Melon}\color{green} \textbf{T} \\
			T & F & T & F & F & F & \cellcolor{Melon}\color{green} \textbf{T} \\
			T & T & T & T & T & T & \cellcolor{Melon}\color{green} \textbf{T} \\
		\end{tabular}
	\end{center}

	In the case of Modus Ponens, the final column is a tautology, hence the deduction is valid.
}

\exsol{
	Show that Modus Ponens is a valid rule of inference.
}{
	\textit{method 2 -- critical-row identification}

	Construct a truth table with each premise and conclusion:
	\begin{center}
		\begin{tabular}{cc|cc|c}
			\(p\) & \(q\) & \(p\) & \(p \Rightarrow q\) & \(q\) \\
			\midrule
			F & F & F & T & F \\
			F & T & F & T & T \\
			T & F & T & F & F \\
			T & T & T & T & T \\
		\end{tabular}
	\end{center}

	Identify the critical-rows.
	\begin{center}
		\begin{tabular}{cc|cc|c}
			\(p\) & \(q\) & \(p\) & \(p \Rightarrow q\) & \(q\) \\
			\midrule
			F & F & F & T & F \\
			F & T & F & T & T \\
			T & F & T & F & F \\
			\rowcolor{Melon}
			T & T & \textbf{T} & \textbf{T} & T \\
		\end{tabular}
	\end{center}

	Inspect the conclusion in each critical-row.
	\begin{center}
		\begin{tabular}{cc|cc|c}
			\(p\) & \(q\) & \(p\) & \(p \Rightarrow q\) & \(q\) \\
			\midrule
			F & F & F & T & F \\
			F & T & F & T & T \\
			T & F & T & F & F \\
			\rowcolor{Melon}
			T & T & \textbf{T} & \textbf{T} & \textbf{\color{green} T} \\
		\end{tabular}
	\end{center}

	In the case of Modus Ponens, the conclusion is true in each critical row, hence the deduction is valid.
}

We leave it to the reader to understand why the two methods are equivalent.

\subsubsection{Deducing Things}

In a later section, we will see that this order of logic is not powerful enough to prove mathematical statements. For now, we can still do interesting things with a given knowledge base.

\exsol{
	Given the following knowledge base, deduce as much new information as possible using the following rules of inference: Modus Ponens, Modus Tollens, Hypothetical Syllogism, and Disjunctive Syllogism.

	\begin{center}
		\hfill \(a \Rightarrow b\) \hfill \(b \Rightarrow (\lnot d)\) \hfill \(e\) \hfill \(d \lor (\lnot e)\) \hfill \mbox{}
	\end{center}
}{
\\
	By Hypothetical Syllogism \(a \Rightarrow b\), \(b \Rightarrow (\lnot d)\), \hfill \(\therefore a \Rightarrow (\lnot d)\)

	By Disjunctive Syllogism \(d \lor (\lnot e)\), \(e\), \hfill \(\therefore d\)

	By Modus Tollens \(d\), \(a \Rightarrow (\lnot d)\), \hfill \(\therefore \lnot a\)

	By Modus Tollens \(d\), \(b \Rightarrow (\lnot d)\), \hfill \(\therefore \lnot b\)

	% todo is this finished?
}

\begin{rem}
	From the above example, we restricted the rules you could have used. We did this mainly because Disjunctive Addition can allow you to generate any new knowledge you like -- so long as you have one thing that is true, then you can add in a disjunction infinitely-many times.
\end{rem}

\begin{rem}
	In the above example, we could have translated \(d \lor (\lnot e) \equiv e \Rightarrow d\) and concluded \(d\) by Modus Ponens. This somewhat tells you that Disjunctive Syllogism and Modus Ponens are equivalent.
\end{rem}

\begin{rem}
	From an inconsistent database, anything follows.

	This is due to the law of contradiction. An \textit{inconsistent database} is one that contains a contradiction. Recall from the law of contradiction that \((\lnot p) \Rightarrow c \equiv (\lnot (\lnot p)) \lor c \equiv p\) using the Identity Boolean algebra theorem. Using Disjunctive Addition, we have the contradiction \(c\), \(\therefore A \lor c\), and by Identity, \(\therefore A\). \(A\) can be \textit{Anything}.
\end{rem}

In Artificial Intelligence, there exists an algorithm called \textbf{The Resolution Algorithm}. Essentially, it says to take a given knowledge base, translate each statement into disjunctive normal form, then apply the Resolution rule of inference as many times as possible.

\section{Predicate Logic}

Sometimes basic propositions are not enough to do what you want. In programming we can have functions that return true or false. We can do the same thing with logic -- we call this \textit{first-order} logic, or \textit{predicate} logic. Predicate logic includes all of propositional logic, however it adds predicates and quantifiers.

\begin{defn}[Predicate\index{Predicate}]
	A property that the subject of a statement can have. In logic, we represent this sort-of like a function. A predicate takes, as input, some element, and returns whether the inputted element has the specific property.
\end{defn}

\begin{example}
	We could use the predicate \(EVEN(x)\) to mean \(x\) is an even number. In this case, the predicate is \(EVEN(\cdot)\)
\end{example}

\begin{example}
	We could use the predicate \(P(y)\) to mean \(y\) is an integer multiple of 3. In this case, the predicate is \(P(\cdot)\)
\end{example}

\begin{rem}
	Predicates take \textbf{elements}. They do \textbf{not} take in other predicates. This is because predicates say whether the input element \textit{has} the property specified by the predicate -- true and false cannot have properties.

	In terms of programming, you can think of a predicate as a program method. For example, the \(EVEN(x)\) predicate might be implemented as follows:

	\begin{lstlisting}
func EVEN(Entity x) -> bool {
	if IS_INTEGER(x) {
		return x % 2 == 0
	}
	return false
}
	\end{lstlisting}

	In this case, entities are \textit{objects} and true/false are \textit{Boolean primitives} (or, propositional statements, which can only be true or false). In contrast to, say, Java, a compiler for this code would not allow \textit{true/false} to be an object.

	A better example,

	\begin{lstlisting}
class Foo extends Entity {
	bool isInteger
	bool isOdd

	Foo(Integer i) {
		this.isInteger = true
		this.isOdd = i % 2 == 1
	}
}

func ODD(Entity x) -> bool {
	if x has type Foo {
		return x.isOdd
	}
	if IS_INTEGER(x) {
		return x % 2 == 1
	}
	return false
}
	\end{lstlisting}
\end{rem}

\begin{defn}[Quantifier\index{Quantifier}]
	A way to select a specific range of elements that get inputted to a predicate. We have two quantifiers:

	\begin{itemize}
		\item The Universal quantifier \(\forall\)
		\item The Existential quantifier \(\exists\)
	\end{itemize}

	The universal quantifier says to select \textbf{all} elements, and the existential quantifier says to select \textbf{at least one} element.
\end{defn}

\begin{defn}[Quantified Statement]
	A logical statement involving predicates and quantifiers. Syntax: \[(\text{quantifier } var \in D)[\text{statement involving predicates}]\]
\end{defn}

And now we can define:

\begin{defn}[Predicate Logic]
	Also called \textit{first-order logic}, is a logic made up of quantified statements.
\end{defn}

\exsol{
	Translate the following statements to predicate logic:
	\begin{enumerate}
		\item All people are mortal
		\item Even integers exist
		\item If an integer is prime then it is not even
	\end{enumerate}
}{
	\begin{enumerate}
		\item Denote \(P\) as the domain of people, and the predicate \(M(x)\) to mean \(x\) is mortal. Then the statement translates to \[(\forall p \in P)[M(p)]\]
		\item Denote \(\Z\) as the domain of integers, and the predicate \(EVEN(x)\) to mean \(x\) is even. Then the statement translates to \[(\exists x \in \Z)[EVEN(x)]\]
		\item Denote the predicate \(PRIME(y)\) to mean \(y\) is prime. Then the statement translates to \[(\forall a \in \Z)[PRIME(a) \Rightarrow \lnot EVEN(a)]\]
	\end{enumerate}
}

\subsection{Negating Quantified Statements}

One may find useful to negate a given quantified statement. We present here how to do this, first with an English example, followed by a quantified example, followed by an algorithm.

\begin{example}
	The following statement
	\begin{center}
		\textit{There is no student who has taken calculus.}
	\end{center}
	is equivalent to
	\begin{center}
		\textit{All students have not taken calculus.}
	\end{center}
\end{example}

\begin{example}
	The following statement
	\begin{center}
		\textit{Not all students have taken calculus.}
	\end{center}
	is equivalent to
	\begin{center}
		\textit{There is a student who has not taken calculus.}
	\end{center}
\end{example}

\begin{example}
	The following statement \[\lnot(\exists x \in D)[C(x)]\] is equivalent to \[(\forall x \in D)[\lnot C(x)]\]
\end{example}

\begin{example}
	The following statement \[\lnot(\forall x \in D)[C(x)]\] is equivalent to \[(\exists x \in D)[\lnot C(x)]\]
\end{example}

The generic algorithm for pushing the negation into a quantified statement:

\begin{enumerate}
	\item Flip each quantifier \(\forall \rightarrow \exists\) and \(\exists \rightarrow \forall\)
	\item Apply the negation to the propositional part of the quantified statement, and simplify
	\begin{enumerate}
		\item If the inside contains another quantified statement, then recursively apply this algorithm
	\end{enumerate}
\end{enumerate}

\begin{rem}
	The domain and variable attached to any quantifier are \textbf{not} changed.
\end{rem}

\exsol{
	Push the negation in as far as possible: \[\lnot (\forall x,y \in \Z)[(x < y) \Rightarrow (\exists m \in \Q)[x < m < y]]\]
}{
	\begin{align*}
	& \lnot (\forall x,y \in \Z)[(x < y) \Rightarrow (\exists m \in \Q)[x < m < y]] \\
	\equiv & (\exists x,y \in \Z) \lnot [(x < y) \Rightarrow (\exists m \in \Q)[x < m < y]] \\
	\equiv & (\exists x,y \in \Z) \lnot [\lnot (x < y) \lor (\exists m \in \Q)[x < m < y]] \\
	\equiv & (\exists x,y \in \Z) [\lnot \lnot (x < y) \land \lnot (\exists m \in \Q)[x < m < y]] \\
	\equiv & (\exists x,y \in \Z) [(x < y) \land (\forall m \in \Q) \lnot [x < m < y]] \\
	\equiv & (\exists x,y \in \Z) [(x < y) \land (\forall m \in \Q) \lnot [x < m \land m < y]] \\
	\equiv & (\exists x,y \in \Z) [(x < y) \land (\forall m \in \Q) [x \geq m \lor m \geq y]]
	\end{align*}
}

\begin{rem}
	We typically expect the final statement to contain no \(\lnot\) operators.
\end{rem}

\subsection{Quantified Rules of Inference}

Again, \textit{deductions} and \textit{inferences} are the same. We present a handful of important \textit{quantified} rules of inference.

\begin{thm}[Universal Instantiation]
	For a predicate \(P(\cdot)\) and some domain \(D\) with \(c \in D\),
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \((\forall x \in D)[P(x)]\) \\
			\cline{2-2}
			\(\therefore\) & \(P(c)\)
		\end{tabular}
	\end{center}

	As an example, if our domain consists of all dogs and Fido is a dog, then the above rule can be read as
	\begin{center}
		``All dogs are cuddly''

		``Therefore Fido is cuddly''
	\end{center}
\end{thm}

\begin{thm}[Universal Generalization]
	For a predicate \(P(\cdot)\) and some domain \(D\) for an arbitrary \(c \in D\),
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(P(c)\) \\
			\cline{2-2}
			\(\therefore\) & \((\forall x \in D)[P(x)]\)
		\end{tabular}
	\end{center}

	This is most-often used in mathematics. As an example, if our domain consists of all dogs, then the above rule can be read as
	\begin{center}
		``An arbitrary dog is cuddly'' (which in-turn applies to all dogs)

		``Therefore all dogs are cuddly''
	\end{center}
\end{thm}

\begin{thm}[Existential Instantiation]
	For a predicate \(P(\cdot)\) and some domain \(D\) for some element \(c \in D\),
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \((\exists x \in D)[P(x)]\) \\
			\cline{2-2}
			\(\therefore\) & \(P(c)\)
		\end{tabular}
	\end{center}

	As an example, if our domain consists of all dogs, then the above rule can be read as
	\begin{center}
		``There is a dog who is cuddly''

		``Let's call that dog \(c\), and so \(c\) is cuddly''
	\end{center}
\end{thm}

\begin{thm}[Existential Generalization]
	For a predicate \(P(\cdot)\) and some domain \(D\) for some element \(c \in D\),
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(P(c)\) \\
			\cline{2-2}
			\(\therefore\) & \((\exists x \in D)[P(x)]\)
		\end{tabular}
	\end{center}

	As an example, if our domain consists of all dogs and Fido is a dog, then the above rule can be read as
	\begin{center}
		``Fido is cuddly''

		``Therefore there is a dog who is cuddly''
	\end{center}
\end{thm}

\begin{thm}[Universal Modus Ponens]
	For two predicates \(P(\cdot)\) and \(Q(\cdot)\), and some domain \(D\) with \(a \in D\),
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(P(a)\) \\
			& \((\forall x \in D)[P(x) \Rightarrow Q(x)]\) \\
			\cline{2-2}
			\(\therefore\) & \(Q(a)\)
		\end{tabular}
	\end{center}
\end{thm}

\begin{thm}[Universal Modus Tollens]
	For two predicates \(P(\cdot)\) and \(Q(\cdot)\), and some domain \(D\) with \(a \in D\),
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \(\lnot Q(a)\) \\
			& \((\forall x \in D)[P(x) \Rightarrow Q(x)]\) \\
			\cline{2-2}
			\(\therefore\) & \(\lnot P(a)\)
		\end{tabular}
	\end{center}
\end{thm}

\subsection{Proving Things}

Our familiar rules of inference are not strong enough to prove abstract mathematical statements. Typically we want our proof to apply to a whole \textit{set} of things (numbers). Now that we know about \textit{predicate logic}, we can apply our more powerful \textit{quantified} rules of inference to prove real mathematical statements.

\exsol{
	Using Universal Modus Ponens, verify the validity of the following proof:
	\begin{proof}
		Let \(m,n \in \Z\), and let \(m\) be even. Then \(m = 2p\) for some integer \(p\).\textsuperscript{\color{blue} (1)} Now,
		\begin{align*}
		m \cdot n &= (2p)n & \text{by substitution} \\
		&= 2(pn)^{\text{\color{blue} (2)}} & \text{by associativity}
		\end{align*}

		Now, \(pn \in \Z\),\textsuperscript{\color{blue} (3)} so by definition of even \(2(pn)\) is even.\textsuperscript{\color{blue} (4)} Thus \(mn\) is even.
	\end{proof}
}{
	\\
	\makebox[4mm]{\color{blue} (1)} \makebox[6mm]{} If an integer is even, then it equals twice some integer.\\
	\makebox[4mm]{} \makebox[6mm]{} \(m\) is a particular integer, and it is even.\\
	\makebox[4mm]{} \makebox[6mm]{\(\therefore\)} \(m\) equals twice some integer \(p\).\\

	\makebox[4mm]{\color{blue} (2)} \makebox[6mm]{} If a quantity is an integer, then it is a real number.\\
	\makebox[4mm]{} \makebox[6mm]{} \(p\) and \(n\) are both particular integers.\\
	\makebox[4mm]{} \makebox[6mm]{\(\therefore\)} \(p\) and \(n\) are both real numbers.\\

	\makebox[4mm]{} \makebox[6mm]{} For all \(a,b,c\), if \(a,b,c \in \R\) then \((ab)c = a(bc)\).\\
	\makebox[4mm]{} \makebox[6mm]{} \(2\), \(p\), and \(n\) are all particular real numbers.\\
	\makebox[4mm]{} \makebox[6mm]{\(\therefore\)} \((2p)n = 2(pn)\).\\

	\makebox[4mm]{\color{blue} (3)} \makebox[6mm]{} For all \(u,v\), if \(u,v \in \Z\) then \(uv \in \Z\).\\
	\makebox[4mm]{} \makebox[6mm]{} \(p\) and \(n\) are both particular integers.\\
	\makebox[4mm]{} \makebox[6mm]{\(\therefore\)} \(pn \in \Z\).\\

	\makebox[4mm]{\color{blue} (4)} \makebox[6mm]{} If a number equals twice some integer, then that number is even.\\
	\makebox[4mm]{} \makebox[6mm]{} \(2(pn)\) equals twice the integer \(pn\).\\
	\makebox[4mm]{} \makebox[6mm]{\(\therefore\)} \(2(pn)\) is even.\\
}

Of course, we would never do a mathematical proof like this. In reality, you do this in your head automatically. Seeing this form, however, allows you to easily verify the \textbf{validity} of the proof.

\section{Summary}

\begin{itemize}
	\item Propositional logic contains the entirety of Boolean algebra and logic connectives, with True and False as the only inputs/outputs
	\item Predicate logic contains the entirety of propositional logic and uses functions along with entities
	\item Deriving knowledge from familiar rules entails mathematical proof
\end{itemize}

\section{Practice}

\begin{enumerate}
	\item Answer the two logic puzzles presented in the introduction of this chapter.
	\item Translate the following statement into propositional logic: \textit{turn right then turn left}.
	\item Translate the following statement into propositional logic: \textit{if it is raining then everyone has an umbrella}.
	\item How can you quickly construct a truth table with all row possibilities? Use your technique to construct a truth table with 4 variables.
	\item How many rows does a truth table with \(n\) variables have?
	\item Prove theorem \ref{bicond-to-imp}.
	\item Prove theorem \ref{imp-to-disj}.
	\item Draw the circuit representation of theorem \ref{bicond-to-imp}.
	\item Prove the following rule valid or invalid:
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \((a \land d) \Rightarrow b\) \\
			& \(e\) \\
			& \(b \Rightarrow (\lnot e)\) \\
			& \((\lnot a) \Rightarrow f\) \\
			& \((\lnot d) \Rightarrow f\) \\
			\cline{2-2}
			\(\therefore\) & \(f\)
		\end{tabular}
	\end{center}
	\item Prove the following rule valid or invalid:
	\begin{center}
		\begin{tabular}{c@{\,}l@{}}
			& \((a \land d) \Rightarrow b\) \\
			& \(e\) \\
			& \(b \Rightarrow (\lnot e)\) \\
			& \((\lnot a) \Rightarrow f\) \\
			& \((\lnot d) \Rightarrow f\) \\
			\cline{2-2}
			\(\therefore\) & \(b \Rightarrow e\)
		\end{tabular}
	\end{center}
	\item Push the negation inside the following statement as far as possible: \[\lnot (\forall x \in \R)(\exists m \in \Z)[(0 \leq x - m < 1) \Leftrightarrow (m = \floor{x})]\]
\end{enumerate}

%\section{Solutions}
%
%\begin{enumerate}
%	\item (1) Sam cannot make any cows, because Sam only starts with 1 cow. (2) We know knights always tell the truth. If we assume the speaker is a knight, then he will have lied about whom he is. Therefore, the speaker is a knave. Since knaves always lie, then we know the speaker lied, so the two people cannot both be knaves. Therefore, the second person is a knight.
%	\item This is a trick question since the statement does not have any true or false value! If you answered something like \(r \Rightarrow l\), good thinking, however this is incorrect.
%	\item One possibility: let \(r\) be the proposition \textit{it is raining} and \(u\) be the proposition \textit{everyone has an umbrella}, then the statement becomes \(r \Rightarrow u\).
%	\item \(2^n\) rows.
%	\item Examine the rows from right to left. In the first column, alternate T/F by 1 step. In the second column, alternate T/F by 2 steps. In the third column, alternate T/F by 4 steps. In the \(n\)th column, alternate T/F by \(2^{n-1}\) steps. The following example uses 1/0, however you should be able to translate it to T/F.
%
%	\begin{center}
%		\begin{tabular}{cccc}
%			\(p\) & \(q\) & \(r\) & \(s\) \\
%			\hline
%			0 & 0 & 0 & 0 \\
%			0 & 0 & 0 & 1 \\
%			0 & 0 & 1 & 0 \\
%			0 & 0 & 1 & 1 \\
%			0 & 1 & 0 & 0 \\
%			0 & 1 & 0 & 1 \\
%			0 & 1 & 1 & 0 \\
%			0 & 1 & 1 & 1 \\
%			1 & 0 & 0 & 0 \\
%			1 & 0 & 0 & 1 \\
%			1 & 0 & 1 & 0 \\
%			1 & 0 & 1 & 1 \\
%			1 & 1 & 0 & 0 \\
%			1 & 1 & 0 & 1 \\
%			1 & 1 & 1 & 0 \\
%			1 & 1 & 1 & 1
%		\end{tabular}
%	\end{center}
%	\item
%	\item
%\end{enumerate}
\end{document}


%\documentclass[12pt]{article}
\documentclass[12pt,landscape]{article}

\usepackage{wrapfig}
\include{preamble}

\newcommand{\instr}{\small Your answer will consist of a lowercase string (e.g. \texttt{aebgd}) where the order of the letters does not matter. \normalsize}

\title{Math 241 Fall \the\year{} \\ Midterm Examination Two}
\author{Professor Adam Kapelner}

\date{Thursday, November 11, \the\year{}}

\begin{document}
\maketitle

%\noindent Full Name \line(1,0){410}

\thispagestyle{empty}

\section*{Code of Academic Integrity}

\footnotesize
Since the college is an academic community, its fundamental purpose is the pursuit of knowledge. Essential to the success of this educational mission is a commitment to the principles of academic integrity. Every member of the college community is responsible for upholding the highest standards of honesty at all times. Students, as members of the community, are also responsible for adhering to the principles and spirit of the following Code of Academic Integrity.

Activities that have the effect or intention of interfering with education, pursuit of knowledge, or fair evaluation of a student's performance are prohibited. Examples of such activities include but are not limited to the following definitions:

\paragraph{Cheating} Using or attempting to use unauthorized assistance, material, or study aids in examinations or other academic work or preventing, or attempting to prevent, another from using authorized assistance, material, or study aids. Example: using an unauthorized cheat sheet in a quiz or exam, altering a graded exam and resubmitting it for a better grade, etc.
\\

\noindent By taking this exam, you acknowledge and agree to uphold this Code of Academic Integrity. \\

%\begin{center}
%\line(1,0){250} ~~~ \line(1,0){100}\\
%~~~~~~~~~~~~~~~~~~~~~signature~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ date
%\end{center}

\normalsize

\section*{Instructions}
This exam is 70 minutes (variable time per question) and closed-book. You are allowed \textbf{one} page (front and back) of a \qu{cheat sheet}, blank scrap paper and a graphing calculator. Please read the questions carefully. Within each problem, I recommend considering the questions that are easy first and then circling back to evaluate the harder ones. No food is allowed, only drinks. %If the question reads \qu{compute,} this means the solution will be a number otherwise you can leave the answer in \textit{any} widely accepted mathematical notation which could be resolved to an exact or approximate number with the use of a computer. I advise you to skip problems marked \qu{[Extra Credit]} until you have finished the other questions on the exam, then loop back and plug in all the holes. I also advise you to use pencil. The exam is 100 points total plus extra credit. Partial credit will be granted for incomplete answers on most of the questions. \fbox{Box} in your final answers. Good luck!

\pagebreak

%%%%%%%%%%%%%%%%%%
\problem\timedsection{12} Consider an apartment building with three floors. Each apartment has a floor number and an apartment letter. The first floor has 5 apartments denoted 1A, 1B, 1C, 1D, 1E; the second floor has 3 apartments denoted 2A, 2B, 2C; the third floor has only a penthouse denoted 3A. Bob walks into this apartment building and selects a floor uniformly (i.e. each floor is equally likely). He then enters an apartment on that floor uniformly.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{15}
\begin{enumerate}[(a)]
\item The probability Bob picks floor 3 is less than the probability Bob picks floor 1.
\item The probability Bob picks floor 3 is more than the probability Bob picks floor 1.
\item The probability of selecting each apartment in the entire building is uniform.
\item The probability of selecting each apartment on floor 2 is uniform if you are told Bob is on floor 2.
\item The probability Bob enters the penthouse is 1/3.
\item The probability Bob enters a C apartment is 2/3.
\item Given that Bob is in a C apartment, the probability he is on the first floor is zero.
\item Given that Bob is in a C apartment, the probability he is on the first floor is 1/3.
\item Given that Bob is in a C apartment, the probability he is on the first floor is 9/24.
\item Given that Bob is in a C apartment, the probability he is on the first floor is 15/24.
\item Given that Bob is in a C apartment, the probability he is on the third floor is zero.
\item Given that Bob is in a C apartment, the probability he is on the third floor is 1/3.
\item Given that Bob is in a C apartment, the probability he is on the third floor is 9/24.
\item Given that Bob is in a C apartment, the probability he is on the third floor is 15/24.
\item The floor selection is independent of the apartment letter selection
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\vspace{-0.4cm}
\begin{wrapfigure}{R}{2in}
\includegraphics[width=1.5in]{spinner.png}
\end{wrapfigure} \problem\timedsection{12}  Consider a game where someone spins the spinner pictured on the right. The numbers represent payouts in \$. The spinner has four colors: red, blue, green, yellow with payouts 2,4, or 8; 5 or 7; 3 or 6; 1 respectively. Let $X$ be the rv whose realization values are the payouts. Assume the spinner is fair.

\benum\truefalsesubquestionwithpoints{18}
\begin{enumerate}[(a)]

\vspace{-0.2cm}
\item $X$ is a discrete rv
\item $X$ is a uniform discrete rv
\item $X$ could be a binomial rv where $n = 8$
\item $X$ could be a hypergeometric rv where $N = 8$
\item $\support{X} = \braces{1, 2,..., 8}$
\item $\support{X} = \bracks{1, 8}$
%\item $|\support{X}| = 8$
\item $|\support{X}| = |\naturals|$
\item If we let $\Omega$ = \{Red, blue, green, yellow\} then we can construct a rv $X$ that maps $\omega \in \Omega$ to the support values of $X$.
\item If we let $\Omega = \bracks{0, 2\pi}$ where $\omega$ represents the angle of the spinner from the right horizontal level between states 2 and 3, then we can construct a rv $X$ that maps $\omega \in \Omega$ to the support values of $X$.
\item $\expe{X} = 4$
\item $\expe{X} = 4.5$
\item $\expe{X} = 5$
\item Med$\bracks{X}$ = 4
\item Med$\bracks{X}$ = 4.5
\item Med$\bracks{X}$ = 5
\item Q$\bracks{X, 0.1}$ = 1
\item Q$\bracks{X, 0.1}$ = 2
\item Range$\bracks{X}$ = 8
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\begin{wrapfigure}{R}{2in}
\includegraphics[width=1.5in]{spinner.png}
\end{wrapfigure} \problem\timedsection{8} \ingray{Consider a game where someone spins the spinner pictured on the right. The numbers represent payouts in dollars. The spinner has four colors: red, blue, green, yellow. Red payouts are 2,4, or 8; blue payouts are 5 or 7; green payouts are 3 or 6; yellow only pays out 1. Let $X$ be the rv whose realization values are the payouts. Assume the spinner is fair.} In this rv, $\mu = 4.5$ and $\support{X} = \braces{1, 2,..., 8}$.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{14}
\begin{enumerate}[(a)]
\item $p(x)$ is monotonically increasing
\item $F(x)$ is monotonically increasing
\item $p(x) < 1$ for all $x \in \support{X}$
\item $F(x) < 1$ for all $x \in \support{X}$
\item $F(4) = 0$
\item $F(4) = 0.5$
\item $F(4) = 1$
\item $p(4) = 0.5$
\item $\sigsq := \var{X} = (1/8) (1^2 + 2^2 + 3^2 + \ldots + 8^2)$
\item $\sigsq := \var{X} = (1/4)(0.5^2 + 1.5^2 + 2.5^2 + 3.5^2)$
\item $\expe{X^2} = 4.5^2$
\item $\sigma := \sd{X} = \expe{X} - 4.5$
\item The unit of the value of the variance of $X$ is dollars
\item The unit of the value of the standard deviation of $X$ is dollars
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\begin{wrapfigure}{R}{2in}
\includegraphics[width=1.3in]{spinner.png}
\end{wrapfigure} \problem\timedsection{10} \ingray{Consider a game where someone spins the spinner pictured on the right. The numbers represent payouts in dollars. The spinner has four colors: red, blue, green, yellow. Red payouts are 2,4, or 8; blue payouts are 5 or 7; green payouts are 3 or 6; yellow only pays out 1. Let $X$ be the rv whose realization values are the payouts. Assume the spinner is fair. In this rv, $\mu = 4.5$ and $\support{X} = \braces{1, 2,..., 8}$.} The variance is $\sigsq := \var{X} = 5.25$ and $\sigma := \sd{X} = 2.29$ rounded to the nearest two digits.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{13}
\begin{enumerate}[(a)]
\item Another way to define variance (i.e. mean \qu{distance} from the mean) could be $\expe{\abss{X - \mu}}$
\item Another way to define variance (i.e. mean \qu{distance} from the mean) could be $\expe{X - \mu}$
\item Another way to define variance (i.e. mean \qu{distance} from the mean) could be $\expe{(X - \mu)^{100}}$
\item $\expe{X^2} = 5.25 + 4.25^2 = 23.3125$
\item $\expe{X^2} = 5.25 - 4.25^2 = -12.8125$
\item $\expe{X^2} = 5.25^2 - 4.25^2 = 9.5$\\

For the rest of these questions let $Y$ denote the rv for the following game. You play the game $X$ but you have to pay a 20\% of the winnings to the casino, then after the tax is taken, you have to pay \$4 to the casino.

\item $X \equalsindist Y$
\item $X, Y$ are independent rv's
\item $Y$ is a \qu{fair game} for you (the player)
\item $\var{Y} = 0.8\sigsq$
\item $\sd{Y} = 0.8\sigma$
\item The probability of winning money if you play the game $Y$ is 3/8
\item $\var{X + Y}$ would have a non-zero covariance term in its expression
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\begin{wrapfigure}{R}{2in}
\includegraphics[width=1.5in]{spinner.png}
\end{wrapfigure} \problem\timedsection{9} \ingray{Consider a game where someone spins the spinner pictured on the right. The numbers represent payouts in dollars. The spinner has four colors: red, blue, green, yellow. Red payouts are 2,4, or 8; blue payouts are 5 or 7; green payouts are 3 or 6; yellow only pays out 1. Let $X$ be the rv whose realization values are the payouts. Assume the spinner is fair. In this rv, $\mu = 4.5$ and $\support{X} = \braces{1, 2,..., 8}$. The variance is $\sigsq := \var{X} = 5.25$ and $\sigma := \sd{X} = 2.29$ rounded to the nearest two digits.} Also consider playing this game $n = 1000$ times where the spinner is reset to the same position and you flick it with approximately the same force each time. The payouts for these $n$ games are denoted by rv's $\Xoneton$.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{11}
\begin{enumerate}[(a)]
\item $\Xoneton \iid$
\item $\Xoneton \inddist$

\item The total winnings after all $n$ games is expected to be $4500$
\item The variance in the total winnings after all $n$ games is 5250
\item The standard deviation in the total winnings after all $n$ games is 72.46 rounded to the nearest two digits.
\item The standard deviation in the total winnings after all $n$ games is 2290

\item The average winnings per game after all $n$ games is expected to be $4.5$
\item The variance in the average winnings per game after all $n$ games is 0.00525
\item The standard deviation in the average winnings per game after all $n$ games is 0.00229 rounded to the nearest 3 digits.
\item The standard deviation in the average winnings per game after all $n$ games is 0.0724 rounded to the nearest 3 digits.
\item As $n$ gets larger, the average winnings per game after all $n$ games approaches a rv centered at $4.5$ with variance shrinking to zero.
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\problem\timedsection{9} In the previous game, the probability of winning is $p := 3/8$ and you played $n = 1000$ times. Each game was $\iid$. Let $\Xoneton$ now denote whether each game was won or not (1 = win and 0 = lose). These are different rv's than the previous problem! Let $T$ denote the total number of wins out over the $n$ games.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{17}
\begin{enumerate}[(a)]
\item $\Xoneton \iid$
\item $X_{17} \sim \bernoulli{3/8}$
\item $X_{17} \sim \bernoulli{5/8}$
\item $T \sim \binomial{n}{p}$
\item $T \sim \hypergeom{n}{np}{n}$
\item $T$ is independent of $X_{17}$
\item $\prob{T = 17} = 3/8$
\item $\prob{T = 17} = \binom{1000}{17} (3/8)^{17} (5/8)^{983}$
\item $\prob{X_{17} = 17} = 3/8$
\item $\prob{X_{17} = 17} = (3/8)^{17}$
\item $\prob{X_{17} = 17} = \binom{1000}{17} (3/8)^{17} (5/8)^{983}$
\item $\expe{T} = (3/8)^{17}$
\item $\expe{T} = 1000 \times 3/8$
\item $\var{T} = 1000 \times 3/8 \times 5/8$
\item $\var{T} = \sum_{t=1}^{1000} \binom{1000}{t} (3/8)^{t} (5/8)^{1000 - t}$
\item $\var{T} = \sum_{t=1}^{1000} t \binom{1000}{t} (3/8)^{t} (5/8)^{1000 - t}$
\item If you kept playing this game until you won (i.e. no limit on $n$, the number of games), then the number of games total played would be a memoryless rv.
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\problem\timedsection{10} Consider a cup with $N = 8$ coins inside and $K = 3$ coins are marked with a permanent marker. Let $p := 3/8$ denote the proportion of marked coins of the total number of coins. You shake the cup and then reach in and pull out $n = 6$ coins so 6 are in your hand and 2 are left in the cup. Let $X_1, X_2, \ldots, X_6$ denote the rv that models if each of the 6 coins in your hand are marked or unmarked ($X_i = 1$ if marked and $X_i = 0$ if unmarked). Let $T$ denote the number of coins in your hand that are marked with the permanent marker. Thus, $T$ is the sum of $X_1, X_2, \ldots, X_6$.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{16}
\begin{enumerate}[(a)]
\item $X_1, X_2, \ldots, X_6 \iid$
\item $X_{3} \equalsindist X_6$
\item $X_{3} \sim \bernoulli{p}$
\item $X_{3} \sim \bernoulli{K/N}$
\item $T \sim \binomial{n}{p}$
\item $T \sim \binomial{N}{p}$
\item $T \sim \hypergeom{n}{K}{N}$
\item $T \sim \hypergeom{n}{np}{N}$
\item $T$ is independent of $X_{3}$
\item $\support{T} = \braces{1, 2, 3, 4, 5, 6, 7, 8}$
\item $\support{T} = \braces{1, 2, 3, 4, 5, 6}$
\item $\support{T} = \braces{1, 2, 3}$
\item $\prob{T = t} = \displaystyle \frac{\binom{3}{t}\binom{5}{6 - t}}{\binom{8}{6}}$
\item $\expe{T} = np$
\item $\expe{T} = n\frac{K}{N}$
\item Given a calculator and enough time, $\var{T}$ can be computed given the information on this page
\end{enumerate}
\eenum\instr\pagebreak

\end{document}


%\renewcommand*{\descriptionlabel}[1]{\hspace\labelsep\normalfont\sffamily #1}
\newenvironment{features}{%
\firmlists\begin{description}}%
{\end{description}}
\newcommand\feat[1]{\item[-- \normalfont\itshape #1]}

\chapter{Features supported by \pharmml}
\label{chap:scope}

\section{Introduction}

The scope of pharmacometric models is very wide, as such models can be empirical as well as
mechanistic; describe continuous as well as discrete data types; and be deterministic, stochastic
or a mixture of both. It is a challenging endeavour to accommodate this variety of possibilities
under one computational standard, therefore it is indispensable to split the task into multiple
steps of subsequent specifications and to define precisely the scope of every release.

In this chapter we define the scope of the functionality in
\pharmml. In particular what information a \pharmml document can
represent and what it cannot. As is common practise in software
engineering we have described the functionality as a set of
``features''. These features are said to be \emph{current} if they are
provided by this release of \pharmml, \emph{planned} if they are not
in the current version, but planned for a future release.
% and \emph{not  include} if we wish to highlight the fact that we believe \pharmml
%will not include this feature.
It is important to remember that this
specification is just the beginning of \pharmml and over time we
expect many of the features currently out of scope to be provided by
future releases of the language.

The language is organised into three sections, which we believe naturally
describe the logical organisation of a pharmacometric model and its
associated tasks. Consequently we have grouped the features to match this
organisation. The sections are:
\begin{description}
\item[Model Definition] A description of the model, incl.\ the structural model, the model
  parameters, relevant covariates, the variability components, and the observations.
\item[Trial Design] A description of the design of a clinical trial associated with the model
  (for example a trial from which data is available to estimate the parameters of the model or
  a trial to be simulated with the model).
\item[Modelling Steps] A description of steps or tasks performed with
  the model. Typically this describes how the model has been used, for
  example to estimate its parameters or to perform a simulation.
\end{description}

\section{Current Features}

\subsection{General}

\begin{features}
\feat{Metadata annotation} Provides support to enable metadata
descriptions of the \pharmml document.
\feat{Extension mechanism} Provides support to enable the extension of
the \pharmml document.
\end{features}

\subsection{Model Definition}

\subsubsection{Structural Model}

\pharmml can encode:
\begin{features}
\feat{A structural model defined by a set of algebraic equations.} Typically the explicit solution to a simple PK model, or a dose-response model.
\feat{A structural model defined by a system of ODEs with initial conditions.} Such systems of ODEs can include algebraic equations as well.
\feat{A structural model defined in \sbml format.}
\feat{A structural model from an external resource or library.}
\feat{Standard PK models} Including those encoded by Monolix \cite{Bertrand:2008} or PREDPP in NONMEM \cite{PREDPP:2011}.
\feat{Standard PD models.} Including those defined by Monolix \cite{Bertrand:2008}.
\end{features}

\subsubsection{Covariate Model}

\pharmml can encode:
\begin{features}
\feat{Continuous covariates.} These can be sampled from a probability distribution and used with an applied transformation.
\feat{Categorical covariates.} These can also be sampled from a probability distribution.
\end{features}

\subsubsection{Parameter Model}

%\footnote{As described in detail in section \ref{maths:parameter-model}, the current specification allows encoding of models that are linear in the transformed parameter, which covers the majority of cases in practical applications. This approach is
%flexible in that one can encode any type of parameter with a distribution that is normal up to a transformation, i.e.
%normal (identity transformation), log-normal (natural logarithm) or logit-normal (logit tranformation).}

\pharmml can encode:
\begin{features}
\feat{The population mean/typical value for a parameter.}
\feat{Linear covariate model.}
\feat{Random effects at arbitrary levels of variability.}
\feat{Correlation of the random effects, described by a correlation or covariance matrix.}
\feat{Non-linear parameter models, such as those described in \cite{Keizer:2011aa}.}
\end{features}

\subsubsection{Variability Model}

\pharmml supports the following levels of variability:
\begin{features}
\feat{Between-Subject Variability (BSV).} Aka inter-individual variability (IIV).
\feat{Inter-Occasion Variability (IOV).} Such as within-subject variability.
\feat{Higher levels of variability above BSV.} Such as variability between countries or centres.
\feat{Lower levels of variability below IOV.} Such as variability between sub-occasions within occasions.
\end{features}

\subsubsection{Observations Model}

\pharmml currently only supports the following observation model:
\begin{features}
\feat{Continuous observation model.} A residual error model applied to one or more variables in the structural model.
\feat{Autocorrelation of the residual errors in a continuous observation model.}
\end{features}

\subsection{Trial Design}

\pharmml can encode the following features of a trial design \emph{explicitly}\footnote{As
opposed to the implicit trial design definition present within a data file.}:
\begin{features}
\feat{Bolus dosing.}
\feat{Infusion dosing.}
\feat{Multiple dosing regimens including mixed bolus and infusion.}
\feat{Repeated dosing.}
\feat{Dosing at arbitrary time points.}
\feat{Steady state dosing.}
\feat{Dosing to more than one compartment.}
\feat{Cross-over designs.}
\feat{Parallel designs.}
\feat{Washout periods.}
\feat{Run-in periods.}
\feat{Occasions -- defined by time interval within a treatment epoch.}
\feat{Trials with different centres or other levels of organisation above study groups (aka arms)}
\end{features}

\subsection{Modelling Steps}

\pharmml can encode the following features related to the task(s) associated with a model:
\begin{features}
\feat{Estimation utilising the maximum likelihood principle.}
\feat{Simulation of the model}
\end{features}

\section{Planned Features}

\subsection{General}

\begin{features}
\feat{Units} Support for unit definitions and unit consistency
checking.
\end{features}

\subsection{Model Definition}

\subsubsection{Covariate Model}

\pharmml does not support the following covariate related features:
\begin{features}
\feat{Conditional distributions of continuous covariates.}
\feat{Clusters of categorical covariates.}
\feat{Selection/exclusion criteria for covariates.}
\end{features}

\subsubsection{Structural Model}

\pharmml does not support the following model types:
\begin{features}
\feat{(Hidden) Markov models.}
\feat{Delay Differential Equations (DDEs).}
\feat{Partial Differential Equations (PDEs).}
\feat{Stochastic Differential Equations (SDEs).}
\end{features}

\subsubsection{Observations Model}

\pharmml does not support the following types of observation models:
\begin{features}
\feat{Count data models.} Poisson, negative binomial, zero-inflated Poisson models etc.
\feat{Nominal and ordered categorical models.} Logistic regression, proportional odds models etc.
\feat{Time-to-event models.} Parametric (e.g.\ exponential, Gompertz, Weibull) or semi-parametric Cox models.
\end{features}

\subsection{Trial Design}

\pharmml cannot encode the following features in a trial design:
\begin{features}
\feat{Reset of all or single compartments.}
\end{features}

\subsection{Modelling Steps}

\pharmml cannot encode the following features related to the task(s) associated with a model:
\begin{features}
\feat{Bayesian inference methods.}
%Methods such as Maximum a posteriori (MAP) or Bayesian inference sing Gibbs sampling methods used in tools of the BUGS-family (winBUGS \cite{Lunn:2002aa}, openBUGS \cite{Lunn:2009fk}) or JAGS \cite{JAGS:2003aa}.
\feat{Writing estimation results to a file or other external resource.}
\feat{Writing simulation results to a file or other external resource.}
\feat{Exchange of results from one modelling step to another.} Currently it is not possible to pass on the results of an estimation task to a subsequent estimation step.
\feat{Model exploration} Tasks such as sensitivity analysis are not
supported.
\feat{Optimal design}
\end{features}

%\section{Features not Included}
%
%\subsection{Model Definition}
%
%\subsubsection{Structural Model}
%
%\pharmml cannot encode:
%\begin{features}
%\feat{Higher order differential equations.}
%\feat{Delay Differential Equations (DDEs).}
%\feat{Partial Differential Equations (PDEs).}
%\feat{Stochastic Differential Equations (SDEs).}
%\feat{(Hidden) Markov models.}
%\end{features}

%\subsubsection{Covariate Model}
%
%\pharmml cannot encode:
%\begin{features}
%\feat{Conditional distributions of continuous covariates.}
%\feat{Clusters of categorical covariates.}
%\feat{Selection/exclusion criteria for covariates.}
%\end{features}

% \begin{itemize}
% \item
% ODE based, standard 1-, 2- or 3-compartmental or physiology based PK (PBPK) models
% \begin{itemize}
% \item
% defined explicitly as a system of ODE's
% \item
% defined as an SBML model
% \end{itemize}
% \item
% algebraic expressions, if analytic solutions are available, e.g. one-compartmental oral model, see section \ref{sec:structuralModel}
% \item
% using library models, e.g. Monolix \cite{Bertrand:2008} or PREDPP \cite{PREDPP:2011}
% \end{itemize}

% \paragraph{Continuous PD models}
% \begin{itemize}
% \item
% ODE based -- e.g. turnover models
% \item
% algebraic -- e.g. Emax-models
% \item
% using library models, e.g. Monolix \cite{Bertrand:2008}
% \end{itemize}

% \section{MS Intro}

% Any part of human and animal anatomy and physiology can be subject to pathological changes and eventually diseases. The scope of pharmacometric models, dealing with virtually any type of such cases, is therefore almost without precedence in science. The models can be
% \begin{itemize}
% \item
% phenomenological or mechanistic
% \item
% they have to cope both with continuous and discrete data types
% \item
% they are deterministic, stochastic or mixture of both
% \item
% they cover all levels of complexity from the molecular to organ and whole body level
% \end{itemize}
% It is a challenging endeavour to accommodate this variety of possibilities under one computational standard but thanks excellent use cases and other documents created and provided by our DDMoRe partners it seams possible. However it is indispensable to split the task into multiple steps of subsequent specifications and to define precisely the scope of every release. This is exactly the goal of this chapter.

% \section{Components of a pharmacometric model}
% In the context of PharmML a typical pharmacometric model can be decomposed into the following components
% \begin{itemize}
% \item
% Data model
% \item
% Trial design model
% \item
% Structural model
% \item
% Parameter model
% \begin{itemize}
% \item
% Covariate model
% \item
% Variability model
% \item
% Correlation of random effects
% \end{itemize}
% \item
% Residual error model
% \item
% Observation model
% \item
% Task model
% \end{itemize}
% In the following sections we describe each of these components briefly and list features which are implemented in the current specification and those which will be included in future releases (the latter listed in the subsections \textit{\textbf{Out of scope}}).

% \section{Features in and outside of current scope}

% \subsection{Data model}

% Coming soon...

% \subparagraph{Out of scope}
% \begin{itemize}
% \item
% trials with different centres or other levels of organisation above study groups (aka arms)
% \item
% levels of variability below one level of inter-occasion variability
% \item
% dose escalation methods, e.g. accelerated titration designs or pharmacologically guided dose escalation
% \item
% complex dosing models, e.g. Higuchi or Weibull release models
% \item
% reset of all or single compartments
% \item
% output compartment definition
% \end{itemize}

% \subsection{Structural model}
% In the current specification only continuous models are considered and any model which can be formulated using
% as system of ordinary differential equations (ODE) or algebraic equations can be implemented. More precisely, the following options are available
% \paragraph{PK models}

% \begin{itemize}
% \item
% ODE based, standard 1-, 2- or 3-compartmental or physiology based PK (PBPK) models
% \begin{itemize}
% \item
% defined explicitly as a system of ODE's
% \item
% defined as an SBML model
% \end{itemize}
% \item
% algebraic expressions, if analytic solutions are available, e.g. one-compartmental oral model, see section \ref{sec:structuralModel}
% \item
% using library models, e.g. Monolix \cite{Bertrand:2008} or PREDPP \cite{PREDPP:2011}
% \end{itemize}

% \paragraph{Continuous PD models}
% \begin{itemize}
% \item
% ODE based -- e.g. turnover models
% \item
% algebraic -- e.g. Emax-models
% \item
% using library models, e.g. Monolix \cite{Bertrand:2008}
% \end{itemize}

% \subparagraph{Out of scope}
% The following model types or approaches are planned for a subsequent release
% \begin{itemize}
% \item
% Discrete data models
% \begin{itemize}
% \item
% nominal and ordered categorical models e.g. logistic regression, proportional odds models etc.
% \item
% count data models, e.g. Poisson, negative binomial, zero-inflated Poisson models etc.
% \item
% time-to-event models, e.g. parametric (e.g. exponential, Gompertz, Weibull) or semi-parametric Cox model
% \end{itemize}
% \item
% (Hidden) Markov models
% \item
% stochastic differential equations (SDE)
% \item
% delay differential equations (SDE)
% \item
% partial differential equations (PDE)
% \end{itemize}

% \subsection{Parameter model}
% As described in detail in section \ref{sec:parameterModel}, the current specification allows for encoding of
% models which are linear in the transformed parameter which covers a majority of cases in practical applications.
% This approach is flexible in that one can encode any type of parameter which distribution is normal up to a transformation,
% i.e. normal (identity transformation), log-normal (natural logarithm) or logit-normal (logit tranformation).\\
% The parameter model consists of the following elements
% \begin{itemize}
% \item
% population/typical value for the parameter
% \item
% continuous and categorical covariate model (covariates can be sampled from probability distributions)
% %---- estimating categorical distribution from external data file \\
% %---- sampling from known categorical distribution \\
% \item
% random effects of arbitrary level, see section \ref{sec:variabilityModel} for details
% \item
% correlation of random effects, described by a correlation or covariance matrix
% \end{itemize}

% \subparagraph{Out of scope}
% The following features are planned for a subsequent release:
% \begin{itemize}
% \item
% non-linear parameter models, such as those described in \cite{Keizer:2011aa}
% \item
% autocorrelation of residual errors
% \item
% clusters of categorical covariates
% \item
% conditional distributions of continuous covariates
% \item
% selection/exclusion criteria for covariates
% \end{itemize}

% \subsection{Residual error model}
% PharmML is flexible with respect to defining residual error models. Currently this can be done
% only explicitly as there is no external library, see section \ref{sec:residualErrorModel}.
% For a future release the creation of an external library is planned.

% \subsection{Observation model}
% The following information can be stored in PharmML
% \begin{itemize}
% \item
% model variable to be observed, both for continuous PK or PD models
% \item
% time points for every model varaiable at which predictions are to be estimated
% \end{itemize}

% \subsection{Task model}
% This model describes a combination of the operations one can perform on the model, such as:
% \begin{itemize}
% \item
% simulation of a trial design, defined explicitly in PharmML or encoded in a data file
% \item
% estimation of population or individual parameters
% \begin{itemize}
% \item
% using the trial design designed in PharmML and objective data encoded in a data file
% \item
% using the trial design and objective data encoded in a data file
% \end{itemize}
% \item
% model exploration, e.g. sensitivity analysis
% \end{itemize}

% \subparagraph{Out of scope}
% \begin{itemize}
% \item
% export of simulation results to an external file
% \item
% export of estimation results to an external file
% \item
% transfer of results from one modelling step to another, for example transferring estimation results to a simulation step
% \end{itemize}

% \paragraph{Inference methods supported in PharmML}
% In general the current specification is restricted to estimation methods utilising the maximum likelihood principle. Not in the scope are Bayesian inference methods such as Maximum a posteriori (MAP) or Bayesian inference sing Gibbs sampling methods used in tools of the BUGS-family (winBUGS \cite{Lunn:2002aa}, openBUGS \cite{Lunn:2009fk}) or JAGS \cite{JAGS:2003aa}.

% %\paragraph{Covariate model}
% %Covariate model is barely covered so far. See also \cite{Keizer:2011aa}. Missing are following features:\\
% %For categorical covariates:\\
% %-- categorical distribution of categorical covariates \\
% %---- estimating categorical distribution from external data file \\
% %---- sampling from known categorical distribution \\
% %---- clusters of categorical covariates \\
% %For continuous covariates:\\
% %-- power-normal distribution for continuous covariates \\
% %---- estimating parameters $\lambda$,$\mu$,$\sigma$ from external data file \\
% %---- sampling from known power-normal distribution \\
% %---- conditional distribution of continuous covariates \\
% %------ none \\
% %------ defined \\
% %------ to be estimated \\
% %---- selecting criteria for continuous covariates \\
% %---- dependent distribution of continuous covariates \\
% %---- correlated continuous covariates \\
% %For both types: \\
% %-- selection/exclusion criteria missing \\
% %
% %\subsection{Observation model}
% %- Name\\
% %- Units\\
% %- Observation types - continuous/discrete\\
% %- Symbol of predicted output\\
% %
% %\subsection{Task model}
% %-- Combination of tasks, e.g.\\
% %1. estimate distribution of covariate from experimental data\\
% %2. Simulation task using the estimated PDF
% %
% %
% %\subsection{Not covered so far}
% %- correlation of residual errors \\
% %---- number models of relevant models identified and described in Use Case document\\
% %

% \input{input/features.tex}