universal-physics-tensor 8.0.0 → 9.0.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 +8 -6
- package/data/atlas/atlas.json +21 -21
- package/data/atlas/atlas.jsonld +1 -1
- package/data/atlas/diffusion.json +5 -5
- package/data/atlas/oscillators.json +7 -7
- package/data/atlas/waves.json +11 -11
- package/data/bridge-catalog.json +490 -338
- package/data/bridge-catalog.schema.json +566 -40
- package/data/quantities.json +230 -218
- package/data/quantities.schema.json +52 -0
- package/data/units.json +1149 -0
- package/data/units.schema.json +124 -0
- package/dist/atlas/association.d.ts +1 -1
- package/dist/atlas/benchmark/hybrid-retrieval.d.ts.map +1 -1
- package/dist/atlas/benchmark/hybrid-retrieval.js +2 -5
- package/dist/atlas/benchmark/hybrid-retrieval.js.map +1 -1
- package/dist/atlas/physjs-entries.generated.d.ts +1601 -220
- package/dist/atlas/physjs-entries.generated.d.ts.map +1 -1
- package/dist/atlas/physjs-entries.generated.js +1854 -345
- package/dist/atlas/physjs-entries.generated.js.map +1 -1
- package/dist/atlas/physjs-ref.d.ts +89 -89
- package/dist/atlas/physjs-ref.d.ts.map +1 -1
- package/dist/atlas/physjs-ref.js +128 -176
- package/dist/atlas/physjs-ref.js.map +1 -1
- package/dist/atlas/proof-target.d.ts +16 -8
- package/dist/atlas/proof-target.d.ts.map +1 -1
- package/dist/atlas/proof-target.js +34 -31
- package/dist/atlas/proof-target.js.map +1 -1
- package/dist/bridges/catalog-adapter.d.ts.map +1 -1
- package/dist/bridges/catalog-adapter.js +5 -5
- package/dist/bridges/catalog-adapter.js.map +1 -1
- package/dist/bridges/catalog-load.d.ts +7 -0
- package/dist/bridges/catalog-load.d.ts.map +1 -1
- package/dist/bridges/catalog-load.js +69 -13
- package/dist/bridges/catalog-load.js.map +1 -1
- package/dist/bridges/catalog-types.d.ts +51 -6
- package/dist/bridges/catalog-types.d.ts.map +1 -1
- package/dist/bridges/evaluation-errors.d.ts +76 -0
- package/dist/bridges/evaluation-errors.d.ts.map +1 -0
- package/dist/bridges/evaluation-errors.js +118 -0
- package/dist/bridges/evaluation-errors.js.map +1 -0
- package/dist/bridges/evaluator-inputs.d.ts +5 -3
- package/dist/bridges/evaluator-inputs.d.ts.map +1 -1
- package/dist/bridges/evaluator-inputs.js +24 -24
- package/dist/bridges/evaluator-inputs.js.map +1 -1
- package/dist/bridges/evaluators.d.ts +32 -7
- package/dist/bridges/evaluators.d.ts.map +1 -1
- package/dist/bridges/evaluators.js +131 -29
- package/dist/bridges/evaluators.js.map +1 -1
- package/dist/bridges/expr-parse.d.ts +11 -3
- package/dist/bridges/expr-parse.d.ts.map +1 -1
- package/dist/bridges/expr-parse.js +46 -153
- package/dist/bridges/expr-parse.js.map +1 -1
- package/dist/bridges/holds.d.ts +11 -7
- package/dist/bridges/holds.d.ts.map +1 -1
- package/dist/bridges/holds.js +113 -234
- package/dist/bridges/holds.js.map +1 -1
- package/dist/bridges/input-contract.d.ts +65 -0
- package/dist/bridges/input-contract.d.ts.map +1 -0
- package/dist/bridges/input-contract.js +97 -0
- package/dist/bridges/input-contract.js.map +1 -0
- package/dist/bridges/notices.d.ts +11 -0
- package/dist/bridges/notices.d.ts.map +1 -0
- package/dist/bridges/notices.js +22 -0
- package/dist/bridges/notices.js.map +1 -0
- package/dist/canonical/canonical-equation.d.ts +31 -0
- package/dist/canonical/canonical-equation.d.ts.map +1 -1
- package/dist/canonical/entries/atomic.d.ts.map +1 -1
- package/dist/canonical/entries/atomic.js +11 -1
- package/dist/canonical/entries/atomic.js.map +1 -1
- package/dist/canonical/entries/condensed-matter.d.ts.map +1 -1
- package/dist/canonical/entries/condensed-matter.js +3 -0
- package/dist/canonical/entries/condensed-matter.js.map +1 -1
- package/dist/canonical/entries/dimensional-classics.d.ts.map +1 -1
- package/dist/canonical/entries/dimensional-classics.js +48 -0
- package/dist/canonical/entries/dimensional-classics.js.map +1 -1
- package/dist/canonical/entries/electromagnetism.d.ts.map +1 -1
- package/dist/canonical/entries/electromagnetism.js +30 -0
- package/dist/canonical/entries/electromagnetism.js.map +1 -1
- package/dist/canonical/entries/fluids-waves.d.ts.map +1 -1
- package/dist/canonical/entries/fluids-waves.js +34 -0
- package/dist/canonical/entries/fluids-waves.js.map +1 -1
- package/dist/canonical/entries/mechanics.d.ts.map +1 -1
- package/dist/canonical/entries/mechanics.js +24 -0
- package/dist/canonical/entries/mechanics.js.map +1 -1
- package/dist/canonical/entries/nonmonomial.d.ts.map +1 -1
- package/dist/canonical/entries/nonmonomial.js +15 -4
- package/dist/canonical/entries/nonmonomial.js.map +1 -1
- package/dist/canonical/entries/relativity.d.ts.map +1 -1
- package/dist/canonical/entries/relativity.js +6 -0
- package/dist/canonical/entries/relativity.js.map +1 -1
- package/dist/canonical/entries/statistical-mechanics.d.ts.map +1 -1
- package/dist/canonical/entries/statistical-mechanics.js +19 -0
- package/dist/canonical/entries/statistical-mechanics.js.map +1 -1
- package/dist/canonical/entries/thermo-nuclear-cosmo.d.ts.map +1 -1
- package/dist/canonical/entries/thermo-nuclear-cosmo.js +15 -0
- package/dist/canonical/entries/thermo-nuclear-cosmo.js.map +1 -1
- package/dist/cases/index.d.ts +9 -2
- package/dist/cases/index.d.ts.map +1 -1
- package/dist/cases/index.js +26 -7
- package/dist/cases/index.js.map +1 -1
- package/dist/cases/kepler-rv.js +6 -6
- package/dist/cases/kepler-rv.js.map +1 -1
- package/dist/cli/commands/_discovery-opts.d.ts +2 -1
- package/dist/cli/commands/_discovery-opts.d.ts.map +1 -1
- package/dist/cli/commands/_discovery-opts.js +7 -12
- package/dist/cli/commands/_discovery-opts.js.map +1 -1
- package/dist/cli/commands/atlas.d.ts.map +1 -1
- package/dist/cli/commands/atlas.js +6 -9
- package/dist/cli/commands/atlas.js.map +1 -1
- package/dist/cli/commands/audit.d.ts.map +1 -1
- package/dist/cli/commands/audit.js +1 -2
- package/dist/cli/commands/audit.js.map +1 -1
- package/dist/cli/commands/connectors.d.ts.map +1 -1
- package/dist/cli/commands/connectors.js +8 -9
- package/dist/cli/commands/connectors.js.map +1 -1
- package/dist/cli/commands/derive.js +9 -10
- package/dist/cli/commands/derive.js.map +1 -1
- package/dist/cli/commands/discover.d.ts.map +1 -1
- package/dist/cli/commands/discover.js +3 -4
- package/dist/cli/commands/discover.js.map +1 -1
- package/dist/cli/commands/eval.d.ts.map +1 -1
- package/dist/cli/commands/eval.js +17 -17
- package/dist/cli/commands/eval.js.map +1 -1
- package/dist/cli/commands/evaluate.d.ts +1 -35
- package/dist/cli/commands/evaluate.d.ts.map +1 -1
- package/dist/cli/commands/evaluate.js +56 -187
- package/dist/cli/commands/evaluate.js.map +1 -1
- package/dist/cli/commands/explain.d.ts.map +1 -1
- package/dist/cli/commands/explain.js +43 -38
- package/dist/cli/commands/explain.js.map +1 -1
- package/dist/cli/commands/ground.js +1 -1
- package/dist/cli/commands/ground.js.map +1 -1
- package/dist/cli/commands/map.js +3 -4
- package/dist/cli/commands/map.js.map +1 -1
- package/dist/cli/commands/metric.d.ts.map +1 -1
- package/dist/cli/commands/metric.js +3 -0
- package/dist/cli/commands/metric.js.map +1 -1
- package/dist/cli/commands/regime.js +1 -1
- package/dist/cli/commands/regime.js.map +1 -1
- package/dist/cli/commands/symbolic.d.ts.map +1 -1
- package/dist/cli/commands/symbolic.js +5 -2
- package/dist/cli/commands/symbolic.js.map +1 -1
- package/dist/cli/commands/testplan.js +3 -3
- package/dist/cli/commands/testplan.js.map +1 -1
- package/dist/cli/conventions.d.ts +6 -7
- package/dist/cli/conventions.d.ts.map +1 -1
- package/dist/cli/conventions.js +19 -28
- package/dist/cli/conventions.js.map +1 -1
- package/dist/cli/euler-guard.d.ts +13 -2
- package/dist/cli/euler-guard.d.ts.map +1 -1
- package/dist/cli/euler-guard.js +17 -3
- package/dist/cli/euler-guard.js.map +1 -1
- package/dist/cli/eval-numbers.d.ts +4 -9
- package/dist/cli/eval-numbers.d.ts.map +1 -1
- package/dist/cli/eval-numbers.js +11 -41
- package/dist/cli/eval-numbers.js.map +1 -1
- package/dist/cli/published-url.d.ts +2 -0
- package/dist/cli/published-url.d.ts.map +1 -1
- package/dist/cli/published-url.js +5 -0
- package/dist/cli/published-url.js.map +1 -1
- package/dist/cli/record-tables.d.ts +2 -1
- package/dist/cli/record-tables.d.ts.map +1 -1
- package/dist/cli/record-tables.js +8 -3
- package/dist/cli/record-tables.js.map +1 -1
- package/dist/cli-api.d.ts +45 -12
- package/dist/cli-api.d.ts.map +1 -1
- package/dist/cli-api.js +38 -11
- package/dist/cli-api.js.map +1 -1
- package/dist/composition/adjudication.d.ts +8 -30
- package/dist/composition/adjudication.d.ts.map +1 -1
- package/dist/composition/adjudication.js +15 -67
- package/dist/composition/adjudication.js.map +1 -1
- package/dist/composition/aliases.d.ts +1 -1
- package/dist/composition/aliases.d.ts.map +1 -1
- package/dist/composition/aliases.js +10 -20
- package/dist/composition/aliases.js.map +1 -1
- package/dist/composition/bridge-analysis.d.ts +4 -0
- package/dist/composition/bridge-analysis.d.ts.map +1 -1
- package/dist/composition/bridge-analysis.js +13 -14
- package/dist/composition/bridge-analysis.js.map +1 -1
- package/dist/composition/canonical-graph.d.ts +7 -9
- package/dist/composition/canonical-graph.d.ts.map +1 -1
- package/dist/composition/canonical-graph.js +35 -19
- package/dist/composition/canonical-graph.js.map +1 -1
- package/dist/composition/canonical-prefactors.d.ts +10 -29
- package/dist/composition/canonical-prefactors.d.ts.map +1 -1
- package/dist/composition/canonical-prefactors.js +15 -202
- package/dist/composition/canonical-prefactors.js.map +1 -1
- package/dist/composition/compose.js +2 -1
- package/dist/composition/compose.js.map +1 -1
- package/dist/composition/discovery.d.ts +50 -0
- package/dist/composition/discovery.d.ts.map +1 -1
- package/dist/composition/discovery.js +2 -2
- package/dist/composition/discovery.js.map +1 -1
- package/dist/composition/edge.d.ts +0 -14
- package/dist/composition/edge.d.ts.map +1 -1
- package/dist/composition/edge.js +1 -17
- package/dist/composition/edge.js.map +1 -1
- package/dist/composition/evaluate-relation.d.ts +29 -5
- package/dist/composition/evaluate-relation.d.ts.map +1 -1
- package/dist/composition/evaluate-relation.js +100 -72
- package/dist/composition/evaluate-relation.js.map +1 -1
- package/dist/composition/explain.d.ts +5 -0
- package/dist/composition/explain.d.ts.map +1 -1
- package/dist/composition/explain.js +9 -8
- package/dist/composition/explain.js.map +1 -1
- package/dist/composition/expr-eval.d.ts.map +1 -1
- package/dist/composition/expr-eval.js +2 -1
- package/dist/composition/expr-eval.js.map +1 -1
- package/dist/composition/index.d.ts +3 -1
- package/dist/composition/index.d.ts.map +1 -1
- package/dist/composition/index.js +3 -1
- package/dist/composition/index.js.map +1 -1
- package/dist/composition/proposed-bridges.d.ts.map +1 -1
- package/dist/composition/proposed-bridges.js +3 -2
- package/dist/composition/proposed-bridges.js.map +1 -1
- package/dist/composition/retrodiction.d.ts +8 -0
- package/dist/composition/retrodiction.d.ts.map +1 -1
- package/dist/composition/retrodiction.js +5 -0
- package/dist/composition/retrodiction.js.map +1 -1
- package/dist/composition/user-equation.d.ts +11 -7
- package/dist/composition/user-equation.d.ts.map +1 -1
- package/dist/composition/user-equation.js +24 -26
- package/dist/composition/user-equation.js.map +1 -1
- package/dist/core/constants.d.ts +27 -4
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +38 -5
- package/dist/core/constants.js.map +1 -1
- package/dist/core/data-file.d.ts +27 -0
- package/dist/core/data-file.d.ts.map +1 -0
- package/dist/core/data-file.js +48 -0
- package/dist/core/data-file.js.map +1 -0
- package/dist/core/json-schema.d.ts +27 -0
- package/dist/core/json-schema.d.ts.map +1 -0
- package/dist/core/json-schema.js +153 -0
- package/dist/core/json-schema.js.map +1 -0
- package/dist/core/types.d.ts +3 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +16 -14
- package/dist/core/types.js.map +1 -1
- package/dist/diff/bridge-ast-gradient.d.ts.map +1 -1
- package/dist/diff/bridge-ast-gradient.js +6 -17
- package/dist/diff/bridge-ast-gradient.js.map +1 -1
- package/dist/diff/bridge-specs.d.ts +2 -1
- package/dist/diff/bridge-specs.d.ts.map +1 -1
- package/dist/diff/bridge-specs.js +1 -1
- package/dist/diff/bridge-specs.js.map +1 -1
- package/dist/dimensional/bridge-check.d.ts.map +1 -1
- package/dist/dimensional/bridge-check.js +3 -5
- package/dist/dimensional/bridge-check.js.map +1 -1
- package/dist/dimensional/constant-rows.d.ts +54 -0
- package/dist/dimensional/constant-rows.d.ts.map +1 -0
- package/dist/dimensional/constant-rows.js +111 -0
- package/dist/dimensional/constant-rows.js.map +1 -0
- package/dist/dimensional/constants.d.ts +4 -13
- package/dist/dimensional/constants.d.ts.map +1 -1
- package/dist/dimensional/constants.js +11 -19
- package/dist/dimensional/constants.js.map +1 -1
- package/dist/dimensional/dimension-spec.d.ts +12 -3
- package/dist/dimensional/dimension-spec.d.ts.map +1 -1
- package/dist/dimensional/dimension-spec.js +114 -150
- package/dist/dimensional/dimension-spec.js.map +1 -1
- package/dist/dimensional/exact-scale.d.ts +79 -0
- package/dist/dimensional/exact-scale.d.ts.map +1 -0
- package/dist/dimensional/exact-scale.js +222 -0
- package/dist/dimensional/exact-scale.js.map +1 -0
- package/dist/dimensional/formula-names.d.ts +13 -12
- package/dist/dimensional/formula-names.d.ts.map +1 -1
- package/dist/dimensional/formula-names.js +28 -51
- package/dist/dimensional/formula-names.js.map +1 -1
- package/dist/dimensional/quantity-registry.d.ts +10 -1
- package/dist/dimensional/quantity-registry.d.ts.map +1 -1
- package/dist/dimensional/quantity-registry.js +45 -16
- package/dist/dimensional/quantity-registry.js.map +1 -1
- package/dist/dimensional/symbolic-constants.d.ts +63 -19
- package/dist/dimensional/symbolic-constants.d.ts.map +1 -1
- package/dist/dimensional/symbolic-constants.js +109 -92
- package/dist/dimensional/symbolic-constants.js.map +1 -1
- package/dist/dimensional/unit-data.d.ts +70 -0
- package/dist/dimensional/unit-data.d.ts.map +1 -0
- package/dist/dimensional/unit-data.js +135 -0
- package/dist/dimensional/unit-data.js.map +1 -0
- package/dist/dimensional/units.d.ts +87 -24
- package/dist/dimensional/units.d.ts.map +1 -1
- package/dist/dimensional/units.js +253 -276
- package/dist/dimensional/units.js.map +1 -1
- package/dist/index.d.ts +15 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/numerical/binding-value.d.ts +21 -1
- package/dist/numerical/binding-value.d.ts.map +1 -1
- package/dist/numerical/binding-value.js +123 -118
- package/dist/numerical/binding-value.js.map +1 -1
- package/dist/numerical/evaluator-uncertainty.d.ts +34 -0
- package/dist/numerical/evaluator-uncertainty.d.ts.map +1 -0
- package/dist/numerical/evaluator-uncertainty.js +117 -0
- package/dist/numerical/evaluator-uncertainty.js.map +1 -0
- package/dist/numerical/formula-contract.d.ts +4 -0
- package/dist/numerical/formula-contract.d.ts.map +1 -1
- package/dist/numerical/formula-contract.js +7 -0
- package/dist/numerical/formula-contract.js.map +1 -1
- package/dist/numerical/formula-dimension.d.ts +9 -0
- package/dist/numerical/formula-dimension.d.ts.map +1 -1
- package/dist/numerical/formula-dimension.js +64 -10
- package/dist/numerical/formula-dimension.js.map +1 -1
- package/dist/numerical/formula-mathts.d.ts.map +1 -1
- package/dist/numerical/formula-mathts.js +6 -2
- package/dist/numerical/formula-mathts.js.map +1 -1
- package/dist/numerical/gl4-integrator.d.ts.map +1 -1
- package/dist/numerical/gl4-integrator.js +3 -3
- package/dist/numerical/gl4-integrator.js.map +1 -1
- package/dist/numerical/spacetime-metrics.d.ts +4 -0
- package/dist/numerical/spacetime-metrics.d.ts.map +1 -1
- package/dist/numerical/spacetime-metrics.js +34 -4
- package/dist/numerical/spacetime-metrics.js.map +1 -1
- package/dist/relations/types.d.ts +8 -1
- package/dist/relations/types.d.ts.map +1 -1
- package/dist/relations/types.js +10 -0
- package/dist/relations/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -18,10 +18,22 @@
|
|
|
18
18
|
* separated by `.`, `*`, or spaces; `^` optional; fractional exponents
|
|
19
19
|
* like `T^1/2` allowed).
|
|
20
20
|
*
|
|
21
|
+
* Forms 3 and 4 are one grammar, the formula grammar MathTS parses
|
|
22
|
+
* ({@link parseFormulaPNode}). The dimension notation differs from a formula
|
|
23
|
+
* only in spelling, and {@link formulaSyntax} rewrites those spellings
|
|
24
|
+
* before the parse: a `.` between factors is `*`, a space between factors is
|
|
25
|
+
* `*`, a glued exponent (`L2`, `T-2`) takes its `^`, a fractional exponent
|
|
26
|
+
* (`T^1/2`) is parenthesized, and a hyphen inside a name (`magnetic-field`)
|
|
27
|
+
* is `_`. There is no subtraction in a dimension, so `-` after a name is
|
|
28
|
+
* always an exponent's sign.
|
|
29
|
+
*
|
|
21
30
|
* @module dimensional/dimension-spec
|
|
22
31
|
*/
|
|
23
32
|
import { DIMENSIONLESS, LENGTH, AREA, TIME, FREQUENCY, MASS, VELOCITY, ACCELERATION, FORCE, ENERGY, POWER, ACTION, TEMPERATURE, ENTROPY, CHARGE, } from './types.js';
|
|
24
33
|
import { divide, multiply, power } from './algebra.js';
|
|
34
|
+
import { dim } from './ast-builders.js';
|
|
35
|
+
import { CONSTANT_REGISTRY } from './symbolic-constants.js';
|
|
36
|
+
import { parseFormulaPNode } from '../numerical/formula-dimension.js';
|
|
25
37
|
/** A bad dimension spec. */
|
|
26
38
|
export class DimensionSpecError extends Error {
|
|
27
39
|
constructor(message) {
|
|
@@ -29,7 +41,8 @@ export class DimensionSpecError extends Error {
|
|
|
29
41
|
this.name = 'DimensionSpecError';
|
|
30
42
|
}
|
|
31
43
|
}
|
|
32
|
-
|
|
44
|
+
/** `dim(L, M, T, I, Θ)`, the one builder, from `ast-builders`. */
|
|
45
|
+
const d = dim;
|
|
33
46
|
/** Named dimensions — matched case-insensitively. */
|
|
34
47
|
const NAMED_DIMS = {
|
|
35
48
|
dimensionless: DIMENSIONLESS,
|
|
@@ -51,26 +64,18 @@ const NAMED_DIMS = {
|
|
|
51
64
|
density: d(-3, 1),
|
|
52
65
|
volume: d(3),
|
|
53
66
|
viscosity: d(-1, 1, -1),
|
|
54
|
-
resistance: d(2, 1, -3,
|
|
55
|
-
magnetic_field: d(0, 1, -2,
|
|
56
|
-
permeability: d(1, 1, -2,
|
|
67
|
+
resistance: d(2, 1, -3, -2, 0),
|
|
68
|
+
magnetic_field: d(0, 1, -2, -1, 0),
|
|
69
|
+
permeability: d(1, 1, -2, -2, 0),
|
|
57
70
|
};
|
|
58
71
|
/**
|
|
59
|
-
* One constant's exact-case spellings
|
|
60
|
-
*
|
|
61
|
-
* names. A dimension term reads this record
|
|
72
|
+
* One constant's exact-case spellings, projected from the constant registry.
|
|
73
|
+
* The first name is the formula name the equation path rewrites the others
|
|
74
|
+
* to. `upt eval` binds the same names. A dimension term reads this record.
|
|
62
75
|
*
|
|
63
76
|
* @internal
|
|
64
77
|
*/
|
|
65
|
-
export const CONSTANT_SPELLINGS = [
|
|
66
|
-
{ names: ['hbar', 'ℏ'], dim: ACTION },
|
|
67
|
-
{ names: ['c'], dim: VELOCITY },
|
|
68
|
-
{ names: ['G'], dim: d(3, -1, -2) },
|
|
69
|
-
{ names: ['k_B', 'kB'], dim: ENTROPY },
|
|
70
|
-
{ names: ['e'], dim: CHARGE },
|
|
71
|
-
{ names: ['mu_0', 'mu0'], dim: d(1, 1, -2, 0, -2) },
|
|
72
|
-
{ names: ['epsilon_0', 'epsilon0', 'eps0'], dim: d(-3, -1, 4, 0, 2) },
|
|
73
|
-
];
|
|
78
|
+
export const CONSTANT_SPELLINGS = CONSTANT_REGISTRY.map((row) => ({ names: [row.name, ...row.spellings], dim: row.dim }));
|
|
74
79
|
/** Fundamental constants by their SI dimension — matched EXACT-case, so
|
|
75
80
|
* `G` (Newton's constant) is never confused with `g` (acceleration). */
|
|
76
81
|
const CONST_DIMS = Object.fromEntries(CONSTANT_SPELLINGS.flatMap(({ names, dim }) => names.map((name) => [name, dim])));
|
|
@@ -84,30 +89,14 @@ const BASES = {
|
|
|
84
89
|
N: 'N',
|
|
85
90
|
J: 'J',
|
|
86
91
|
};
|
|
87
|
-
|
|
88
|
-
if (raw === '')
|
|
89
|
-
return 1;
|
|
90
|
-
if (raw.includes('/')) {
|
|
91
|
-
const [n, den] = raw.split('/');
|
|
92
|
-
const num = Number(n);
|
|
93
|
-
const dd = Number(den);
|
|
94
|
-
if (!Number.isFinite(num) || !Number.isFinite(dd) || dd === 0) {
|
|
95
|
-
throw new DimensionSpecError(`bad exponent '${raw}'`);
|
|
96
|
-
}
|
|
97
|
-
return num / dd;
|
|
98
|
-
}
|
|
99
|
-
const v = Number(raw);
|
|
100
|
-
if (!Number.isFinite(v))
|
|
101
|
-
throw new DimensionSpecError(`bad exponent '${raw}'`);
|
|
102
|
-
return v;
|
|
103
|
-
}
|
|
104
|
-
/** Resolve one atom: constant (exact case) or named dimension (case-insensitive). */
|
|
92
|
+
/** Resolve one atom: constant (exact case, `_` or `-`) or named dimension (case-insensitive). */
|
|
105
93
|
function resolveAtom(raw) {
|
|
106
94
|
const s = raw.trim();
|
|
107
95
|
if (!s)
|
|
108
96
|
return null;
|
|
109
|
-
|
|
110
|
-
|
|
97
|
+
const constant = CONST_DIMS[s] ?? CONST_DIMS[s.replaceAll('_', '-')];
|
|
98
|
+
if (constant)
|
|
99
|
+
return constant;
|
|
111
100
|
const key = s.toLowerCase().replace(/[\s-]+/g, '_');
|
|
112
101
|
return NAMED_DIMS[key] ?? NAMED_DIMS[s.toLowerCase()] ?? null;
|
|
113
102
|
}
|
|
@@ -115,133 +104,108 @@ function baseAtom(id) {
|
|
|
115
104
|
const baseKey = BASES[id.toUpperCase()] ?? BASES[id];
|
|
116
105
|
if (!baseKey)
|
|
117
106
|
return null;
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
return
|
|
107
|
+
const out = d();
|
|
108
|
+
out[baseKey] = 1;
|
|
109
|
+
return out;
|
|
121
110
|
}
|
|
122
111
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* Returns `null` when the string is not this form (so the base-exponent path
|
|
127
|
-
* can try).
|
|
128
|
-
*/
|
|
129
|
-
/**
|
|
130
|
-
* A product/quotient with parentheses and exponents: `power/(area*temperature^4)`,
|
|
131
|
-
* `mass/length^3`, `M/L^3`. A slash followed by a digit is a fractional
|
|
132
|
-
* exponent on the explicit-base path (`T^1/2`), not this one.
|
|
112
|
+
* The dimension notation in formula syntax. Each rewrite is a spelling the
|
|
113
|
+
* notation allows and a formula does not; none adds an operator a reader
|
|
114
|
+
* did not write.
|
|
133
115
|
*/
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
116
|
+
function formulaSyntax(spec) {
|
|
117
|
+
return (spec
|
|
118
|
+
// A hyphen inside a name: `magnetic-field` is `magnetic_field`.
|
|
119
|
+
.replace(/(?<=[A-Za-zΘ])-(?=[A-Za-zΘ])/g, '_')
|
|
120
|
+
// Spaces around an operator carry nothing; between two factors they multiply.
|
|
121
|
+
.replace(/\s*([*/^().])\s*/g, '$1')
|
|
122
|
+
.replace(/\s+/g, '*')
|
|
123
|
+
// A glued exponent: `L2`, `T-2`, `T-2.5` (a name's own digits follow `_`, as in `mu_0`).
|
|
124
|
+
.replace(/(?<=[A-Za-zΘ])([+-]?\d)/g, '^$1')
|
|
125
|
+
// A fractional exponent: `T^1/2` is `T^(1/2)`.
|
|
126
|
+
.replace(/\^([+-]?\d+(?:\.\d+)?)\/(\d+(?:\.\d+)?)/g, '^($1/$2)')
|
|
127
|
+
// A dot between factors is a product; a dot before a digit is a decimal point.
|
|
128
|
+
.replace(/\.(?!\d)/g, '*'));
|
|
129
|
+
}
|
|
130
|
+
/** A numeric exponent: a number, a signed number, or a quotient or product of numbers. */
|
|
131
|
+
function exponentOf(node, spec) {
|
|
132
|
+
switch (node.kind) {
|
|
133
|
+
case 'num':
|
|
134
|
+
return node.value;
|
|
135
|
+
case 'neg':
|
|
136
|
+
return -exponentOf(node.arg, spec);
|
|
137
|
+
case 'op': {
|
|
138
|
+
const values = node.args.map((arg) => exponentOf(arg, spec));
|
|
139
|
+
if (node.op === '/')
|
|
140
|
+
return values.reduce((a, b) => a / b);
|
|
141
|
+
if (node.op === '*')
|
|
142
|
+
return values.reduce((a, b) => a * b, 1);
|
|
143
|
+
if (node.op === '+')
|
|
144
|
+
return values.reduce((a, b) => a + b, 0);
|
|
145
|
+
return values.length === 1 ? -values[0] : values.reduce((a, b) => a - b);
|
|
153
146
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
147
|
+
default:
|
|
148
|
+
throw new DimensionSpecError(`bad exponent in '${spec}'`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function unknownTerm(id) {
|
|
152
|
+
return new DimensionSpecError(`unknown base dimension '${id}' (use L M T I Theta N J, a named dimension, a constant name, ` +
|
|
153
|
+
'or a named product/quotient like power/area)');
|
|
154
|
+
}
|
|
155
|
+
/** The dimension a parsed spec states. */
|
|
156
|
+
function dimensionOf(node, spec) {
|
|
157
|
+
switch (node.kind) {
|
|
158
|
+
case 'sym': {
|
|
159
|
+
const found = resolveAtom(node.name) ?? baseAtom(node.name);
|
|
160
|
+
if (found === null)
|
|
161
|
+
throw unknownTerm(node.name);
|
|
162
|
+
return { ...found };
|
|
166
163
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (base)
|
|
178
|
-
return base;
|
|
179
|
-
throw new DimensionSpecError(`unrecognized dimension term '${id}' (use a named dimension, a constant, ` +
|
|
180
|
-
`or bases L M T I Theta N J)`);
|
|
181
|
-
};
|
|
182
|
-
const parsePower = () => {
|
|
183
|
-
const base = parseAtom();
|
|
184
|
-
skip();
|
|
185
|
-
if (s[i] !== '^')
|
|
186
|
-
return base;
|
|
187
|
-
i++;
|
|
188
|
-
return power(base, parseExponentToken());
|
|
189
|
-
};
|
|
190
|
-
const parseProduct = () => {
|
|
191
|
-
let acc = parsePower();
|
|
192
|
-
while (true) {
|
|
193
|
-
skip();
|
|
194
|
-
const op = s[i];
|
|
195
|
-
if (op !== '*' && op !== '/')
|
|
196
|
-
break;
|
|
197
|
-
i++;
|
|
198
|
-
const rhs = parsePower();
|
|
199
|
-
acc = op === '*' ? multiply(acc, rhs) : divide(acc, rhs);
|
|
164
|
+
case 'num':
|
|
165
|
+
// A literal 1 is the dimensionless numerator: `1/time`.
|
|
166
|
+
if (node.value === 1)
|
|
167
|
+
return d();
|
|
168
|
+
throw new DimensionSpecError(`a number is not a dimension term ('${node.value}' in '${spec}')`);
|
|
169
|
+
case 'pow': {
|
|
170
|
+
const exponent = exponentOf(node.exp, spec);
|
|
171
|
+
if (!Number.isFinite(exponent))
|
|
172
|
+
throw new DimensionSpecError(`bad exponent in '${spec}'`);
|
|
173
|
+
return { ...power(dimensionOf(node.base, spec), exponent) };
|
|
200
174
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return true;
|
|
214
|
-
return /\*/.test(s) && /[A-Za-z]{2,}/.test(s);
|
|
175
|
+
case 'op': {
|
|
176
|
+
if (node.op !== '*' && node.op !== '/') {
|
|
177
|
+
throw new DimensionSpecError(`unrecognized dimension term '${spec}' (a dimension has no '${node.op}')`);
|
|
178
|
+
}
|
|
179
|
+
const [first, ...rest] = node.args.map((arg) => dimensionOf(arg, spec));
|
|
180
|
+
return { ...rest.reduce((acc, next) => (node.op === '*' ? multiply(acc, next) : divide(acc, next)), first) };
|
|
181
|
+
}
|
|
182
|
+
case 'neg':
|
|
183
|
+
throw new DimensionSpecError(`unrecognized dimension term '${spec}' (a dimension has no sign)`);
|
|
184
|
+
case 'call':
|
|
185
|
+
throw new DimensionSpecError(`unrecognized dimension term '${node.fn}' in '${spec}'`);
|
|
186
|
+
}
|
|
215
187
|
}
|
|
216
188
|
/** Parse a dimension spec string into a {@link Dimension}. @internal */
|
|
217
189
|
export function parseDimensionSpec(spec) {
|
|
218
190
|
const s = spec.trim();
|
|
219
191
|
if (!s)
|
|
220
192
|
throw new DimensionSpecError('empty dimension spec');
|
|
221
|
-
//
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// (4) explicit base exponents.
|
|
232
|
-
const out = d();
|
|
233
|
-
const parts = s.split(/[.*\s]+/).filter(Boolean);
|
|
234
|
-
for (const part of parts) {
|
|
235
|
-
const m = /^([A-Za-zΘ]+)\^?(-?\d+(?:\/\d+)?)?$/.exec(part);
|
|
236
|
-
if (!m)
|
|
237
|
-
throw new DimensionSpecError(`unrecognized dimension term '${part}'`);
|
|
238
|
-
const baseKey = BASES[m[1].toUpperCase()] ?? BASES[m[1]];
|
|
239
|
-
if (!baseKey) {
|
|
240
|
-
throw new DimensionSpecError(`unknown base dimension '${m[1]}' (use L M T I Theta N J, a named ` +
|
|
241
|
-
`dimension, a constant name, or a named product/quotient like power/area)`);
|
|
242
|
-
}
|
|
243
|
-
out[baseKey] += parseExponent(m[2] ?? '');
|
|
193
|
+
// A whole name: a constant (exact case, so G is not g) or a named dimension.
|
|
194
|
+
const whole = resolveAtom(s);
|
|
195
|
+
if (whole)
|
|
196
|
+
return whole;
|
|
197
|
+
let node;
|
|
198
|
+
try {
|
|
199
|
+
node = parseFormulaPNode(formulaSyntax(s));
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
throw new DimensionSpecError(`unrecognized dimension spec '${s}' (${error instanceof Error ? error.message : String(error)})`);
|
|
244
203
|
}
|
|
204
|
+
const out = dimensionOf(node, s);
|
|
205
|
+
// A zero exponent raised to a negative power is -0; a dimension has no signed zero.
|
|
206
|
+
for (const key of Object.keys(out))
|
|
207
|
+
if (out[key] === 0)
|
|
208
|
+
out[key] = 0;
|
|
245
209
|
return out;
|
|
246
210
|
}
|
|
247
211
|
//# sourceMappingURL=dimension-spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dimension-spec.js","sourceRoot":"","sources":["../../src/dimensional/dimension-spec.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dimension-spec.js","sourceRoot":"","sources":["../../src/dimensional/dimension-spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,EACL,aAAa,EACb,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,GACP,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAqB,MAAM,mCAAmC,CAAC;AAEzF,4BAA4B;AAC5B,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,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AAC,CAAC;IAC1F,CAAC;AACH,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACtB,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;IAC7D,6EAA6E;IAC7E,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IACxB,IAAI,IAAkB,CAAC;IACvB,IAAI,CAAC;QACH,IAAI,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,kBAAkB,CAC1B,gCAAgC,CAAC,MAAM,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CACjG,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACjC,oFAAoF;IACpF,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAwB;QAAE,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5F,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exact unit scales.
|
|
3
|
+
*
|
|
4
|
+
* A unit's scale to SI is a rational number times one floating factor that
|
|
5
|
+
* holds its irrational part (π for an angle, ln 2 for a bit). Prefixes,
|
|
6
|
+
* products, quotients and integer powers multiply the rationals exactly, so
|
|
7
|
+
* `g/cm^3` is 1000 and `72 mN/m` is 0.072 with no float noise to round away.
|
|
8
|
+
* The one rounding is {@link scaleToNumber}, which rounds the rational
|
|
9
|
+
* correctly and then multiplies by the irrational factor once.
|
|
10
|
+
*
|
|
11
|
+
* A decimal literal is read digit for digit. A JavaScript number is read
|
|
12
|
+
* through its shortest round-trip decimal (`String(x)`), which is the
|
|
13
|
+
* literal a constant was written with.
|
|
14
|
+
*
|
|
15
|
+
* @module dimensional/exact-scale
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
/** `num / den × irrational`, with `den > 0` and the fraction in lowest terms. @internal */
|
|
19
|
+
export interface ExactScale {
|
|
20
|
+
readonly num: bigint;
|
|
21
|
+
readonly den: bigint;
|
|
22
|
+
/** The factor no rational states (π, ln 2). 1 for a rational scale. */
|
|
23
|
+
readonly irrational: number;
|
|
24
|
+
}
|
|
25
|
+
/** The scale 1. @internal */
|
|
26
|
+
export declare const UNIT_SCALE: ExactScale;
|
|
27
|
+
/**
|
|
28
|
+
* The exact value of a decimal literal (`72`, `0.45359237`, `1.602176634e-19`),
|
|
29
|
+
* or null when `text` is not one.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare function decimalScale(text: string): ExactScale | null;
|
|
33
|
+
/** The exact scale a finite JavaScript number was written as. @internal */
|
|
34
|
+
export declare function scaleOf(x: number): ExactScale;
|
|
35
|
+
/** `num / den`, exactly. @internal */
|
|
36
|
+
export declare function ratioScale(num: number | bigint, den: number | bigint): ExactScale;
|
|
37
|
+
/** A factor no rational states, such as π or ln 2. @internal */
|
|
38
|
+
export declare function irrationalScale(x: number): ExactScale;
|
|
39
|
+
/** `a × b × …`. @internal */
|
|
40
|
+
export declare function multiplyScales(...factors: readonly ExactScale[]): ExactScale;
|
|
41
|
+
/** `a / b`. @internal */
|
|
42
|
+
export declare function divideScales(a: ExactScale, b: ExactScale): ExactScale;
|
|
43
|
+
/**
|
|
44
|
+
* `a ^ n`. An integer power stays exact. A fractional power has no exact
|
|
45
|
+
* rational in general, so it becomes one floating factor.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare function powerScale(a: ExactScale, n: number): ExactScale;
|
|
49
|
+
/** `a + b`: exact when both are rational multiples of the same irrational factor. @internal */
|
|
50
|
+
export declare function addScales(a: ExactScale, b: ExactScale): ExactScale;
|
|
51
|
+
/** The scale as a double: the rational rounded once, times the irrational factor. @internal */
|
|
52
|
+
export declare function scaleToNumber(s: ExactScale): number;
|
|
53
|
+
/**
|
|
54
|
+
* The two sides of a unit text or a scale expression under the single-solidus
|
|
55
|
+
* convention of ISO 80000-1: everything after the first `/` is the
|
|
56
|
+
* denominator, so a chain is one denominator (`km/s/Mpc` is km/(s·Mpc), and
|
|
57
|
+
* `W/m*K` is W/(m·K), not (W/m)·K). The denominator comes back as one
|
|
58
|
+
* `*`-joined product, each `/`-part's outer parentheses dropped. `units.ts`
|
|
59
|
+
* and {@link readScaleExpression} both split here, so a unit text and a scale
|
|
60
|
+
* expression in `data/units.json` read a `/` the same way.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export declare function solidusSides(text: string): {
|
|
64
|
+
readonly numerator: string;
|
|
65
|
+
readonly denominator: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The exact value of a scale expression, the form `data/units.json` stores:
|
|
69
|
+
* factors joined by `*`, then optionally `/` and the denominator's factors,
|
|
70
|
+
* each a decimal literal or a name with an optional integer power
|
|
71
|
+
* (`4.1868*453.59237/1.8`, `pi/180`, `lbf/inch^2`). A `/` follows the unit
|
|
72
|
+
* grammar ({@link solidusSides}): `a/b*c` is a/(b·c). `resolve` gives a name
|
|
73
|
+
* its scale and returns undefined for a name it does not know, which throws
|
|
74
|
+
* here. A decimal literal is read digit for digit, so the result is the
|
|
75
|
+
* rational the text states.
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
export declare function readScaleExpression(text: string, resolve: (name: string) => ExactScale | undefined): ExactScale;
|
|
79
|
+
//# sourceMappingURL=exact-scale.d.ts.map
|
|
@@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