Phy

A language in which the physics equations are the code

Phy checks units, structure and proofs when it builds, and compiles to small, fast firmware.

A wrong sign, a missing term or a wrong law is refused before any code exists.

the physics, written as equationsΔφ = k · g · T² [rad]units on every symbolidentities proved at build ✓invalid samples refused ✕formulas cross-checked ⋔stand-alone Cfor the device, no runtime to installsin(ωt) where cos(ωt)a planted bug:refused beforeany code exists
What Phy does

You write a sensor’s physics as equations with their units

Checks units on every symbol, and converts units and prefixes automatically: nT ↔ µT, g/cm³ ↔ kg/m³, % ↔ 1, degrees ↔ radians.

Proves identities when it builds (✓). It shows that a derived formula really follows from its parent law.

Cross-checks several formulas for the same quantity (⋔).

Generates solvers from the equations as written: a partial differential equation written in 2 lines becomes a spectral solver.

Includes a quantum layer: states, operators, tensor products, matrix exponentials, with checks that operators are Hermitian or unitary and states are normalised.

Refuses invalid sensor samples one by one without stopping the program.

Compiles to stand-alone C for the device, with no runtime to install.

Physics in ordinary code is a copy of the physics, written by hand. Ordinary languages check types, not physics.

A unit slip, a wrong sign, sin in place of cos, or a missing term compiles, runs and ships. Even languages with units of measure cannot tell a correct law from a wrong one with the same units.

phy · terminal$ phy check examples.phylaw iħ ∂ψ/∂t = Ĥ ψ✓ unitsĤ = −ħ²/2m ∇² + V(r)✓ Hermitianω_L = γ_e · B [rad/s]✓ CODATAΔφ = k_eff · g · T² [rad]✓ proved∂T/∂t = α ∇²T→ solverR_μν = 0 (Kerr, a = 0.9375)✓ checkedx = A sin(ωt)✕ not the law$ phy build nv_sensor.phyemitted nv_sensor.c · 0.22 MB✓ checked
Measured

A pre-registered comparison with OpenModelica and F#

MeasurePhyF# (units of measure)OpenModelica (unit checking on)
Planted physics bugs kept out of shipped firmware (35, pre-registered)20175
The same, excluding the 3 bugs with no effect on the data (of 32)17142
Bugs caught by this language alone (of 32)740
NV-sensor firmware, ns per sample5898,07124,526
Gravity-gradiometer firmware, ns per sample3,7089,56926,757
What the NV device carries0.22 MB82.6 MB (with .NET)4.1 MB
Cold start, NV device0.016 s0.136 s0.026 s
NV-sensor firmware, ns per sample, lower is betterPhy → C589C++2,074F#8,071Modelica FMU24,526

On the NV sensor, Phy → C was 3.5× faster than C++ (2,074 ns), 14× faster than F# and 42× faster than the Modelica FMU.

On the gradiometer, Phy → C reproduces the reference to 3e-15.

In a 3-body thermal-network model, Phy took 2 lines against 28 (F#) and 20 (OpenModelica).

Phy’s extra catches were physics structure: signs, the wrong trigonometric function, a missing term, a wrong lag law.

Cross-build. The same Phy-generated C builds for 6 processor families: x86-64 Windows and Linux, ARM64, ARMv7, RISC-V 64 and WebAssembly. It has been run and matched on 3 of them so far, with 20–55 kB of code per processor.

Notes
  • F# came second (17 of 35) and OpenModelica third (5 of 35).
  • Phy 0.4 runs inside a host program, which handles input and output.
a spring and a massxF = −k x