NuSMV执行flatten_hierarchy报错:‘x-1’未定义问题咨询
flatten_hierarchy Let's break down why you're seeing this error and how to fix it. The "undefined" error for x-1 typically stems from NuSMV's static type checking or expression resolution rules, even though your logic seems correct at first glance. Here are the most likely causes and solutions:
1. Bounded Integer Type Compatibility Issue
Your variable x is declared as 0..3, a bounded integer type. While x-1 stays within 0..3 when x>0, some older NuSMV versions have strict static checking that may not recognize the conditional guard (status = no_empty) & (x>0) as sufficient to guarantee the result is within bounds.
Fix:
Change x to an unbounded integer type and add an invariant to enforce its original range:
MODULE main VAR status:{empty, no_empty}; x : integer; // Switch to integer type ASSIGN init(status):= empty; init(x):=0; next(status):= case (status = empty): no_empty; (status = no_empty) & (x=0): empty; TRUE: status; esac; next(x):= case (status = empty): x+3; (status = no_empty) & (x>0): x-1; TRUE: x; esac; INVAR x >= 0 & x <= 3; // Enforce original bounds with an invariant
2. Operator Parsing Ambiguity
Even with parentheses, NuSMV's parser might misinterpret the conditional expression in edge cases. Using the short-circuit logical AND (&&) instead of the standard & can help the parser correctly prioritize your conditions.
Fix:
Modify the next(x) case guard to use short-circuit AND:
next(x):= case (status = empty): x+3; (status = no_empty) && (x>0): x-1; // Use short-circuit AND TRUE: x; esac;
3. Outdated NuSMV Version
Older NuSMV releases (pre-2.6) have known quirks with arithmetic operations on bounded integers. If you're using an outdated version, upgrading to the latest stable build will likely resolve the issue.
4. Explicit Expression Formatting
Sometimes, adding explicit parentheses around arithmetic expressions can help the parser resolve them correctly, especially if there's a hidden parsing quirk.
Fix:
Rewrite x-1 with clear spacing and parentheses:
(status = no_empty) & (x>0): (x - 1);
After trying any of these fixes, re-run flatten_hierarchy—the error should no longer occur.
内容的提问来源于stack exchange,提问作者Gold

