DEVELOPMENT EDITION · 769442725406
Verification Manual
On this page

Ghost models, lemmas, and quantified properties

A model describes the logical value you want to reason about without exposing every runtime representation detail. A vector can be specified as a sequence; a set by membership; a reclaimed text by its characters. Ghost entities let those descriptions exist for proof without determining ordinary executable output.

Separate three domains

Domain Appropriate question
Runtime representation Where are the values stored, copied, adjusted, freed, indexed and range-checked?
Public logical model Which sequence/map/set/number does the API promise that representation denotes?
Mathematical property Which relation should hold between inputs, entry model, result model and outputs?

Do not silently replace one with another. An unbounded mathematical integer does not make an executable Integer addition safe. An abstract sequence is not an automatically allocated Python list. A contract relating a container to its model is a premise from the supplied API; proof of its implementation is a separate release evidence obligation.

Ghost isolation

Ghost objects, subprograms and packages support specifications and proof. Ghost state may record history or auxiliary progress; ghost lemmas can establish reusable facts. Ordinary compiled behavior must not depend on ghost values, and ghost code cannot alter ordinary state in a way that would change behavior when erased. B3013/B3014 identify violations.

For example, the counter flow corpus keeps a ghost step count and proves its relation alongside the executable count/total. That history can help specifications but cannot be used to decide an ordinary printed answer after strict compilation erases it.

Proved, cached and proof-disabled builds leave ghost code out. An advisory build compiles it, so contracts that call ghost functions are checked when the program runs, but not every mathematical model has an executable implementation. See mode limits. In Vibe, @ghost marks a function as ghost.

Mathematical integers and rationals

Ada.Numerics.Big_Numbers.Big_Integers gives the proof model mathematical integer operations. When relating a bounded computation to that model, convert operands before the operation: the model of a + b is useful only if the conversion did not occur after a bounded overflow. The exact overload/argument types remain those of the supplied library.

Executable big integers have arbitrary precision, as their proof model does. As for any allocation, a proof does not show that memory holds every result: one it cannot hold raises Storage_Error.

Big_Reals is a ghost rational model. It supports exact rational reasoning, not arbitrary exact computation of transcendental real functions in native code. Do not interpret a solver's real sort as a promise that all executable float operations use exact arithmetic. Floating results require their own algorithm/rounding specification in numerics.

Sequence models

Verada.Containers.Functional.Sequences provides operations such as empty sequence, length, indexed get, add, set, equality, prefix relation and membership. The vector's Model contract connects that model's length and elements to the executable vector. Positions in this model are one-based; Vibe list positions are zero-based at its surface.

For an append, a useful postcondition relates the new model to the old model followed by the new element. For replacement, state equality of lengths, the changed element, and all other elements unchanged. Reading only the last element guarantee does not establish the frame for every earlier value unless the API also supplies it.

Choose the model boundary you actually need. A client sorting algorithm may specify order plus a permutation/multiset relation; stating only sortedness permits an implementation that discards values. Conversely, a filter's result usually needs both membership and order/ multiplicity rules, not just “every result satisfies the predicate.”

Sets, maps, arenas, and text

Functional set/map models describe membership/association independent of an arbitrary enumeration position. Do not attach meaning to incidental ordering of a ghost set's internal positions. An executable ordered set or insertion-ordered dictionary can promise an order; that is a distinct API property.

Maps may expose a key model and value lookup relation. A graph represented through a bounded arena can use indices/liveness/model relations instead of unrestricted cyclic ownership. Specify what an index denotes, when it is live, and which updates preserve other nodes. The graph corpus gives an implemented index-based approach; a graph with shared vertices can also be a proof enclave, as Verada.Containers.Graphs is.

Copyable text's model is its string value, not reference counts or buffer addresses. Public equality and character/length contracts let proof ignore immutable internal sharing. Tests can check resource behavior, but adjustment counts are not an ordinary logical output. Read each library specification rather than assuming all model families have identical operations or runtime status.

Quantifiers

A universal property says that every value in a specified domain satisfies a predicate. An existential property says some value does. Finite domain/bound facts are part of the specification. In Vada these use the supported quantified expression forms; Varc has its corresponding forms; Vibe recognizes all(predicate for ...) and any(...) in supported generator/iteration contexts.

Intended property What to establish
Every indexable element is nonnegative Domain covers exactly valid present positions
A search result exists Witness is in range and satisfies the predicate
No earlier match Quantified prefix excludes the selected/result position appropriately
Unchanged values outside an update Domain and implication select every preserved position
All calls in a quantified formula are legal Each callee's precondition holds for every domain value where it is evaluated

Guard partial operations inside the predicate. A quantified statement whose body indexes outside the declared domain is not made safe by being “only a specification.” Calls under quantification cannot assume their own preconditions without justification. Empty-domain universal statements are true; empty-domain existential statements are false, so check whether an accidental empty range made an intended test vacuous.

Lemmas and intermediate assertions

A lemma procedure is ordinary proved ghost code whose postcondition states a reusable fact. At a call, establish its precondition; after the call, use the result. Its own body must prove the postcondition. A bodyless imported lemma is a trusted axiom/interface, not a derived theorem merely because it is named Lemma.

Use a small assertion to expose a relation already following from current facts, or split a quantified consequence into stages the solver can instantiate. Prefer a meaningful mathematical explanation to a mysterious collection of assertions tailored only to one seed. Keep lemma statements and caller use narrow enough to review.

When an assertion itself fails, investigate it as an obligation. Do not replace it with Assume and continue describing the original fact as proved. If a fact genuinely comes from hardware/foreign code, document it in the trust inventory with its external evidence.

Make model-based proof maintainable

Start with the logical result clients need, then connect the executable representation to that model through stable API contracts. Use loop invariants for processed prefixes/frames, and small lemmas for recurring relations. Preserve the source and effective model/library versions in proof provenance. Solver resource increases can help quantified search, but they cannot repair an incorrect domain, missing frame or assumed implementation relation.