The answer by Taylor is excellent, and already correctly gives the posterior kernel, which gives an intractable integral. If your goal is to find the posterior density (as opposed to sampling from the posterior distribution) then you are effectively just looking for the constant-of-integration:
$$H(x) \equiv \frac{1}{\pi} \int \limits_{-\infty}^\infty \frac{\exp(-\tfrac{1}{2} (\theta - x)^2)}{(1+\theta^2)} d\theta.$$
In this case acceptance-sampling is an inefficient method of numerically estimating the integral, since it discards a lot of generated values. A more efficient method is to calculate numerically using a large number $m$ of quantiles of the standard normal distribution:
$$\hat{H}_m(x) \equiv \sqrt{\frac{2}{\pi}} \sum_{k=1}^m \frac{1}{1+(x+z_{(k)})^2} \quad \quad \quad z_{(k)} = \Phi^{-1}(\tfrac{2k-1}{2m}).$$
It is simple to establish that $\hat{H}_m \rightarrow H$ as $m \rightarrow \infty$, which gives you the approximate posterior:
$$\pi(\theta|x) \approx \frac{1}{\pi} \cdot \frac{\exp(-\tfrac{1}{2} (\theta - x)^2)}{(1+\theta^2) \hat{H}_m(x)} \quad \quad \text{for all } \theta \in \mathbb{R}.$$
Simulating the required constant: This estimate of the definite integral can be implemented in R
with a vectorised function of x
using the code below. The integral is symmetric about zero so we plot it (on a logarithmic scale) for positive values of $x$.
#Create function to estimate definite integral
H <- function(x, m) { P <- ((1:m) - 1/2)/m;
Z <- qnorm(P, 0, 1);
HHAT <- rep(0, length(x));
for (i in 1:length(x)) {
DENOM <- 1 + (x[i]+Z)^2;
HHAT[i] <- sqrt(2/pi)*sum(1/DENOM); }
HHAT; }
#Plot this function for values of x
library(ggplot2);
library(scales);
theme_update(plot.title = element_text(size = 15, hjust = 0.5),
plot.subtitle = element_text(size = 10, hjust = 0.5),
axis.title.x = element_text(size = 10, hjust = 0.5),
axis.title.y = element_text(size = 10, vjust = 0.5),
plot.margin = unit(c(1, 1, 1, 1), "cm"));
m <- 10^6;
DATA <- data.frame(xx = (0:100),
HH = H((0:100), m));
ggplot(data = DATA, aes(x = xx, y = HH)) +
geom_line(size = 1.2, colour = 'red') +
scale_y_log10(breaks = trans_breaks('log10', function(x) 10^x),
labels = trans_format('log10', math_format(10^.x))) +
ggtitle('Plot of estimated value of integral') +
labs(subtitle = paste0('(Quantile sampling with ',
format(m, scientific = FALSE, big.mark = ','),
' values)')) +
xlab('x') + ylab('hat(H)');
