Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
a50a9c0
fgl implements Show for Patricia trees from 5.5.0.0 on
hbasold Jun 14, 2014
fd984e7
Merge branch 'ShowGraph' into develop
hbasold Jun 14, 2014
f82c023
Give strategy the opportunity to return hints (aka counterexamples)
hbasold Jun 14, 2014
4d977b1
Generate hints if k-induction fails within given depth
hbasold Jun 22, 2014
08ba832
Improve code layout
hbasold Jun 22, 2014
4846537
Use hints feature in examples
hbasold Jun 22, 2014
c7cdb28
Instance of MonadSMT for WriterT
hbasold Jun 22, 2014
ecd520f
Removed dead (commented) code
hbasold Jun 22, 2014
8eef480
Merge branch 'GenCounterEx' into develop
hbasold Jun 23, 2014
363fbd3
Readme about installation etc.
hbasold Oct 13, 2014
ee91d6d
Example of a proof by coinduction
hbasold Apr 19, 2015
dc4e026
Rudementary functionality, variables not streams any more
Jul 7, 2015
98eb001
Implemented initialisation assertion
Aug 28, 2015
3f4d597
Invariant and precondition implemented, but with only one boolean arg…
Sep 1, 2015
beba562
Argument is now a list of boolean expressions
Sep 3, 2015
42c2ccc
Arguments now connected to function body
Sep 10, 2015
603474e
FlowDefs working if no nodes and activeCond used
Sep 14, 2015
1dd0031
Activation condition has to be a function not an expression
Sep 15, 2015
f8f4e91
nodeEnvOut is now a Map, nodeEnvIn still a list
Sep 15, 2015
35d1a0a
FlowDefs now with node usage, but nodes without automatons
Sep 15, 2015
630104b
FlowTrans also activated on a very simple way
Sep 15, 2015
fb292d6
First try on using Idents in Definitions to get TypedExpr from VarEnv
Sep 16, 2015
2f302bb
Revert "First try on using Idents in Definitions to get TypedExpr fro…
Sep 16, 2015
277966c
Reactivated some commented Declarations
Sep 16, 2015
a3cc3b7
Global list of variables, but no correct assignment
Sep 16, 2015
3dc270f
Assignment now working except for transitions
Sep 16, 2015
11e17fc
BMC working on nodes without automatons
Sep 17, 2015
cfcfbff
(0-co)induction working for some nodes
Sep 17, 2015
9a6f2fc
0-coinduction is now k-coinduction
Sep 17, 2015
03a39e0
Added an Args instance declaration for TypedExpr
Sep 23, 2015
2463185
Removed type parameter from TypedExpr and TypedFunc
Sep 23, 2015
1c3b112
Replaced SMTExpr Bool through TypedExpr as argument list
Sep 24, 2015
3b72c18
Enum datatypes (probably) working
Sep 25, 2015
e24dab4
Product datatypes now also working, but not verified
Sep 25, 2015
85f8ee3
Conditional assign implemented correctly
Sep 26, 2015
0206276
Definitions in automaton locations but arguments not correct
Sep 26, 2015
70f22a5
Migration to ghc-7.10
Sep 24, 2015
eb21805
Some improvments for location arguments
Sep 26, 2015
f7a6609
No integer argument for defFunc any more
Sep 26, 2015
e9895ac
Location match no with right arguments
Sep 28, 2015
9065d06
Transitions in automata
Sep 28, 2015
3dad98a
Fixed transitions and definition having only one variable
Sep 28, 2015
f3e4dc8
Fixed bug in project argument bindings
Sep 28, 2015
c623455
Automata have now edges
Sep 28, 2015
e98a37e
Subautomata in locations but buggy
Sep 29, 2015
58136eb
Fixed default in location transitions being bottom
Sep 29, 2015
d752832
Models are being dumped again
Oct 13, 2015
4935c9e
Fixed bug with ProdType models
Oct 14, 2015
539293b
First automaton transition bug fixed
Oct 16, 2015
233dd73
Models with kinduction, too
Oct 17, 2015
963a4c4
Unit not needed anymore
Oct 17, 2015
0207491
Second automaton "bug" fixed
Oct 17, 2015
2db5519
Corrected options in runBase.sh
Oct 17, 2015
e048f33
Created new strategy Invariant and set of terms in environment
Oct 19, 2015
de4633e
Renamed addVar to putVar
Oct 19, 2015
c89f028
First assertions about r made
Oct 19, 2015
68d25cd
Assertion is now correctly conjunctive
Oct 20, 2015
da974b3
Filtering in first step implemented
Oct 20, 2015
d28ad38
More term for relations are being saved
Oct 20, 2015
50cf1df
Filtering is now propably correct
Oct 20, 2015
eaeacac
Automatons now activated conditionally each step
Oct 21, 2015
1f34ba6
Bumped LamaSMT version to 0.2
Oct 21, 2015
4d7891c
Ident for location match enum
Nov 4, 2015
39285f4
Replaced set of idents through list of idents
Nov 9, 2015
2a06155
Default expression's arguments added to argument list
Nov 9, 2015
67cf546
Corrected bug with node returns
Oct 21, 2015
1125d49
Correct default values not being added to argument list
Nov 10, 2015
e4c27b0
Brought node output in right order with list instead of map
Nov 10, 2015
6ca2846
Automatons now activated conditionally each step
Oct 21, 2015
5280ede
Bumped LamaSMT version to 0.2
Oct 21, 2015
b6bec08
Ident for location match enum
Nov 4, 2015
d3f5681
Replaced set of idents through list of idents
Nov 9, 2015
d440cf6
Default expression's arguments added to argument list
Nov 9, 2015
0c23586
Corrected bug with node returns
Oct 21, 2015
6b3096e
Correct default values not being added to argument list
Nov 10, 2015
207a1e1
Brought node output in right order with list instead of map
Nov 10, 2015
2cbc7f1
Added instantiation set for integers
Nov 11, 2015
8c84970
Added option for showing number of invariants
Nov 11, 2015
535a490
Simplification in implementation of getting values for filtering
Nov 23, 2015
6e4b8ba
Instantiation sets are now lists instead of Data.Set
Nov 23, 2015
b6aa006
First implementation of poset graph and assertions
Nov 23, 2015
5eb7792
Trying to create new nodes and edges
Nov 23, 2015
2a21769
Creation of bool invariant now better but not finished
Nov 27, 2015
3a4a4c0
evalTerm gets Value from Solver
Nov 27, 2015
78fa021
Partition of graph nodes implemented but no edges
Nov 27, 2015
c782d62
Implemented building of new Graph
Nov 27, 2015
a807c0d
Empty nodes are removed during building of new graph
Nov 30, 2015
7f19314
invariant-stats instead of invariant-count activated
Nov 30, 2015
641628d
Forgot to assert edges
Nov 30, 2015
1a2f4be
Induction step for invariants is being made. Possibly correct
Dec 1, 2015
570c952
Release LamaSMT-0.2
Dec 4, 2015
bac6b6e
Miscellaneous changes to induction step and assertions
Dec 4, 2015
9e4c990
Optimization regarding the removal of useless nodes
Dec 4, 2015
515bb82
Corrected mistake with useless nodes
Dec 5, 2015
995ad42
Moved poset calculation to dedicated module
Dec 5, 2015
f551d84
Code cleanup, remove redundant imports
Dec 5, 2015
00d9273
Made invariant checks more generic for int implementation
Dec 5, 2015
4088132
Term does now take a type parameter
Dec 7, 2015
9dc6685
Alternatively try to use variables instead of expressions
Dec 8, 2015
b54a9b4
Sorting algorithm for integer invariants
Dec 9, 2015
6e07e9c
Correct union of mapping for sorting
Dec 9, 2015
7eefa03
Renewed invariant statistics
Dec 9, 2015
dc2c2c6
Assert integer equality just once
Dec 9, 2015
69b706c
Introduced option to use just bool or int invariants
Dec 9, 2015
cdbebab
Merge branch 'invariant' into develop
Jan 25, 2016
c6711ef
Some code cleanup and comments
Jan 25, 2016
5c99910
Script for viewing the SMT-LIB stream
Jan 25, 2016
b12608c
Version bump to lamasmt-0.3
Jan 25, 2016
7fadf47
Release LamaSMT-0.3
Jan 25, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions example/Switch-coinduction.smt
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
;; Implementation of Switch.lm by hand for exploration
;; Proves the 3 given properties using (0-)coinduction.
;; There are slight variants (commented) of those
;; properties which are incorrect. Those give the
;; expected counterexamples.

;; node Switch
(define-fun Switch_s_def ((on Bool) (off Bool) (s_1 Bool) (s Bool)) Bool
(= s
(ite s_1 (not off) on)))
(define-fun Switch_s_1_def ((s Bool) (s_1_next Bool)) Bool
(= s_1_next
s ))
(define-fun Switch_so_def ((so Bool) (s Bool)) Bool
(= so
s))

;; Global flow
(define-fun Switch_on_def ((Switch_on Bool) (on Bool)) Bool
(= Switch_on
on))
(define-fun Switch_off_def ((Switch_off Bool) (off Bool)) Bool
(= Switch_off
off))
(define-fun s_def ((Switch_so Bool) (s Bool)) Bool
(= s
Switch_so))
(define-fun s_1_def ((s_1_next Bool) (s Bool)) Bool
(= s_1_next
s))

;; properties
(define-fun prop1 ((off Bool) (on Bool) (s Bool)) Bool
; (=> on s))
(=> (and on (not off)) s))
(define-fun prop2 ((off Bool) (on Bool) (s Bool)) Bool
; (=> off (not s)))
(=> (and off (not on)) (not s)))
(define-fun prop3 ((off Bool) (on Bool) (s Bool) (s_1 Bool)) Bool
(=> (and (not off) (not on)) (= s s_1)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Prove that initial state fulfils property

(push)

;; declarations
(declare-fun Switch_on_0 () Bool)
(declare-fun Switch_off_0 () Bool)
(declare-fun Switch_so_0 () Bool)
(declare-fun Switch_s_0 () Bool)
(declare-fun Switch_s_1_0 () Bool)

(declare-fun on_0 () Bool)
(declare-fun off_0 () Bool)
(declare-fun s_0 () Bool)
(declare-fun s_1_0 () Bool)

(declare-fun Switch_s_1_1 () Bool)
(declare-fun s_1_1 () Bool)

;; initialisation
(assert (= Switch_s_1_0 false))
(assert (= s_1_0 false))

(assert (Switch_on_def Switch_on_0 on_0))
(assert (Switch_off_def Switch_off_0 off_0))

(assert (Switch_so_def Switch_so_0 Switch_s_0))
(assert (Switch_s_def Switch_on_0 Switch_off_0 Switch_s_1_0 Switch_s_0))
(assert (Switch_s_1_def Switch_s_0 Switch_s_1_1))

(assert (s_def s_0 Switch_so_0))
(assert (s_1_def s_1_1 s_0))

;(assert (not (prop1 off_0 on_0 s_0)))
(assert (not (prop2 off_0 on_0 s_0)))
;(assert (not (prop3 off_0 on_0 s_0 s_1_0)))

(check-sat)
(get-model)
(pop)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Prove that property is an invariant

;; declarations
(declare-fun Switch_on () Bool)
(declare-fun Switch_off () Bool)
(declare-fun Switch_so () Bool)
(declare-fun Switch_s () Bool)
(declare-fun Switch_s_1 () Bool)

(declare-fun on () Bool)
(declare-fun off () Bool)
(declare-fun s () Bool)
(declare-fun s_1 () Bool)

(declare-fun Switch_s_1_n1 () Bool)
(declare-fun s_1_n1 () Bool)

(declare-fun Switch_on_n1 () Bool)
(declare-fun Switch_off_n1 () Bool)
(declare-fun Switch_so_n1 () Bool)
(declare-fun Switch_s_n1 () Bool)

(declare-fun on_n1 () Bool)
(declare-fun off_n1 () Bool)
(declare-fun s_n1 () Bool)

(declare-fun Switch_s_1_n2 () Bool)
(declare-fun s_1_n2 () Bool)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Assume that we start in a state in which the invariant holds

;(assert (prop1 off on s))
(assert (prop2 off on s))
;(assert (prop3 off on s s_1))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set up variables in starting state

(assert (Switch_on_def Switch_on on))
(assert (Switch_off_def Switch_off off))

(assert (Switch_so_def Switch_so Switch_s))
(assert (Switch_s_def Switch_on Switch_off Switch_s_1 Switch_s))
(assert (Switch_s_1_def Switch_s Switch_s_1_n1))

(assert (s_def s Switch_so))
(assert (s_1_def s_1_n1 s))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Make transition

(assert (Switch_on_def Switch_on_n1 on_n1))
(assert (Switch_off_def Switch_off_n1 off_n1))

(assert (Switch_so_def Switch_so_n1 Switch_s_n1))
(assert (Switch_s_def Switch_on_n1 Switch_off_n1 Switch_s_1_n1 Switch_s_n1))
(assert (Switch_s_1_def Switch_s_n1 Switch_s_1_n2))

(assert (s_def s_n1 Switch_so_n1))
(assert (s_1_def s_1_n2 s_n1))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Try to prove that property holds after transition
(push)
;(assert (not (prop1 off_n1 on_n1 s_n1)))
(assert (not (prop2 off_n1 on_n1 s_n1)))
;(assert (not (prop3 off_n1 on_n1 s_n1 s_1_n1)))

(check-sat)
(get-model)
(pop)
2 changes: 1 addition & 1 deletion interpreter/LAMA.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description:
Executable test-lama
default-language: Haskell2010
build-depends: base, containers, mtl, bytestring, natural-numbers,
transformers, pretty, array, HUnit, language-lama
transformers, pretty, array, HUnit, language-lama, fgl >= 5.5.0.0
hs-source-dirs: test lib
GHC-Options: -Wall
other-modules:
Expand Down
1 change: 0 additions & 1 deletion interpreter/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Data.Foldable (forM_, foldlM, foldl)
import Lang.LAMA.Identifier
import qualified Data.Map as Map
import Data.Map (Map)
import Data.Graph.Inductive.GenShow ()
import Control.Monad (void, when, MonadPlus(..))
import Control.Monad.Trans.Maybe
import Control.Monad.IO.Class
Expand Down
4 changes: 2 additions & 2 deletions lamaSMT/LamaSMT.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: LamaSMT
Version: 0.1
Version: 0.3
Build-Type: Simple
Cabal-Version: >= 1.10
Description:
Expand All @@ -15,4 +15,4 @@ Executable lamasmt
GHC-Options: -Wall -rtsopts
other-modules:
Transform
Main-Is: Main.hs
Main-Is: Main.hs
39 changes: 31 additions & 8 deletions lamaSMT/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ module Main (main) where

import qualified Data.ByteString.Lazy.Char8 as BL

import Text.PrettyPrint (render)
import Text.PrettyPrint (Doc, render, vcat, text, ($$))
import Data.List.Split (splitOn)
import Data.List (intercalate)
import Data.Natural

import System.IO (stdin)
import System.Environment (getArgs)
Expand Down Expand Up @@ -170,7 +168,7 @@ run opts@Options{..} file inp = do
model <- runCheck opts
( (liftSMT $ mapM_ setOption optSMTOpts) >>
lamaSMT optNatImpl optEnumImpl p >>=
(uncurry $ checkWithModel optNatImpl optStrategy) )
(uncurry $ checkWithModel optStrategy) )
liftIO $ checkModel opts p model

checkErrors :: Either Error a -> MaybeT IO a
Expand Down Expand Up @@ -204,11 +202,36 @@ runCheck progOpts = chooseSolver progOpts . checkError
-- ++ solverBase
-- withPipe solverCmd []

checkModel :: Ident i => Options -> Program i -> Maybe (Natural, Model i) -> IO ()
checkModel _ _ Nothing = putStrLn "42"
checkModel opts prog (Just (lastIndex, m)) =
checkModel :: Ident i =>
Options
-> Program i
-> (StrategyResult i)
-> IO ()
checkModel _ _ Success = putStrLn "42"
checkModel opts prog (Failure lastIndex m) =
do putStrLn ":-("
putStrLn $ "Found counterexample at depth " ++ show lastIndex
when (optDumpModel opts) (putStrLn . render $ prettyModel m)
case optScenarioFile opts of
Nothing -> return ()
Just f -> writeFile f $ render $ scadeScenario prog (optTopNodePath opts) lastIndex m
Just f -> writeFile f $ render $ scadeScenario prog (optTopNodePath opts) m
checkModel opts prog (Unknown what hints) =
do putStrLn ":-("
putStrLn what
when (optDumpModel opts)
(putStrLn . render . prettyHints $ hints)
case optScenarioFile opts of
Nothing -> return ()
Just f ->
mapM_ (\h ->
writeFile (f ++ "_" ++ hintDescr h)
. render
$ scadeScenario prog (optTopNodePath opts) (hintModel h))
hints

prettyHints :: Ident i => Hints i -> Doc
prettyHints = vcat . map prettyHint
where
prettyHint h
= text ("Hint for " ++ (hintDescr h))
$$ prettyModel (hintModel h)
2 changes: 1 addition & 1 deletion lamaSMT/lib/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module Check where
import Strategy

check :: Strategy s =>
check = undefined
check = undefined
27 changes: 16 additions & 11 deletions lamaSMT/lib/Definition.hs
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
module Definition where

import Data.Array as Arr

import Language.SMTLib2 as SMT

import Data.Array as Arr

import LamaSMTTypes
import Internal.Monads

data Definition =
SingleDef (Stream Bool)
SingleDef [Int] Bool (SMTFunction [TypedExpr] Bool)
| ProdDef (Array Int Definition)
-- deriving Show
deriving Show

ensureDefinition :: TypedStream i -> Definition
ensureDefinition (BoolStream s) = SingleDef s
ensureDefinition (ProdStream ps) = ProdDef $ fmap ensureDefinition ps
ensureDefinition _
= error $ "ensureDefinition: not a boolean stream" -- : " ++ show s
ensureDefinition :: [Int] -> Bool -> TypedFunc -> Definition
ensureDefinition argN succ (BoolFunc s) = SingleDef argN succ s
ensureDefinition argN succ (ProdFunc ps) = ProdDef $ fmap (ensureDefinition argN succ) ps
ensureDefinition _ _ _
= error $ "ensureDefinition: not a boolean function"

assertDefinition :: MonadSMT m =>
(SMTExpr Bool -> SMTExpr Bool)
-> StreamPos
-> ([TypedExpr], [TypedExpr])
-> Definition
-> m ()
assertDefinition f i (SingleDef s) = liftSMT $ assert (f $ s `app` i)
assertDefinition f i (SingleDef argN succ s) = liftSMT $ assert (f $ s `app` (lookupArgs argN succ i))
assertDefinition f i (ProdDef ps) = mapM_ (assertDefinition f i) $ Arr.elems ps

lookupArgs :: [Int] -> Bool -> ([TypedExpr], [TypedExpr])
-> [TypedExpr]
lookupArgs argN True vars = [(snd vars) !! (head argN)] ++ (map ((!!) (fst vars)) $ tail argN)
lookupArgs argN False vars = map ((!!) (fst vars)) argN

data ProgDefs = ProgDefs
{ flowDef :: [Definition]
, precondition :: Definition
Expand Down
4 changes: 4 additions & 0 deletions lamaSMT/lib/Internal/Monads.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Control.Monad.Error
import Control.Monad.State.Lazy as Lazy
import Control.Monad.State.Strict as Strict
import Control.Monad.Reader
import Control.Monad.Writer

-- | Lift an SMT action into an arbitrary monad (like liftIO).
class Monad m => MonadSMT m where
Expand All @@ -25,3 +26,6 @@ instance MonadSMT m => MonadSMT (Strict.StateT s m) where

instance MonadSMT m => MonadSMT (ReaderT r m) where
liftSMT = lift . liftSMT

instance (Monoid w, MonadSMT m) => MonadSMT (WriterT w m) where
liftSMT = lift . liftSMT
Loading