Suppose I have two finite dimensional, Hermitian operators $A,B : V\rightarrow V$ that commute. Let $\lambda_i$ denote the eigenvalues of $A$, and $\gamma_j$ denote the eigenvalues of $B$, without repetition. By the spectral theorem, $A$ and $B$ admit a shared eigenbasis in which they are both diagonal, and, as a consequence, one may decompose the vector space $V$ as a direct sum of the "simultaneous eigenspaces"
$$V = \bigoplus_{ij} E_{ij}^{AB},$$
where
$$v \in E_{ij}^{AB} \text{ iff } Av = \lambda_i v \text{ and } Bv = \gamma_j v.$$
My question is: can I construct, from $A$ and $B$, a single operator whose eigenspaces are $E_{ij}^{AB}$? Ideally, such an operator would be an explicit function of $A$ and $B$.
Below are two of my attempts at this problem.
My attempts at this were to try the following two operators:
$$C = A + B, \quad D = AB.$$
Indeed, we have, for $v \in E_{ij}^{AB}$:
$$Cv = (\lambda_i + \gamma_j)v \quad Dv = \lambda_i \gamma_j v,$$
meaning that $C$ and $D$ are diagonal in the shared eigenbasis of $A,B$. However, the fact that the maps $(\lambda_i, \gamma_j) \mapsto \lambda_i + \gamma_j$ and $(\lambda_i, \gamma_j) \mapsto \lambda_i\gamma_j$ aren't necessarily injective means that the eigenspaces of $C$ and $D$ might be larger than the $E_{ij}^{AB}$, and contain the $E_{ij}^{AB}$ as proper subspaces. So perhaps my problem can be solved if I can find, given a collection of eigenvalue tuples $\{(\lambda_i, \gamma_j)\}$ an injective map $f : \{(\lambda_i, \gamma_j)\} \rightarrow \mathbb{R}$, and then construct an operator function of $A,B$ that implements this map, but I am not sure how to proceed from here.
Furthermore, I note that this problem can be solved easily using the spectral theorem. Let $\{v_{ij}^1,\ldots, v_{ij}^{N_{ij}}\}$ denote an orthonormal eigenbasis for $E_{ij}^{AB}$. Then, if $f : \mathbb{N}^2 \rightarrow \mathbb{R}$ is an injective function, then
$$ X = \sum_{i}\sum_{j}\sum_{k=1}^{N_{ij}} f(i,j) v_{ij}^k \left(v_{ij}^k\right)^T,$$
is the spectral decomposition of an operator whose eigenspaces are $E_{ij}^{AB}$. However, ideally I would like an operator that is a function of $A$ and $B$, that doesn't make reference to the eigenvectors.
A very simple solution is to take $C=A+iB$. This will have eigenvalue $\lambda_i+i\gamma_j$ on each $E_{ij}^{AB}$, and these are all distinct since the $\lambda$s and $\gamma$s are all real. (Or, comparing to your attempts with $A+B$ and $AB$, this works because the map $\mathbb{R}\times\mathbb{R}\to\mathbb{C}$ given by $(x,y)\mapsto x+iy$ is injective.)
If you want $C$ to be Hermitian then there is nothing quite so simple you can do. If $f:\mathbb{R}^2\to\mathbb{R}$ is a Borel injection, you could take $C=f(A,B)$ where $f(A,B)$ is defined using the Borel functional calculus. This is perhaps not as explicit as you would want, though. (And you cannot use the simpler continuous functional calculus in the same way, since there is no continuous injection $\mathbb{R}^2\to\mathbb{R}$!)
If you are willing to use some data about the spectra of $A$ and $B$ as input into your formula for $C$, here is something you could do. Let $\epsilon>0$ be such that the distance between any two distinct eigenvalues of $A$ is at least $\epsilon$ and let $m>0$ be such that every eigenvalue of $B$ has absolute value at most $m$. Then $C=A+\frac{\epsilon}{3m}B$ will work. Indeed, given an eigenvalue $\kappa=\lambda_i+\frac{\epsilon}{3m}\gamma_j$ of $C$, $\lambda_i$ is the unique eigenvalue of $A$ that is within $\epsilon/3$ of $\kappa$, so $\lambda_i$ (and hence also $\gamma_j$) is uniquely determined by $\kappa$.