How did they got the final result?
Take natural logarithm of the expression. Logarithm of product of two terms can be written as sum of logarithms of each term: log(a.b) = loga + logb. e and natural logarithm cancel each other, there is left first term in the result. Logarithm of a 1/number is equal to -log(number), it gives second term in the result.
Taking logarithms of exponentials is quite common method for preventing numerical overflows and ensuring numerical stability.