---
title: "quantity / unit / dimension 统一模型"
---

> Documentation Index
> Fetch the complete documentation index at: https://koine.systems/llms.txt
> Use this file to discover all available pages before exploring further.

# quantity / unit / dimension 统一模型

## 背景

pairwise `conversion` 只能表达一条有向的标量换算，无法自然处理厘米、分米、米、千米，也无法表达 `F = ma` 这种量纲公式。Koine 发布时不可能提供全量 quantity 和 unit；用户必须能自行定义。

## 选项

- 继续使用 pairwise `conversion`。
- 只做单位表，不做量纲运算。
- 引入 quantity、unit 和量纲指数运算。
- 语言内置完整 SI 目录。

## 决定

引入三个概念，但只增加两个声明：

- `quantity`：带量纲的值类型；无身份；base quantity 定义量纲基，derived quantity 用量纲等式定义。
- `unit`：某个 quantity 的命名尺度；不是值，不是类型；factor 相对 canonical base。
- `dimension`：quantity 的类型级指数向量；不是运行时值，不单独声明。

```koine
quantity Length

quantity Mass

quantity Time

quantity Acceleration = Length / Time^2

quantity Force = Mass * Acceleration

unit Meter : Length = 1

unit Centimeter : Length = 0.01

unit Kilometer : Length = 1000

unit Second : Time = 1

unit Kilogram : Mass = 1

unit Newton : Force = 1
```

规则：

- quantity 值没有身份、按 canonical 值比较，可以进 relation、define、transition。
- `quantity` 是值层的新类别，但不是 `value` 声明；`value` 继续保持无量纲 newtype/产品值。
- `unit` 有独立命名空间；用户可给已有 quantity 增加 unit，不需要修改 quantity。
- 同一 quantity 的 `+`、`-`、比较要求量纲相同；`*`、`/`、`^` 做指数加减。
- `F = ma` 由类型检查器验证：`Mass * Acceleration = Force`。
- 量纲运算内置，不允许用户自定义运算符重载。
- pairwise `conversion` 不再用于物理单位；K-008 标记 `deprecated`，旧 ADR-0010 保留为历史决策。
- 货币汇率是动态世界数据，仍用 relation/define，不进入 unit。
- 仿射单位（温度）需要 point/delta 模型，不在本次范围内。
- 标准库不是语言概念；quantity/unit 目录可以由用户或普通模块提供。

## 理由

- 用户自定义 base quantity/unit 是开放世界要求，不能依赖全量目录。
- unit 是尺度而不是类型：新增单位是 additive declaration，不修改已有 quantity。
- 量纲公式由类型检查器验证，Agent 不需要记住 pairwise 转换表。
- 连续单位通过 canonical base 自动组合，不需要 O(n²) 转换。
- 与 `value` 分离，避免给所有值增加量纲和算术语义。

## 后果

- 新增 K-028 quantity、K-029 unit、K-030 量纲运算。
- 需要新的规范节、parser/check/experiment 和形式化验证。
- K-008 conversion 标记 deprecated；市场例子移除服务距离，等 unit 原型可用后再加回。
- 货币、温度继续留在模型外；需要时另立点/区间或汇率特性。
- 当前原型只验证声明、单位 factor 和量纲依赖；完整运行时算术是后续工作。

Source: https://koine.systems/notes/decisions/0021-quantity-unit-dimension/index.mdx
