# DMSD Horizon Edition v0.5
## Algorithm Plugin + Calibration Layer

**日期：** 2026-09-30  
**狀態：** COMPLETE  
**定位：** 將 v0.4 的 structural cost laws 接上實測 wall-clock calibration

---

# 1. 這一輪和 v0.4 的差別

v0.4 有：

\[
W_Q(n),
\quad
M_Q(n),
\quad
IO_Q(n).
\]

但它仍然只是：

\[
\boxed{
\text{structural / asymptotic cost geometry}.
}
\]

v0.5 開始實際量：

\[
\boxed{
T_Q(n)
}
\]

並建立：

\[
\boxed{
\text{Algorithm Plugin}
+
\text{Environment}
+
\text{Measured Range}
+
\text{Calibration Fit}.
}
\]

所以 Horizon Edition 現在第一次具有：

\[
\boxed{
\text{Measured Compute-Horizon Surface}.
}
\]

---

# 2. Calibration Environment

本輪不是在使用者本機。

實測環境：

```text
OS: Linux x86-64
Python: 3.13.5
logical CPUs: 5
NumPy: 2.3.5
BLAS: OpenBLAS 0.3.30
BLAS threads: 5
OpenBLAS architecture target: SkylakeX
cgroup memory limit: 4 GiB
```

因此：

\[
\boxed{
\text{所有 wall-clock calibration 只屬於本 runtime}.
}
\]

不能直接套到：

- RTX 3070；
- RTX PRO 6000；
- LineShine；
- 任何使用者本機。

---

# 3. 四個 Algorithm Plugins

本輪實際跑：

1. Python bytearray segmented sieve；
2. CPython built-in arbitrary-precision integer multiplication；
3. NumPy/OpenBLAS float64 dense GEMM；
4. Python modular-relation certificate verifier。

每組都做：

- warmup；
- 多次 repeats；
- median wall-clock；
- correctness gate；
- log-log tail fit。

---

# 4. Plugin A — Segmented Sieve

測量範圍：

\[
N=
10^5
\rightarrow
3\times10^7.
\]

最大實測：

\[
\boxed{
N=30,000,000
}
\]

median：

\[
\boxed{
0.23435\text{ s}.
}
\]

prime count：

\[
1,857,859.
\]

---

# 5. Sieve Empirical Scaling

tail fit 使用最後四點：

\[
10^6
\rightarrow
3\times10^7.
\]

擬合：

\[
\log_{10}T
=
a+b\log_{10}N
\]

得到：

\[
\boxed{
b\approx1.15245.
}
\]

\[
R^2_{\log-\log}
\approx
\boxed{0.99910}.
\]

這並不推翻：

\[
N\log\log N
\]

structural model。

在有限 range 上：

\[
N\log\log N
\]

本來就可能局部看起來像：

\[
N^\alpha
\]

且 Python / cache / segmentation overhead 會改變 local slope。

---

# 6. Plugin B — CPython Big Integer Multiplication

測量：

\[
1,024
\rightarrow
4,194,304
\]

bit operands。

最大實測：

\[
\boxed{
4,194,304\text{ bits}
}
\]

約：

\[
524,288\text{ bytes}
\]

per raw operand bit payload。

median multiplication：

\[
\boxed{
0.87850\text{ s}.
}
\]

product：

\[
8,388,608
\]

bits。

---

# 7. Bigint Empirical Scaling

tail range：

\[
65,536
\rightarrow
4,194,304
\]

bits。

fit：

\[
\boxed{
b\approx1.62411.
}
\]

\[
R^2
\approx
\boxed{0.99993}.
\]

所以目前這個 CPython implementation 在這個 range 的實測 growth 明顯：

\[
< b^2
\]

但：

\[
> b\log b
\]

的最簡單理想形狀。

這很合理，
因為 arbitrary-precision runtime 會隨 size 切換不同 multiplication regime。

---

# 8. Plugin C — NumPy / OpenBLAS DGEMM

矩陣尺寸：

\[
128
\rightarrow
1280.
\]

最大實測：

\[
1280\times1280.
\]

median：

\[
\boxed{
0.02629\text{ s}.
}
\]

對應：

\[
2n^3
\]

classical FLOP count，

effective：

\[
\boxed{
159.57\text{ GFLOP/s}
}
\]

為本 sweep 最佳點。

---

# 9. 為什麼 GEMM 全域 slope 看起來只有 2 左右

如果把：

\[
128
\rightarrow1280
\]

全部一起 fit，

小矩陣會被：

- function dispatch；
- BLAS startup；
- cache；
- threading overhead；

強烈影響。

所以 all-size slope 約：

\[
2.05.
\]

但只看最後四點：

\[
512
\rightarrow1280,
\]

得到：

\[
\boxed{
b\approx2.93562.
}
\]

\[
R^2
\approx
0.99815.
\]

這才接近 classical：

\[
\boxed{
n^3
}
\]

geometry。

這是 calibration layer 必須存在的最佳例子。

---

# 10. GEMM Memory Gate

若 A/B/C 三個 float64 dense matrices 同時 resident：

\[
M(n)
\approx
3n^2\times8
=
24n^2
\text{ bytes}.
\]

目前 container memory cap：

\[
4\text{ GiB}.
\]

因此理想化 resident upper bound：

\[
24n^2
\le
4\text{ GiB}
\]

得到：

\[
\boxed{
n\lesssim13,377.
}
\]

還沒有扣：

- Python；
- NumPy metadata；
- BLAS buffers；
- OS / runtime；

所以實際安全上限應更低。

這證明：

\[
\boxed{
\text{Time Fit Horizon}
\neq
\text{Executable Horizon}.
}
\]

---

# 11. Plugin D — Arithmetic Relation Certificate Verification

本輪 certificate 不是 Pratt / SNARK。

它是明確定義的 synthetic arithmetic trace：

\[
(a,b,c)
\]

驗證：

\[
a\cdot b\bmod(2^{61}-1)=c.
\]

這樣可以校準：

\[
\boxed{
\text{linear local-check verifier}.
}
\]

---

# 12. Certificate Benchmark

測量：

\[
1,000
\rightarrow
300,000
\]

relations。

最大點：

\[
300,000
\]

relations，

median：

\[
\boxed{
0.05503\text{ s}.
}
\]

約：

\[
\boxed{
5.45\times10^6
}
\]

relations/s。

---

# 13. Certificate Scaling

tail fit：

\[
10,000
\rightarrow300,000
\]

relations。

得到：

\[
\boxed{
b\approx1.00462.
}
\]

\[
R^2
\approx
\boxed{0.99978}.
\]

非常接近：

\[
\Theta(C).
\]

這和 v0.4 generic linear certificate law 對上。

---

# 14. 四種 Empirical Slopes

本 runtime：

| Plugin | Tail empirical exponent |
|---|---:|
| Segmented sieve | 1.152 |
| Python bigint multiply | 1.624 |
| Dense GEMM | 2.936 |
| Certificate verify | 1.005 |

因此同一個：

\[
\log_{10}\text{input}
\]

往右移一格，
四種 task 的 wall-clock 增長完全不同。

這就是：

\[
\boxed{
\text{Task Geometry}
}
\]

真正被實測出來。

---

# 15. Calibration Fit

每個 plugin 保存：

```text
measurement range
tail fit range
tail slope
tail intercept
R²
in-sample log residual
environment
implementation
```

形式：

\[
\boxed{
\log_{10}T
=
a+b\log_{10}x.
}
\]

注意：

這是：

\[
\boxed{
\text{local empirical fit}.
}
\]

不是 global complexity theorem。

---

# 16. Fit Residual

四個 tail fits 的：

\[
R^2
\]

全部：

\[
>0.998.
\]

in-sample log10 RMSE 約：

\[
0.008
\rightarrow0.019.
\]

對應 multiplicative residual 約只有幾個百分點量級。

但：

\[
\boxed{
\text{in-sample fit quality}
\neq
\text{far extrapolation reliability}.
}
\]

---

# 17. Horizon Projection States

v0.5 對 fit inversion 分三類：

## MEASURED_RANGE

projection 落在 calibration range 內。

## NEAR_EXTRAPOLATION

超過最大 measured input，
但不超過 10 倍。

## FAR_EXTRAPOLATION

超過：

\[
10\times
\]

最大 measured input。

因此：

> 一天可以跑到哪裡

如果只是由 local power fit 推出去，
通常會被標成：

\[
\boxed{
\texttt{FAR\_EXTRAPOLATION}.
}
\]

不是 benchmark fact。

---

# 18. 1-Second Near-Horizon

依 tail local fit：

### Sieve

約：

\[
1.05\times10^8
\]

upper-bound input。

這是約 3.5 倍最大實測，
標：

```text
NEAR_EXTRAPOLATION
```

### Bigint multiply

約：

\[
4.60\times10^6
\]

bits。

和最大實測：

\[
4.19\times10^6
\]

非常接近。

### GEMM

約：

\[
n\approx4,357.
\]

仍是 near extrapolation。

### Certificate

fit 約：

\[
5.32\times10^6
\]

relations，

已超最大實測 17 倍，

所以直接標：

```text
FAR_EXTRAPOLATION
```

---

# 19. 為什麼不把 1-day Fit 當預測

例如 local sieve power fit 若直接推一天，
會得到：

\[
\sim2.0\times10^{12}.
\]

這不是本輪實測結果。

它跨越：

\[
\sim67,000\times
\]

最大 measured \(N\)。

期間可能改變：

- memory hierarchy；
- base-prime overhead；
- scheduling；
- algorithm implementation；
- swap / storage；
- system thermal behavior。

所以：

\[
\boxed{
2\times10^{12}
}
\]

只能叫：

```text
FAR EXTRAPOLATED MODEL POINT
```

不能叫：

```text
this machine can sieve to 2e12/day
```

---

# 20. Resource-Capped Horizon

最重要的改進是：

\[
\boxed{
H_{\rm executable}
=
\min(
H_{\rm time-fit},
H_{\rm memory},
H_{\rm storage},
H_{\rm algorithm-admission}
).
}
\]

例如 GEMM local fit 一天：

\[
n\sim2.09\times10^5.
\]

但 resident-memory model 在 4 GiB cap 下：

\[
n\lesssim13,377.
\]

所以 v0.5 不輸出：

> 一天可以算 \(n=209,000\)。

而保存：

```text
time-fit horizon: ~209k
resource-capped horizon: ~13.4k
limiting axis: memory
```

這才是 Horizon runtime 應該做的。

---

# 21. Calibration Object

正式定義：

\[
\boxed{
\mathcal C_Q
=
(
Q,
A,
E,
R,
\hat T,
\epsilon,
G
)
}
\]

其中：

- \(Q\)：task family；
- \(A\)：algorithm / implementation；
- \(E\)：environment；
- \(R\)：measurement range；
- \(\hat T\)：empirical fit；
- \(\epsilon\)：fit residual；
- \(G\)：resource gates。

---

# 22. Algorithm Plugin

一個 Algorithm Plugin 至少包含：

```text
task family
implementation
input coordinate
work metric
structural reference
measurement range
benchmark data
fit
resource model
correctness verifier
```

未來同一 task 可以有多個 plugin。

例如 multiplication：

```text
CPython int
GMP
Rust num-bigint
GPU FFT
custom ISQL arithmetic
```

全部可以放到同一 Horizon Map 比較。

---

# 23. v0.4 / v0.5 的關係

v0.4：

\[
\boxed{
W_Q(n)
}
\]

回答：

> 理論上 work 怎麼長？

v0.5：

\[
\boxed{
T_{Q,A,E}(n)
}
\]

回答：

> 這個實作，在這個環境，實際怎麼長？

因此：

\[
\boxed{
\text{Structural Law}
\neq
\text{Implementation Calibration}.
}
\]

但兩者可以互相檢查。

---

# 24. Correctness Gates

本輪不是只跑 timer。

另外驗證：

### Sieve

對：

\[
10^5,3\times10^5,10^6
\]

用 independent simple sieve 比對。

並確認：

\[
\pi(10^6)=78,498.
\]

### Bigint

檢查：

\[
(ab)/a=b.
\]

### GEMM

8×8 使用 explicit triple-sum 對照 NumPy。

### Certificate

正 certificate：

```text
PASS
```

修改一個 relation：

```text
FAIL
```

---

# 25. Validation Result

Correctness gates：

```text
PASS
```

Fit quality gates：

```text
PASS
```

四個 tail：

\[
R^2>0.998.
\]

所以：

\[
\boxed{
\text{v0.5 Calibration Dataset VALID}
}
\]

在目前註冊環境範圍內成立。

---

# 26. MVP

v0.5 MVP 可以：

- 選 algorithm plugin；
- 看所有 measured points；
- 看 log-log fit；
- 顯示 tail slope；
- 顯示 measured range；
- 切換 time budget；
- 顯示 MEASURED / NEAR / FAR extrapolation；
- 顯示 GEMM memory cap；
- 顯示 implementation / environment。

因此 Horizon Edition 從：

\[
\text{theoretical map}
\]

正式進入：

\[
\boxed{
\text{measured map}.
}
\]

---

# 27. 現在完整 Horizon Pipeline

目前可以寫成：

\[
\boxed{
\text{Scale}
\rightarrow
\text{Task Family}
\rightarrow
\text{Algorithm Plugin}
\rightarrow
\text{Calibration}
\rightarrow
\text{Capacity / Resource Gates}
\rightarrow
\text{Executable Horizon}.
}
\]

這已經不再只是 Big-O calculator。

---

# 28. 下一步

下一輪最值得做：

# Horizon Edition v0.6 — Cross-Algorithm Competition

同一 task 註冊多個 algorithms。

例如：

### Integer Multiplication

```text
schoolbook reference
CPython current implementation
GMP if available
FFT-like proxy
```

### Prime-domain computation

```text
trial division
segmented sieve
probabilistic test
certificate verifier
```

然後找：

\[
\boxed{
\text{Algorithm Crossover}.
}
\]

也就是：

> 到什麼 size，A 比 B 好？

這樣 Horizon Map 就可以自動選：

\[
\boxed{
A^*(n,C,B).
}
\]

---

# 29. 結論

v0.5 最重要的不是：

> 這台 runtime 一秒能跑多少。

而是正式建立：

\[
\boxed{
\text{Theory}
\rightarrow
\text{Implementation}
\rightarrow
\text{Measurement}
\rightarrow
\text{Fit}
\rightarrow
\text{Resource Gate}
\rightarrow
\text{Horizon}.
}
\]

因此「能算到哪裡」現在第一次有：

\[
\boxed{
\text{實測校準層}.
}
\]

---

```text
DMSD Horizon Edition v0.5: COMPLETE
Algorithm Plugins: 4
Measured Calibration: PASS
Correctness Gates: PASS
Resource-Capped Horizon: ENABLED

Next:
v0.6 — Cross-Algorithm Competition
```
