07-linalgok
Structure
importla:ext/linalg/linalg.mq.md
fn · h1Formula documents with ext/linalg
comment
comment
Idea: if the .mq.md runs and the asserted form matches, the identity holds under the library rules. Algebra reads like a lecture; factorize / lstsq / draw stay explicit calculation steps.
fn · h1main
comment
Declare symbols in a table, multiply, transpose — T_ascii is one-step display (auto-simplify).
bind
`shapes` = [{name: A, rows: 2, cols: 3}, {name: B, rows: 3, cols: 2}]bind
`env` = > la.declare table=`shapes`bind
`A` = [A](`env`)bind
`B` = [B](`env`)bind
`P` = `A` * `B`bind
`t` = > `P`.T_asciicall
> print text=`t`branch
arm
`t` == B^T*A^Tcall
> print text=formula-doc-okarm
elsecall
> print text=formula-doc-failcall
> print text=see-examples-linalg-transposeFunctions
Variables
-
A matrix
_type matrix ascii A cols 3 kind symbol latex A name A … key value _type matrix ascii A cols 3 kind symbol latex A name A rows 2 shape # value 1 2 2 3 -
B matrix
_type matrix ascii B cols 2 kind symbol latex B name B … key value _type matrix ascii B cols 2 kind symbol latex B name B rows 3 shape # value 1 3 2 2 -
P matrix
_type matrix ascii A*B factors List(2) kind mul latex AB shape List(2) key value _type matrix ascii A*B factors # _type ascii cols kind latex name rows shape 1 matrix A 3 symbol A A 2 # value 1 2 2 3 2 matrix B 2 symbol B B 3 # value 1 3 2 2 kind mul latex AB shape # value 1 2 2 2 -
env matrix_env
A Map(8) B Map(8) _type matrix_env key value A key value _type matrix ascii A cols 3 kind symbol latex A name A rows 2 shape # value 1 2 2 3 B key value _type matrix ascii B cols 2 kind symbol latex B name B rows 3 shape # value 1 3 2 2 _type matrix_env -
shapes list · 2
# name rows cols 1 A 2 3 2 B 3 2 # name rows cols 1 A 2 3 2 B 3 2 -
t textB^T*A^TB^T*A^T
Execution
B^T*A^T
formula-doc-ok
see-examples-linalg-transpose
Source
--- title: How to write a linear-algebra formula document description: ext/linalg formula-doc — declare, infix, run-implies-correct import la:ext/linalg/linalg.mq.md --- # Formula documents with ext/linalg Not stdlib. Install: `marqdo ext add linalg` (or build `marqdo_plugin_linalg`). *Idea:* if the `.mq.md` runs and the asserted form matches, the identity holds under the library rules. Algebra reads like a lecture; `factorize` / `lstsq` / `draw` stay explicit calculation steps. # main Declare symbols in a table, multiply, transpose — `T_ascii` is one-step display (auto-simplify). `shapes` = | @ | name | rows | cols | |---|------|------|------| | 1 | A | 2 | 3 | | 2 | B | 3 | 2 | **`env` = > la.declare table=`shapes`** **`A` = [A](env)** **`B` = [B](env)** **`P` = `A` * `B`** **`t` = > `P`.T_ascii** > print text=`t` 1. `t` == "B^T*A^T" > print text=formula-doc-ok 2. * > print text=formula-doc-fail > print text=see-examples-linalg-transpose
Not stdlib. Install:
marqdo ext add linalg(or buildmarqdo_plugin_linalg).