diff --git a/doc/roadmap/lib-ext-code-as-docs.md b/doc/roadmap/lib-ext-code-as-docs.md index aadf7da..6d8e67f 100644 --- a/doc/roadmap/lib-ext-code-as-docs.md +++ b/doc/roadmap/lib-ext-code-as-docs.md @@ -26,7 +26,7 @@ | **M1** | 试点 `lib/table` · `lib/text` · `lib/json`(中英)+ public/stdlib | **done** | | **M2** | 其余 `lib/*` 叙述化;禁新脚注取元 | **done** | | **M3–M4** | `ext/web`、`ext/ai`:脚注→链接取元;叙述;示例可逐步换括号调用 | **done**(取元迁移) | -| **M5** | quantum / linalg + full gold | pending | +| **M5** | quantum / linalg + full gold | **done** | ## 2. 验收(出门) @@ -42,3 +42,4 @@ | 2026-09-14 | M1 试点 table/text/json + public/stdlib 标 done | | 2026-09-14 | M2 其余 lib 叙述化标 done | | 2026-09-14 | M3–M4 ext/web+ai 脚注→链接取元 | +| 2026-09-14 | M5 quantum/linalg 叙述 + public/features 取元 | diff --git a/ext/linalg/linalg.mq.md b/ext/linalg/linalg.mq.md index 6530417..230b5ff 100644 --- a/ext/linalg/linalg.mq.md +++ b/ext/linalg/linalg.mq.md @@ -5,6 +5,8 @@ import plugin:lib/plugin.mq.md import sys:lib/sys.mq.md --- +Formula-first linear algebra (English). MatExpr simplify + display; ABI plugin. + ## ensure_plugin Load the ABI v2 `linalg` plugin once. @@ -19,6 +21,8 @@ Load the ABI v2 `linalg` plugin once. ## ping +Plugin health check. + > ensure_plugin *> linalg_ping* @@ -35,6 +39,8 @@ Matrix product (lazy MatMul; shape-checked). + `a` + `b` +Matrix / expression addition. + > ensure_plugin *> linalg_add a=`a` b=`b`* @@ -42,12 +48,16 @@ Matrix product (lazy MatMul; shape-checked). + `a` + `b` +Matrix / expression subtraction. + > ensure_plugin *> linalg_sub a=`a` b=`b`* ## transpose + `expr` +Transpose expression. + > ensure_plugin *> linalg_transpose expr=`expr`* @@ -80,12 +90,16 @@ Display ASCII (default simplify first). Pass `raw=True` to keep the written tree + `expr` + `raw`=False +LaTeX display. + > ensure_plugin *> linalg_latex expr=`expr` raw=`raw`* ## shape + `expr` +Matrix shape (rows, cols). + > ensure_plugin *> linalg_shape expr=`expr`* @@ -102,6 +116,8 @@ Record a formula SVG via host plot channel (default simplify). Returns the expr ## eye + `n` +Identity matrix of order n. + > ensure_plugin *> linalg_eye n=`n`* @@ -109,6 +125,8 @@ Record a formula SVG via host plot channel (default simplify). Returns the expr + `rows` + `cols` +Zero matrix. + > ensure_plugin *> linalg_zeros rows=`rows` cols=`cols`* @@ -140,12 +158,16 @@ Evaluate to dense (default simplify first). ## det + `expr` +Determinant. + > ensure_plugin *> linalg_det expr=`expr`* ## trace + `expr` +Trace. + > ensure_plugin *> linalg_trace expr=`expr`* @@ -292,6 +314,8 @@ Matrix value (`_type=matrix`). Prefer infix `A + B` / `A * B`, or methods `` `A` ## T +Transpose (method). + *> linalg_transpose expr=`self`* ## T_ascii @@ -304,69 +328,99 @@ Transpose then display ASCII (auto-simplified). Handy for lecture identities. ## add + `b` +Matrix / expression addition. + *> linalg_add a=`self` b=`b`* ## sub + `b` +Matrix / expression subtraction. + *> linalg_sub a=`self` b=`b`* ## mul + `b` +Matrix / expression product. + *> linalg_mul a=`self` b=`b`* ## inv +Inverse. + *> linalg_inv expr=`self`* ## simplify +Simplify MatExpr. + *> linalg_simplify expr=`self`* ## ascii +ASCII display. + *> linalg_ascii expr=`self` raw=False* ## latex +LaTeX display. + *> linalg_latex expr=`self` raw=False* ## explicit +Evaluate to an explicit matrix. + *> linalg_explicit expr=`self` raw=False* ## det +Determinant. + *> linalg_det expr=`self`* ## trace +Trace. + *> linalg_trace expr=`self`* ## show + `path`=None + `raw`=False +Show / export the expression. + *> linalg_show expr=`self` path=`path` raw=`raw`* ## eye + `n` +Identity matrix of order n. + *> linalg_eye n=`n`* ## zeros + `rows` + `cols` +Zero matrix. + *> linalg_zeros rows=`rows` cols=`cols`* ## from_list + `data` +Matrix from nested list. + *> linalg_from_list data=`data`* ## from_formula + `formula` +Matrix from formula text. + *> linalg_from_formula formula=`formula`* diff --git a/ext/linalg/线性代数.mq.md b/ext/linalg/线性代数.mq.md index eaa975c..eab4c11 100644 --- a/ext/linalg/线性代数.mq.md +++ b/ext/linalg/线性代数.mq.md @@ -5,6 +5,8 @@ import plugin:lib/plugin.mq.md import sys:lib/sys.mq.md --- +公式优先的线性代数(中文)。矩阵表达式化简与展示;ABI 插件。 + ## 确保插件 加载 ABI v2 `linalg` 插件一次。 @@ -19,6 +21,8 @@ import sys:lib/sys.mq.md ## 探测 +插件探活。 + > 确保插件 *> linalg_ping* @@ -35,6 +39,8 @@ import sys:lib/sys.mq.md + `左` + `右` +矩阵 / 表达式加法。 + > 确保插件 *> linalg_add a=`左` b=`右`* @@ -42,18 +48,24 @@ import sys:lib/sys.mq.md + `左` + `右` +矩阵 / 表达式减法。 + > 确保插件 *> linalg_sub a=`左` b=`右`* ## 转置 + `式` +转置。 + > 确保插件 *> linalg_transpose expr=`式`* ## 逆 + `式` +求逆。 + > 确保插件 *> linalg_inv expr=`式`* @@ -78,12 +90,16 @@ import sys:lib/sys.mq.md + `式` + `原始`=False +LaTeX 展示。 + > 确保插件 *> linalg_latex expr=`式` raw=`原始`* ## 形状 + `式` +形状。 + > 确保插件 *> linalg_shape expr=`式`* @@ -100,6 +116,8 @@ import sys:lib/sys.mq.md ## 单位 + `阶` +对比特施加单位门 / 单位矩阵。 + > 确保插件 *> linalg_eye n=`阶`* @@ -107,12 +125,16 @@ import sys:lib/sys.mq.md + `行` + `列` +零矩阵。 + > 确保插件 *> linalg_zeros rows=`行` cols=`列`* ## 自列表 + `数据` +由嵌套列表构造矩阵。 + > 确保插件 *> linalg_from_list data=`数据`* @@ -136,12 +158,16 @@ import sys:lib/sys.mq.md ## 行列式 + `式` +行列式。 + > 确保插件 *> linalg_det expr=`式`* ## 迹 + `式` +迹。 + > 确保插件 *> linalg_trace expr=`式`* @@ -159,6 +185,8 @@ import sys:lib/sys.mq.md + `左` + `右` +稠密乘。 + > 确保插件 *> linalg_matmul a=`左` b=`右`* @@ -286,6 +314,8 @@ import sys:lib/sys.mq.md ## 转置 +转置。 + *> linalg_transpose expr=`self`* ## 转置文本 @@ -298,70 +328,100 @@ import sys:lib/sys.mq.md ## 加 + `右` +矩阵 / 表达式加法。 + *> linalg_add a=`self` b=`右`* ## 减 + `右` +矩阵 / 表达式减法。 + *> linalg_sub a=`self` b=`右`* ## 乘 + `右` +矩阵 / 表达式乘法。 + *> linalg_mul a=`self` b=`右`* ## 逆 +求逆。 + *> linalg_inv expr=`self`* ## 化简 +化简矩阵表达式。 + *> linalg_simplify expr=`self`* ## 文本 +ASCII 展示。 + *> linalg_ascii expr=`self` raw=False* ## 乳胶 +LaTeX 展示。 + *> linalg_latex expr=`self` raw=False* ## 求值 + `原始`=False +求成显式矩阵。 + *> linalg_explicit expr=`self` raw=`原始`* ## 行列式 +行列式。 + *> linalg_det expr=`self`* ## 迹 +迹。 + *> linalg_trace expr=`self`* ## 展示 + `路径`=None + `原始`=False +展示 / 导出表达式。 + *> linalg_show expr=`self` path=`路径` raw=`原始`* ## 单位 + `阶` +对比特施加单位门 / 单位矩阵。 + *> linalg_eye n=`阶`* ## 零阵 + `行` + `列` +零矩阵。 + *> linalg_zeros rows=`行` cols=`列`* ## 自列表 + `数据` +由嵌套列表构造矩阵。 + *> linalg_from_list data=`数据`* ## 自公式 + `公式` +由公式文本构造矩阵。 + *> linalg_from_formula formula=`公式`* diff --git a/ext/quantum/quantum.mq.md b/ext/quantum/quantum.mq.md index 026a107..10d2b1c 100644 --- a/ext/quantum/quantum.mq.md +++ b/ext/quantum/quantum.mq.md @@ -6,6 +6,8 @@ import sys:lib/sys.mq.md import json:lib/json.mq.md --- +Official quantum circuit simulator (English). Gates + circuits; ABI plugin. + ## ensure_plugin Load the ABI v2 `quantum` plugin once. @@ -57,72 +59,98 @@ State-vector circuit (default |0…0⟩). Optional `steps=` gate table (column o ## h + `qubit`=0 +Hadamard on qubit (default 0). + *> quantum_h circuit=`self` qubit=`qubit`* ## x + `qubit`=0 +Pauli X on qubit. + *> quantum_x circuit=`self` qubit=`qubit`* ## y + `qubit`=0 +Pauli Y on qubit. + *> quantum_y circuit=`self` qubit=`qubit`* ## z + `qubit`=0 +Pauli Z on qubit. + *> quantum_z circuit=`self` qubit=`qubit`* ## s + `qubit`=0 +Phase S on qubit. + *> quantum_s circuit=`self` qubit=`qubit`* ## t + `qubit`=0 +Phase T on qubit. + *> quantum_t circuit=`self` qubit=`qubit`* ## i + `qubit`=0 +Identity on qubit. + *> quantum_i circuit=`self` qubit=`qubit`* ## rx + `qubit`=0 + `theta` +Rotate about X by theta. + *> quantum_rx circuit=`self` qubit=`qubit` theta=`theta`* ## ry + `qubit`=0 + `theta` +Rotate about Y by theta. + *> quantum_ry circuit=`self` qubit=`qubit` theta=`theta`* ## rz + `qubit`=0 + `theta` +Rotate about Z by theta. + *> quantum_rz circuit=`self` qubit=`qubit` theta=`theta`* ## cx + `control`=0 + `target`=1 +CNOT: control → target. + *> quantum_cx circuit=`self` control=`control` target=`target`* ## cz + `control`=0 + `target`=1 +Controlled-Z. + *> quantum_cz circuit=`self` control=`control` target=`target`* ## swap + `a`=0 + `b`=1 +Swap two qubits. + *> quantum_swap circuit=`self` a=`a` b=`b`* ## barrier @@ -229,12 +257,16 @@ Named built-in gate (`name=H`) or custom unitary from `matrix=` (nested list or ## matrix +Explicit matrix of this object. + *> quantum_gate_matrix gate=`self`* ## matches_matrix + `matrix` + `tol`=0.000000001 +Whether this gate matches matrix (tol). + *> quantum_gate_matches_matrix gate=`self` matrix=`matrix` tol=`tol`* ## draw @@ -259,6 +291,8 @@ Density matrix from a state/circuit (`state=`) or an explicit Hermitian `matrix= ## matrix +Explicit matrix of this object. + *> quantum_density_matrix density=`self`* ## purity @@ -283,6 +317,8 @@ Hermitian spectrum → `{eigenvalues, eigenvectors}`. ## expect + `obs` +Expectation value of obs. + *> quantum_density_expect density=`self` obs=`obs`* ## draw diff --git a/ext/quantum/量子.mq.md b/ext/quantum/量子.mq.md index 54b8c6f..bdb9b56 100644 --- a/ext/quantum/量子.mq.md +++ b/ext/quantum/量子.mq.md @@ -6,6 +6,8 @@ import sys:lib/sys.mq.md import json:lib/json.mq.md --- +官方量子电路模拟(中文)。门 + 电路;ABI 插件。 + ## 确保插件 加载 ABI v2 `quantum` 插件。 @@ -31,6 +33,8 @@ import json:lib/json.mq.md + `态` + `分割`=1 +纯态 / 电路的施密特分解。 + > 确保插件 *> quantum_schmidt state=`态` cut=`分割`* @@ -55,72 +59,98 @@ import json:lib/json.mq.md ## 哈达玛 + `比特`=0 +对比特施加哈达玛(默认 0)。 + *> quantum_h circuit=`self` qubit=`比特`* ## 泡利X + `比特`=0 +对比特施加泡利 X。 + *> quantum_x circuit=`self` qubit=`比特`* ## 泡利Y + `比特`=0 +对比特施加泡利 Y。 + *> quantum_y circuit=`self` qubit=`比特`* ## 泡利Z + `比特`=0 +对比特施加泡利 Z。 + *> quantum_z circuit=`self` qubit=`比特`* ## 相位S + `比特`=0 +对比特施加相位 S。 + *> quantum_s circuit=`self` qubit=`比特`* ## 相位T + `比特`=0 +对比特施加相位 T。 + *> quantum_t circuit=`self` qubit=`比特`* ## 单位 + `比特`=0 +对比特施加单位门 / 单位矩阵。 + *> quantum_i circuit=`self` qubit=`比特`* ## 绕X + `比特`=0 + `参数` +绕 X 旋转参数角。 + *> quantum_rx circuit=`self` qubit=`比特` theta=`参数`* ## 绕Y + `比特`=0 + `参数` +绕 Y 旋转参数角。 + *> quantum_ry circuit=`self` qubit=`比特` theta=`参数`* ## 绕Z + `比特`=0 + `参数` +绕 Z 旋转参数角。 + *> quantum_rz circuit=`self` qubit=`比特` theta=`参数`* ## 控非 + `控制`=0 + `目标`=1 +控非门:控制 → 目标。 + *> quantum_cx circuit=`self` control=`控制` target=`目标`* ## 控相 + `控制`=0 + `目标`=1 +控制相位 Z。 + *> quantum_cz circuit=`self` control=`控制` target=`目标`* ## 交换 + `比特甲`=0 + `比特乙`=1 +交换两比特。 + *> quantum_swap circuit=`self` a=`比特甲` b=`比特乙`* ## 屏障 @@ -227,12 +257,16 @@ Pauli 串(左端=高比特)或矩阵期望值。 ## 矩阵 +本对象的显式矩阵。 + *> quantum_gate_matrix gate=`self`* ## 匹配矩阵 + `矩阵` + `容差`=0.000000001 +门是否匹配给定矩阵(容差)。 + *> quantum_gate_matches_matrix gate=`self` matrix=`矩阵` tol=`容差`* ## 绘图 @@ -257,6 +291,8 @@ Pauli 串(左端=高比特)或矩阵期望值。 ## 矩阵 +本对象的显式矩阵。 + *> quantum_density_matrix density=`self`* ## 纯度 @@ -281,6 +317,8 @@ Tr(ρ²)。 ## 期望 + `可观测量` +可观测量的期望值。 + *> quantum_density_expect density=`self` obs=`可观测量`* ## 绘图 diff --git a/public/features/07-linalg.mq.md b/public/features/07-linalg.mq.md index d4c48a0..cbae15e 100644 --- a/public/features/07-linalg.mq.md +++ b/public/features/07-linalg.mq.md @@ -22,8 +22,8 @@ Declare symbols in a table, multiply, transpose — `T_ascii` is one-step displa | 2 | B | 3 | 2 | **`env` = > la.declare table=`shapes`** -**`A` = env[^A]** -**`B` = env[^B]** +**`A` = [A](env)** +**`B` = [B](env)** **`P` = `A` * `B`** **`t` = > `P`.T_ascii** > print text=`t` diff --git a/public/features/07-线性代数.mq.md b/public/features/07-线性代数.mq.md index b930b5b..5fd51a5 100644 --- a/public/features/07-线性代数.mq.md +++ b/public/features/07-线性代数.mq.md @@ -22,8 +22,8 @@ description: ext/linalg 公式文档面 — 声明、中缀、跑通即正确 | 2 | B | 3 | 2 | **`环境` = > la.声明 表=`形状`** -**`A` = 环境[^A]** -**`B` = 环境[^B]** +**`A` = [A](环境)** +**`B` = [B](环境)** **`P` = `A` * `B`** **`t` = > `P`.转置文本** > 打印 内容=`t` diff --git a/public/features/11-csv-text.mq.md b/public/features/11-csv-text.mq.md index 565c6a3..c6145e7 100644 --- a/public/features/11-csv-text.mq.md +++ b/public/features/11-csv-text.mq.md @@ -14,8 +14,8 @@ Parse a tiny CSV, normalize a field, print — no plugins. **raw = "name,city\nAda,london\nBob,PARIS\n"** **rows = > csv.parse text=`raw`** **r0 = > at value=`rows` index=0** -**city = > text.to_upper text=`r0`[^city]** -> print text=`r0`[^name] +**city = > text.to_upper text=[city](`r0`)** +> print text=[name](`r0`) > print text=`city` **n = > len `rows`** 1. `n` == 2 diff --git a/public/features/11-逗号表文本.mq.md b/public/features/11-逗号表文本.mq.md index f5bfa21..790200f 100644 --- a/public/features/11-逗号表文本.mq.md +++ b/public/features/11-逗号表文本.mq.md @@ -14,8 +14,8 @@ description: lib/逗号表 + 加厚 lib/文本(中层 M4) **raw = "name,city\nAda,london\nBob,PARIS\n"** **rows = > 逗号表.解析 内容=`raw`** **r0 = > at value=`rows` index=0** -**city = > 文本.大写 内容=`r0`[^city]** -> 打印 内容=`r0`[^name] +**city = > 文本.大写 内容=[city](`r0`)** +> 打印 内容=[name](`r0`) > 打印 内容=`city` **n = > 长度 `rows`** 1. `n` == 2 diff --git a/public/features/12-list-cli.mq.md b/public/features/12-list-cli.mq.md index a1046b9..738c128 100644 --- a/public/features/12-list-cli.mq.md +++ b/public/features/12-list-cli.mq.md @@ -16,12 +16,12 @@ Zero plugins: parse CSV, sort by key, parse `--input`. **rows = > csv.parse text=`raw`** **rows = > table.sort_by list=`rows` key="name"** **r0 = > at value=`rows` index=0** -> print text=`r0`[^name] +> print text=[name](`r0`) **args = > split value="--input,scores.csv,--pretty" sep=","** **flags = > cli.parse args=`args`** -> print text=`flags`[^input] -1. `flags`[^pretty] +> print text=[input](`flags`) +1. [pretty](`flags`) > print text=mid-m5-ok 2. * > print text=mid-m5-fail diff --git a/public/features/12-列表命令行.mq.md b/public/features/12-列表命令行.mq.md index 0a135b8..0a8475e 100644 --- a/public/features/12-列表命令行.mq.md +++ b/public/features/12-列表命令行.mq.md @@ -16,12 +16,12 @@ description: 表排序/去重 + 命令行解析(中层 M5) **rows = > 逗号表.解析 内容=`raw`** **rows = > 表.按键排序 list=`rows` key="name"** **r0 = > at value=`rows` index=0** -> 打印 内容=`r0`[^name] +> 打印 内容=[name](`r0`) **args = > split value="--input,scores.csv,--pretty" sep=","** **flags = > 命令行.解析 参数=`args`** -> 打印 内容=`flags`[^input] -1. `flags`[^pretty] +> 打印 内容=[input](`flags`) +1. [pretty](`flags`) > 打印 内容=mid-m5-ok 2. * > 打印 内容=mid-m5-fail diff --git a/public/features/14-datetime-url.mq.md b/public/features/14-datetime-url.mq.md index d857008..f127cab 100644 --- a/public/features/14-datetime-url.mq.md +++ b/public/features/14-datetime-url.mq.md @@ -12,8 +12,8 @@ Moments are maps `{unix, zone, iso}`. Parse HTTPS URLs and round-trip query stri # main **epoch = > dt.from_unix unix=0 zone="Asia/Shanghai"** -> print text=`epoch`[^iso] +> print text=[iso](`epoch`) **u = > url.parse text="https://example.com/path?q=1#top"** -> print text=`u`[^host] -> print text=`u`[^query] +> print text=[host](`u`) +> print text=[query](`u`) diff --git a/public/features/14-日期时间地址.mq.md b/public/features/14-日期时间地址.mq.md index d161883..957d736 100644 --- a/public/features/14-日期时间地址.mq.md +++ b/public/features/14-日期时间地址.mq.md @@ -12,8 +12,8 @@ description: 日历时刻 + URL/查询串(Mid2 M7) # main **epoch = > 日时.自戳 秒=0 区="Asia/Shanghai"** -> print text=`epoch`[^iso] +> print text=[iso](`epoch`) **u = > 址.解析 内容="https://example.com/path?q=1"** -> print text=`u`[^host] -> print text=`u`[^query] +> print text=[host](`u`) +> print text=[query](`u`) diff --git a/public/features/15-toml-html-encoding.mq.md b/public/features/15-toml-html-encoding.mq.md index 69957e4..b70c367 100644 --- a/public/features/15-toml-html-encoding.mq.md +++ b/public/features/15-toml-html-encoding.mq.md @@ -13,9 +13,9 @@ Parse a TOML subset for tools, escape HTML before assembly, encode with base32. # main **cfg = > toml.parse text="app = \"demo\"\n[server]\nport = 8080\n"** -> print text=`cfg`[^app] -**srv = `cfg`[^server]** -> print text=`srv`[^port] +> print text=[app](`cfg`) +**srv = [server](`cfg`)** +> print text=[port](`srv`) **safe = > html.escape text=""** > print text=`safe` diff --git a/public/features/15-配置表超文本编码.mq.md b/public/features/15-配置表超文本编码.mq.md index 1c7059d..c4fad58 100644 --- a/public/features/15-配置表超文本编码.mq.md +++ b/public/features/15-配置表超文本编码.mq.md @@ -11,7 +11,7 @@ description: TOML 配置 + HTML 转义 + base32(Mid2 M8) # main **cfg = > 配置.解析 内容="app = \"演示\"\n"** -> print text=`cfg`[^app] +> print text=[app](`cfg`) **safe = > 超.转义 内容=""** > print text=`safe` diff --git a/public/features/16-fs-mid2.mq.md b/public/features/16-fs-mid2.mq.md index 1e3d275..94b1f72 100644 --- a/public/features/16-fs-mid2.mq.md +++ b/public/features/16-fs-mid2.mq.md @@ -15,7 +15,7 @@ import fs:lib/fs.mq.md > fs.write_text path="m9-demo/readme.txt" text="ok" **st = > fs.stat path="m9-demo/readme.txt"** -> print text=`st`[^size] +> print text=[size](`st`) **w = > fs.walk path="m9-demo"** **n = > len `w`** diff --git a/public/features/16-文件mid2.mq.md b/public/features/16-文件mid2.mq.md index c7efe60..ce44d5a 100644 --- a/public/features/16-文件mid2.mq.md +++ b/public/features/16-文件mid2.mq.md @@ -13,7 +13,7 @@ description: 递归目录、遍历与元数据(Mid2 M9) > 文件.写文本 路径="m9-演示/说明.txt" 内容="好" **st = > 文件.状态 路径="m9-演示/说明.txt"** -> print text=`st`[^size] +> print text=[size](`st`) **w = > 文件.遍历 路径="m9-演示"** **n = > 长度 `w`**