Definition by Cases is Primitive Recursive

Theorem
Let $$\mathcal{R}_1, \mathcal{R}_2, \ldots, \mathcal{R}_k$$ be primitive recursive relations on $$\N^l$$ such that:
 * $$\forall i, j \in \left\{{1, 2, \ldots, k}\right\}: \mathcal{R}_i \iff \lnot \mathcal{R}_j$$, i.e. all relations are mutually exclusive;
 * $$\forall \left({n_1, n_2, \ldots, n_l}\right) \in \N^l: \exists i \in \left\{{1, 2, \ldots, k}\right\}: \mathcal{R}_i \left({n_1, n_2, \ldots, n_l}\right)$$, that is, the set of relations is exhaustive.

Let $$\forall i \in \left\{{1, 2, \ldots, k}\right\}: g_i: \N^l \to \N$$ be primitive recursive functions.

Then the function $$f: \N^l \to \N$$ defined as:
 * $$f \left({n_1, n_2, \ldots, n_l}\right) = \begin{cases}

g_1 \left({n_1, n_2, \ldots, n_l}\right) & : \mathcal{R}_1 \left({n_1, n_2, \ldots, n_l}\right) \\ g_2 \left({n_1, n_2, \ldots, n_l}\right) & : \mathcal{R}_2 \left({n_1, n_2, \ldots, n_l}\right) \\ \quad \vdots & \quad \vdots \\ g_k \left({n_1, n_2, \ldots, n_l}\right) & : \mathcal{R}_k \left({n_1, n_2, \ldots, n_l}\right) \end{cases}$$ is primitive recursive.

Corollary
The definition can be made more flexible by defining $$f$$ as:
 * $$f \left({n_1, n_2, \ldots, n_l}\right) = \begin{cases}

g_1 \left({n_1, n_2, \ldots, n_l}\right) & : \mathcal{R}_1 \left({n_1, n_2, \ldots, n_l}\right) \\ g_2 \left({n_1, n_2, \ldots, n_l}\right) & : \mathcal{R}_2 \left({n_1, n_2, \ldots, n_l}\right) \\ \quad \vdots & \quad \vdots \\ g_{k-1} \left({n_1, n_2, \ldots, n_l}\right) & : \mathcal{R}_{k-1} \left({n_1, n_2, \ldots, n_l}\right) \\ g_k \left({n_1, n_2, \ldots, n_l}\right) & : \text {otherwise} \end{cases}$$

where "otherwise" can be replaced by:
 * $$\mathcal{R}_k \left({n_1, n_2, \ldots, n_l}\right) = \lnot \left({\mathcal{R}_1 \left({n_1, n_2, \ldots, n_l}\right) \lor \mathcal{R}_2 \left({n_1, n_2, \ldots, n_l}\right) \lor \ldots \lor \mathcal{R}_{k-1} \left({n_1, n_2, \ldots, n_l}\right)}\right)$$

Thus we need to define only $$k-1$$ mutually exclusive and exhaustive relations as the "otherwise" case takes care of the default case.

Proof
We have:

$$ $$ $$ $$

because if $$\left({n_1, n_2, \ldots, n_l}\right) \in \N^k$$, there is a unique $$r$$ such that $$\mathcal{R}_r \left({n_1, n_2, \ldots, n_l}\right)$$.

Then $$\chi_{\mathcal{R}_r} \left({n_1, n_2, \ldots, n_l}\right) = 1$$ and $$\chi_{\mathcal{R}_s} \left({n_1, n_2, \ldots, n_l}\right) = 0$$ for $$s \ne r$$.

Then the value of the RHS is $$g_r \left({n_1, n_2, \ldots, n_l}\right)$$ as required.

Since $$\mathcal{R}_1, \mathcal{R}_2, \ldots, \mathcal{R}_k$$ are primitive recursive, the functions $$\chi_{\mathcal{R}_1}, \chi_{\mathcal{R}_2}, \ldots, \chi_{\mathcal{R}_k}$$ are primitive recursive as well.

Hence $$f$$ is obtained by substitution from:
 * the primitive recursive function $\operatorname{add}$;
 * the primitive recursive functions $$g_j$$;
 * the primitive recursive functions $$\chi_{\mathcal{R}_j}$$.

Hence the result.

Proof of Corollary
Immediate from the main proof and Set Operations on Primitive Recursive Relations.