In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Property.hs 1.84 KB
Newer Older
Philipp Meyer's avatar
Philipp Meyer committed
1 2 3 4
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

module Property
    (Property(..),
5
     showPropertyName,
Philipp Meyer's avatar
Philipp Meyer committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
     PropertyType(..),
     Formula(..),
     LinearInequation(..),
     Op(..),
     Term(..),
     LinAtom(..))
where

import Data.List (intercalate)

data LinAtom = Var Integer String | Const Integer

instance Show LinAtom where
        show (Var c x) | c == 1 = x
        show (Var c x) | c == -1 = "-" ++ x
        show (Var c x) = show c ++ "*" ++ x
        show (Const c) = show c

data Term = Term [LinAtom]

instance Show Term where
        show (Term xs) = intercalate " + " (map show xs)

data Op = Gt | Ge | Eq | Le | Lt

instance Show Op where
        show Gt = ">"
33
        show Ge = "≥"
Philipp Meyer's avatar
Philipp Meyer committed
34
        show Eq = "="
35
        show Le = "≤"
Philipp Meyer's avatar
Philipp Meyer committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
        show Lt = "<"

data LinearInequation = LinIneq Term Op Term

instance Show LinearInequation where
        show (LinIneq lhs op rhs) = show lhs ++ " " ++ show op ++ " " ++ show rhs

data Formula = Atom LinearInequation
             | Neg Formula
             | Formula :&: Formula
             | Formula :|: Formula

infixr 3 :&:
infixr 2 :|:

instance Show Formula where
        show (Atom a) = show a
53
        show (Neg p) = "¬" ++ "(" ++ show p ++ ")"
Philipp Meyer's avatar
Philipp Meyer committed
54 55 56 57 58 59 60 61 62
        show (p :&: q) = "(" ++ show p ++ " ∧ " ++ show q ++ ")"
        show (p :|: q) = "(" ++ show p ++ " ∨ " ++ show q ++ ")"

data PropertyType = Safety | Liveness

instance Show PropertyType where
        show Safety = "safety"
        show Liveness = "liveness"

63 64 65 66 67
data Property = Property {
        pname :: String,
        ptype :: PropertyType,
        pformula :: Formula
}
Philipp Meyer's avatar
Philipp Meyer committed
68 69

instance Show Property where
70
        show p =
71
            showPropertyName p ++ " { " ++ show (pformula p) ++ " }"
Philipp Meyer's avatar
Philipp Meyer committed
72

73
showPropertyName :: Property -> String
74
showPropertyName p = show (ptype p) ++ " property" ++
75
               (if null (pname p) then "" else " " ++ show (pname p))