Refactor executable library handbooks and improve document reading

This commit is contained in:
cflmy committed 2026-11-08 22:19:11 +08:00
1 parent 16c44588d5
commit c50c515c4a
191 files changed
+29572 -7816

No files matched your search

+86 -77
View File
@@ -45,6 +45,10 @@ which binds the Hadamard formula directly into the author gate constructor.
## hadamard
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Hadamard gate handle |
The Hadamard gate creates equal superposition from computational basis states.
Its matrix in the computational basis is one over square-root two times the
matrix with ones on the first row and one then minus one on the second row.
@@ -53,43 +57,43 @@ equal minus combination. This tool returns a named gate handle for later apply.
This tool takes no parameters.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Hadamard gate handle |
> cap.load
*> quantum_gate_new name="H" theta=None matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[The Hadamard gate creates equal superposition from computational basis states](quantum_gate_new(name="H", theta=None, matrix=None))*.
## pauli_x
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Pauli X handle |
Pauli X is the bit-flip gate: a two-by-two matrix that swaps ket-zero and
ket-one. Use it when a lecture needs an explicit NOT on the computational basis.
This tool takes no parameters.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Pauli X handle |
> cap.load
*> quantum_gate_new name="X" theta=None matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Pauli X is the bit-flip gate: a two-by-two matrix that swaps ket-zero and ket-one](quantum_gate_new(name="X", theta=None, matrix=None))*.
## pauli_z
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Pauli Z handle |
Pauli Z applies a phase of minus one to ket-one while leaving ket-zero alone.
Its diagonal matrix is the standard computational-basis Z.
This tool takes no parameters.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Pauli Z handle |
> cap.load
*> quantum_gate_new name="Z" theta=None matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Pauli Z applies a phase of minus one to ket-one while leaving ket-zero alone](quantum_gate_new(name="Z", theta=None, matrix=None))*.
## cnot
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | CNOT gate handle |
The controlled-NOT on two qubits flips the target when the control is ket-one.
Wire order and bit-endianness follow the package convention where qubit 0 is the
rightmost label bit. Prefer applying via circuit tools with explicit control and
@@ -97,103 +101,108 @@ target indices when building lectures step by step.
This tool takes no parameters.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | CNOT gate handle |
> cap.load
*> quantum_gate_new name="CX" theta=None matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[The controlled-NOT on two qubits flips the target when the control is ket-one](quantum_gate_new(name="CX", theta=None, matrix=None))*.
## custom
| 参数 | 类型 | 说明 |
|------|------|------|
| matrix | any | unitary matrix formula or list |
| name | text | optional label defaulting to U |
Build a gate from an explicit unitary given as `matrix`. Authors usually bind a
formula matrix first, then pass that binding. Optional label `name`="U" marks
drawings when the caller omits a name.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| matrix | any | required | unitary matrix formula or list |
| name | text | "U" | optional label defaulting to U |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | custom gate handle |
> cap.load
*> quantum_gate_new name=`name` theta=None matrix=`matrix`*
Use `matrix`, `name`="U" as the inputs for this operation.
Build a gate from an explicit unitary given as `matrix`. Authors usually bind a
formula matrix first, then pass that binding. Optional label `name`="U" marks
drawings when the caller omits a name.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Build a gate from an explicit unitary given as matrix](quantum_gate_new(name=`name`, theta=None, matrix=`matrix`))*.
## matches
| 参数 | 类型 | 说明 |
|------|------|------|
| gate | any | gate handle to test |
| matrix | any | expected unitary |
| tol | number | absolute tolerance |
Teaching check: does `gate` match expected `matrix` within absolute tolerance
`tol`=0.000000001 ? Use after defining a formula so the lecture and the simulator
cannot drift apart.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| gate | any | required | gate handle to test |
| matrix | any | required | expected unitary |
| tol | number | 0.000000001 | absolute tolerance |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | True when matrices match |
> cap.load
*> quantum_gate_matches_matrix gate=`gate` matrix=`matrix` tol=`tol`*
Use `gate`, `matrix`, `tol`=0.000000001 as the inputs for this operation.
Teaching check: does `gate` match expected `matrix` within absolute tolerance
`tol`=0.000000001 ? Use after defining a formula so the lecture and the simulator
cannot drift apart.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Teaching check: does gate match expected matrix within absolute tolerance cannot drift apart.](quantum_gate_matches_matrix(gate=`gate`, matrix=`matrix`, tol=`tol`))*.
## named
| 参数 | 类型 | 说明 |
|------|------|------|
| name | text | Built-in gate name |
| theta | any | Rotation angle or None |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| name | text | "H" | Built-in gate name |
| theta | any | None | Rotation angle or None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Gate handle for circuit.apply |
Use `name`="H", `theta`=None as the inputs for this operation.
Construct built-in `name`="H" with optional `theta`=None . Rx, Ry and Rz require
a numeric angle in radians. The returned gate can be passed to circuit.apply;
creating it never changes a circuit. Supported names are listed above.
> cap.load
*> quantum_gate_new name=`name` theta=`theta` matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Construct built-in name="H" with optional theta=None ](quantum_gate_new(name=`name`, theta=`theta`, matrix=None))*.
## matrix
| 参数 | 类型 | 说明 |
|------|------|------|
| gate | any | Gate handle |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| gate | any | required | Gate handle |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Nested complex entries with re and im |
Use `gate` as the inputs for this operation.
Export the explicit unitary of `gate`. Each complex entry has re and im fields.
Use this to compare a formula with independent expected entries. Reading a gate
matrix neither modifies its handle nor applies the operator to any circuit.
> cap.load
*> quantum_gate_matrix gate=`gate`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Export the explicit unitary of gate](quantum_gate_matrix(gate=`gate`))*.
# gate
| 参数 | 类型 | 说明 |
|------|------|------|
| name | any | Default None |
| theta | number | Default None |
| matrix | any | Default None |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| name | any | None | Default None |
| theta | number | None | Default None |
| matrix | any | None | Default None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Gate handle for circuit.apply |
Inputs: `name`=None, `theta`=None, `matrix`=None (input).
Use `name`=None, `theta`=None, `matrix`=None as the inputs for this operation.
Named built-in gate (name=H) or a custom unitary defined by matrix= (nested lists or a formula matrix fence). Custom gates may set name= (default U). Authors and call-style tools share this object surface.
> cap.load
*> quantum_gate_new name=`name` theta=`theta` matrix=`matrix`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Named built-in gate (name=H) or a custom unitary defined by matrix= (nested lists or a formula matrix fence)](quantum_gate_new(name=`name`, theta=`theta`, matrix=`matrix`))*.
## matrix
@@ -203,38 +212,38 @@ Named built-in gate (name=H) or a custom unitary defined by matrix= (nested list
Return the explicit unitary matrix of this gate handle. Use it to inspect entries or to feed matches_matrix after constructing a gate from a formula.
*> quantum_gate_matrix gate=`self`*
Return *[Return the explicit unitary matrix of this gate handle. Use it to inspect entries or to feed matches_matrix after constructing a gate from a formula.](quantum_gate_matrix(gate=`self`))*.
## matches_matrix
| 参数 | 类型 | 说明 |
|------|------|------|
| matrix | any | Required |
| tol | any | Default 0.000000001 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| matrix | any | required | Required |
| tol | any | 0.000000001 | Default 0.000000001 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | Match within absolute tolerance |
Inputs: `matrix`, `tol`=0.000000001 (input).
Use `matrix`, `tol`=0.000000001 as the inputs for this operation.
Check whether this gate matches the given matrix within absolute tolerance tol. Typical after building a custom gate from a Markdown formula fence in a lecture notebook.
*> quantum_gate_matches_matrix gate=`self` matrix=`matrix` tol=`tol`*
Return *[Check whether this gate matches the given matrix within absolute tolerance tol](quantum_gate_matches_matrix(gate=`self`, matrix=`matrix`, tol=`tol`))*.
## draw
| 参数 | 类型 | 说明 |
|------|------|------|
| path | any | Default None |
| kind | any | Default gate |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | any | None | Default None |
| kind | any | "gate" | Default gate |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | quantum_svg with kind and svg |
Inputs: `path`=None, `kind`="gate" (input).
Use `path`=None, `kind`="gate" as the inputs for this operation.
Draw a gate symbol or a complex-matrix heatmap (kind=gate or matrix). Optional path writes SVG to disk; plots also enter view/CLI through record_plot for the session.
*> quantum_gate_draw gate=`self` path=`path` kind=`kind`*
Return *[Draw a gate symbol or a complex-matrix heatmap (kind=gate or matrix)](quantum_gate_draw(gate=`self`, path=`path`, kind=`kind`))*.