Created
January 8, 2016 19:13
-
-
Save Isweet/bf287cc362225e8d2b75 to your computer and use it in GitHub Desktop.
Possible model for computing equational analysis, based on RD from Ch. 1 of NNH
This file contains 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
import qualified Data.Set as Set | |
import qualified Data.Array.IArray as Array | |
type Var = String | |
type Lab = Integer | |
type RD = Set.Set (Var, Lab) | |
type VecRD = Array.Array Integer RD | |
type VecF = Array.Array Integer (Solution -> RD) | |
data Solution = Solution { entryRD :: VecRD | |
, exitRD :: VecRD | |
} deriving (Show, Eq) | |
data Solver = Solver { entryF :: VecF | |
, exitF :: VecF | |
} | |
genIter :: Integer -> Solver -> Solution -> Solution | |
genIter l s rd = Solution { entryRD = entries, exitRD = exits } | |
where | |
entries = Array.array (1, l) [ (i, ((entryF s) Array.! i) rd) | i <- [1..l]] | |
exits = Array.array (1, l) [ (i, ((exitF s) Array.! i) rd) | i <- [1..l]] | |
-- compute fixpoint | |
fix :: (Eq a) => a -> (a -> a) -> a | |
fix start f = | |
if start == next then | |
start | |
else | |
fix next f | |
where | |
next = f start | |
main = do | |
let tmp = Array.array (1, 6) [(i, Set.empty) | i <- [1..6]] :: VecRD | |
let solu = Solution { entryRD = tmp, exitRD = tmp } | |
let entrys = Array.array (1, 6) [ (1, (\ rd -> Set.fromList [("x", -1), ("y", -1), ("z", -1)])) | |
, (2, (\ rd -> (exitRD rd) Array.! 1)) | |
, (3, (\ rd -> Set.unions [(exitRD rd) Array.! 2, (exitRD rd) Array.! 5])) | |
, (4, (\ rd -> (exitRD rd) Array.! 3)) | |
, (5, (\ rd -> (exitRD rd) Array.! 4)) | |
, (6, (\ rd -> (exitRD rd) Array.! 3)) | |
] :: VecF | |
let exits = Array.array (1, 6) [ (1, (\ rd -> Set.unions [((entryRD rd) Array.! 1) Set.\\ (Set.fromList [("y", l) | l <- [-1..6]]), Set.singleton ("y", 1)])) | |
, (2, (\ rd -> Set.unions [((entryRD rd) Array.! 2) Set.\\ (Set.fromList [("z", l) | l <- [-1..6]]), Set.singleton ("z", 2)])) | |
, (3, (\ rd -> (entryRD rd) Array.! 3)) | |
, (4, (\ rd -> Set.unions [((entryRD rd) Array.! 4) Set.\\ (Set.fromList [("z", l) | l <- [-1..6]]), Set.singleton ("z", 4)])) | |
, (5, (\ rd -> Set.unions [((entryRD rd) Array.! 5) Set.\\ (Set.fromList [("y", l) | l <- [-1..6]]), Set.singleton ("y", 5)])) | |
, (6, (\ rd -> Set.unions [((entryRD rd) Array.! 6) Set.\\ (Set.fromList [("y", l) | l <- [-1..6]]), Set.singleton ("y", 6)])) | |
] :: VecF | |
let solv = Solver { entryF = entrys, exitF = exits } | |
print $ fix solu $ genIter 6 solv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment