Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -1,3 +1,25 @@
|
|||
;Related tasks:
|
||||
* [[Arrays]]
|
||||
* [[Vector]]
|
||||
* [[Matrices]]
|
||||
** [[Determinant and permanent]]
|
||||
*** [[wp:Laplace_expansion|Laplace expansion]] <math>O\bigl(n!\bigr)</math>
|
||||
*** [[wp:Leibniz_formula_for_determinants|Leibniz fomula]] <math>\Omega\bigl(n!\cdot n\bigr)</math>
|
||||
*** [[wp:Bareiss_algorithm|Bareiss algorithm]] <math>O\bigl(n^3\bigr)</math>
|
||||
*** [[wp:LU_decomposition|LU-decomposition]] <math>O\bigl(n^3\bigr)</math>
|
||||
*** [[wp:Strassen_algorithm|Strassen algorithm]] <math>O\bigl(n^{2.807}\bigr)</math>
|
||||
*** [[wp:Coppersmith%E2%80%93Winograd_algorithm|Coppersmith-Winograd algorithm]] <math>O\bigl(n^{2.376}\bigr)</math>
|
||||
*** [[wp:Jean-Fran%C3%A7ois_Le_Gall|Le Gall algorithm]]
|
||||
*** [https://codegolf.stackexchange.com/questions/236835/birds-algorithm-for-computing-determinants Bird's algorithm]
|
||||
* [[Bivector]]
|
||||
* [[Antivector]]
|
||||
* [[Tensor]]
|
||||
* [[Quaternion]]
|
||||
* [[Rotor]]
|
||||
* [[Motor]]
|
||||
* [[Sedenion]]
|
||||
* [[Octonion]]
|
||||
<br>
|
||||
For a given matrix, return the [[wp:Determinant|determinant]] and the [[wp:Permanent_(mathematics)|permanent]] of the matrix.
|
||||
For a matrix of [[wp:Orthonormal_basis|orthonormal basis]] vectors, return the [[wp:Levi-Civita_symbol|Levi-Civita symbol]] of the orthonormal basis vector permutation.
|
||||
|
||||
|
|
@ -6,24 +28,10 @@ The determinant is given by
|
|||
while the permanent is given by
|
||||
:: <big><math> \operatorname{perm}(A)=\sum_\sigma\prod_{i=1}^n M_{i,\sigma_i}</math></big>
|
||||
In both cases the sum is over the permutations <math>\sigma</math> of the permutations of 1, 2, ..., ''n''. (A permutation's sign is 1 if there are an even number of inversions and -1 otherwise; see [[wp:Parity of a permutation|parity of a permutation]].)
|
||||
|
||||
|
||||
;Complexity of known algorithms:
|
||||
* [[wp:Laplace_expansion|Laplace expansion]] <math>O\bigl(n!\bigr)</math>
|
||||
* [[wp:Leibniz_formula_for_determinants|Leibniz fomula]] <math>\Omega\bigl(n!\cdot n\bigr)</math>
|
||||
* [[wp:Bareiss_algorithm|Bareiss algorithm]] <math>O\bigl(n^3\bigr)</math>
|
||||
* [[wp:LU_decomposition|LU-decomposition]] <math>O\bigl(n^3\bigr)</math>
|
||||
* [[wp:Strassen_algorithm|Strassen algorithm]] <math>O\bigl(n^{2.807}\bigr)</math>
|
||||
* [[wp:Coppersmith%E2%80%93Winograd_algorithm|Coppersmith-Winograd algorithm]] <math>O\bigl(n^{2.376}\bigr)</math>
|
||||
* [[wp:Jean-Fran%C3%A7ois_Le_Gall|Le Gall algorithm]]
|
||||
* [https://codegolf.stackexchange.com/questions/236835/birds-algorithm-for-computing-determinants Bird's algorithm]
|
||||
|
||||
|
||||
;Related task:
|
||||
<br><br>
|
||||
;C.f.
|
||||
* [[wp:Computational_complexity_of_matrix_multiplication#Matrix_inversion,_determinant_and_Gaussian_elimination|Computational complexity of matrix multiplication]]
|
||||
* [https://dai.fmph.uniba.sk/courses/FPRO/bird_pearls.pdf Richard Bird Pearls]
|
||||
* [https://dai.fmph.uniba.sk/courses/FPRO/ Funkcionálne programovanie]
|
||||
* [[Permutations by swapping]]
|
||||
|
||||
<br><br>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
#include "mat.hpp"
|
||||
|
||||
template<size_t N, size_t M = N, enum alg A = alg::std>
|
||||
using i32 = mat<int,N,M,A>;
|
||||
|
||||
template<typename T, size_t N, size_t M = N, enum alg A = alg::std>
|
||||
constexpr inline bool test(mat<T,N,M,A>& src);
|
||||
|
||||
int main()
|
||||
{
|
||||
i32<2,2> A =
|
||||
{
|
||||
{ 1, 2},
|
||||
{ 3, 4}
|
||||
};
|
||||
i32<3,3> B =
|
||||
{
|
||||
{-2, 2,-3},
|
||||
{-1, 1, 3},
|
||||
{ 2, 0,-1}
|
||||
};
|
||||
i32<4,4> C =
|
||||
{
|
||||
{ 1, 2, 3, 4},
|
||||
{ 4, 5, 6, 7},
|
||||
{ 7, 8, 9,10},
|
||||
{10,11,12,13}
|
||||
};
|
||||
i32<5,5> D =
|
||||
{
|
||||
{ 0, 1, 2, 3, 4},
|
||||
{ 5, 6, 7, 8, 9},
|
||||
{10, 11, 12, 13, 14},
|
||||
{15, 16, 17, 18, 19},
|
||||
{20, 21, 22, 23, 24}
|
||||
};
|
||||
|
||||
exit(test(A) && test(B) && test(C) && test(D) ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
template<typename T, size_t N, size_t M, enum alg A>
|
||||
constexpr inline bool test(mat<T,N,M,A>& src)
|
||||
{
|
||||
src.println();
|
||||
printf(" permanent: %+e\n", (flt)src.perm());
|
||||
printf("determinant: %+e\n", (flt)src.det());
|
||||
printf(" align/size: %zu/%zu\n", alignof(src), sizeof(src));
|
||||
puts("");
|
||||
return true;
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/* generalized Kronecker delta - antisymmetrizer */
|
||||
template<ari T, size_t N>
|
||||
constexpr int8_t gkd(const std::array<T,N>& v, const std::array<T,N>& orig)
|
||||
{
|
||||
bool trans = 0;
|
||||
for(size_t i = 0; i < orig.size(); i++)
|
||||
{
|
||||
size_t cnt = 0;
|
||||
for(size_t j = 0; j < std::min<size_t>(i + 1,v.size()); j++)
|
||||
if(orig[i] == v[j]) ++cnt;
|
||||
for(size_t j = i + 1; j < v.size(); j++)
|
||||
{
|
||||
if(orig[i] == v[j]) ++cnt;
|
||||
if( v[i] > v[j]) trans += -1;
|
||||
}
|
||||
if(cnt != 1) return 0;
|
||||
}
|
||||
return trans ? -1 : 1;
|
||||
}
|
||||
|
||||
/* generalized permanent delta - complete symmetrizer *
|
||||
* equivalent to abs(gKd(v,orig)) or is_index_sequence */
|
||||
template<ari T, size_t N>
|
||||
inline constexpr int8_t gpd(const std::array<T,N>& v, const std::array<T,N>& orig)
|
||||
{
|
||||
for(auto& i : orig)
|
||||
if(std::count(v.begin(), v.end(), i) != 1) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
require "matrix"
|
||||
|
||||
local arrays = {
|
||||
{ {1, 2},
|
||||
{3, 4} },
|
||||
|
||||
{ {-2, 2, -3},
|
||||
{-1, 1, 3},
|
||||
{ 2, 0, -1} },
|
||||
|
||||
{ { 1, 2, 3, 4},
|
||||
{ 4, 5, 6, 7},
|
||||
{ 7, 8, 9, 10},
|
||||
{10, 11, 12, 13} },
|
||||
|
||||
{ { 0, 1, 2, 3, 4},
|
||||
{ 5, 6, 7, 8, 9},
|
||||
{10, 11, 12, 13, 14},
|
||||
{15, 16, 17, 18, 19},
|
||||
{20, 21, 22, 23, 24} }
|
||||
}
|
||||
|
||||
for arrays as array do
|
||||
local m = matrix.from(array)
|
||||
print(m)
|
||||
print($"\nDeterminant: {m:det()}")
|
||||
print($"Permanent : {m:perm()}\n")
|
||||
end
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
function det-perm ($array) {
|
||||
if($array) {
|
||||
$size = $array.Count
|
||||
function prod($A) {
|
||||
$prod = 1
|
||||
if($A) { $A | foreach{$prod *= $_} }
|
||||
$prod
|
||||
}
|
||||
function generate($sign, $n, $A) {
|
||||
if($n -eq 1) {
|
||||
$i = 0
|
||||
$prod = prod @($A | foreach{$array[$i++][$_]})
|
||||
[pscustomobject]@{det = $sign*$prod; perm = $prod}
|
||||
}
|
||||
else{
|
||||
for($i = 0; $i -lt ($n - 1); $i += 1) {
|
||||
generate $sign ($n - 1) $A
|
||||
if($n % 2 -eq 0){
|
||||
$i1, $i2 = $i, ($n-1)
|
||||
$A[$i1], $A[$i2] = $A[$i2], $A[$i1]
|
||||
}
|
||||
else{
|
||||
$i1, $i2 = 0, ($n-1)
|
||||
$A[$i1], $A[$i2] = $A[$i2], $A[$i1]
|
||||
}
|
||||
$sign *= -1
|
||||
}
|
||||
generate $sign ($n - 1) $A
|
||||
}
|
||||
}
|
||||
$det = $perm = 0
|
||||
generate 1 $size @(0..($size-1)) | foreach{
|
||||
$det += $_.det
|
||||
$perm += $_.perm
|
||||
}
|
||||
[pscustomobject]@{det = "$det"; perm = "$perm"}
|
||||
} else {Write-Error "empty array"}
|
||||
}
|
||||
det-perm 5
|
||||
det-perm @(@(1,0,0),@(0,1,0),@(0,0,1))
|
||||
det-perm @(@(0,0,1),@(0,1,0),@(1,0,0))
|
||||
det-perm @(@(4,3),@(2,5))
|
||||
det-perm @(@(2,5),@(4,3))
|
||||
det-perm @(@(4,4),@(2,2))
|
||||
Loading…
Add table
Add a link
Reference in a new issue