singleton.sage 743 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. K = GF(5)
  2. n = 5
  3. d = 3
  4. # Ambient vector space
  5. V = VectorSpace(K, n)
  6. assert V([1, 1, 0, 0, 0]).hamming_weight() == 2
  7. def is_codespace(W, d):
  8. return all(v.hamming_weight() >= d for v in W if v != 0)
  9. done = False
  10. for j in range(2, n+1):
  11. print(f"trying k={j}")
  12. for W in V.subspaces(j):
  13. if is_codespace(W, d):
  14. C = W
  15. done = True
  16. break
  17. if done:
  18. break
  19. k = C.dimension()
  20. E = V.subspace([
  21. [1, 0, 0, 0, 0],
  22. [0, 1, 0, 0, 0],
  23. ])
  24. #assert C.dimension() == k
  25. assert E.dimension() == d - 1
  26. assert C.intersection(E).dimension() == 0
  27. assert C.dimension() + E.dimension() == (C + E).dimension()
  28. # But C + E are both subspaces of V which is dim N
  29. assert (C + E).dimension() <= n