@johnhenry/math 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -139,7 +139,7 @@ Well beyond the original ActionScript scope, the library now spans:
139
139
  | Area | Module(s) | Highlights |
140
140
  |------|-----------|------------|
141
141
  | Numerical linear algebra | `MatrixMath` | LU, QR, Cholesky, symmetric eigen (Jacobi), SVD; `solve`, RREF, rank, null space, least squares, pseudo-inverse, norms, condition number |
142
- | Symbolic calculus | `Symbolic` | expression parser (41 unary elementary functions incl. inverse-trig, reciprocal-trig, hyperbolic/inverse-hyperbolic, `abs`/`log10`/`log2`/`cbrt`/`floor`/`ceil`/`round`/`sign`/`trunc`, and `expm1`/`log1p`/`sigmoid`/`erf`/`relu`, with `arcsin`/`logistic`-style aliases and `\|x\|` bar syntax, plus N-ary `atan2`/`hypot`/`min`/`max`/`gcd`/`lcm`, `log(base, x)`/`clamp(x, lo, hi)`, and `piecewise(cond, expr, ..., otherwise)` with `<`/`<=`/`>`/`>=`/`==`/`!=` comparisons), symbolic differentiation (incl. the multivariate chain rule for the N-ary functions and branch-wise piecewise differentiation) with a u-substitution fallback for `integrate`, algebraic simplification with like-term collection and constant-folding, elementary integration (incl. by-parts, arctan/arcsin forms, and u-substitution), `integrateDefinite` (closed-form first, adaptive-quadrature fallback), `sumSeries` (finite/infinite, closed-form geometric recognition + numeric fallback), Taylor series, `expand`/`substitute`, polynomial `solve`/`factor`, linear `solveSystem`, L'Hopital `limit` (incl. limits at infinity), LaTeX round-trip (`toLatex`/`fromLatex`, incl. `\operatorname{...}`, bracket notation for `abs`/`floor`/`ceil`/`cbrt`, and `\begin{cases}` for piecewise), `evaluateExact` (exact `Rational` evaluation), `evaluateOverStructure` (folds an `Expr` through an arbitrary `Structure`'s own algebra, e.g. for plotting over Z/7Z), and `freeVariables`/`assertVariables` (auto-detect an expression's variables, or opt into strict mode and throw `UndeclaredVariableError` instead of silently resolving an undeclared one to `NaN`) |
142
+ | Symbolic calculus | `Symbolic` | expression parser (41 unary elementary functions incl. inverse-trig, reciprocal-trig, hyperbolic/inverse-hyperbolic, `abs`/`log10`/`log2`/`cbrt`/`floor`/`ceil`/`round`/`sign`/`trunc`, and `expm1`/`log1p`/`sigmoid`/`erf`/`relu`, with `arcsin`/`logistic`-style aliases and `\|x\|` bar syntax, plus N-ary `atan2`/`hypot`/`min`/`max`/`gcd`/`lcm`, `log(base, x)`/`clamp(x, lo, hi)`, and `piecewise(cond, expr, ..., otherwise)` with `<`/`<=`/`>`/`>=`/`==`/`!=` comparisons), symbolic differentiation (incl. the multivariate chain rule for the N-ary functions and branch-wise piecewise differentiation) with a u-substitution fallback for `integrate`, algebraic simplification with like-term collection and constant-folding, elementary integration (incl. by-parts, arctan/arcsin forms, and u-substitution), `integrateDefinite` (closed-form first, adaptive-quadrature fallback), `sumSeries` (finite/infinite, closed-form geometric recognition + numeric fallback), Taylor series, `expand`/`substitute`, polynomial `solve`/`factor`, linear `solveSystem`, L'Hopital `limit` (incl. limits at infinity), LaTeX round-trip (`toLatex`/`fromLatex`, incl. `\operatorname{...}`, bracket notation for `abs`/`floor`/`ceil`/`cbrt`, and `\begin{cases}` for piecewise), `toGLSL`/`toWGSL` (compile an `Expr` to a GLSL ES 3.0 / WGSL expression over float or, with `{ complex: true }`, `vec2` complex numbers; deterministic output, unsupported nodes refused with `ShaderUnsupportedError`), `evaluateExact` (exact `Rational` evaluation), `evaluateOverStructure` (folds an `Expr` through an arbitrary `Structure`'s own algebra, e.g. for plotting over Z/7Z), and `freeVariables`/`assertVariables` (auto-detect an expression's variables, or opt into strict mode and throw `UndeclaredVariableError` instead of silently resolving an undeclared one to `NaN`) |
143
143
  | Number types | `Rational`, `Quaternion`, `DualNumber`, `Interval` | exact bigint rationals, 3D-rotation quaternions, forward-mode autodiff, rigorous interval arithmetic — each also a `Structure` preset |
144
144
  | 4D geometric algebra | `Vec4`, `Bivector4`, `Rotor4`, `GeometricAlgebra4` | a genuine fourth *spatial* dimension (not time): 4D vectors, 6-component bivectors (the 2-planes of 4D), and rotors that generalize `Quaternion` to 4D — including 4D-only **double rotations** (simultaneous, independent rotation in two orthogonal planes at once); built on an internal Cl(4,0) blade engine for correctness (verified against `Quaternion` on their shared 3D subspace). `GeometricAlgebra4` also has the `commutatorProduct` and `leftContraction` operations n-dimensional rigid-body dynamics needs (generalized Euler's equation, point velocity). `Rotor4.factor()`/`renormalize()` implement Perwass-style rotor factorization — the proper fix for numerical drift on a double rotation, where naive magnitude normalization silently produces an invalid rotor (verified against 200+ random plane orientations/angles, including the isoclinic and right-isoclinic degenerate cases) |
145
145
  | Number theory | `NumberTheory` | `bigint` modPow, extended GCD, CRT, Miller–Rabin, Pollard-rho factorization, Legendre/Jacobi |
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Shader code generation for `Expr` trees: GLSL ES 3.0 and WGSL.
3
+ *
4
+ * Output is deterministic (no timestamps, ids or hash ordering): the same tree
5
+ * and options always give the same strings, so callers can golden-test them
6
+ * and cache compiled programs by source text.
7
+ */
8
+ import type { Expr } from "./Symbolic.ts";
9
+ export type ShaderDialect = "glsl" | "wgsl";
10
+ export interface ShaderOptions {
11
+ /**
12
+ * `false` (default): every value is a scalar `float` / `f32`.
13
+ * `true`: every value is a complex number held in a `vec2` (x = real,
14
+ * y = imaginary); the variable `i` (unless listed in `variables`) is the
15
+ * imaginary unit and the helper functions the expression needs are emitted once.
16
+ */
17
+ complex?: boolean;
18
+ /**
19
+ * Free variables the expression may mention; they are emitted as identifiers of the
20
+ * same name and must be in scope where the expression is pasted. Default
21
+ * `["x"]` (real) or `["z"]` (complex). A variable not listed is an error.
22
+ */
23
+ variables?: string[];
24
+ /** When set, `source` is a complete function `name(<variables>)` wrapping the expression. */
25
+ functionName?: string;
26
+ }
27
+ export interface ShaderResult {
28
+ /** The expression text, e.g. `sin(x) * 2.0`. Paste it where a float (or vec2) is wanted. */
29
+ expression: string;
30
+ /** Helper function definitions the expression calls, in dependency order; empty when none are needed. */
31
+ helpers: string;
32
+ /** Complete source: `helpers` followed by the wrapping function when `functionName` was given, else `helpers` and nothing more. */
33
+ source: string;
34
+ /** The free variables actually used, sorted. */
35
+ variables: string[];
36
+ }
37
+ export declare class ShaderUnsupportedError extends Error {
38
+ constructor(message: string);
39
+ }
40
+ export declare function compileShader(expr: Expr, dialect: ShaderDialect, options?: ShaderOptions): ShaderResult;
41
+ //# sourceMappingURL=Shader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Shader.d.ts","sourceRoot":"","sources":["../src/Shader.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,6FAA6F;IAC7F,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,4FAA4F;IAC5F,UAAU,EAAE,MAAM,CAAC;IACnB,yGAAyG;IACzG,OAAO,EAAE,MAAM,CAAC;IAChB,mIAAmI;IACnI,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AA0uBD,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,CA6C3G"}