Collatz¶
The Collatz recurrence \(x \mapsto x/2\) (even) or \(x \mapsto 3x + 1\) (odd) is the smallest non-trivial behavior tree with genuinely rich dynamics.
Location¶
examples/Collatz/collatz.tree
Features exercised¶
A
selectorwrapping a three-childsequence.loop-constructed set-valued initial assignment (\(x \in [1, 254]\)).Integer clamping via
(min max_val ...).INVARSPEConly — no temporal operators needed.
Invocation¶
python -m behaverify nuxmv examples/Collatz/collatz.tree ../out/ \
--generate --invar --nuxmv_path ../nuXmv
Suggested exercise¶
Run with
--use_encoding naiveand compare the generated SMV against the defaultfastforwardingencoding. See Encodings.Render the tree with
latexmode on the small variantcollatz_small.tree:python -m behaverify latex examples/Collatz/collatz_small.tree \ ./collatz.tex pdflatex collatz.tex