TAOCP 7.2.2.2 Exercise 218

The ternary operator $u,?,v:w$ has value $v$ when $u=1$ and value $w$ when $u=0$.

Section 7.2.2.2: Satisfiability

Exercise 218. [20] [20] Express the formula $(x \vee A) \wedge (\bar{x} \vee B)$ in terms of the ternary operator $u,?,v : w$.

Verified: no
Solve time: 1m15s


Solution

The ternary operator $u,?,v:w$ has value $v$ when $u=1$ and value $w$ when $u=0$. Consider the two possible values of $x$.

If $x=1$, then

$$ (x\vee A)\wedge(\bar{x}\vee B) =(1\vee A)\wedge(0\vee B) =1\wedge B =B. $$

If $x=0$, then

$$ (x\vee A)\wedge(\bar{x}\vee B) =(0\vee A)\wedge(1\vee B) =A\wedge1 =A. $$

Therefore the expression selects $B$ when $x=1$ and selects $A$ when $x=0$. This is exactly the meaning of the ternary expression $x,?,B:A$. Hence

$$ \boxed{(x\vee A)\wedge(\bar{x}\vee B)=x,?,B:A} $$