Formal Verification

Understand Modeloop's numerical safety analysis and model-to-HLIR equivalence checks, including their assumptions, results, and limits.

Modeloop verifies supported properties of control models within declared types, input ranges, and modeled behavior. Numerical safety analysis checks operations such as division and square root. Translation validation compares the model with the final optimized high-level intermediate representation (HLIR). Testing compiled C provides separate execution evidence. See software-in-the-loop testing.

Contracts

Numerical safety analysis uses the mathematical contracts of supported blocks. A contract describes the computation, any preconditions on its inputs, and guarantees about its outputs within those assumptions.

  • What it computes. A Sum block computes the signed sum of its inputs.
  • What it requires (preconditions). Sqrt requires a non-negative input. Log requires a positive one. Asin and Acos require an input in [-1, 1]. A division requires a non-zero divisor.
  • What it guarantees (postconditions). Sin and Cos always produce values in [-1, 1]. Abs is always non-negative. A Comparator is always a boolean.

Your model contributes contracts of its own, without writing anything new:

  • Data types are input contracts. An input declared uint8 is guaranteed to be in 0…255; an int16 in −32768…32767. The tighter you type your interfaces, the more the verifier knows.
  • Structure is a contract. Clamping a signal through a Curve block, or guarding a path with a Comparator and If-Then-Else, constrains what can reach the blocks downstream — and the verifier uses it.

What numerical safety analysis checks

Modeloop uses known upstream types, ranges, and supported block contracts to check preconditions. A result applies to the inputs and semantics covered by the analysis.

Property Question answered
Division by zero Can any input ever make a divisor zero?
Math domain violations Can a Sqrt, Log, Asin, or Acos ever receive an input outside its domain?
Numeric overflow Can a signal ever exceed the representable range of its declared type?

Two concrete examples of how contracts compose:

  • The contract for Sin bounds its output to [-1, 1]. That range meets the input condition for Asin.
  • A square root fed by an unconstrained float64 may receive a negative value. If the application requires a non-negative input, express that assumption in the model, for example with a declared range or a guard.

When it runs, and what you see

When verification is enabled for code generation, a proven property holds within the assumptions of that check. A counterexample identifies a violation within the checked scope. An inconclusive result leaves the property open and can occur with unsupported semantics or a solver timeout. Review diagnostics and their severity before using the generated code. See checks and traceability.

Designing provable models

The verifier rewards the same habits the Modeling Guidelines already recommend:

  1. Type interfaces deliberately. Use a type that represents the signal, then declare any narrower physical range the system enforces.
  2. Guard partial functions in the model. Express conditions such as a non-negative square-root input where they belong in the design.
  3. Review inferred ranges. A saturation limits a signal, and downstream operations can widen the range again.
  4. Investigate inconclusive checks. Check whether an assumption is missing or the operation is outside the analysis scope.

Verified code generation

Modeloop checks translation at the HLIR boundary and checks numerical safety separately:

  • Final equivalence checking compares the original model with the final optimized HLIR once, including outputs, initialization and state updates where supported. Counterexamples block generation; unsupported semantics and solver timeouts remain explicit inconclusive results.
  • Numerical verification checks the model’s contracts for division by zero, overflow and invalid ranges.
  • Back-to-back validation compares executions on supplied input sequences, providing evidence for those sequences.

C lowering, C-specific optimization and source emission follow the formal equivalence check and are outside its proof boundary. Testing generated code through SIL/PIL supplies additional evidence for those stages.