| 1 | """Generate exact-fold results with Python's arbitrary-precision integers.""" |
| 2 | from pathlib import Path |
| 3 | import random |
| 4 | |
| 5 | rng = random.Random(733819) |
| 6 | minimum, maximum = -(1 << 63), (1 << 63) - 1 |
| 7 | rows = [] |
| 8 | for _ in range(150): |
| 9 | terms = [] |
| 10 | for _ in range(rng.randrange(1, 24)): |
| 11 | value = rng.choice([maximum, rng.randrange(1, maximum), 1, 2]) |
| 12 | terms += [value, -value] |
| 13 | terms += [rng.choice([minimum, maximum, 0, 1, -1, 42])] |
| 14 | rng.shuffle(terms) |
| 15 | # Preserve the fixture's original spelling; whitespace has no numeric role. |
| 16 | rows.append(("(+" + " ".join(" " + str(v) for v in terms) + ")", sum(terms))) |
| 17 | |
| 18 | base = rng.choice([minimum, maximum, 0, 1, -1, 42]) |
| 19 | terms = [] |
| 20 | for _ in range(rng.randrange(1, 24)): |
| 21 | value = rng.choice([maximum, rng.randrange(1, maximum), 1]) |
| 22 | terms += [value, -value] |
| 23 | rng.shuffle(terms) |
| 24 | rows.append(("(- " + " ".join(map(str, [base] + terms)) + ")", base - sum(terms))) |
| 25 | |
| 26 | factors = [rng.choice([minimum, maximum, 0, -1, 1, 2, -2]) |
| 27 | for _ in range(rng.randrange(3, 40))] |
| 28 | product = 1 |
| 29 | for value in factors: |
| 30 | product *= value |
| 31 | rows.append(("(* " + " ".join(map(str, factors)) + ")", product)) |
| 32 | |
| 33 | output = "# Python arbitrary-integer oracle, seed 733819; expression TAB exact result.\n" |
| 34 | output += "\n".join(source + "\t" + str(value) |
| 35 | for source, value in rows) + "\n" |
| 36 | Path(__file__).with_name("integer_folds.tsv").write_text(output) |
| 37 | print(f"Generated {len(rows)} exact integer folds") |
| 38 | |