Executable declaration solving #
This module is the declaration checker of Section 3 of our paper. It decides,
in exact rational arithmetic, the conditions that LambdaS.Declare
(consistency), LambdaS.Determinacy (which factors are fixed), and
LambdaS.DeclarationComplete (whether every legal conversion is fixed) state
semantically, and proves each decision sound and complete.
Three entry points, in the order a caller wants them.
checkaccepts a complete certified system: the declarations are dimensionally sound, some valuation satisfies them all, and every same-dimension conversion has the same factor in every satisfying valuation. Acceptance returns the proofs as aCheckedcertificate, andcheck_isSome_iff(Theorem 3.2) proves acceptance equivalent to these three conditions.solveanswers the weaker question of consistency alone, whether any valuation satisfies the declarations (solve_isSome_iff).conversionExactreturns a factor as anExactFactor, a positive rational radicand and a positive integer root degree, proved equal toV u / V vunder every satisfying valuation (conversionExact_correct). For a consistent set it succeeds exactly when that factor is determined (factorCoefficients_iff_determined), and in a checked system it succeeds for every same-dimension pair (Checked.conversionExact_isSome).
DeclarationSolverExamples runs all three: disconnected feet and meters are
rejected, adding foot = 0.3048 meter makes the system pass, and the
dimensionless self-equation u = 2/u forces the magnitude √2, returned as
radicand 2 and degree 2.
The mechanics: the solver works over explicit enumerations of the finite
base-unit and base-dimension universes (enum, dims), supplied as input data
rather than as a noncomputable choice of order, and reduces each declaration
to one linear equation in the logarithms of the magnitudes
(satisfies_valuation_iff). RationalSolver performs the elimination, and
LogFactor carries the exact arithmetic that keeps it decidable.
The rational coefficient matrix of declaration equations.
Equations
Instances For
The valuation whose log-magnitudes are x, indexed in the base-unit order
enum supplies.
Equations
Instances For
Compute rational witnesses expressing a queried ratio through declarations.
Failure means the ratio is not in the ℚ-span of the declared ratios. For a
consistent set that is exactly the semantic statement that the declarations
leave the factor undetermined (Decl.determined_iff_coefficients); for an
inconsistent set no valuation satisfies the declarations at all, so the
semantic notion is vacuous and only the span statement applies.
Equations
- LambdaS.DeclSolver.factorCoefficients enum ds r = LambdaS.RationalSolver.solve (Matrix.of fun (j : Fin m) (i : Fin n) => (ds i).ratio.base (enum j)) fun (j : Fin m) => r.base (enum j)
Instances For
Successful factor lookup supplies an exact dependency witness.
Lookup decides span membership, including failure, using exact rationals.
Solve declaration equations in exact logarithmic numbers. A solution fixes free log-magnitudes to zero, but its particular choices do not determine a conversion unless the separate factor-witness check succeeds.
Equations
- LambdaS.DeclSolver.solve enum ds = LambdaS.RationalSolver.solve (LambdaS.DeclSolver.matrix enum ds) fun (i : Fin n) => LambdaS.LogFactor.ofRat (ds i).factor ⋯
Instances For
Every returned exact solution denotes a valuation satisfying every declaration.
Executable solving decides existence of a real satisfying valuation. No assumption that the magnitudes or their logarithms are rational is needed.
Interpret the factor witness without choosing magnitudes for unconstrained units.
Equations
- LambdaS.DeclSolver.factorLog ds c = ∑ i : Fin n, c i • LambdaS.LogFactor.ofRat (ds i).factor ⋯
Instances For
A linear combination of declaration ratios fixes the same combination of log-factors.
Exact conversion lookup. An unresolved ratio returns none, even if an arbitrary satisfying valuation could assign it a numerical value.
Equations
- LambdaS.DeclSolver.conversion enum ds u v = Option.map (LambdaS.DeclSolver.factorLog ds) (LambdaS.DeclSolver.factorCoefficients enum ds (LambdaS.Term.div u v))
Instances For
The returned exact logarithm gives the conversion factor in every satisfying valuation.
The executable factor test is exactly semantic determinacy on consistent declarations.
For a consistent declaration set, conversion lookup succeeds exactly when the
factor of u / v is determined, so success decides determinacy rather than
producing a guess.
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
The real number the factor denotes, radicand ^ (1 / degree), written as
exp (log radicand / degree). Noncomputable; constructing and comparing
ExactFactor values is executable.
Instances For
Return an inspectable exact radical for a determined conversion.
Equations
- LambdaS.DeclSolver.conversionExact enum ds u v = Option.map (LambdaS.DeclSolver.exactFactor ds) (LambdaS.DeclSolver.factorCoefficients enum ds (LambdaS.Term.div u v))
Instances For
The extracted radical is the conversion factor in every satisfying valuation.
A checked unit system carries its computed solution and evidence that its declarations are sound, consistent, and determine every legal conversion.
Exact log-magnitudes, in
enumorder, of one satisfying valuation. Free coordinates are0; they never supply a factor.Every declaration relates units of one dimension.
magnitudesis whatsolvereturned, so it satisfies every declaration (solve_sound).The declared ratios and dimension rows span the unit space.
Instances For
The declaration checker. Accepts, returning a Checked certificate, when
every declaration is Decl.Sound, solve finds a solution, and
DeclarationComplete.check confirms that the declared ratios and dimension rows
span the unit space; returns none otherwise. check_isSome_iff characterizes
acceptance.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Every checked system supplies a genuine satisfying valuation.
Every same-dimension conversion in a checked system is determined.
Executable declaration checking (Theorem 3.2 of our paper). check
accepts exactly when every declaration is dimensionally sound, some valuation
satisfies them all, and every same-dimension pair has the same factor in every
satisfying valuation. So an accepted system has these properties, and a system
that has them is never rejected.
Factor extraction cannot fail for a legal conversion in a checked system.