From 72b7c4e0da5cf0ebf2ce6da875a129c815d79093 Mon Sep 17 00:00:00 2001 From: darkfi Date: Thu, 1 May 2025 08:06:45 +0200 Subject: [PATCH] research/codes: minor fixes/improvements --- script/research/codes/decode-simple.sage | 21 +++++++++++---------- script/research/codes/punch.sage | 19 ++++++++++++------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/script/research/codes/decode-simple.sage b/script/research/codes/decode-simple.sage index fc391a933..2bcdcadde 100644 --- a/script/research/codes/decode-simple.sage +++ b/script/research/codes/decode-simple.sage @@ -25,16 +25,17 @@ c[1] = 0 table = [] count = 0 total = 0 -for (i0, i1) in itertools.permutations(range(n), int(2)): - g = R.lagrange_polynomial([(α^i0, c[i0]), (α^i1, c[i1])]) - table.append([ - (i0, i1), - g, - "*" if f == g else None - ]) - if f == g: - count += 1 - total += 1 +for i0 in range(n): + for i1 in range(i0+1, n): + g = R.lagrange_polynomial([(α^i0, c[i0]), (α^i1, c[i1])]) + table.append([ + (i0, i1), + g, + "*" if f == g else None + ]) + if f == g: + count += 1 + total += 1 print(tabulate(table)) print(f"{count} / {total}") diff --git a/script/research/codes/punch.sage b/script/research/codes/punch.sage index 58f45d2a5..ff31e451a 100644 --- a/script/research/codes/punch.sage +++ b/script/research/codes/punch.sage @@ -1,3 +1,4 @@ +from tabulate import tabulate q = 11 k = 3 d0 = q - k + 1 @@ -11,19 +12,23 @@ K = GF(q) F. = K[] V = VectorSpace(K, n) -C = V.subspace([ +M = V.subspace([ [1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], ]) -for c in C: - f = c[0] + c[1]*z + c[2]*z^2 +table = [] +for m in M: + f = m[0] + m[1]*z + m[2]*z^2 - w = vector(f(β) for β in list(K)[:n]) - assert len(w) == n + c = vector(f(β) for β in list(K)[:n]) + assert len(c) == n - if w.is_zero(): + if c.is_zero(): continue - assert d <= w.hamming_weight() + table.append((c, c.hamming_weight())) + assert d <= c.hamming_weight() +print(tabulate(table)) +print(d)