Two machine settings computed from sensor readings, with every sum shown.
control-system.py · output · proof · check · try it in the playground
A controller reads sensors and decides how hard to drive its actuators (the parts that act: a valve, a motor, a heater).
This example computes commands for two actuators:
What should each command be, and how was it worked out?
fact(measurement1('input1', [6, 11]))
fact(measurement2('input2', 'true'))
fact(measurement3('disturbance1', 35766))
fact(measurement4('output2', 24))
fact(observation3('state3', 22))
fact(target2('output2', 29))
# …
A pair like [6, 11] is turned into one number by a helper rule: if the first
value is smaller, use the square root of the difference (here √5); otherwise
use the first value.
implied_by(
control1('actuator1', C),
measurement10('input1', M1)
& measurement2('input2', 'true')
& measurement3('disturbance1', D1)
& is_(C1, M1 * 19.6) # proportional part
& is_(C2, log(D1) / log(10)) # compensation part
& is_(C, C1 - C2), # simple feedforward control
)
is_ means “calculate”. The compensation is the base-10 logarithm of the
disturbance.
implied_by(
control1('actuator2', C),
observation3('state3', P3)
& measurement4('output2', M4)
& target2('output2', T2)
& is_(E, T2 - M4) # error
& is_(D, P3 - M4) # differential error
& is_(C1, 5.8 * E) # proportional part
& is_(N, 7.3 / E) # nonlinear factor
& is_(C2, N * D) # nonlinear differential part
& is_(C, C1 + C2), # PND feedback control
)
control1('actuator1', 39.27346198678276)
control1('actuator2', 26.08)
These are ordinary decimal (floating-point) numbers, printed in full.
Actuator 1
Actuator 2
Every one of these values is written into the proof.
The checker does not take the arithmetic on faith: it recomputes each calculation itself and compares.
Verdict: checked.
python -m peye examples/control-system.py # the commands
python -m peye --proof examples/control-system.py # answers with their proof
Or open it in the playground.
Raise the target to fact(target2('output2', 34)) and run again: the error becomes
10, and actuator 2’s command becomes 56.54 instead of 26.08. Actuator 1 is
unchanged.
When a machine setting comes from a chain of formulas, a proof that lists and re-checks every intermediate value turns “the controller said so” into something an engineer can audit line by line.