@@ -6,18 +6,23 @@ import Typedefs.Names
66import Data.Vect
77import PetriGraph
88
9+ public export
910TNat : TDefR 2
1011TNat = RRef 0
1112
13+ public export
1214TEdges : TDefR 2
1315TEdges = RRef 1
1416
17+ public export
1518TState : TDefR 3
1619TState = RRef 2
1720
21+ public export
1822TPetriSpec : TDefR 2
1923TPetriSpec = TProd [TNat , TEdges ]
2024
25+ public export
2126convertSpec : Ty [Nat , List (List Nat , List Nat )] TPetriSpec -> Maybe (n ** PetriSpec n)
2227convertSpec (places, edges) =
2328 MkDPair (length edges) . MkPetriSpec places <$> convertList places (fromList edges)
@@ -27,6 +32,7 @@ convertSpec (places, edges) =
2732 convertList p = traverse (\ (a, b) => [| MkPair (traverse (\ v => natToFin v p) a)
2833 (traverse (\ v => natToFin v p) b) | ])
2934
35+ public export
3036TTree : TDefR 1
3137TTree = TMu
3238 [ (" Tensor" , TProd [TVar 0 , TVar 0 ])
@@ -36,13 +42,25 @@ TTree = TMu
3642 , (" Mor" , TVar 1 )
3743 ]
3844
45+ -- converts from TDef to Tree
3946convertTree : Ty [Nat ] TTree -> (Tree Nat Nat )
4047convertTree (Inn (Left (a, b))) = Tensor (convertTree a) (convertTree b)
4148convertTree (Inn (Right (Left (a, b)))) = Sequence (convertTree a) (convertTree b)
4249convertTree (Inn (Right (Right (Left (a, b))))) = Sym a b
4350convertTree (Inn (Right (Right (Right (Left i))))) = Id i
4451convertTree (Inn (Right (Right (Right (Right m))))) = Mor m
4552
53+
54+ -- converts from Tree to TDef
55+ export
56+ convertTree' : Tree Nat Nat -> Ty [Nat ] TTree
57+ convertTree' (Tensor a b) = (Inn (Left (convertTree' a, convertTree' b)))
58+ convertTree' (Sequence a b) = (Inn (Right (Left (convertTree' a, convertTree' b))))
59+ convertTree' (Sym a b) = (Inn (Right (Right (Left (a, b)))))
60+ convertTree' (Id x) = (Inn (Right (Right (Right (Left x)))))
61+ convertTree' (Mor x) = (Inn (Right (Right (Right (Right x)))))
62+
63+ public export
4664convertState : (spec : PetriSpec k) -> List Nat -> Maybe (PetriState spec)
4765convertState spec = traverse (\ s => natToFin s (Places spec))
4866
@@ -51,8 +69,9 @@ TPetriExec : TDefR 3
5169TPetriExec = TProd [TProd [RRef 0 , RRef 1 ], RRef 2 , weakenTDef TTree 3 (LTESucc LTEZero )]
5270
5371dropContext : Ty [Nat , a, b] (weakenTDef TTree 3 (LTESucc LTEZero)) -> Ty [Nat ] TTree
72+ dropContext tdef = really_believe_me tdef
5473
55- export
74+ public export
5675convertExec : Ty [Nat , List (List Nat , List Nat ), List Nat ] TPetriExec -> Maybe PetriExec
5776convertExec ((a, b), c, d) = do (k ** spec) <- convertSpec (a , b)
5877 path <- checkTree spec (convertTree $ dropContext d)
0 commit comments