universal-physics-tensor 0.4.5
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/LICENSE +21 -0
- package/README.md +377 -0
- package/dist/bridges/equations/be-11-decoherence-master.d.ts +83 -0
- package/dist/bridges/equations/be-11-decoherence-master.d.ts.map +1 -0
- package/dist/bridges/equations/be-11-decoherence-master.js +116 -0
- package/dist/bridges/equations/be-11-decoherence-master.js.map +1 -0
- package/dist/bridges/equations/be-12-coherence-length.d.ts +80 -0
- package/dist/bridges/equations/be-12-coherence-length.d.ts.map +1 -0
- package/dist/bridges/equations/be-12-coherence-length.js +128 -0
- package/dist/bridges/equations/be-12-coherence-length.js.map +1 -0
- package/dist/bridges/equations/be-13-einstein-trace.d.ts +89 -0
- package/dist/bridges/equations/be-13-einstein-trace.d.ts.map +1 -0
- package/dist/bridges/equations/be-13-einstein-trace.js +143 -0
- package/dist/bridges/equations/be-13-einstein-trace.js.map +1 -0
- package/dist/bridges/equations/be-14-ryu-takayanagi.d.ts +67 -0
- package/dist/bridges/equations/be-14-ryu-takayanagi.d.ts.map +1 -0
- package/dist/bridges/equations/be-14-ryu-takayanagi.js +112 -0
- package/dist/bridges/equations/be-14-ryu-takayanagi.js.map +1 -0
- package/dist/bridges/equations/be-15-emergence.d.ts +164 -0
- package/dist/bridges/equations/be-15-emergence.d.ts.map +1 -0
- package/dist/bridges/equations/be-15-emergence.js +204 -0
- package/dist/bridges/equations/be-15-emergence.js.map +1 -0
- package/dist/bridges/equations/be-16-landauer.d.ts +180 -0
- package/dist/bridges/equations/be-16-landauer.d.ts.map +1 -0
- package/dist/bridges/equations/be-16-landauer.js +206 -0
- package/dist/bridges/equations/be-16-landauer.js.map +1 -0
- package/dist/bridges/equations/be-17-einstein-cartan.d.ts +245 -0
- package/dist/bridges/equations/be-17-einstein-cartan.d.ts.map +1 -0
- package/dist/bridges/equations/be-17-einstein-cartan.js +304 -0
- package/dist/bridges/equations/be-17-einstein-cartan.js.map +1 -0
- package/dist/bridges/equations/be-18-higgs-mass.d.ts +65 -0
- package/dist/bridges/equations/be-18-higgs-mass.d.ts.map +1 -0
- package/dist/bridges/equations/be-18-higgs-mass.js +86 -0
- package/dist/bridges/equations/be-18-higgs-mass.js.map +1 -0
- package/dist/bridges/equations/be-19-quantum-bounce.d.ts +72 -0
- package/dist/bridges/equations/be-19-quantum-bounce.d.ts.map +1 -0
- package/dist/bridges/equations/be-19-quantum-bounce.js +151 -0
- package/dist/bridges/equations/be-19-quantum-bounce.js.map +1 -0
- package/dist/bridges/equations/be-20-vacuum-energy.d.ts +72 -0
- package/dist/bridges/equations/be-20-vacuum-energy.d.ts.map +1 -0
- package/dist/bridges/equations/be-20-vacuum-energy.js +115 -0
- package/dist/bridges/equations/be-20-vacuum-energy.js.map +1 -0
- package/dist/bridges/equations/be-21-kss-bound.d.ts +72 -0
- package/dist/bridges/equations/be-21-kss-bound.d.ts.map +1 -0
- package/dist/bridges/equations/be-21-kss-bound.js +103 -0
- package/dist/bridges/equations/be-21-kss-bound.js.map +1 -0
- package/dist/bridges/equations/be-22-topological-entanglement.d.ts +90 -0
- package/dist/bridges/equations/be-22-topological-entanglement.d.ts.map +1 -0
- package/dist/bridges/equations/be-22-topological-entanglement.js +123 -0
- package/dist/bridges/equations/be-22-topological-entanglement.js.map +1 -0
- package/dist/bridges/equations/be-23-syk-planckian.d.ts +89 -0
- package/dist/bridges/equations/be-23-syk-planckian.d.ts.map +1 -0
- package/dist/bridges/equations/be-23-syk-planckian.js +155 -0
- package/dist/bridges/equations/be-23-syk-planckian.js.map +1 -0
- package/dist/bridges/equations/be-24-foerster-fret.d.ts +81 -0
- package/dist/bridges/equations/be-24-foerster-fret.d.ts.map +1 -0
- package/dist/bridges/equations/be-24-foerster-fret.js +121 -0
- package/dist/bridges/equations/be-24-foerster-fret.js.map +1 -0
- package/dist/bridges/equations/be-25-iit-phi.d.ts +220 -0
- package/dist/bridges/equations/be-25-iit-phi.d.ts.map +1 -0
- package/dist/bridges/equations/be-25-iit-phi.js +259 -0
- package/dist/bridges/equations/be-25-iit-phi.js.map +1 -0
- package/dist/bridges/equations/be-25-orch-or.d.ts +78 -0
- package/dist/bridges/equations/be-25-orch-or.d.ts.map +1 -0
- package/dist/bridges/equations/be-25-orch-or.js +121 -0
- package/dist/bridges/equations/be-25-orch-or.js.map +1 -0
- package/dist/bridges/equations/be-26-dna-tunneling.d.ts +75 -0
- package/dist/bridges/equations/be-26-dna-tunneling.d.ts.map +1 -0
- package/dist/bridges/equations/be-26-dna-tunneling.js +138 -0
- package/dist/bridges/equations/be-26-dna-tunneling.js.map +1 -0
- package/dist/bridges/equations/be-27-effective-temperature.d.ts +81 -0
- package/dist/bridges/equations/be-27-effective-temperature.d.ts.map +1 -0
- package/dist/bridges/equations/be-27-effective-temperature.js +120 -0
- package/dist/bridges/equations/be-27-effective-temperature.js.map +1 -0
- package/dist/bridges/equations/be-28-onsager-entropy-production.d.ts +175 -0
- package/dist/bridges/equations/be-28-onsager-entropy-production.d.ts.map +1 -0
- package/dist/bridges/equations/be-28-onsager-entropy-production.js +203 -0
- package/dist/bridges/equations/be-28-onsager-entropy-production.js.map +1 -0
- package/dist/bridges/equations/be-29-jarzynski.d.ts +86 -0
- package/dist/bridges/equations/be-29-jarzynski.d.ts.map +1 -0
- package/dist/bridges/equations/be-29-jarzynski.js +132 -0
- package/dist/bridges/equations/be-29-jarzynski.js.map +1 -0
- package/dist/bridges/equations/be-30-flm-first-law.d.ts +93 -0
- package/dist/bridges/equations/be-30-flm-first-law.d.ts.map +1 -0
- package/dist/bridges/equations/be-30-flm-first-law.js +109 -0
- package/dist/bridges/equations/be-30-flm-first-law.js.map +1 -0
- package/dist/bridges/equations/be-31-causal-set-bd.d.ts +96 -0
- package/dist/bridges/equations/be-31-causal-set-bd.d.ts.map +1 -0
- package/dist/bridges/equations/be-31-causal-set-bd.js +133 -0
- package/dist/bridges/equations/be-31-causal-set-bd.js.map +1 -0
- package/dist/bridges/equations/be-32-quantum-reference-frame.d.ts +113 -0
- package/dist/bridges/equations/be-32-quantum-reference-frame.d.ts.map +1 -0
- package/dist/bridges/equations/be-32-quantum-reference-frame.js +155 -0
- package/dist/bridges/equations/be-32-quantum-reference-frame.js.map +1 -0
- package/dist/bridges/equations/be-33-hertz-millis.d.ts +77 -0
- package/dist/bridges/equations/be-33-hertz-millis.d.ts.map +1 -0
- package/dist/bridges/equations/be-33-hertz-millis.js +113 -0
- package/dist/bridges/equations/be-33-hertz-millis.js.map +1 -0
- package/dist/bridges/equations/be-34-kibble-zurek.d.ts +76 -0
- package/dist/bridges/equations/be-34-kibble-zurek.d.ts.map +1 -0
- package/dist/bridges/equations/be-34-kibble-zurek.js +139 -0
- package/dist/bridges/equations/be-34-kibble-zurek.js.map +1 -0
- package/dist/bridges/equations/be-35-conformal-bootstrap.d.ts +117 -0
- package/dist/bridges/equations/be-35-conformal-bootstrap.d.ts.map +1 -0
- package/dist/bridges/equations/be-35-conformal-bootstrap.js +167 -0
- package/dist/bridges/equations/be-35-conformal-bootstrap.js.map +1 -0
- package/dist/bridges/equations/be-36-gw-speed-bound.d.ts +77 -0
- package/dist/bridges/equations/be-36-gw-speed-bound.d.ts.map +1 -0
- package/dist/bridges/equations/be-36-gw-speed-bound.js +107 -0
- package/dist/bridges/equations/be-36-gw-speed-bound.js.map +1 -0
- package/dist/bridges/equations/be-37-shapiro-delay.d.ts +260 -0
- package/dist/bridges/equations/be-37-shapiro-delay.d.ts.map +1 -0
- package/dist/bridges/equations/be-37-shapiro-delay.js +429 -0
- package/dist/bridges/equations/be-37-shapiro-delay.js.map +1 -0
- package/dist/bridges/equations/be-38-mond.d.ts +86 -0
- package/dist/bridges/equations/be-38-mond.d.ts.map +1 -0
- package/dist/bridges/equations/be-38-mond.js +122 -0
- package/dist/bridges/equations/be-38-mond.js.map +1 -0
- package/dist/bridges/equations/be-39-asymptotic-safety.d.ts +106 -0
- package/dist/bridges/equations/be-39-asymptotic-safety.d.ts.map +1 -0
- package/dist/bridges/equations/be-39-asymptotic-safety.js +155 -0
- package/dist/bridges/equations/be-39-asymptotic-safety.js.map +1 -0
- package/dist/bridges/equations/be-40-composite-higgs.d.ts +81 -0
- package/dist/bridges/equations/be-40-composite-higgs.d.ts.map +1 -0
- package/dist/bridges/equations/be-40-composite-higgs.js +149 -0
- package/dist/bridges/equations/be-40-composite-higgs.js.map +1 -0
- package/dist/bridges/equations/be-41-swampland.d.ts +67 -0
- package/dist/bridges/equations/be-41-swampland.d.ts.map +1 -0
- package/dist/bridges/equations/be-41-swampland.js +109 -0
- package/dist/bridges/equations/be-41-swampland.js.map +1 -0
- package/dist/bridges/equations/be-42-hawking-temperature.d.ts +67 -0
- package/dist/bridges/equations/be-42-hawking-temperature.d.ts.map +1 -0
- package/dist/bridges/equations/be-42-hawking-temperature.js +109 -0
- package/dist/bridges/equations/be-42-hawking-temperature.js.map +1 -0
- package/dist/bridges/equations/be-43-er-epr.d.ts +73 -0
- package/dist/bridges/equations/be-43-er-epr.d.ts.map +1 -0
- package/dist/bridges/equations/be-43-er-epr.js +114 -0
- package/dist/bridges/equations/be-43-er-epr.js.map +1 -0
- package/dist/bridges/equations/be-44-soft-hair.d.ts +151 -0
- package/dist/bridges/equations/be-44-soft-hair.d.ts.map +1 -0
- package/dist/bridges/equations/be-44-soft-hair.js +185 -0
- package/dist/bridges/equations/be-44-soft-hair.js.map +1 -0
- package/dist/bridges/equations/be-45-tcc.d.ts +116 -0
- package/dist/bridges/equations/be-45-tcc.d.ts.map +1 -0
- package/dist/bridges/equations/be-45-tcc.js +157 -0
- package/dist/bridges/equations/be-45-tcc.js.map +1 -0
- package/dist/bridges/equations/be-46-multiverse-measure.d.ts +163 -0
- package/dist/bridges/equations/be-46-multiverse-measure.d.ts.map +1 -0
- package/dist/bridges/equations/be-46-multiverse-measure.js +198 -0
- package/dist/bridges/equations/be-46-multiverse-measure.js.map +1 -0
- package/dist/bridges/equations/be-47-bbn-dark-sector.d.ts +72 -0
- package/dist/bridges/equations/be-47-bbn-dark-sector.d.ts.map +1 -0
- package/dist/bridges/equations/be-47-bbn-dark-sector.js +121 -0
- package/dist/bridges/equations/be-47-bbn-dark-sector.js.map +1 -0
- package/dist/bridges/equations/be-48-grw-localization.d.ts +84 -0
- package/dist/bridges/equations/be-48-grw-localization.d.ts.map +1 -0
- package/dist/bridges/equations/be-48-grw-localization.js +107 -0
- package/dist/bridges/equations/be-48-grw-localization.js.map +1 -0
- package/dist/bridges/equations/be-49-quantum-darwinism.d.ts +97 -0
- package/dist/bridges/equations/be-49-quantum-darwinism.d.ts.map +1 -0
- package/dist/bridges/equations/be-49-quantum-darwinism.js +129 -0
- package/dist/bridges/equations/be-49-quantum-darwinism.js.map +1 -0
- package/dist/bridges/equations/be-50-wheeler-feynman.d.ts +120 -0
- package/dist/bridges/equations/be-50-wheeler-feynman.d.ts.map +1 -0
- package/dist/bridges/equations/be-50-wheeler-feynman.js +151 -0
- package/dist/bridges/equations/be-50-wheeler-feynman.js.map +1 -0
- package/dist/bridges/gravitational-lensing.d.ts +52 -0
- package/dist/bridges/gravitational-lensing.d.ts.map +1 -0
- package/dist/bridges/gravitational-lensing.js +48 -0
- package/dist/bridges/gravitational-lensing.js.map +1 -0
- package/dist/bridges/index.d.ts +104 -0
- package/dist/bridges/index.d.ts.map +1 -0
- package/dist/bridges/index.js +1663 -0
- package/dist/bridges/index.js.map +1 -0
- package/dist/bridges/perihelion-precession.d.ts +62 -0
- package/dist/bridges/perihelion-precession.d.ts.map +1 -0
- package/dist/bridges/perihelion-precession.js +68 -0
- package/dist/bridges/perihelion-precession.js.map +1 -0
- package/dist/core/tensor.d.ts +135 -0
- package/dist/core/tensor.d.ts.map +1 -0
- package/dist/core/tensor.js +376 -0
- package/dist/core/tensor.js.map +1 -0
- package/dist/core/types.d.ts +131 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +25 -0
- package/dist/core/types.js.map +1 -0
- package/dist/dimensional/algebra.d.ts +34 -0
- package/dist/dimensional/algebra.d.ts.map +1 -0
- package/dist/dimensional/algebra.js +90 -0
- package/dist/dimensional/algebra.js.map +1 -0
- package/dist/dimensional/bridge-check.d.ts +48 -0
- package/dist/dimensional/bridge-check.d.ts.map +1 -0
- package/dist/dimensional/bridge-check.js +137 -0
- package/dist/dimensional/bridge-check.js.map +1 -0
- package/dist/dimensional/connection-validators.d.ts +53 -0
- package/dist/dimensional/connection-validators.d.ts.map +1 -0
- package/dist/dimensional/connection-validators.js +84 -0
- package/dist/dimensional/connection-validators.js.map +1 -0
- package/dist/dimensional/connection.d.ts +40 -0
- package/dist/dimensional/connection.d.ts.map +1 -0
- package/dist/dimensional/connection.js +81 -0
- package/dist/dimensional/connection.js.map +1 -0
- package/dist/dimensional/constants.d.ts +30 -0
- package/dist/dimensional/constants.d.ts.map +1 -0
- package/dist/dimensional/constants.js +31 -0
- package/dist/dimensional/constants.js.map +1 -0
- package/dist/dimensional/errors.d.ts +161 -0
- package/dist/dimensional/errors.d.ts.map +1 -0
- package/dist/dimensional/errors.js +254 -0
- package/dist/dimensional/errors.js.map +1 -0
- package/dist/dimensional/fresh-label.d.ts +26 -0
- package/dist/dimensional/fresh-label.d.ts.map +1 -0
- package/dist/dimensional/fresh-label.js +31 -0
- package/dist/dimensional/fresh-label.js.map +1 -0
- package/dist/dimensional/metric-validators.d.ts +124 -0
- package/dist/dimensional/metric-validators.d.ts.map +1 -0
- package/dist/dimensional/metric-validators.js +141 -0
- package/dist/dimensional/metric-validators.js.map +1 -0
- package/dist/dimensional/metric.d.ts +67 -0
- package/dist/dimensional/metric.d.ts.map +1 -0
- package/dist/dimensional/metric.js +177 -0
- package/dist/dimensional/metric.js.map +1 -0
- package/dist/dimensional/tensor.d.ts +153 -0
- package/dist/dimensional/tensor.d.ts.map +1 -0
- package/dist/dimensional/tensor.js +138 -0
- package/dist/dimensional/tensor.js.map +1 -0
- package/dist/dimensional/types.d.ts +50 -0
- package/dist/dimensional/types.d.ts.map +1 -0
- package/dist/dimensional/types.js +66 -0
- package/dist/dimensional/types.js.map +1 -0
- package/dist/dimensional/validator.d.ts +84 -0
- package/dist/dimensional/validator.d.ts.map +1 -0
- package/dist/dimensional/validator.js +505 -0
- package/dist/dimensional/validator.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/numerical/be37-covariant-eikonal.d.ts +90 -0
- package/dist/numerical/be37-covariant-eikonal.d.ts.map +1 -0
- package/dist/numerical/be37-covariant-eikonal.js +79 -0
- package/dist/numerical/be37-covariant-eikonal.js.map +1 -0
- package/dist/numerical/connection-lowering-helpers.d.ts +107 -0
- package/dist/numerical/connection-lowering-helpers.d.ts.map +1 -0
- package/dist/numerical/connection-lowering-helpers.js +315 -0
- package/dist/numerical/connection-lowering-helpers.js.map +1 -0
- package/dist/numerical/engine-registry.d.ts +50 -0
- package/dist/numerical/engine-registry.d.ts.map +1 -0
- package/dist/numerical/engine-registry.js +82 -0
- package/dist/numerical/engine-registry.js.map +1 -0
- package/dist/numerical/errors.d.ts +28 -0
- package/dist/numerical/errors.d.ts.map +1 -0
- package/dist/numerical/errors.js +39 -0
- package/dist/numerical/errors.js.map +1 -0
- package/dist/numerical/float64-engine.d.ts +53 -0
- package/dist/numerical/float64-engine.d.ts.map +1 -0
- package/dist/numerical/float64-engine.js +638 -0
- package/dist/numerical/float64-engine.js.map +1 -0
- package/dist/numerical/geodesic-integrator.d.ts +62 -0
- package/dist/numerical/geodesic-integrator.d.ts.map +1 -0
- package/dist/numerical/geodesic-integrator.js +103 -0
- package/dist/numerical/geodesic-integrator.js.map +1 -0
- package/dist/numerical/grid-field.d.ts +24 -0
- package/dist/numerical/grid-field.d.ts.map +1 -0
- package/dist/numerical/grid-field.js +2 -0
- package/dist/numerical/grid-field.js.map +1 -0
- package/dist/numerical/index.d.ts +80 -0
- package/dist/numerical/index.d.ts.map +1 -0
- package/dist/numerical/index.js +75 -0
- package/dist/numerical/index.js.map +1 -0
- package/dist/numerical/lowering.d.ts +48 -0
- package/dist/numerical/lowering.d.ts.map +1 -0
- package/dist/numerical/lowering.js +443 -0
- package/dist/numerical/lowering.js.map +1 -0
- package/dist/numerical/mathts-engine.d.ts +55 -0
- package/dist/numerical/mathts-engine.d.ts.map +1 -0
- package/dist/numerical/mathts-engine.js +164 -0
- package/dist/numerical/mathts-engine.js.map +1 -0
- package/dist/numerical/metric-inverse.d.ts +31 -0
- package/dist/numerical/metric-inverse.d.ts.map +1 -0
- package/dist/numerical/metric-inverse.js +68 -0
- package/dist/numerical/metric-inverse.js.map +1 -0
- package/dist/numerical/null-ray-integrator.d.ts +13 -0
- package/dist/numerical/null-ray-integrator.d.ts.map +1 -0
- package/dist/numerical/null-ray-integrator.js +53 -0
- package/dist/numerical/null-ray-integrator.js.map +1 -0
- package/dist/numerical/pderiv.d.ts +43 -0
- package/dist/numerical/pderiv.d.ts.map +1 -0
- package/dist/numerical/pderiv.js +121 -0
- package/dist/numerical/pderiv.js.map +1 -0
- package/dist/numerical/tensor-engine.d.ts +114 -0
- package/dist/numerical/tensor-engine.d.ts.map +1 -0
- package/dist/numerical/tensor-engine.js +64 -0
- package/dist/numerical/tensor-engine.js.map +1 -0
- package/dist/numerical/types.d.ts +37 -0
- package/dist/numerical/types.d.ts.map +1 -0
- package/dist/numerical/types.js +8 -0
- package/dist/numerical/types.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MathTSEngine — a TensorEngine implementation backed by
|
|
3
|
+
* @danielsimonjr/mathts-tensor's rank-N Tensor. The second v0.3.5 engine;
|
|
4
|
+
* becomes UPT's default in v0.4.0 (v0.3.5-Design.md §12).
|
|
5
|
+
*
|
|
6
|
+
* Thin adapter: it translates the TensorEngine contract onto the MathTS
|
|
7
|
+
* Tensor's methods. Both engines pass the identical engine-conformance
|
|
8
|
+
* suite, which is what guarantees behavioural parity across the two repos.
|
|
9
|
+
*
|
|
10
|
+
* @module numerical/mathts-engine
|
|
11
|
+
*/
|
|
12
|
+
import { Tensor } from '@danielsimonjr/mathts-tensor';
|
|
13
|
+
import { NumericalBackendError } from './errors.js';
|
|
14
|
+
import { EngineCapabilityError } from './tensor-engine.js';
|
|
15
|
+
/** EngineTensor handle wrapping a MathTS Tensor. */
|
|
16
|
+
class MathTSEngineTensor {
|
|
17
|
+
inner;
|
|
18
|
+
constructor(inner) {
|
|
19
|
+
this.inner = inner;
|
|
20
|
+
}
|
|
21
|
+
get shape() { return this.inner.shape; }
|
|
22
|
+
}
|
|
23
|
+
function unwrap(t, op) {
|
|
24
|
+
if (!(t instanceof MathTSEngineTensor)) {
|
|
25
|
+
throw new NumericalBackendError(`MathTSEngine.${op}: operand is not a MathTSEngineTensor`);
|
|
26
|
+
}
|
|
27
|
+
return t.inner;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* `TensorEngine` backed by `@danielsimonjr/mathts-tensor`'s rank-N Tensor —
|
|
31
|
+
* the second v0.3.5 engine; becomes UPT's default in v0.4.0.
|
|
32
|
+
*
|
|
33
|
+
* @public — reachable only via the
|
|
34
|
+
* `universal-physics-tensor/numerical/mathts-engine` exports subpath; requires
|
|
35
|
+
* the `@danielsimonjr/mathts-tensor` optional dependency. Intentionally NOT
|
|
36
|
+
* re-exported from the root barrel.
|
|
37
|
+
*/
|
|
38
|
+
export class MathTSEngine {
|
|
39
|
+
name = 'MathTSEngine';
|
|
40
|
+
fromNested(data, shape) {
|
|
41
|
+
return new MathTSEngineTensor(Tensor.fromNested(data, shape));
|
|
42
|
+
}
|
|
43
|
+
toNested(t) {
|
|
44
|
+
return unwrap(t, 'toNested').toNested();
|
|
45
|
+
}
|
|
46
|
+
einsum(spec, ...operands) {
|
|
47
|
+
const inner = operands.map((o, i) => unwrap(o, `einsum (operand ${i})`));
|
|
48
|
+
return new MathTSEngineTensor(Tensor.einsum(spec, ...inner));
|
|
49
|
+
}
|
|
50
|
+
matMul(a, b) {
|
|
51
|
+
return new MathTSEngineTensor(unwrap(a, 'matMul').matMul(unwrap(b, 'matMul')));
|
|
52
|
+
}
|
|
53
|
+
transpose(t, perm) {
|
|
54
|
+
return new MathTSEngineTensor(unwrap(t, 'transpose').transpose(perm));
|
|
55
|
+
}
|
|
56
|
+
reshape(t, shape) {
|
|
57
|
+
return new MathTSEngineTensor(unwrap(t, 'reshape').reshape(shape));
|
|
58
|
+
}
|
|
59
|
+
add(a, b) {
|
|
60
|
+
return new MathTSEngineTensor(unwrap(a, 'add').add(unwrap(b, 'add')));
|
|
61
|
+
}
|
|
62
|
+
sub(a, b) {
|
|
63
|
+
return new MathTSEngineTensor(unwrap(a, 'sub').sub(unwrap(b, 'sub')));
|
|
64
|
+
}
|
|
65
|
+
mul(a, b) {
|
|
66
|
+
return new MathTSEngineTensor(unwrap(a, 'mul').mul(unwrap(b, 'mul')));
|
|
67
|
+
}
|
|
68
|
+
scale(t, k) {
|
|
69
|
+
return new MathTSEngineTensor(unwrap(t, 'scale').scale(k));
|
|
70
|
+
}
|
|
71
|
+
identity(n) {
|
|
72
|
+
return new MathTSEngineTensor(Tensor.identity(n));
|
|
73
|
+
}
|
|
74
|
+
normInf(t) {
|
|
75
|
+
return unwrap(t, 'normInf').normInf();
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Internal helpers for AD boundary conversions
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
/** Unwrap an EngineTensor to its underlying MathTS Tensor (for the AD boundary). */
|
|
81
|
+
toMathTSTensor(t) {
|
|
82
|
+
return unwrap(t, 'toMathTSTensor');
|
|
83
|
+
}
|
|
84
|
+
/** Wrap a MathTS Tensor (returned by autograd) back as an EngineTensor. */
|
|
85
|
+
fromMathTSTensor(t) {
|
|
86
|
+
return new MathTSEngineTensor(t);
|
|
87
|
+
}
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// Forward-mode AD (Jacobian-vector product)
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
/**
|
|
92
|
+
* Forward-mode automatic differentiation via a lazy-imported
|
|
93
|
+
* `@danielsimonjr/mathts-autograd`. Throws `EngineCapabilityError` if the
|
|
94
|
+
* optional dependency is absent.
|
|
95
|
+
*
|
|
96
|
+
* S1 fix: `fn` is passed UNCHANGED to `autograd.forwardGrad`. The autograd
|
|
97
|
+
* package wraps `x` as a DualTensor internally; MathTSEngine's arithmetic
|
|
98
|
+
* methods (mul/add/sub/scale) must dispatch DualTensor inputs through to
|
|
99
|
+
* mathts-autograd's dual arithmetic — there must be no fn-wrapping at the
|
|
100
|
+
* boundary, which would strip DualTensor instrumentation and silence the
|
|
101
|
+
* AD trace.
|
|
102
|
+
*/
|
|
103
|
+
async forwardGrad(fn, x) {
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
+
let autograd;
|
|
106
|
+
// @ts-ignore — @danielsimonjr/mathts-autograd is an optional dependency;
|
|
107
|
+
// tsc cannot resolve it when not installed. The try/catch handles absence
|
|
108
|
+
// at runtime; EngineCapabilityError is thrown when the package is absent.
|
|
109
|
+
try {
|
|
110
|
+
autograd = await import('@danielsimonjr/mathts-autograd');
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
throw new EngineCapabilityError('MathTSEngine', 'forwardGrad');
|
|
114
|
+
}
|
|
115
|
+
// S1 fix: pass fn UNCHANGED. autograd.forwardGrad wraps x as a DualTensor;
|
|
116
|
+
// MathTSEngine's arithmetic methods (mul/add/sub/scale) MUST dispatch
|
|
117
|
+
// DualTensor inputs to mathts-autograd's dual arithmetic (same dispatch
|
|
118
|
+
// story Float64ReferenceEngine has, via `'tangent' in arg`). Wrapping fn
|
|
119
|
+
// at the boundary strips the instrumentation — the v0 sketch's bug.
|
|
120
|
+
const xMathts = this.toMathTSTensor(x);
|
|
121
|
+
const { value, jacobian } = await autograd.forwardGrad(fn, xMathts);
|
|
122
|
+
return {
|
|
123
|
+
value: this.fromMathTSTensor(value),
|
|
124
|
+
jacobian: this.fromMathTSTensor(jacobian),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
// Reverse-mode AD (vector-Jacobian product)
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
/**
|
|
131
|
+
* Reverse-mode automatic differentiation via a lazy-imported
|
|
132
|
+
* `@danielsimonjr/mathts-autograd`. Throws `EngineCapabilityError` if the
|
|
133
|
+
* optional dependency is absent.
|
|
134
|
+
*
|
|
135
|
+
* S1 fix: `fn` is passed UNCHANGED (see forwardGrad note above). The
|
|
136
|
+
* autograd package wraps `x` as a TapedTensor; MathTSEngine's op methods
|
|
137
|
+
* must dispatch TapedTensor inputs to mathts-autograd's tape arithmetic via
|
|
138
|
+
* `'tape' in arg` branching.
|
|
139
|
+
*/
|
|
140
|
+
async reverseGrad(fn, x, cotangent) {
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
|
+
let autograd;
|
|
143
|
+
// @ts-ignore — @danielsimonjr/mathts-autograd is an optional dependency;
|
|
144
|
+
// tsc cannot resolve it when not installed. The try/catch handles absence
|
|
145
|
+
// at runtime; EngineCapabilityError is thrown when the package is absent.
|
|
146
|
+
try {
|
|
147
|
+
autograd = await import('@danielsimonjr/mathts-autograd');
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
throw new EngineCapabilityError('MathTSEngine', 'reverseGrad');
|
|
151
|
+
}
|
|
152
|
+
// S1 fix: pass fn UNCHANGED (see forwardGrad note above). autograd.reverseGrad
|
|
153
|
+
// wraps x as a TapedTensor; MathTSEngine's mul/add/sub/scale dispatch
|
|
154
|
+
// TapedTensor inputs to mathts-autograd's tape arithmetic via `'tape' in arg`.
|
|
155
|
+
const xMathts = this.toMathTSTensor(x);
|
|
156
|
+
const ctMathts = cotangent ? this.toMathTSTensor(cotangent) : undefined;
|
|
157
|
+
const { value, gradient } = await autograd.reverseGrad(fn, xMathts, ctMathts);
|
|
158
|
+
return {
|
|
159
|
+
value: this.fromMathTSTensor(value),
|
|
160
|
+
gradient: this.fromMathTSTensor(gradient),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=mathts-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mathts-engine.js","sourceRoot":"","sources":["../../src/numerical/mathts-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAGtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,oDAAoD;AACpD,MAAM,kBAAkB;IACD;IAArB,YAAqB,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IACtC,IAAI,KAAK,KAA4B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;CAChE;AAED,SAAS,MAAM,CAAC,CAAe,EAAE,EAAU;IACzC,IAAI,CAAC,CAAC,CAAC,YAAY,kBAAkB,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,qBAAqB,CAAC,gBAAgB,EAAE,uCAAuC,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,CAAC,CAAC,KAAK,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IACd,IAAI,GAAG,cAAc,CAAC;IAE/B,UAAU,CAAC,IAAiB,EAAE,KAA4B;QACxD,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAChE,CAAC;IACD,QAAQ,CAAC,CAAe;QACtB,OAAO,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC1C,CAAC;IAED,MAAM,CAA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|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InverseMetricInconsistencyWarning — numerical path. Builds g⁻¹ and g as
|
|
3
|
+
* EngineTensors, computes ‖matMul(g⁻¹, g) − I‖_∞, and emits a
|
|
4
|
+
* 'warning'-severity Violation when it exceeds tolerance. v0.3.5-Design.md
|
|
5
|
+
* §7. Resolves the v0.3.0 §13 Q2 deferral. `scanForMetricPair` finds an
|
|
6
|
+
* identifiable lower/upper metric pair in an AST so evaluateNumerical can
|
|
7
|
+
* run the check automatically.
|
|
8
|
+
*
|
|
9
|
+
* @module numerical/metric-inverse
|
|
10
|
+
*/
|
|
11
|
+
import type { ExprNode, Violation } from '../dimensional/validator.js';
|
|
12
|
+
import type { MetricTensorNode } from '../dimensional/metric-validators.js';
|
|
13
|
+
import type { TensorEngine } from './tensor-engine.js';
|
|
14
|
+
import type { NumericalInputs } from './types.js';
|
|
15
|
+
/** Compute ‖g⁻¹g − I‖_∞ and, if it exceeds tolerance, return a warning.
|
|
16
|
+
* @public */
|
|
17
|
+
export declare function evaluateMetricInverse(gInverse: MetricTensorNode, g: MetricTensorNode, inputs: NumericalInputs, tolerance?: number, options?: {
|
|
18
|
+
engine?: TensorEngine;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
residualNorm: number;
|
|
21
|
+
warning?: Violation;
|
|
22
|
+
}>;
|
|
23
|
+
/** Walk an ExprNode tree; return the first all-lower / all-upper
|
|
24
|
+
* metric-tensor pair found, or null. Cheap — evaluateNumerical already
|
|
25
|
+
* walks the tree to lower it.
|
|
26
|
+
* @internal — cross-module use only; not part of the consumer surface. */
|
|
27
|
+
export declare function scanForMetricPair(node: ExprNode): {
|
|
28
|
+
gLower: MetricTensorNode;
|
|
29
|
+
gUpper: MetricTensorNode;
|
|
30
|
+
} | null;
|
|
31
|
+
//# sourceMappingURL=metric-inverse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metric-inverse.d.ts","sourceRoot":"","sources":["../../src/numerical/metric-inverse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAMlD;cACc;AACd,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,gBAAgB,EAC1B,CAAC,EAAE,gBAAgB,EACnB,MAAM,EAAE,eAAe,EACvB,SAAS,GAAE,MAA0B,EACrC,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAE,GAClC,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC,CAkCxD;AAED;;;2EAG2E;AAC3E,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,QAAQ,GACb;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,GAAG,IAAI,CAiB/D"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DIMENSIONLESS } from '../dimensional/types.js';
|
|
2
|
+
import { getActiveEngine } from './engine-registry.js';
|
|
3
|
+
import { NumericalBackendError } from './errors.js';
|
|
4
|
+
const DEFAULT_TOLERANCE = 1e-10;
|
|
5
|
+
/** Compute ‖g⁻¹g − I‖_∞ and, if it exceeds tolerance, return a warning.
|
|
6
|
+
* @public */
|
|
7
|
+
export async function evaluateMetricInverse(gInverse, g, inputs, tolerance = DEFAULT_TOLERANCE, options) {
|
|
8
|
+
const engine = options?.engine ?? await getActiveEngine();
|
|
9
|
+
const N = inputs.dimension ?? 4;
|
|
10
|
+
const gInvData = inputs.tensors.get(gInverse.name);
|
|
11
|
+
const gData = inputs.tensors.get(g.name);
|
|
12
|
+
if (gInvData === undefined) {
|
|
13
|
+
throw new NumericalBackendError(`evaluateMetricInverse: missing tensor components for "${gInverse.name}" in inputs.tensors`);
|
|
14
|
+
}
|
|
15
|
+
if (gData === undefined) {
|
|
16
|
+
throw new NumericalBackendError(`evaluateMetricInverse: missing tensor components for "${g.name}" in inputs.tensors`);
|
|
17
|
+
}
|
|
18
|
+
const gInvT = engine.fromNested(gInvData, [N, N]);
|
|
19
|
+
const gT = engine.fromNested(gData, [N, N]);
|
|
20
|
+
const residual = engine.sub(engine.matMul(gInvT, gT), engine.identity(N));
|
|
21
|
+
const residualNorm = engine.normInf(residual);
|
|
22
|
+
if (residualNorm > tolerance) {
|
|
23
|
+
const warning = {
|
|
24
|
+
location: `${gInverse.name}·${g.name}`,
|
|
25
|
+
expected: DIMENSIONLESS,
|
|
26
|
+
actual: DIMENSIONLESS,
|
|
27
|
+
note: `InverseMetricInconsistencyWarning: ‖${gInverse.name}·${g.name} − I‖_∞ = `
|
|
28
|
+
+ `${residualNorm.toExponential(3)} exceeds tolerance ${tolerance.toExponential(1)} — `
|
|
29
|
+
+ `the supplied metrics are not numerical inverses`,
|
|
30
|
+
severity: 'warning',
|
|
31
|
+
};
|
|
32
|
+
return { residualNorm, warning };
|
|
33
|
+
}
|
|
34
|
+
return { residualNorm };
|
|
35
|
+
}
|
|
36
|
+
/** Walk an ExprNode tree; return the first all-lower / all-upper
|
|
37
|
+
* metric-tensor pair found, or null. Cheap — evaluateNumerical already
|
|
38
|
+
* walks the tree to lower it.
|
|
39
|
+
* @internal — cross-module use only; not part of the consumer surface. */
|
|
40
|
+
export function scanForMetricPair(node) {
|
|
41
|
+
const metrics = [];
|
|
42
|
+
const walk = (n) => {
|
|
43
|
+
if (n.kind === 'metric-tensor')
|
|
44
|
+
metrics.push(n);
|
|
45
|
+
else if (n.kind === 'op')
|
|
46
|
+
n.args.forEach(walk);
|
|
47
|
+
else if (n.kind === 'tensor-product')
|
|
48
|
+
n.args.forEach(walk);
|
|
49
|
+
else if (n.kind === 'integral') {
|
|
50
|
+
walk(n.over);
|
|
51
|
+
walk(n.integrand);
|
|
52
|
+
}
|
|
53
|
+
else if (n.kind === 'derivative') {
|
|
54
|
+
walk(n.of);
|
|
55
|
+
walk(n.wrt);
|
|
56
|
+
}
|
|
57
|
+
else if (n.kind === 'tensor-partial-derivative') {
|
|
58
|
+
walk(n.of);
|
|
59
|
+
walk(n.wrt);
|
|
60
|
+
}
|
|
61
|
+
// tensor-symbol / kronecker-delta / symbol: leaves, no metric inside
|
|
62
|
+
};
|
|
63
|
+
walk(node);
|
|
64
|
+
const lower = metrics.find((m) => m.indices.every((i) => i.variance === 'lower'));
|
|
65
|
+
const upper = metrics.find((m) => m.indices.every((i) => i.variance === 'upper'));
|
|
66
|
+
return lower && upper ? { gLower: lower, gUpper: upper } : null;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=metric-inverse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metric-inverse.js","sourceRoot":"","sources":["../../src/numerical/metric-inverse.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC;cACc;AACd,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,QAA0B,EAC1B,CAAmB,EACnB,MAAuB,EACvB,YAAoB,iBAAiB,EACrC,OAAmC;IAEnC,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,MAAM,eAAe,EAAE,CAAC;IAC1D,MAAM,CAAC,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;IAEhC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAA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,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC;IAClF,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC;IAClF,OAAO,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** A first-order ODE system: dy/dλ = f(λ, y). `y` and the return are
|
|
2
|
+
* state vectors of equal length.
|
|
3
|
+
* @internal — cross-module/test use only; not part of the consumer surface. */
|
|
4
|
+
export type ODESystem = (lambda: number, y: ReadonlyArray<number>) => number[];
|
|
5
|
+
/**
|
|
6
|
+
* Integrate `system` from affine parameter `lambda0` to `lambda1` in
|
|
7
|
+
* `steps` fixed RK4 steps, starting from state `y0`. Returns the final
|
|
8
|
+
* state vector. Classical 4th-order Runge-Kutta — global error O(h⁴).
|
|
9
|
+
*
|
|
10
|
+
* @internal — cross-module/test use only; not part of the consumer surface.
|
|
11
|
+
*/
|
|
12
|
+
export declare function integrateRK4(system: ODESystem, y0: ReadonlyArray<number>, lambda0: number, lambda1: number, steps: number): number[];
|
|
13
|
+
//# sourceMappingURL=null-ray-integrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null-ray-integrator.d.ts","sourceRoot":"","sources":["../../src/numerical/null-ray-integrator.ts"],"names":[],"mappings":"AAUA;;gFAEgF;AAChF,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,MAAM,EAAE,CAAC;AAgB/E;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,EACzB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,MAAM,EAAE,CAyBV"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-step classical RK4 integrator for affine-parameterized null
|
|
3
|
+
* geodesics — the numerical core of the BE-37 Shapiro-delay evaluator
|
|
4
|
+
* (v0.3.5-Design.md §8). Self-contained: operates on plain number[] state
|
|
5
|
+
* vectors, no TensorEngine dependency.
|
|
6
|
+
*
|
|
7
|
+
* @module numerical/null-ray-integrator
|
|
8
|
+
*/
|
|
9
|
+
import { NumericalBackendError } from './errors.js';
|
|
10
|
+
function addScaled(a, b, k) {
|
|
11
|
+
const out = new Array(a.length);
|
|
12
|
+
for (let i = 0; i < a.length; i++)
|
|
13
|
+
out[i] = a[i] + k * b[i];
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
function checkLength(k, expected) {
|
|
17
|
+
if (k.length !== expected) {
|
|
18
|
+
throw new NumericalBackendError(`integrateRK4: ODE system returned a state vector of length ${k.length}, expected ${expected}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Integrate `system` from affine parameter `lambda0` to `lambda1` in
|
|
23
|
+
* `steps` fixed RK4 steps, starting from state `y0`. Returns the final
|
|
24
|
+
* state vector. Classical 4th-order Runge-Kutta — global error O(h⁴).
|
|
25
|
+
*
|
|
26
|
+
* @internal — cross-module/test use only; not part of the consumer surface.
|
|
27
|
+
*/
|
|
28
|
+
export function integrateRK4(system, y0, lambda0, lambda1, steps) {
|
|
29
|
+
if (!Number.isInteger(steps) || steps <= 0) {
|
|
30
|
+
throw new NumericalBackendError(`integrateRK4: step count must be a positive integer, got ${steps}`);
|
|
31
|
+
}
|
|
32
|
+
const h = (lambda1 - lambda0) / steps;
|
|
33
|
+
let lambda = lambda0;
|
|
34
|
+
let y = [...y0];
|
|
35
|
+
for (let n = 0; n < steps; n++) {
|
|
36
|
+
const k1 = system(lambda, y);
|
|
37
|
+
checkLength(k1, y.length);
|
|
38
|
+
const k2 = system(lambda + h / 2, addScaled(y, k1, h / 2));
|
|
39
|
+
checkLength(k2, y.length);
|
|
40
|
+
const k3 = system(lambda + h / 2, addScaled(y, k2, h / 2));
|
|
41
|
+
checkLength(k3, y.length);
|
|
42
|
+
const k4 = system(lambda + h, addScaled(y, k3, h));
|
|
43
|
+
checkLength(k4, y.length);
|
|
44
|
+
const next = new Array(y.length);
|
|
45
|
+
for (let i = 0; i < y.length; i++) {
|
|
46
|
+
next[i] = y[i] + (h / 6) * (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]);
|
|
47
|
+
}
|
|
48
|
+
y = next;
|
|
49
|
+
lambda += h;
|
|
50
|
+
}
|
|
51
|
+
return y;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=null-ray-integrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null-ray-integrator.js","sourceRoot":"","sources":["../../src/numerical/null-ray-integrator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAOpD,SAAS,SAAS,CAAC,CAAwB,EAAE,CAAwB,EAAE,CAAS;IAC9E,MAAM,GAAG,GAAG,IAAI,KAAK,CAAS,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,WAAW,CAAC,CAAw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AC,MAAM,CAAC,CAAC;QAC1B,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QACnD,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;QAC1B,MAAM,IAAI,GAAG,IAAI,KAAK,CAAS,CAAC,CAAC,MAAM,CAAC,CAAC;QACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,CAAC;QACD,CAAC,GAAG,IAAI,CAAC;QACT,MAAM,IAAI,CAAC,CAAC;IACd,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numerical partial derivative — two-way dispatch (v0.3.5-Design.md §6).
|
|
3
|
+
* 'grid' — centered finite-difference over a GridField.
|
|
4
|
+
* 'numerical-fn' — centered finite-difference over a caller-supplied fn.
|
|
5
|
+
* 'symbolic' — no CAS in v0.3.5; consumes an explicit pre-supplied
|
|
6
|
+
* derivative from NumericalInputs.derivatives.
|
|
7
|
+
*
|
|
8
|
+
* @module numerical/pderiv
|
|
9
|
+
*/
|
|
10
|
+
import type { GridField } from './grid-field.js';
|
|
11
|
+
import type { NestedArray } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Centered finite-difference of a GridField along `axis`. Returns a flat
|
|
14
|
+
* number[] of the same total size as the grid. O(h²) interior stencil;
|
|
15
|
+
* edges follow `grid.boundary`:
|
|
16
|
+
* - 'clamp' — one-sided (forward/backward) difference at the edge.
|
|
17
|
+
* - 'periodic' — wraps to the opposite edge.
|
|
18
|
+
*
|
|
19
|
+
* @internal — consumed by the lowering pass; not part of the consumer surface.
|
|
20
|
+
*/
|
|
21
|
+
export declare function pderivGrid(grid: GridField, axis: number): number[];
|
|
22
|
+
/**
|
|
23
|
+
* Centered finite-difference of a caller-supplied scalar field with respect
|
|
24
|
+
* to coordinate `axis`. Step h = 1e-6 · max(|x|, 1) (v0.3.5-Design.md §13 Q3).
|
|
25
|
+
*
|
|
26
|
+
* @internal — consumed by the lowering pass; not part of the consumer surface.
|
|
27
|
+
*/
|
|
28
|
+
export declare function pderivNumericalFn(fn: (coords: ReadonlyArray<number>) => NestedArray, coords: ReadonlyArray<number>, axis: number): NestedArray;
|
|
29
|
+
/**
|
|
30
|
+
* 'symbolic' numericalForm path: v0.3.5 has no CAS, so the caller supplies
|
|
31
|
+
* the derivative explicitly, keyed `${symbolName}/${coordLabel}`.
|
|
32
|
+
*
|
|
33
|
+
* @internal — consumed by the lowering pass; not part of the consumer surface.
|
|
34
|
+
*/
|
|
35
|
+
export declare function pderivSymbolic(symbolName: string, coordLabel: string, derivatives: ReadonlyMap<string, NestedArray>): NestedArray;
|
|
36
|
+
/**
|
|
37
|
+
* 'supplied' derivativeStrategy path: v0.4.0 metric derivative looked up
|
|
38
|
+
* from explicit caller-supplied components. Keyed `${metricName}/${coordLabel}`.
|
|
39
|
+
* Mirror of `pderivSymbolic` for the metric-tensor lowering path.
|
|
40
|
+
* Throws NumericalBackendError with a clear message when absent.
|
|
41
|
+
*/
|
|
42
|
+
export declare function metricDerivSupplied(metricName: string, coordLabel: string, metricDerivatives: ReadonlyMap<string, NestedArray>): NestedArray;
|
|
43
|
+
//# sourceMappingURL=pderiv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pderiv.d.ts","sourceRoot":"","sources":["../../src/numerical/pderiv.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAe9C;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAiClE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,WAAW,EAClD,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,IAAI,EAAE,MAAM,GACX,WAAW,CAeb;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,GAC5C,WAAW,CAWb;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,GAClD,WAAW,CAYb"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { NumericalBackendError } from './errors.js';
|
|
2
|
+
/** Flatten a (possibly scalar) NestedArray to a number[] in row-major order. */
|
|
3
|
+
function flattenToNumbers(data) {
|
|
4
|
+
if (typeof data === 'number')
|
|
5
|
+
return [data];
|
|
6
|
+
const out = [];
|
|
7
|
+
const walk = (n) => {
|
|
8
|
+
if (typeof n === 'number')
|
|
9
|
+
out.push(n);
|
|
10
|
+
else
|
|
11
|
+
for (const c of n)
|
|
12
|
+
walk(c);
|
|
13
|
+
};
|
|
14
|
+
walk(data);
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Centered finite-difference of a GridField along `axis`. Returns a flat
|
|
19
|
+
* number[] of the same total size as the grid. O(h²) interior stencil;
|
|
20
|
+
* edges follow `grid.boundary`:
|
|
21
|
+
* - 'clamp' — one-sided (forward/backward) difference at the edge.
|
|
22
|
+
* - 'periodic' — wraps to the opposite edge.
|
|
23
|
+
*
|
|
24
|
+
* @internal — consumed by the lowering pass; not part of the consumer surface.
|
|
25
|
+
*/
|
|
26
|
+
export function pderivGrid(grid, axis) {
|
|
27
|
+
if (axis < 0 || axis >= grid.shape.length) {
|
|
28
|
+
throw new NumericalBackendError(`pderivGrid: axis ${axis} out of range for shape [${grid.shape}]`);
|
|
29
|
+
}
|
|
30
|
+
const h = grid.spacing[axis];
|
|
31
|
+
if (!(h > 0)) {
|
|
32
|
+
throw new NumericalBackendError(`pderivGrid: non-positive spacing ${h} on axis ${axis}`);
|
|
33
|
+
}
|
|
34
|
+
const flat = flattenToNumbers(grid.data);
|
|
35
|
+
const shape = grid.shape;
|
|
36
|
+
const strides = new Array(shape.length);
|
|
37
|
+
let acc = 1;
|
|
38
|
+
for (let k = shape.length - 1; k >= 0; k--) {
|
|
39
|
+
strides[k] = acc;
|
|
40
|
+
acc *= shape[k];
|
|
41
|
+
}
|
|
42
|
+
const out = new Array(flat.length).fill(0);
|
|
43
|
+
const n = shape[axis];
|
|
44
|
+
const step = strides[axis];
|
|
45
|
+
// Walk every multi-index; compute the axis position from the flat index.
|
|
46
|
+
for (let f = 0; f < flat.length; f++) {
|
|
47
|
+
const pos = Math.floor(f / step) % n;
|
|
48
|
+
if (pos > 0 && pos < n - 1) {
|
|
49
|
+
out[f] = (flat[f + step] - flat[f - step]) / (2 * h);
|
|
50
|
+
}
|
|
51
|
+
else if (grid.boundary === 'periodic') {
|
|
52
|
+
const next = pos === n - 1 ? f - (n - 1) * step : f + step;
|
|
53
|
+
const prev = pos === 0 ? f + (n - 1) * step : f - step;
|
|
54
|
+
out[f] = (flat[next] - flat[prev]) / (2 * h);
|
|
55
|
+
}
|
|
56
|
+
else { // 'clamp' — one-sided difference at the edge
|
|
57
|
+
out[f] = pos === 0
|
|
58
|
+
? (flat[f + step] - flat[f]) / h
|
|
59
|
+
: (flat[f] - flat[f - step]) / h;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Centered finite-difference of a caller-supplied scalar field with respect
|
|
66
|
+
* to coordinate `axis`. Step h = 1e-6 · max(|x|, 1) (v0.3.5-Design.md §13 Q3).
|
|
67
|
+
*
|
|
68
|
+
* @internal — consumed by the lowering pass; not part of the consumer surface.
|
|
69
|
+
*/
|
|
70
|
+
export function pderivNumericalFn(fn, coords, axis) {
|
|
71
|
+
if (axis < 0 || axis >= coords.length) {
|
|
72
|
+
throw new NumericalBackendError(`pderivNumericalFn: axis ${axis} out of range`);
|
|
73
|
+
}
|
|
74
|
+
const x = coords[axis];
|
|
75
|
+
const h = 1e-6 * Math.max(Math.abs(x), 1);
|
|
76
|
+
const plus = [...coords];
|
|
77
|
+
plus[axis] = x + h;
|
|
78
|
+
const minus = [...coords];
|
|
79
|
+
minus[axis] = x - h;
|
|
80
|
+
const fp = flattenToNumbers(fn(plus));
|
|
81
|
+
const fm = flattenToNumbers(fn(minus));
|
|
82
|
+
if (fp.length !== fm.length) {
|
|
83
|
+
throw new NumericalBackendError('pderivNumericalFn: field returned inconsistent shapes');
|
|
84
|
+
}
|
|
85
|
+
const d = fp.map((v, i) => (v - fm[i]) / (2 * h));
|
|
86
|
+
return d.length === 1 ? d[0] : d;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 'symbolic' numericalForm path: v0.3.5 has no CAS, so the caller supplies
|
|
90
|
+
* the derivative explicitly, keyed `${symbolName}/${coordLabel}`.
|
|
91
|
+
*
|
|
92
|
+
* @internal — consumed by the lowering pass; not part of the consumer surface.
|
|
93
|
+
*/
|
|
94
|
+
export function pderivSymbolic(symbolName, coordLabel, derivatives) {
|
|
95
|
+
const key = `${symbolName}/${coordLabel}`;
|
|
96
|
+
const d = derivatives.get(key);
|
|
97
|
+
if (d === undefined) {
|
|
98
|
+
throw new NumericalBackendError(`pderivSymbolic: no explicit derivative supplied for "${key}" — `
|
|
99
|
+
+ `a 'symbolic' tensor-symbol under a partial-derivative requires `
|
|
100
|
+
+ `inputs.derivatives to contain its pre-computed components (v0.3.5 has no CAS)`);
|
|
101
|
+
}
|
|
102
|
+
return d;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 'supplied' derivativeStrategy path: v0.4.0 metric derivative looked up
|
|
106
|
+
* from explicit caller-supplied components. Keyed `${metricName}/${coordLabel}`.
|
|
107
|
+
* Mirror of `pderivSymbolic` for the metric-tensor lowering path.
|
|
108
|
+
* Throws NumericalBackendError with a clear message when absent.
|
|
109
|
+
*/
|
|
110
|
+
export function metricDerivSupplied(metricName, coordLabel, metricDerivatives) {
|
|
111
|
+
const key = `${metricName}/${coordLabel}`;
|
|
112
|
+
const d = metricDerivatives.get(key);
|
|
113
|
+
if (d === undefined) {
|
|
114
|
+
throw new NumericalBackendError(`metricDerivSupplied: no metric derivative supplied for "${key}" — `
|
|
115
|
+
+ `a metric-tensor with derivativeStrategy='supplied' under a `
|
|
116
|
+
+ `christoffel/covariant-derivative requires inputs.metricDerivatives `
|
|
117
|
+
+ `to contain its pre-computed ∂g components`);
|
|
118
|
+
}
|
|
119
|
+
return d;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=pderiv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pderiv.js","sourceRoot":"","sources":["../../src/numerical/pderiv.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD,gFAAgF;AAChF,SAAS,gBAAgB,CAAC,IAAiB;IACzC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,GAA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