omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / evidence / deepinfer-flops-pairs / wolfram.md
| 1 | # Wolfram checks for examples/deepinfer |
| 2 | |
| 3 | Every identity, bound and expected value used by `examples/deepinfer` (flops_pairs.om, boundary.txt, |
| 4 | the callers) came from the Wolfram Language evaluator (MCP `WolframLanguageEvaluator`), 2026-10-31. |
| 5 | Each line is `query -> result`. Notation: n = ratio*b + s with b = Quotient[n, ratio], 0 <= s < ratio; |
| 6 | m = 2^63 - 1. |
| 7 | |
| 8 | ## Closed forms (the upstream code is a closed form of a sum) |
| 9 | |
| 10 | - Sum of floor(t/r) over t = 1..n, split into whole blocks and the partial block: |
| 11 | `Simplify[Sum[j r,{j,0,b-1}]+b (s+1) == b (b r+s+1)-r b (b+1)/2]` -> `True` |
| 12 | (the left sum simplifies to `((-1 + b)*b*r)/2 + b*(1 + s)`, the second closed form diff.cpp and |
| 13 | diff.py compare against). |
| 14 | - floor_prefix equals the enumeration on the test grid, with fp[n,r] = b (n+1) - r b (b+1)/2: |
| 15 | `AllTrue[Table[fp[n,r]==Sum[Floor[t/r],{t,1,n}],{n,0,300},{r,1,40}]]` -> `True` |
| 16 | - The `/ 2` is exact: `Resolve[ForAll[b, b∈Integers, Mod[b (b+1),2]==0]]` -> `True` |
| 17 | - capped_prefix: for t >= r*c, floor(t/r) >= c, and for t < r*c, floor(t/r) <= c, so |
| 18 | sum min(floor(t/r), c) = floor_prefix(min(n, r c), r) + (n - min(n, r c)) c: |
| 19 | `Simplify[Floor[(r c+d)/r]>=c, r>0&&c>=0&&d>=1&&integers]` -> `True`; |
| 20 | `Simplify[Floor[(r c-d)/r]<=c, r>0&&c>=0&&d>=0&&integers]` -> `True`; |
| 21 | the capped form against an `Accumulate` of min(floor(t/r), c) over n 0..300, r 1..40, c 0..40 |
| 22 | (493640 cases) -> `True`. |
| 23 | - pairs(begin, end) = prefix(end) - prefix(begin) is the sum over t = begin+1..end by definition of |
| 24 | the prefix sum (no query needed). |
| 25 | |
| 26 | ## Overflow boundaries (where an upstream step leaves int64_t) |
| 27 | |
| 28 | - `Floor[(Sqrt[4 m+1]-1)/2]` -> `3037000499` (n0, largest n with n (n+1) <= m); |
| 29 | `n0 (n0+1) <= m` -> `True`; `(n0+1)(n0+2) > m` -> `True`; `n0 (n0+1)/2` -> `4611686016981624750`. |
| 30 | - `Sum[t,{t,1,3037000500}] <= m` -> `True` and `3037000500*3037000501 > m` -> `True`: the true |
| 31 | floor_prefix(3037000500, 1) fits in int64_t but the upstream step `blocks * (n + 1)` overflows; |
| 32 | Omega traps 1 at the same step (boundary `fp 3037000500 1 | ovf`). |
| 33 | - `2^32*2^31 > m` -> `True` (capped_prefix `ratio * cap` overflows at ratio 2^32, cap 2^31); |
| 34 | `4294967296*2147483648 > 2^63-1` -> `True`; `2^32*2147483647 <= m` -> `True`. |
| 35 | - `2^62` -> `4611686018427387904`; `(2^62-2)*2+3 == m` -> `True`; `(2^62-1)*2 <= m` -> `True`; |
| 36 | `(2^62-1)*2+3 > m` -> `True`; `Sum[Min[t,2],{t,1,2^62+1}] > m` -> `True`. |
| 37 | |
| 38 | ## Expected values (boundary.txt and callers) |
| 39 | |
| 40 | - `Sum[Floor[t/2],{t,1,9}]` -> `20` (fp 9 2) |
| 41 | - `Sum[Min[Floor[t/2],3],{t,1,9}]` -> `18` (cp 9 2 3) |
| 42 | - `Sum[Min[Floor[t/2],3],{t,4,9}]` -> `16` (pairs 3 9 2 3); `Sum[Min[Floor[t/2],3],{t,1,3}]` -> `2` |
| 43 | - `Sum[Floor[t/2],{t,4,9}]` -> `18`, and `Sum[Floor[t/2],{t,1,9}]-Sum[Floor[t/2],{t,1,3}]` -> `18` (pairs 3 9 2 0) |
| 44 | - `Sum[Min[t,512],{t,1,4096}]` -> `1966336` (pairs 0 4096 1 512: a 512-token SWA window over 4096 queries) |
| 45 | - `Sum[t,{t,1,3037000499}]` -> `4611686016981624750`; `Sum[Floor[t/1],{t,1,3037000499}]` -> `4611686016981624750` |
| 46 | - `Sum[Min[t,2],{t,1,2^62}]` -> `9223372036854775807` (cp 2^62 1 2 = m exactly) |
| 47 | - `Sum[Min[t,1],{t,1,2^63-1}]==2^63-1` -> `True` (cp m 1 1, pairs 0 m 1 1) |
| 48 | - `Sum[Min[Floor[t/2^32],2147483647],{t,1,5}]` -> `0`; `Sum[Min[Floor[t/4294967296],2147483647],{t,1,5}]` -> `0` |
| 49 | |
| 50 | ## Overflow measurement controls (overflow-measurement.log) |
| 51 | |
| 52 | - `Mod[2^63-1,7]` -> `0`; `Mod[2^63-2,7]` -> `6`; `Mod[3037000499*3037000500,7]` -> `2`; |
| 53 | `3037000500^2 > 2^63-1` -> `True`. |