# Distribution of the Inner Product of a Gaussian Random Vector and its Reversal

Suppose I have a random variable $$\mathbf{x} \sim \mathcal{N}(0, \sigma^{2} \mathbf{I})$$, where $$\mathbf{x} \in \mathbf{R}^{N}$$, where $$N$$ is an even number. Let $$\mathbf{x}_{r} = \mathbf{A}_{rev} \mathbf{x}$$, where $$\mathbf{A}_{rev}$$ is the matrix that reverses the elements. I want to know what the distribution of $$y = \mathbf{x}_{r}^{T} \mathbf{x}$$ will be.

It seems that since $$x_{i}$$, the elements of $$\mathbf{x}$$, are i.i.d., then since $$N$$ is even, $$x_{r_{i}}$$ should be independent of $$x_{i}$$ $$\forall i$$. Therefore, according to the book "Products of Random Variables" (https://link.springer.com/chapter/10.1007/978-0-387-47694-0_7), the pdf of $$y$$ should be:

$$f(y) = \frac{e^{-\frac{|y|}{\sigma^{2}}}}{\sigma^{2}(M-1)!} \sum_{k=0}^{M-1} \frac{(M+k-1)!}{2^{(M+k)} k! (M-k-1)!} \left(\frac{|y|}{\sigma^{2}}\right)^{M-1-k}$$

where $$M = \frac{N}{2}$$.

However, when I code this up in python like this:

    length = 2**6
sigma_2 = 2.0

#===Generate RV===#
x = numpy.random.normal(0, numpy.sqrt(sigma_2), length)
x_r = x[::-1]
y = sum(x_r*x)



I get the following:

The left hand side is the corresponding histogram of the computed $$y$$ values, and the right hand side is the analytic pdf. It is clear they do not match.

When I do:

    length = 2**6
sigma_2 = 2.0

#===Generate RV===#
x = numpy.random.normal(0, numpy.sqrt(sigma_2), length)
x_r = numpy.random.normal(0, numpy.sqrt(sigma_2), length)
y = sum(x_r*x)



I get:

which actually do match.

Question:

Why are these plots different? Is it because of the correlation induced by the random variable generation process, or am I missing something fundamental about what the pdf of $$y$$ should actually be?