/
LocalMoves.hs
1023 lines (834 loc) · 33.1 KB
/
LocalMoves.hs
1
2
3
4
5
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module LocalMoves where
import TambaraYamagami as TY
import Algebra
import Finite
import Control.Monad.State
import TwoComplex as TC
import qualified Data.List.NonEmpty as N
import qualified Data.Matrix as M
import qualified Data.Foldable as F
import Data.Semigroup
import qualified Data.Vector as V
import qualified Data.List as L
import qualified Stringnet as S
import Data.Group
import Control.Monad as CM
import qualified Data.Tree as T
import Tree
import TambaraYamagami
-- Tree corresponding to a summand of a vertex-morphism's codomain
data InternalTree = ILeaf Edge SimpleObject
| INode SimpleObject InternalTree InternalTree
deriving (Eq, Show)
rootLabel :: InternalTree -> SimpleObject
rootLabel it =
case it of
ILeaf _ so -> so
INode so _ _ -> so
-- Simple colored graph
data SimpleColoring = SimpleColoring
{ objectLabel :: !(Edge -> SimpleObject)
-- CCW ordering, outgoing orientation
, objectTree :: !(Vertex -> InternalTree)
}
data Stringnet = Stringnet
{ twoComplex :: TC.TwoComplex
, edgeTree :: (Vertex -> Tree Edge)
, colorCoeff :: SimpleColoring -> Scalar
}
-- vertices sn = TC.vertices $ twoComplex sn
-- edges sn = TC.edges $ twoComplex sn
-- disks sn = TC.disks $ twoComplex sn
-- perimeter sn = TC.perimeter $ twoComplex sn
-- imageVertex sn = TC.imageVertex $ twoComplex sn
-- toTensorTree :: Morphism -> Tree Morphism
-- toTensorTree (tensorM x y) =
-- Node (toTensorTree x) (toTensorTree y)
-- toTensorTree x = Leaf x
-- toCompositionList :: Morphism -> [Morphism]
-- toCompositionList (Compose ms) = ms
-- toCompositionList m = [m]
-- toTree :: Morphism -> T.Tree (Maybe Morphism)
-- -- toTree m@(Compose _) =
-- -- T.Node Nothing (map toTree $ toCompositionList m)
-- toTree (tensorM x y) =
-- T.Node Nothing [(toTree x), (toTree y)]
-- toTree x = T.Node (Just x) []
instance Semigroup Morphism where
a <> b = compose a b
-- toDataTree :: Tree a -> T.Tree (Maybe a)
-- toDataTree (Leaf x) = T.Node (Just x) []
-- toDataTree (Node x y) = T.Node Nothing [toDataTree x, toDataTree y]
-- -- Pretty print
-- pprint :: (Show a) => Tree a-> IO ()
-- pprint = putStr. T.drawTree . fmap (\x -> case x of
-- Nothing -> "+"
-- Just e -> show e
-- )
-- . toDataTree
-- Monadic versions of methods
edgeTreeM :: Vertex -> State Stringnet (Tree Edge)
edgeTreeM v = state $ \sn -> (edgeTree sn v, sn)
endpointsM :: Edge -> State Stringnet [Vertex]
endpointsM e = state $ \sn -> (endpoints e (twoComplex sn), sn)
perimeterM :: Disk -> State Stringnet [Edge]
perimeterM d = state $ \sn -> (perimeter (twoComplex sn) d, sn)
treeLabel :: (Edge -> Object) -> Tree Edge -> Object
treeLabel label (Leaf e) = label e
treeLabel label (Node x y) =
tensorO (treeLabel label x) (treeLabel label y)
-- perimeter before contractions
initialPerimeter :: Disk -> [Edge]
initialPerimeter Outside = [IE LeftLoop, IE RightLoop]
initialPerimeter LeftDisk =
[Reverse $ IE LeftLoop, IE LeftLeg, Reverse $ IE LeftLeg]
initialPerimeter RightDisk =
[Reverse $ IE RightLoop, IE RightLeg, Reverse $ IE RightLeg]
initialEdgeTree :: Vertex -> Tree Edge
initialEdgeTree v = case v of
Punc LeftPuncture -> Leaf $ Reverse $ IE LeftLeg
Punc RightPuncture -> Leaf $ Reverse $ IE RightLeg
IV Main ->
Node
(Node
(Leaf $ Reverse $ IE RightLoop)
(Node
(Leaf $ IE RightLeg)
(Leaf $ IE RightLoop)
)
)
(Node
(Leaf $ Reverse $ IE LeftLoop)
(Node
(Leaf $ IE LeftLeg)
(Leaf $ IE LeftLoop)
)
)
-- objectLabel0 :: InitialBasisElement -> Edge -> Object
-- objectLabel0 be (IE e) = toObject $ initialLabel be e
-- objectLabel0 be (FirstHalf e) = objectLabel0 be e
-- objectLabel0 be (SecondHalf e) = objectLabel0 be e
-- objectLabel0 be (Connector _ _ _) = toObject one
-- objectLabel0 be (TensorE e1 e2)
-- = tensorO (objectLabel0 be e1) (objectLabel0 be e2)
-- objectLabel0 be (Reverse e) = star (objectLabel0 be e)
initialTwoComplex :: TwoComplex
initialTwoComplex =
TwoComplex
{ vertices = [Main]
, edges = map IE [LeftLoop, RightLoop, LeftLeg, RightLeg]
, disks = [Outside, LeftDisk, RightDisk]
, imageVertex = id
, perimeter = initialPerimeter
}
-- initialSimpleColoring :: InitialBasisElement -> SimpleColoring
-- initialSimpleColoring basisElement =
-- SimpleColoring { twoComplex = initialTwoComplex
-- , morphismLabel = \m ->
-- case m of Main
-- -> morphismFromBE basisElement
-- , edgeTree = initialEdgeTree
-- , objectLabel = objectLabel0 basisElement
-- }
braid :: State Stringnet ()
braid = do
(_,l1,r1) <- addCoev $ IE LeftLoop
(_,l2,r2) <- addCoev $ IE LeftLeg
(_,r13,l3) <- addCoev r1
(_,_,r4) <- addCoev $ IE RightLoop
e1 <- connect (rev l1) r2 LeftDisk
e2 <- connect (rev l2) (rev r13) (Cut $ e1)
e3 <- connect l3 r4 Outside
contract e1
contract e2
contract e3
tensor (Cut $ rev e1)
tensor (Cut $ rev e2)
tensor (Cut $ rev e3)
v <- contract r4
-- At this point we're done with local moves, but we still need to
-- modify the final vertex's edge tree. It should look the same as
-- the initial edge tree, except left and right are swapped. This is
-- somewhat implementation-dependent since I haven't specified
-- complete edgeTree behavior for most of the local moves.
--
-- TODO: make a method to turn a tree into a specified shape
--
-- Current Edgetree:
--
--
--
-- +
-- |
-- +- +
-- | |
-- | +- +
-- | | |
-- | | +- +
-- | | | |
-- | | | +- Reverse (FirstHalf (SecondHalf LeftLoop))
-- | | | |
-- | | | `- SecondHalf LeftLeg
-- | | |
-- | | `- FirstHalf (SecondHalf LeftLoop)
-- | |
-- | `- TensorE (TensorE (TensorE (Reverse (FirstHalf LeftLoop)) (Reverse (FirstHalf LeftLeg))) (SecondHalf (SecondHalf LeftLoop))) (Reverse (FirstHalf RightLoop))
-- |
-- `- +
-- |
-- +- RightLeg
-- |
-- `- Reverse (TensorE (TensorE (TensorE (Reverse (FirstHalf LeftLoop)) (Reverse (FirstHalf LeftLeg))) (SecondHalf (SecondHalf LeftLoop))) (Reverse (FirstHalf RightLoop)))
associateR v
(Node
(Node
(Leaf (Reverse (FirstHalf (SecondHalf $ IE LeftLoop))))
(Leaf (SecondHalf $ IE LeftLeg))
)
(Leaf (FirstHalf (SecondHalf $ IE LeftLoop)))
)
et <- edgeTreeM (IV v)
associateR v et
return ()
newInitialEdge :: InitialEdge -> Edge
newInitialEdge ie =
case ie of
RightLeg -> SecondHalf (IE LeftLeg)
RightLoop -> FirstHalf (SecondHalf (IE LeftLoop))
LeftLeg -> IE RightLeg
LeftLoop -> Reverse (TensorE (TensorE (TensorE (Reverse (FirstHalf (IE LeftLoop))) (Reverse (FirstHalf (IE LeftLeg)))) (SecondHalf (SecondHalf (IE LeftLoop)))) (Reverse (FirstHalf (IE RightLoop))))
--fragile
-- midMorphism :: InitialBasisElement -> State Stringnet () -> Morphism
-- midMorphism be st =
-- let
-- cg = (execState st . initialSimpleColoring) be
-- in
-- morphismLabel cg (vertices cg !! 0)
-- finalSN :: InitialBasisElement -> SimpleColoring
-- finalSN = execState braid . initialSimpleColoring
-- finalVertex :: InitialBasisElement -> InteriorVertex
-- finalVertex be = vertices (finalSN be) !! 0
-- finalMorphism :: InitialBasisElement -> Morphism
-- finalMorphism be = morphismLabel (finalSN be) (finalVertex be)
-- finalEdgeTree :: InitialBasisElement -> Tree Edge
-- finalEdgeTree be = edgeTree (finalSN be) $ IV (finalVertex be)
-- finalObjectTree :: InitialBasisElement -> Tree Object
-- finalObjectTree be = fmap (objectLabel (finalSN be)) $ finalEdgeTree be
-- TODO: fix this
-- instance Num Object where
-- o1 + o2 = Object $ multiplicity o1 + multiplicity o2
-- o1 * o2 = o1 `tensorO` o2
-- fromInteger = undefined -- could change
-- negate _ = undefined
-- signum _ = undefined
-- abs _ = undefined
-- instance Num Morphism where
-- m1 + m2 =
-- Morphism
-- { domain = if (domain m1) == (domain m2)
-- then domain m1
-- else undefined
-- , codomain = if (codomain m1) == (codomain m2)
-- then codomain m1
-- else undefined
-- , subMatrix = (subMatrix m1) + (subMatrix m2)
-- }
-- m1 * m2 = m1 `tensorM` m2
-- fromInteger _ = undefined
-- negate _ = undefined
-- signum _ = undefined
-- abs _ = undefined
-- expandRows :: [Int] -> M.Matrix a -> Int -> M.Matrix a
-- expandRows indices m multiple =
-- let list = M.toLists m in
-- (take index list)
-- ++ repeat multiple (list !! index)
-- ++ drop index list
-- expandColumn :: Int -> M.Matrix a -> Int -> M.Matrix a
-- expandColumn index m multiple =
-- transpose $ expandRow (transpose M) index multiple
-- tensorInv :: SimpleObject -> [(SimpleObject, SimpleObject)]
-- tensorInv so =
-- case so of
-- M -> [(M, AE ae) | ae <- group] ++ [(AE ae, M) | ae <- group]
-- AE ae -> [(ae1, ae2) |
-- ae1 <- group,
-- ae2 <- group,
-- ae1 `plus` ae2 == ae]
-- ++ [(M,M)]
-- ------------------------------------------------------
-- -- Substituting TY labels for arbitrary ones
-- ------------------------------------------------------
-- Substitute in the TY-specific objects.
-- substO :: (InitialEdge -> SimpleObject) -> Object -> Object
-- substO il o0 = case o0 of
-- OVar ie -> toObject $ il ie
-- One -> toObject $ AE (AElement 0)
-- Star o -> star $ substO il o
-- TensorO o1 o2 -> (substO il o1) `tensorO` (substO il o2)
type InitialData = (InitialEdge -> SimpleObject, Morphism)
-- standard (nondiagrammatic) order
compose :: Morphism -> Morphism -> Morphism
compose m1 m2 =
if domain m1 /= codomain m2
then error $ "Invalid composition: Codomain doesn't match domain. "
++ (show m2) ++ " has codomain: "
++ (show $ codomain m2) ++ ". "
++ (show m1) ++ " has domain: " ++ (show $ domain m1)
else morphism (domain m1) (codomain m2) $ (matrix m1) * (matrix m2)
lambda :: Object -> Morphism
lambda o = idMorphism o
lambdaI :: Object -> Morphism
lambdaI o = idMorphism o
rho :: Object -> Morphism
rho o = idMorphism o
rhoI :: Object -> Morphism
rhoI o = idMorphism o
-- Substitute in the TY-specific morphisms
-- substM :: (InitialEdge -> SimpleObject) -> Morphism -> Morphism -> Morphism
-- substM il phi m = case m of
-- Phi -> phi
-- Id o -> idMorphism $ substO il o
-- Lambda o -> idMorphism $ substO il o
-- LambdaI o -> idMorphism $ substO il o
-- Rho o -> idMorphism $ substO il o
-- RhoI o -> idMorphism $ substO il o
-- TensorM m1 m2 -> (substM il phi m1) `tensorM` (substM il phi m2)
-- Alpha o1 o2 o3 -> alpha (substO il o1) (substO il o2) (substO il o3)
-- AlphaI o1 o2 o3 -> alphaI (substO il o1) (substO il o2) (substO il o3)
-- Coev o -> coev $ substO il o
-- Ev o -> ev $ substO il o
-- PivotalJ o -> pivotalJ $ substO il o
-- PivotalJI o -> pivotalJI $ substO il o
-- Compose sms ->
-- foldl (compose (il, phi)) (substM il phi $ head sms) (tail sms)
allInitialEdges :: [InitialEdge]
allInitialEdges = [LeftLoop, RightLoop, LeftLeg, RightLeg]
numInitialEdges :: Int
numInitialEdges = length allInitialEdges
allInitialLabels :: [InitialEdge -> SimpleObject]
allInitialLabels = map (\x y -> x !! (fromEnum y))
(replicateM (length allInitialEdges) allSimpleObjects)
-- toCodomainSO :: (InitialEdge -> SimpleObject) -> Object
-- toCodomainSO il =
-- substO il $ treeLabel (objectLabel initialSimpleColoring) (initialEdgeTree $ IV Main)
--FIXME: use this function to define an order on InitialBasisElement
toCodomain :: (InitialEdge -> Object) -> Object
toCodomain il =
(star $ il RightLoop)
`tensorO`
(il RightLeg)
`tensorO`
(il RightLoop)
`tensorO`
(star $ il LeftLoop)
`tensorO`
(il LeftLeg)
`tensorO`
(il LeftLoop)
-- Basis element for the stringnet space corresponding to
-- initial and final configurations
-- data InitialBasisElement = InitialBasisElement
-- { initialLabel :: !(Edge -> SimpleObject)
-- , initialTree :: !(InteriorVertex -> InternalTree)
-- } deriving (Show)
-- instance Eq InitialBasisElement where
-- be1 == be2 =
-- (and $
-- map (\ie ->
-- initialLabel be1 ie == initialLabel be2 ie)
-- (allElements :: [InitialEdge])
-- )
-- && oneIndex be1 == oneIndex be2
-- morphismFromBE :: InitialBasisElement -> Morphism
-- morphismFromBE basisElement =
-- oneIndexToMorphism (toCodomain (toObject . initialLabel basisElement))
-- $ oneIndex basisElement
-- oneIndexToMorphism :: Object -> Int -> Morphism
-- oneIndexToMorphism codomain0 n =
-- if multiplicity codomain0 one > 0
-- then morphism (toObject one) codomain0 $ \so ->
-- if so == one
-- then M.fromLists $
-- (replicate n [0])
-- ++ [[1]]
-- ++ (replicate
-- ((multiplicity codomain0 one) - 1 - n) [0])
-- else emptyMatrix
-- else error "One index for wrong object"
-- instance Finite InitialBasisElement where
-- allElements = concat $ map (uncurry $ \il ms ->
-- [ InitialBasisElement il m
-- | m <- ms
-- ]
-- )
-- [(il, morphismSet $ toCodomain $ toObject . il)
-- | il <- allInitialLabels]
-- ------------------------------------------------------
-- -- Initial labels
-- ------------------------------------------------------
morphismSet :: Object -> [Int]
morphismSet codomain0 =
if multiplicity codomain0 one > 0
then [0..(multiplicity codomain0 one - 1)]
else []
-- finalMorphism :: InitialBasisElement -> Morphism
-- finalMorphism be =
-- let
-- initialCodomain = toCodomainSO $ initialLabel be
-- initialMorphism = oneIndexToMorphism
-- initialCodomain $ oneIndex be
-- in
-- substM (initialLabel be) initialMorphism finalMorphism
-- answer = map finalMorphism (allElements :: [InitialBasisElement])
-- Given a morphism and a choice of indexed simple object for each edge,
-- return the list of scalars corresponding to that subspace
-- component :: InitialBasisElement -> InitialBasisElement -> (InitialEdge -> (SimpleObject, Int)) -> [Scalar]
-- component m oTree oneIndex0 =
-- multiplicityBE :: (InitialEdge -> Object) -> InitialBasisElement -> Int
-- multiplicityBE label0 be0 =
-- product
-- [multiplicity (label0 initialEdge0) (initialLabel be0 initialEdge0)
-- | initialEdge0 <- allElements]
-- -- translate the final basis oneIndex into an index for the final object
-- decomposeH :: InitialBasisElement -> InitialBasisElement -> [Int]
-- decomposeH initialBe finalBe =
-- let
-- label0 = (objectLabel $ finalSN initialBe) . newInitialEdge
-- beIndex = case (L.elemIndex finalBe allElements) of
-- Just i -> i
-- Nothing -> error "decomposeH impossible branch"
-- increment = multiplicity (codomain $ morphismFromBE finalBe) one
-- base = sum $ map (multiplicityBE label0)
-- (take beIndex (allElements :: [InitialBasisElement]))
-- in
-- [ base + increment*i
-- | i <- [0..(multiplicityBE label0 finalBe - 1)]]
-- decompose :: InitialBasisElement -> InitialBasisElement -> Scalar
-- decompose initialBe finalBe =
-- sum $ map (\i ->
-- (subMatrix (finalMorphism initialBe) one) M.! (i + 1, 1)
-- )
-- $ decomposeH initialBe finalBe
-- decompose2 i j = decompose (allElements !! (i-1)) (allElements !! (j-1))
-- rmatrix :: M.Matrix Scalar
-- rmatrix =
-- let
-- size0 = length (allElements :: [InitialBasisElement])
-- in
-- M.matrix size0 size0
-- (\(i,j) -> decompose2 i j)
-- A basis element should really include labellings of internal edges
-- tensorTreeToIndex :: T.Tree (Object, SimpleObject, Int) -> SimpleObject -> Int
-- tensorTreeToIndex (Leaf (o, so, i)) so2 = if multiplicity o so2 > i
-- then (o, so, i)
-- else error "Index out of bounds"
-- tensorTreeToIndex (Node a b) =
-- let
-- (o1, so1, i1) = tensorTreeToIndex a
-- (o2, so2, i2) = tensorTreeToIndex b
-- so1s = map fst (tensorInv so)
-- so2s = map snd (tensorInv so)
-- zipWith (,) (map (tensorTreeToIndex a) so1s)
-- (map (tensorTreeToIndex b) so2s)
-- in
-- dropWhile (\(a,b) -> multiplicity )
edgeLabels :: TwoComplex -> [Edge -> SimpleObject]
edgeLabels tc =
let
labels = replicateM (length $ edges tc) allSimpleObjects
in
[ \e -> label !! (TC.indexE tc e)
| label <- labels]
tensorSOList :: SimpleObject -> SimpleObject -> [SimpleObject]
tensorSOList so1 so2 =
case (so1, so2) of
(AE ae1, AE ae2) -> [AE $ ae1]
(AE _ , M) -> [M]
(M , AE _) -> [M]
(M , M ) -> map AE group
objectTrees :: (Edge -> SimpleObject) -> Tree Edge -> [InternalTree]
objectTrees label0 soTree =
let
-- All trees of the form (Node _ child1 child2)
tensorITree :: InternalTree -> InternalTree -> [InternalTree]
tensorITree child1 child2 =
map (\so -> INode so child1 child2)
$ tensorSOList (rootLabel child1) (rootLabel child2)
in
case soTree of
Leaf e -> [ILeaf e (label0 e)]
Node a b -> concat [ tensorITree ot1 ot2
| ot1 <- objectTrees label0 a
, ot2 <- objectTrees label0 b
]
defaultEdgeTree :: TwoComplex -> Vertex -> Tree Edge
defaultEdgeTree = undefined
vertexLabels :: TwoComplex -> (Edge -> SimpleObject) -> Vertex -> [InternalTree]
vertexLabels tc oLabel v =
objectTrees oLabel $ defaultEdgeTree tc v
basis :: TwoComplex -> [Stringnet]
basis tc = [ Stringnet
{ twoComplex = tc
, edgeTree = undefined
, colorCoeff = undefined
-- \c ->
-- if c == SimpleColoring
-- { objectLabel = objectLabel0
-- , objectTree = undefined -- objectTree0
-- }
-- then 1
-- else 0
}
| objectLabel0 <- edgeLabels tc
, objectTree0 <- map (vertexLabels tc objectLabel0)
(map IV $ TC.vertices tc)
]
-- Test: replacePlusH Phi (Node (Leaf (Reverse (IE
-- RightLoop))) (Node (Leaf (IE RightLeg)) (Leaf (IE RightLoop)))) (Leaf $ IE
-- RightLoop) (initialEdgeTree $ IV Main)
replacePlusH :: SimpleColoring -> Morphism -> Tree Edge -> Tree Edge -> Tree Edge -> (Tree Edge, Tree Morphism)
replacePlusH sn m oldSubTree newSubTree bigTree = undefined
-- if bigTree == oldSubTree
-- then (newSubTree, Leaf m)
-- else case bigTree of
-- Leaf x -> (Leaf x, Leaf $ idMorphism $ objectLabel sn x)
-- Node x y ->
-- let
-- (tex, tmx) = replacePlusH sn m oldSubTree newSubTree x
-- (tey, tmy) = replacePlusH sn m oldSubTree newSubTree y
-- in
-- (Node tex tey, Node tmx tmy)
--TODO: replace these functions with a Foldable instance
tensorMTree :: Tree Morphism -> Morphism
tensorMTree (Leaf m) = m
tensorMTree (Node x y) = tensorM (tensorMTree x) (tensorMTree y)
tensorOTree :: Tree Object -> Object
tensorOTree (Leaf m) = m
tensorOTree (Node x y) = tensorO (tensorOTree x) (tensorOTree y)
replacePlus :: SimpleColoring -> Morphism -> Tree Edge -> Tree Edge -> Tree Edge -> (Tree Edge, Morphism)
replacePlus sn m oldSubTree newSubTree bigTree =
let (eTree, mTree) = replacePlusH sn m oldSubTree newSubTree bigTree in
(eTree, tensorMTree mTree)
associateL :: InteriorVertex -> Tree Edge -> State Stringnet (Tree Edge)
associateL v0 subTree@(Node x yz) = undefined
-- case yz of
-- Node y z ->
-- let newSubTree = (Node (Node x y) z) in
-- state $ \sn ->
-- (newSubTree,
-- let
-- (newEdgeTree, morphism) = replacePlus sn
-- (alphaI (treeLabel (objectLabel sn) x) (treeLabel (objectLabel sn) y)
-- (treeLabel (objectLabel sn) z))
-- subTree newSubTree $ edgeTree sn $ IV v0
-- in
-- sn
-- { edgeTree = \v ->
-- if v == IV v0
-- then newEdgeTree
-- else edgeTree sn v
-- , colorCoeff = undefined --(\sc ->
-- }
-- )
associateR :: InteriorVertex -> Tree Edge -> State Stringnet (Tree Edge)
associateR v0 subTree@(Node xy z) = undefined
-- case xy of
-- Node x y ->
-- let newSubTree = (Node x (Node y z)) in
-- state $ \sn ->
-- (newSubTree,
-- let
-- (newEdgeTree, morphism) = replacePlus sn
-- (alpha
-- (treeLabel (objectLabel sn) x)
-- (treeLabel (objectLabel sn) y)
-- (treeLabel (objectLabel sn) z)
-- )
-- subTree newSubTree $ edgeTree sn $ IV v0
-- in
-- sn
-- { edgeTree = \v ->
-- if v == IV v0
-- then newEdgeTree
-- else edgeTree sn v
-- , colorCoeff = undefined
-- -- morphismLabel = \v ->
-- -- if v == v0
-- -- then compose (morphism)
-- -- (morphismLabel sn v)
-- -- else morphismLabel sn v
-- }
-- )
isolateHelperR :: InteriorVertex -> Stringnet -> Stringnet
isolateHelperR v sn = undefined
-- let t = edgeTree sn (IV v) in
-- case t of
-- Node _ (Leaf _) -> sn
-- Node _ (Node _ _) -> isolateHelperR v
-- $ execState (associateL v t) sn
isolateHelperL :: InteriorVertex -> Stringnet -> Stringnet
isolateHelperL v sn = undefined
-- let t = edgeTree sn (IV v) in
-- case t of
-- Node (Leaf _) _ -> sn
-- Node (Node _ _) _ -> isolateHelperL v
-- $ execState (associateR v t) sn
-- Turns the far right leaf into a depth one leaf
isolateR :: InteriorVertex -> State Stringnet ()
isolateR v0 = state $ \sn ->
((), isolateHelperR v0 sn)
isolateL :: InteriorVertex -> State Stringnet ()
isolateL v0 = state $ \sn ->
((), isolateHelperL v0 sn)
swap :: Tree a -> Tree a
swap (Node x y) = Node y x
zMorphism :: Object -> Object -> Morphism -> Morphism
zMorphism xl yl m =
((idMorphism xl) `tensorM` (rho yl))
<> ((idMorphism xl) `tensorM` ((idMorphism yl) `tensorM` (ev $ star xl))) -- X (Y 1)
<> ((idMorphism xl) `tensorM` (alpha yl xl (star xl))) -- X (Y (X *X))
<> ((idMorphism xl) `tensorM` (m `tensorM` (idMorphism $ star xl))) -- X 1 *X -> X ((Y X) *X)
<> ((pivotalJI xl) `tensorM` (lambdaI $ star xl)) -- **X *X -> X (1 *X)
<> (coev $ star xl) -- 1 -> **X *X
-- rotation of the rightmost edge in v0's to the leftside
zRotate :: InteriorVertex -> State Stringnet ()
zRotate v0 =
isolateR v0 >>
( state $ \sn ->
((), sn
{ edgeTree = \v ->
(
if v == IV v0
then swap
else id
)
$ edgeTree sn v
, colorCoeff = undefined
-- morphismLabel = \v ->
-- if v == v0
-- then case (edgeTree sn (IV v0)) of
-- Node y (Leaf x) ->
-- zMorphism (objectLabel sn x) (treeLabel (objectLabel sn) y) (morphismLabel sn v)
-- else morphismLabel sn v
}
)
)
rotateToEndHelper :: Edge -> InteriorVertex -> Stringnet -> Stringnet
rotateToEndHelper e0 v0 sn =
let
es = flatten $ edgeTree sn (IV v0)
in
if es !! (length es - 1) == e0
then sn
else rotateToEndHelper e0 v0 $ execState (zRotate v0) sn
rotateToEnd :: Edge -> InteriorVertex -> State Stringnet ()
rotateToEnd e0 v0 = (state $ \sn ->
((), rotateToEndHelper e0 v0 sn)) >> isolateR v0
elemT :: Eq a => a -> Tree a -> Bool
elemT u = (elem u) . flatten
minimalSuperTree :: (Eq a) => a -> a -> Tree a -> Tree a
minimalSuperTree a1 a2 t@(Node x y)
| a1 `elemT` x && a2 `elemT` x = minimalSuperTree a1 a2 x
| a1 `elemT` y && a2 `elemT` y = minimalSuperTree a1 a2 y
| otherwise = t
-- Easy optimization: calculate t from previous t
isolate2Helper :: Edge -> Edge -> InteriorVertex -> Stringnet -> Stringnet
isolate2Helper e1 e2 v0 sn0 =
let
t = minimalSuperTree e1 e2 (edgeTree sn0 $ IV v0)
in
case t of
Node x y ->
case x of
Node _ _ -> isolate2Helper e1 e2 v0 $ execState (associateR v0 t) sn0
Leaf _ -> case y of
Node _ _ -> isolate2Helper e1 e2 v0 $ execState (associateL v0 t) sn0
Leaf _ -> sn0
-- Put (rev) e1 and e2 on same node
isolate2 :: Edge -> Edge -> InteriorVertex -> State Stringnet ()
isolate2 e1 e2 v0 = state $ \sn0 ->
let
firstEdge = (flatten $ edgeTree sn0 $ IV v0) !! 0
sn1 = if (e2 == firstEdge)
then execState (zRotate v0) sn0
else sn0
in
((), isolate2Helper e1 e2 v0 sn1)
-- The disk's perimeter should only have two edges
tensorHelper :: Disk -> State Stringnet Edge
tensorHelper d0 = undefined
-- state $ \sn0 ->
-- let
-- e1 = (perimeter sn0 d0) !! 0
-- e2 = rev ((perimeter sn0 d0) !! 1)
-- v0 = toIV ((endpoints e1 sn0) !! 0)
-- v1 = toIV ((endpoints e1 sn0) !! 1)
-- product = TensorE e1 e2
-- edgeImage e = case () of
-- _ | e `elem` [e1, e2] -> product
-- | e `elem` [rev e1, rev e2] -> rev product
-- | otherwise -> e
-- sn = execState (isolate2 e1 e2 v0
-- >> isolate2 (rev e2) (rev e1) v1
-- ) sn0
-- in
-- ( product
-- , sn
-- { edges = map edgeImage (edges sn)
-- , disks = [d | d <- disks sn
-- , d /= d0]
-- , perimeter = (map edgeImage) . (perimeter sn)
-- , edgeTree = (replace (Node (Leaf e1) (Leaf e2)) (Leaf product))
-- . (replace (Node (Leaf $ rev e2) (Leaf $ rev e1)) (Leaf $ rev product))
-- . (edgeTree sn)
-- }
-- )
tensorN :: Disk -> Stringnet -> Stringnet
tensorN d0 sn0 = undefined
-- let
-- e1 = (perimeter sn0 d0) !! 0
-- e2 = rev ((perimeter sn0 d0) !! 1)
-- v0 = toIV ((endpoints e1 sn0) !! 0)
-- v1 = toIV ((endpoints e1 sn0) !! 1)
-- in
-- execState (isolate2 e1 e2 v0
-- >> isolate2 (rev e2) (rev e1) v1
-- >> tensorHelper d0
-- ) sn0
tensor :: Disk -> State Stringnet ()
tensor d = state $ \sn -> ((), tensorN d sn)
-- do
-- e1 <- fmap (!! 0) (perimeter d0)
-- e2 <- fmap rev $ fmap (!! 1) (perimeterM d0)
-- v0 <- fmap (!! 0) (endpointsM e1)
-- v1 <- fmap (!! 1) (endpointsM e1)
-- isolate2 e1 e2 v0
-- isolate2 (rev e2) (rev e1) v1
-- tensorHelper d0
contract :: Edge -> State Stringnet InteriorVertex
contract e = do
v0 <- fmap (toIV . (!! 0)) $ endpointsM e
v1 <- fmap (toIV . (!! 1)) $ endpointsM e
rotateToEnd e v0
rotateToEnd (rev e) v1
zRotate v1
isolateL v1
contractHelper e
leftSubTree :: Tree a -> Tree a
leftSubTree (Node x _) = x
rightSubTree :: Tree a -> Tree a
rightSubTree (Node _ y) = y
contractHelper :: Edge -> State Stringnet InteriorVertex
contractHelper contractedEdge = undefined
-- state $ \sn ->
-- let
-- v0 = toIV $ (endpoints contractedEdge sn) !! 0
-- v1 = toIV $ (endpoints contractedEdge sn) !! 1
-- composition = Contraction contractedEdge
-- in
-- (composition, sn
-- { vertices = [composition] ++
-- [v | v <- vertices sn
-- , not $ v `elem` [v0, v1]]
-- , edges = [e | e <- edges sn
-- , e /= contractedEdge
-- , e /= rev contractedEdge]
-- , imageVertex = (\v -> if v `elem` [IV v0, IV v1]
-- then IV composition
-- else v
-- ) . (imageVertex sn)
-- , edgeTree = \v ->
-- if v == IV composition
-- then Node (leftSubTree $ edgeTree sn $ IV v0)
-- (rightSubTree $ edgeTree sn $ IV v1)
-- else edgeTree sn v
-- , colorCoeff = undefined
-- -- morphismLabel = (\v -> if (v == composition)
-- -- then compose ((idMorphism $ treeLabel (objectLabel sn) (leftSubTree $ edgeTree sn $ IV v0))
-- -- `tensorM`
-- -- (ev $ objectLabel sn contractedEdge)
-- -- `tensorM`
-- -- (idMorphism $ treeLabel (objectLabel sn) (rightSubTree $ edgeTree sn $ IV v1))
-- -- )
-- -- (tensorM (morphismLabel sn v0)
-- -- (morphismLabel sn v1))
-- -- else morphismLabel sn v )
-- , perimeter = \d -> [e | e <- perimeter sn d
-- , e /= contractedEdge
-- , e /= rev contractedEdge
-- ]
-- }
-- )
-- Connect the starting point of the first edge to that of the second
-- through the disk The edges e1 and e2 should be distinct elements of
-- perimeter d.
connect :: Edge -> Edge -> Disk -> State Stringnet Edge
connect e1 e2 d = undefined
-- state $ \sn ->
-- let connection = Connector e1 e2 d in
-- ( connection
-- ,
-- let
-- (edgeTree1, morphism1) =
-- replacePlus sn (rhoI $ objectLabel sn e1)
-- (Leaf e1) (Node (Leaf e1) (Leaf $ connection))
-- (edgeTree sn $ start e1 sn)
-- (edgeTree2, morphism2) =
-- replacePlus sn (rhoI $ objectLabel sn e2)
-- (Leaf e2) (Node (Leaf e2) (Leaf $ rev connection))
-- (edgeTree sn $ start e2 sn)
-- in
-- sn
-- { edges = [connection] ++ edges sn
-- , disks = [Cut connection, Cut $ rev connection]
-- ++ [d2 | d2 <- disks sn
-- , d2 /= d]
-- , edgeTree = \v -> case () of
-- _ | v == (start e1 sn) -> edgeTree1
-- | v == (start e2 sn) -> edgeTree2
-- | otherwise -> edgeTree sn v
-- , perimeter = \d0 -> case () of
-- _ | d0 == Cut connection -> [connection] ++
-- (takeWhile (/= e1) $ dropWhile (/= e2) $ cycle $ perimeter sn d)
-- | d0 == Cut (rev connection) -> [rev connection] ++
-- (takeWhile (/= e2) $ dropWhile (/= e1) $ cycle $ perimeter sn d)
-- | otherwise -> perimeter sn d0
-- -- Find index of objectlabels
-- , colorCoeff = undefined
-- -- morphismLabel = \v -> case () of
-- -- _ | v == toIV (start e1 sn) -> morphism1 <> morphismLabel sn v
-- -- | v == toIV (start e2 sn) -> morphism2 <> morphismLabel sn v
-- -- | otherwise -> morphismLabel sn v
-- }
-- )
addCoev :: Edge -> State Stringnet (InteriorVertex, Edge, Edge)
addCoev e = undefined
-- state $ \sn ->
-- let mp = Midpoint e
-- fh = FirstHalf e
-- sh = SecondHalf e
-- in
-- ((mp, fh, sh), sn
-- { vertices = [mp] ++ vertices sn
-- , edges = [fh, sh] ++ [f | f <- edges sn
-- , f /= e
-- , f /= rev e]