| 1 | """Independent signed64 multiplication oracles, computed with Python integers.""" |
| 2 | from pathlib import Path |
| 3 | import random |
| 4 | |
| 5 | root=Path(__file__).resolve().parent |
| 6 | boundaries=[-(1<<63),-(1<<63)+1,-(1<<62),-3037000500,-3037000499, |
| 7 | -2,-1,0,1,2,3037000499,3037000500,1<<62,(1<<63)-2,(1<<63)-1] |
| 8 | pairs={(a,b) for a in boundaries for b in boundaries} |
| 9 | for k in range(64): |
| 10 | for delta in [-1,0,1]: |
| 11 | for sign in [-1,1]: |
| 12 | a=sign*((1<<k)+delta) |
| 13 | if -(1<<63)<=a<(1<<63): |
| 14 | for b in [-3,-2,-1,0,1,2,3]:pairs.add((a,b)) |
| 15 | rng=random.Random(393001) |
| 16 | for _ in range(4096): |
| 17 | ka=rng.randrange(1,65);kb=rng.randrange(1,65) |
| 18 | a=rng.randrange(-(1<<(ka-1)),1<<(ka-1)) |
| 19 | b=rng.randrange(-(1<<(kb-1)),1<<(kb-1)) |
| 20 | pairs.add((a,b)) |
| 21 | rows=['# Independent Python integer products; seed393001; original signed64 operands.', |
| 22 | '# a\tb\tproduct\trepresentation'] |
| 23 | for a,b in sorted(pairs): |
| 24 | product=a*b |
| 25 | kind='integer' if -(1<<63)<=product<(1<<63) else 'big_integer' |
| 26 | rows.append(f'{a}\t{b}\t{product}\t{kind}') |
| 27 | fixture=root/'small_product393.tsv';fixture.write_text('\n'.join(rows)+'\n') |
| 28 | print('Wrote',len(pairs),'independent product pairs',flush=True) |
| 29 | |