Package: pyModelChecking
pyModelCheckingpyModelCheckingis a small Python model checking package. Currently, it is
able to representKripke structures,CTL,LTL, andCTL*formulas and it providesmodel checkingmethods
for LTL, CTL, and CTL*. In future, it will hopefully support symbolic model
checking.DocumentationHereyou can find thepyModelCheckingdocumenation. It contains:a brief introduction to Kripke structures, temporal logics and model checkingthe user manual and some examplesthe API manualExamplesFirst of all, import all the functions and all the classes in the package.>>>frompyModelCheckingimport*In order to represent a Kripke structure use theKripkeclass.>>> K=Kripke(R=[(0,0),(0,1),(1,2),(2,2),(3,3)],
...          L={0: set(['p']), 1:set(['p','q']),3:set(['p'])})CTL can be represented by importing theCTLmodule.>>>frompyModelChecking.CTLimport*>>>phi=AU(True,Or('q',Not(EX('p'))))>>>print(phi)A(TrueU(qornot(EXp)))Whenever a non-CTL formula is built, an exception is thrown.>>>psi=A(F(G('p')))Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"pyModelChecking/CTL/language.py",line42,in__init__self.wrap_subformulas(phi,StateFormula)File"pyModelChecking/CTLS/language.py",line59,inwrap_subformulasphi.__desc__,phi))TypeError:expectedaCTLstateformula,gottheCTLpathformulaGpIt is also possible to parse a string representing a CTL formula by using
theParserclass in the moduleCTL.>>>parser=Parser()>>>psi=parser("A(true U (q or not E X p))")>>>print(psi)A(TrueU(qornotEXp))>>>print(psi.__class__)<class'pyModelChecking.CTL.language.A'>The functionmodelcheckin the moduleCTLfinds the states of Kripke
structure that model a given CTL formula.>>>modelcheck(K,phi)set([1,2])The formulaAFG p, which we tried to build above, is a LTL formula. TheLTLmodule can be used to represent and model check it on any Kripke
structure.>>>frompyModelChecking.LTLimport*>>>psi=A(F(G('p')))>>>print(psi)A(G(F(p))>>>modelcheck(K,psi)set([3])Strings representing formulas in the opportune language can be used as a
parameter of the model checking function too.>>>modelcheck(K,'A G F p')set([3])The moduleCTLSis meant to deal with CTL* formulas. It can also combine and
model checks CTL and LTL formulas.>>>frompyModelChecking.CTLSimport*>>>eta=A(F(E(U(True,Imply('p',Not('q'))))))>>>print(eta,eta.__class__)(A(F(E((TrueU(p-->notq))))),<class'pyModelChecking.CTLS.language.A'>)>>>rho=A(G(And(X('p'),'p')))>>>print(rho,rho.__class__)(A(G((X(p)andp))),<class'pyModelChecking.CTLS.language.A'>)>>>gamma=And(phi,psi)>>>print(gamma,gamma.__class__)(A(TrueU(qornot(EXp)))andA(G(F(p)))),<class'pyModelChecking.CTLS.language.And'>)>>>modelcheck(K,eta)set([0,1,2,3])>>>modelcheck(K,psi)set([3])>>>modelcheck(K,gamma)set([])Whenever a CTL* formula is a CTL formula (LTL formula), CTL (LTL) model
checking can be applied to it.>>>importpyModelChecking.CTLasCTL>>>CTL.modelcheck(K,eta)set([0,1,2,3])>>>CTL.modelcheck(K,rho)Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"pyModelChecking/CTL/model_checking.py",line183,inmodelcheckraiseRuntimeError('%sis not a CTL formula'%(formula))RuntimeError:A(G((X(p)andp)))isnotaCTLformula>>>importpyModelChecking.LTLasLTL>>>LTL.modelcheck(K,rho)set([3])Copyright and licensepyModelChecking
Copyright (C) 2015-2019  Alberto Casagrandeacasagrande@units.itpyModelChecking is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.