Skip to content

Instantly share code, notes, and snippets.

@Agnishom
Last active June 20, 2018 09:53
Show Gist options
  • Select an option

  • Save Agnishom/a561525f3d0104b8f441c9908bee5ef0 to your computer and use it in GitHub Desktop.

Select an option

Save Agnishom/a561525f3d0104b8f441c9908bee5ef0 to your computer and use it in GitHub Desktop.
Vector Addition State Systems
module Lib where
import Data.Graph
import Data.Vector
import Data.Map
newtype State = State Int
data Transition = Transition { addV :: [Int],
toState :: State
}
data Vass = Vass { d :: Int,
states :: Vector State,
transitions :: Map State (Vector Transition)
}
data VassConfig = VassConfig { currentVector :: [Int],
currentState :: State,
vass :: Vass
}
instance Num a => Num [a] where -- definition of addition and multiplication on lists assuming they are polynomials
(f:fs) + (g:gs) = f+g : fs+gs
fs + [] = fs
[] + gs = gs
(f:fs) * (g:gs) = f*g : [f]*gs + fs*(g:gs)
_ * _ = []
abs = undefined -- I can't think of a sensible definition
signum = Prelude.map signum
fromInteger n = [fromInteger n]
negate = Prelude.map (\x -> -x)
fireTransition :: VassConfig -> Transition -> VassConfig
fireTransition (VassConfig v s vs) (Transition u t) = VassConfig (v + u) t vs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment