# Domain problem when calculating marginal density

I have the following homework assignment: the life expectancy $$X$$ of a lamp has exponential distribution with rate $$\lambda$$. The rate depends on the production proccess, such that its population can be described by the uniform distribution $$\lambda \sim U[0,1]$$. (I'm sorry if the translation is bad, I hope it is understandable).

1. Describe the joint density of the lamp life $$X$$ and rate $$\lambda$$.

This one is just $$f_{X \mid\lambda}(x\mid\lambda)f_{\lambda}(\lambda) = \lambda e^{-\lambda x}$$ for $$x \geq 0$$ and $$\lambda \in [0,1]$$ or $$0$$ elsewhere.

1. Find $$X$$ distribution.

First I tried to find the marginal density of $$X$$ by integrating the joint density over $$\lambda$$: $$f_{X}(x) = \int_{0}^{1} \lambda e^{-\lambda x} \,d\lambda = -\frac{e^{-x}}{x} - \frac{e^{-x}}{x^{2}} + \frac{1}{x^{2}} \quad \text{if x \geq 0 and 0 otherwise}$$ I am already in trouble, somewhere along the way I lost the ability to compute the marginal density for $$X = 0$$, which was fine for the joint density, I don't know what happened (the integral is correct) nor do I know why was this information lost. It gets even uglier when I try to find the distribution of $$X$$: $$F(X \leq x) = \int_{0}^{x} -\frac{e^{-x}}{x} - \frac{e^{-x}}{x^{2}} + \frac{1}{x^{2}} \,dx = (-\frac{1}{x} + \frac{e^{-x}}{x})\Big|_{0}^{x}$$ Once again the integral is correct but now I can't even evaluate it because of the lower limit being $$0$$. So my question is what am I doing wrong? And why did I lose the information on $$X = 0$$? I know I can just calculate $$F(X \leq x \mid \lambda)$$ and get some nice results after integrating over $$\lambda$$ but I really don't know why this straight forward way doesn't really work here...

The marginal density \begin{align}f(x)&=\int_0^1 \lambda e^{-\lambda x} \text{d}\lambda\\ &= \int_0^1 -\frac{\partial}{\partial x} e^{-\lambda x} \text{d}\lambda\\ &= -\frac{\partial}{\partial x}\int_0^1 e^{-\lambda x} \text{d}\lambda\\ &= -\frac{\partial}{\partial x} \frac{1-e^{-x}}{x}\tag{1}\\ &= \frac{1-e^{-x}}{x^2} -\frac{e^{-x}}{x}\end{align} is well-defined over $$(0,\infty)$$. The fact that it goes to infinity at $$x=0$$ does not matter since a density is uniquely defined almost everywhere. Setting $$f(0)=0$$ or $$f(0)=12346$$ is equally valid (and irrelevant). The important fact is that $$f$$ is integrable over $$(0,\infty)$$, with mass equal to one.
The cdf is found in (1): since $$\lim_{x\to 0} \frac{1-e^{-x}}{x} = \lim_{x\to 0} \frac{\frac{\partial}{\partial x} 1-e^{-x}}{\frac{\partial}{\partial x} x} = \lim_{x\to 0} \frac{e^{-x}}{1} = 1$$ by L'Hospital's rule, $$F(x)= 1-\frac{1-e^{-x}}{x}$$