Code Examples
Table of Contents
This section contains code examples for using Spot. This is a work in progress. Feel free to send suggestions of small tasks you would like to see illustrated here.
If you have difficulties compiling the C++ examples, check out these instructions.
Reading the concepts page might help if you are not familiar with some of the objects or concepts used here.
Examples with Shell, Python, and C++
All the following pages show how to perform the same task using the three interfaces supported by Spot: shell commands, Python, or C++.
- Parsing and Printing LTL Formulas
- Relabeling Formulas
- Testing the equivalence of two LTL formulas
- Translating an LTL formula into a never claim
- Translating an LTL formula into a monitor
- Working with LTL formulas with finite semantics
- Converting a never claim into HOA
- Converting Rabin (or Other) to Büchi, and simplifying it
- Removing alternation
- Using ppLTLTT to work with pure-past LTL subformulas
Examples in Python and C++
- Constructing and transforming formulas
- Custom print of an automaton
- Printing a Büchi automaton in the "BA format"
- Creating an automaton by adding states and transitions
- Creating an alternating automaton by adding states and transitions
- Iterating over alternating automata
- Solving a safety game to decide direct simulation
- Creating an explicit Kripke structure
- Using the
bdd_dictto associate atomic proposition to BDD variables, or allocate anonymous BDD variables (advanced)
Examples in C++ only
Examples in Python only
In directory python/tests, the Spot tarball contains a small
collection of IPython notebooks. As the name of the directory implies,
these are part of the test suite for the Python bindings, however they
can be interesting to look at if you want to see more code examples.
For convenience, the following links offer static HTML renderings of these notebooks, but we strongly suggest interactively evaluating the real notebooks instead.
formulas.ipynbcovers the basics of LTL/PSL formula parsing and printing, with some light operationsautomata.ipynbcovers translation from formulas to automata, automata printing, and some lights transformationsautomata-io.ipynbshows how to save and read automata from filesrandaut.ipynbshows a simple case where therandautcommands generated random automata, which are displayed in a table before and after acceptance simplificationaccparse.ipynbexercises the acceptance condition parseracc_cond.ipynbdocuments the interface for manipulating acceptance conditionsbackprop.ipynbsolving reachability games by backpropagationcontains.ipynbdemonstrates containment checks between formulas or automatasplit.ipynbillustrates various ways to split labelsparity.ipynbdocuments algorithms for manipulating parity automata in Pythongames.ipynbillustrates support for gamessynthesis.ipynbillustrates support for game-based LTL reactive synthesisproduct.ipynbshows how to re-implement the product of two automata in Pythonrandltl.ipynbdemonstrates a Python-version ofrandltlgen.ipynbshow how to generate families of LTL formulas (as done ingenltl) or automata (genaut)decompose.ipynbillustrates thedecompose_strength(),decompose_acc_scc()anddecompose_scc()functionstestingaut.ipynbshows the steps necessary to build a testing automatonltsmin-dve.ipynbloading a DiVinE model using the LTSmin interface.ltsmin-pml.ipynbloading a Promela model using the LTSmin interface.word.ipynbexample for thetwa_runandtwa_wordclasses.highlighting.ipynbshows how to highlight states or edges in automata.atva16-fig2a.ipynbfirst example from our ATVA'16 tool paper.atva16-fig2b.ipynbsecond example from our ATVA'16 tool paper.cav22-figs.ipynbfigures from our CAV'22 tool paper.alternation.ipynbexamples of alternating automata.stutter-inv.ipynbworking with stutter-invariant formulas properties.satmin.ipynbPython interface for SAT-based minimization of deterministic ω-automata.twagraph-internals.ipynbInner workings of thetwa_graphclass.aliases.ipynbSupport for HOA aliases.zlktree.ipynbdemonstration of Zielonka Trees and ACDgiven.ipynbsimplification of automata given some apriori knowledgeltlf2dfa.ipynbtranslation between LTLf and MTDFAmtdtwa.ipynbsupport for MTBDD-based deterministic twa