Adding python functions to mirror the functionalities found in src/bin
* wrap/python/spot.i: Rename to... * wrap/python/spot_impl.i: ...this, and import spot_impl from spot.py so that it is not needed to recompile everything when modifying python code. * wrap/python/spot.py: Adding python functions to mirror the functionalities found in src/bin. * src/bin/common_r.cc: Move simplification level... * src/ltlvisit/simplify.hh: ... here as a constructor of ltl_simplifier_options, to make it available in wrap/python. * src/bin/ltlfilt.cc: Set simplification level using the new ltl_simplifier_options constructor. * src/bin/randltl.cc: Move most of the code... * src/ltlvisit/randomltl.cc, src/ltlvisit/randomltl.hh: ... here, as a class named randltlgenerator. * wrap/python/tests/bddnqueen.py, wrap/python/tests/minato.py: Avoid calling bdd_init twice by moving 'import spot' after bdd initialization. * wrap/python/Makefile.am: Rename spot to spot_impl * wrap/python/tests/Makefile.am: Add ipnbdoctest.py. * wrap/python/.gitignore: Rename spot.py to spot_impl.py * src/ltlvisit/tostring.cc: \ttrue and \ffalse should be \top and \bot. * wrap/python/tests/ipnbdoctest.py: Run code cells of a python notebook and compare the output to the actual content of the notebook. * wrap/python/tests/randltl.ipynb: Document and test randltl. * wrap/python/tests/run.in: Call ipnbdoctest.py to run ipython notebooks.
This commit is contained in:
parent
cb9867b7d4
commit
3bf3d2c8a1
17 changed files with 1528 additions and 257 deletions
|
|
@ -1,4 +1,4 @@
|
|||
## Copyright (C) 2010, 2012, 2013 Labortatoire de Recherche et Développement de
|
||||
## Copyright (C) 2010, 2012, 2013, 2014 Labortatoire de Recherche et Développement de
|
||||
## l'EPITA.
|
||||
## Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
## département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
|
|
@ -21,7 +21,8 @@
|
|||
|
||||
EXTRA_DIST = \
|
||||
$(TESTS) \
|
||||
ltl2tgba.py
|
||||
ltl2tgba.py \
|
||||
ipnbdoctest.py
|
||||
|
||||
LOG_COMPILER = ./run
|
||||
LOG_DRIVER = $(TEST_LOG_DRIVER)
|
||||
|
|
@ -39,4 +40,5 @@ TESTS = \
|
|||
minato.py \
|
||||
optionmap.py \
|
||||
parsetgba.py \
|
||||
randltl.ipynb \
|
||||
setxor.py
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2010, 2011, 2012 Laboratoire de Recherche et
|
||||
# Copyright (C) 2010, 2011, 2012, 2014 Laboratoire de Recherche et
|
||||
# Développement de l'EPITA.
|
||||
# Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6
|
||||
# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
|
||||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
import sys
|
||||
from buddy import *
|
||||
from spot import nl_cout
|
||||
|
||||
# Build the requirements for all other fields than (i,j) assuming
|
||||
# that (i,j) has a queen.
|
||||
|
|
@ -96,6 +95,9 @@ sys.stdout.write("There are %d solutions, one is:\n" %
|
|||
bdd_satcount(queen))
|
||||
solution = bdd_satone(queen)
|
||||
bdd_printset(solution)
|
||||
|
||||
from spot import nl_cout
|
||||
|
||||
nl_cout()
|
||||
|
||||
# Cleanup all BDD variables before calling bdd_done(), otherwise
|
||||
|
|
|
|||
220
wrap/python/tests/ipnbdoctest.py
Executable file
220
wrap/python/tests/ipnbdoctest.py
Executable file
|
|
@ -0,0 +1,220 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
simple example script for running and testing notebooks.
|
||||
|
||||
Usage: `ipnbdoctest.py foo.ipynb [bar.ipynb [...]]`
|
||||
|
||||
Each cell is submitted to the kernel, and the outputs are compared with those stored in the notebook.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os,sys,time
|
||||
import base64
|
||||
import re
|
||||
from difflib import unified_diff as diff
|
||||
|
||||
from collections import defaultdict
|
||||
try:
|
||||
from queue import Empty
|
||||
except ImportError:
|
||||
print('Python 3.x is needed to run this script.')
|
||||
sys.exit(77)
|
||||
|
||||
try:
|
||||
from IPython.kernel import KernelManager
|
||||
except ImportError:
|
||||
from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
|
||||
|
||||
from IPython.nbformat.current import reads, NotebookNode
|
||||
|
||||
|
||||
def compare_png(a64, b64):
|
||||
"""compare two b64 PNGs (incomplete)"""
|
||||
try:
|
||||
import Image
|
||||
except ImportError:
|
||||
pass
|
||||
adata = base64.decodestring(a64)
|
||||
bdata = base64.decodestring(b64)
|
||||
return True
|
||||
|
||||
def sanitize(s):
|
||||
"""sanitize a string for comparison.
|
||||
|
||||
fix universal newlines, strip trailing newlines, and normalize likely random values (memory addresses and UUIDs)
|
||||
"""
|
||||
if not isinstance(s, str):
|
||||
return s
|
||||
# normalize newline:
|
||||
s = s.replace('\r\n', '\n')
|
||||
|
||||
# ignore trailing newlines (but not space)
|
||||
s = s.rstrip('\n')
|
||||
|
||||
# normalize hex addresses:
|
||||
s = re.sub(r'0x[a-f0-9]+', '0xFFFFFFFF', s)
|
||||
|
||||
# normalize UUIDs:
|
||||
s = re.sub(r'[a-f0-9]{8}(\-[a-f0-9]{4}){3}\-[a-f0-9]{12}', 'U-U-I-D', s)
|
||||
|
||||
return s
|
||||
|
||||
|
||||
def consolidate_outputs(outputs):
|
||||
"""consolidate outputs into a summary dict (incomplete)"""
|
||||
data = defaultdict(list)
|
||||
data['stdout'] = ''
|
||||
data['stderr'] = ''
|
||||
|
||||
for out in outputs:
|
||||
if out.type == 'stream':
|
||||
data[out.stream] += out.text
|
||||
elif out.type == 'pyerr':
|
||||
data['pyerr'] = dict(ename=out.ename, evalue=out.evalue)
|
||||
else:
|
||||
for key in ('png', 'svg', 'latex', 'html', 'javascript', 'text', 'jpeg',):
|
||||
if key in out:
|
||||
data[key].append(out[key])
|
||||
return data
|
||||
|
||||
|
||||
def compare_outputs(test, ref, skip_compare=('png', 'traceback', 'latex', 'prompt_number')):
|
||||
for key in ref:
|
||||
if key not in test:
|
||||
print("missing key: %s != %s" % (test.keys(), ref.keys()))
|
||||
return False
|
||||
elif key not in skip_compare and sanitize(test[key]) != sanitize(ref[key]):
|
||||
print("mismatch %s:" % key)
|
||||
exp = ref[key]
|
||||
eff = test[key]
|
||||
if exp[:-1] != '\n':
|
||||
exp += '\n'
|
||||
if eff[:-1] != '\n':
|
||||
eff += '\n'
|
||||
print(''.join(diff(exp.splitlines(1), eff.splitlines(1),
|
||||
fromfile='expected', tofile='effective')))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def run_cell(shell, iopub, cell):
|
||||
# print cell.input
|
||||
shell.execute(cell.input)
|
||||
# wait for finish, maximum 20s
|
||||
shell.get_msg(timeout=20)
|
||||
outs = []
|
||||
|
||||
while True:
|
||||
try:
|
||||
msg = iopub.get_msg(timeout=0.2)
|
||||
except Empty:
|
||||
break
|
||||
msg_type = msg['msg_type']
|
||||
if msg_type in ('status', 'pyin'):
|
||||
continue
|
||||
elif msg_type == 'clear_output':
|
||||
outs = []
|
||||
continue
|
||||
|
||||
content = msg['content']
|
||||
# print msg_type, content
|
||||
out = NotebookNode(output_type=msg_type)
|
||||
|
||||
if msg_type == 'stream':
|
||||
out.stream = content['name']
|
||||
out.text = content['data']
|
||||
elif msg_type in ('display_data', 'pyout'):
|
||||
out['metadata'] = content['metadata']
|
||||
for mime, data in content['data'].items():
|
||||
attr = mime.split('/')[-1].lower()
|
||||
# this gets most right, but fix svg+html, plain
|
||||
attr = attr.replace('+xml', '').replace('plain', 'text')
|
||||
setattr(out, attr, data)
|
||||
if msg_type == 'pyout':
|
||||
out.prompt_number = content['execution_count']
|
||||
elif msg_type == 'pyerr':
|
||||
out.ename = content['ename']
|
||||
out.evalue = content['evalue']
|
||||
out.traceback = content['traceback']
|
||||
else:
|
||||
print("unhandled iopub msg:", msg_type)
|
||||
|
||||
outs.append(out)
|
||||
return outs
|
||||
|
||||
|
||||
def test_notebook(nb):
|
||||
km = KernelManager()
|
||||
km.start_kernel(extra_arguments=['--pylab=inline'], stderr=open(os.devnull, 'w'))
|
||||
try:
|
||||
kc = km.client()
|
||||
kc.start_channels()
|
||||
iopub = kc.iopub_channel
|
||||
except AttributeError:
|
||||
# IPython 0.13
|
||||
kc = km
|
||||
kc.start_channels()
|
||||
iopub = kc.sub_channel
|
||||
shell = kc.shell_channel
|
||||
|
||||
# run %pylab inline, because some notebooks assume this
|
||||
# even though they shouldn't
|
||||
shell.execute("pass")
|
||||
shell.get_msg()
|
||||
while True:
|
||||
try:
|
||||
iopub.get_msg(timeout=1)
|
||||
except Empty:
|
||||
break
|
||||
|
||||
successes = 0
|
||||
failures = 0
|
||||
errors = 0
|
||||
for ws in nb.worksheets:
|
||||
for i, cell in enumerate(ws.cells):
|
||||
if cell.cell_type != 'code':
|
||||
continue
|
||||
try:
|
||||
outs = run_cell(shell, iopub, cell)
|
||||
except Exception as e:
|
||||
print("failed to run cell:", repr(e))
|
||||
print(cell.input)
|
||||
errors += 1
|
||||
continue
|
||||
|
||||
failed = False
|
||||
if len(outs) != len(cell.outputs):
|
||||
print("output length mismatch (expected {}, got {})".format(
|
||||
len(cell.outputs), len(outs)))
|
||||
failed = True
|
||||
for out, ref in zip(outs, cell.outputs):
|
||||
if not compare_outputs(out, ref):
|
||||
failed = True
|
||||
print("cell %d: " % i, end="")
|
||||
if failed:
|
||||
print("FAIL")
|
||||
failures += 1
|
||||
else:
|
||||
print("OK")
|
||||
successes += 1
|
||||
|
||||
print()
|
||||
print("tested notebook %s" % nb.metadata.name)
|
||||
print(" %3i cells successfully replicated" % successes)
|
||||
if failures:
|
||||
print(" %3i cells mismatched output" % failures)
|
||||
if errors:
|
||||
print(" %3i cells failed to complete" % errors)
|
||||
kc.stop_channels()
|
||||
km.shutdown_kernel()
|
||||
del km
|
||||
if failures | errors:
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
for ipynb in sys.argv[1:]:
|
||||
print("testing %s" % ipynb)
|
||||
with open(ipynb) as f:
|
||||
nb = reads(f.read(), 'json')
|
||||
test_notebook(nb)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2010, 2012, 2013 Laboratoire de Recherche et Développement
|
||||
# de l'Epita
|
||||
# Copyright (C) 2010, 2012, 2013, 2014 Laboratoire de Recherche et
|
||||
# Développement de l'Epita
|
||||
# Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
# et Marie Curie.
|
||||
|
|
@ -20,7 +20,6 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import spot
|
||||
import buddy
|
||||
import sys
|
||||
|
||||
|
|
@ -33,6 +32,8 @@ c = buddy.bdd_ithvar(2)
|
|||
|
||||
w = -a & -b | -c & b | a & -b
|
||||
|
||||
import spot
|
||||
|
||||
isop = spot.minato_isop(w)
|
||||
|
||||
i = isop.next()
|
||||
|
|
|
|||
632
wrap/python/tests/randltl.ipynb
Normal file
632
wrap/python/tests/randltl.ipynb
Normal file
|
|
@ -0,0 +1,632 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:b16de2c9883c0fecb450f9d7f4885937abcfc1d1fef584d47109fcee13a68c9a"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
"worksheets": [
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 1,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Documentation for spot's randltl python binding"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": true,
|
||||
"input": [
|
||||
"import spot"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 1
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 2,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Basic usage"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Generate random formulas from specified atomic propositions:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(['a', 'b', 'c'])\n",
|
||||
"for i in range(3):\n",
|
||||
" print(next(f))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"0\n",
|
||||
"0 R b\n",
|
||||
"F(XG(F!b M Fb) W (b R a))\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 2
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Generate random formulas using 3 atomic propositions:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3)\n",
|
||||
"for i in range(3):\n",
|
||||
" print(next(f))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"0\n",
|
||||
"0 R p1\n",
|
||||
"F(XG(F!p1 M Fp1) W (p1 R p0))\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 3
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"By default, there is no limit to the number of formulas generated.<br/>\n",
|
||||
"To specify a number of formulas:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3, 4)\n",
|
||||
"for formula in f:\n",
|
||||
" print(formula)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"0\n",
|
||||
"0 R p1\n",
|
||||
"F(XG(F!p1 M Fp1) W (p1 R p0))\n",
|
||||
"F(p0 R !p2)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 4
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 2,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Keyword arguments"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 2,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"seed"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Seed for the pseudo random number generator (default: 0)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3, seed=11)\n",
|
||||
"print(next(f))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"G(p1 U Gp0)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 12
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"output"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Type of formulas to output: 'ltl', 'psl', 'bool' or 'sere' (default: 'ltl')."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3, output='psl', seed=332)\n",
|
||||
"print(next(f))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"{{p0 && p2}[*]}<>-> (Fp2 & Fp0)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 26
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"allow_dups"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Allow duplicate formulas (default: False)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(1, allow_dups=True)\n",
|
||||
"print(next(f))\n",
|
||||
"print(next(f))\n",
|
||||
"print(next(f))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"0\n",
|
||||
"0\n",
|
||||
"Fp0\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 27
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"tree_size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Tree size of the formulas generated, before mandatory simplifications (default: 15)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3, tree_size=30, seed=11)\n",
|
||||
"print(next(f))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"G(((p0 U !Xp2) M Gp2) U Gp0)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 29
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"A range can be specified as a tuple:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3, tree_size=(1, 40))\n",
|
||||
"print(next(f))\n",
|
||||
"print(next(f))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"X!(Gp2 M p1) R (!p1 M Xp2)\n",
|
||||
"F(G(F(Gp0 R (1 U Fp1)) M (p1 -> Gp0)) M F((p0 | Fp0) W Gp1))\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 30
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"boolean_priorities, ltl_priorities, sere_priorities, dump_priorities"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3, output='bool', boolean_priorities='and=10,or=0')\n",
|
||||
"for i in range(5):\n",
|
||||
" print(next(f))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"0\n",
|
||||
"!p1 & (p1 <-> p2)\n",
|
||||
"p1\n",
|
||||
"p0 & ((p1 & p2) <-> !(!p0 & p1 & p2))\n",
|
||||
"1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 31
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"To see which operators are available along with their default priorities:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"spot.randltl(3, output='psl', dump_priorities=True)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Use argument ltl_priorities=STRING to set the following LTL priorities:\n",
|
||||
"\n",
|
||||
"ap\t3\n",
|
||||
"false\t1\n",
|
||||
"true\t1\n",
|
||||
"not\t1\n",
|
||||
"F\t1\n",
|
||||
"G\t1\n",
|
||||
"X\t1\n",
|
||||
"Closure\t1\n",
|
||||
"equiv\t1\n",
|
||||
"implies\t1\n",
|
||||
"xor\t1\n",
|
||||
"R\t1\n",
|
||||
"U\t1\n",
|
||||
"W\t1\n",
|
||||
"M\t1\n",
|
||||
"and\t1\n",
|
||||
"or\t1\n",
|
||||
"EConcat\t1\n",
|
||||
"UConcat\t1\n",
|
||||
"\n",
|
||||
"Use argument sere_priorities=STRING to set the following SERE priorities:\n",
|
||||
"\n",
|
||||
"ap\t3\n",
|
||||
"false\t1\n",
|
||||
"true\t1\n",
|
||||
"not\t1\n",
|
||||
"F\t1\n",
|
||||
"G\t1\n",
|
||||
"X\t1\n",
|
||||
"Closure\t1\n",
|
||||
"equiv\t1\n",
|
||||
"implies\t1\n",
|
||||
"xor\t1\n",
|
||||
"R\t1\n",
|
||||
"U\t1\n",
|
||||
"W\t1\n",
|
||||
"M\t1\n",
|
||||
"and\t1\n",
|
||||
"or\t1\n",
|
||||
"EConcat\t1\n",
|
||||
"UConcat\t1\n",
|
||||
"eword\t1\n",
|
||||
"boolform\t1\n",
|
||||
"star\t1\n",
|
||||
"star_b\t1\n",
|
||||
"fstar\t1\n",
|
||||
"fstar_b\t1\n",
|
||||
"and\t1\n",
|
||||
"andNLM\t1\n",
|
||||
"or\t1\n",
|
||||
"concat\t1\n",
|
||||
"fusion\t1\n",
|
||||
"\n",
|
||||
"Use argument boolean_priorities=STRING to set the following Boolean formula priorities:\n",
|
||||
"\n",
|
||||
"ap\t3\n",
|
||||
"false\t1\n",
|
||||
"true\t1\n",
|
||||
"not\t1\n",
|
||||
"F\t1\n",
|
||||
"G\t1\n",
|
||||
"X\t1\n",
|
||||
"Closure\t1\n",
|
||||
"equiv\t1\n",
|
||||
"implies\t1\n",
|
||||
"xor\t1\n",
|
||||
"R\t1\n",
|
||||
"U\t1\n",
|
||||
"W\t1\n",
|
||||
"M\t1\n",
|
||||
"and\t1\n",
|
||||
"or\t1\n",
|
||||
"EConcat\t1\n",
|
||||
"UConcat\t1\n",
|
||||
"eword\t1\n",
|
||||
"boolform\t1\n",
|
||||
"star\t1\n",
|
||||
"star_b\t1\n",
|
||||
"fstar\t1\n",
|
||||
"fstar_b\t1\n",
|
||||
"and\t1\n",
|
||||
"andNLM\t1\n",
|
||||
"or\t1\n",
|
||||
"concat\t1\n",
|
||||
"fusion\t1\n",
|
||||
"ap\t3\n",
|
||||
"false\t1\n",
|
||||
"true\t1\n",
|
||||
"not\t1\n",
|
||||
"equiv\t1\n",
|
||||
"implies\t1\n",
|
||||
"xor\t1\n",
|
||||
"and\t1\n",
|
||||
"or\t1\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 32
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"simplify"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"0 No rewriting<br/>\n",
|
||||
"1 basic rewritings and eventual/universal rules<br/>\n",
|
||||
"2 additional syntactic implication rules<br/>\n",
|
||||
"3 better implications using containment<br/>\n",
|
||||
"default: 3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3, simplify=0, seed=5)\n",
|
||||
"print(next(f))\n",
|
||||
"f = spot.randltl(3, simplify=3, seed=5)\n",
|
||||
"print(next(f))"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"G!(!p2 & (Xp1 | F(p0 R Xp1)))\n",
|
||||
"G(p2 | (X!p1 & G(!p0 U X!p1)))\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 36
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 2,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Filters and maps"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"most boolean functions found in the class formula can be used to filter the random formula generator like this:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3, 20).is_syntactic_stutter_invariant()\n",
|
||||
"for formula in f:\n",
|
||||
" print(formula)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"0\n",
|
||||
"0 R p1\n",
|
||||
"F(p0 R !p2)\n",
|
||||
"G(p0 | Fp1) W (FGp1 R !p1)\n",
|
||||
"(p1 R G!p2) | G(p1 U !p0)\n",
|
||||
"(p1 W p0) U p1\n",
|
||||
"F!G(!Gp2 W p2)\n",
|
||||
"G!p2 & (!((p1 & Fp2) M p2) U p2)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 40
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"likewise, functions from formula to formula can be applied to map the iterator:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(2, 6).remove_x()\n",
|
||||
"for formula in f:\n",
|
||||
" print(formula)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"0\n",
|
||||
"!(F!p1 M 1)\n",
|
||||
"(Fp1 | Gp0) M 1\n",
|
||||
"F!(!p1 <-> FGp1)\n",
|
||||
"Gp1 U (p1 U GFp1)\n",
|
||||
"(!p1 U p1) U ((p0 & (p0 U (!p0 & (!p0 -> Fp1))) & ((p1 U !p0) | (!p1 U !p0))) | (!p0 & (!p0 U (p0 & (!p0 -> Fp1))) & ((!p1 U p0) | (p1 U p0))) | (p1 & (p1 U (!p1 & (!p0 -> Fp1))) & ((!p0 U !p1) | (p0 U !p1))) | (!p1 & (!p1 U (p1 & (!p0 -> Fp1))) & ((!p0 U p1) | (p0 U p1))) | ((!p0 -> Fp1) & (Gp0 | G!p0) & (Gp1 | G!p1)))\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 42
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"You may have noticed that the return type of randltl is 'formulaiterator'.<br/>\n",
|
||||
"Since the boolean functions and the 'mapping' functions return an iterator of the same type, this means these operations can be chained like this:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"f = spot.randltl(3, 20).is_syntactic_stutter_invariant().relabel(spot.Abc).simplify()\n",
|
||||
"for formula in f:\n",
|
||||
" print(formula)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"0\n",
|
||||
"Ga\n",
|
||||
"F(a R !b)\n",
|
||||
"G(a | Fb) | (FGb R !b)\n",
|
||||
"G!b | G(a U !c)\n",
|
||||
"b U a\n",
|
||||
"0\n",
|
||||
"0\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 44
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2010, 2011 Laboratoire de Recherche et Developpement de
|
||||
# l'EPITA (LRDE).
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2010, 2011, 2014, 2015 Laboratoire de Recherche et
|
||||
# Developpement de l'EPITA (LRDE).
|
||||
# Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6
|
||||
# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
|
||||
# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
|
||||
# Pierre et Marie Curie.
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
@ -36,11 +36,14 @@ test -z "$1" &&
|
|||
PYTHONPATH=$pypath DYLD_LIBRARY_PATH=$modpath exec @PYTHON@
|
||||
|
||||
case $1 in
|
||||
*.ipynb)
|
||||
PYTHONPATH=$pypath DYLD_LIBRARY_PATH=$modpath \
|
||||
exec @PYTHON@ @srcdir@/ipnbdoctest.py "$@";;
|
||||
*.py)
|
||||
PYTHONPATH=$pypath DYLD_LIBRARY_PATH=$modpath exec @PYTHON@ "$@";;
|
||||
*.test)
|
||||
exec sh -x "$@";;
|
||||
ipython*)
|
||||
*python*)
|
||||
PYTHONPATH=$pypath DYLD_LIBRARY_PATH=$modpath exec "$@";;
|
||||
*)
|
||||
echo "Unknown extension" >&2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue