A code correcting \(t = \lfloor (d-1)/2 \rfloor\) errors has disjoint balls of radius \(t\), so \(|C| \le q^n / \sum_{i \le t} \binom{n}{i}(q-1)^i\).
Details
A code meeting it is PERFECT, and perfect codes barely exist: over a prime power alphabet the only ones are the trivial codes, the Hamming codes and the two Golay codes.
Examples
morie_hamming_bound(n = 5L, d = 5L)
#> $bound
#> [1] 2
#>
#> $bound_exact
#> [1] "2"
#>
#> $errors_corrected
#> [1] 2
#>
#> $ball_volume
#> [1] 16
#>
#> $total_words
#> [1] "32"
#>
#> $is_perfect_possible
#> [1] TRUE
#>
#> $n
#> [1] 5
#>
#> $d
#> [1] 5
#>
#> $q
#> [1] 2
#>
#> $method
#> [1] "Hamming sphere-packing bound (Hamming 1950)"
#>
