# DMSD Phase 2C — Square Layer

**日期：** 2026-09-30  
**狀態：** COMPLETE  
**Property class：** Non-periodic / exact analytic block summary

---

## 1. 目的

Phase 2A 驗證 parity；Phase 2B 驗證 finite-state residue vectors。

Phase 2C 刻意換成：

\[
Q(n)=\mathbf 1_{\exists r\in\mathbb N:r^2=n}.
\]

平方數不是 fixed-period property，因此不能再依賴有限 residue cycle 完整描述。

但它仍具有 exact block summary。

這使 square 成為：

\[
\boxed{
\text{finite-period property}
\quad\longrightarrow\quad
\text{irregular sparse property}
}
\]

之間非常好的中間測試。

---

## 2. Exact square count

對：

\[
B=[a,b),\qquad 1\le a<b,
\]

其中平方數為：

\[
r^2\in[a,b).
\]

因此：

\[
\boxed{
C_{\square}(a,b)
=
\lfloor\sqrt{b-1}\rfloor
-
\lfloor\sqrt{a-1}\rfloor.
}
\]

這個公式只需要 integer square root。

所以即使：

\[
[a,b)
=
[10^{100},10^{101}),
\]

也不需要枚舉區間元素。

---

## 3. SquareSummary

本輪不只保存 count，而定義：

\[
S_{\square}(B)
=
(
C,
r_{\min},
r_{\max},
q_{\min},
q_{\max}
),
\]

其中：

- \(C\)：平方數個數；
- \(r_{\min}\)：第一個平方根；
- \(r_{\max}\)：最後一個平方根；
- \(q_{\min}=r_{\min}^2\)；
- \(q_{\max}=r_{\max}^2\)。

因此 summary 是：

```text
count
first_root
last_root
first_square
last_square
```

且每個 block 只需要 \(O(1)\) summary state。

---

## 4. 驗證

本輪完成：

```text
Scale checks k=0..100:            101
Hierarchy merge checks:             7
Nested refinement trials:          300
Independent brute-force oracles:   500
```

全部：

```text
PASS
```

其中 500 個小區間使用逐元素 enumeration 作獨立 oracle，
再與 integer-sqrt 公式比較。

所以本輪不是只有「公式自己驗自己」。

---

## 5. Composable Summary

若：

\[
B=\bigsqcup_iB_i
\]

且 children 依數線順序排列，則：

### Count

\[
C(B)=\sum_iC(B_i).
\]

### First square

取第一個 non-empty child 的 first square。

### Last square

取最後一個 non-empty child 的 last square。

因此存在 merge operator：

\[
\boxed{
S_{\square}(B)
=
\bigoplus_iS_{\square}(B_i).
}
\]

這比 Phase 2A / 2B 更進一步：

> DMSD summary 不必只是可加總的 scalar/vector；也可以是具有自訂 merge algebra 的結構化 object。

---

## 6. 第一個 Summary Algebra

可以暫時把 DMSD property layer 寫成：

\[
(\mathcal S_Q,\oplus_Q)
\]

其中：

- \(\mathcal S_Q\)：property summary space；
- \(\oplus_Q\)：disjoint ordered block merge operator。

對 square：

\[
\mathcal S_{\square}
=
(C,r_{\min},r_{\max},q_{\min},q_{\max}).
\]

這給 DMSD 一個新的方向：

\[
\boxed{
\text{Property Layer}
=
\text{Summary State}
+
\text{Merge Algebra}
+
\text{Local Generator}.
}
\]

---

## 7. 非週期，但仍能 coarse-scale exact

這是本輪最重要的概念結果。

Square property 不需要：

```text
fixed period
finite residue state
element enumeration
```

也可以在 coarse block 上 exact。

因此：

\[
\boxed{
\text{Exact coarse summary}
\not\Rightarrow
\text{finite periodicity}.
}
\]

真正需要的可能是：

\[
\boxed{
\text{boundary-computable summary}.
}
\]

平方數就是由：

\[
\sqrt a,\sqrt b
\]

兩個邊界決定整個 block 的 exact count。

---

## 8. 尺度幾何

對 decade：

\[
L_k=[10^k,10^{k+1}),
\]

平方數數量約為：

\[
C_k
\sim
(\sqrt{10}-1)10^{k/2}.
\]

但 block size 為：

\[
|L_k|=9\cdot10^k.
\]

因此 square density 約按：

\[
10^{-k/2}
\]

下降。

換句話說：

\[
\boxed{
\text{absolute square count grows}
}
\]

但：

\[
\boxed{
\text{relative square density shrinks}.
}
\]

這是 multiscale visualization 很適合直接呈現的現象。

---

## 9. Even / Odd Scale Phase

平方根將 exponent：

\[
k
\]

轉成：

\[
k/2.
\]

所以 decimal decade 在 square layer 中自然帶有：

\[
\boxed{k\bmod2}
\]

的兩相尺度幾何。

這與 Phase 2B 的：

\[
10^k\bmod m
\]

不同。

Residue phase 來自 scale base 與 modular algebra 的關係；

Square phase 則來自：

\[
\text{scale exponent}
\mapsto
\frac{1}{2}\text{ scale exponent}.
\]

因此 DMSD 開始能區分不同種類的 scale coupling。

---

## 10. 不是直接宣稱 base-independent

即使「平方數」本身是 base-independent property，

以下可視 pattern：

- decade boundary；
- even/odd \(k\) phase；
- 每層的視覺寬度；
- normalized location；

仍然依賴 decimal scale grammar。

所以應區分：

\[
\boxed{
\text{Property Ontology}
\neq
\text{Scale Projection Geometry}.
}
\]

Square ontology 是 base-independent；

但它在 DMSD decimal projection 中的形狀仍有 representation component。

---

## 11. Mathematical LOD 的第二個層級

現在至少出現兩種 exact property mechanism：

### Class E1 — Finite-state / periodic exact summary

例如：

```text
parity
mod m
```

### Class E2 — Boundary-analytic exact summary

例如：

```text
perfect squares
```

其中 E2 不需要 property 具有有限週期。

所以 DMSD Mathematical LOD 已經從：

```text
periodic counting
```

跨到：

```text
non-periodic analytic counting.
```

---

## 12. MVP

`DMSD_Phase2C_Square_MVP.html` 支援：

- Kmax 到 100；
- Pyramid / Staircase；
- upward / downward traversal；
- exact square count；
- exact first/last root；
- exact first/last square；
- lazy refinement；
- structured-summary merge certificate；
- BigInt integer sqrt。

所以：

\[
10^{100}
\]

尺度上的 square property 也可以直接被互動式瀏覽。

---

## 13. 為什麼這一步比 residue 更接近 prime

平方數已具有：

- 稀疏性；
- density 隨尺度下降；
- gap 隨尺度增加；
- 非 fixed-period；
- 局部位置不由短 residue tuple 完全決定。

但又比 prime 簡單，因為：

\[
\boxed{
\text{square membership}
\leftrightarrow
\text{integer sqrt boundary / equality}
}
\]

給了我們 exact generator 與 summary。

所以 Square Layer 是一個很好的 control：

> 如果未來 prime layer 很難 coarse-scale exact，不代表 DMSD 失敗；而可能只是 prime property 缺少像 square-root boundary 這樣的壓縮 summary operator。

---

## 14. 下一輪

現在已經可以進：

# DMSD Phase 3A — Prime Layer Baseline

但第一輪 Prime Layer 應該非常克制。

只做有限、有明確證書邊界的：

- exact prime count for materialized / computed blocks；
- scale density；
- normalized local positions；
- lazy refinement；
- computation-state 標記；
- **未知區塊不得偽裝成 exact summary**。

最關鍵的差異會是：

```text
Parity / Residue / Square:
coarse block can be exact from compact rule.

Prime:
coarse block may require real computation or external certificate.
```

這正是我們這套 DMSD 最值得看的地方。

---

## 15. 結論

Phase 2C 得到：

\[
\boxed{
S_{\square}(B)
=
\bigoplus_i S_{\square}(B_i)
}
\]

而且：

\[
\boxed{
\text{non-periodic property}
+
\text{exact O(1) block summary}
}
\]

確實可行。

所以 DMSD 的核心已經不只是：

\[
\text{lazy visual rendering}.
\]

而是逐漸形成：

\[
\boxed{
\text{multiscale mathematical state algebra}.
}
\]

---

```text
DMSD Phase 2C: COMPLETE
Validation: PASS

Next:
DMSD Phase 3A — Prime Layer Baseline
```
