⚠ not yet verified
Counterexample generation¶
Expanded 2026; class names and module locations checked against the sources.
KeY can search for counterexamples to an (unprovable) goal by translating the sequent to SMT and asking Z3 for a model.
High-level flow¶
- The user clicks the Counterexample button in the toolbar; this triggers
CounterExampleAction(inkeyext.ui.testgen). - The action constructs and starts a
CEWorker(aSwingWorker), so the search runs off the event thread and can be interrupted. AbstractCounterExampleGenerator#searchCounterExamplecopies the sequent into a hidden side proof and prepares it by applying theSemanticsBlastingMacro, which rewrites the sequent into a form suitable for SMT model finding (expanding the heap/JavaDL semantics).SolverLauncherstarts Z3 in counterexample mode;Z3CESockethandles the solver communication and awaits its output.- If Z3 reports sat,
Z3CESocketqueries the model and passes it to theModelExtractor, which reconstructs heap/object values from the SMT model. InformationWindow#initModeldisplays the counterexample to the user.
See also¶
- SMT translation — how sequents are translated to SMT-LIB.
- Adding SMT solvers — how solvers are configured and launched.
- Test case generation (
key.core.testgen) reuses the same model-extraction machinery to derive test inputs.