# On the conditional expectation with respect to $\left\{Y=a\right\}$

For me it is pretty clear how the conditional expectation

$$\mathbb{E}\left[X\left|\right.\mathcal{G}\right]\quad (1)$$

of a random variable $$X$$ with respect to a $$\sigma$$-algebra $$\mathcal{G}$$ is defined. In particular, $$(1)$$ is the almost-unique $$\mathcal{G}$$-measurable random variable such that

$$\mathbb{E}[(X-\mathbb{E}\left[X\left|\right.\mathcal{G}\right])^2] = \inf_{Z\text{ is }\mathcal{G}\text{-measurable}}\mathbb{E}[(X-Z)^2].$$

This said, how the conditional expected value

$$\mathbb{E}\left[X\left|\right.Y=a\right],$$ where $$Y$$ is another random variable and $$a\in\mathbb{R}$$, is formally defined?

If you understood conditional expectation with respect to a sub-$$\sigma$$-algebra (actually your definition only work for $$X\in L^2$$, for $$L^1$$ you should use Radon-Nikodym or limiting argument), then the conditional expectation $$\mathbb{E}[X\mid A]$$ with respect to an event $$A$$ is simply as the value of the conditional expectation with respect to the sub-$$\sigma$$-algebra $$\{\varnothing,A,A^c,\Omega\}]$$ evaluated at points of $$A$$ (since $$\mathbb{R}$$ is Hausdorff every $$a\in A$$ give the same answer). Note that since $$\mathbb{E}[X\mid\mathcal{G}]$$ is only defined as an element of $$L^1(\mathcal{G})$$ (i.e. modulo almost sure equivalence) and not the set of all integrable $$\mathscr{G}$$-measurable random variable $$\mathscr{L}^1(\mathcal{G})$$, this is ill-defined for null event $$A$$, and is well-defined if $$A$$ is non-null. Conventionally, if $$A$$ is null we define $$\mathbb{E}[X\mid A]=0$$ (similar to how we construct $$\mathbb{E}[X\mid\mathcal{G}]$$) for definiteness). In particular, we have $$\mathbb{E}[X\mid A]\mathbb{P}(A)=\mathbb{E}[X1_A].$$ Note that $$Y=a$$ is an event $$Y^{-1}(a)$$, so this gives $$\mathbb{E}[X\mid Y=a]$$.
There are authors who insist on promoting nonsense such as $$\displaystyle\mathbb{E}[X\mid Y=a]=\int_{\mathbb{R}} x\frac{f_{X,Y}(x,a)}{f_Y(a)}\,\mathrm{d}x$$ even when $$\mathbb{P}(Y=y)=0$$. If you encounter it in any book, please do the good deed and burn the book along with the author.