Selaa lähdekoodia

research/codes: minor fixes/improvements

darkfi 1 vuosi sitten
vanhempi
sitoutus
72b7c4e0da
2 muutettua tiedostoa jossa 23 lisäystä ja 17 poistoa
  1. 11 10
      script/research/codes/decode-simple.sage
  2. 12 7
      script/research/codes/punch.sage

+ 11 - 10
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}")
 

+ 12 - 7
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.<z> = 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)