feat(linalg): L6 lstsq, norms, complex dtype, draw themes

Add QR/SVD least squares, norm/cond/rank, complex dense Frobenius
baseline, and light/dark/bw draw themes aligned with quantum Q8.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-07 14:47:30 +08:00
1 parent 01287d9e7e
commit c0fbe9b182
15 files changed
+910 -136

No files matched your search

+8 -18
View File
@@ -1,13 +1,13 @@
---
title: Least squares via QR
description: Overdetermined Ax≈b with ext/linalg QR + heatmap.
title: Least squares via lstsq
description: Overdetermined Ax≈b with ext/linalg lstsq + heatmap.
import la:ext/linalg/linalg.mq.md
import math:lib/math.mq.md
---
# Least squares from a runnable document
Fit a line through three points with an overdetermined `A x ≈ b`. Factor `A = QR`, form `Qᵀ b`, then solve the square upper-triangular `R`. A heatmap makes the design matrix visible in `view`.
Fit a line through three points with an overdetermined `A x ≈ b` using `lstsq` (QR path). A heatmap makes the design matrix visible in `view`.
# main
@@ -24,22 +24,12 @@ $$
*`A` = > la.from_formula formula=`A`*
*`b` = > la.from_formula formula=`b`*
*`_` = > la.draw factor=`A` kind="heatmap" path="ls-heatmap.svg"*
*`_` = > la.draw factor=`A` kind="heatmap" theme="light" path="ls-heatmap.svg"*
*`qr` = > la.factorize matrix=`A` kind="qr"*
*`Q` = qr[^Q]*
*`R` = qr[^R]*
*`Qt` = > la.transpose expr=`Q`*
*`Qtb` = > la.matmul a=`Qt` b=`b`*
*`sol` = > la.solve a=`R` b=`Qtb`*
*`x` = sol[^x]*
*`Ax` = > la.matmul a=`A` b=`x`*
*`r0` = > at value=Ax[^data] index=0*
*`ax0` = > at value=`r0` index=0*
*`diff` = > math.sub a=`ax0` b=1*
*`diff` = > math.abs value=`diff`*
*`ls` = > la.lstsq a=`A` b=`b`*
*`x` = ls[^x]*
*`resid` = ls[^residual_fro]*
> print text=`x`
> print text=`diff`
> print text=`resid`
> print text=ls-ok