How to represent some logical propositions How can I logically represent the following propositions:


*

*At most one of $p$,$q$,$r$.

*Only one of $p$, $q$, $r$.


My solutions:


*

*($p$ and ~($q$ or $r$)) or ($q$ and ~($p$ or $r$)) or ($r$ and ~( $p$ or $q$)).

*($p$ and ~($q$ and $r$)) or ($q$ and ~($p$ and $r$)) or ($r$ and ~($p$ and $q$)).

 A: For (1), "at most one of" a set means 1 or fewer from the set. Your solution for (1) rules out 2 or more of $p,q,r$, which is good, but you need to think about numbers smaller than 1 :-).
For (2), ($p$ and ~($q$ and $r$)) is true if $p$ is true and $q$ is true and $r$ is false, so it doesn't do what you want.  Hint: your original answer for (1) seems to work for (2)!
A: The correct answers are the following ($\land$ stands for "and", $\lor$ stands for "or"):


*

*(~$p$ $\lor$ ~($q$ $\lor$ $r$)) $\land$ (~$q$ $\lor$ ~($p$ $\lor$ $r$)) $\land$ (~$r$ $\lor$ ~($p$ $\lor$ $q$))

*($p$ $\land$ ~($q$ $\lor$ $r$)) $\lor$ ($q$ $\land$ ~($p$ $\lor$ $r$)) $\lor$ ($r$ $\land$ ~( $p$ $\lor$ $q$)).


Note that your original answer for (1) is actually the good answer for (2).
You can check the soundness of my answers looking at the following truth table, in particular rows 4, 6-8 for question (1), and rows 4, 6-7 for question (2):
$
\begin{array}{ccc|cccccc}
\quad p & \quad q & \quad r \quad & \ \sim\!p & \sim\!(q \lor r) &\sim\!q & \sim\!(p \lor r) & \sim\!r & \sim\!(p \lor q) \\
\quad \mathtt{T} & \quad \mathtt{T} & \quad \mathtt{T} \quad & \quad \mathtt{F} & \mathtt{F} & \mathtt{F} & \mathtt{F} & \mathtt{F} & \mathtt{F} \\
\quad \mathtt{T} & \quad \mathtt{T} & \quad \mathtt{F} \quad & \quad \mathtt{F} & \mathtt{F} & \mathtt{F} & \mathtt{F} & \mathtt{T} & \mathtt{F} \\
\quad \mathtt{T} & \quad \mathtt{F} & \quad \mathtt{T} \quad & \quad \mathtt{F} & \mathtt{F} & \mathtt{T} & \mathtt{F} & \mathtt{F} & \mathtt{F} \\
\quad \mathtt{T} & \quad \mathtt{F} & \quad \mathtt{F} \quad & \quad \mathtt{F} & \mathtt{T} & \mathtt{T} & \mathtt{F} & \mathtt{T} & \mathtt{F} \\
\quad \mathtt{F} & \quad \mathtt{T} & \quad \mathtt{T} \quad & \quad \mathtt{T} & \mathtt{F} & \mathtt{F} & \mathtt{F} & \mathtt{F} & \mathtt{F} \\
\quad \mathtt{F} & \quad \mathtt{T} & \quad \mathtt{F} \quad & \quad \mathtt{T} & \mathtt{F} & \mathtt{F} & \mathtt{T} & \mathtt{T} & \mathtt{F} \\
\quad \mathtt{F} & \quad \mathtt{F} & \quad \mathtt{T} \quad & \quad \mathtt{T} & \mathtt{F} & \mathtt{T} & \mathtt{F} & \mathtt{F} & \mathtt{T} \\
\quad \mathtt{F} & \quad \mathtt{F} & \quad \mathtt{F} \quad & \quad \mathtt{T} & \mathtt{T} & \mathtt{T} & \mathtt{T} & \mathtt{T} & \mathtt{T} \\
\end{array}
$
A: XOR might also come handy for (2) as
$$p \oplus q \oplus r$$
will be true if, and only if, an odd number of variables are true. But then,
$$(p \oplus q \oplus r) \land \lnot (p \land q \land r)$$
will be true if, and only if, exactly one of them is true.
Once you have solved (2), (1) follows immediately as it's equivalent to
$$((p \oplus q \oplus r) \land \lnot (p \land q \land r)) \lor \lnot (p \lor q \lor r)$$
i.e., "exactly one is true OR none is true".
