universal-physics-tensor 0.7.3 → 0.14.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 +147 -109
- package/bin/upt.mjs +508 -0
- package/dist/bridges/be23-planckian-confrontation.d.ts +162 -0
- package/dist/bridges/be23-planckian-confrontation.d.ts.map +1 -0
- package/dist/bridges/be23-planckian-confrontation.js +196 -0
- package/dist/bridges/be23-planckian-confrontation.js.map +1 -0
- package/dist/bridges/be36-gw170817-confrontation.d.ts +111 -0
- package/dist/bridges/be36-gw170817-confrontation.d.ts.map +1 -0
- package/dist/bridges/be36-gw170817-confrontation.js +100 -0
- package/dist/bridges/be36-gw170817-confrontation.js.map +1 -0
- package/dist/bridges/bridge-equations.d.ts +129 -0
- package/dist/bridges/bridge-equations.d.ts.map +1 -0
- package/dist/bridges/bridge-equations.js +130 -0
- package/dist/bridges/bridge-equations.js.map +1 -0
- package/dist/bridges/catalog-adapter.d.ts +1 -1
- package/dist/bridges/catalog-adapter.js +1 -1
- package/dist/bridges/confrontation-coverage.d.ts +67 -0
- package/dist/bridges/confrontation-coverage.d.ts.map +1 -0
- package/dist/bridges/confrontation-coverage.js +83 -0
- package/dist/bridges/confrontation-coverage.js.map +1 -0
- package/dist/bridges/equations/_be-helpers.d.ts +2 -1
- package/dist/bridges/equations/_be-helpers.d.ts.map +1 -1
- package/dist/bridges/equations/be-12-coherence-length.d.ts +1 -1
- package/dist/bridges/equations/be-13-einstein-trace.d.ts +2 -2
- package/dist/bridges/equations/be-13-einstein-trace.js +1 -1
- package/dist/bridges/equations/be-14-ryu-takayanagi.d.ts +2 -2
- package/dist/bridges/equations/be-15-emergence.d.ts +19 -5
- package/dist/bridges/equations/be-15-emergence.d.ts.map +1 -1
- package/dist/bridges/equations/be-15-emergence.js +18 -4
- package/dist/bridges/equations/be-15-emergence.js.map +1 -1
- package/dist/bridges/equations/be-16-landauer.d.ts +1 -1
- package/dist/bridges/equations/be-17-einstein-cartan.d.ts +1 -1
- package/dist/bridges/equations/be-18-higgs-mass.d.ts +1 -1
- package/dist/bridges/equations/be-19-quantum-bounce.d.ts +1 -1
- package/dist/bridges/equations/be-20-vacuum-energy.d.ts +4 -4
- package/dist/bridges/equations/be-20-vacuum-energy.d.ts.map +1 -1
- package/dist/bridges/equations/be-20-vacuum-energy.js +4 -2
- package/dist/bridges/equations/be-20-vacuum-energy.js.map +1 -1
- package/dist/bridges/equations/be-22-topological-entanglement.d.ts +1 -1
- package/dist/bridges/equations/be-23-syk-planckian.d.ts +1 -1
- package/dist/bridges/equations/be-24-foerster-fret.d.ts +1 -1
- package/dist/bridges/equations/be-25-iit-phi.d.ts +1 -1
- package/dist/bridges/equations/be-25-orch-or.d.ts +13 -1
- package/dist/bridges/equations/be-25-orch-or.d.ts.map +1 -1
- package/dist/bridges/equations/be-25-orch-or.js +12 -0
- package/dist/bridges/equations/be-25-orch-or.js.map +1 -1
- package/dist/bridges/equations/be-26-dna-tunneling.d.ts +2 -2
- package/dist/bridges/equations/be-26-dna-tunneling.js +1 -1
- package/dist/bridges/equations/be-27-effective-temperature.d.ts +1 -1
- package/dist/bridges/equations/be-28-onsager-entropy-production.d.ts +1 -1
- package/dist/bridges/equations/be-29-jarzynski.d.ts +1 -1
- package/dist/bridges/equations/be-30-flm-first-law.d.ts +2 -2
- package/dist/bridges/equations/be-31-causal-set-bd.d.ts +1 -1
- package/dist/bridges/equations/be-32-quantum-reference-frame.d.ts +1 -1
- package/dist/bridges/equations/be-33-hertz-millis.d.ts +1 -1
- package/dist/bridges/equations/be-34-kibble-zurek.d.ts +1 -1
- package/dist/bridges/equations/be-35-conformal-bootstrap.d.ts +1 -1
- package/dist/bridges/equations/be-36-gw-speed-bound.d.ts +12 -5
- package/dist/bridges/equations/be-36-gw-speed-bound.d.ts.map +1 -1
- package/dist/bridges/equations/be-36-gw-speed-bound.js +11 -4
- package/dist/bridges/equations/be-36-gw-speed-bound.js.map +1 -1
- package/dist/bridges/equations/be-38-mond.d.ts +1 -1
- package/dist/bridges/equations/be-39-asymptotic-safety.d.ts +2 -2
- package/dist/bridges/equations/be-40-composite-higgs.d.ts +1 -1
- package/dist/bridges/equations/be-41-swampland.d.ts +1 -1
- package/dist/bridges/equations/be-43-er-epr.d.ts +1 -1
- package/dist/bridges/equations/be-44-soft-hair.d.ts +1 -1
- package/dist/bridges/equations/be-45-tcc.d.ts +1 -1
- package/dist/bridges/equations/be-46-multiverse-measure.d.ts +1 -1
- package/dist/bridges/equations/be-47-bbn-dark-sector.d.ts +1 -1
- package/dist/bridges/equations/be-48-grw-localization.d.ts +1 -1
- package/dist/bridges/equations/be-49-quantum-darwinism.d.ts +1 -1
- package/dist/bridges/equations/be-50-wheeler-feynman.d.ts +1 -1
- package/dist/bridges/index.d.ts +10 -7
- package/dist/bridges/index.d.ts.map +1 -1
- package/dist/bridges/index.js +47 -34
- package/dist/bridges/index.js.map +1 -1
- package/dist/bridges/membership.d.ts +44 -0
- package/dist/bridges/membership.d.ts.map +1 -0
- package/dist/bridges/membership.js +59 -0
- package/dist/bridges/membership.js.map +1 -0
- package/dist/bridges/rejected.d.ts +40 -0
- package/dist/bridges/rejected.d.ts.map +1 -0
- package/dist/bridges/rejected.js +81 -0
- package/dist/bridges/rejected.js.map +1 -0
- package/dist/composition/bridge-analysis.d.ts +189 -0
- package/dist/composition/bridge-analysis.d.ts.map +1 -0
- package/dist/composition/bridge-analysis.js +445 -0
- package/dist/composition/bridge-analysis.js.map +1 -0
- package/dist/composition/bridge-prediction.d.ts +95 -0
- package/dist/composition/bridge-prediction.d.ts.map +1 -0
- package/dist/composition/bridge-prediction.js +0 -0
- package/dist/composition/bridge-prediction.js.map +1 -0
- package/dist/composition/catalog-graph.d.ts +20 -0
- package/dist/composition/catalog-graph.d.ts.map +1 -0
- package/dist/composition/catalog-graph.js +39 -0
- package/dist/composition/catalog-graph.js.map +1 -0
- package/dist/composition/compose-surface.d.ts +12 -0
- package/dist/composition/compose-surface.d.ts.map +1 -0
- package/dist/composition/compose-surface.js +10 -0
- package/dist/composition/compose-surface.js.map +1 -0
- package/dist/composition/compose-symbolic.d.ts +75 -0
- package/dist/composition/compose-symbolic.d.ts.map +1 -0
- package/dist/composition/compose-symbolic.js +157 -0
- package/dist/composition/compose-symbolic.js.map +1 -0
- package/dist/composition/compose.d.ts +110 -0
- package/dist/composition/compose.d.ts.map +1 -0
- package/dist/composition/compose.js +231 -0
- package/dist/composition/compose.js.map +1 -0
- package/dist/composition/consistency.d.ts +24 -0
- package/dist/composition/consistency.d.ts.map +1 -0
- package/dist/composition/consistency.js +26 -0
- package/dist/composition/consistency.js.map +1 -0
- package/dist/composition/discovery.d.ts +104 -0
- package/dist/composition/discovery.d.ts.map +1 -0
- package/dist/composition/discovery.js +165 -0
- package/dist/composition/discovery.js.map +1 -0
- package/dist/composition/edge.d.ts +139 -0
- package/dist/composition/edge.d.ts.map +1 -0
- package/dist/composition/edge.js +72 -0
- package/dist/composition/edge.js.map +1 -0
- package/dist/composition/edges/calibration.d.ts +107 -0
- package/dist/composition/edges/calibration.d.ts.map +1 -0
- package/dist/composition/edges/calibration.js +373 -0
- package/dist/composition/edges/calibration.js.map +1 -0
- package/dist/composition/edges/catalog-full.d.ts +299 -0
- package/dist/composition/edges/catalog-full.d.ts.map +1 -0
- package/dist/composition/edges/catalog-full.js +989 -0
- package/dist/composition/edges/catalog-full.js.map +1 -0
- package/dist/composition/edges/catalog-tranche.d.ts +112 -0
- package/dist/composition/edges/catalog-tranche.d.ts.map +1 -0
- package/dist/composition/edges/catalog-tranche.js +241 -0
- package/dist/composition/edges/catalog-tranche.js.map +1 -0
- package/dist/composition/enumerate.d.ts +67 -0
- package/dist/composition/enumerate.d.ts.map +1 -0
- package/dist/composition/enumerate.js +78 -0
- package/dist/composition/enumerate.js.map +1 -0
- package/dist/composition/explain.d.ts +102 -0
- package/dist/composition/explain.d.ts.map +1 -0
- package/dist/composition/explain.js +244 -0
- package/dist/composition/explain.js.map +1 -0
- package/dist/composition/expr-eval.d.ts +33 -0
- package/dist/composition/expr-eval.d.ts.map +1 -0
- package/dist/composition/expr-eval.js +95 -0
- package/dist/composition/expr-eval.js.map +1 -0
- package/dist/composition/expr-simplify.d.ts +60 -0
- package/dist/composition/expr-simplify.d.ts.map +1 -0
- package/dist/composition/expr-simplify.js +330 -0
- package/dist/composition/expr-simplify.js.map +1 -0
- package/dist/composition/expr-subst.d.ts +29 -0
- package/dist/composition/expr-subst.d.ts.map +1 -0
- package/dist/composition/expr-subst.js +60 -0
- package/dist/composition/expr-subst.js.map +1 -0
- package/dist/composition/identifiability.d.ts +103 -0
- package/dist/composition/identifiability.d.ts.map +1 -0
- package/dist/composition/identifiability.js +148 -0
- package/dist/composition/identifiability.js.map +1 -0
- package/dist/composition/index.d.ts +37 -0
- package/dist/composition/index.d.ts.map +1 -0
- package/dist/composition/index.js +27 -0
- package/dist/composition/index.js.map +1 -0
- package/dist/composition/quantities.d.ts +297 -0
- package/dist/composition/quantities.d.ts.map +1 -0
- package/dist/composition/quantities.js +1017 -0
- package/dist/composition/quantities.js.map +1 -0
- package/dist/composition/quantity.d.ts +59 -0
- package/dist/composition/quantity.d.ts.map +1 -0
- package/dist/composition/quantity.js +36 -0
- package/dist/composition/quantity.js.map +1 -0
- package/dist/composition/retrodiction.d.ts +94 -0
- package/dist/composition/retrodiction.d.ts.map +1 -0
- package/dist/composition/retrodiction.js +171 -0
- package/dist/composition/retrodiction.js.map +1 -0
- package/dist/composition/symbolic-constants.d.ts +33 -0
- package/dist/composition/symbolic-constants.d.ts.map +1 -0
- package/dist/composition/symbolic-constants.js +50 -0
- package/dist/composition/symbolic-constants.js.map +1 -0
- package/dist/composition/uncertainty.d.ts +45 -0
- package/dist/composition/uncertainty.d.ts.map +1 -0
- package/dist/composition/uncertainty.js +59 -0
- package/dist/composition/uncertainty.js.map +1 -0
- package/dist/core/axes-registry.d.ts +1 -1
- package/dist/core/axes-registry.js +1 -1
- package/dist/core/cell.d.ts +0 -8
- package/dist/core/cell.d.ts.map +1 -1
- package/dist/core/cell.js +1 -1
- package/dist/core/cell.js.map +1 -1
- package/dist/core/constants.d.ts +15 -1
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +15 -1
- package/dist/core/constants.js.map +1 -1
- package/dist/core/flux-rules.d.ts +10 -13
- package/dist/core/flux-rules.d.ts.map +1 -1
- package/dist/core/flux-rules.js +19 -10
- package/dist/core/flux-rules.js.map +1 -1
- package/dist/core/labeled-tensor.d.ts +80 -1
- package/dist/core/labeled-tensor.d.ts.map +1 -1
- package/dist/core/labeled-tensor.js +263 -17
- package/dist/core/labeled-tensor.js.map +1 -1
- package/dist/core/universal-index.d.ts +1 -1
- package/dist/core/universal-index.js +1 -1
- package/dist/dimensional/buckingham.d.ts +103 -0
- package/dist/dimensional/buckingham.d.ts.map +1 -0
- package/dist/dimensional/buckingham.js +284 -0
- package/dist/dimensional/buckingham.js.map +1 -0
- package/dist/dimensional/dimension-spec.d.ts +24 -0
- package/dist/dimensional/dimension-spec.d.ts.map +1 -0
- package/dist/dimensional/dimension-spec.js +110 -0
- package/dist/dimensional/dimension-spec.js.map +1 -0
- package/dist/dimensional/field-equation-helpers.d.ts +1 -1
- package/dist/dimensional/field-equation-helpers.js +1 -1
- package/dist/dimensional/friedmann-equation.d.ts +1 -1
- package/dist/dimensional/friedmann-equation.js +1 -1
- package/dist/dimensional/gauge-field.d.ts +1 -1
- package/dist/dimensional/gauge-field.js +1 -1
- package/dist/dimensional/klein-gordon-equation.d.ts +8 -5
- package/dist/dimensional/klein-gordon-equation.d.ts.map +1 -1
- package/dist/dimensional/klein-gordon-equation.js +8 -5
- package/dist/dimensional/klein-gordon-equation.js.map +1 -1
- package/dist/dimensional/tensor-trace.d.ts +1 -1
- package/dist/dimensional/tensor-trace.js +1 -1
- package/dist/dimensional/validator.d.ts +13 -3
- package/dist/dimensional/validator.d.ts.map +1 -1
- package/dist/dimensional/validator.js +129 -42
- package/dist/dimensional/validator.js.map +1 -1
- package/dist/index.d.ts +32 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -2
- package/dist/index.js.map +1 -1
- package/dist/numerical/be37-covariant-eikonal.d.ts.map +1 -1
- package/dist/numerical/be37-covariant-eikonal.js +15 -18
- package/dist/numerical/be37-covariant-eikonal.js.map +1 -1
- package/dist/numerical/curvature-lowering-helpers.d.ts +7 -13
- package/dist/numerical/curvature-lowering-helpers.d.ts.map +1 -1
- package/dist/numerical/curvature-lowering-helpers.js +1 -1
- package/dist/numerical/curvature-lowering-helpers.js.map +1 -1
- package/dist/numerical/derivative-lowering.d.ts +2 -1
- package/dist/numerical/derivative-lowering.d.ts.map +1 -1
- package/dist/numerical/formula-dimension.d.ts +40 -0
- package/dist/numerical/formula-dimension.d.ts.map +1 -0
- package/dist/numerical/formula-dimension.js +199 -0
- package/dist/numerical/formula-dimension.js.map +1 -0
- package/dist/numerical/formula-mathts.d.ts +27 -0
- package/dist/numerical/formula-mathts.d.ts.map +1 -0
- package/dist/numerical/formula-mathts.js +98 -0
- package/dist/numerical/formula-mathts.js.map +1 -0
- package/dist/numerical/formula-registry.d.ts +30 -0
- package/dist/numerical/formula-registry.d.ts.map +1 -0
- package/dist/numerical/formula-registry.js +88 -0
- package/dist/numerical/formula-registry.js.map +1 -0
- package/dist/numerical/formula.d.ts +75 -0
- package/dist/numerical/formula.d.ts.map +1 -0
- package/dist/numerical/formula.js +275 -0
- package/dist/numerical/formula.js.map +1 -0
- package/dist/numerical/geometrized.d.ts +51 -0
- package/dist/numerical/geometrized.d.ts.map +1 -0
- package/dist/numerical/geometrized.js +66 -0
- package/dist/numerical/geometrized.js.map +1 -0
- package/dist/numerical/gl4-integrator.d.ts +8 -6
- package/dist/numerical/gl4-integrator.d.ts.map +1 -1
- package/dist/numerical/gl4-integrator.js +6 -6
- package/dist/numerical/gl4-integrator.js.map +1 -1
- package/dist/numerical/klein-gordon.d.ts +145 -0
- package/dist/numerical/klein-gordon.d.ts.map +1 -0
- package/dist/numerical/klein-gordon.js +145 -0
- package/dist/numerical/klein-gordon.js.map +1 -0
- package/dist/numerical/kretschmann.d.ts +43 -12
- package/dist/numerical/kretschmann.d.ts.map +1 -1
- package/dist/numerical/kretschmann.js +116 -29
- package/dist/numerical/kretschmann.js.map +1 -1
- package/dist/numerical/lowering.d.ts +18 -0
- package/dist/numerical/lowering.d.ts.map +1 -1
- package/dist/numerical/lowering.js +54 -42
- package/dist/numerical/lowering.js.map +1 -1
- package/dist/numerical/null-ic.d.ts +1 -1
- package/dist/numerical/null-ic.d.ts.map +1 -1
- package/dist/numerical/null-ic.js +3 -2
- package/dist/numerical/null-ic.js.map +1 -1
- package/dist/numerical/painleve-gullstrand-metric.d.ts +18 -6
- package/dist/numerical/painleve-gullstrand-metric.d.ts.map +1 -1
- package/dist/numerical/painleve-gullstrand-metric.js +31 -16
- package/dist/numerical/painleve-gullstrand-metric.js.map +1 -1
- package/dist/numerical/perihelion-finder.d.ts +4 -3
- package/dist/numerical/perihelion-finder.d.ts.map +1 -1
- package/dist/numerical/perihelion-finder.js +5 -4
- package/dist/numerical/perihelion-finder.js.map +1 -1
- package/dist/numerical/types.d.ts +6 -3
- package/dist/numerical/types.d.ts.map +1 -1
- package/dist/numerical/weyl-lowering.d.ts +4 -4
- package/dist/numerical/weyl-lowering.d.ts.map +1 -1
- package/dist/numerical/weyl-lowering.js +14 -1
- package/dist/numerical/weyl-lowering.js.map +1 -1
- package/package.json +19 -8
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Explain this quantity" — the unified entry point over the three
|
|
3
|
+
* bridge-inference primitives (docs/planning/Bridge-Inference-Epistemics-
|
|
4
|
+
* Note.md). Given a target quantity and a set of knowns (names, or
|
|
5
|
+
* name→value), it composes:
|
|
6
|
+
*
|
|
7
|
+
* 1. the identifiability classifier — CAN the graph compute the target
|
|
8
|
+
* from the knowns, and via how many independent derivations?
|
|
9
|
+
* 2. the retrodiction harness — when values are supplied, RECOVER the
|
|
10
|
+
* value via each derivation and (for over-determined targets) check
|
|
11
|
+
* they agree;
|
|
12
|
+
* 3. the Buckingham-π enumerator — is the known set even DIMENSIONALLY
|
|
13
|
+
* sufficient to fix the target up to a constant, independent of the
|
|
14
|
+
* graph's encoded edges?
|
|
15
|
+
*
|
|
16
|
+
* The three answer complementary questions, so the explanation is richer
|
|
17
|
+
* than any one alone: the graph may compute a target whose dimensional
|
|
18
|
+
* closure relies on constants baked into the evaluator (e.g. r_s = 2GM/c²
|
|
19
|
+
* — mass alone is not dimensionally sufficient), and the classifier +
|
|
20
|
+
* Buckingham layer make that explicit together.
|
|
21
|
+
*
|
|
22
|
+
* @module composition/explain
|
|
23
|
+
*/
|
|
24
|
+
import type { BridgeEdge } from './edge.js';
|
|
25
|
+
import type { QuantityIdentification } from './compose.js';
|
|
26
|
+
import type { IdentifiabilityResult } from './identifiability.js';
|
|
27
|
+
import type { RetrodictionResult } from './retrodiction.js';
|
|
28
|
+
import type { Dimension } from '../dimensional/types.js';
|
|
29
|
+
import type { DimensionalDeterminationResult } from '../dimensional/buckingham.js';
|
|
30
|
+
/** One structural derivation of the target, with the recovered value when
|
|
31
|
+
* ground-truth values were supplied. @public */
|
|
32
|
+
export interface DerivationExplanation {
|
|
33
|
+
readonly edge: string;
|
|
34
|
+
readonly label: string;
|
|
35
|
+
/** The edge's immediate (last-hop) source quantities. */
|
|
36
|
+
readonly sources: readonly string[];
|
|
37
|
+
/**
|
|
38
|
+
* The LEAF inputs this derivation ultimately depends on — its immediate
|
|
39
|
+
* sources traced back through every intermediate to the known set. The
|
|
40
|
+
* full-chain (leaf-to-target) view, vs `sources` (last-hop). A subset of
|
|
41
|
+
* the known set.
|
|
42
|
+
*/
|
|
43
|
+
readonly leafInputs: readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* The target as a dimensionless-constant-times-monomial in the LEAF
|
|
46
|
+
* inputs, when those leaves dimensionally fix it (Buckingham-π over the
|
|
47
|
+
* full chain). Absent when the leaves rely on dimensionful constants
|
|
48
|
+
* baked into the evaluators (the common case for the bridge graph).
|
|
49
|
+
*/
|
|
50
|
+
readonly dimensionalForm?: {
|
|
51
|
+
readonly monomial: Readonly<Record<string, number>>;
|
|
52
|
+
/** e.g. `period ∝ length^1·gravity^-1` (up to a dimensionless constant). */
|
|
53
|
+
readonly formula: string;
|
|
54
|
+
};
|
|
55
|
+
/** Value recovered via this derivation (only when values were given). */
|
|
56
|
+
readonly value?: number;
|
|
57
|
+
}
|
|
58
|
+
/** Options for {@link explainQuantity}. @public */
|
|
59
|
+
export interface ExplainOptions {
|
|
60
|
+
readonly identifications?: readonly QuantityIdentification[];
|
|
61
|
+
/** Consistency tolerance forwarded to the retrodiction harness. */
|
|
62
|
+
readonly tolerance?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Dimensions for known names that are not graph quantities (e.g. raw
|
|
65
|
+
* constants `G`, `c`, `hbar`) — lets the Buckingham layer test a known
|
|
66
|
+
* set richer than the graph's nodes.
|
|
67
|
+
*/
|
|
68
|
+
readonly extraDimensions?: Readonly<Record<string, Dimension>>;
|
|
69
|
+
}
|
|
70
|
+
/** The unified explanation of one quantity. @public */
|
|
71
|
+
export interface QuantityExplanation {
|
|
72
|
+
readonly target: string;
|
|
73
|
+
readonly known: readonly string[];
|
|
74
|
+
/** Structural verdict (under/exactly/over-determined or given). */
|
|
75
|
+
readonly identifiability: IdentifiabilityResult;
|
|
76
|
+
/** One entry per independent derivation the classifier found. */
|
|
77
|
+
readonly derivations: readonly DerivationExplanation[];
|
|
78
|
+
/** Retrodiction result, present when ≥2 derivations fired on values. */
|
|
79
|
+
readonly consistency?: RetrodictionResult;
|
|
80
|
+
/** Agreed recovered value (consistent or single), when values supplied. */
|
|
81
|
+
readonly recoveredValue?: number;
|
|
82
|
+
/** Whether the KNOWN set dimensionally fixes the target (Buckingham-π);
|
|
83
|
+
* absent when the target has no resolvable dimension. */
|
|
84
|
+
readonly dimensional?: DimensionalDeterminationResult;
|
|
85
|
+
/** Upstream gaps for an under-determined target (from the classifier). */
|
|
86
|
+
readonly blockingFrontier: readonly string[];
|
|
87
|
+
/** Plain-language synthesis of the above. */
|
|
88
|
+
readonly summary: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Explain a quantity: synthesize the identifiability verdict, the
|
|
92
|
+
* recovered value + consistency (when values are supplied), and the
|
|
93
|
+
* dimensional sufficiency of the known set into one report.
|
|
94
|
+
*
|
|
95
|
+
* `known` may be a list of names (structural + dimensional analysis only)
|
|
96
|
+
* or a `name → value` map (adds value recovery and the over-determined
|
|
97
|
+
* consistency check).
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
export declare function explainQuantity(edges: readonly BridgeEdge[], target: string, known: readonly string[] | Readonly<Record<string, number>>, opts?: ExplainOptions): QuantityExplanation;
|
|
102
|
+
//# sourceMappingURL=explain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.d.ts","sourceRoot":"","sources":["../../src/composition/explain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAGnF;iDACiD;AACjD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;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AM,CAAC;CAC1B;AAmID;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC3D,IAAI,GAAE,cAAmB,GACxB,mBAAmB,CAoHrB"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Explain this quantity" — the unified entry point over the three
|
|
3
|
+
* bridge-inference primitives (docs/planning/Bridge-Inference-Epistemics-
|
|
4
|
+
* Note.md). Given a target quantity and a set of knowns (names, or
|
|
5
|
+
* name→value), it composes:
|
|
6
|
+
*
|
|
7
|
+
* 1. the identifiability classifier — CAN the graph compute the target
|
|
8
|
+
* from the knowns, and via how many independent derivations?
|
|
9
|
+
* 2. the retrodiction harness — when values are supplied, RECOVER the
|
|
10
|
+
* value via each derivation and (for over-determined targets) check
|
|
11
|
+
* they agree;
|
|
12
|
+
* 3. the Buckingham-π enumerator — is the known set even DIMENSIONALLY
|
|
13
|
+
* sufficient to fix the target up to a constant, independent of the
|
|
14
|
+
* graph's encoded edges?
|
|
15
|
+
*
|
|
16
|
+
* The three answer complementary questions, so the explanation is richer
|
|
17
|
+
* than any one alone: the graph may compute a target whose dimensional
|
|
18
|
+
* closure relies on constants baked into the evaluator (e.g. r_s = 2GM/c²
|
|
19
|
+
* — mass alone is not dimensionally sufficient), and the classifier +
|
|
20
|
+
* Buckingham layer make that explicit together.
|
|
21
|
+
*
|
|
22
|
+
* @module composition/explain
|
|
23
|
+
*/
|
|
24
|
+
import { QUANTITY_IDENTIFICATIONS } from './compose.js';
|
|
25
|
+
import { classifyIdentifiability, forwardClosure } from './identifiability.js';
|
|
26
|
+
import { retrodictNode } from './retrodiction.js';
|
|
27
|
+
import { dimensionallyDetermines } from '../dimensional/buckingham.js';
|
|
28
|
+
function buildDimMap(edges, extra) {
|
|
29
|
+
const m = new Map();
|
|
30
|
+
for (const e of edges) {
|
|
31
|
+
for (const s of e.sources)
|
|
32
|
+
if (!m.has(s.name))
|
|
33
|
+
m.set(s.name, s.dim);
|
|
34
|
+
if (!m.has(e.target.name))
|
|
35
|
+
m.set(e.target.name, e.target.dim);
|
|
36
|
+
}
|
|
37
|
+
if (extra)
|
|
38
|
+
for (const [k, v] of Object.entries(extra))
|
|
39
|
+
m.set(k, v);
|
|
40
|
+
return m;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Trace `startSources` back through every intermediate to the leaf inputs
|
|
44
|
+
* — names in `known`, or terminals that no determinable edge produces.
|
|
45
|
+
* Never expands the target (a self-loop would be circular). The union over
|
|
46
|
+
* alternative sub-derivations of an over-determined intermediate.
|
|
47
|
+
*/
|
|
48
|
+
function traceLeaves(edges, known, determinable, startSources, idents, target) {
|
|
49
|
+
const leaves = new Set();
|
|
50
|
+
const visited = new Set([target]); // never expand the target itself
|
|
51
|
+
const stack = [...startSources];
|
|
52
|
+
while (stack.length) {
|
|
53
|
+
const q = stack.pop();
|
|
54
|
+
if (known.has(q)) {
|
|
55
|
+
leaves.add(q);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (visited.has(q))
|
|
59
|
+
continue;
|
|
60
|
+
visited.add(q);
|
|
61
|
+
let expanded = false;
|
|
62
|
+
for (const e of edges) {
|
|
63
|
+
if (e.target.name !== q)
|
|
64
|
+
continue;
|
|
65
|
+
if (!e.sources.every((s) => determinable.has(s.name)))
|
|
66
|
+
continue;
|
|
67
|
+
for (const s of e.sources)
|
|
68
|
+
stack.push(s.name);
|
|
69
|
+
expanded = true;
|
|
70
|
+
}
|
|
71
|
+
if (!expanded) {
|
|
72
|
+
for (const id of idents) {
|
|
73
|
+
if (id.to === q && determinable.has(id.from)) {
|
|
74
|
+
stack.push(id.from);
|
|
75
|
+
expanded = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!expanded)
|
|
80
|
+
leaves.add(q); // a terminal we cannot expand
|
|
81
|
+
}
|
|
82
|
+
return [...leaves].sort();
|
|
83
|
+
}
|
|
84
|
+
function formatMonomial(m) {
|
|
85
|
+
const parts = Object.entries(m)
|
|
86
|
+
.filter(([, e]) => e !== 0)
|
|
87
|
+
.map(([n, e]) => (e === 1 ? n : `${n}^${e}`));
|
|
88
|
+
return parts.join('·') || '1';
|
|
89
|
+
}
|
|
90
|
+
function buildSummary(target, id, derivations, consistency, recoveredValue, dimensional, knownNames) {
|
|
91
|
+
const known = knownNames.length
|
|
92
|
+
? `{${knownNames.join(', ')}}`
|
|
93
|
+
: '{} (no inputs)';
|
|
94
|
+
const ids = derivations.map((d) => d.edge).join(', ');
|
|
95
|
+
let s;
|
|
96
|
+
switch (id.verdict) {
|
|
97
|
+
case 'given':
|
|
98
|
+
s = `'${target}' is a supplied input.`;
|
|
99
|
+
if (derivations.length) {
|
|
100
|
+
s += ` ${derivations.length} graph derivation(s) (${ids}) can cross-check it`;
|
|
101
|
+
s += consistency
|
|
102
|
+
? consistency.outcome === 'consistent'
|
|
103
|
+
? `, and they are consistent (relative spread ${consistency.relativeSpread.toExponential(1)}).`
|
|
104
|
+
: ` — and they are INCONSISTENT (relative spread ${consistency.relativeSpread.toExponential(1)}).`
|
|
105
|
+
: '.';
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case 'under-determined':
|
|
109
|
+
s = `'${target}' cannot be determined from ${known}: the graph has no derivation path.`;
|
|
110
|
+
if (id.blockingFrontier.length) {
|
|
111
|
+
s += ` Knowing one of {${id.blockingFrontier.join(', ')}} would unblock it.`;
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case 'exactly-determined':
|
|
115
|
+
s = `'${target}' is determined from ${known} via ${derivations[0]?.edge} (${derivations[0]?.label}).`;
|
|
116
|
+
if (recoveredValue !== undefined) {
|
|
117
|
+
s += ` Recovered value: ${recoveredValue.toExponential(4)}.`;
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
case 'over-determined':
|
|
121
|
+
default:
|
|
122
|
+
s = `'${target}' is over-determined from ${known}: ${derivations.length} independent derivations (${ids}).`;
|
|
123
|
+
if (consistency) {
|
|
124
|
+
s +=
|
|
125
|
+
consistency.outcome === 'consistent'
|
|
126
|
+
? ` They agree (relative spread ${consistency.relativeSpread.toExponential(1)}) — a passing consistency check.`
|
|
127
|
+
: ` They DISAGREE (relative spread ${consistency.relativeSpread.toExponential(1)}) — a falsification.`;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
s += ` The ${id.surplusConstraints} surplus derivation(s) are falsifiable consistency constraints (supply values to check them).`;
|
|
131
|
+
}
|
|
132
|
+
if (recoveredValue !== undefined) {
|
|
133
|
+
s += ` Recovered value: ${recoveredValue.toExponential(4)}.`;
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
if (dimensional?.determined && dimensional.monomial) {
|
|
138
|
+
s += ` Dimensionally, ${known} fix it up to a dimensionless constant: ${target} ∝ ${formatMonomial(dimensional.monomial)}.`;
|
|
139
|
+
}
|
|
140
|
+
else if (dimensional && !dimensional.determined && knownNames.length) {
|
|
141
|
+
s += ` Dimensionally, those inputs alone do not fix it — the encoded formula carries dimensionful constants.`;
|
|
142
|
+
}
|
|
143
|
+
return s;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Explain a quantity: synthesize the identifiability verdict, the
|
|
147
|
+
* recovered value + consistency (when values are supplied), and the
|
|
148
|
+
* dimensional sufficiency of the known set into one report.
|
|
149
|
+
*
|
|
150
|
+
* `known` may be a list of names (structural + dimensional analysis only)
|
|
151
|
+
* or a `name → value` map (adds value recovery and the over-determined
|
|
152
|
+
* consistency check).
|
|
153
|
+
*
|
|
154
|
+
* @public
|
|
155
|
+
*/
|
|
156
|
+
export function explainQuantity(edges, target, known, opts = {}) {
|
|
157
|
+
const identifications = opts.identifications ?? QUANTITY_IDENTIFICATIONS;
|
|
158
|
+
const hasValues = !Array.isArray(known);
|
|
159
|
+
const values = hasValues ? known : null;
|
|
160
|
+
const knownNames = hasValues
|
|
161
|
+
? Object.keys(values)
|
|
162
|
+
: [...new Set(known)];
|
|
163
|
+
const identifiability = classifyIdentifiability(edges, knownNames, target, {
|
|
164
|
+
identifications,
|
|
165
|
+
});
|
|
166
|
+
const byId = new Map(edges.map((e) => [e.id, e]));
|
|
167
|
+
let consistency;
|
|
168
|
+
let recoveredValue;
|
|
169
|
+
const valueByEdge = new Map();
|
|
170
|
+
if (values) {
|
|
171
|
+
const references = target in values ? { [target]: values[target] } : undefined;
|
|
172
|
+
const retro = retrodictNode(edges, values, target, {
|
|
173
|
+
identifications,
|
|
174
|
+
tolerance: opts.tolerance,
|
|
175
|
+
references,
|
|
176
|
+
});
|
|
177
|
+
for (const p of retro.predictions)
|
|
178
|
+
valueByEdge.set(p.edge, p.value);
|
|
179
|
+
if (retro.predictions.length >= 2)
|
|
180
|
+
consistency = retro;
|
|
181
|
+
if ((retro.outcome === 'consistent' || retro.outcome === 'single') &&
|
|
182
|
+
retro.predictions.length > 0) {
|
|
183
|
+
recoveredValue =
|
|
184
|
+
retro.predictions.reduce((a, p) => a + p.value, 0) /
|
|
185
|
+
retro.predictions.length;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const dimMap = buildDimMap(edges, opts.extraDimensions);
|
|
189
|
+
const knownSet = new Set(knownNames);
|
|
190
|
+
const determinable = forwardClosure(edges, knownNames, identifications);
|
|
191
|
+
const derivations = identifiability.derivations.map((eid) => {
|
|
192
|
+
const e = byId.get(eid);
|
|
193
|
+
const sources = e ? e.sources.map((s) => s.name) : [];
|
|
194
|
+
// Full-chain: trace the immediate sources back to the leaf inputs.
|
|
195
|
+
const leafInputs = e
|
|
196
|
+
? traceLeaves(edges, knownSet, determinable, sources, identifications, target)
|
|
197
|
+
: [];
|
|
198
|
+
// Dimensional form in terms of those leaves, when they fix the target.
|
|
199
|
+
let dimensionalForm;
|
|
200
|
+
const targetDimForChain = dimMap.get(target);
|
|
201
|
+
if (targetDimForChain && leafInputs.length) {
|
|
202
|
+
const governing = leafInputs
|
|
203
|
+
.filter((n) => n !== target && dimMap.has(n))
|
|
204
|
+
.map((n) => ({ name: n, dim: dimMap.get(n) }));
|
|
205
|
+
const det = dimensionallyDetermines({ name: target, dim: targetDimForChain }, governing);
|
|
206
|
+
if (det.determined && det.monomial) {
|
|
207
|
+
dimensionalForm = {
|
|
208
|
+
monomial: det.monomial,
|
|
209
|
+
formula: `${target} ∝ ${formatMonomial(det.monomial)}`,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
edge: eid,
|
|
215
|
+
label: e?.label ?? eid,
|
|
216
|
+
sources,
|
|
217
|
+
leafInputs,
|
|
218
|
+
...(dimensionalForm ? { dimensionalForm } : {}),
|
|
219
|
+
...(valueByEdge.has(eid) ? { value: valueByEdge.get(eid) } : {}),
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
// Dimensional sufficiency of the KNOWN set, independent of the graph.
|
|
223
|
+
let dimensional;
|
|
224
|
+
const targetDim = dimMap.get(target);
|
|
225
|
+
if (targetDim) {
|
|
226
|
+
const governing = knownNames
|
|
227
|
+
.filter((n) => n !== target && dimMap.has(n))
|
|
228
|
+
.map((n) => ({ name: n, dim: dimMap.get(n) }));
|
|
229
|
+
dimensional = dimensionallyDetermines({ name: target, dim: targetDim }, governing);
|
|
230
|
+
}
|
|
231
|
+
const summary = buildSummary(target, identifiability, derivations, consistency, recoveredValue, dimensional, knownNames);
|
|
232
|
+
return {
|
|
233
|
+
target,
|
|
234
|
+
known: knownNames,
|
|
235
|
+
identifiability,
|
|
236
|
+
derivations,
|
|
237
|
+
...(consistency ? { consistency } : {}),
|
|
238
|
+
...(recoveredValue !== undefined ? { recoveredValue } : {}),
|
|
239
|
+
...(dimensional ? { dimensional } : {}),
|
|
240
|
+
blockingFrontier: identifiability.blockingFrontier,
|
|
241
|
+
summary,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=explain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../../src/composition/explain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAiEvE,SAAS,WAAW,CAClB,KAA4B,EAC5B,KAA2C;IAE3C,MAAM,CAAC,GAAG,IAAI,GAAG,EAAqB,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO;YAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;gBAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QACpE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,KAAK;QAAE,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnE,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;;GAKG;AACH,SA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CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,CAAC;IACrF,CAAC;IAED,MAAM,OAAO,GAAG,YAAY,CAC1B,MAAM,EACN,eAAe,EACf,WAAW,EACX,WAAW,EACX,cAAc,EACd,WAAW,EACX,UAAU,CACX,CAAC;IAEF,OAAO;QACL,MAAM;QACN,KAAK,EAAE,UAAU;QACjB,eAAe;QACf,WAAW;QACX,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,GAAG,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3D,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,gBAAgB,EAAE,eAAe,CAAC,gBAAgB;QAClD,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scalar `ExprNode` value evaluator (v0.12 symbolic composition).
|
|
3
|
+
*
|
|
4
|
+
* Numerically evaluates a SCALAR `ExprNode` (the `symbol` / `op` / `integral`
|
|
5
|
+
* / `derivative` arms) given leaf values. The dimensional validator infers
|
|
6
|
+
* dimensions but never computes values, and the formula parser evaluates a
|
|
7
|
+
* DIFFERENT AST — so this is the missing primitive that makes a bridge's
|
|
8
|
+
* `symbolic` form executable.
|
|
9
|
+
*
|
|
10
|
+
* Leaf resolution order (Adam A-1, A-5): caller `values` win, then the
|
|
11
|
+
* `CONSTANTS` registry, then a base-10 numeric-literal symbol (`'2'`, `'3'`);
|
|
12
|
+
* an unresolved or non-finite leaf throws. `^` reads its exponent from the
|
|
13
|
+
* second arg's `name` via `Number(...)` (matching validator.ts) and uses
|
|
14
|
+
* `Math.pow`. Tensor / integral / derivative arms are out of scope and throw.
|
|
15
|
+
*
|
|
16
|
+
* INTERNAL — not on the public surface.
|
|
17
|
+
*
|
|
18
|
+
* @module composition/expr-eval
|
|
19
|
+
*/
|
|
20
|
+
import type { ExprNode } from '../dimensional/validator.js';
|
|
21
|
+
/** A scalar `ExprNode` could not be evaluated (unsupported arm / unresolved
|
|
22
|
+
* leaf / non-finite result). @public */
|
|
23
|
+
export declare class SymbolicEvalError extends Error {
|
|
24
|
+
constructor(message: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Evaluate a scalar `ExprNode` to a number. See module docs for the leaf
|
|
28
|
+
* resolution order and scope.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare function evalExpr(node: ExprNode, values?: Readonly<Record<string, number>>): number;
|
|
33
|
+
//# sourceMappingURL=expr-eval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expr-eval.d.ts","sourceRoot":"","sources":["../../src/composition/expr-eval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAG5D;yCACyC;AACzC,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAeD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,QAAQ,EACd,MAAM,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,GAC5C,MAAM,CAyCR"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scalar `ExprNode` value evaluator (v0.12 symbolic composition).
|
|
3
|
+
*
|
|
4
|
+
* Numerically evaluates a SCALAR `ExprNode` (the `symbol` / `op` / `integral`
|
|
5
|
+
* / `derivative` arms) given leaf values. The dimensional validator infers
|
|
6
|
+
* dimensions but never computes values, and the formula parser evaluates a
|
|
7
|
+
* DIFFERENT AST — so this is the missing primitive that makes a bridge's
|
|
8
|
+
* `symbolic` form executable.
|
|
9
|
+
*
|
|
10
|
+
* Leaf resolution order (Adam A-1, A-5): caller `values` win, then the
|
|
11
|
+
* `CONSTANTS` registry, then a base-10 numeric-literal symbol (`'2'`, `'3'`);
|
|
12
|
+
* an unresolved or non-finite leaf throws. `^` reads its exponent from the
|
|
13
|
+
* second arg's `name` via `Number(...)` (matching validator.ts) and uses
|
|
14
|
+
* `Math.pow`. Tensor / integral / derivative arms are out of scope and throw.
|
|
15
|
+
*
|
|
16
|
+
* INTERNAL — not on the public surface.
|
|
17
|
+
*
|
|
18
|
+
* @module composition/expr-eval
|
|
19
|
+
*/
|
|
20
|
+
import { CONSTANTS } from './symbolic-constants.js';
|
|
21
|
+
/** A scalar `ExprNode` could not be evaluated (unsupported arm / unresolved
|
|
22
|
+
* leaf / non-finite result). @public */
|
|
23
|
+
export class SymbolicEvalError extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = 'SymbolicEvalError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Resolve a leaf symbol's numeric value: values → CONSTANTS → literal. */
|
|
30
|
+
function resolveLeaf(name, values) {
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(values, name))
|
|
32
|
+
return values[name];
|
|
33
|
+
const constant = CONSTANTS[name];
|
|
34
|
+
if (constant !== undefined)
|
|
35
|
+
return constant.value;
|
|
36
|
+
const literal = Number(name);
|
|
37
|
+
if (Number.isFinite(literal))
|
|
38
|
+
return literal;
|
|
39
|
+
throw new SymbolicEvalError(`evalExpr: leaf symbol '${name}' has no value (not in inputs, not a ` +
|
|
40
|
+
`registered constant, not a numeric literal).`);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Evaluate a scalar `ExprNode` to a number. See module docs for the leaf
|
|
44
|
+
* resolution order and scope.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export function evalExpr(node, values = {}) {
|
|
49
|
+
switch (node.kind) {
|
|
50
|
+
case 'symbol':
|
|
51
|
+
return resolveLeaf(node.name, values);
|
|
52
|
+
case 'op': {
|
|
53
|
+
if (node.op === '^') {
|
|
54
|
+
if (node.args.length !== 2) {
|
|
55
|
+
throw new SymbolicEvalError(`evalExpr: '^' needs exactly 2 args, got ${node.args.length}.`);
|
|
56
|
+
}
|
|
57
|
+
// The exponent may be a numeric-literal symbol (resolveLeaf returns its
|
|
58
|
+
// value) OR a general input-dependent expression (v0.13 — e.g. −1/z).
|
|
59
|
+
// `finite()` still catches a non-finite result (NaN/Inf).
|
|
60
|
+
const base = evalExpr(node.args[0], values);
|
|
61
|
+
const exp = evalExpr(node.args[1], values);
|
|
62
|
+
return finite(Math.pow(base, exp), node);
|
|
63
|
+
}
|
|
64
|
+
if (node.args.length === 0) {
|
|
65
|
+
// Mirrors the validator's empty-op convention: * / → 1, + - → 0.
|
|
66
|
+
return node.op === '*' || node.op === '/' ? 1 : 0;
|
|
67
|
+
}
|
|
68
|
+
let acc = evalExpr(node.args[0], values);
|
|
69
|
+
for (let i = 1; i < node.args.length; i++) {
|
|
70
|
+
const v = evalExpr(node.args[i], values);
|
|
71
|
+
if (node.op === '+')
|
|
72
|
+
acc += v;
|
|
73
|
+
else if (node.op === '-')
|
|
74
|
+
acc -= v;
|
|
75
|
+
else if (node.op === '*')
|
|
76
|
+
acc *= v;
|
|
77
|
+
else
|
|
78
|
+
acc /= v;
|
|
79
|
+
}
|
|
80
|
+
return finite(acc, node);
|
|
81
|
+
}
|
|
82
|
+
default:
|
|
83
|
+
throw new SymbolicEvalError(`evalExpr: node kind '${node.kind}' is out of scope (scalar ` +
|
|
84
|
+
`symbol/op only; integral/derivative/tensor nodes are not ` +
|
|
85
|
+
`numerically evaluable here).`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function finite(value, node) {
|
|
89
|
+
if (!Number.isFinite(value)) {
|
|
90
|
+
throw new SymbolicEvalError(`evalExpr: '${node.op ?? node.kind}' produced a ` +
|
|
91
|
+
`non-finite value (${value}).`);
|
|
92
|
+
}
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=expr-eval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expr-eval.js","sourceRoot":"","sources":["../../src/composition/expr-eval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD;yCACyC;AACzC,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,2EAA2E;AAC3E,SAAS,WAAW,CAAC,IAAY,EAAE,MAAwC;IACzE,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5E,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC,KAAK,CAAC;IAClD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAC7C,MAAM,IAAI,iBAAiB,CACzB,0BAA0B,IAAI,uCAAuC;QACnE,8CAA8C,CACjD,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAc,EACd,SAA2C,EAAE;IAE7C,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,WAAW,CAAC,IAAI,CAAC,I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AAE,GAAG,IAAI,CAAC,CAAC;qBACzB,IAAI,IAAI,CAAC,EAAE,KAAK,GAAG;oBAAE,GAAG,IAAI,CAAC,CAAC;qBAC9B,IAAI,IAAI,CAAC,EAAE,KAAK,GAAG;oBAAE,GAAG,IAAI,CAAC,CAAC;;oBAC9B,GAAG,IAAI,CAAC,CAAC;YAChB,CAAC;YACD,OAAO,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC3B,CAAC;QAED;YACE,MAAM,IAAI,iBAAiB,CACzB,wBAAwB,IAAI,CAAC,IAAI,4BAA4B;gBAC3D,2DAA2D;gBAC3D,8BAA8B,CACjC,CAAC;IACN,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,KAAa,EAAE,IAAc;IAC3C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,iBAAiB,CACzB,cAAe,IAAwB,CAAC,EAAE,IAAI,IAAI,CAAC,IAAI,eAAe;YACpE,qBAAqB,KAAK,IAAI,CACjC,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbolic simplification of a scalar `ExprNode` via MathTS (v0.12 — optional
|
|
3
|
+
* supplement to symbolic composition).
|
|
4
|
+
*
|
|
5
|
+
* Composing two bridges' symbolic forms leaves an UNSIMPLIFIED AST — CT-1 is
|
|
6
|
+
* `k_B·(ℏc³/8πG·mass·k_B)·ln2`, with `k_B` uncancelled. This folds it to the
|
|
7
|
+
* canonical `ℏc³·ln2/(8πG·mass)` using `@danielsimonjr/mathts-functions`'
|
|
8
|
+
* `simplify` (the same OPTIONAL peer the Path-A formula parser loads).
|
|
9
|
+
*
|
|
10
|
+
* Pipeline (Adam+Eve-vetted — docs/planning/v0.12.0-Symbolic-Simplification-
|
|
11
|
+
* Design.md): GENSYM every non-exponent leaf to a mathjs-safe identifier
|
|
12
|
+
* (shared by name, so repeated leaves cancel), render FULLY-PARENTHESIZED
|
|
13
|
+
* (EVE-A — no precedence ambiguity), `parse`+`simplify`, walk the result back
|
|
14
|
+
* (un-gensym, INTEGER-exponent-strict — EVE/Adam HIGH-1). Three guards make a
|
|
15
|
+
* black-box CAS safe to trust:
|
|
16
|
+
* 1. dimensional — `validate(simplified)` dim `equals` the original's;
|
|
17
|
+
* 2. structural — non-numeric symbols of the result ⊆ those of the original
|
|
18
|
+
* (no leaf invented — Adam HIGH-2 / EVE-B);
|
|
19
|
+
* 3. numeric — `evalExpr` agrees over ≥2 finite synthesized probes at
|
|
20
|
+
* rel tol 1e-9 (Adam CRITICAL-2 / EVE-C).
|
|
21
|
+
* A representable result that DISAGREES dimensionally/numerically THROWS (a
|
|
22
|
+
* bug to surface); anything we cannot represent / verify / load degrades to a
|
|
23
|
+
* graceful no-op (return the original, `simplified:false`).
|
|
24
|
+
*
|
|
25
|
+
* INTERNAL — surfaced via `upt symbolic --simplify`.
|
|
26
|
+
*
|
|
27
|
+
* @module composition/expr-simplify
|
|
28
|
+
*/
|
|
29
|
+
import type { ExprNode } from '../dimensional/validator.js';
|
|
30
|
+
import type { Observable } from './compose-symbolic.js';
|
|
31
|
+
/** A simplification completed but produced a dimensionally/numerically wrong
|
|
32
|
+
* result (a real bug — not a graceful no-op). @internal */
|
|
33
|
+
export declare class SimplificationError extends Error {
|
|
34
|
+
constructor(message: string);
|
|
35
|
+
}
|
|
36
|
+
/** The result of attempting to simplify an expression. */
|
|
37
|
+
export interface SimplifyResult {
|
|
38
|
+
readonly expr: ExprNode;
|
|
39
|
+
/** True iff MathTS was present AND produced a guard-passing, distinct form. */
|
|
40
|
+
readonly simplified: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Simplify a scalar `ExprNode` via MathTS, guarded. Returns the original
|
|
44
|
+
* unchanged (`simplified:false`) when the peer is absent or the result cannot
|
|
45
|
+
* be represented/verified; THROWS {@link SimplificationError} only when a
|
|
46
|
+
* representable result disagrees dimensionally/numerically. See module docs.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare function simplifyExpr(expr: ExprNode): Promise<SimplifyResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Simplify a composed {@link Observable}: returns a freshly-RECONSTRUCTED
|
|
53
|
+
* Observable (new strict `evaluate` closure over the simplified `expr` +
|
|
54
|
+
* recomputed `leaves`) when simplification succeeds, else the original
|
|
55
|
+
* unchanged. See module docs.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export declare function simplifyObservable(obs: Observable): Promise<Observable>;
|
|
60
|
+
//# sourceMappingURL=expr-simplify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expr-simplify.d.ts","sourceRoot":"","sources":["../../src/composition/expr-simplify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAO5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD;4DAC4D;AAC5D,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAoQD,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,+EAA+E;IAC/E,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,CAmD1E;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAI7E"}
|