Last active
June 20, 2018 09:53
-
-
Save Agnishom/a561525f3d0104b8f441c9908bee5ef0 to your computer and use it in GitHub Desktop.
Vector Addition State Systems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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