From b1fd9cd74a1ff341632d4bcf3ed756a5d722e755 Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Sat, 27 Jul 2024 13:39:25 +0200 Subject: [PATCH] Consider only combinations, not permutations Empirically, if a solution is satisfying, so are all its permutation. So it is sufficient to iterate over all subsets of length `NUM_CELLS` of the small range, which is much faster for larger sizes. Additionally, the iterator is not converted to a list (which leads to a combinatorial sized memory allocation). --- poseidon2_rust_params.sage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poseidon2_rust_params.sage b/poseidon2_rust_params.sage index 3011070..cd7a0f6 100644 --- a/poseidon2_rust_params.sage +++ b/poseidon2_rust_params.sage @@ -461,7 +461,7 @@ def generate_matrix_partial_small_entries(FIELD, FIELD_SIZE, NUM_CELLS): exit(1) elif FIELD == 1: M_circulant = matrix.circulant(vector([F(0)] + [F(1) for _ in range(0, NUM_CELLS - 1)])) - combinations = list(itertools.product(range(2, 6), repeat=NUM_CELLS)) + combinations = itertools.combinations(range(2, 6), NUM_CELLS) for entry in combinations: M = M_circulant + matrix.diagonal(vector(F, list(entry))) print(M)