如何找出NuSMV中所有可能反例?建模得单个反例后能否获取所有含反例路径?
Hey there! Let's tackle your two NuSMV questions one by one—these are common pain points when working with model checking, so I’m glad you asked:
First off, NuSMV doesn’t spit out all counterexamples by default because, let’s be real, in many systems there are infinitely many of them (especially if your model has loops). But there are practical approaches to get more counterexamples or characterize the full set:
- Use Bounded Model Checking (BMC) for finite-length counterexamples: If you’re using NuSMV’s BMC module, you can run the command:
This will find all counterexamples of length up tocheck_ltlspec_bmc -k <max_length> -all<max_length>. Since BMC works within a finite path bound, it can safely enumerate every violation in that range. - Interactive simulation to explore more paths: After getting your first counterexample, use NuSMV’s interactive
simulatecommand to generate additional violating paths. For example, if your initial counterexample is saved in a trace file likecex.trace, run:
This lets you step through the state space starting from the end of your existing counterexample, generating new paths that also violate your LTL property.simulate -i -f cex.trace - Custom scripting for full control: For advanced use cases, you can use NuSMV’s C API or Python bindings (like
pynusmv) to write a script that traverses the entire state space, identifies all paths that violate your property, and collects their traces. This is more work, but it gives you full control over which counterexamples you capture.
First, let’s clarify: I assume you mean paths that either start with the exact state sequence of your counterexample, or contain that sequence as a substring. Either way, enumerating every single such path is impossible if your model has infinite behavior (like loops), but you can do these things:
- Generate paths extending your counterexample: Use the
simulatecommand to start from the final state of your counterexample. If your counterexample is saved incex.trace, run:
This lets you generate endless variations of paths that continue from the end of your counterexample—all of which will include your original counterexample as a prefix.simulate -i -initfile cex.trace - Characterize the set of paths with a new property: Instead of enumerating, define an LTL property that describes paths containing your counterexample’s state sequence. For example, if your counterexample is
s0 → s1 → s2, write a property that asserts this sequence must occur, then check for paths that violate your original property and satisfy this sequence. You can use NuSMV’s state predicates to define each state in the sequence and chain them with temporal operators. - Verify that all extending paths are counterexamples: If you want to confirm every path that includes your counterexample as a prefix violates your original property, modify your model to fix the prefix as your counterexample, then re-run the LTL check. If the property still fails, that means every path extending your counterexample is also a violating path.
内容的提问来源于stack exchange,提问作者Ali Kianinejad

