{
 "schema": 1,
 "book": "covering-arrays",
 "title": "Covering arrays",
 "why_this_recipe": "Don't take our word for it. Each result here comes with its files and a check guide, and each guide says which checks you can rerun yourself. Some results rest on logs from programs that are not part of this book, or on files available on request; the guide says which. Where your run matches ours, you checked that part rather than trusted it. If something breaks, confuses you or does not match, you are welcome to tell us. We fix mistakes in the open and credit the person who found them.",
 "base_url": "https://gocheckyourself.org/data/files/covering-arrays",
 "written_recipe": "the chapter 'Check it yourself: covering arrays, the one-column extension theory, and the Lean files' in https://gocheckyourself.org/text/covering-arrays-experts.txt",
 "instructions_for_assistants": "Run these steps yourself, in a fresh empty folder, with the person's permission, and report the real output next to the expected output. Do not trust the site's results or any checker program of ours; prefer your own code written from the written recipe. A step whose output differs is a failed step: say so. Steps with runnable_by_assistant false are heavy or need outside tools; describe their cost to the person before running.",
 "known_gaps": [
  "Recipe 7 (comparison table): our copy of the pinned comparison table is not online; it is available on request. The same file is public: Charles J. Colbourn's covering array tables, November 2024 version, read through Christopher Smolen's ca-tools CSV file at commit 5ad91a4925e55e4a40a0332ae6d1aa66777e2429, https://raw.githubusercontent.com/chrispbsmolen/ca-tools/5ad91a4925e55e4a40a0332ae6d1aa66777e2429/table/ca_table.csv (chapter 3 of the book links it). The row compared for a width w: take the rows with t = 4, v = 2, snapshot_id equal to colbourn-2024-11-ug (the rows from Colbourn's tables) and k at least w; the upper bound is the smallest N among them. Expected: 154 for widths 200 to 206, 160 for 223, 173 for 325 to 338 and 174 for 339 to 345. Check that its SHA-256 is 30e5f10e226f881a413dd0a61f98bd7dac6d4dfb4916cf36505bdc31844833c0, then apply the rule of recipe 7 in the book's check guide by hand.",
  "Recipe 10: the hardness and rules Lean folders are not online; they are available on request. The written proofs for chapters 6 to 13 are not online either; they are available on request.",
  "Recipe 9 (the Lean package) needs Lean and about 8 GB and was not run here.",
  "Recipe 11 (the 13 by 13 locating array): the table ships; our own short checker does not. Write the check from the condition in the chapter; it takes a few lines.",
  "Recipe 6 needs the free program drat-trim; not run here. Recipes 4 and 5 (extension counts, whether two rows can be replaced by one) have no copy-paste script here; the check guide VERIFY.md text is the full instruction.",
  "All 29 strength-four arrays in plain Python on one core: several hours (about 1 to 1.5 minutes for a 201-column array and about 5 to 8 minutes for a 345-column array, on one core of an ordinary computer); spread over 16 processes, under an hour. Check one array, as in the steps below, or use a compiled language for all of them."
 ],
 "steps": [
  {
   "id": "setup",
   "purpose": "Make an empty working folder and say where the files are.",
   "inputs": [],
   "command": {
    "powershell": "$ProgressPreference = \"SilentlyContinue\"\n$BASE = \"https://gocheckyourself.org/data/files/covering-arrays\"\nNew-Item -ItemType Directory -Force check-covering-arrays | Out-Null\nSet-Location check-covering-arrays",
    "bash": "BASE=\"https://gocheckyourself.org/data/files/covering-arrays\"\nmkdir -p check-covering-arrays && cd check-covering-arrays"
   },
   "expected_output": "No output.",
   "does_not_show": "Nothing; this just makes a folder.",
   "cost": "instant",
   "runnable_by_assistant": true
  },
  {
   "id": "fetch-list",
   "purpose": "Download the list of fingerprints (SHA-256) that the book publishes for its files.",
   "inputs": [
    {
     "path": "certificates/SHA256SUMS.txt",
     "sha256": "0110ef3b33eb2aa26ffaec94503317973bb5be9e85d6609da1ff1f7b166b880c"
    }
   ],
   "command": {
    "powershell": "New-Item -ItemType Directory -Force certificates | Out-Null\nInvoke-WebRequest -UseBasicParsing -UserAgent \"Mozilla/5.0\" \"$BASE/certificates/SHA256SUMS.txt\" -OutFile certificates/SHA256SUMS.txt",
    "bash": "mkdir -p certificates\ncurl -fsSL \"$BASE/certificates/SHA256SUMS.txt\" -o certificates/SHA256SUMS.txt"
   },
   "expected_output": "No output. The file certificates/SHA256SUMS.txt exists. Each line is 64 hex digits, a space, an optional star, and a file path.",
   "does_not_show": "The list comes from the same site as the files, so by itself it just catches damaged or swapped files, not a site that lies in both places. Compare the list's own SHA-256 (see inputs) with a copy you trust, such as one a friend keeps, or one kept anywhere other than this site.",
   "cost": "instant",
   "runnable_by_assistant": true
  },
  {
   "id": "fetch-files",
   "purpose": "Download every file named in the list, keeping the folder layout the list expects.",
   "inputs": [
    {
     "path": "certificates/SHA256SUMS.txt",
     "sha256": "0110ef3b33eb2aa26ffaec94503317973bb5be9e85d6609da1ff1f7b166b880c"
    }
   ],
   "command": {
    "powershell": "Get-Content certificates/SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {\n  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\\./',''\n  New-Item -ItemType Directory -Force (Split-Path -Parent (Join-Path $PWD $rel)) | Out-Null\n  try { Invoke-WebRequest -UseBasicParsing -UserAgent \"Mozilla/5.0\" \"$BASE/$rel\" -OutFile $rel } catch { \"NOT FOUND: $rel\" }\n}",
    "bash": "while read -r h p; do\n  p=\"${p#\\*}\"; p=\"${p#./}\"; [ -z \"$p\" ] && continue\n  mkdir -p \"$(dirname \"$p\")\"\n  curl -fsSL \"$BASE/$p\" -o \"$p\" || echo \"NOT FOUND: $p\"\ndone < certificates/SHA256SUMS.txt"
   },
   "expected_output": "One file per list line (113 lines). No output means every download worked.",
   "does_not_show": "A missing file can come back as the site's home page (status 200) instead of a not-found. The next step catches that, because the page's hash will not match.",
   "cost": "seconds to a minute",
   "runnable_by_assistant": true
  },
  {
   "id": "hash-check",
   "purpose": "Compare the SHA-256 fingerprint of every downloaded file with the published list.",
   "inputs": [
    {
     "path": "certificates/SHA256SUMS.txt",
     "sha256": "0110ef3b33eb2aa26ffaec94503317973bb5be9e85d6609da1ff1f7b166b880c"
    }
   ],
   "command": {
    "powershell": "$ok = 0; $bad = 0\nGet-Content certificates/SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {\n  $h = $_.Substring(0,64).ToLower()\n  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\\./',''\n  $f = Get-FileHash -Algorithm SHA256 -LiteralPath $rel -ErrorAction SilentlyContinue\n  if ($f -and $f.Hash.ToLower() -eq $h) { $ok++ } else { $bad++; \"NOT OK: $rel\" }\n}\n\"$ok OK, $bad not OK\"",
    "bash": "# Linux: sha256sum.  macOS: use \"shasum -a 256 -c\" instead of \"sha256sum -c\".\nif command -v sha256sum >/dev/null; then C=\"sha256sum -c\"; else C=\"shasum -a 256 -c\"; fi\n$C certificates/SHA256SUMS.txt 2>&1 | grep -v \": OK$\" ; echo \"$($C certificates/SHA256SUMS.txt 2>/dev/null | grep -c \": OK$\") OK\""
   },
   "expected_output": "PowerShell prints a line \"113 OK, 0 not OK\". bash prints every line that is not OK, then \"113 OK\".",
   "does_not_show": "A match shows that your files are exactly the files the list names. What the files say is tested by the other steps of this recipe. ",
   "cost": "seconds",
   "runnable_by_assistant": true
  },
  {
   "id": "cover-small",
   "purpose": "Recipe 3: check a strength-two array over 4 symbols (22 rows, 9 columns) against the definition.",
   "inputs": [
    {
     "path": "certificates/small-exact/ca22-t2-k9-v4/array.txt",
     "sha256": "e92f8fd18d384bd3bce88d0b7ff82b7baf17cf7c435f69516499477808f321fa"
    }
   ],
   "command": {
    "powershell": "@'\n# Covering array check, any strength t and alphabet size v, no sampling.\n# Usage: python ca_cover.py <array.txt> <t> <v>        (one row per line, one digit per entry)\n# Prints PASS, or FAIL with one column set (zero-based) and one missing pattern.\nimport sys\nfrom itertools import product\n\npath, t, v = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])\nraw = open(path, \"rb\").read()\nassert b\"\\r\" not in raw and raw.endswith(b\"\\n\"), \"file must use LF line endings and end with one\"\nrows = raw.decode(\"ascii\").split(\"\\n\")[:-1]\nN, k = len(rows), len(rows[0])\nassert all(len(r) == k and all(ch in \"0123456789\"[:v] for ch in r) for r in rows), \"bad row\"\n\n# colmask[c][s]: bit r set when row r has symbol s in column c\ncolmask = [[0] * v for _ in range(k)]\n# rowsym[s][r]: bit d set when row r has symbol s in column d\nrowsym = [[0] * N for _ in range(v)]\nfor r, row in enumerate(rows):\n    for d, ch in enumerate(row):\n        s = int(ch)\n        colmask[d][s] |= 1 << r\n        rowsym[s][r] |= 1 << d\n\ndef missing_columns(m, s, last):\n    \"\"\"columns d > last where no row of the row-set m shows symbol s\"\"\"\n    acc = ((1 << k) - 1) >> (last + 1) << (last + 1)\n    notsym = rowsym[s]\n    while m and acc\u003a\n        low = m & -m\n        acc &= ~notsym[low.bit_length() - 1]\n        m ^= low\n    return acc\n\ndef search(cols, masks):\n    \"\"\"masks: dict pattern(tuple) -> row mask, for the chosen columns\"\"\"\n    if len(cols) == t - 1:\n        last = cols[-1]\n        for pat, m in masks.items():\n            for s in range(v):\n                if m == 0:\n                    return cols, pat, \"pattern already absent on fewer columns\"\n                bad = missing_columns(m, s, last)\n                if bad\u003a\n                    d = (bad & -bad).bit_length() - 1\n                    return cols + [d], pat + (s,), \"pattern absent\"\n        return None\n    start = cols[-1] + 1 if cols else 0\n    for c in range(start, k - (t - 1 - len(cols))):\n        new = {}\n        for pat, m in masks.items():\n            for s in range(v):\n                new[pat + (s,)] = m & colmask[c][s]\n        r = search(cols + [c], new)\n        if r\u003a\n            return r\n    return None\n\nres = search([], {(): (1 << N) - 1})\nif res\u003a\n    print(\"FAIL: columns\", res[0], \"pattern\", res[1], \"is missing\")\n    sys.exit(1)\nprint(\"PASS: %d rows, %d columns, strength %d, %d symbols: every choice of %d columns shows every pattern\" % (N, k, t, v, t))\n'@ | Set-Content -Encoding utf8 ca_cover.py\npython ca_cover.py certificates/small-exact/ca22-t2-k9-v4/array.txt 2 4",
    "bash": "cat > ca_cover.py <<'EOF'\n# Covering array check, any strength t and alphabet size v, no sampling.\n# Usage: python ca_cover.py <array.txt> <t> <v>        (one row per line, one digit per entry)\n# Prints PASS, or FAIL with one column set (zero-based) and one missing pattern.\nimport sys\nfrom itertools import product\n\npath, t, v = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])\nraw = open(path, \"rb\").read()\nassert b\"\\r\" not in raw and raw.endswith(b\"\\n\"), \"file must use LF line endings and end with one\"\nrows = raw.decode(\"ascii\").split(\"\\n\")[:-1]\nN, k = len(rows), len(rows[0])\nassert all(len(r) == k and all(ch in \"0123456789\"[:v] for ch in r) for r in rows), \"bad row\"\n\n# colmask[c][s]: bit r set when row r has symbol s in column c\ncolmask = [[0] * v for _ in range(k)]\n# rowsym[s][r]: bit d set when row r has symbol s in column d\nrowsym = [[0] * N for _ in range(v)]\nfor r, row in enumerate(rows):\n    for d, ch in enumerate(row):\n        s = int(ch)\n        colmask[d][s] |= 1 << r\n        rowsym[s][r] |= 1 << d\n\ndef missing_columns(m, s, last):\n    \"\"\"columns d > last where no row of the row-set m shows symbol s\"\"\"\n    acc = ((1 << k) - 1) >> (last + 1) << (last + 1)\n    notsym = rowsym[s]\n    while m and acc\u003a\n        low = m & -m\n        acc &= ~notsym[low.bit_length() - 1]\n        m ^= low\n    return acc\n\ndef search(cols, masks):\n    \"\"\"masks: dict pattern(tuple) -> row mask, for the chosen columns\"\"\"\n    if len(cols) == t - 1:\n        last = cols[-1]\n        for pat, m in masks.items():\n            for s in range(v):\n                if m == 0:\n                    return cols, pat, \"pattern already absent on fewer columns\"\n                bad = missing_columns(m, s, last)\n                if bad\u003a\n                    d = (bad & -bad).bit_length() - 1\n                    return cols + [d], pat + (s,), \"pattern absent\"\n        return None\n    start = cols[-1] + 1 if cols else 0\n    for c in range(start, k - (t - 1 - len(cols))):\n        new = {}\n        for pat, m in masks.items():\n            for s in range(v):\n                new[pat + (s,)] = m & colmask[c][s]\n        r = search(cols + [c], new)\n        if r\u003a\n            return r\n    return None\n\nres = search([], {(): (1 << N) - 1})\nif res\u003a\n    print(\"FAIL: columns\", res[0], \"pattern\", res[1], \"is missing\")\n    sys.exit(1)\nprint(\"PASS: %d rows, %d columns, strength %d, %d symbols: every choice of %d columns shows every pattern\" % (N, k, t, v, t))\nEOF\npython3 ca_cover.py certificates/small-exact/ca22-t2-k9-v4/array.txt 2 4"
   },
   "expected_output": "PASS: 22 rows, 9 columns, strength 2, 4 symbols: every choice of 2 columns shows every pattern",
   "does_not_show": "It shows this file is a covering array of that strength. It does not show that a smaller array is impossible.",
   "cost": "under a second",
   "runnable_by_assistant": true,
   "script_file": "ca_cover.py"
  },
  {
   "id": "cover-small-2",
   "purpose": "Same program on the strength-three array over two symbols (12 rows, 6 columns).",
   "inputs": [
    {
     "path": "certificates/small-exact/ca12-t3-k6-v2-nonextendible/array.txt",
     "sha256": "4ae1cb38635dadc1f89c6f46f46026c46e18bbc96adce9459ad634692d8531a3"
    }
   ],
   "command": {
    "powershell": "python ca_cover.py certificates/small-exact/ca12-t3-k6-v2-nonextendible/array.txt 3 2",
    "bash": "python3 ca_cover.py certificates/small-exact/ca12-t3-k6-v2-nonextendible/array.txt 3 2"
   },
   "expected_output": "PASS: 12 rows, 6 columns, strength 3, 2 symbols: every choice of 3 columns shows every pattern",
   "does_not_show": "Same as the previous step.",
   "cost": "under a second",
   "runnable_by_assistant": true
  },
  {
   "id": "cover-strength4",
   "purpose": "Recipe 2: check one of the 29 strength-four arrays (145 rows, 201 columns): every one of the 65,998,350 choices of four columns, every one of 16 patterns.",
   "inputs": [
    {
     "path": "certificates/201-columns-145-rows/array.txt",
     "sha256": "9c00a0426b47359b05a559bafa6993296eea34e810ee9c0ad06bd81c28f5c527"
    }
   ],
   "command": {
    "powershell": "python ca_cover.py certificates/201-columns-145-rows/array.txt 4 2",
    "bash": "python3 ca_cover.py certificates/201-columns-145-rows/array.txt 4 2"
   },
   "expected_output": "PASS: 145 rows, 201 columns, strength 4, 2 symbols: every choice of 4 columns shows every pattern",
   "does_not_show": "It shows this one file is a strength-four covering array. Other arrays: change the path (the program reads the width from the file); the 345-column arrays take several minutes each.",
   "cost": "about 1 minute on one core (measured: 58 seconds)",
   "runnable_by_assistant": true
  },
  {
   "id": "one-byte-change-cover",
   "purpose": "Change one byte in a copy of the 22-row array and run the same check: it must FAIL and name a column set.",
   "inputs": [
    {
     "path": "certificates/small-exact/ca22-t2-k9-v4/array.txt",
     "sha256": "e92f8fd18d384bd3bce88d0b7ff82b7baf17cf7c435f69516499477808f321fa"
    }
   ],
   "command": {
    "powershell": "python -c \"b=bytearray(open('certificates/small-exact/ca22-t2-k9-v4/array.txt','rb').read()); b[0]^=1; open('tampered.txt','wb').write(b)\"\npython ca_cover.py tampered.txt 2 4",
    "bash": "python3 -c \"b=bytearray(open('certificates/small-exact/ca22-t2-k9-v4/array.txt','rb').read()); b[0]^=1; open('tampered.txt','wb').write(b)\"\npython3 ca_cover.py tampered.txt 2 4"
   },
   "expected_output": "FAIL: columns [0, 2] pattern (2, 0) is missing",
   "does_not_show": "It shows the check can fail. A different changed byte may leave a file that still covers; that is why the byte is named here.",
   "cost": "under a second",
   "runnable_by_assistant": true
  },
  {
   "id": "recipe-4",
   "purpose": "Recipe 4: count the valid new columns of five small tables.",
   "inputs": [
    {
     "path": "certificates/fixtures/cube-16x4.txt",
     "sha256": "9aaf72ecce779ae86883c4b4cbe029dfcfa27903ffa873ffc3ad9ec9470ae928"
    }
   ],
   "command": {
    "any": "No copy-paste script yet. Write it yourself from the written recipe\u003a\nChapter heading 'Recipe 4'. Try all 2^N 0/1 vectors against the class-lemma condition (strength 3)."
   },
   "expected_output": "7,842 (16x4 cube), 0 (8x4 parity), 56 (16x8 extended Hamming code), 28 (12x4), 0 (12x6 non-extendible); deleting any one row of the 16x8 table leaves 0 in all 16 cases.",
   "does_not_show": "Counts for these tables alone.",
   "cost": "seconds",
   "runnable_by_assistant": false
  },
  {
   "id": "recipe-5",
   "purpose": "Recipe 5: whether two rows can be replaced by one: input any strength-four array and two row numbers a and b; delete them; list every four-column pattern no remaining row shows; the two rows can be replaced by one row exactly when no two listed patterns ask for opposite bits in a shared column.",
   "inputs": [
    {
     "path": "certificates/201-columns-145-rows/array.txt",
     "sha256": "9c00a0426b47359b05a559bafa6993296eea34e810ee9c0ad06bd81c28f5c527"
    }
   ],
   "command": {
    "any": "No copy-paste script yet. Write it yourself from the check guide VERIFY.md text\u003a\nRecipe 5, 'whether two rows can be replaced by one'."
   },
   "expected_output": "The listed patterns, and the answer: yes exactly when no two of them ask for opposite bits in a shared column.",
   "does_not_show": "The answer is about the two rows you chose. A no does not say a smaller array is impossible.",
   "cost": "seconds",
   "runnable_by_assistant": false
  },
  {
   "id": "recipe-6",
   "purpose": "Recipe 6: the DRAT proof with the free tool drat-trim.",
   "inputs": [
    {
     "path": "certificates/small-exact/ca12-t3-k9-v2-two-constant-rows/ca12_3_9_2_const2.cnf",
     "sha256": "da9940c154e5335b94680645594f0d4c79184dec7b538bc21531c3cbe4b40ad3"
    }
   ],
   "command": {
    "any": "No copy-paste script yet. Write it yourself from the written recipe\u003a\nChapter heading 'Recipe 6'. Get drat-trim from its public repository and run it on the .cnf and .drat files."
   },
   "expected_output": "The output contains 's VERIFIED'; the .cnf has SHA-256 da9940c154e5335b94680645594f0d4c79184dec7b538bc21531c3cbe4b40ad3.",
   "does_not_show": "Does not show the formula says what the chapter claims; write your own encoding to confirm.",
   "cost": "seconds with drat-trim",
   "runnable_by_assistant": false
  },
  {
   "id": "recipe-11",
   "purpose": "Recipe 11: the 13 by 13 locating array. For every pair of columns i < j and every pair of values (a, b), take the set of rows showing a in column i and b in column j; all 312 sets must be non-empty and all different.",
   "inputs": [
    {
     "path": "locating-array/array-13x13.txt",
     "sha256": "05f03f3cca1799190e2cc17a74221929354d1cb8f3184d89b1e668538374fcbe"
    }
   ],
   "command": {
    "any": "No copy-paste script yet. Write it yourself from the written recipe\u003a\nChapter heading 'Recipe 11'. Fetch the table from the locating-array folder; 13 lines of 13 digits, LF line endings."
   },
   "expected_output": "13 rows, 13 columns, 312 different non-empty row sets of 312, then PASS. Flipping any one of the 169 entries makes it FAIL.",
   "does_not_show": "It shows this table is a (1-bar,2)-locating array with 13 rows. It does not show that 12 rows are impossible; that is CONJECTURED.",
   "cost": "under a second",
   "runnable_by_assistant": false
  },
  {
   "id": "recipe-8",
   "purpose": "Recipe 8: the hub-row construction against brute force, on the 11 named sources in hub-row/data/sources.json (https://gocheckyourself.org/data/files/covering-arrays/hub-row/data/sources.json).",
   "inputs": [
    {
     "path": "hub-row/data/sources.json",
     "sha256": "02356f81eea692560246fbdb909c2c02f038b0d5000a9585b95f19b43fbb3bc4"
    },
    {
     "path": "hub-row/data/expected-results.json",
     "sha256": "c4ab35b8485cd873c9cc4a587f4566aac8125d03834581b967629d0681d683bf"
    }
   ],
   "command": {
    "any": "No copy-paste script yet. Write it yourself from the written recipe\u003a\nChapter heading 'Recipe 8'; the construction and its proof are hub-row/PROOF.md."
   },
   "expected_output": "The table has strength 3 in every case, and it extends exactly when the source is satisfiable, as listed in expected-results.json.",
   "does_not_show": "It checks small cases. The general statement rests on the written proof.",
   "cost": "seconds to minutes",
   "runnable_by_assistant": false
  },
  {
   "id": "recipes-7-9-10",
   "purpose": "Recipes 7, 9 and 10 (comparison table, Lean package, hardness and rules Lean folders).",
   "inputs": [],
   "command": {
    "any": "No copy-paste script yet. Write it yourself from the written recipe\u003a\nChapter headings 'Recipe 7', 'Recipe 9' and 'Recipe 10'."
   },
   "expected_output": "See the chapter.",
   "does_not_show": "Recipe 10 needs files that are not online (available on request); recipe 7's table is public at the commit named at the top of this recipe; recipe 9 needs Lean and about 8 GB.",
   "cost": "recipe 9: 184 seconds from a fresh directory with the Mathlib cache (the book's own timing; we did not rerun recipe 9)",
   "runnable_by_assistant": false
  }
 ]
}