Given a vector of \$n\$ values \$(x_1,x_2,x_3,\ldots,x_n)\$ return the determinant of the corresponding Vandermonde matrix
\$V(x_1, x_2, \ldots, x_n) = \begin{bmatrix}1 & x_1 & x_1^2 & x_1^3 & \ldots &x_1^{n-1} \\1 & x_2 & x_2^2 & x_2^3 & \ldots &x_2^{n-1} \\ \vdots & & & \vdots & & \vdots \\ 1 & x_n & x_n^2 & x_n^3 & \ldots & x_n^{n-1}\end{bmatrix}\$.
This determinant can be written as:
\$\det V(x_1, x_2, \ldots x_n) = \prod_\limits{1 \leqslant i < j \leqslant n} (x_j - x_i)\$
Details
Your program/function has to accept a list of floating point numbers in any convenient format that allows for a variable length, and output the specified determinant.
You can assume that the input as well as the output is within the range of the values your language supports. If you language does not support floating point numbers, you may assume integers.
Some test cases
Note that whenever there are two equal entries, the determinant will be 0
as there are two equal rows in the corresponding Vandermonde matrix. Thanks to @randomra for pointing out this missing testcase.
[1,2,2,3] 0
[-13513] 1
[1,2] 1
[2,1] -1
[1,2,3] 2
[3,2,1] -2
[1,2,3,4] 12
[1,2,3,4,5] 288
[1,2,4] 6
[1,2,4,8] 1008
[1,2,4,8,16] 20321280
[0, .1, .2,...,1] 6.6586e-028
[1, .5, .25, .125] 0.00384521
[.25, .5, 1, 2, 4] 19.3798828
[1,2,2,3] => 0
: two equal elements in the array, to test if the code checks self-difference (xi-xi
) just by comparing to0
. \$\endgroup\$