Lambda Calculus Problem Solution: Logical Exclusive OR (XOR) Exclusive OR is true precisely when one of its two Boolean inputs is true and the other is false. Using Church booleans, we can express XOR by conditionally negating the second argument.
\[\mathrm{XOR}(p,q)=\mathrm{IF}\ p\ \mathrm{THEN}\ (\mathrm{NOT}\ q)\ \mathrm{ELSE}\ q\]
1. Church Boolean definitions \[\begin{aligned}\mathrm{TRUE}&\equiv\lambda a.\lambda b.a\\\mathrm{FALSE}&\equiv\lambda a.\lambda b.b\\\mathrm{NOT}&\equiv\lambda x.x\ \mathrm{FALSE}\ \mathrm{TRUE}\\\mathrm{IF}&\equiv\lambda p.\lambda a.\lambda b.p\ a\ b\end{aligned}\]
Church booleans are functions that choose between two arguments: TRUE selects the first and FALSE selects the second.
2. Construct the XOR expression \[\begin{aligned}\mathrm{XOR}&\equiv\lambda p.\lambda q.p\ (\mathrm{NOT}\ q)\ q\\&\equiv\lambda p.\lambda q.p\ (q\ \mathrm{FALSE}\ \mathrm{TRUE})\ q\\&\equiv\boxed{\lambda p.\lambda q.p\ (q\ (\lambda a.\lambda b.b)\ (\lambda a.\lambda b.a))\ q}\end{aligned}\]
The boxed expression is a pure, closed lambda term: it requires no predefined logical operators.
3. Verify the four cases \(p\) \(q\) \(\mathrm{XOR}(p,q)\) FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE
4. Beta-reduction examples When the first input is TRUE, the expression selects the negation of the second input:
\[\begin{aligned}\mathrm{XOR}\ \mathrm{TRUE}\ \mathrm{FALSE}&\to_\beta\mathrm{TRUE}\ (\mathrm{NOT}\ \mathrm{FALSE})\ \mathrm{FALSE}\\&\to_\beta\mathrm{NOT}\ \mathrm{FALSE}\\&\to_\beta\mathrm{TRUE}\end{aligned}\]
When both inputs are TRUE:
\[\begin{aligned}\mathrm{XOR}\ \mathrm{TRUE}\ \mathrm{TRUE}&\to_\beta\mathrm{TRUE}\ (\mathrm{NOT}\ \mathrm{TRUE})\ \mathrm{TRUE}\\&\to_\beta\mathrm{NOT}\ \mathrm{TRUE}\\&\to_\beta\mathrm{FALSE}\end{aligned}\]
5. Equivalent Boolean-algebra formulation \[p\oplus q=(p\land\neg q)\lor(\neg p\land q)\]
Both forms encode the same logical operation. The conditional lambda expression is particularly compact because a Church boolean already acts as a selector.
Lambda Calculus — XOR derivation and verification.