universal-physics-tensor 10.0.0 → 12.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 +39 -36
- package/bin/upt.mjs +13 -1
- package/data/applied-cases.json +1892 -0
- package/data/applied-cases.schema.json +194 -0
- package/data/atlas/atlas.json +25 -25
- package/data/atlas/atlas.jsonld +1 -1
- package/data/atlas/diffusion.json +6 -6
- package/data/atlas/oscillators.json +7 -7
- package/data/atlas/waves.json +14 -14
- package/data/atlas/witness-results.json +11 -11
- package/data/bridge-catalog.json +389 -230
- package/data/bridge-catalog.schema.json +45 -7
- package/data/units.json +6 -25
- package/dist/atlas/applicability.d.ts.map +1 -1
- package/dist/atlas/applicability.js +21 -15
- package/dist/atlas/applicability.js.map +1 -1
- package/dist/atlas/benchmark/hybrid-retrieval.d.ts +9 -1
- package/dist/atlas/benchmark/hybrid-retrieval.d.ts.map +1 -1
- package/dist/atlas/benchmark/hybrid-retrieval.js +15 -13
- package/dist/atlas/benchmark/hybrid-retrieval.js.map +1 -1
- package/dist/atlas/benchmark/loader.js +2 -2
- package/dist/atlas/benchmark/loader.js.map +1 -1
- package/dist/atlas/benchmark/stats.d.ts +2 -2
- package/dist/atlas/benchmark/stats.d.ts.map +1 -1
- package/dist/atlas/benchmark/stats.js +9 -15
- package/dist/atlas/benchmark/stats.js.map +1 -1
- package/dist/atlas/catalog-formal-ref.d.ts +26 -3
- package/dist/atlas/catalog-formal-ref.d.ts.map +1 -1
- package/dist/atlas/catalog-formal-ref.js +52 -5
- package/dist/atlas/catalog-formal-ref.js.map +1 -1
- package/dist/atlas/chain-pipeline.d.ts.map +1 -1
- package/dist/atlas/chain-pipeline.js +7 -8
- package/dist/atlas/chain-pipeline.js.map +1 -1
- package/dist/atlas/diffusion/bridges-closure.d.ts +0 -4
- package/dist/atlas/diffusion/bridges-closure.d.ts.map +1 -1
- package/dist/atlas/diffusion/bridges-closure.js +8 -12
- package/dist/atlas/diffusion/bridges-closure.js.map +1 -1
- package/dist/atlas/diffusion/bridges.d.ts.map +1 -1
- package/dist/atlas/diffusion/bridges.js +27 -39
- package/dist/atlas/diffusion/bridges.js.map +1 -1
- package/dist/atlas/diffusion/dimensions.d.ts +6 -14
- package/dist/atlas/diffusion/dimensions.d.ts.map +1 -1
- package/dist/atlas/diffusion/dimensions.js +8 -16
- package/dist/atlas/diffusion/dimensions.js.map +1 -1
- package/dist/atlas/diffusion/models.d.ts +3 -3
- package/dist/atlas/diffusion/models.d.ts.map +1 -1
- package/dist/atlas/diffusion/models.js +5 -10
- package/dist/atlas/diffusion/models.js.map +1 -1
- package/dist/atlas/diffusion/numerics.d.ts +16 -4
- package/dist/atlas/diffusion/numerics.d.ts.map +1 -1
- package/dist/atlas/diffusion/numerics.js +38 -24
- package/dist/atlas/diffusion/numerics.js.map +1 -1
- package/dist/atlas/link-prediction.d.ts +106 -3
- package/dist/atlas/link-prediction.d.ts.map +1 -1
- package/dist/atlas/link-prediction.js +212 -66
- package/dist/atlas/link-prediction.js.map +1 -1
- package/dist/atlas/oscillators/bridges-coarse.d.ts.map +1 -1
- package/dist/atlas/oscillators/bridges-coarse.js +7 -11
- package/dist/atlas/oscillators/bridges-coarse.js.map +1 -1
- package/dist/atlas/oscillators/bridges-exact.d.ts.map +1 -1
- package/dist/atlas/oscillators/bridges-exact.js +6 -7
- package/dist/atlas/oscillators/bridges-exact.js.map +1 -1
- package/dist/atlas/oscillators/bridges-limits.d.ts +3 -16
- package/dist/atlas/oscillators/bridges-limits.d.ts.map +1 -1
- package/dist/atlas/oscillators/bridges-limits.js +23 -34
- package/dist/atlas/oscillators/bridges-limits.js.map +1 -1
- package/dist/atlas/oscillators/dimensions.d.ts +9 -21
- package/dist/atlas/oscillators/dimensions.d.ts.map +1 -1
- package/dist/atlas/oscillators/dimensions.js +9 -21
- package/dist/atlas/oscillators/dimensions.js.map +1 -1
- package/dist/atlas/oscillators/limit-witnesses.d.ts +2 -2
- package/dist/atlas/oscillators/limit-witnesses.d.ts.map +1 -1
- package/dist/atlas/oscillators/limit-witnesses.js +17 -15
- package/dist/atlas/oscillators/limit-witnesses.js.map +1 -1
- package/dist/atlas/oscillators/models.d.ts.map +1 -1
- package/dist/atlas/oscillators/models.js +2 -6
- package/dist/atlas/oscillators/models.js.map +1 -1
- package/dist/atlas/oscillators/pendulum-motion.d.ts +29 -6
- package/dist/atlas/oscillators/pendulum-motion.d.ts.map +1 -1
- package/dist/atlas/oscillators/pendulum-motion.js +60 -40
- package/dist/atlas/oscillators/pendulum-motion.js.map +1 -1
- package/dist/atlas/oscillators/phase-translation.d.ts +0 -11
- package/dist/atlas/oscillators/phase-translation.d.ts.map +1 -1
- package/dist/atlas/oscillators/phase-translation.js +3 -4
- package/dist/atlas/oscillators/phase-translation.js.map +1 -1
- package/dist/atlas/oscillators/position-translation.d.ts +68 -7
- package/dist/atlas/oscillators/position-translation.d.ts.map +1 -1
- package/dist/atlas/oscillators/position-translation.js +123 -12
- package/dist/atlas/oscillators/position-translation.js.map +1 -1
- package/dist/atlas/oscillators/rejections.d.ts +0 -2
- package/dist/atlas/oscillators/rejections.d.ts.map +1 -1
- package/dist/atlas/oscillators/rejections.js +0 -7
- package/dist/atlas/oscillators/rejections.js.map +1 -1
- package/dist/atlas/physjs-entries.generated.d.ts +35 -25
- package/dist/atlas/physjs-entries.generated.d.ts.map +1 -1
- package/dist/atlas/physjs-entries.generated.js +37 -25
- package/dist/atlas/physjs-entries.generated.js.map +1 -1
- package/dist/atlas/physjs-ref.d.ts +34 -31
- package/dist/atlas/physjs-ref.d.ts.map +1 -1
- package/dist/atlas/physjs-ref.js +55 -53
- package/dist/atlas/physjs-ref.js.map +1 -1
- package/dist/atlas/physjs-reviewed.d.ts +1 -1
- package/dist/atlas/physjs-reviewed.js +15 -15
- package/dist/atlas/physjs-reviewed.js.map +1 -1
- package/dist/atlas/poster/statements.d.ts +0 -19
- package/dist/atlas/poster/statements.d.ts.map +1 -1
- package/dist/atlas/poster/statements.js +1 -1
- package/dist/atlas/poster/statements.js.map +1 -1
- package/dist/atlas/proof-target.d.ts +1 -1
- package/dist/atlas/proof-target.js +1 -1
- package/dist/atlas/proof-target.js.map +1 -1
- package/dist/atlas/regime.d.ts +1 -1
- package/dist/atlas/regime.d.ts.map +1 -1
- package/dist/atlas/regime.js +1 -1
- package/dist/atlas/regime.js.map +1 -1
- package/dist/atlas/text-overlap.d.ts +23 -0
- package/dist/atlas/text-overlap.d.ts.map +1 -0
- package/dist/atlas/text-overlap.js +41 -0
- package/dist/atlas/text-overlap.js.map +1 -0
- package/dist/atlas/waves/bridges-closure.d.ts.map +1 -1
- package/dist/atlas/waves/bridges-closure.js +2 -6
- package/dist/atlas/waves/bridges-closure.js.map +1 -1
- package/dist/atlas/waves/bridges.d.ts.map +1 -1
- package/dist/atlas/waves/bridges.js +32 -48
- package/dist/atlas/waves/bridges.js.map +1 -1
- package/dist/atlas/waves/models.d.ts +5 -6
- package/dist/atlas/waves/models.d.ts.map +1 -1
- package/dist/atlas/waves/models.js +7 -13
- package/dist/atlas/waves/models.js.map +1 -1
- package/dist/atlas/waves/numerics.d.ts.map +1 -1
- package/dist/atlas/waves/numerics.js +10 -3
- package/dist/atlas/waves/numerics.js.map +1 -1
- package/dist/atlas/witness-numeric.d.ts +30 -0
- package/dist/atlas/witness-numeric.d.ts.map +1 -1
- package/dist/atlas/witness-numeric.js +53 -0
- package/dist/atlas/witness-numeric.js.map +1 -1
- package/dist/atlas/witness-specs.d.ts.map +1 -1
- package/dist/atlas/witness-specs.js +19 -0
- package/dist/atlas/witness-specs.js.map +1 -1
- package/dist/atlas/witness-symbolic.d.ts +75 -3
- package/dist/atlas/witness-symbolic.d.ts.map +1 -1
- package/dist/atlas/witness-symbolic.js +116 -10
- package/dist/atlas/witness-symbolic.js.map +1 -1
- package/dist/bridges/catalog-load.d.ts.map +1 -1
- package/dist/bridges/catalog-load.js +13 -8
- package/dist/bridges/catalog-load.js.map +1 -1
- package/dist/bridges/catalog-types.d.ts +26 -2
- package/dist/bridges/catalog-types.d.ts.map +1 -1
- package/dist/bridges/catalog-types.js +11 -1
- package/dist/bridges/catalog-types.js.map +1 -1
- package/dist/bridges/evaluation-errors.d.ts +31 -1
- package/dist/bridges/evaluation-errors.d.ts.map +1 -1
- package/dist/bridges/evaluation-errors.js +20 -2
- package/dist/bridges/evaluation-errors.js.map +1 -1
- package/dist/bridges/evaluator-inputs.d.ts.map +1 -1
- package/dist/bridges/evaluator-inputs.js +7 -5
- package/dist/bridges/evaluator-inputs.js.map +1 -1
- package/dist/bridges/evaluators.d.ts.map +1 -1
- package/dist/bridges/evaluators.js +27 -12
- package/dist/bridges/evaluators.js.map +1 -1
- package/dist/bridges/expr-parse.d.ts +11 -0
- package/dist/bridges/expr-parse.d.ts.map +1 -1
- package/dist/bridges/expr-parse.js +14 -5
- package/dist/bridges/expr-parse.js.map +1 -1
- package/dist/bridges/holds.d.ts +35 -3
- package/dist/bridges/holds.d.ts.map +1 -1
- package/dist/bridges/holds.js +117 -23
- package/dist/bridges/holds.js.map +1 -1
- package/dist/bridges/notices.d.ts.map +1 -1
- package/dist/bridges/notices.js +5 -5
- package/dist/bridges/notices.js.map +1 -1
- package/dist/bridges/relation-eval.d.ts +4 -4
- package/dist/bridges/relation-eval.d.ts.map +1 -1
- package/dist/bridges/relation-eval.js +15 -16
- package/dist/bridges/relation-eval.js.map +1 -1
- package/dist/bridges/sensitivity.d.ts.map +1 -1
- package/dist/bridges/sensitivity.js +3 -3
- package/dist/bridges/sensitivity.js.map +1 -1
- package/dist/bridges/validity.d.ts +33 -0
- package/dist/bridges/validity.d.ts.map +1 -0
- package/dist/bridges/validity.js +67 -0
- package/dist/bridges/validity.js.map +1 -0
- package/dist/canonical/entries/atomic.js +1 -3
- 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 +4 -5
- 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 +3 -4
- 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 +4 -10
- 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 +3 -7
- 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 +4 -6
- 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 +9 -17
- 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 -6
- package/dist/canonical/entries/relativity.js.map +1 -1
- package/dist/canonical/entries/thermo-nuclear-cosmo.d.ts.map +1 -1
- package/dist/canonical/entries/thermo-nuclear-cosmo.js +6 -10
- package/dist/canonical/entries/thermo-nuclear-cosmo.js.map +1 -1
- package/dist/canonical/fixed-points.d.ts +94 -0
- package/dist/canonical/fixed-points.d.ts.map +1 -0
- package/dist/canonical/fixed-points.js +81 -0
- package/dist/canonical/fixed-points.js.map +1 -0
- package/dist/canonical/linkage.d.ts.map +1 -1
- package/dist/canonical/linkage.js +25 -44
- package/dist/canonical/linkage.js.map +1 -1
- package/dist/canonical/normal-form.d.ts.map +1 -1
- package/dist/canonical/normal-form.js +5 -11
- package/dist/canonical/normal-form.js.map +1 -1
- package/dist/canonical/structural.d.ts +21 -21
- package/dist/canonical/structural.d.ts.map +1 -1
- package/dist/canonical/structural.js +40 -19
- package/dist/canonical/structural.js.map +1 -1
- package/dist/cases/catalog-checks.d.ts +10 -0
- package/dist/cases/catalog-checks.d.ts.map +1 -0
- package/dist/cases/catalog-checks.js +241 -0
- package/dist/cases/catalog-checks.js.map +1 -0
- package/dist/cases/catalog.d.ts +83 -0
- package/dist/cases/catalog.d.ts.map +1 -0
- package/dist/cases/catalog.js +118 -0
- package/dist/cases/catalog.js.map +1 -0
- package/dist/cases/engine.d.ts +13 -0
- package/dist/cases/engine.d.ts.map +1 -0
- package/dist/cases/engine.js +179 -0
- package/dist/cases/engine.js.map +1 -0
- package/dist/cases/index.d.ts.map +1 -1
- package/dist/cases/index.js +5 -7
- package/dist/cases/index.js.map +1 -1
- package/dist/cases/methods.d.ts +215 -0
- package/dist/cases/methods.d.ts.map +1 -0
- package/dist/cases/methods.js +743 -0
- package/dist/cases/methods.js.map +1 -0
- package/dist/cases/quadrature.d.ts +7 -9
- package/dist/cases/quadrature.d.ts.map +1 -1
- package/dist/cases/quadrature.js +28 -32
- package/dist/cases/quadrature.js.map +1 -1
- package/dist/cases/types.d.ts +12 -0
- package/dist/cases/types.d.ts.map +1 -1
- package/dist/cases/types.js.map +1 -1
- package/dist/cli/args.d.ts +25 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +30 -8
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/bindings.d.ts.map +1 -1
- package/dist/cli/bindings.js +5 -4
- package/dist/cli/bindings.js.map +1 -1
- package/dist/cli/command.d.ts +11 -1
- package/dist/cli/command.d.ts.map +1 -1
- package/dist/cli/command.js.map +1 -1
- package/dist/cli/commands/_atlas-map.d.ts +0 -9
- package/dist/cli/commands/_atlas-map.d.ts.map +1 -1
- package/dist/cli/commands/_atlas-map.js +8 -18
- package/dist/cli/commands/_atlas-map.js.map +1 -1
- package/dist/cli/commands/_atlas-route.d.ts.map +1 -1
- package/dist/cli/commands/_atlas-route.js +6 -2
- package/dist/cli/commands/_atlas-route.js.map +1 -1
- package/dist/cli/commands/_discovery-opts.d.ts +1 -0
- package/dist/cli/commands/_discovery-opts.d.ts.map +1 -1
- package/dist/cli/commands/_discovery-opts.js +9 -9
- 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 +8 -5
- 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 +8 -1
- package/dist/cli/commands/audit.js.map +1 -1
- package/dist/cli/commands/axes.d.ts.map +1 -1
- package/dist/cli/commands/axes.js +20 -1
- package/dist/cli/commands/axes.js.map +1 -1
- package/dist/cli/commands/confront.d.ts.map +1 -1
- package/dist/cli/commands/confront.js +8 -14
- package/dist/cli/commands/confront.js.map +1 -1
- package/dist/cli/commands/derive.d.ts.map +1 -1
- package/dist/cli/commands/derive.js +22 -22
- 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 +122 -73
- 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 +1 -0
- package/dist/cli/commands/eval.js.map +1 -1
- package/dist/cli/commands/evaluate.d.ts.map +1 -1
- package/dist/cli/commands/evaluate.js +67 -39
- 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 +24 -3
- package/dist/cli/commands/explain.js.map +1 -1
- package/dist/cli/commands/ground.d.ts.map +1 -1
- package/dist/cli/commands/ground.js +7 -1
- package/dist/cli/commands/ground.js.map +1 -1
- package/dist/cli/commands/map.d.ts.map +1 -1
- package/dist/cli/commands/map.js +84 -11
- 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 +12 -9
- package/dist/cli/commands/metric.js.map +1 -1
- package/dist/cli/commands/path.d.ts +10 -0
- package/dist/cli/commands/path.d.ts.map +1 -1
- package/dist/cli/commands/path.js +25 -3
- package/dist/cli/commands/path.js.map +1 -1
- package/dist/cli/commands/probe.d.ts.map +1 -1
- package/dist/cli/commands/probe.js +59 -16
- package/dist/cli/commands/probe.js.map +1 -1
- package/dist/cli/commands/regime.d.ts.map +1 -1
- package/dist/cli/commands/regime.js +1 -0
- package/dist/cli/commands/regime.js.map +1 -1
- package/dist/cli/commands/retrieve.d.ts.map +1 -1
- package/dist/cli/commands/retrieve.js +1 -0
- package/dist/cli/commands/retrieve.js.map +1 -1
- package/dist/cli/commands/search.d.ts.map +1 -1
- package/dist/cli/commands/search.js +1 -0
- package/dist/cli/commands/search.js.map +1 -1
- package/dist/cli/commands/symbolic.d.ts.map +1 -1
- package/dist/cli/commands/symbolic.js +19 -28
- package/dist/cli/commands/symbolic.js.map +1 -1
- package/dist/cli/commands/testplan.d.ts.map +1 -1
- package/dist/cli/commands/testplan.js +4 -2
- package/dist/cli/commands/testplan.js.map +1 -1
- package/dist/cli/determination.d.ts +1 -0
- package/dist/cli/determination.d.ts.map +1 -1
- package/dist/cli/determination.js.map +1 -1
- package/dist/cli/expr-print.d.ts +0 -2
- package/dist/cli/expr-print.d.ts.map +1 -1
- package/dist/cli/expr-print.js +7 -31
- package/dist/cli/expr-print.js.map +1 -1
- package/dist/cli/flag-help.d.ts +1 -0
- package/dist/cli/flag-help.d.ts.map +1 -1
- package/dist/cli/flag-help.js +1 -0
- package/dist/cli/flag-help.js.map +1 -1
- package/dist/cli/graphs.d.ts +2 -0
- package/dist/cli/graphs.d.ts.map +1 -1
- package/dist/cli/graphs.js +1 -0
- package/dist/cli/graphs.js.map +1 -1
- package/dist/cli/main.d.ts +8 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +19 -3
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/numeric-flag.d.ts +12 -0
- package/dist/cli/numeric-flag.d.ts.map +1 -0
- package/dist/cli/numeric-flag.js +44 -0
- package/dist/cli/numeric-flag.js.map +1 -0
- package/dist/cli/output.d.ts +28 -0
- package/dist/cli/output.d.ts.map +1 -1
- package/dist/cli/output.js +23 -0
- package/dist/cli/output.js.map +1 -1
- package/dist/cli/record-reach.js +2 -2
- package/dist/cli/record-reach.js.map +1 -1
- package/dist/cli/record-tables.d.ts.map +1 -1
- package/dist/cli/record-tables.js +6 -5
- package/dist/cli/record-tables.js.map +1 -1
- package/dist/cli/record.d.ts +1 -5
- package/dist/cli/record.d.ts.map +1 -1
- package/dist/cli/record.js +9 -8
- package/dist/cli/record.js.map +1 -1
- package/dist/cli/search-index.d.ts.map +1 -1
- package/dist/cli/search-index.js +7 -6
- package/dist/cli/search-index.js.map +1 -1
- package/dist/cli/statuses.d.ts +0 -2
- package/dist/cli/statuses.d.ts.map +1 -1
- package/dist/cli/statuses.js +12 -9
- package/dist/cli/statuses.js.map +1 -1
- package/dist/cli/stored-results.d.ts +7 -0
- package/dist/cli/stored-results.d.ts.map +1 -0
- package/dist/cli/stored-results.js +23 -0
- package/dist/cli/stored-results.js.map +1 -0
- package/dist/cli/version.d.ts +1 -0
- package/dist/cli/version.d.ts.map +1 -1
- package/dist/cli/version.js +8 -5
- package/dist/cli/version.js.map +1 -1
- package/dist/cli-api.d.ts +36 -5
- package/dist/cli-api.d.ts.map +1 -1
- package/dist/cli-api.js +30 -4
- package/dist/cli-api.js.map +1 -1
- package/dist/composition/algebraic-equivalence.d.ts +43 -0
- package/dist/composition/algebraic-equivalence.d.ts.map +1 -0
- package/dist/composition/algebraic-equivalence.js +115 -0
- package/dist/composition/algebraic-equivalence.js.map +1 -0
- package/dist/composition/axes.d.ts +0 -6
- package/dist/composition/axes.d.ts.map +1 -1
- package/dist/composition/axes.js +6 -6
- package/dist/composition/axes.js.map +1 -1
- package/dist/composition/axis-audit.d.ts +47 -20
- package/dist/composition/axis-audit.d.ts.map +1 -1
- package/dist/composition/axis-audit.js +82 -9
- package/dist/composition/axis-audit.js.map +1 -1
- package/dist/composition/bridge-analysis.d.ts +17 -0
- package/dist/composition/bridge-analysis.d.ts.map +1 -1
- package/dist/composition/bridge-analysis.js +102 -55
- package/dist/composition/bridge-analysis.js.map +1 -1
- package/dist/composition/canonical-compare.d.ts +40 -0
- package/dist/composition/canonical-compare.d.ts.map +1 -1
- package/dist/composition/canonical-compare.js +122 -24
- package/dist/composition/canonical-compare.js.map +1 -1
- package/dist/composition/canonical-graph.d.ts +3 -3
- package/dist/composition/canonical-graph.d.ts.map +1 -1
- package/dist/composition/canonical-graph.js +11 -38
- package/dist/composition/canonical-graph.js.map +1 -1
- package/dist/composition/canonical-json.js +2 -2
- package/dist/composition/canonical-json.js.map +1 -1
- package/dist/composition/catalog-graph.d.ts.map +1 -1
- package/dist/composition/catalog-graph.js +2 -5
- package/dist/composition/catalog-graph.js.map +1 -1
- package/dist/composition/chain-candidate.d.ts +8 -0
- package/dist/composition/chain-candidate.d.ts.map +1 -1
- package/dist/composition/chain-candidate.js +9 -2
- package/dist/composition/chain-candidate.js.map +1 -1
- package/dist/composition/chain-match.d.ts +6 -3
- package/dist/composition/chain-match.d.ts.map +1 -1
- package/dist/composition/chain-match.js +4 -1
- package/dist/composition/chain-match.js.map +1 -1
- package/dist/composition/chain-result.d.ts.map +1 -1
- package/dist/composition/chain-result.js +2 -14
- package/dist/composition/chain-result.js.map +1 -1
- package/dist/composition/compose-symbolic.d.ts.map +1 -1
- package/dist/composition/compose-symbolic.js +3 -2
- package/dist/composition/compose-symbolic.js.map +1 -1
- package/dist/composition/compose.d.ts.map +1 -1
- package/dist/composition/compose.js +13 -5
- package/dist/composition/compose.js.map +1 -1
- package/dist/composition/composition-recovery.d.ts.map +1 -1
- package/dist/composition/composition-recovery.js +4 -7
- package/dist/composition/composition-recovery.js.map +1 -1
- package/dist/composition/consequence.d.ts +15 -5
- package/dist/composition/consequence.d.ts.map +1 -1
- package/dist/composition/consequence.js +6 -4
- package/dist/composition/consequence.js.map +1 -1
- package/dist/composition/discovery.d.ts +129 -9
- package/dist/composition/discovery.d.ts.map +1 -1
- package/dist/composition/discovery.js +171 -67
- package/dist/composition/discovery.js.map +1 -1
- package/dist/composition/edge.d.ts +21 -2
- package/dist/composition/edge.d.ts.map +1 -1
- package/dist/composition/edge.js +23 -1
- package/dist/composition/edge.js.map +1 -1
- package/dist/composition/enumerate.d.ts.map +1 -1
- package/dist/composition/enumerate.js +18 -3
- package/dist/composition/enumerate.js.map +1 -1
- package/dist/composition/evaluate-relation.d.ts +35 -11
- package/dist/composition/evaluate-relation.d.ts.map +1 -1
- package/dist/composition/evaluate-relation.js +60 -39
- package/dist/composition/evaluate-relation.js.map +1 -1
- package/dist/composition/explain.d.ts +3 -12
- package/dist/composition/explain.d.ts.map +1 -1
- package/dist/composition/explain.js +7 -20
- package/dist/composition/explain.js.map +1 -1
- package/dist/composition/expr-eval.d.ts +1 -1
- package/dist/composition/expr-eval.d.ts.map +1 -1
- package/dist/composition/expr-eval.js +6 -15
- package/dist/composition/expr-eval.js.map +1 -1
- package/dist/composition/expr-simplify.d.ts +26 -14
- package/dist/composition/expr-simplify.d.ts.map +1 -1
- package/dist/composition/expr-simplify.js +64 -72
- package/dist/composition/expr-simplify.js.map +1 -1
- package/dist/composition/formula-shape.d.ts +23 -4
- package/dist/composition/formula-shape.d.ts.map +1 -1
- package/dist/composition/formula-shape.js +57 -17
- package/dist/composition/formula-shape.js.map +1 -1
- package/dist/composition/graph-structure.d.ts +98 -0
- package/dist/composition/graph-structure.d.ts.map +1 -0
- package/dist/composition/graph-structure.js +167 -0
- package/dist/composition/graph-structure.js.map +1 -0
- package/dist/composition/graph-viz-svg.d.ts.map +1 -1
- package/dist/composition/graph-viz-svg.js +1 -1
- package/dist/composition/graph-viz-svg.js.map +1 -1
- package/dist/composition/graph-viz.d.ts.map +1 -1
- package/dist/composition/graph-viz.js +8 -37
- package/dist/composition/graph-viz.js.map +1 -1
- package/dist/composition/grounding.d.ts.map +1 -1
- package/dist/composition/grounding.js +19 -7
- package/dist/composition/grounding.js.map +1 -1
- package/dist/composition/identifiability.d.ts +91 -4
- package/dist/composition/identifiability.d.ts.map +1 -1
- package/dist/composition/identifiability.js +363 -6
- package/dist/composition/identifiability.js.map +1 -1
- package/dist/composition/index.d.ts +8 -4
- package/dist/composition/index.d.ts.map +1 -1
- package/dist/composition/index.js +3 -2
- package/dist/composition/index.js.map +1 -1
- package/dist/composition/mathts-quiet.d.ts +7 -8
- package/dist/composition/mathts-quiet.d.ts.map +1 -1
- package/dist/composition/mathts-quiet.js +7 -16
- package/dist/composition/mathts-quiet.js.map +1 -1
- package/dist/composition/mathts-scalar-symbols.d.ts.map +1 -1
- package/dist/composition/mathts-scalar-symbols.js +2 -1
- package/dist/composition/mathts-scalar-symbols.js.map +1 -1
- package/dist/composition/own-equation-magnitude.d.ts +95 -0
- package/dist/composition/own-equation-magnitude.d.ts.map +1 -0
- package/dist/composition/own-equation-magnitude.js +270 -0
- package/dist/composition/own-equation-magnitude.js.map +1 -0
- package/dist/composition/probe/backend-protocol.d.ts +3 -0
- package/dist/composition/probe/backend-protocol.d.ts.map +1 -1
- package/dist/composition/probe/backend-protocol.js.map +1 -1
- package/dist/composition/probe/candidate-store.d.ts +1 -0
- package/dist/composition/probe/candidate-store.d.ts.map +1 -1
- package/dist/composition/probe/candidate-store.js +1 -0
- package/dist/composition/probe/candidate-store.js.map +1 -1
- package/dist/composition/probe/corpus.d.ts +8 -4
- package/dist/composition/probe/corpus.d.ts.map +1 -1
- package/dist/composition/probe/corpus.js +23 -12
- package/dist/composition/probe/corpus.js.map +1 -1
- package/dist/composition/probe/dataset.d.ts +18 -0
- package/dist/composition/probe/dataset.d.ts.map +1 -1
- package/dist/composition/probe/dataset.js +95 -50
- package/dist/composition/probe/dataset.js.map +1 -1
- package/dist/composition/probe/experiment-design.d.ts +7 -1
- package/dist/composition/probe/experiment-design.d.ts.map +1 -1
- package/dist/composition/probe/experiment-design.js +44 -24
- package/dist/composition/probe/experiment-design.js.map +1 -1
- package/dist/composition/probe/falsify.d.ts +2 -0
- package/dist/composition/probe/falsify.d.ts.map +1 -1
- package/dist/composition/probe/falsify.js +2 -0
- package/dist/composition/probe/falsify.js.map +1 -1
- package/dist/composition/probe/fit.d.ts +7 -0
- package/dist/composition/probe/fit.d.ts.map +1 -1
- package/dist/composition/probe/fit.js +46 -22
- package/dist/composition/probe/fit.js.map +1 -1
- package/dist/composition/probe/frontier.d.ts.map +1 -1
- package/dist/composition/probe/frontier.js +33 -15
- package/dist/composition/probe/frontier.js.map +1 -1
- package/dist/composition/probe/generator.d.ts +30 -1
- package/dist/composition/probe/generator.d.ts.map +1 -1
- package/dist/composition/probe/generator.js +58 -36
- package/dist/composition/probe/generator.js.map +1 -1
- package/dist/composition/probe/index.d.ts +14 -0
- package/dist/composition/probe/index.d.ts.map +1 -1
- package/dist/composition/probe/index.js +6 -0
- package/dist/composition/probe/index.js.map +1 -1
- package/dist/composition/probe/limits.d.ts +25 -1
- package/dist/composition/probe/limits.d.ts.map +1 -1
- package/dist/composition/probe/limits.js +53 -11
- package/dist/composition/probe/limits.js.map +1 -1
- package/dist/composition/probe/pipeline.d.ts +5 -0
- package/dist/composition/probe/pipeline.d.ts.map +1 -1
- package/dist/composition/probe/pipeline.js +73 -24
- package/dist/composition/probe/pipeline.js.map +1 -1
- package/dist/composition/probe/power-law.d.ts +121 -0
- package/dist/composition/probe/power-law.d.ts.map +1 -0
- package/dist/composition/probe/power-law.js +251 -0
- package/dist/composition/probe/power-law.js.map +1 -0
- package/dist/composition/probe/problem.d.ts +8 -4
- package/dist/composition/probe/problem.d.ts.map +1 -1
- package/dist/composition/probe/problem.js +177 -49
- package/dist/composition/probe/problem.js.map +1 -1
- package/dist/composition/probe/report.js +1 -1
- package/dist/composition/probe/report.js.map +1 -1
- package/dist/composition/probe/residual.d.ts +7 -1
- package/dist/composition/probe/residual.d.ts.map +1 -1
- package/dist/composition/probe/residual.js +10 -7
- package/dist/composition/probe/residual.js.map +1 -1
- package/dist/composition/probe/run-manifest.d.ts +1 -0
- package/dist/composition/probe/run-manifest.d.ts.map +1 -1
- package/dist/composition/probe/run-manifest.js.map +1 -1
- package/dist/composition/probe/scalar-search.d.ts +50 -0
- package/dist/composition/probe/scalar-search.d.ts.map +1 -0
- package/dist/composition/probe/scalar-search.js +169 -0
- package/dist/composition/probe/scalar-search.js.map +1 -0
- package/dist/composition/probe/scoring.d.ts +1 -0
- package/dist/composition/probe/scoring.d.ts.map +1 -1
- package/dist/composition/probe/scoring.js.map +1 -1
- package/dist/composition/probe/structure.d.ts +82 -17
- package/dist/composition/probe/structure.d.ts.map +1 -1
- package/dist/composition/probe/structure.js +129 -55
- package/dist/composition/probe/structure.js.map +1 -1
- package/dist/composition/probe/study.d.ts +31 -9
- package/dist/composition/probe/study.d.ts.map +1 -1
- package/dist/composition/probe/study.js +235 -184
- package/dist/composition/probe/study.js.map +1 -1
- package/dist/composition/probe/t-tail.d.ts +16 -0
- package/dist/composition/probe/t-tail.d.ts.map +1 -0
- package/dist/composition/probe/t-tail.js +29 -0
- package/dist/composition/probe/t-tail.js.map +1 -0
- package/dist/composition/probe/types.d.ts +3 -0
- package/dist/composition/probe/types.d.ts.map +1 -1
- package/dist/composition/probe/types.js.map +1 -1
- package/dist/composition/proposed-bridges.d.ts +52 -12
- package/dist/composition/proposed-bridges.d.ts.map +1 -1
- package/dist/composition/proposed-bridges.js +107 -60
- package/dist/composition/proposed-bridges.js.map +1 -1
- package/dist/composition/quantity-clusters.d.ts +48 -0
- package/dist/composition/quantity-clusters.d.ts.map +1 -0
- package/dist/composition/quantity-clusters.js +98 -0
- package/dist/composition/quantity-clusters.js.map +1 -0
- package/dist/composition/rational-exponent.d.ts +40 -0
- package/dist/composition/rational-exponent.d.ts.map +1 -0
- package/dist/composition/rational-exponent.js +65 -0
- package/dist/composition/rational-exponent.js.map +1 -0
- package/dist/composition/representative-values.d.ts +22 -0
- package/dist/composition/representative-values.d.ts.map +1 -1
- package/dist/composition/representative-values.js +29 -0
- package/dist/composition/representative-values.js.map +1 -1
- package/dist/composition/retrodiction.d.ts +15 -0
- package/dist/composition/retrodiction.d.ts.map +1 -1
- package/dist/composition/retrodiction.js +12 -4
- package/dist/composition/retrodiction.js.map +1 -1
- package/dist/composition/user-equation.d.ts +1 -0
- package/dist/composition/user-equation.d.ts.map +1 -1
- package/dist/composition/user-equation.js +3 -2
- package/dist/composition/user-equation.js.map +1 -1
- package/dist/core/assignment.d.ts +19 -0
- package/dist/core/assignment.d.ts.map +1 -0
- package/dist/core/assignment.js +19 -0
- package/dist/core/assignment.js.map +1 -0
- package/dist/core/compare.d.ts +32 -0
- package/dist/core/compare.d.ts.map +1 -0
- package/dist/core/compare.js +46 -0
- package/dist/core/compare.js.map +1 -0
- package/dist/core/constants.d.ts +42 -41
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +71 -51
- package/dist/core/constants.js.map +1 -1
- package/dist/core/data-file.d.ts +7 -0
- package/dist/core/data-file.d.ts.map +1 -1
- package/dist/core/data-file.js +17 -0
- package/dist/core/data-file.js.map +1 -1
- package/dist/core/format.d.ts +36 -0
- package/dist/core/format.d.ts.map +1 -0
- package/dist/core/format.js +39 -0
- package/dist/core/format.js.map +1 -0
- package/dist/core/hash.d.ts +14 -0
- package/dist/core/hash.d.ts.map +1 -0
- package/dist/core/hash.js +17 -0
- package/dist/core/hash.js.map +1 -0
- package/dist/core/json-schema.d.ts +2 -0
- package/dist/core/json-schema.d.ts.map +1 -1
- package/dist/core/json-schema.js +14 -13
- package/dist/core/json-schema.js.map +1 -1
- package/dist/core/labeled-tensor.d.ts.map +1 -1
- package/dist/core/labeled-tensor.js +0 -8
- package/dist/core/labeled-tensor.js.map +1 -1
- package/dist/core/mathts-read.d.ts +25 -0
- package/dist/core/mathts-read.d.ts.map +1 -0
- package/dist/core/mathts-read.js +51 -0
- package/dist/core/mathts-read.js.map +1 -0
- package/dist/core/tensor.d.ts.map +1 -1
- package/dist/core/tensor.js +24 -0
- package/dist/core/tensor.js.map +1 -1
- package/dist/core/types.d.ts +5 -5
- package/dist/diff/bridge-ast-gradient.d.ts +27 -23
- package/dist/diff/bridge-ast-gradient.d.ts.map +1 -1
- package/dist/diff/bridge-ast-gradient.js +75 -173
- package/dist/diff/bridge-ast-gradient.js.map +1 -1
- package/dist/diff/bridge-gradient.d.ts +19 -6
- package/dist/diff/bridge-gradient.d.ts.map +1 -1
- package/dist/diff/bridge-gradient.js +19 -11
- package/dist/diff/bridge-gradient.js.map +1 -1
- package/dist/diff/bridge-specs.d.ts.map +1 -1
- package/dist/diff/bridge-specs.js +3 -0
- package/dist/diff/bridge-specs.js.map +1 -1
- package/dist/dimensional/algebra.d.ts +18 -0
- package/dist/dimensional/algebra.d.ts.map +1 -1
- package/dist/dimensional/algebra.js +41 -1
- package/dist/dimensional/algebra.js.map +1 -1
- package/dist/dimensional/ast-builders.d.ts +7 -0
- package/dist/dimensional/ast-builders.d.ts.map +1 -1
- package/dist/dimensional/ast-builders.js +11 -0
- package/dist/dimensional/ast-builders.js.map +1 -1
- package/dist/dimensional/ast-leaves.d.ts +81 -0
- package/dist/dimensional/ast-leaves.d.ts.map +1 -0
- package/dist/dimensional/ast-leaves.js +146 -0
- package/dist/dimensional/ast-leaves.js.map +1 -0
- package/dist/dimensional/ast-types.d.ts +15 -0
- package/dist/dimensional/ast-types.d.ts.map +1 -1
- package/dist/dimensional/ast-types.js.map +1 -1
- package/dist/dimensional/buckingham.d.ts.map +1 -1
- package/dist/dimensional/buckingham.js +15 -27
- package/dist/dimensional/buckingham.js.map +1 -1
- package/dist/dimensional/constant-rows.js +9 -9
- package/dist/dimensional/constant-rows.js.map +1 -1
- package/dist/dimensional/curvature-composite.d.ts +1 -1
- package/dist/dimensional/curvature-composite.js.map +1 -1
- package/dist/dimensional/dimension-inference.d.ts.map +1 -1
- package/dist/dimensional/dimension-inference.js +1 -2
- package/dist/dimensional/dimension-inference.js.map +1 -1
- package/dist/dimensional/errors.d.ts +1 -1
- package/dist/dimensional/errors.d.ts.map +1 -1
- package/dist/dimensional/errors.js +1 -15
- package/dist/dimensional/errors.js.map +1 -1
- package/dist/dimensional/exact-scale.d.ts +24 -11
- package/dist/dimensional/exact-scale.d.ts.map +1 -1
- package/dist/dimensional/exact-scale.js +122 -130
- package/dist/dimensional/exact-scale.js.map +1 -1
- package/dist/dimensional/gauge-field.d.ts.map +1 -1
- package/dist/dimensional/gauge-field.js +2 -2
- package/dist/dimensional/gauge-field.js.map +1 -1
- package/dist/dimensional/hyphen-names.d.ts +12 -2
- package/dist/dimensional/hyphen-names.d.ts.map +1 -1
- package/dist/dimensional/hyphen-names.js +44 -19
- package/dist/dimensional/hyphen-names.js.map +1 -1
- package/dist/dimensional/mathts-unit-delegation.d.ts +29 -0
- package/dist/dimensional/mathts-unit-delegation.d.ts.map +1 -0
- package/dist/dimensional/mathts-unit-delegation.js +187 -0
- package/dist/dimensional/mathts-unit-delegation.js.map +1 -0
- package/dist/dimensional/mathts-unit-wrapper.d.ts +33 -0
- package/dist/dimensional/mathts-unit-wrapper.d.ts.map +1 -0
- package/dist/dimensional/mathts-unit-wrapper.js +190 -0
- package/dist/dimensional/mathts-unit-wrapper.js.map +1 -0
- package/dist/dimensional/metric.d.ts.map +1 -1
- package/dist/dimensional/metric.js +0 -1
- package/dist/dimensional/metric.js.map +1 -1
- package/dist/dimensional/scalar-lowering.d.ts +21 -0
- package/dist/dimensional/scalar-lowering.d.ts.map +1 -0
- package/dist/dimensional/scalar-lowering.js +45 -0
- package/dist/dimensional/scalar-lowering.js.map +1 -0
- package/dist/dimensional/symbolic-constants.d.ts +9 -0
- package/dist/dimensional/symbolic-constants.d.ts.map +1 -1
- package/dist/dimensional/symbolic-constants.js +13 -1
- package/dist/dimensional/symbolic-constants.js.map +1 -1
- package/dist/dimensional/types.d.ts +36 -0
- package/dist/dimensional/types.d.ts.map +1 -1
- package/dist/dimensional/types.js +45 -7
- package/dist/dimensional/types.js.map +1 -1
- package/dist/dimensional/unit-data.d.ts +5 -1
- package/dist/dimensional/unit-data.d.ts.map +1 -1
- package/dist/dimensional/unit-data.js +30 -6
- package/dist/dimensional/unit-data.js.map +1 -1
- package/dist/dimensional/units.d.ts +2 -0
- package/dist/dimensional/units.d.ts.map +1 -1
- package/dist/dimensional/units.js +59 -3
- package/dist/dimensional/units.js.map +1 -1
- package/dist/dimensional/validator.d.ts +2 -0
- package/dist/dimensional/validator.d.ts.map +1 -1
- package/dist/dimensional/validator.js.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/numerical/christoffel-flat.d.ts.map +1 -1
- package/dist/numerical/christoffel-flat.js +3 -2
- package/dist/numerical/christoffel-flat.js.map +1 -1
- package/dist/numerical/connection-lowering-helpers.d.ts +3 -1
- package/dist/numerical/connection-lowering-helpers.d.ts.map +1 -1
- package/dist/numerical/connection-lowering-helpers.js +11 -15
- package/dist/numerical/connection-lowering-helpers.js.map +1 -1
- package/dist/numerical/covariant-eikonal.d.ts.map +1 -1
- package/dist/numerical/covariant-eikonal.js +34 -11
- package/dist/numerical/covariant-eikonal.js.map +1 -1
- package/dist/numerical/curvature-lowering-helpers.js +3 -2
- package/dist/numerical/curvature-lowering-helpers.js.map +1 -1
- package/dist/numerical/errors.d.ts.map +1 -1
- package/dist/numerical/errors.js +0 -3
- package/dist/numerical/errors.js.map +1 -1
- package/dist/numerical/finite-difference.d.ts +22 -0
- package/dist/numerical/finite-difference.d.ts.map +1 -0
- package/dist/numerical/finite-difference.js +27 -0
- package/dist/numerical/finite-difference.js.map +1 -0
- package/dist/numerical/geodesic-integrator.d.ts.map +1 -1
- package/dist/numerical/geodesic-integrator.js +22 -14
- package/dist/numerical/geodesic-integrator.js.map +1 -1
- package/dist/numerical/geometrized.d.ts.map +1 -1
- package/dist/numerical/geometrized.js +0 -1
- package/dist/numerical/geometrized.js.map +1 -1
- package/dist/numerical/mathts-engine.d.ts.map +1 -1
- package/dist/numerical/mathts-engine.js +10 -24
- package/dist/numerical/mathts-engine.js.map +1 -1
- package/dist/numerical/metric-inverse.d.ts.map +1 -1
- package/dist/numerical/metric-inverse.js +83 -46
- package/dist/numerical/metric-inverse.js.map +1 -1
- package/dist/numerical/null-ray-integrator.d.ts +2 -1
- package/dist/numerical/null-ray-integrator.d.ts.map +1 -1
- package/dist/numerical/null-ray-integrator.js +12 -12
- package/dist/numerical/null-ray-integrator.js.map +1 -1
- package/dist/numerical/painleve-gullstrand-metric.js +2 -2
- package/dist/numerical/painleve-gullstrand-metric.js.map +1 -1
- package/dist/numerical/pderiv.d.ts.map +1 -1
- package/dist/numerical/pderiv.js +2 -6
- package/dist/numerical/pderiv.js.map +1 -1
- package/dist/numerical/perihelion-finder.d.ts +0 -36
- package/dist/numerical/perihelion-finder.d.ts.map +1 -1
- package/dist/numerical/perihelion-finder.js +41 -87
- package/dist/numerical/perihelion-finder.js.map +1 -1
- package/dist/numerical/quadrature.d.ts.map +1 -1
- package/dist/numerical/quadrature.js +11 -13
- package/dist/numerical/quadrature.js.map +1 -1
- package/dist/numerical/rk4-trajectory.d.ts +10 -0
- package/dist/numerical/rk4-trajectory.d.ts.map +1 -0
- package/dist/numerical/rk4-trajectory.js +37 -0
- package/dist/numerical/rk4-trajectory.js.map +1 -0
- package/dist/numerical/schwarzschild.d.ts +14 -0
- package/dist/numerical/schwarzschild.d.ts.map +1 -0
- package/dist/numerical/schwarzschild.js +17 -0
- package/dist/numerical/schwarzschild.js.map +1 -0
- package/dist/numerical/spacetime-metrics.d.ts +12 -0
- package/dist/numerical/spacetime-metrics.d.ts.map +1 -1
- package/dist/numerical/spacetime-metrics.js +72 -56
- package/dist/numerical/spacetime-metrics.js.map +1 -1
- package/dist/numerical/statistics.d.ts +24 -0
- package/dist/numerical/statistics.d.ts.map +1 -0
- package/dist/numerical/statistics.js +52 -0
- package/dist/numerical/statistics.js.map +1 -0
- package/dist/numerical/strides.d.ts +3 -2
- package/dist/numerical/strides.d.ts.map +1 -1
- package/dist/numerical/strides.js +3 -10
- package/dist/numerical/strides.js.map +1 -1
- package/dist/numerical/tensor-engine.d.ts +21 -0
- package/dist/numerical/tensor-engine.d.ts.map +1 -1
- package/dist/numerical/tensor-engine.js +12 -0
- package/dist/numerical/tensor-engine.js.map +1 -1
- package/dist/relations/regime.d.ts +10 -0
- package/dist/relations/regime.d.ts.map +1 -1
- package/dist/relations/regime.js +18 -1
- package/dist/relations/regime.js.map +1 -1
- package/package.json +9 -12
- package/dist/cases/brownian-sphere.d.ts +0 -68
- package/dist/cases/brownian-sphere.d.ts.map +0 -1
- package/dist/cases/brownian-sphere.js +0 -354
- package/dist/cases/brownian-sphere.js.map +0 -1
- package/dist/cases/damped-resonator.d.ts +0 -23
- package/dist/cases/damped-resonator.d.ts.map +0 -1
- package/dist/cases/damped-resonator.js +0 -224
- package/dist/cases/damped-resonator.js.map +0 -1
- package/dist/cases/kepler-rv.d.ts +0 -13
- package/dist/cases/kepler-rv.d.ts.map +0 -1
- package/dist/cases/kepler-rv.js +0 -172
- package/dist/cases/kepler-rv.js.map +0 -1
- package/dist/cases/lumped-cooling.d.ts +0 -46
- package/dist/cases/lumped-cooling.d.ts.map +0 -1
- package/dist/cases/lumped-cooling.js +0 -261
- package/dist/cases/lumped-cooling.js.map +0 -1
- package/dist/cases/resistor-noise.d.ts +0 -14
- package/dist/cases/resistor-noise.d.ts.map +0 -1
- package/dist/cases/resistor-noise.js +0 -215
- package/dist/cases/resistor-noise.js.map +0 -1
- package/dist/cases/skin-depth.d.ts +0 -21
- package/dist/cases/skin-depth.d.ts.map +0 -1
- package/dist/cases/skin-depth.js +0 -174
- package/dist/cases/skin-depth.js.map +0 -1
|
@@ -116,8 +116,18 @@ export function isInputContractError(error) {
|
|
|
116
116
|
error instanceof DuplicateInputError ||
|
|
117
117
|
error instanceof ConstantInputError);
|
|
118
118
|
}
|
|
119
|
+
/** `T_K = -1 violates T_K >= 0`; two inputs: `T_c_K = 5, T_h_K = 3 violate T_c_K <= T_h_K`. */
|
|
120
|
+
function describeViolation(violation) {
|
|
121
|
+
if (violation.inputs.length === 0)
|
|
122
|
+
return `${violation.condition} fails`;
|
|
123
|
+
const given = violation.inputs.map((input) => `${input.key} = ${input.value}`).join(', ');
|
|
124
|
+
return `${given} ${violation.inputs.length === 1 ? 'violates' : 'violate'} ${violation.condition}`;
|
|
125
|
+
}
|
|
119
126
|
/**
|
|
120
127
|
* Evaluation refused: the inputs fall outside the relation's validity domain.
|
|
128
|
+
* The error lists only the conditions that failed, each with the input keys it
|
|
129
|
+
* reads and their values; the message is rendered from them, so it cannot name
|
|
130
|
+
* a condition the check did not run.
|
|
121
131
|
*
|
|
122
132
|
* Honest deviation from design D-3's "domain-incompatible at compose
|
|
123
133
|
* time": domain predicates are opaque functions, so incompatibility is
|
|
@@ -128,8 +138,16 @@ export function isInputContractError(error) {
|
|
|
128
138
|
* @public
|
|
129
139
|
*/
|
|
130
140
|
export class DomainViolationError extends Error {
|
|
131
|
-
|
|
132
|
-
|
|
141
|
+
id;
|
|
142
|
+
violations;
|
|
143
|
+
context;
|
|
144
|
+
/** The id evaluated, every violated condition, and, for a composed edge, where in the composition it failed. */
|
|
145
|
+
constructor(id, violations, context) {
|
|
146
|
+
super(`${id}: outside the validity domain${context === undefined ? '' : ` (${context})`}: ` +
|
|
147
|
+
violations.map(describeViolation).join('; '));
|
|
148
|
+
this.id = id;
|
|
149
|
+
this.violations = violations;
|
|
150
|
+
this.context = context;
|
|
133
151
|
this.name = 'DomainViolationError';
|
|
134
152
|
}
|
|
135
153
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation-errors.js","sourceRoot":"","sources":["../../src/bridges/evaluation-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,4EAA4E;AAC5E,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAG/B,EAAE;IACF,OAAO;IACP,MAAM;IAJjB,iEAAiE;IACjE,YACW,EAAU,EACV,OAA0B,EAC1B,MAAyB;QAElC,KAAK,CAAC,GAAG,EAAE,mBAAmB,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,IAA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I,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF","sourcesContent":["/**\n * The errors one evaluation throws, in the order it checks: the bindings\n * against the declared inputs first (an unknown key, a non-number, a number\n * that is not finite, a key given twice, an absent input), then the validity\n * domain. An input error says what the caller left out or misspelled; a\n * domain error says the physics refuses the values. The library throws these classes so a caller can tell them\n * apart by type, never by message text.\n *\n * @module bridges/evaluation-errors\n */\n\n/** A required input is absent. It is not a physically bad value. @public */\nexport class MissingInputError extends Error {\n /** The id evaluated, the absent keys, and every declared key. */\n constructor(\n readonly id: string,\n readonly missing: readonly string[],\n readonly inputs: readonly string[],\n ) {\n super(`${id}: missing input ${missing.map((key) => `'${key}'`).join(', ')}; the inputs are: ${inputs.join(', ')}`);\n this.name = 'MissingInputError';\n }\n}\n\nconst prefix = (id: string | undefined): string => (id === undefined ? '' : `${id}: `);\n\n/** A binding names no declared input, alias or alternate of the id. @public */\nexport class UnknownInputError extends Error {\n /** The id evaluated (absent when the reader was not told it), the unknown key, and every declared key. */\n constructor(\n readonly id: string | undefined,\n readonly key: string,\n readonly inputs: readonly string[],\n ) {\n super(`${prefix(id)}'${key}' is not an input here; the inputs are: ${inputs.join(', ')}`);\n this.name = 'UnknownInputError';\n }\n}\n\n/** A binding's value is not a number. A `TypeError`, as before it was typed. @public */\nexport class InputTypeError extends TypeError {\n /** The id evaluated, the key, and the JavaScript type that was given. */\n constructor(\n readonly id: string,\n readonly key: string,\n readonly got: string,\n ) {\n super(`${id}: ${key} must be a number, got ${got}`);\n this.name = 'InputTypeError';\n }\n}\n\n/**\n * A binding's value is a number that is not finite (`NaN`, `Infinity`,\n * `-Infinity`). It is refused before the domain, so a validity predicate never\n * sees it and a closed form never turns it into an unset result. @public\n */\nexport class NonFiniteInputError extends Error {\n /** The id evaluated, the key, and the value that was given. */\n constructor(\n readonly id: string,\n readonly key: string,\n readonly value: number,\n ) {\n super(`${id}: ${key} must be a finite number, got ${value}`);\n this.name = 'NonFiniteInputError';\n }\n}\n\n/**\n * A binding names π, a registered physical constant or a formula overlay\n * (`G`, `k_B`, `m_p`, …). A constant is never an input: the value would\n * silently replace the constant in the formula. A relation's own declared\n * source may carry such a name (a named default the caller overrides); any\n * other key with that name is refused before the formula is evaluated.\n * @public\n */\nexport class ConstantInputError extends Error {\n /** The key that was given. */\n constructor(readonly key: string) {\n super(`'${key}' names a registered constant and is not an input`);\n this.name = 'ConstantInputError';\n }\n}\n\n/** One input is given twice, under two of its spellings (its key, an alias, or an alternate). @public */\nexport class DuplicateInputError extends Error {\n /** The id evaluated (absent when the reader was not told it), the input, and the two spellings it was given under. */\n constructor(\n readonly id: string | undefined,\n readonly key: string,\n readonly spellings: readonly [string, string],\n ) {\n super(\n spellings[0] === spellings[1]\n ? `${prefix(id)}'${key}' is given twice`\n : `${prefix(id)}'${key}' is given twice (once through an alternate): ${spellings[0]} and ${spellings[1]}`,\n );\n this.name = 'DuplicateInputError';\n }\n}\n\n/**\n * True for an error the input contract throws: an absent, unknown, non-number,\n * non-finite, twice-given or constant-named input. A caller that reports input errors one way\n * and domain errors another asks this, not the message.\n * @internal\n */\nexport function isInputContractError(\n error: unknown,\n): error is MissingInputError | UnknownInputError | InputTypeError | NonFiniteInputError | DuplicateInputError | ConstantInputError {\n return (\n error instanceof MissingInputError ||\n error instanceof UnknownInputError ||\n error instanceof InputTypeError ||\n error instanceof NonFiniteInputError ||\n error instanceof DuplicateInputError ||\n error instanceof ConstantInputError\n );\n}\n\n/**\n * Evaluation refused: the inputs fall outside the relation's validity domain.\n *\n * Honest deviation from design D-3's \"domain-incompatible at compose\n * time\": domain predicates are opaque functions, so incompatibility is\n * detectable only at evaluation. This error is thrown by `evaluateEdge`, by\n * a catalog evaluator, and by composed edges internally, not by\n * `composeEdges`.\n *\n * @public\n */\nexport class DomainViolationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'DomainViolationError';\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evaluation-errors.js","sourceRoot":"","sources":["../../src/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bindings\n * against the declared inputs first (an unknown key, a non-number, a number\n * that is not finite, a key given twice, an absent input), then the validity\n * domain. An input error says what the caller left out or misspelled; a\n * domain error says the physics refuses the values. The library throws these classes so a caller can tell them\n * apart by type, never by message text.\n *\n * @module bridges/evaluation-errors\n */\n\n/** A required input is absent. It is not a physically bad value. @public */\nexport class MissingInputError extends Error {\n /** The id evaluated, the absent keys, and every declared key. */\n constructor(\n readonly id: string,\n readonly missing: readonly string[],\n readonly inputs: readonly string[],\n ) {\n super(`${id}: missing input ${missing.map((key) => `'${key}'`).join(', ')}; the inputs are: ${inputs.join(', ')}`);\n this.name = 'MissingInputError';\n }\n}\n\nconst prefix = (id: string | undefined): string => (id === undefined ? '' : `${id}: `);\n\n/** A binding names no declared input, alias or alternate of the id. @public */\nexport class UnknownInputError extends Error {\n /** The id evaluated (absent when the reader was not told it), the unknown key, and every declared key. */\n constructor(\n readonly id: string | undefined,\n readonly key: string,\n readonly inputs: readonly string[],\n ) {\n super(`${prefix(id)}'${key}' is not an input here; the inputs are: ${inputs.join(', ')}`);\n this.name = 'UnknownInputError';\n }\n}\n\n/** A binding's value is not a number. A `TypeError`, as before it was typed. @public */\nexport class InputTypeError extends TypeError {\n /** The id evaluated, the key, and the JavaScript type that was given. */\n constructor(\n readonly id: string,\n readonly key: string,\n readonly got: string,\n ) {\n super(`${id}: ${key} must be a number, got ${got}`);\n this.name = 'InputTypeError';\n }\n}\n\n/**\n * A binding's value is a number that is not finite (`NaN`, `Infinity`,\n * `-Infinity`). It is refused before the domain, so a validity predicate never\n * sees it and a closed form never turns it into an unset result. @public\n */\nexport class NonFiniteInputError extends Error {\n /** The id evaluated, the key, and the value that was given. */\n constructor(\n readonly id: string,\n readonly key: string,\n readonly value: number,\n ) {\n super(`${id}: ${key} must be a finite number, got ${value}`);\n this.name = 'NonFiniteInputError';\n }\n}\n\n/**\n * A binding names π, a registered physical constant or a formula overlay\n * (`G`, `k_B`, `m_p`, …). A constant is never an input: the value would\n * silently replace the constant in the formula. A relation's own declared\n * source may carry such a name (a named default the caller overrides); any\n * other key with that name is refused before the formula is evaluated.\n * @public\n */\nexport class ConstantInputError extends Error {\n /** The key that was given. */\n constructor(readonly key: string) {\n super(`'${key}' names a registered constant and is not an input`);\n this.name = 'ConstantInputError';\n }\n}\n\n/** One input is given twice, under two of its spellings (its key, an alias, or an alternate). @public */\nexport class DuplicateInputError extends Error {\n /** The id evaluated (absent when the reader was not told it), the input, and the two spellings it was given under. */\n constructor(\n readonly id: string | undefined,\n readonly key: string,\n readonly spellings: readonly [string, string],\n ) {\n super(\n spellings[0] === spellings[1]\n ? `${prefix(id)}'${key}' is given twice`\n : `${prefix(id)}'${key}' is given twice (once through an alternate): ${spellings[0]} and ${spellings[1]}`,\n );\n this.name = 'DuplicateInputError';\n }\n}\n\n/**\n * True for an error the input contract throws: an absent, unknown, non-number,\n * non-finite, twice-given or constant-named input. A caller that reports input errors one way\n * and domain errors another asks this, not the message.\n * @internal\n */\nexport function isInputContractError(\n error: unknown,\n): error is MissingInputError | UnknownInputError | InputTypeError | NonFiniteInputError | DuplicateInputError | ConstantInputError {\n return (\n error instanceof MissingInputError ||\n error instanceof UnknownInputError ||\n error instanceof InputTypeError ||\n error instanceof NonFiniteInputError ||\n error instanceof DuplicateInputError ||\n error instanceof ConstantInputError\n );\n}\n\n/**\n * One input a violated condition reads: the key the caller gave it under, the\n * name the relation reads it by, and its value. @public\n */\nexport interface DomainInput {\n readonly key: string;\n readonly quantity: string;\n readonly value: number;\n}\n\n/**\n * One violated condition of a validity domain. `condition` is the conjunct of\n * the record's `holds` that failed, written with the caller's keys\n * (`T_K >= 0`); `key` and `value` are the first input it reads, and `inputs`\n * every input it reads. A condition that reads no input (a constant check) has\n * `key` `''` and `value` `NaN`. A later range-per-kind change generates the\n * same objects. @public\n */\nexport interface DomainViolation {\n readonly condition: string;\n readonly key: string;\n readonly value: number;\n readonly inputs: readonly DomainInput[];\n}\n\n/** `T_K = -1 violates T_K >= 0`; two inputs: `T_c_K = 5, T_h_K = 3 violate T_c_K <= T_h_K`. */\nfunction describeViolation(violation: DomainViolation): string {\n if (violation.inputs.length === 0) return `${violation.condition} fails`;\n const given = violation.inputs.map((input) => `${input.key} = ${input.value}`).join(', ');\n return `${given} ${violation.inputs.length === 1 ? 'violates' : 'violate'} ${violation.condition}`;\n}\n\n/**\n * Evaluation refused: the inputs fall outside the relation's validity domain.\n * The error lists only the conditions that failed, each with the input keys it\n * reads and their values; the message is rendered from them, so it cannot name\n * a condition the check did not run.\n *\n * Honest deviation from design D-3's \"domain-incompatible at compose\n * time\": domain predicates are opaque functions, so incompatibility is\n * detectable only at evaluation. This error is thrown by `evaluateEdge`, by\n * a catalog evaluator, and by composed edges internally, not by\n * `composeEdges`.\n *\n * @public\n */\nexport class DomainViolationError extends Error {\n /** The id evaluated, every violated condition, and, for a composed edge, where in the composition it failed. */\n constructor(\n readonly id: string,\n readonly violations: readonly DomainViolation[],\n readonly context?: string,\n ) {\n super(\n `${id}: outside the validity domain${context === undefined ? '' : ` (${context})`}: ` +\n violations.map(describeViolation).join('; '),\n );\n this.name = 'DomainViolationError';\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator-inputs.d.ts","sourceRoot":"","sources":["../../src/bridges/evaluator-inputs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluator-inputs.d.ts","sourceRoot":"","sources":["../../src/bridges/evaluator-inputs.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAG1D,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAuCD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,SAAS,kBAAkB,EAAE,EACzC,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,EAAE,CAAC,EAAE,MAAM,GACV;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,QAAQ,EAAE,aAAa,EAAE,CAAA;CAAE,CAgD/D"}
|
|
@@ -10,22 +10,24 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @module bridges/evaluator-inputs
|
|
12
12
|
*/
|
|
13
|
+
import { splitAssignment } from '../core/assignment.js';
|
|
14
|
+
import { formatQuantity } from '../core/format.js';
|
|
13
15
|
import { affineReadingNote, unitConventionNotes, UnitError } from '../dimensional/units.js';
|
|
14
16
|
import { resolveQuantityName, synonymGroup, synonymDisagreement, temperatureQuantityRole, } from '../dimensional/formula-names.js';
|
|
15
17
|
import { readNamedBinding } from '../numerical/binding-value.js';
|
|
16
18
|
import { DuplicateInputError, UnknownInputError } from './evaluation-errors.js';
|
|
17
|
-
/** 15 significant digits
|
|
18
|
-
const show =
|
|
19
|
+
/** 15 significant digits in the note; the value itself is passed unrounded. */
|
|
20
|
+
const show = formatQuantity;
|
|
19
21
|
/** Disclosures that a unit symbol does not carry by itself. */
|
|
20
22
|
function unitAside(given) {
|
|
21
23
|
const notes = unitConventionNotes(given);
|
|
22
24
|
return notes.length === 0 ? '' : ` — ${notes.join('; ')}`;
|
|
23
25
|
}
|
|
24
26
|
const splitArg = (a) => {
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
+
const split = splitAssignment(a);
|
|
28
|
+
if (split === null)
|
|
27
29
|
throw new UnitError(`'${a}' must be key=value (e.g. d_m=1um)`);
|
|
28
|
-
return [
|
|
30
|
+
return [split.name, split.raw];
|
|
29
31
|
};
|
|
30
32
|
function convert(p, raw, reading, siblings, givenName) {
|
|
31
33
|
const read = readNamedBinding(givenName, raw, { reading, siblings, declaredUnit: p.unit });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator-inputs.js","sourceRoot":"","sources":["../../src/bridges/evaluator-inputs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,SAAS,EAA2B,MAAM,yBAAyB,CAAC;AACrH,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAA4B,MAAM,+BAA+B,CAAC;AAE3F,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAahF,mEAAmE;AACnE,MAAM,IAAI,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;AAE9D,+DAA+D;AAC/D,SAAS,SAAS,CAAC,KAAa;IAC9B,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC5D,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAoB,EAAE;IAC/C,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,EAAE,IAAI,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IAC5E,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CA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,IAAI;YACZ,KAAK,EAAE,GAAG;YACV,GAAG,CAAC,GAAG,KAAK,SAAS,IAAI,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,GAAG,CAAC,GAAG,KAAK,SAAS;gBACnB,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC3H,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS;oBACpB,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;SACxB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * `key=value[unit]` arguments → an evaluator's numeric inputs, through the\n * evaluator's declared parameters.\n *\n * Every argument must name a declared input or a declared alternate: an\n * unrecognised key is refused rather than ignored, because an ignored\n * `radius_m=` beside a required `diameter_m` is exactly the silent mistake the\n * declarations exist to catch. A value may carry a unit; it is converted into\n * the declared unit only when the dimensions agree.\n *\n * @module bridges/evaluator-inputs\n */\nimport { affineReadingNote, unitConventionNotes, UnitError, type TemperatureReading } from '../dimensional/units.js';\nimport {\n resolveQuantityName,\n synonymGroup,\n synonymDisagreement,\n temperatureQuantityRole,\n} from '../dimensional/formula-names.js';\nimport { readNamedBinding, type NamedBindingSibling } from '../numerical/binding-value.js';\nimport type { EvaluatorParameter } from './evaluators.js';\nimport { DuplicateInputError, UnknownInputError } from './evaluation-errors.js';\n\n/** One input as it was given and as the evaluator receives it. @internal */\nexport interface ResolvedInput {\n readonly key: string;\n readonly value: number;\n readonly unit: string;\n readonly given: string;\n /** The alternate key it was given under, when it was. */\n readonly via?: string;\n readonly note?: string;\n}\n\n/** 15 significant digits: the value itself is passed unrounded. */\nconst show = (v: number): number => Number(v.toPrecision(15));\n\n/** Disclosures that a unit symbol does not carry by itself. */\nfunction unitAside(given: string): string {\n const notes = unitConventionNotes(given);\n return notes.length === 0 ? '' : ` — ${notes.join('; ')}`;\n}\n\nconst splitArg = (a: string): [string, string] => {\n const eq = a.indexOf('=');\n if (eq <= 0) throw new UnitError(`'${a}' must be key=value (e.g. d_m=1um)`);\n return [a.slice(0, eq), a.slice(eq + 1)];\n};\n\nfunction convert(\n p: EvaluatorParameter,\n raw: string,\n reading: TemperatureReading,\n siblings: readonly NamedBindingSibling[],\n givenName: string,\n): { value: number; note?: string } {\n const read = readNamedBinding(givenName, raw, { reading, siblings, declaredUnit: p.unit });\n if (!read.dimensioned) return { value: read.value };\n // How an affine reading was applied comes from the unit table's own row (scale and ice point).\n const offset = read.affine === undefined ? '' : ` (${affineReadingNote(read.affine, reading)})`;\n // An angular input counts radians; a cycle-counting unit (the `cycles` flag on its row) takes 2π per cycle.\n const turns = p.angular === true ? read.cycles : 0;\n if (Number.isNaN(turns)) {\n throw new UnitError(`'${raw.trim()}' adds a cycle rate to a plain rate, so its radians per second are not defined`);\n }\n const value = turns === 0 ? read.value : read.value * (2 * Math.PI) ** turns;\n const turnsNote = turns === 0 ? '' : turns === 1 ? ' (cycles: × 2π)' : ` (cycles: × (2π)^${turns})`;\n const base = `${raw.trim()} → ${show(value)} ${p.unit || '(dimensionless)'}${offset}${turnsNote}${unitAside(raw)}`;\n return { value, note: read.temperatureNote === undefined ? base : `${base}. ${read.temperatureNote}` };\n}\n\n/**\n * Resolve `args` against `parameters`. `id` names the evaluated id in an input error.\n * @throws UnknownInputError on an unknown key.\n * @throws DuplicateInputError on an input given twice.\n * @throws UnitError on a unit that does not fit.\n * @internal\n */\nexport function resolveEvaluatorInputs(\n parameters: readonly EvaluatorParameter[],\n args: readonly string[],\n id?: string,\n): { inputs: Record<string, number>; resolved: ResolvedInput[] } {\n const inputs: Record<string, number> = {};\n const resolved: ResolvedInput[] = [];\n const known = parameters.flatMap((p) => [p.key, ...(p.alternates ?? []).map((a) => a.key)]);\n const parameterNames = new Set(parameters.map((p) => p.key));\n const siblings: NamedBindingSibling[] = args.map((arg) => {\n const [key, raw] = splitArg(arg);\n return { name: key, raw };\n });\n for (const arg of args) {\n const [key, raw] = splitArg(arg);\n const direct = parameters.find((p) => p.key === key);\n const viaAlt = parameters.find((p) => (p.alternates ?? []).some((a) => a.key === key));\n const viaName = direct === undefined && viaAlt === undefined ? resolveQuantityName(key, parameterNames) : null;\n const viaSynonym = viaName === null ? undefined : parameters.find((p) => p.key === viaName);\n const p = direct ?? viaAlt ?? viaSynonym;\n if (p === undefined) throw new UnknownInputError(id, key, known);\n const earlier = resolved.find((r) => r.key === p.key);\n const role = temperatureQuantityRole(p.quantity) === 'difference' ? 'difference' : temperatureQuantityRole(key);\n const c = convert(p, raw, role, siblings, key);\n const alt = direct === undefined && viaAlt !== undefined ? p.alternates!.find((a) => a.key === key)! : undefined;\n const value = alt === undefined ? c.value : c.value * alt.toKey;\n if (earlier !== undefined) {\n const earlierName = earlier.via ?? earlier.key;\n const group = synonymGroup(key);\n const synonymRepeat =\n group !== undefined && earlierName !== key && group.includes(earlierName) && group.includes(key);\n if (synonymRepeat && earlier.value === value) continue;\n if (synonymRepeat) {\n throw synonymDisagreement([earlierName, key], { [earlierName]: earlier.value, [key]: value })!;\n }\n throw new DuplicateInputError(id, p.key, [earlierName, key]);\n }\n inputs[p.key] = value;\n resolved.push({\n key: p.key,\n value,\n unit: p.unit,\n given: raw,\n ...(alt !== undefined || viaSynonym !== undefined ? { via: key } : {}),\n ...(alt !== undefined\n ? { note: `${key}=${raw.trim()} is ${alt.meaning}; ${p.key} = ${alt.toKey} × ${show(c.value)} = ${show(value)} ${p.unit}` }\n : c.note === undefined\n ? {}\n : { note: c.note }),\n });\n }\n return { inputs, resolved };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evaluator-inputs.js","sourceRoot":"","sources":["../../src/bridges/evaluator-inputs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,SAAS,EAA2B,MAAM,yBAAyB,CAAC;AACrH,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAA4B,MAAM,+BAA+B,CAAC;AAE3F,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAahF,+EAA+E;AAC/E,MAAM,IAAI,GAAG,cAAc,CAAC;AAE5B,+DAA+D;AAC/D,SAAS,SAAS,CAAC,KAAa;IAC9B,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC5D,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAoB,EAAE;IAC/C,MAAM,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;IACjC,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IACnF,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF,SAAS,OAAO,CACd,CAAqB,EACrB,GAAW,EACX,OAA2B,EAC3B,Q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AAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,GAAG,CAAC,GAAG,KAAK,SAAS;gBACnB,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC3H,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS;oBACpB,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;SACxB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * `key=value[unit]` arguments → an evaluator's numeric inputs, through the\n * evaluator's declared parameters.\n *\n * Every argument must name a declared input or a declared alternate: an\n * unrecognised key is refused rather than ignored, because an ignored\n * `radius_m=` beside a required `diameter_m` is exactly the silent mistake the\n * declarations exist to catch. A value may carry a unit; it is converted into\n * the declared unit only when the dimensions agree.\n *\n * @module bridges/evaluator-inputs\n */\nimport { splitAssignment } from '../core/assignment.js';\nimport { formatQuantity } from '../core/format.js';\nimport { affineReadingNote, unitConventionNotes, UnitError, type TemperatureReading } from '../dimensional/units.js';\nimport {\n resolveQuantityName,\n synonymGroup,\n synonymDisagreement,\n temperatureQuantityRole,\n} from '../dimensional/formula-names.js';\nimport { readNamedBinding, type NamedBindingSibling } from '../numerical/binding-value.js';\nimport type { EvaluatorParameter } from './evaluators.js';\nimport { DuplicateInputError, UnknownInputError } from './evaluation-errors.js';\n\n/** One input as it was given and as the evaluator receives it. @internal */\nexport interface ResolvedInput {\n readonly key: string;\n readonly value: number;\n readonly unit: string;\n readonly given: string;\n /** The alternate key it was given under, when it was. */\n readonly via?: string;\n readonly note?: string;\n}\n\n/** 15 significant digits in the note; the value itself is passed unrounded. */\nconst show = formatQuantity;\n\n/** Disclosures that a unit symbol does not carry by itself. */\nfunction unitAside(given: string): string {\n const notes = unitConventionNotes(given);\n return notes.length === 0 ? '' : ` — ${notes.join('; ')}`;\n}\n\nconst splitArg = (a: string): [string, string] => {\n const split = splitAssignment(a);\n if (split === null) throw new UnitError(`'${a}' must be key=value (e.g. d_m=1um)`);\n return [split.name, split.raw];\n};\n\nfunction convert(\n p: EvaluatorParameter,\n raw: string,\n reading: TemperatureReading,\n siblings: readonly NamedBindingSibling[],\n givenName: string,\n): { value: number; note?: string } {\n const read = readNamedBinding(givenName, raw, { reading, siblings, declaredUnit: p.unit });\n if (!read.dimensioned) return { value: read.value };\n // How an affine reading was applied comes from the unit table's own row (scale and ice point).\n const offset = read.affine === undefined ? '' : ` (${affineReadingNote(read.affine, reading)})`;\n // An angular input counts radians; a cycle-counting unit (the `cycles` flag on its row) takes 2π per cycle.\n const turns = p.angular === true ? read.cycles : 0;\n if (Number.isNaN(turns)) {\n throw new UnitError(`'${raw.trim()}' adds a cycle rate to a plain rate, so its radians per second are not defined`);\n }\n const value = turns === 0 ? read.value : read.value * (2 * Math.PI) ** turns;\n const turnsNote = turns === 0 ? '' : turns === 1 ? ' (cycles: × 2π)' : ` (cycles: × (2π)^${turns})`;\n const base = `${raw.trim()} → ${show(value)} ${p.unit || '(dimensionless)'}${offset}${turnsNote}${unitAside(raw)}`;\n return { value, note: read.temperatureNote === undefined ? base : `${base}. ${read.temperatureNote}` };\n}\n\n/**\n * Resolve `args` against `parameters`. `id` names the evaluated id in an input error.\n * @throws UnknownInputError on an unknown key.\n * @throws DuplicateInputError on an input given twice.\n * @throws UnitError on a unit that does not fit.\n * @internal\n */\nexport function resolveEvaluatorInputs(\n parameters: readonly EvaluatorParameter[],\n args: readonly string[],\n id?: string,\n): { inputs: Record<string, number>; resolved: ResolvedInput[] } {\n const inputs: Record<string, number> = {};\n const resolved: ResolvedInput[] = [];\n const known = parameters.flatMap((p) => [p.key, ...(p.alternates ?? []).map((a) => a.key)]);\n const parameterNames = new Set(parameters.map((p) => p.key));\n const siblings: NamedBindingSibling[] = args.map((arg) => {\n const [key, raw] = splitArg(arg);\n return { name: key, raw };\n });\n for (const arg of args) {\n const [key, raw] = splitArg(arg);\n const direct = parameters.find((p) => p.key === key);\n const viaAlt = parameters.find((p) => (p.alternates ?? []).some((a) => a.key === key));\n const viaName = direct === undefined && viaAlt === undefined ? resolveQuantityName(key, parameterNames) : null;\n const viaSynonym = viaName === null ? undefined : parameters.find((p) => p.key === viaName);\n const p = direct ?? viaAlt ?? viaSynonym;\n if (p === undefined) throw new UnknownInputError(id, key, known);\n const earlier = resolved.find((r) => r.key === p.key);\n const role = temperatureQuantityRole(p.quantity) === 'difference' ? 'difference' : temperatureQuantityRole(key);\n const c = convert(p, raw, role, siblings, key);\n const alt = direct === undefined && viaAlt !== undefined ? p.alternates!.find((a) => a.key === key)! : undefined;\n const value = alt === undefined ? c.value : c.value * alt.toKey;\n if (earlier !== undefined) {\n const earlierName = earlier.via ?? earlier.key;\n const group = synonymGroup(key);\n const synonymRepeat =\n group !== undefined && earlierName !== key && group.includes(earlierName) && group.includes(key);\n if (synonymRepeat && earlier.value === value) continue;\n if (synonymRepeat) {\n throw synonymDisagreement([earlierName, key], { [earlierName]: earlier.value, [key]: value })!;\n }\n throw new DuplicateInputError(id, p.key, [earlierName, key]);\n }\n inputs[p.key] = value;\n resolved.push({\n key: p.key,\n value,\n unit: p.unit,\n given: raw,\n ...(alt !== undefined || viaSynonym !== undefined ? { via: key } : {}),\n ...(alt !== undefined\n ? { note: `${key}=${raw.trim()} is ${alt.meaning}; ${p.key} = ${alt.toKey} × ${show(c.value)} = ${show(value)} ${p.unit}` }\n : c.note === undefined\n ? {}\n : { note: c.note }),\n });\n }\n return { inputs, resolved };\n}\n"]}
|
|
@@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E,CAc7D;AAsFD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,gBAAgB,GAAG,aAAa,CAKvE;AAuDD,uCAAuC;AACvC,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAEhE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOhE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACvC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIxB"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { FORMULA_NAMED } from '../dimensional/formula-names.js';
|
|
13
13
|
import { catalogEntries, catalogEntry, catalogEvaluators, primaryRelation } from './catalog-load.js';
|
|
14
14
|
import { evaluateFormula, formulaVariables, parseCatalogExpression, reservedFormulaNames } from './expr-parse.js';
|
|
15
|
-
import { evaluateCatalogRelation,
|
|
15
|
+
import { evaluateCatalogRelation, relationDomain } from './relation-eval.js';
|
|
16
16
|
import { DomainViolationError } from './evaluation-errors.js';
|
|
17
17
|
import { checkInputs, inputContract } from './input-contract.js';
|
|
18
18
|
function toParameter(row, optional) {
|
|
@@ -139,6 +139,22 @@ function bindRelationInputs(relation, parameters, inputs) {
|
|
|
139
139
|
}
|
|
140
140
|
return bound;
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* An optional positive parameter no source owns (so the relation's condition
|
|
144
|
+
* cannot read it) states its own condition: `key > 0` when it is given.
|
|
145
|
+
*/
|
|
146
|
+
function unsignedOptional(parameter, value) {
|
|
147
|
+
if (parameter.optional !== true || parameter.sign !== 'positive' || value === undefined || value > 0)
|
|
148
|
+
return [];
|
|
149
|
+
return [
|
|
150
|
+
{
|
|
151
|
+
condition: `${parameter.key} > 0`,
|
|
152
|
+
key: parameter.key,
|
|
153
|
+
value,
|
|
154
|
+
inputs: [{ key: parameter.key, quantity: parameter.quantity, value }],
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
}
|
|
142
158
|
/**
|
|
143
159
|
* The spec of one catalog evaluator row. A parameter that binds no relation
|
|
144
160
|
* source is read only by an extra output and is optional: the output is left
|
|
@@ -172,6 +188,10 @@ function buildSpec(catalogId, name, parameters, outputs) {
|
|
|
172
188
|
const outputScope = [...keys, 'value'];
|
|
173
189
|
// An output is computed when every parameter key it reads was given.
|
|
174
190
|
const reads = outputs.map((output) => formulaVariables(output.expression).filter((name) => keys.includes(name)));
|
|
191
|
+
const keyOfSource = new Map(parameters.flatMap((parameter) => {
|
|
192
|
+
const source = sourceOfParameter(relation, parameter);
|
|
193
|
+
return source === undefined ? [] : [[source, parameter.key]];
|
|
194
|
+
}));
|
|
175
195
|
return {
|
|
176
196
|
bridgeId: catalogId,
|
|
177
197
|
name,
|
|
@@ -182,19 +202,14 @@ function buildSpec(catalogId, name, parameters, outputs) {
|
|
|
182
202
|
run(inputs, want = 'all') {
|
|
183
203
|
const given = checkInputs(contract, inputs, want);
|
|
184
204
|
const bound = bindRelationInputs(relation, parameters, given);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
throw new DomainViolationError(`${relation.id}: ${parameter.key} must be > 0`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
205
|
+
const violated = [
|
|
206
|
+
...relationDomain(relation).violations(bound, (source) => keyOfSource.get(source) ?? source),
|
|
207
|
+
...parameters.flatMap((parameter) => unsignedOptional(parameter, given[parameter.key])),
|
|
208
|
+
];
|
|
209
|
+
if (violated.length > 0)
|
|
210
|
+
throw new DomainViolationError(relation.id, violated);
|
|
194
211
|
const value = evaluateCatalogRelation(relation, bound);
|
|
195
212
|
const result = { value };
|
|
196
|
-
if (want === 'value')
|
|
197
|
-
return result;
|
|
198
213
|
outputs.forEach((output, i) => {
|
|
199
214
|
if (reads[i].some((key) => given[key] === undefined))
|
|
200
215
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluators.js","sourceRoot":"","sources":["../../src/bridges/evaluators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAErG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAElH,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,aAAa,EAA2D,MAAM,qBAAqB,CAAC;AAkD1H,SAAS,WAAW,CAAC,GAA8B,EAAE,QAAiB;IACpE,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,GAAG,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,GAAG,CAAC,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GA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AC;IAC3E,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Closed-form evaluators projected from the catalog. `run` evaluates the\n * relation expression. It does not switch on a catalog id.\n *\n * `run` is the one evaluation of a catalog closed form: `evaluateRelation`,\n * the CLI and the uncertainty probes all call it. It checks the bindings\n * against the evaluator's {@link InputContract} before the validity domain,\n * so an absent input is a {@link MissingInputError}, never a domain failure.\n *\n * @module bridges/evaluators\n */\n\nimport { FORMULA_NAMED } from '../dimensional/formula-names.js';\nimport { catalogEntries, catalogEntry, catalogEvaluators, primaryRelation } from './catalog-load.js';\nimport type { CatalogEvaluator, CatalogEvaluatorOutput, CatalogEvaluatorParameter, CatalogRelation } from './catalog-types.js';\nimport { evaluateFormula, formulaVariables, parseCatalogExpression, reservedFormulaNames } from './expr-parse.js';\nimport type { ExprNode } from '../dimensional/ast-types.js';\nimport { evaluateCatalogRelation, relationHolds } from './relation-eval.js';\nimport { DomainViolationError } from './evaluation-errors.js';\nimport { checkInputs, inputContract, type EvaluationWant, type InputContract, type InputSlot } from './input-contract.js';\n\n/** How a length input is read: radius, diameter, separation, impact parameter, or semi-major axis. @public */\nexport type GeometryRole = 'radius' | 'diameter' | 'separation' | 'impact-parameter' | 'semi-major-axis';\n\n/** A second key that converts into the parameter's key. @public */\nexport interface ParameterAlternate {\n readonly key: string;\n readonly meaning: string;\n readonly toKey: number;\n}\n\n/** One named input of an evaluator. @public */\nexport interface EvaluatorParameter {\n readonly key: string;\n readonly quantity: string;\n readonly symbol: string;\n readonly unit: string;\n readonly meaning: string;\n readonly geometry?: GeometryRole;\n readonly temperature?: 'absolute';\n /** The sign this input must have; the catalog loader turns it into a validity clause. */\n readonly sign?: 'positive' | 'nonnegative' | 'any';\n /** An angular frequency in rad/s. A cycle unit (Hz, rpm) given to it is multiplied by 2π. */\n readonly angular?: true;\n readonly alternates?: readonly ParameterAlternate[];\n /** Derived: the parameter binds no relation source, so only an extra output reads it. */\n readonly optional?: true;\n}\n\n/** A callable bridge evaluator with its input contract. @public */\nexport interface EvaluatorSpec {\n readonly bridgeId: number;\n readonly name: string;\n readonly inputKeys: readonly string[];\n readonly parameters: readonly EvaluatorParameter[];\n /** Further numbers `run` returns beside `value`, keyed by `name`. */\n readonly outputs: readonly CatalogEvaluatorOutput[];\n /** Every spelling that binds an input, and which inputs are required. `run` checks it first. */\n readonly contract: InputContract;\n /**\n * Evaluate at `inputs`, keyed by parameter key, quantity, relation source,\n * alias or alternate. Throws `UnknownInputError`, `InputTypeError`,\n * `DuplicateInputError` or `MissingInputError` before any\n * `DomainViolationError`. With `want` `'value'` it returns `{ value }`\n * alone, and an input only an extra output reads is not required.\n */\n run(inputs: Readonly<Record<string, number>>, want?: EvaluationWant): Record<string, number>;\n}\n\nfunction toParameter(row: CatalogEvaluatorParameter, optional: boolean): EvaluatorParameter {\n return {\n key: row.key,\n quantity: row.quantity,\n symbol: row.symbol,\n unit: row.unit,\n meaning: row.meaning,\n ...(row.geometry !== undefined ? { geometry: row.geometry } : {}),\n ...(row.temperature !== undefined ? { temperature: row.temperature } : {}),\n ...(row.sign !== undefined ? { sign: row.sign } : {}),\n ...(row.angular === true ? { angular: true as const } : {}),\n ...(row.alternates !== undefined ? { alternates: row.alternates } : {}),\n ...(optional ? { optional: true as const } : {}),\n };\n}\n\nconst NAMED_DEFAULT = new Map(FORMULA_NAMED.map((named) => [named.name, named.value]));\n\n/** The relation source a parameter is the input for, or undefined when it owns none. */\nfunction sourceOfParameter(relation: CatalogRelation, parameter: Pick<EvaluatorParameter, 'key' | 'quantity'>): string | undefined {\n for (const source of relation.sources) {\n if (source === parameter.key || (relation.aliases[source] ?? []).includes(parameter.key)) return source;\n }\n return relation.sources.includes(parameter.quantity) ? parameter.quantity : undefined;\n}\n\n/** Every symbol name in an expression tree. */\nfunction symbolNames(node: ExprNode): string[] {\n if (node.kind === 'symbol') return [node.name];\n if (node.kind === 'op') return node.args.flatMap(symbolNames);\n if (node.kind === 'abs' || node.kind === 'transcendental') return symbolNames(node.arg);\n return [];\n}\n\n/**\n * Keys of the parameters whose source does not appear in the relation's\n * expression. They are checked against the validity domain and do not change\n * the value, so a caller who varies one sees no effect.\n */\nexport function unusedInputKeys(spec: EvaluatorSpec): string[] {\n const relation = primaryRelation(spec.bridgeId);\n if (relation === undefined) return [];\n const used = new Set(symbolNames(parseCatalogExpression(relation.expression)));\n // An output reads the scope names its parsed expression names, the same parse `run` evaluates.\n const outputReads = new Set(spec.outputs.flatMap((output) => formulaVariables(output.expression)));\n const readByOutput = (key: string): boolean => outputReads.has(key.replaceAll('-', '_'));\n return spec.parameters\n .filter((parameter) => {\n const source = sourceOfParameter(relation, parameter);\n // A parameter that owns no relation source is read only by an extra output.\n return (source === undefined || !used.has(source)) && !readByOutput(parameter.key);\n })\n .map((parameter) => parameter.key);\n}\n\n/**\n * The declared inputs of a catalog evaluator: one slot per parameter, spelled\n * by its key, its relation source and that source's aliases, and its quantity\n * when no other slot shares it; then one optional, unlisted slot per relation\n * source no parameter owns, which a named constant fills when not given.\n * Building it throws when one spelling would bind two slots.\n */\nfunction evaluatorContract(catalogId: number, relation: CatalogRelation, parameters: readonly EvaluatorParameter[]): InputContract {\n const quantityCount = new Map<string, number>();\n for (const p of parameters) quantityCount.set(p.quantity, (quantityCount.get(p.quantity) ?? 0) + 1);\n const owned = new Set<string>();\n const slots: InputSlot[] = parameters.map((p) => {\n const source = sourceOfParameter(relation, p);\n if (source !== undefined) owned.add(source);\n const spellings = [\n p.key,\n ...(source === undefined ? [] : [source, ...(relation.aliases[source] ?? [])]),\n ...(quantityCount.get(p.quantity) === 1 ? [p.quantity] : []),\n ];\n return {\n key: p.key,\n spellings: [...new Set(spellings)],\n alternates: (p.alternates ?? []).map((alt) => ({ key: alt.key, toKey: alt.toKey })),\n optional: p.optional === true,\n readBy: source === undefined ? ('outputs' as const) : ('value' as const),\n listed: true,\n };\n });\n for (const source of relation.sources) {\n if (owned.has(source)) continue;\n slots.push({\n key: source,\n spellings: [source, ...(relation.aliases[source] ?? [])],\n alternates: [],\n optional: NAMED_DEFAULT.has(source.replaceAll('-', '_')),\n readBy: 'value',\n listed: false,\n });\n }\n return inputContract(`be-${catalogId}`, slots);\n}\n\n/**\n * Checked inputs (keyed by slot key) onto catalog source names. A source no\n * parameter owns takes its given value, else its named constant.\n */\nfunction bindRelationInputs(\n relation: CatalogRelation,\n parameters: readonly EvaluatorParameter[],\n inputs: Readonly<Record<string, number>>,\n): Record<string, number> {\n const bound: Record<string, number> = {};\n const owned = new Set<string>();\n for (const parameter of parameters) {\n const source = sourceOfParameter(relation, parameter);\n if (source === undefined) continue;\n owned.add(source);\n const value = inputs[parameter.key];\n if (value !== undefined) bound[source] = value;\n }\n for (const source of relation.sources) {\n if (owned.has(source)) continue;\n const value = inputs[source] ?? NAMED_DEFAULT.get(source.replaceAll('-', '_'));\n if (value !== undefined) bound[source] = value;\n }\n return bound;\n}\n\n/**\n * The spec of one catalog evaluator row. A parameter that binds no relation\n * source is read only by an extra output and is optional: the output is left\n * out when it is not given. An output expression reads the scope by\n * parameter key, so a key that names a registered constant (be-66's\n * reflectance `R`) may bind the relation's source but may not be read by an\n * output: building the spec refuses it.\n * @internal\n */\nexport function buildEvaluatorSpec(row: CatalogEvaluator): EvaluatorSpec {\n const relation = primaryRelation(row.catalogId);\n if (relation === undefined) throw new Error(missingEvaluatorMessage(row.catalogId));\n const parameters = row.parameters.map((p) => toParameter(p, sourceOfParameter(relation, p) === undefined));\n return buildSpec(row.catalogId, row.name, parameters, row.outputs ?? []);\n}\n\nfunction buildSpec(\n catalogId: number,\n name: string,\n parameters: readonly EvaluatorParameter[],\n outputs: readonly CatalogEvaluatorOutput[],\n): EvaluatorSpec {\n const relation = primaryRelation(catalogId);\n if (relation === undefined) throw new Error(missingEvaluatorMessage(catalogId));\n const contract = evaluatorContract(catalogId, relation, parameters);\n const keys = parameters.map((parameter) => parameter.key);\n const reserved = reservedFormulaNames();\n for (const output of outputs) {\n const shadowed = formulaVariables(output.expression).find((name) => reserved.has(name) && keys.includes(name));\n if (shadowed !== undefined) {\n throw new Error(`be-${catalogId}: output '${output.name}' reads '${shadowed}', which names a registered constant`);\n }\n }\n // An output reads the parameter keys and `value`; a key that shadows a constant is refused above.\n const outputScope = [...keys, 'value'];\n // An output is computed when every parameter key it reads was given.\n const reads = outputs.map((output) => formulaVariables(output.expression).filter((name) => keys.includes(name)));\n return {\n bridgeId: catalogId,\n name,\n inputKeys: parameters.filter((parameter) => parameter.optional !== true).map((parameter) => parameter.key),\n parameters,\n outputs,\n contract,\n run(inputs, want = 'all') {\n const given = checkInputs(contract, inputs, want);\n const bound = bindRelationInputs(relation, parameters, given);\n if (!relationHolds(relation, bound)) {\n throw new DomainViolationError(`${relation.id}: inputs violate validity domain (${relation.domain})`);\n }\n for (const parameter of parameters) {\n const value = given[parameter.key];\n if (parameter.optional === true && parameter.sign === 'positive' && value !== undefined && !(value > 0)) {\n throw new DomainViolationError(`${relation.id}: ${parameter.key} must be > 0`);\n }\n }\n const value = evaluateCatalogRelation(relation, bound);\n const result: Record<string, number> = { value };\n if (want === 'value') return result;\n outputs.forEach((output, i) => {\n if (reads[i]!.some((key) => given[key] === undefined)) return;\n result[output.name] = evaluateFormula(output.expression, { ...given, value }, outputScope);\n });\n return result;\n },\n };\n}\n\n/** Bridge id → evaluator. @internal */\nexport const BRIDGE_EVALUATORS: ReadonlyMap<number, EvaluatorSpec> = new Map(\n catalogEvaluators().map((row) => [row.catalogId, buildEvaluatorSpec(row)] as const),\n);\n\n/**\n * What to say when an id is not in {@link BRIDGE_EVALUATORS}: an id outside\n * the catalog and a catalog row with no evaluator are two different facts.\n * @internal\n */\nexport function missingEvaluatorMessage(bridgeId: number): string {\n const entry = catalogEntry(bridgeId);\n if (entry === undefined) {\n const ids = catalogEntries().map((e) => e.id);\n return `be-${bridgeId} is not a catalog id (the catalog holds be-${Math.min(...ids)} to be-${Math.max(...ids)})`;\n }\n return `be-${bridgeId} (${entry.name}) has no evaluator; \\`upt atlas be-${bridgeId}\\` prints its record, and \\`upt evaluate\\` with no id lists the evaluable ids`;\n}\n\n/**\n * Evaluate a catalog id with a numeric input record: the evaluator's `run`,\n * which checks the inputs first. Throws on an unknown id.\n *\n * @internal\n */\nexport function evaluateBridge(\n bridgeId: number,\n inputs: Readonly<Record<string, number>>,\n): Record<string, number> {\n const spec = BRIDGE_EVALUATORS.get(bridgeId);\n if (spec === undefined) throw new Error(missingEvaluatorMessage(bridgeId));\n return spec.run(inputs);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evaluators.js","sourceRoot":"","sources":["../../src/bridges/evaluators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAErG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAElH,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAwB,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,aAAa,EAA2D,MAAM,qBAAqB,CAAC;AAkD1H,SAAS,WAAW,CAAC,GAA8B,EAAE,QAAiB;IACpE,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,GAAG,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,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EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAU,CAAC,CACpF,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAgB;IACtD,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IACrC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9C,OAAO,MAAM,QAAQ,8CAA8C,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC;IACnH,CAAC;IACD,OAAO,MAAM,QAAQ,KAAK,KAAK,CAAC,IAAI,sCAAsC,QAAQ,+EAA+E,CAAC;AACpK,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAgB,EAChB,MAAwC;IAExC,MAAM,IAAI,GAAG,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,IAAI,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3E,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Closed-form evaluators projected from the catalog. `run` evaluates the\n * relation expression. It does not switch on a catalog id.\n *\n * `run` is the one evaluation of a catalog closed form: `evaluateRelation`,\n * the CLI and the uncertainty probes all call it. It checks the bindings\n * against the evaluator's {@link InputContract} before the validity domain,\n * so an absent input is a {@link MissingInputError}, never a domain failure.\n *\n * @module bridges/evaluators\n */\n\nimport { FORMULA_NAMED } from '../dimensional/formula-names.js';\nimport { catalogEntries, catalogEntry, catalogEvaluators, primaryRelation } from './catalog-load.js';\nimport type { CatalogEvaluator, CatalogEvaluatorOutput, CatalogEvaluatorParameter, CatalogRelation } from './catalog-types.js';\nimport { evaluateFormula, formulaVariables, parseCatalogExpression, reservedFormulaNames } from './expr-parse.js';\nimport type { ExprNode } from '../dimensional/ast-types.js';\nimport { evaluateCatalogRelation, relationDomain } from './relation-eval.js';\nimport { DomainViolationError, type DomainViolation } from './evaluation-errors.js';\nimport { checkInputs, inputContract, type EvaluationWant, type InputContract, type InputSlot } from './input-contract.js';\n\n/** How a length input is read: radius, diameter, separation, impact parameter, or semi-major axis. @public */\nexport type GeometryRole = 'radius' | 'diameter' | 'separation' | 'impact-parameter' | 'semi-major-axis';\n\n/** A second key that converts into the parameter's key. @public */\nexport interface ParameterAlternate {\n readonly key: string;\n readonly meaning: string;\n readonly toKey: number;\n}\n\n/** One named input of an evaluator. @public */\nexport interface EvaluatorParameter {\n readonly key: string;\n readonly quantity: string;\n readonly symbol: string;\n readonly unit: string;\n readonly meaning: string;\n readonly geometry?: GeometryRole;\n readonly temperature?: 'absolute';\n /** The sign this input must have; the catalog loader turns it into a validity clause. */\n readonly sign?: 'positive' | 'nonnegative' | 'any';\n /** An angular frequency in rad/s. A cycle unit (Hz, rpm) given to it is multiplied by 2π. */\n readonly angular?: true;\n readonly alternates?: readonly ParameterAlternate[];\n /** Derived: the parameter binds no relation source, so only an extra output reads it. */\n readonly optional?: true;\n}\n\n/** A callable bridge evaluator with its input contract. @public */\nexport interface EvaluatorSpec {\n readonly bridgeId: number;\n readonly name: string;\n readonly inputKeys: readonly string[];\n readonly parameters: readonly EvaluatorParameter[];\n /** Further numbers `run` returns beside `value`, keyed by `name`. */\n readonly outputs: readonly CatalogEvaluatorOutput[];\n /** Every spelling that binds an input, and which inputs are required. `run` checks it first. */\n readonly contract: InputContract;\n /**\n * Evaluate at `inputs`, keyed by parameter key, quantity, relation source,\n * alias or alternate. Throws `UnknownInputError`, `InputTypeError`,\n * `DuplicateInputError` or `MissingInputError` before any\n * `DomainViolationError`. With `want` `'value'` it returns `{ value }`\n * alone, and an input only an extra output reads is not required.\n */\n run(inputs: Readonly<Record<string, number>>, want?: EvaluationWant): Record<string, number>;\n}\n\nfunction toParameter(row: CatalogEvaluatorParameter, optional: boolean): EvaluatorParameter {\n return {\n key: row.key,\n quantity: row.quantity,\n symbol: row.symbol,\n unit: row.unit,\n meaning: row.meaning,\n ...(row.geometry !== undefined ? { geometry: row.geometry } : {}),\n ...(row.temperature !== undefined ? { temperature: row.temperature } : {}),\n ...(row.sign !== undefined ? { sign: row.sign } : {}),\n ...(row.angular === true ? { angular: true as const } : {}),\n ...(row.alternates !== undefined ? { alternates: row.alternates } : {}),\n ...(optional ? { optional: true as const } : {}),\n };\n}\n\nconst NAMED_DEFAULT = new Map(FORMULA_NAMED.map((named) => [named.name, named.value]));\n\n/** The relation source a parameter is the input for, or undefined when it owns none. */\nfunction sourceOfParameter(relation: CatalogRelation, parameter: Pick<EvaluatorParameter, 'key' | 'quantity'>): string | undefined {\n for (const source of relation.sources) {\n if (source === parameter.key || (relation.aliases[source] ?? []).includes(parameter.key)) return source;\n }\n return relation.sources.includes(parameter.quantity) ? parameter.quantity : undefined;\n}\n\n/** Every symbol name in an expression tree. */\nfunction symbolNames(node: ExprNode): string[] {\n if (node.kind === 'symbol') return [node.name];\n if (node.kind === 'op') return node.args.flatMap(symbolNames);\n if (node.kind === 'abs' || node.kind === 'transcendental') return symbolNames(node.arg);\n return [];\n}\n\n/**\n * Keys of the parameters whose source does not appear in the relation's\n * expression. They are checked against the validity domain and do not change\n * the value, so a caller who varies one sees no effect.\n */\nexport function unusedInputKeys(spec: EvaluatorSpec): string[] {\n const relation = primaryRelation(spec.bridgeId);\n if (relation === undefined) return [];\n const used = new Set(symbolNames(parseCatalogExpression(relation.expression)));\n // An output reads the scope names its parsed expression names, the same parse `run` evaluates.\n const outputReads = new Set(spec.outputs.flatMap((output) => formulaVariables(output.expression)));\n const readByOutput = (key: string): boolean => outputReads.has(key.replaceAll('-', '_'));\n return spec.parameters\n .filter((parameter) => {\n const source = sourceOfParameter(relation, parameter);\n // A parameter that owns no relation source is read only by an extra output.\n return (source === undefined || !used.has(source)) && !readByOutput(parameter.key);\n })\n .map((parameter) => parameter.key);\n}\n\n/**\n * The declared inputs of a catalog evaluator: one slot per parameter, spelled\n * by its key, its relation source and that source's aliases, and its quantity\n * when no other slot shares it; then one optional, unlisted slot per relation\n * source no parameter owns, which a named constant fills when not given.\n * Building it throws when one spelling would bind two slots.\n */\nfunction evaluatorContract(catalogId: number, relation: CatalogRelation, parameters: readonly EvaluatorParameter[]): InputContract {\n const quantityCount = new Map<string, number>();\n for (const p of parameters) quantityCount.set(p.quantity, (quantityCount.get(p.quantity) ?? 0) + 1);\n const owned = new Set<string>();\n const slots: InputSlot[] = parameters.map((p) => {\n const source = sourceOfParameter(relation, p);\n if (source !== undefined) owned.add(source);\n const spellings = [\n p.key,\n ...(source === undefined ? [] : [source, ...(relation.aliases[source] ?? [])]),\n ...(quantityCount.get(p.quantity) === 1 ? [p.quantity] : []),\n ];\n return {\n key: p.key,\n spellings: [...new Set(spellings)],\n alternates: (p.alternates ?? []).map((alt) => ({ key: alt.key, toKey: alt.toKey })),\n optional: p.optional === true,\n readBy: source === undefined ? ('outputs' as const) : ('value' as const),\n listed: true,\n };\n });\n for (const source of relation.sources) {\n if (owned.has(source)) continue;\n slots.push({\n key: source,\n spellings: [source, ...(relation.aliases[source] ?? [])],\n alternates: [],\n optional: NAMED_DEFAULT.has(source.replaceAll('-', '_')),\n readBy: 'value',\n listed: false,\n });\n }\n return inputContract(`be-${catalogId}`, slots);\n}\n\n/**\n * Checked inputs (keyed by slot key) onto catalog source names. A source no\n * parameter owns takes its given value, else its named constant.\n */\nfunction bindRelationInputs(\n relation: CatalogRelation,\n parameters: readonly EvaluatorParameter[],\n inputs: Readonly<Record<string, number>>,\n): Record<string, number> {\n const bound: Record<string, number> = {};\n const owned = new Set<string>();\n for (const parameter of parameters) {\n const source = sourceOfParameter(relation, parameter);\n if (source === undefined) continue;\n owned.add(source);\n const value = inputs[parameter.key];\n if (value !== undefined) bound[source] = value;\n }\n for (const source of relation.sources) {\n if (owned.has(source)) continue;\n const value = inputs[source] ?? NAMED_DEFAULT.get(source.replaceAll('-', '_'));\n if (value !== undefined) bound[source] = value;\n }\n return bound;\n}\n\n/**\n * An optional positive parameter no source owns (so the relation's condition\n * cannot read it) states its own condition: `key > 0` when it is given.\n */\nfunction unsignedOptional(parameter: EvaluatorParameter, value: number | undefined): DomainViolation[] {\n if (parameter.optional !== true || parameter.sign !== 'positive' || value === undefined || value > 0) return [];\n return [\n {\n condition: `${parameter.key} > 0`,\n key: parameter.key,\n value,\n inputs: [{ key: parameter.key, quantity: parameter.quantity, value }],\n },\n ];\n}\n\n/**\n * The spec of one catalog evaluator row. A parameter that binds no relation\n * source is read only by an extra output and is optional: the output is left\n * out when it is not given. An output expression reads the scope by\n * parameter key, so a key that names a registered constant (be-66's\n * reflectance `R`) may bind the relation's source but may not be read by an\n * output: building the spec refuses it.\n * @internal\n */\nexport function buildEvaluatorSpec(row: CatalogEvaluator): EvaluatorSpec {\n const relation = primaryRelation(row.catalogId);\n if (relation === undefined) throw new Error(missingEvaluatorMessage(row.catalogId));\n const parameters = row.parameters.map((p) => toParameter(p, sourceOfParameter(relation, p) === undefined));\n return buildSpec(row.catalogId, row.name, parameters, row.outputs ?? []);\n}\n\nfunction buildSpec(\n catalogId: number,\n name: string,\n parameters: readonly EvaluatorParameter[],\n outputs: readonly CatalogEvaluatorOutput[],\n): EvaluatorSpec {\n const relation = primaryRelation(catalogId);\n if (relation === undefined) throw new Error(missingEvaluatorMessage(catalogId));\n const contract = evaluatorContract(catalogId, relation, parameters);\n const keys = parameters.map((parameter) => parameter.key);\n const reserved = reservedFormulaNames();\n for (const output of outputs) {\n const shadowed = formulaVariables(output.expression).find((name) => reserved.has(name) && keys.includes(name));\n if (shadowed !== undefined) {\n throw new Error(`be-${catalogId}: output '${output.name}' reads '${shadowed}', which names a registered constant`);\n }\n }\n // An output reads the parameter keys and `value`; a key that shadows a constant is refused above.\n const outputScope = [...keys, 'value'];\n // An output is computed when every parameter key it reads was given.\n const reads = outputs.map((output) => formulaVariables(output.expression).filter((name) => keys.includes(name)));\n const keyOfSource = new Map(\n parameters.flatMap((parameter) => {\n const source = sourceOfParameter(relation, parameter);\n return source === undefined ? [] : [[source, parameter.key] as const];\n }),\n );\n return {\n bridgeId: catalogId,\n name,\n inputKeys: parameters.filter((parameter) => parameter.optional !== true).map((parameter) => parameter.key),\n parameters,\n outputs,\n contract,\n run(inputs, want = 'all') {\n const given = checkInputs(contract, inputs, want);\n const bound = bindRelationInputs(relation, parameters, given);\n const violated = [\n ...relationDomain(relation).violations(bound, (source) => keyOfSource.get(source) ?? source),\n ...parameters.flatMap((parameter) => unsignedOptional(parameter, given[parameter.key])),\n ];\n if (violated.length > 0) throw new DomainViolationError(relation.id, violated);\n const value = evaluateCatalogRelation(relation, bound);\n const result: Record<string, number> = { value };\n outputs.forEach((output, i) => {\n if (reads[i]!.some((key) => given[key] === undefined)) return;\n result[output.name] = evaluateFormula(output.expression, { ...given, value }, outputScope);\n });\n return result;\n },\n };\n}\n\n/** Bridge id → evaluator. @internal */\nexport const BRIDGE_EVALUATORS: ReadonlyMap<number, EvaluatorSpec> = new Map(\n catalogEvaluators().map((row) => [row.catalogId, buildEvaluatorSpec(row)] as const),\n);\n\n/**\n * What to say when an id is not in {@link BRIDGE_EVALUATORS}: an id outside\n * the catalog and a catalog row with no evaluator are two different facts.\n * @internal\n */\nexport function missingEvaluatorMessage(bridgeId: number): string {\n const entry = catalogEntry(bridgeId);\n if (entry === undefined) {\n const ids = catalogEntries().map((e) => e.id);\n return `be-${bridgeId} is not a catalog id (the catalog holds be-${Math.min(...ids)} to be-${Math.max(...ids)})`;\n }\n return `be-${bridgeId} (${entry.name}) has no evaluator; \\`upt atlas be-${bridgeId}\\` prints its record, and \\`upt evaluate\\` with no id lists the evaluable ids`;\n}\n\n/**\n * Evaluate a catalog id with a numeric input record: the evaluator's `run`,\n * which checks the inputs first. Throws on an unknown id.\n *\n * @internal\n */\nexport function evaluateBridge(\n bridgeId: number,\n inputs: Readonly<Record<string, number>>,\n): Record<string, number> {\n const spec = BRIDGE_EVALUATORS.get(bridgeId);\n if (spec === undefined) throw new Error(missingEvaluatorMessage(bridgeId));\n return spec.run(inputs);\n}\n"]}
|
|
@@ -29,6 +29,17 @@ export declare function formulaScope(inputs?: Readonly<Record<string, number>>,
|
|
|
29
29
|
* quantity written with underscores.
|
|
30
30
|
*/
|
|
31
31
|
export declare function formulaVariables(expression: string): readonly string[];
|
|
32
|
+
/**
|
|
33
|
+
* The names a catalog expression mentions, each hyphenated quantity or
|
|
34
|
+
* constant spelling rewritten to its one token first (`truncation-coefficient-b`
|
|
35
|
+
* is `truncation_coefficient_b`, not `b`), π included (MathTS does not list it
|
|
36
|
+
* as a variable). Cached per expression text. `reduced-planck-constant` is
|
|
37
|
+
* `hbar`: the rewrite takes the longest spelling at each segment, so the
|
|
38
|
+
* declared `planck-constant` inside it does not win. The one identifier
|
|
39
|
+
* walk: the notices reader and the condition interpreter read it too.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export declare function expressionNames(expression: string): ReadonlySet<string>;
|
|
32
43
|
/**
|
|
33
44
|
* `inputs` without the reserved keys that `reads` does not name. A reserved
|
|
34
45
|
* key the formula reads and `declared` does not name is refused: the caller's
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expr-parse.d.ts","sourceRoot":"","sources":["../../src/bridges/expr-parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAoB,MAAM,6BAA6B,CAAC;AAgC9E,gFAAgF;AAChF,wBAAgB,YAAY,IAAI,WAAW,CAAC,MAAM,CAAC,CAMlD;AAID,yFAAyF;AACzF,wBAAgB,oBAAoB,IAAI,WAAW,CAAC,MAAM,CAAC,CAE1D;AAID;;;;;;;GAOG;AACH,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;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACxC,QAAQ,GAAE,SAAS,MAAM,EAAO,GAC/B,MAAM,CAUR;AA8FD,mGAAmG;AACnG,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAGnE"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @module bridges/expr-parse
|
|
11
11
|
*/
|
|
12
12
|
import { DIMENSIONLESS } from '../dimensional/types.js';
|
|
13
|
-
import { CONSTANTS } from '../dimensional/symbolic-constants.js';
|
|
13
|
+
import { CONSTANTS, isRegisteredConstant } from '../dimensional/symbolic-constants.js';
|
|
14
14
|
import { FORMULA_NAMED } from '../dimensional/formula-names.js';
|
|
15
15
|
import { rewriteCatalogHyphens } from '../dimensional/hyphen-names.js';
|
|
16
16
|
import { allQuantityRecords } from '../dimensional/quantity-registry.js';
|
|
@@ -86,8 +86,17 @@ export function formulaVariables(expression) {
|
|
|
86
86
|
}
|
|
87
87
|
const VARIABLES = new Map();
|
|
88
88
|
const IDENTIFIER = /[A-Za-z_][A-Za-z0-9_]*/g;
|
|
89
|
-
/**
|
|
90
|
-
|
|
89
|
+
/**
|
|
90
|
+
* The names a catalog expression mentions, each hyphenated quantity or
|
|
91
|
+
* constant spelling rewritten to its one token first (`truncation-coefficient-b`
|
|
92
|
+
* is `truncation_coefficient_b`, not `b`), π included (MathTS does not list it
|
|
93
|
+
* as a variable). Cached per expression text. `reduced-planck-constant` is
|
|
94
|
+
* `hbar`: the rewrite takes the longest spelling at each segment, so the
|
|
95
|
+
* declared `planck-constant` inside it does not win. The one identifier
|
|
96
|
+
* walk: the notices reader and the condition interpreter read it too.
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
export function expressionNames(expression) {
|
|
91
100
|
let names = VARIABLES.get(expression);
|
|
92
101
|
if (names === undefined) {
|
|
93
102
|
names = new Set(rewriteCatalogHyphens(expression, formulaNames()).match(IDENTIFIER) ?? []);
|
|
@@ -131,7 +140,7 @@ export function evaluateFormula(expression, inputs, declared = []) {
|
|
|
131
140
|
GRAMMAR_CHECKED.add(expression);
|
|
132
141
|
}
|
|
133
142
|
const rewritten = rewriteCatalogHyphens(expression, formulaNames());
|
|
134
|
-
const scope = formulaScope(withoutUnreadConstants(inputs,
|
|
143
|
+
const scope = formulaScope(withoutUnreadConstants(inputs, expressionNames(expression), declared), declared);
|
|
135
144
|
return parseFormula(rewritten).evaluate(scope);
|
|
136
145
|
}
|
|
137
146
|
const GRAMMAR_CHECKED = new Set();
|
|
@@ -223,7 +232,7 @@ function foldKnownConstants(node) {
|
|
|
223
232
|
right.name === 'pi' &&
|
|
224
233
|
left.kind === 'symbol' &&
|
|
225
234
|
/^(?:2|4|8)$/.test(left.name) &&
|
|
226
|
-
`${left.name}pi`
|
|
235
|
+
isRegisteredConstant(`${left.name}pi`)) {
|
|
227
236
|
merged.push(symbol(`${left.name}pi`));
|
|
228
237
|
i += 1;
|
|
229
238
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expr-parse.js","sourceRoot":"","sources":["../../src/bridges/expr-parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAkB,MAAM,yBAAyB,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAqB,MAAM,mCAAmC,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBA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Content":["/**\n * One expression parser for a catalog formula: MathTS.\n *\n * Numeric evaluation is MathTS `parseFormula` on the hyphen-rewritten string,\n * and the dimensional `ExprNode` is built from the MathTS parse tree of the\n * same string, so the number and the tree can never disagree on precedence.\n * The `ExprNode` keeps hyphenated quantity names and unary minus, so symbolic\n * composition and dimensional checks see the same formula.\n *\n * @module bridges/expr-parse\n */\n\nimport { DIMENSIONLESS, type Dimension } from '../dimensional/types.js';\nimport type { ExprNode, TranscendentalFn } from '../dimensional/ast-types.js';\nimport { CONSTANTS } from '../dimensional/symbolic-constants.js';\nimport { FORMULA_NAMED } from '../dimensional/formula-names.js';\nimport { rewriteCatalogHyphens } from '../dimensional/hyphen-names.js';\nimport { allQuantityRecords } from '../dimensional/quantity-registry.js';\nimport { parseFormula } from '../numerical/formula-mathts.js';\nimport { parseFormulaPNode, type FormulaPNode } from '../numerical/formula-dimension.js';\nimport { ConstantInputError } from './evaluation-errors.js';\n\nconst TRANSCENDENTAL = new Set<TranscendentalFn>([\n 'exp', 'ln', 'log2', 'log10', 'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh',\n]);\n\nconst quantityNames = new Set(allQuantityRecords().map((row) => row.id));\n\nconst DIM_BY_NAME = new Map<string, Dimension>();\nfor (const row of allQuantityRecords()) DIM_BY_NAME.set(row.id, row.dimension);\nfor (const [name, constant] of Object.entries(CONSTANTS)) DIM_BY_NAME.set(name, constant.dim);\nfor (const named of FORMULA_NAMED) DIM_BY_NAME.set(named.name, named.dim);\n\nfunction dimOf(name: string): Dimension {\n return DIM_BY_NAME.get(name) ?? DIMENSIONLESS;\n}\n\nfunction symbol(name: string): ExprNode {\n return { kind: 'symbol', name, dim: dimOf(name) };\n}\n\nfunction numberSymbol(text: string): ExprNode {\n return { kind: 'symbol', name: text, dim: DIMENSIONLESS };\n}\n\n/** Names a formula may mention: quantities, constants, and formula overlays. */\nexport function formulaNames(): ReadonlySet<string> {\n const names = new Set<string>(quantityNames);\n for (const name of Object.keys(CONSTANTS)) names.add(name);\n for (const named of FORMULA_NAMED) names.add(named.name);\n names.add('pi');\n return names;\n}\n\nconst RESERVED = new Set<string>(['pi', ...Object.keys(CONSTANTS), ...FORMULA_NAMED.map((named) => named.name)]);\n\n/** π, the registered constants and the formula overlays: names a caller may not bind. */\nexport function reservedFormulaNames(): ReadonlySet<string> {\n return RESERVED;\n}\n\nconst underscored = (name: string): string => name.replace(/-/g, '_');\n\n/**\n * Numeric scope: constants, formula overlays, and π, then the caller's inputs.\n * An input whose name is reserved is refused with {@link ConstantInputError}\n * unless `declared` names it: a relation's own source may carry a constant's\n * name as a default the caller overrides (be-63's Lane-Emden ω₃).\n * {@link evaluateFormula} first drops a reserved key its expression does not\n * read; this builder refuses every undeclared one.\n */\nexport function formulaScope(\n inputs: Readonly<Record<string, number>> = {},\n declared: readonly string[] = [],\n): Record<string, number> {\n const scope: Record<string, number> = { pi: Math.PI };\n for (const [name, constant] of Object.entries(CONSTANTS)) scope[name] = constant.value;\n for (const named of FORMULA_NAMED) scope[named.name] = named.value;\n const allowed = new Set(declared.map(underscored));\n for (const [key, value] of Object.entries(inputs)) {\n const name = underscored(key);\n if (RESERVED.has(name) && !allowed.has(name)) throw new ConstantInputError(key);\n scope[name] = value;\n }\n return scope;\n}\n\n/**\n * The free variables of a catalog expression, read from the same MathTS parse\n * {@link evaluateFormula} evaluates: the scope names it reads, a hyphenated\n * quantity written with underscores.\n */\nexport function formulaVariables(expression: string): readonly string[] {\n return parseFormula(rewriteCatalogHyphens(expression, formulaNames())).variables;\n}\n\nconst VARIABLES = new Map<string, ReadonlySet<string>>();\n\nconst IDENTIFIER = /[A-Za-z_][A-Za-z0-9_]*/g;\n\n/** The names an expression mentions (π included, which MathTS does not list as a variable), cached per expression text. */\nfunction readNames(expression: string): ReadonlySet<string> {\n let names = VARIABLES.get(expression);\n if (names === undefined) {\n names = new Set(rewriteCatalogHyphens(expression, formulaNames()).match(IDENTIFIER) ?? []);\n VARIABLES.set(expression, names);\n }\n return names;\n}\n\n/**\n * `inputs` without the reserved keys that `reads` does not name. A reserved\n * key the formula reads and `declared` does not name is refused: the caller's\n * number would replace the constant. One the formula does not read is not an\n * input of this formula; it is dropped, as any other extra key is on the\n * graph path (a composed edge forwards every input to each component).\n */\nexport function withoutUnreadConstants(\n inputs: Readonly<Record<string, number>>,\n reads: ReadonlySet<string>,\n declared: readonly string[],\n): Record<string, number> {\n const allowed = new Set(declared.map(underscored));\n const kept: Record<string, number> = {};\n for (const [key, value] of Object.entries(inputs)) {\n const name = underscored(key);\n if (RESERVED.has(name) && !allowed.has(name)) {\n if (reads.has(name)) throw new ConstantInputError(key);\n continue;\n }\n kept[key] = value;\n }\n return kept;\n}\n\n/**\n * Evaluate a catalog expression with MathTS. Inputs are quantity names.\n * `declared` are the names the caller may bind although they are reserved\n * (the relation's sources); a reserved key the expression reads and\n * `declared` does not name is a {@link ConstantInputError}, and one it does\n * not read is dropped ({@link withoutUnreadConstants}).\n */\nexport function evaluateFormula(\n expression: string,\n inputs: Readonly<Record<string, number>>,\n declared: readonly string[] = [],\n): number {\n // One grammar: the expression must also build a dimensional tree, so a function the tree\n // does not know (`max`) or a call of the wrong arity is refused here too.\n if (!GRAMMAR_CHECKED.has(expression)) {\n parseCatalogExpression(expression);\n GRAMMAR_CHECKED.add(expression);\n }\n const rewritten = rewriteCatalogHyphens(expression, formulaNames());\n const scope = formulaScope(withoutUnreadConstants(inputs, readNames(expression), declared), declared);\n return parseFormula(rewritten).evaluate(scope);\n}\n\nconst GRAMMAR_CHECKED = new Set<string>();\n\n/** A literal exponent: a number, or a ratio of two numbers (`1/3`), folded to one literal. */\nfunction literalExponent(node: FormulaPNode): ExprNode | undefined {\n if (node.kind === 'num') return numberSymbol(String(node.value));\n if (node.kind === 'op' && node.op === '/' && node.args.length === 2) {\n const [p, q] = node.args;\n if (p!.kind === 'num' && q!.kind === 'num' && q!.value !== 0) return numberSymbol(String(p!.value / q!.value));\n }\n return undefined;\n}\n\n/**\n * The sign-preserving `ExprNode` of a normalized MathTS parse node. Unary minus\n * is `-1 ×`, `sqrt` is `^0.5`, a literal ratio exponent (`^(1/3)`) is one\n * literal, and a transcendental keeps its name; a quantity name written with\n * underscores is restored to its hyphenated id. A call takes exactly one\n * argument: a second one is refused, never dropped.\n */\nfunction exprOf(node: FormulaPNode): ExprNode {\n switch (node.kind) {\n case 'num':\n return numberSymbol(String(node.value));\n case 'sym':\n return symbol(hyphenName(node.name));\n case 'neg':\n return { kind: 'op', op: '*', args: [numberSymbol('-1'), exprOf(node.arg)] };\n case 'op':\n return { kind: 'op', op: node.op, args: node.args.map(exprOf) };\n case 'pow':\n return { kind: 'op', op: '^', args: [exprOf(node.base), literalExponent(node.exp) ?? exprOf(node.exp)] };\n case 'call': {\n if (node.args.length !== 1) throw new Error(`expression calls '${node.fn}' with ${node.args.length} arguments; one is expected`);\n const arg = exprOf(node.args[0]!);\n if (node.fn === 'sqrt') return { kind: 'op', op: '^', args: [arg, numberSymbol('0.5')] };\n if (node.fn === 'abs') return { kind: 'abs', arg };\n if (TRANSCENDENTAL.has(node.fn as TranscendentalFn)) return { kind: 'transcendental', fn: node.fn as TranscendentalFn, arg };\n throw new Error(`expression calls an unknown function '${node.fn}'`);\n }\n }\n}\n\nfunction hyphenName(underscored: string): string {\n const hyphen = underscored.replace(/_/g, '-');\n if (quantityNames.has(hyphen)) return hyphen;\n return underscored;\n}\n\n/**\n * `8*pi` is the constant `8pi`, and `ln(2)` is the constant `ln2`. A product\n * flattens so the tree matches a flat canonical product of the same factors.\n */\nfunction foldKnownConstants(node: ExprNode): ExprNode {\n if (node.kind === 'transcendental') {\n const arg = foldKnownConstants(node.arg);\n if (node.fn === 'ln' && arg.kind === 'symbol' && arg.name === '2') return symbol('ln2');\n return { kind: 'transcendental', fn: node.fn, arg };\n }\n if (node.kind === 'abs') return { kind: 'abs', arg: foldKnownConstants(node.arg) };\n if (node.kind !== 'op') return node;\n const args = node.args.map(foldKnownConstants);\n if (node.op !== '*') return { kind: 'op', op: node.op, args };\n const factors: ExprNode[] = [];\n const push = (factor: ExprNode): void => {\n if (factor.kind === 'op' && factor.op === '*') {\n for (const inner of factor.args) push(inner);\n } else {\n factors.push(factor);\n }\n };\n for (const arg of args) push(arg);\n const merged: ExprNode[] = [];\n for (let i = 0; i < factors.length; i++) {\n const left = factors[i]!;\n const right = factors[i + 1];\n if (\n right?.kind === 'symbol' &&\n right.name === 'pi' &&\n left.kind === 'symbol' &&\n /^(?:2|4|8)$/.test(left.name) &&\n `${left.name}pi` in CONSTANTS\n ) {\n merged.push(symbol(`${left.name}pi`));\n i += 1;\n continue;\n }\n merged.push(left);\n }\n if (merged.length === 1) return merged[0]!;\n return { kind: 'op', op: '*', args: merged };\n}\n\n/** Parse a catalog expression into a sign-preserving `ExprNode`, through the one MathTS parser. */\nexport function parseCatalogExpression(expression: string): ExprNode {\n const rewritten = rewriteCatalogHyphens(expression, formulaNames());\n return foldKnownConstants(exprOf(parseFormulaPNode(rewritten)));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"expr-parse.js","sourceRoot":"","sources":["../../src/bridges/expr-parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAkB,MAAM,yBAAyB,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAqB,MAAM,mCAAmC,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAmB;IAC/C,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,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IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QACzB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC7B,IACE,KAAK,EAAE,IAAI,KAAK,QAAQ;YACxB,KAAK,CAAC,IAAI,KAAK,IAAI;YACnB,IAAI,CAAC,IAAI,KAAK,QAAQ;YACtB,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAC7B,oBAAoB,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,EACtC,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;YACtC,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,CAAC,CAAE,CAAC;IAC3C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC/C,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,sBAAsB,CAAC,UAAkB;IACvD,MAAM,SAAS,GAAG,qBAAqB,CAAC,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;IACpE,OAAO,kBAAkB,CAAC,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC","sourcesContent":["/**\n * One expression parser for a catalog formula: MathTS.\n *\n * Numeric evaluation is MathTS `parseFormula` on the hyphen-rewritten string,\n * and the dimensional `ExprNode` is built from the MathTS parse tree of the\n * same string, so the number and the tree can never disagree on precedence.\n * The `ExprNode` keeps hyphenated quantity names and unary minus, so symbolic\n * composition and dimensional checks see the same formula.\n *\n * @module bridges/expr-parse\n */\n\nimport { DIMENSIONLESS, type Dimension } from '../dimensional/types.js';\nimport type { ExprNode, TranscendentalFn } from '../dimensional/ast-types.js';\nimport { CONSTANTS, isRegisteredConstant } from '../dimensional/symbolic-constants.js';\nimport { FORMULA_NAMED } from '../dimensional/formula-names.js';\nimport { rewriteCatalogHyphens } from '../dimensional/hyphen-names.js';\nimport { allQuantityRecords } from '../dimensional/quantity-registry.js';\nimport { parseFormula } from '../numerical/formula-mathts.js';\nimport { parseFormulaPNode, type FormulaPNode } from '../numerical/formula-dimension.js';\nimport { ConstantInputError } from './evaluation-errors.js';\n\nconst TRANSCENDENTAL = new Set<TranscendentalFn>([\n 'exp', 'ln', 'log2', 'log10', 'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh',\n]);\n\nconst quantityNames = new Set(allQuantityRecords().map((row) => row.id));\n\nconst DIM_BY_NAME = new Map<string, Dimension>();\nfor (const row of allQuantityRecords()) DIM_BY_NAME.set(row.id, row.dimension);\nfor (const [name, constant] of Object.entries(CONSTANTS)) DIM_BY_NAME.set(name, constant.dim);\nfor (const named of FORMULA_NAMED) DIM_BY_NAME.set(named.name, named.dim);\n\nfunction dimOf(name: string): Dimension {\n return DIM_BY_NAME.get(name) ?? DIMENSIONLESS;\n}\n\nfunction symbol(name: string): ExprNode {\n return { kind: 'symbol', name, dim: dimOf(name) };\n}\n\nfunction numberSymbol(text: string): ExprNode {\n return { kind: 'symbol', name: text, dim: DIMENSIONLESS };\n}\n\n/** Names a formula may mention: quantities, constants, and formula overlays. */\nexport function formulaNames(): ReadonlySet<string> {\n const names = new Set<string>(quantityNames);\n for (const name of Object.keys(CONSTANTS)) names.add(name);\n for (const named of FORMULA_NAMED) names.add(named.name);\n names.add('pi');\n return names;\n}\n\nconst RESERVED = new Set<string>(['pi', ...Object.keys(CONSTANTS), ...FORMULA_NAMED.map((named) => named.name)]);\n\n/** π, the registered constants and the formula overlays: names a caller may not bind. */\nexport function reservedFormulaNames(): ReadonlySet<string> {\n return RESERVED;\n}\n\nconst underscored = (name: string): string => name.replace(/-/g, '_');\n\n/**\n * Numeric scope: constants, formula overlays, and π, then the caller's inputs.\n * An input whose name is reserved is refused with {@link ConstantInputError}\n * unless `declared` names it: a relation's own source may carry a constant's\n * name as a default the caller overrides (be-63's Lane-Emden ω₃).\n * {@link evaluateFormula} first drops a reserved key its expression does not\n * read; this builder refuses every undeclared one.\n */\nexport function formulaScope(\n inputs: Readonly<Record<string, number>> = {},\n declared: readonly string[] = [],\n): Record<string, number> {\n const scope: Record<string, number> = { pi: Math.PI };\n for (const [name, constant] of Object.entries(CONSTANTS)) scope[name] = constant.value;\n for (const named of FORMULA_NAMED) scope[named.name] = named.value;\n const allowed = new Set(declared.map(underscored));\n for (const [key, value] of Object.entries(inputs)) {\n const name = underscored(key);\n if (RESERVED.has(name) && !allowed.has(name)) throw new ConstantInputError(key);\n scope[name] = value;\n }\n return scope;\n}\n\n/**\n * The free variables of a catalog expression, read from the same MathTS parse\n * {@link evaluateFormula} evaluates: the scope names it reads, a hyphenated\n * quantity written with underscores.\n */\nexport function formulaVariables(expression: string): readonly string[] {\n return parseFormula(rewriteCatalogHyphens(expression, formulaNames())).variables;\n}\n\nconst VARIABLES = new Map<string, ReadonlySet<string>>();\n\nconst IDENTIFIER = /[A-Za-z_][A-Za-z0-9_]*/g;\n\n/**\n * The names a catalog expression mentions, each hyphenated quantity or\n * constant spelling rewritten to its one token first (`truncation-coefficient-b`\n * is `truncation_coefficient_b`, not `b`), π included (MathTS does not list it\n * as a variable). Cached per expression text. `reduced-planck-constant` is\n * `hbar`: the rewrite takes the longest spelling at each segment, so the\n * declared `planck-constant` inside it does not win. The one identifier\n * walk: the notices reader and the condition interpreter read it too.\n * @internal\n */\nexport function expressionNames(expression: string): ReadonlySet<string> {\n let names = VARIABLES.get(expression);\n if (names === undefined) {\n names = new Set(rewriteCatalogHyphens(expression, formulaNames()).match(IDENTIFIER) ?? []);\n VARIABLES.set(expression, names);\n }\n return names;\n}\n\n/**\n * `inputs` without the reserved keys that `reads` does not name. A reserved\n * key the formula reads and `declared` does not name is refused: the caller's\n * number would replace the constant. One the formula does not read is not an\n * input of this formula; it is dropped, as any other extra key is on the\n * graph path (a composed edge forwards every input to each component).\n */\nexport function withoutUnreadConstants(\n inputs: Readonly<Record<string, number>>,\n reads: ReadonlySet<string>,\n declared: readonly string[],\n): Record<string, number> {\n const allowed = new Set(declared.map(underscored));\n const kept: Record<string, number> = {};\n for (const [key, value] of Object.entries(inputs)) {\n const name = underscored(key);\n if (RESERVED.has(name) && !allowed.has(name)) {\n if (reads.has(name)) throw new ConstantInputError(key);\n continue;\n }\n kept[key] = value;\n }\n return kept;\n}\n\n/**\n * Evaluate a catalog expression with MathTS. Inputs are quantity names.\n * `declared` are the names the caller may bind although they are reserved\n * (the relation's sources); a reserved key the expression reads and\n * `declared` does not name is a {@link ConstantInputError}, and one it does\n * not read is dropped ({@link withoutUnreadConstants}).\n */\nexport function evaluateFormula(\n expression: string,\n inputs: Readonly<Record<string, number>>,\n declared: readonly string[] = [],\n): number {\n // One grammar: the expression must also build a dimensional tree, so a function the tree\n // does not know (`max`) or a call of the wrong arity is refused here too.\n if (!GRAMMAR_CHECKED.has(expression)) {\n parseCatalogExpression(expression);\n GRAMMAR_CHECKED.add(expression);\n }\n const rewritten = rewriteCatalogHyphens(expression, formulaNames());\n const scope = formulaScope(withoutUnreadConstants(inputs, expressionNames(expression), declared), declared);\n return parseFormula(rewritten).evaluate(scope);\n}\n\nconst GRAMMAR_CHECKED = new Set<string>();\n\n/** A literal exponent: a number, or a ratio of two numbers (`1/3`), folded to one literal. */\nfunction literalExponent(node: FormulaPNode): ExprNode | undefined {\n if (node.kind === 'num') return numberSymbol(String(node.value));\n if (node.kind === 'op' && node.op === '/' && node.args.length === 2) {\n const [p, q] = node.args;\n if (p!.kind === 'num' && q!.kind === 'num' && q!.value !== 0) return numberSymbol(String(p!.value / q!.value));\n }\n return undefined;\n}\n\n/**\n * The sign-preserving `ExprNode` of a normalized MathTS parse node. Unary minus\n * is `-1 ×`, `sqrt` is `^0.5`, a literal ratio exponent (`^(1/3)`) is one\n * literal, and a transcendental keeps its name; a quantity name written with\n * underscores is restored to its hyphenated id. A call takes exactly one\n * argument: a second one is refused, never dropped.\n */\nfunction exprOf(node: FormulaPNode): ExprNode {\n switch (node.kind) {\n case 'num':\n return numberSymbol(String(node.value));\n case 'sym':\n return symbol(hyphenName(node.name));\n case 'neg':\n return { kind: 'op', op: '*', args: [numberSymbol('-1'), exprOf(node.arg)] };\n case 'op':\n return { kind: 'op', op: node.op, args: node.args.map(exprOf) };\n case 'pow':\n return { kind: 'op', op: '^', args: [exprOf(node.base), literalExponent(node.exp) ?? exprOf(node.exp)] };\n case 'call': {\n if (node.args.length !== 1) throw new Error(`expression calls '${node.fn}' with ${node.args.length} arguments; one is expected`);\n const arg = exprOf(node.args[0]!);\n if (node.fn === 'sqrt') return { kind: 'op', op: '^', args: [arg, numberSymbol('0.5')] };\n if (node.fn === 'abs') return { kind: 'abs', arg };\n if (TRANSCENDENTAL.has(node.fn as TranscendentalFn)) return { kind: 'transcendental', fn: node.fn as TranscendentalFn, arg };\n throw new Error(`expression calls an unknown function '${node.fn}'`);\n }\n }\n}\n\nfunction hyphenName(underscored: string): string {\n const hyphen = underscored.replace(/_/g, '-');\n if (quantityNames.has(hyphen)) return hyphen;\n return underscored;\n}\n\n/**\n * `8*pi` is the constant `8pi`, and `ln(2)` is the constant `ln2`. A product\n * flattens so the tree matches a flat canonical product of the same factors.\n */\nfunction foldKnownConstants(node: ExprNode): ExprNode {\n if (node.kind === 'transcendental') {\n const arg = foldKnownConstants(node.arg);\n if (node.fn === 'ln' && arg.kind === 'symbol' && arg.name === '2') return symbol('ln2');\n return { kind: 'transcendental', fn: node.fn, arg };\n }\n if (node.kind === 'abs') return { kind: 'abs', arg: foldKnownConstants(node.arg) };\n if (node.kind !== 'op') return node;\n const args = node.args.map(foldKnownConstants);\n if (node.op !== '*') return { kind: 'op', op: node.op, args };\n const factors: ExprNode[] = [];\n const push = (factor: ExprNode): void => {\n if (factor.kind === 'op' && factor.op === '*') {\n for (const inner of factor.args) push(inner);\n } else {\n factors.push(factor);\n }\n };\n for (const arg of args) push(arg);\n const merged: ExprNode[] = [];\n for (let i = 0; i < factors.length; i++) {\n const left = factors[i]!;\n const right = factors[i + 1];\n if (\n right?.kind === 'symbol' &&\n right.name === 'pi' &&\n left.kind === 'symbol' &&\n /^(?:2|4|8)$/.test(left.name) &&\n isRegisteredConstant(`${left.name}pi`)\n ) {\n merged.push(symbol(`${left.name}pi`));\n i += 1;\n continue;\n }\n merged.push(left);\n }\n if (merged.length === 1) return merged[0]!;\n return { kind: 'op', op: '*', args: merged };\n}\n\n/** Parse a catalog expression into a sign-preserving `ExprNode`, through the one MathTS parser. */\nexport function parseCatalogExpression(expression: string): ExprNode {\n const rewritten = rewriteCatalogHyphens(expression, formulaNames());\n return foldKnownConstants(exprOf(parseFormulaPNode(rewritten)));\n}\n"]}
|
package/dist/bridges/holds.d.ts
CHANGED
|
@@ -18,9 +18,41 @@ export declare class HoldsError extends Error {
|
|
|
18
18
|
constructor(message: string);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* One conjunct of a validity condition: the text it is written in (the
|
|
22
|
+
* relation's own names), the names it reads, and its test.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export interface HoldsCondition {
|
|
26
|
+
/** The conjunct as the condition states it, in the relation's names (`swing-kelvin >= 0`). */
|
|
27
|
+
readonly text: string;
|
|
28
|
+
/** The names it reads, in order of first use, as the relation spells them. */
|
|
29
|
+
readonly names: readonly string[];
|
|
30
|
+
/** True when the conjunct holds; a name it cannot bind, or a non-boolean result, throws {@link HoldsError}. */
|
|
31
|
+
test(scope: Readonly<Record<string, number>>): boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The conjuncts of the condition `source`, each testable alone. Their
|
|
35
|
+
* conjunction is the condition, so a caller that tests them all decides
|
|
36
|
+
* exactly what {@link holds} decides, and can say which part failed.
|
|
37
|
+
* Hyphenated names are rewritten with `names` before parsing and restored in
|
|
38
|
+
* each conjunct's `text` and `names`.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export declare function holdsConditions(source: string, names: readonly string[]): readonly HoldsCondition[];
|
|
42
|
+
/** The names (hyphens written as underscores) the conditions read. @internal */
|
|
43
|
+
export declare function conditionReads(conditions: readonly HoldsCondition[]): ReadonlySet<string>;
|
|
44
|
+
/**
|
|
45
|
+
* A scope for a condition: the constants, then `values` with hyphens written as
|
|
46
|
+
* underscores. A value whose name is a constant that `declared` does not name
|
|
47
|
+
* is a {@link ConstantInputError} when `reads` holds it, and is dropped otherwise.
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare function holdsScope(values: Readonly<Record<string, number>>, constants: Readonly<Record<string, number>>, reads: ReadonlySet<string>, declared?: readonly string[]): Record<string, number>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether `holds` is true for `values`: every conjunct of
|
|
53
|
+
* {@link holdsConditions} holds. Hyphenated quantity names are rewritten with
|
|
54
|
+
* `names` before parsing; an unbound name, a non-boolean result, and a syntax
|
|
55
|
+
* error are a {@link HoldsError}.
|
|
24
56
|
* A value whose name is one of `constants` and which the condition reads is
|
|
25
57
|
* a {@link ConstantInputError}, a caller error and not a false condition,
|
|
26
58
|
* unless `declared` names it; one the condition does not read is dropped, as
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"holds.d.ts","sourceRoot":"","sources":["../../src/bridges/holds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"hol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