-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFast.hs
More file actions
2122 lines (1855 loc) · 87.9 KB
/
Fast.hs
File metadata and controls
2122 lines (1855 loc) · 87.9 KB
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
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
module Fast where
import Control.Applicative
import Control.Monad
-- import CirParser
import Control.Monad.State
import Control.Monad.Trans.Writer.Strict
import Data.Bifunctor
import Data.Char
import Data.Function
import Data.List
import qualified Data.Map.Strict as M
import Data.Maybe
import qualified Data.Set as Set
import GateStruct
import QCParser
import Quipper
import Quipper.Libraries.QuipperASCIIParser
import QuipperParser
import System.Environment
import TfcParser
--import qc2_inHSformat
i45eff_inc = sortBy (compare `on` t_count) i45eff
i45eff_dec = reverse i45eff_inc
i45eff = [[G 1 [0], G 1 [1], G 1 [2], G 1 [3], G 7 [0, 1], G 7 [0, 2], G 7 [0, 3], G 7 [1, 2], G 7 [1, 3], G 7 [2, 3], G 1 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 2, 3], G 1 [1, 2, 3], G 7 [0, 1, 2, 3]], [G 1 [0], G 1 [1], G 1 [2], G 1 [4], G 7 [0, 1], G 7 [0, 2], G 7 [0, 4], G 7 [1, 2], G 7 [1, 4], G 7 [2, 4], G 1 [0, 1, 2], G 1 [0, 1, 4], G 1 [0, 2, 4], G 1 [1, 2, 4], G 7 [0, 1, 2, 4]], [G 1 [0], G 1 [1], G 1 [3], G 1 [4], G 7 [0, 1], G 7 [0, 3], G 7 [0, 4], G 7 [1, 3], G 7 [1, 4], G 7 [3, 4], G 1 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 3, 4], G 1 [1, 3, 4], G 7 [0, 1, 3, 4]], [G 1 [0], G 1 [2], G 1 [3], G 1 [4], G 7 [0, 2], G 7 [0, 3], G 7 [0, 4], G 7 [2, 3], G 7 [2, 4], G 7 [3, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 1 [2, 3, 4], G 7 [0, 2, 3, 4]], [G 1 [1], G 1 [2], G 1 [3], G 1 [4], G 7 [1, 2], G 7 [1, 3], G 7 [1, 4], G 7 [2, 3], G 7 [2, 4], G 7 [3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [1, 2, 3, 4]], [G 2 [0], G 2 [1], G 2 [2], G 1 [3], G 1 [4], G 6 [01], G 6 [0, 2], G 7 [0, 3], G 7 [0, 4], G 6 [1, 2], G 7 [1, 3], G 7 [1, 4], G 7 [2, 3], G 7 [2, 4], G 2 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4]], [G 2 [0], G 2 [1], G 1 [2], G 2 [3], G 1 [4], G 6 [0, 1], G 7 [0, 2], G 6 [0, 3], G 7 [0, 4], G 7 [1, 2], G 6 [1, 3], G 7 [1, 4], G 7 [2, 3], G 7 [3, 4], G 1 [0, 1, 2], G 2 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 3, 4]], [G 2 [0], G 1 [1], G 2 [2], G 2 [3], G 1 [4], G 7 [0, 1], G 6 [0, 2], G 6 [0, 3], G 7 [0, 4], G 7 [1, 2], G 7 [1, 3], G 6 [2, 3], G 7 [2, 4], G 7 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 3], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 2, 3, 4]], [G 1 [0], G 2 [1], G 2 [2], G 2 [3], G 1 [4], G 7 [0, 1], G 7 [0, 2], G 7 [0, 3], G 6 [1, 2], G 6 [1, 3], G 7 [1, 4], G 6 [2, 3], G 7 [2, 4], G 7 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 2, 3], G 2 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [1, 2, 3, 4]], [G 2 [0], G 2 [1], G 1 [2], G 1 [3], G 2 [4], G 6 [0, 1], G 7 [0, 2], G 7 [0, 3], G 6 [0, 4], G 7 [1, 2], G 7 [1, 3], G 6 [1, 4], G 7 [2, 4], G 7 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 4], G 1 [1, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4]], [G 2 [0], G 1 [1], G 2 [2], G 1 [3], G 2 [4], G 7 [0, 1], G 6 [0, 2], G 7 [0, 3], G 6 [0, 4], G 7 [1, 2], G 7 [1, 4], G 7 [2, 3], G 6 [2, 4], G 7 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 4], G 1 [0, 2, 3], G 2 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 2, 3, 4]], [G 1 [0], G 2 [1], G 2 [2], G 1 [3], G 2 [4], G 7 [0, 1], G 7 [0, 2], G 7 [0, 4], G 6 [1, 2], G 7 [1, 3], G 6 [1, 4], G 7 [2, 3], G 6 [2, 4], G 7 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 4], G 1 [0, 2, 4], G 1 [1, 2, 3], G 2 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [1, 2, 3, 4]], [G 2 [0], G 1 [1], G 1 [2], G 2 [3], G 2 [4], G 7 [0, 1], G 7 [0, 2], G 6 [0, 3], G 6 [0, 4], G 7 [1, 3], G 7 [1, 4], G 7 [2, 3], G 7 [2, 4], G 6 [3, 4], G 1 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4]], [G 1 [0], G 2 [1], G 1 [2], G 2 [3], G 2 [4], G 7 [0, 1], G 7 [0, 3], G 7 [0, 4], G 7 [1, 2], G 6 [1, 3], G 6 [1, 4], G 7 [2, 3], G 7 [2, 4], G 6 [3, 4], G 1 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 2 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 3, 4], G 7 [1, 2, 3, 4]], [G 1 [0], G 1 [1], G 2 [2], G 2 [3], G 2 [4], G 7 [0, 2], G 7 [0, 3], G 7 [0, 4], G 7 [1, 2], G 7 [1, 3], G 7 [1, 4], G 6 [2, 3], G 6 [2, 4], G 6 [3, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4]], [G 3 [0], G 3 [1], G 2 [2], G 2 [3], G 2 [4], G 5 [0, 1], G 6 [0, 2], G 6 [0, 3], G 6 [0, 4], G 6 [1, 2], G 6 [1, 3], G 6 [1, 4], G 7 [2, 3], G 7 [2, 4], G 7 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4]], [G 3 [0], G 2 [1], G 3 [2], G 2 [3], G 2 [4], G 6 [0, 1], G 5 [0, 2], G 6 [0, 3], G 6 [0, 4], G 6 [1, 2], G 7 [1, 3], G 7 [1, 4], G 6 [2, 3], G 6 [2, 4], G 7 [3, 4], G 2 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 2, 3, 4]], [G 2 [0], G 3 [1], G 3 [2], G 2 [3], G 2 [4], G 6 [0, 1], G 6 [0, 2], G 7 [0, 3], G 7 [0, 4], G 5 [1, 2], G 6 [1, 3], G 6 [1, 4], G 6 [2, 3], G 6 [2, 4], G 7 [3, 4], G 2 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [1, 2, 3, 4]], [G 3 [0], G 2 [1], G 2 [2], G 3 [3], G 2 [4], G 6 [0, 1], G 6 [0, 2], G 5 [0, 3], G 6 [0, 4], G 7 [1, 2], G 6 [1, 3], G 7 [1, 4], G 6 [2, 3], G 7 [2, 4], G 6 [3, 4], G 1 [0, 1, 2], G 2 [0, 1, 3], G 1 [0, 1, 4], G 2 [0, 2, 3], G 1 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4]], [G 2 [0], G 3 [1], G 2 [2], G 3 [3], G 2 [4], G 6 [0, 1], G 7 [0, 2], G 6 [0, 3], G 7 [0, 4], G 6 [1, 2], G 5 [1, 3], G 6 [1, 4], G 6 [2, 3], G 7 [2, 4], G 6 [3, 4], G 1 [0, 1, 2], G 2 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 3, 4], G 2 [1, 2, 3], G 1 [1, 2, 4], G 2 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 3, 4], G 7 [1, 2, 3, 4]], [G 2 [0], G 2 [1], G 3 [2], G 3 [3], G 2 [4], G 7 [0, 1], G 6 [0, 2], G 6 [0, 3], G 7 [0, 4], G 6 [1, 2], G 6 [1, 3], G 7 [1, 4], G 5 [2, 3], G 6 [2, 4], G 6 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 2 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4]], [G 3 [0], G 2 [1], G 2 [2], G 2 [3], G 3 [4], G 6 [0, 1], G 6 [0, 2], G 6 [0, 3], G 5 [0, 4], G 7 [1, 2], G 7 [1, 3], G 6 [1, 4], G 7 [2, 3], G 6 [2, 4], G 6 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4]], [G 2 [0], G 3 [1], G 2 [2], G 2 [3], G 3 [4], G 6 [0, 1], G 7 [0, 2], G 7 [0, 3], G 6 [0, 4], G 6 [1, 2], G 6 [1, 3], G 5 [1, 4], G 7 [2, 3], G 6 [2, 4], G 6 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [1, 2, 3, 4]], [G 2 [0], G 2 [1], G 3 [2], G 2 [3], G 3 [4], G 7 [0, 1], G 6 [0, 2], G 7 [0, 3], G 6 [0, 4], G 6 [1, 2], G 7 [1, 3], G 6 [1, 4], G 6 [2, 3], G 5 [2, 4], G 6 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 4], G 1 [0, 2, 3], G 2 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 3], G 2 [1, 2, 4], G 1 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4]], [G 2 [0], G 2 [1], G 2 [2], G 3 [3], G 3 [4], G 7 [0, 1], G 7 [0, 2], G 6 [0, 3], G 6 [0, 4], G 7 [1, 2], G 6 [1, 3], G 6 [1, 4], G 6 [2, 3], G 6 [2, 4], G 5 [3, 4], G 1 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4]], [G 4 [0], G 3 [1], G 3 [2], G 3 [3], G 3 [4], G 5 [0, 1], G 5 [0, 2], G 5 [0, 3], G 5 [0, 4], G 6 [1, 2], G 6 [1, 3], G 6 [1, 4], G 6 [2, 3], G 6 [2, 4], G 6 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4]], [G 3 [0], G 4 [1], G 3 [2], G 3 [3], G 3 [4], G 5 [0, 1], G 6 [0, 2], G 6 [0, 3], G 6 [0, 4], G 5 [1, 2], G 5 [1, 3], G 5 [1, 4], G 6 [2, 3], G 6 [2, 4], G 6 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [1, 2, 3, 4]], [G 3 [0], G 3 [1], G 4 [2], G 3 [3], G 3 [4], G 6 [0, 1], G 5 [0, 2], G 6 [0, 3], G 6 [0, 4], G 5 [1, 2], G 6 [1, 3], G 6 [1, 4], G 5 [2, 3], G 5 [2, 4], G 6 [3, 4], G 2 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 1 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 1 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4]], [G 3 [0], G 3 [1], G 3 [2], G 4 [3], G 3 [4], G 6 [0, 1], G 6 [0, 2], G 5 [0, 3], G 6 [0, 4], G 6 [1, 2], G 5 [1, 3], G 6 [1, 4], G 5 [2, 3], G 6 [2, 4], G 5 [3, 4], G 1 [0, 1, 2], G 2 [0, 1, 3], G 1 [0, 1, 4], G 2 [0, 2, 3], G 1 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 1 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4]], [G 3 [0], G 3 [1], G 3 [2], G 3 [3], G 4 [4], G 6 [0, 1], G 6 [0, 2], G 6 [0, 3], G 5 [0, 4], G 6 [1, 2], G 6 [1, 3], G 5 [1, 4], G 6 [2, 3], G 5 [2, 4], G 5 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4]], [G 3 [0], G 3 [1], G 3 [2], G 3 [3], G 3 [4], G 6 [0, 1], G 6 [0, 2], G 6 [0, 3], G 6 [0, 4], G 6 [1, 2], G 6 [1, 3], G 6 [1, 4], G 6 [2, 3], G 6 [2, 4], G 6 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 4 [0], G 4 [1], G 4 [2], G 4 [3], G 3 [4], G 5 [0, 1], G 5 [0, 2], G 5 [0, 3], G 6 [0, 4], G 5 [1, 2], G 5 [1, 3], G 6 [1, 4], G 5 [2, 3], G 6 [2, 4], G 6 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 1 [0, 1, 4], G 2 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 2 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 3, 4]], [G 4 [0], G 4 [1], G 4 [2], G 3 [3], G 4 [4], G 5 [0, 1], G 5 [0, 2], G 6 [0, 3], G 5 [0, 4], G 5 [1, 2], G 6 [1, 3], G 5 [1, 4], G 6 [2, 3], G 5 [2, 4], G 6 [3, 4], G 2 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 3], G 2 [0, 2, 4], G 1 [0, 3, 4], G 1 [1, 2, 3], G 2 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 1, 2, 3, 4]], [G 4 [0], G 4 [1], G 3 [2], G 4 [3], G 4 [4], G 5 [0, 1], G 6 [0, 2], G 5 [0, 3], G 5 [0, 4], G 6 [1, 2], G 5 [1, 3], G 5 [1, 4], G 6 [2, 3], G 6 [2, 4], G 5 [3, 4], G 1 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 2 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 4 [0], G 3 [1], G 4 [2], G 4 [3], G 4 [4], G 6 [0, 1], G 5 [0, 2], G 5 [0, 3], G 5 [0, 4], G 6 [1, 2], G 6 [1, 3], G 6 [1, 4], G 5 [2, 3], G 5 [2, 4], G 5 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 3 [0], G 4 [1], G 4 [2], G 4 [3], G 4 [4], G 6 [0, 1], G 6 [0, 2], G 6 [0, 3], G 6 [0, 4], G 5 [1, 2], G 5 [1, 3], G 5 [1, 4], G 5 [2, 3], G 5 [2, 4], G 5 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 5 [1], G 5 [2], G 4 [3], G 4 [4], G 4 [0, 1], G 4 [0, 2], G 5 [0, 3], G 5 [0, 4], G 4 [1, 2], G 5 [1, 3], G 5 [1, 4], G 5 [2, 3], G 5 [2, 4], G 6 [3, 4], G 3 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 1 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 1 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 5 [1], G 4 [2], G 5 [3], G 4 [4], G 4 [0, 1], G 5 [0, 2], G 4 [0, 3], G 5 [0, 4], G 5 [1, 2], G 4 [1, 3], G 5 [1, 4], G 5 [2, 3], G 6 [2, 4], G 5 [3, 4], G 2 [0, 1, 2], G 3 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 1 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 1 [1, 2, 4], G 2 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 4 [1], G 5 [2], G 5 [3], G 4 [4], G 5 [0, 1], G 4 [0, 2], G 4 [0, 3], G 5 [0, 4], G 5 [1, 2], G 5 [1, 3], G 6 [1, 4], G 4 [2, 3], G 5 [2, 4], G 5 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 1 [0, 1, 4], G 3 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 1 [1, 2, 4], G 1 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 4 [0], G 5 [1], G 5 [2], G 5 [3], G 4 [4], G 5 [0, 1], G 5 [0, 2], G 5 [0, 3], G 6 [0, 4], G 4 [1, 2], G 4 [1, 3], G 5 [1, 4], G 4 [2, 3], G 5 [2, 4], G 5 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 1 [0, 1, 4], G 2 [0, 2, 3], G 1 [0, 2, 4], G 1 [0, 3, 4], G 3 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 5 [1], G 4 [2], G 4 [3], G 5 [4], G 4 [0, 1], G 5 [0, 2], G 5 [0, 3], G 4 [0, 4], G 5 [1, 2], G 5 [1, 3], G 4 [1, 4], G 6 [2, 3], G 5 [2, 4], G 5 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 3 [0, 1, 4], G 1 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 4 [1], G 5 [2], G 4 [3], G 5 [4], G 5 [0, 1], G 4 [0, 2], G 5 [0, 3], G 4 [0, 4], G 5 [1, 2], G 6 [1, 3], G 5 [1, 4], G 5 [2, 3], G 4 [2, 4], G 5 [3, 4], G 2 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 3 [0, 2, 4], G 2 [0, 3, 4], G 1 [1, 2, 3], G 2 [1, 2, 4], G 1 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 4 [0], G 5 [1], G 5 [2], G 4 [3], G 5 [4], G 5 [0, 1], G 5 [0, 2], G 6 [0, 3], G 5 [0, 4], G 4 [1, 2], G 5 [1, 3], G 4 [1, 4], G 5 [2, 3], G 4 [2, 4], G 5 [3, 4], G 2 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 3], G 2 [0, 2, 4], G 1 [0, 3, 4], G 2 [1, 2, 3], G 3 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 4 [1], G 4 [2], G 5 [3], G 5 [4], G 5 [0, 1], G 5 [0, 2], G 4 [0, 3], G 4 [0, 4], G 6 [1, 2], G 5 [1, 3], G 5 [1, 4], G 5 [2, 3], G 5 [2, 4], G 4 [3, 4], G 1 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 3 [0, 3, 4], G 1 [1, 2, 3], G 1 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 4 [0], G 5 [1], G 4 [2], G 5 [3], G 5 [4], G 5 [0, 1], G 6 [0, 2], G 5 [0, 3], G 5 [0, 4], G 5 [1, 2], G 4 [1, 3], G 4 [1, 4], G 5 [2, 3], G 5 [2, 4], G 4 [3, 4], G 1 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 1 [0, 2, 3], G 1 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 3 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 4 [0], G 4 [1], G 5 [2], G 5 [3], G 5 [4], G 6 [0, 1], G 5 [0, 2], G 5 [0, 3], G 5 [0, 4], G 5 [1, 2], G 5 [1, 3], G 5 [1, 4], G 4 [2, 3], G 4 [2, 4], G 4 [3, 4], G 1 [0, 1, 2], G 1 [0, 1, 3], G 1 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 3 [2, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 6 [0], G 6 [1], G 5 [2], G 5 [3], G 5 [4], G 3 [0, 1], G 4 [0, 2], G 4 [0, 3], G 4 [0, 4], G 4 [1, 2], G 4 [1, 3], G 4 [1, 4], G 5 [2, 3], G 5 [2, 4], G 5 [3, 4], G 3 [0, 1, 2], G 3 [0, 1, 3], G 3 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 1 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 6 [0], G 5 [1], G 6 [2], G 5 [3], G 5 [4], G 4 [0, 1], G 3 [0, 2], G 4 [0, 3], G 4 [0, 4], G 4 [1, 2], G 5 [1, 3], G 5 [1, 4], G 4 [2, 3], G 4 [2, 4], G 5 [3, 4], G 3 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 3 [0, 2, 3], G 3 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 1 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 6 [1], G 6 [2], G 5 [3], G 5 [4], G 4 [0, 1], G 4 [0, 2], G 5 [0, 3], G 5 [0, 4], G 3 [1, 2], G 4 [1, 3], G 4 [1, 4], G 4 [2, 3], G 4 [2, 4], G 5 [3, 4], G 3 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 1 [0, 3, 4], G 3 [1, 2, 3], G 3 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 6 [0], G 5 [1], G 5 [2], G 6 [3], G 5 [4], G 4 [0, 1], G 4 [0, 2], G 3 [0, 3], G 4 [0, 4], G 5 [1, 2], G 4 [1, 3], G 5 [1, 4], G 4 [2, 3], G 5 [2, 4], G 4 [3, 4], G 2 [0, 1, 2], G 3 [0, 1, 3], G 2 [0, 1, 4], G 3 [0, 2, 3], G 2 [0, 2, 4], G 3 [0, 3, 4], G 2 [1, 2, 3], G 1 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 6 [1], G 5 [2], G 6 [3], G 5 [4], G 4 [0, 1], G 5 [0, 2], G 4 [0, 3], G 5 [0, 4], G 4 [1, 2], G 3 [1, 3], G 4 [1, 4], G 4 [2, 3], G 5 [2, 4], G 4 [3, 4], G 2 [0, 1, 2], G 3 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 1 [0, 2, 4], G 2 [0, 3, 4], G 3 [1, 2, 3], G 2 [1, 2, 4], G 3 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 5 [1], G 6 [2], G 6 [3], G 5 [4], G 5 [0, 1], G 4 [0, 2], G 4 [0, 3], G 5 [0, 4], G 4 [1, 2], G 4 [1, 3], G 5 [1, 4], G 3 [2, 3], G 4 [2, 4], G 4 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 1 [0, 1, 4], G 3 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 3 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 3 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 6 [0], G 5 [1], G 5 [2], G 5 [3], G 6 [4], G 4 [0, 1], G 4 [0, 2], G 4 [0, 3], G 3 [0, 4], G 5 [1, 2], G 5 [1, 3], G 4 [1, 4], G 5 [2, 3], G 4 [2, 4], G 4 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 3 [0, 1, 4], G 2 [0, 2, 3], G 3 [0, 2, 4], G 3 [0, 3, 4], G 1 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 6 [1], G 5 [2], G 5 [3], G 6 [4], G 4 [0, 1], G 5 [0, 2], G 5 [0, 3], G 4 [0, 4], G 4 [1, 2], G 4 [1, 3], G 3 [1, 4], G 5 [2, 3], G 4 [2, 4], G 4 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 3 [0, 1, 4], G 1 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 3 [1, 2, 4], G 3 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 5 [1], G 6 [2], G 5 [3], G 6 [4], G 5 [0, 1], G 4 [0, 2], G 5 [0, 3], G 4 [0, 4], G 4 [1, 2], G 5 [1, 3], G 4 [1, 4], G 4 [2, 3], G 3 [2, 4], G 4 [3, 4], G 2 [0, 1, 2], G 1 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 3 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 3 [1, 2, 4], G 2 [1, 3, 4], G 3 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 5 [0], G 5 [1], G 5 [2], G 6 [3], G 6 [4], G 5 [0, 1], G 5 [0, 2], G 4 [0, 3], G 4 [0, 4], G 5 [1, 2], G 4 [1, 3], G 4 [1, 4], G 4 [2, 3], G 4 [2, 4], G 3 [3, 4], G 1 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 3 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 3 [1, 3, 4], G 3 [2, 3, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 7 [0], G 6 [1], G 6 [2], G 6 [3], G 6 [4], G 3 [0, 1], G 3 [0, 2], G 3 [0, 3], G 3 [0, 4], G 4 [1, 2], G 4 [1, 3], G 4 [1, 4], G 4 [2, 3], G 4 [2, 4], G 4 [3, 4], G 3 [0, 1, 2], G 3 [0, 1, 3], G 3 [0, 1, 4], G 3 [0, 2, 3], G 3 [0, 2, 4], G 3 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 6 [0], G 7 [1], G 6 [2], G 6 [3], G 6 [4], G 3 [0, 1], G 4 [0, 2], G 4 [0, 3], G 4 [0, 4], G 3 [1, 2], G 3 [1, 3], G 3 [1, 4], G 4 [2, 3], G 4 [2, 4], G 4 [3, 4], G 3 [0, 1, 2], G 3 [0, 1, 3], G 3 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 3 [1, 2, 3], G 3 [1, 2, 4], G 3 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 6 [0], G 6 [1], G 7 [2], G 6 [3], G 6 [4], G 4 [0, 1], G 3 [0, 2], G 4 [0, 3], G 4 [0, 4], G 3 [1, 2], G 4 [1, 3], G 4 [1, 4], G 3 [2, 3], G 3 [2, 4], G 4 [3, 4], G 3 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 3 [0, 2, 3], G 3 [0, 2, 4], G 2 [0, 3, 4], G 3 [1, 2, 3], G 3 [1, 2, 4], G 2 [1, 3, 4], G 3 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 6 [0], G 6 [1], G 6 [2], G 7 [3], G 6 [4], G 4 [0, 1], G 4 [0, 2], G 3 [0, 3], G 4 [0, 4], G 4 [1, 2], G 3 [1, 3], G 4 [1, 4], G 3 [2, 3], G 4 [2, 4], G 3 [3, 4], G 2 [0, 1, 2], G 3 [0, 1, 3], G 2 [0, 1, 4], G 3 [0, 2, 3], G 2 [0, 2, 4], G 3 [0, 3, 4], G 3 [1, 2, 3], G 2 [1, 2, 4], G 3 [1, 3, 4], G 3 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 6 [0], G 6 [1], G 6 [2], G 6 [3], G 7 [4], G 4 [0, 1], G 4 [0, 2], G 4 [0, 3], G 3 [0, 4], G 4 [1, 2], G 4 [1, 3], G 3 [1, 4], G 4 [2, 3], G 3 [2, 4], G 3 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 3 [0, 1, 4], G 2 [0, 2, 3], G 3 [0, 2, 4], G 3 [0, 3, 4], G 2 [1, 2, 3], G 3 [1, 2, 4], G 3 [1, 3, 4], G 3 [2, 3, 4], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]], [G 4 [0], G 4 [1], G 4 [2], G 4 [3], G 4 [4], G 5 [0, 1], G 5 [0, 2], G 5 [0, 3], G 5 [0, 4], G 5 [1, 2], G 5 [1, 3], G 5 [1, 4], G 5 [2, 3], G 5 [2, 4], G 5 [3, 4], G 2 [0, 1, 2], G 2 [0, 1, 3], G 2 [0, 1, 4], G 2 [0, 2, 3], G 2 [0, 2, 4], G 2 [0, 3, 4], G 2 [1, 2, 3], G 2 [1, 2, 4], G 2 [1, 3, 4], G 2 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4]], [G 7 [0], G 7 [1], G 7 [2], G 7 [3], G 7 [4], G 3 [0, 1], G 3 [0, 2], G 3 [0, 3], G 3 [0, 4], G 3 [1, 2], G 3 [1, 3], G 3 [1, 4], G 3 [2, 3], G 3 [2, 4], G 3 [3, 4], G 3 [0, 1, 2], G 3 [0, 1, 3], G 3 [0, 1, 4], G 3 [0, 2, 3], G 3 [0, 2, 4], G 3 [0, 3, 4], G 3 [1, 2, 3], G 3 [1, 2, 4], G 3 [1, 3, 4], G 3 [2, 3, 4], G 7 [0, 1, 2, 3], G 7 [0, 1, 2, 4], G 7 [0, 1, 3, 4], G 7 [0, 2, 3, 4], G 7 [1, 2, 3, 4], G 7 [0, 1, 2, 3, 4]]]
--------------------------------------------------------------------------
-- | For QPL 2019 paper
-- | A heuristic to reduce pi/t-parity-phase circuits
-- | Data structure for phase Gadget. The first parameter encodes the
-- phase k * Pi/4, where k in Z_8 = Z/(8). The second parameter is the
-- qubit indexes (starts from 0. 0, 1, 2, ...) that the gadget acts
-- upon. For example, G 1 [0,1] is the following gadget:
-- 0 ---------O----------------
-- \
-- >-X-O(pi/4)
-- /
-- 1 ---------O---------------
--data Gadget = G Int [Int]
-- The HG (HGadget), XG, YG... are just H, X, Y diagrams in ZX
-- calculus. Think of the diagram of H, X, Y, Cnot, ... as
-- "generalized gadget", we can construct ZXTerm from these
-- generalized gadgets, we call them ZXAtoms. InitG QState i is used
-- to record which wire is initialized which state. Similarly for
-- TermG.
-- | Qubit state {|0>, |1>, |+>, |->}. We can add finite many more
-- state in here.
data ZXAtom
= InitG QState Int
| TermG QState Int
| SwapG Int Int
| G Int [Int] -- the list must be an ordered list for improving efficiency.
| HG Int -- we have hRewrite which decompses it into gadgets + Cliffords
| CNZG [Int] -- we have cnzRewrite which decompses it into gadgets
| XG Int
| YG Int
| ZG Int
| CZG Int Int
| SG Int
| S'G Int
| Tn Int Int
| -- for polynomial calculation, 1st int the k in k * pi/4
CTn Int Int Int
| -- for polynomial calculation, 1st int is k * pi/4, 2nd is target,
-- 3rd is control
CCTn Int Int Int Int
| -- for polynomial calculation, 1st int is k * pi/4, 2nd is target,
-- 3rd and 4th are control
CnotG Int Int
deriving (Eq, Show, Ord, Read)
-- | hRewrite and cnzRewrite could have been done using gtrans, but
-- that is not convenient.
-- | We are using list to encode a zx-diagram. Here the diagram looks
-- like a quantum circuit, that is the reason we can use list to
-- encode them. Intuitively, the first element in the list is the left
-- most gate you see when you look at a circuit. And the index for
-- that gate (XG i) indicate which wire the gate is on counting from
-- top to bottom.
type ZXTerm = [ZXAtom]
-- | The translation goes this way. (1) Proprocess Toffoli and
-- multi-Toffoli into H and muli-control Z gate, translate Y gate into
-- X Z gates. (2) Translate all the gates to the corresponding gates
-- in ZXAtom with some exceptions. (3) Translate CNZG gate --- the
-- multi-control Z gate --- into gadgets and Clifford gates.
-- | Translate HZH to X (including the multi-controled HZH to multi-controled X)
z2x_step :: [Gate] -> Maybe [Gate]
z2x_step ((H i) : (CCZ a b c) : (H j) : t) =
if i == j
then case i of
_ | i == a -> Just $ Toffoli a b c : t
_ | i == b -> Just $ Toffoli b a c : t
_ | i == c -> Just $ Toffoli c a b : t
_ -> do
t' <- z2x_step t
return (H i : CCZ a b c : H j : t')
else do
t' <- z2x_step t
return (H i : CCZ a b c : H j : t')
z2x_step (h : t) = do
t' <- z2x_step t
return (h : t')
z2x_step [] = Nothing
z2x = repeatedly z2x_step
-- | Translate X to Z (including the multi-controled X to multi-controled Z)
x2z :: Gate -> Gate
x2z (X i) = Z i
x2z (Toffoli i j k) = CCZ i j k
x2z (Toffolin xs) = CNZ xs
x2z g = g
{-
x2z_ciri :: [Gate] -> [Gate] -> [Gate]
x2z_ciri (h@(X i) : t) ref = glok where
gli = zip gl [0..]
focusOnWires [i] ref
-}
-- c2zx function packed the above translation.
-- | preProcess decompose circuits into circuits using only the
-- following basic gates: {CNZ, Cnot, CZ, X, Z, H, S, S', T, T'}. That
-- is:
-- 1) preProcess decompose Toffolin into CNZ.
-- 2) CCZ -> CNZ
-- 3) Toffoli -> CNZ
-- 4) Y -> XZ (ignoring global phase).
preProcess :: [Gate] -> [Gate]
preProcess cir = cirok
where
auxfun (Toffolin xs@(h : t)) = case length xs of
1 -> [X h]
2 -> [Cnot h (head t)]
_ -> [H h, CNZ (sort xs), H h]
auxfun (CCZ i j k) = [CNZ (sort [i, j, k])]
auxfun (Toffoli i j k) = [H i, CNZ (sort [i, j, k]), H i]
auxfun (Y i) = [X i, Z i]
auxfun x = [x]
cirok = concatMap auxfun cir
-- a version of preprocess when the circuit only has tof and cnot. it
-- moves all the cont to the ends by commuting cot with tof. But
-- commuting tof and cnot, it will introduce new tof, so this function
-- also minimize the number of tofs intruduced by commuting.
id_tof_cnot :: (Gate, Gate) -> (Gate, Gate, Gate)
id_tof_cnot (Cnot i j, Toffoli a b c) = case i /= b && i /= c && j == a of
True -> (Toffoli a b c, Toffoli i b c, Cnot i j)
preProcess_tof_cnot' :: [Gate] -> Maybe [Gate]
preProcess_tof_cnot' ((Cnot i j) : (Toffoli a b c) : t) =
if i /= b && i /= c && j == a
then
( do
-- t' <- (preProcess_tof_cnot' ((Cnot i j) : t))
return (Toffoli a b c : Toffoli i b c : Cnot i j : t)
)
else
( do
-- t' <- (preProcess_tof_cnot' ((Cnot i j) : t))
return (Toffoli a b c : Cnot i j : t)
)
preProcess_tof_cnot' (h : xs) = do
xs' <- preProcess_tof_cnot' xs
return (h : xs')
preProcess_tof_cnot' [] = Nothing
tofn2tof :: Gate -> Gate
tofn2tof h@(Toffolin [a, b, c]) = Toffoli a b c
tofn2tof h@(Toffolin [a, b]) = Cnot a b
tofn2tof x = x
tofns2tofs = map tofn2tof
tof2ccz (Toffoli a b c) = CCZ a b c
tof2ccz x = x
preProcess_tof_cnot = repeatedly preProcess_tof_cnot'
-- Specialied preprocess function for Galois field multiplier cirucuit.
-- commuting cnot and tof. two cases 1) cnot and tof commute. 2) need
-- to introdue addtional tof.
-- move a cnot to the left or right. l and r are tow sequence of tof
-- gates.
move_cnot :: Gate -> ([Gate], [Gate]) -> ([Gate], [Gate])
move_cnot (Cnot i j) (l, r) = (l', r')
where
target (Toffoli a b c) = a
ltt = filter (\x -> target x == j) l
rtt = filter (\x -> target x == j) r
(l', r') = if length ltt <= length rtt then (l1, []) else ([], r1)
new_tof (Toffoli a b c) = Toffoli i b c
l1 = map new_tof ltt
r1 = map new_tof rtt
move_cnot _ _ = error "wrong use of move_cnot. It must be used in Galois field multiplier circuit."
-- move a cnot to the left or right. l and r are tow sequence of tof
-- gates.
move_cnotg :: [Gate] -> ZXTerm
move_cnotg gl = zxt
where
xs = map tof2ccz_cnot2cnot gl
l = takeWhile (not . isCnot) xs
t = drop (length l) xs
m = takeWhile isCnot t
r = drop (length (l ++ m)) xs
nl = length m `div` 2 + 1
nr = length m - nl
ml = take nl m
mr = drop nl m
lml = l ++ ml
rmr' = reverse (mr ++ r)
lmlg = bubleCliffordLeft $ c2zx2 lml
rmrg = reverse $ bubleCliffordLeft $ c2zx2 rmr'
zxt = lmlg ++ rmrg
isCnot (Cnot i j) = True
isCnot _ = False
move_cnots :: [Gate] -> [Gate]
move_cnots xs = xsok
where
l = takeWhile (not . isCnot) xs
t = drop (length l) xs
m = takeWhile isCnot t
r = drop (length (l ++ m)) xs
aux (h@(Cnot i j) : t) (l, r) = case move_cnot h (l, r) of
(l', []) -> Data.Bifunctor.first (l' ++) (aux t (l, r))
([], r') -> ([], h : t)
aux [] (l, r) = ([], [])
ll = aux m (l, r)
rr = aux (reverse $ snd ll) (reverse r, reverse l)
xsok = if null (snd rr) then fst ll `union` fst rr ++ l ++ r else error "move_cnot has not been completed"
move_cnots' :: [Gate] -> LMR [Gate]
move_cnots' xs = xsok
where
l = takeWhile (not . isCnot) xs
t = drop (length l) xs
m = takeWhile isCnot t
r = drop (length (l ++ m)) xs
aux (h@(Cnot i j) : t) (l, r) = case move_cnot h (l, r) of
(l', []) -> Data.Bifunctor.first (l' ++) (aux t (l, r))
([], r') -> ([], h : t)
aux [] (l, r) = ([], [])
ll = aux m (l, r)
rr = aux (reverse $ snd ll) (reverse r, reverse l)
xsok' = if null (snd rr) then fst ll `union` fst rr ++ l ++ r else error "move_cnot has not been completed"
--ll' = ll1 ++ [Cnot i j ]
xsok = LMR [] xsok' []
-- | Translation from Gate to ZXTerm. H gate is translated to HGadget,
-- later the HGadget between gadgets will be decomposed to into the
-- ZXTerm without H gate. The HGadgets in the two ends of the diagram
-- will stay. Other generalized gadget gates (Clifford gates) will be
-- moved to the left.
gtrans :: Gate -> ZXTerm
gtrans (I i) = []
gtrans (X i) = [XG i]
gtrans (Y i) = [XG i, ZG i]
gtrans (H i) = [HG i]
gtrans (Cnot i j) = [CnotG i j]
gtrans (CX i j) = [CnotG i j]
gtrans (Swap i j) = [SwapG i j]
gtrans (T i) = [G 1 [i]]
--gtrans (T' i) = [G 7 [i]]
--gtrans (CS i j) = [] -- Not considered for now
--gtrans (CS' i j) = [] -- Not considered for now
gtrans (CZ i j) = [CZG i j] --[G 6 [i, j], G 2 [i], G 2 [j]]
--gtrans (CCZ i j k) = [G 1 [i], G 1 [j], G 1 [k], G 7 [i, j], G 7 [i, k], G 7 [j, k],G 1 [i, j, k]]
gtrans (CCZ i j k) = [CNZG (sort [i, j, k])]
gtrans (CNZ inds) = [CNZG (sort inds)]
gtrans (S i) = [SG i]
--gtrans (S' i) = [S'G i]
gtrans (Z i) = [ZG i]
gtrans (Toffoli i j k) = [HG i] ++ gtrans (CCZ i j k) ++ [HG i]
-- Toffolin has been preprocssed
--gtrans (P is) = [] -- Not cosidered for now
--gtrans (M i) = [] -- Not cosidered for now
gtrans (Init s i) = [InitG s i]
gtrans (Term s i) = [TermG s i]
cir2zx :: [Gate] -> ZXTerm
cir2zx = concatMap gtrans
-- | Deocompe HG and CNZG into basic gate sets i.e. BGS = {gadgets and
-- Clifford and Init and Term}.
-- | translate HGs to BGS. g2h stands for gate to gadgets.
h2g :: Int -> ZXAtom -> ZXTerm
h2g m (HG i) = [InitG QMY (m + 1), SwapG i (m + 1), G 2 (sort [i, m + 1]), TermG QMY (m + 1)]
h2g m x = [x]
hRewrite' :: Int -> ZXTerm -> ZXTerm
hRewrite' m term@((HG i) : t) = h2g m (HG i) ++ hRewrite' (m + 1) t
hRewrite' m [] = []
hRewrite' m (h : t) = h : hRewrite' m t
hRewrite t = hRewrite' (maxIndexOfZXTerm t) t
maxIndexOfZXTerm :: ZXTerm -> Int
--maxIndexOfZXTerm [] = error "maximum over empty list"
maxIndexOfZXTerm zxterm = maximum $ wiresOfTerm zxterm
-- | CCZ to 7 gadgets
ccz_to_7gs :: ZXAtom -> ZXTerm
ccz_to_7gs (CNZG inds) = case inds of
[h] -> [ZG h]
[i, j] -> [G 6 (sort [i, j]), G 2 [i], G 2 [j]]
[i, j, k] ->
[ G 1 [i],
G 1 [j],
G 1 [k],
G 7 (sort [i, j]),
G 7 (sort [i, k]),
G 7 (sort [j, k]),
G 1 (sort [i, j, k])
]
-- | rewrite CNZ gate to BGS.
cnzRewrite' :: Int -> ZXTerm -> ZXTerm
cnzRewrite' n term@((CNZG inds) : t) = case inds of
[h] -> ZG h : cnzRewrite' n t
[i, j] -> [G 6 [i, j], G 2 [i], G 2 [j]] ++ cnzRewrite' n t
-- [i,j] -> [CZG i j] ++ cnzRewrite' n t
[i, j, k] ->
[ G 1 [i],
G 1 [j],
G 1 [k],
G 7 [i, j],
G 7 [i, k],
G 7 [j, k],
G 1 [i, j, k]
]
++ cnzRewrite' n t
where
-- (i:j:r) -> [InitG QP (m), G 7 [m], G 1 (sort[j,m]), G 1 (sort[i,m]), G 7 (sort[i,j,m]), HG m] ++ cnzRewrite' m ((CNZG (sort(m:r))):t) ++ [TermG QMY m]
m = n + 1
cnzRewrite' n [] = []
cnzRewrite' n (h : t) = h : cnzRewrite' n t
cnzRewrite t = cnzRewrite' (maxIndexOfZXTerm t) t
twire :: ZXAtom -> Int
twire (CnotG i j) = i
cwire :: ZXAtom -> Int
cwire (CnotG i j) = j
isCZG :: ZXAtom -> Bool
isCZG (CZG _ _) = True
isCZG _ = False
isCnotG :: ZXAtom -> Bool
isCnotG (CnotG _ _) = True
isCnotG _ = False
isCNZG :: ZXAtom -> Bool
isCNZG (CNZG _) = True
isCNZG _ = False
type MM = M.Map Int ZXAtom
--mmcnz :: MM -> MM
type ZXTermI = [(ZXAtom, Int)]
mcnzok t = l ++ m
where
(l, m, r) = mcnz (maxIndexOfZXTerm t) (t2ti t) t ([], [], [])
t2ti :: ZXTerm -> ZXTermI
t2ti xs = zip xs [0 .. (length xs)]
unjust :: Maybe a -> a
unjust (Just a) = a
focusOnwiresI :: [Int] -> ZXTermI -> ZXTermI
focusOnwiresI ws xs = zsok
where
zs' =
filter
( \(x, y) ->
not . null $ (wiresOfAtom x `intersect` ws)
)
xs
(rzs, zs) = partition (\(x, y) -> isCZG x || (isCNZG x && length (wiresOfAtom x) <= 2)) zs'
(rest, zsok) = partition (\(x, y) -> isCnotG x && notElem (twire x) ws) zs
mcnz :: Int -> ZXTermI -> ZXTerm -> (ZXTerm, ZXTerm, ZXTerm) -> (ZXTerm, ZXTerm, ZXTerm)
mcnz mm ((CNZG ws, k) : t) ys (lll, rrr, sss) = case length ws of
1 -> mcnz mm t ys (lll ++ [ZG (head ws)], rrr, sss ++ [ZG (head ws)])
2 -> mcnz mm t ys (lll ++ [CZG (head ws) (last ws)], rrr, sss ++ [CZG (head ws) (last ws)])
-- new added clause for 7 gadges translation.
3 -> mcnz mm t ys (lll ++ ccz_to_7gs (CNZG ws), rrr, sss ++ ccz_to_7gs (CNZG ws))
_ -> mzx
where
asows =
[ (cc, ws2)
| ws2 <- choosen 2 ws,
let cc = focusOnwiresI ws2 t,
not . null $cc
]
fit = filter (\(x, y) -> isCNZG (fst . head $ x) && y == y `intersect` wiresOfAtom (fst . head $ x)) asows
fit2 =
map
( \(x, y) ->
(filter (\(a, b) -> (isCNZG a && y == y `intersect` wiresOfAtom a) || (not . isCNZG $ a)) x, y)
)
fit
ordf = sortBy (compare `on` mylen) fit2
mylen (x, y) = length $ takeWhile (isCNZG . fst) x
best = last ordf
ij = snd best
bb = takeWhile (isCNZG . fst) (fst best)
mzx = if null fit then mcnz (mm + 1) ((CNZG (sort ((mm + 1) : drop 2 ws)), k) : t) ys (lll ++ mcnzh2 (mm + 1) (take 2 ws), TermG QMY (mm + 1) : rrr, sss) else mcnz (mm + 1) xsi ys' (lll ++ mcnzh2 (mm + 1) ij, TermG QMY (mm + 1) : rrr, sss)
ys' = mcnzh (mm + 1) (head ij, last ij) (map snd bb) ys
xsi = ssk ++ drop (k + 1) (t2ti ys')
ssk = [(CNZG (sort ((mm + 1) : (ws \\ ij))), k)]
mcnz mm [] ys (lll, rrr, sss) = (lll, rrr, sss)
mcnz mm (h : t) ys (lll, rrr, sss) = mcnz mm t ys (lll ++ [fst h], rrr, sss ++ [fst h])
mcnzh2 :: Int -> [Int] -> ZXTerm
mcnzh2 n [i, j] = [InitG QP m, G 7 [m], G 1 (sort [j, m]), G 1 (sort [i, m]), G 7 (sort [i, j, m]), HG m]
where
m = n
mcnzh :: Int -> (Int, Int) -> [Int] -> ZXTerm -> ZXTerm
mcnzh _ _ [] ys = ys
mcnzh mm (w1, w2) (h : t) ys = zs''
where
oa = ys !! h
na = CNZG (sort ((wiresOfAtom oa \\ [w1, w2]) ++ [mm]))
zs = updateList ys h na
zs' = mcnzh mm (w1, w2) t zs
zs'' = zs'
updateList :: Eq a => [a] -> Int -> a -> [a]
updateList xs i a = ys
where
l = take i xs
r = drop (i + 1) xs
ys = l ++ [a] ++ r
-- | New Translation. To combine as many overlaped Control Z gate as
-- possible.
-- | Given a n-control Z Gate, find all n-control Z gates in the given
-- term sharing 2 controls without interception.
-- findCNZsharing2ControlsAs :: (Int,Int) -> ZXTerm -> [ZXAtom]
-- findCNZsharing2ControlsAs (i,j) xs =
c2zx' :: [Gate] -> ZXTerm
c2zx' = concatMap gtrans
c2zx = mcnzok . c2zx' . hreduce . desugar_to_ZZHST . preProcess
c2zx2 = cnzRewrite . c2zx' . hreduce . desugar_to_ZZHST . preProcess
moveh x = (hred35 . bubCLR) (LMR [] (desugar35 x) [])
c2zx35 x = (cnzRewrite . c2zx' . mid) ((hred35 . bubCLR) (LMR [] (desugar35 x) []))
c2term35 x = LMR l m r
where
LMR a b c = zx2term $ c2zx35 x
LMR d e f = (hred35 . bubCLR) (LMR [] (desugar35 x) [])
l = c2zx d ++ a
m = b
r = c ++ c2zx f
mod5tc = [HG 6, InitG QP 7, InitG QP 8, InitG QP 9, InitG QP 10, InitG QP 11, InitG QP 12, InitG QP 13, InitG QP 14, InitG QP 15, InitG QP 16, InitG QP 17, InitG QP 18, InitG QP 19, InitG QP 20, InitG QP 21, InitG QP 22, InitG QP 23, InitG QP 24, InitG QP 25, InitG QP 26, InitG QP 27, InitG QMY 28, InitG QMY 29, InitG QMY 30, InitG QMY 31, InitG QMY 32, InitG QMY 33, InitG QMY 34, InitG QMY 35, InitG QMY 36, SwapG 7 28, SwapG 8 29, SwapG 11 30, SwapG 14 31, CZG 6 14, CZG 6 4, SwapG 15 32, CZG 6 15, CZG 6 3, SwapG 16 33, CZG 6 16, CZG 6 2, SwapG 17 34, SwapG 20 35, CZG 6 20, CZG 6 5, SwapG 23 36, CZG 6 23, CZG 6 1, G 2 [7, 28], G 2 [8, 29], G 2 [11, 30], G 2 [14, 31], G 2 [15, 32], G 2 [16, 33], G 2 [17, 34], G 2 [20, 35], G 2 [23, 36], G 0 [22], G 0 [25], G 0 [5, 22], G 0 [5, 25], G 0 [6, 22], G 0 [6, 25], G 0 [5, 6, 22], G 0 [5, 6, 25], G 0 [21], G 0 [27], G 0 [1, 21], G 0 [1, 27], G 0 [2, 21], G 0 [2, 27], G 0 [1, 2, 21], G 0 [1, 2, 27], G 2 [2], G 2 [5], G 2 [6], G 0 [9], G 6 [5, 6], G 0 [5, 9], G 0 [6, 9], G 0 [5, 6, 9], G 1 [1], G 7 [10], G 7 [12], G 7 [13], G 7 [18], G 7 [19], G 7 [24], G 7 [26], G 7 [28], G 7 [29], G 7 [30], G 7 [31], G 7 [32], G 7 [33], G 7 [34], G 7 [35], G 7 [36], G 7 [1, 2], G 1 [1, 24], G 1 [1, 26], G 1 [28, 1], G 1 [30, 1], G 1 [34, 1], G 1 [35, 1], G 7 [2, 5], G 7 [2, 6], G 7 [2, 9], G 1 [28, 2], G 1 [30, 2], G 1 [33, 2], G 1 [34, 2], G 1 [36, 2], G 1 [3, 18], G 1 [3, 24], G 1 [29, 3], G 1 [32, 3], G 1 [33, 3], G 1 [4, 12], G 1 [4, 26], G 1 [29, 4], G 1 [31, 4], G 1 [32, 4], G 1 [5, 12], G 1 [5, 18], G 1 [31, 5], G 1 [35, 5], G 1 [36, 5], G 1 [6, 13], G 1 [6, 19], G 1 [7, 10], G 1 [8, 10], G 1 [11, 13], G 1 [17, 19], G 7 [21, 27], G 7 [22, 25], G 7 [28, 1, 2], G 7 [30, 1, 2], G 7 [34, 1, 2], G 7 [1, 3, 24], G 7 [1, 4, 26], G 7 [35, 1, 5], G 1 [1, 21, 27], G 7 [33, 2, 3], G 1 [2, 5, 6], G 1 [2, 5, 9], G 7 [36, 2, 5], G 1 [2, 6, 9], G 1 [2, 21, 27], G 7 [29, 3, 4], G 7 [32, 3, 4], G 7 [3, 5, 18], G 7 [4, 5, 12], G 7 [31, 4, 5], G 1 [5, 22, 25], G 7 [6, 11, 13], G 7 [6, 17, 19], G 1 [6, 22, 25], G 7 [7, 8, 10], G 7 [1, 2, 21, 27], G 7 [2, 5, 6, 9], G 7 [5, 6, 22, 25], TermG QMY 28, TermG QMY 29, TermG QMY 30, TermG QMY 31, TermG QMY 32, TermG QMY 33, TermG QMY 34, TermG QMY 35, TermG QMY 36, HG 9, HG 10, CZG 9 10, HG 12, HG 13, CZG 12 13, HG 18, HG 19, CZG 18 19, HG 21, HG 22, CZG 21 22, HG 24, HG 25, CZG 24 25, HG 26, CZG 6 26, HG 27, CZG 6 27, HG 6, TermG QMY 27, TermG QMY 26, TermG QMY 25, TermG QMY 24, TermG QMY 23, TermG QMY 22, TermG QMY 21, TermG QMY 20, TermG QMY 19, TermG QMY 18, TermG QMY 17, TermG QMY 16, TermG QMY 15, TermG QMY 14, TermG QMY 13, TermG QMY 12, TermG QMY 11, TermG QMY 10, TermG QMY 9, TermG QMY 8, TermG QMY 7]
-- | First example in the paper, i.e. Mod5_4
mod54 = [CCZ 0 3 4, CCZ 2 3 4, CZ 3 4, CCZ 1 2 4, CZ 2 4, CCZ 0 1 4, CZ 1 4, CZ 0 4]
-- | Second example, i.e. tof3
tof2 = [Toffolin [2, 0, 1]]
tof3 = [Toffolin [3, 0, 1, 2]]
tof4 = [Toffolin [4, 0, 1, 2, 3]]
tof5 = [Toffolin [5, 0, 1, 2, 3, 4]]
tof6 = [Toffolin [5, 0, 1, 2, 3, 4, 6]]
tof7 = [Toffolin [5, 0, 1, 2, 3, 4, 6, 7]]
tof8 = [Toffolin [5, 0, 1, 2, 3, 4, 6, 7, 8]]
tof9 = [Toffolin [5, 0, 1, 2, 3, 4, 6, 7, 8, 9]]
-- | other example
rd32 = [Toffoli 4 1 2, Cnot 2 1, Toffoli 4 2 3, Cnot 3 2]
--qft_4 = [H 1,Toffolin [2,1],T' 2,Toffolin [2,1],T 1,T 2,H 5,Toffolin [1,3],S' 3,Toffolin [5,1],Toffolin [3,5],T 3,T' 5,Toffolin [3,1],Toffolin [5,1],T 3,T' 5,Toffolin [5,3],H 3,T 3,H 3,Toffolin [5,3],T' 3,T 5,Toffolin [5,1],Toffolin [3,1],T 5,T' 3,Toffolin [3,5],Toffolin [5,1],S 3,Toffolin [1,3],H 5,Toffolin [5,1],H 1,CCZ 4 5 1,H 1,Toffolin [5,1],T 5,S 5,H 5,T 5,S 5,H 5,T 5,H 5,T 5,S 5,H 5,T 5,S 5,H 5,T 5,S 5,H 5,T 5,H 5,T 5,S 5,H 5,T 5,S 5,H 5,T 5,S 5,H 5,T 5,H 5,T 5,S 5,H 5,T 5,S 5,H 5,T 5,H 5,T 5,S 5,H 5,T 5,H 5,T 5,H 5,T 5,H 5,T 5,H 5,T 5,S 5,H 5,T 5,H 5,T 5,S 5,H 5,T 5,S 5,H 5,T 5,S 5,H 5,T 5,S 5,H 5,T 5,S' 5,H 5,T 5,H 5,T 5,S 5,Toffolin [5,1],H 1,CCZ 4 5 1,H 1,Toffolin [5,1],H 2,Toffolin [3,2],T' 3,Toffolin [3,2],T 2,T 3,H 5,Toffolin [2,4],S' 4,Toffolin [5,2],Toffolin [4,5],T 4,T' 5,Toffolin [4,2],Toffolin [5,2],T 4,T' 5,Toffolin [5,4],H 4,T 4,H 4,Toffolin [5,4],T' 4,T 5,Toffolin [5,2],Toffolin [4,2],T 5,T' 4,Toffolin [4,5],Toffolin [5,2],S 4,Toffolin [2,4],H 5,H 3,Toffolin [4,3],T' 4,Toffolin [4,3],T 3,T 4]
-- | after translation, we need to do some rewriting on ZXTerm.
-- | First, we consider the case where the ZXTerm is a list of
-- homogneous gadgets, i.e. no "generalzed gadgets". In this case,
-- they are all commute with each other, so we can freely reorder
-- them. Actually, we will sort them in some order easier for us to do
-- rewrite. We don't have a normal form here, but the idea is to fuse
-- as many gadgets as possible, so the sorting should act grouping
-- fusable gadgets. Fusable gadgets are the ones with the same
-- targets. So the ordering used to sort is first comparing the number
-- of targets, then comparing the indexes.
-- | another way to fuse is also considered for efficency reasons,
-- will see it later.
-- | Since we need constantly divides a circuits into three part, we
-- define the following data structure that is the term we will do
-- reduction on. LMR stands for left mid right. Normally we want that
-- in LMR l m r, l is the left end of the circuits consisting only of
-- Init and Clifford gates, r is the right end consisting only of Term
-- and Clifford gates. We have several function for doing so. moveIT
-- moves Init gate to l, and Term gate to r. moveClifford moves all
-- movable Cliffords to l or r.
data LMR a = LMR a a a deriving (Eq, Ord)
type Term = LMR ZXTerm
instance Show Term where
show = showterm
instance Show (LMR [Gate]) where
show = showcir
showterm :: Term -> String
showterm (LMR l m r) = show l ++ "\n" ++ show m ++ "\n" ++ show r
showcir :: LMR [Gate] -> String
showcir (LMR l m r) = show l ++ "\n" ++ show m ++ "\n" ++ show r
-- | class for Thing that can be show in pdf.
class PDFable a where
topdf_generic :: Format -> a -> IO ()
topdf :: a -> IO ()
topdf = topdf_generic Preview
topdf_file :: a -> IO ()
topdf_file = topdf_generic PDF
instance PDFable [Gate] where
topdf_generic format cir = do
print_generic
format
( \x -> do
foldM gl2cir x (reindexCir (+ 1) cir)
)
(replicate (1 + maximum (wiresOfCir cir)) qubit)
instance PDFable [[Gate]] where
topdf_generic format = topdf_generic format . intercalate [M 0]
instance PDFable ZXTerm where
topdf_generic format cir = do
print_generic
format
( \x -> do
foldM zx2cir x cir
)
(replicate (1 + maximum (wiresOfTerm cir) - initqw) qubit)
where
initqw = length $ wiresOfTerm $ filter isInit cir
instance PDFable Term where
topdf_generic format term@(LMR l m r) = do
let xs = replicate (1 + maximum (wiresOfTerm cir) - initqw) qubit
print_generic
format
( \x -> do
x' <- foldM zx2cir x l
-- comment "Clifford on the left"
comment ("t-count: " ++ show (tCount term))
-- comment "t-count per wire"
label x' (map show (aveTGs term))
foldM_ zx2cir x' m
comment "Clifford on the right"
foldM zx2cir x' r
)
xs
where
(ll, lr) = partition isInit l
l' = lr ++ ll
cir = l ++ m ++ r
initqw = length $ wiresOfTerm $ filter isInit cir
instance PDFable (LMR [Gate]) where
topdf_generic format term@(LMR l' m' r') = do
let xs = replicate (maximum $ wiresOfCir cir) qubit
print_generic
format
( \x -> do
foldM_ gl2cir x l
comment "Clifford on the left"
label x (repeat "|")
foldM_ gl2cir x m
label x (repeat "|")
comment "Clifford on the right"
foldM gl2cir x r
)
xs
where
l = reindexCir (+ 1) l'
m = reindexCir (+ 1) m'
r = reindexCir (+ 1) r'
cir = l ++ m ++ r
topdf' term@(LMR l m r) = do
let xs = replicate (1 + maximum (wiresOfTerm cir) - initqw) qubit
print_generic
PDF
( \x -> do
foldM_ zx2cir x l
comment (show (tCount term))
label x (map show (aveTGs term))
foldM_ zx2cir x m
foldM zx2cir x r
)
xs
where
cir = l ++ m ++ r
initqw = length $ wiresOfTerm $ filter isInit cir
unJust :: Maybe a -> a
unJust (Just x) = x
focusOnwiresCir :: [Int] -> [Gate] -> [Gate]
focusOnwiresCir wires = filter (\x -> not . null $ wiresOfGate x `intersect` wires)
focusOnwiresCirExactly :: [Int] -> [Gate] -> [Gate]
focusOnwiresCirExactly wires =
filter
( \x ->
Set.fromList (wiresOfGate x) `Set.isSubsetOf` Set.fromList wires
)
maxIndexOfCir :: [Gate] -> Int
maxIndexOfCir cir = maximum $ wiresOfCir cir
focusOnwires :: [Int] -> ZXTerm -> ZXTerm
focusOnwires wires = filter (\x -> not . null $ wiresOfAtom x `intersect` wires)
focusOnwiresExactly :: [Int] -> ZXTerm -> ZXTerm
focusOnwiresExactly wires =
filter
( \x ->
Set.fromList (wiresOfAtom x) `Set.isSubsetOf` wires'
)
where
wires' = Set.fromList wires
-- | We use Wire and Int interchangably.
type Wire = Int
wiresOfAtom :: ZXAtom -> [Wire]
wiresOfAtom (InitG s i) = [i]
wiresOfAtom (TermG s i) = [i]
wiresOfAtom (SwapG i j) = [i, j]
wiresOfAtom (Tn i j) = [j]
wiresOfAtom (CTn i j k) = [j, k]
wiresOfAtom (CCTn i j k l) = [j, k, l]
wiresOfAtom (G p inds) = inds
wiresOfAtom (CNZG inds) = inds
wiresOfAtom (HG i) = [i]
wiresOfAtom (XG i) = [i]
wiresOfAtom (YG i) = [i]
wiresOfAtom (ZG i) = [i]
wiresOfAtom (CZG i j) = [i, j]
wiresOfAtom (SG i) = [i]
wiresOfAtom (S'G i) = [i]
wiresOfAtom (CnotG i j) = [i, j]
wiresOfTerm :: ZXTerm -> [Wire]
wiresOfTerm term = foldl' union [] (map wiresOfAtom term)
gorder :: ZXAtom -> ZXAtom -> Ordering
gorder (G k is) (G l is') = if length is == length is' then compare (sort is) (sort is') else compare (length is) (length is')
gorder1 :: ZXAtom -> ZXAtom -> Ordering
gorder1 (G k is) (G l is') =
if is == is' then compare k l else compare is is'
-- | fuse two reduced homogeneous gadget lists. xs ys must be reduced.
fuse' :: ZXTerm -> ZXTerm
fuse' [] = []
fuse' [a] = [a]
fuse' (a : t) = last t' : fuse' (init t')
where
t' = fuse'1 a t
fuse'1 :: ZXAtom -> ZXTerm -> ZXTerm
fuse'1 (G p xs) [] = [G p xs]
fuse'1 a@(G p xs) (h@(G q ys) : t) = if xs == ys then fuse'1 (G (p + q `mod` 8) xs) t else h : fuse'1 a t
--(sort xs) == (sort ys), xs ys will always be sorted list
-- | fast way to do fusion O(logt)
-- | Fuse adjacent gadets with the same target indexes. The rest stays
-- the same.
fuse2 :: ZXTerm -> Maybe ZXTerm
fuse2 [] = Nothing
fuse2 [a] = Nothing
fuse2 (a@(G k is) : b@(G l is') : t) =
if sort is == sort is'
then return (G ((k + l) `mod` 8) is : t)
else
( do
r1 <- fuse2 $ b : t
return $ a : r1
)
fuse2 (h : t) = do
t' <- fuse2 t
return (h : t')
-- | first sort, then repeatedly fuse 2 adjacent Gadgets. Only applies
-- to homogeneous Gadget diagram i.e. all the components are gadgets.
fuseHomoGs :: ZXTerm -> ZXTerm
fuseHomoGs t = repeatedly fuse2 (sortBy gorder t)
sortGs = sortBy gorder
-- | determine whether the ZXAtom is a Gadget or not.
isGadget :: ZXAtom -> Bool
isGadget (G _ _) = True
isGadget _ = False
-- | determine whether the ZXAtom is a Init or not.
isInit :: ZXAtom -> Bool
isInit (InitG s i) = True
isInit _ = False
-- | determine whether the ZXAtom is a Term or not.
isTerm :: ZXAtom -> Bool
isTerm (TermG s i) = True
isTerm _ = False
-- | determine whether the ZXAtom is a HG or not.
isHG :: ZXAtom -> Bool
isHG (HG i) = True
isHG _ = False
-- | determine whether the ZXAtom is a nonIT or not.
isClifford :: ZXAtom -> Bool
isClifford (SwapG _ _) = True
isClifford (HG _) = True
isClifford (XG _) = True
isClifford (YG _) = True
isClifford (ZG _) = True
isClifford (CZG _ _) = True
isClifford (SG _) = True
isClifford (S'G _) = True
isClifford (CnotG _ _) = True
isClifford _ = False
-- | substute short for long if possible, otherwise identity. only
-- consider the gadget with targets in the given index list. And the
-- term must be homogeneous and distinct (i.e. after being fused)
-- gadgets term.
-- | the first argument should be an identity. Both argumens should be
-- homogeneous lists of gadgets. This one works on terms.
rewriteM :: [ZXTerm] -> Term -> Term
rewriteM eqns term = foldl' (flip rewriteWithIdentity) term eqns
rewriteMM :: [ZXTerm] -> Term -> (Term, [LogEntry])
rewriteMM eqns term = runWriter $ foldM (flip rewriteWithIdentityM) term eqns
heuri5M = heuri'M
heuri'M (LMR l m r) = rewriteMM (i45effun $wiresOfTerm m) (LMR l m r)
heuriM (LMR l m r) = rewriteMM (id4s $wiresOfTerm m) (LMR l m r)
heuri5 (LMR l m r) = rewriteM (i45effun $wiresOfTerm m) (LMR l m r)
heuri5_fast (LMR l m r) = rewriteM (i45effun_fast $wiresOfTerm m) (LMR l m r)
heuri5_inc (LMR l m r) = rewriteM (i45effun_inc $wiresOfTerm m) (LMR l m r)
heuri5_dec (LMR l m r) = rewriteM (i45effun_dec $wiresOfTerm m) (LMR l m r)
heuri6 (LMR l m r) = rewriteM (i6effun $wiresOfTerm m) (LMR l m r)
heurif idfun (LMR l m r) = rewriteM (idfun $wiresOfTerm m) (LMR l m r)
rewriteWithIdentity :: ZXTerm -> Term -> Term
rewriteWithIdentity eo term@(LMR lo mo ro) =
if (t_count m2' >= 8) && (t_count commonGadgets > (t_count e `div` 2)) then fused else term
where
e = sortGinds eo
(l2, m2, r2) = (sortGinds lo, sortGinds mo, sortGinds ro)
m2' = focusOnwiresExactly (wiresOfTerm e) m2
m2'' = filter isoddG m2'
e' = filter isoddG e
commonGadgets = e' `intersectModuloParity` m2''
m1 = fuseHomoGs (e ++ m2)
(om, em) = partition isoddG m1
fused = LMR (l2 ++ em) om r2
type LogEntry = ZXTerm
rewriteWithIdentityM :: ZXTerm -> Term -> Writer [LogEntry] Term
rewriteWithIdentityM eo term@(LMR lo mo ro) =
if t_count m2' >= 8
then
if t_count commonGadgets > (t_count e `div` 2)
then
( do
tell [e]
return fused
)
else
( do
return term
)
else do
return term
where
e = sortGinds eo
(l2, m2, r2) = (sortGinds lo, sortGinds mo, sortGinds ro)
m2' = focusOnwiresExactly (wiresOfTerm e) m2
m2'' = filter isoddG m2'
e' = filter isoddG e
commonGadgets = e' `intersectModuloParity` m2''
m1 = fuseHomoGs (e ++ m2)
(om, em) = partition isoddG m1
fused = LMR (l2 ++ em) om r2
intersectModuloParity :: ZXTerm -> ZXTerm -> ZXTerm
intersectModuloParity xs ys = zs
where
xs' = moduloParityOnTerm xs
ys' = moduloParityOnTerm ys
zs = xs' `intersect` ys'
-- | Identity is represented by a function on wires, which generates
-- the corresponding identity when given wires. When using this type,
-- programmer need to make sure that the term is indeed an identity by
-- himself. The int indicate how may wires this identity needs.
type MyId = (Int, [Wire] -> ZXTerm)
rewriteUsingMyId :: MyId -> Term -> Term
rewriteUsingMyId myid@(numOfwire, fun) term@(LMR l m r) = termReduced
where
wiresNeedConsidered = wiresOfTerm m
choosenWiress = chooseNWireFrom numOfwire wiresNeedConsidered
myIdsOnChoosenWiress = map fun choosenWiress
termReduced' = foldl' (flip rewriteWithIdentity) term myIdsOnChoosenWiress
termReduced = moveEvenGToLeft termReduced'
--- | Identities we will consider.
myid4 :: MyId
myid4 = (4, idFunOn4Wires)
-- | when calling this function, make sure there are 4 distinct indexes in the
-- first argument.
idFunOn4Wires :: [Int] -> ZXTerm
idFunOn4Wires inds = [G 1 [x] | x <- inds] ++ [G 7 (sort xs) | xs <- choosen 2 inds] ++ [G 1 (sort xs) | xs <- choosen 3 inds] ++ [G 7 (sort inds)]
id4 :: [Int] -> ZXTerm
id4 = idFunOn4Wires
myid5 :: MyId
myid5 = (5, idFunOn5Wires)
-- | when calling this function, make sure there are 5 distinct
-- indexes in the first argument.
idFunOn5Wires :: [Int] -> ZXTerm
idFunOn5Wires inds = [G 3 [x] | x <- inds] ++ [G 6 (sort xs) | xs <- choosen 2 inds] ++ [G 1 (sort xs) | xs <- choosen 3 inds] ++ [G 7 (sort inds)]
id5 :: [Int] -> ZXTerm
id5 = idFunOn5Wires
-- | when calling this function, make sure there are 5 distinct
-- indexes in the first argument.
idFunOn6Wires :: [Int] -> ZXTerm
idFunOn6Wires inds = [G 6 [x] | x <- inds] ++ [G 5 (sort xs) | xs <- choosen 2 inds] ++ [G 1 (sort xs) | xs <- choosen 3 inds] ++ [G 7 (sort inds)]
id6 :: [Int] -> ZXTerm
id6 = idFunOn6Wires
myid6 :: MyId
myid6 = (6, idFunOn6Wires)
myid7 :: MyId
myid7 = (7, idFunOn7Wires)
-- | used for decrease number of wires of a gadget.
fun_dec (G x ws) = case length ws of
4 -> concat $ replicate (x `mod` 8) (drop 1 $ reverse (id4 ws))
5 -> concat $ replicate (x `mod` 8) (drop 1 $ reverse (id5 ws))
6 -> concat $ replicate (x `mod` 8) (drop 1 $ reverse (id6 ws))
7 -> concat $ replicate (x `mod` 8) (drop 1 $ reverse (id7 ws))
_ -> [G x ws]
-- | when calling this function, make sure there are 5 distinct
-- indexes in the first argument.
idFunOn7Wires :: [Int] -> ZXTerm
idFunOn7Wires inds = [G 2 [x] | x <- inds] ++ [G 4 (sort xs) | xs <- choosen 2 inds] ++ [G 1 (sort xs) | xs <- choosen 3 inds] ++ [G 7 (sort inds)]
id7 :: [Int] -> ZXTerm
id7 = idFunOn7Wires
id4s :: [Int] -> [ZXTerm]
id4s wires = [id4 fourwires | fourwires <- choosen 4 wires]
id5s :: [Int] -> [ZXTerm]
id5s wires = [] : [id5 fivewires | fivewires <- choosen 5 wires]
id6s :: [Int] -> [ZXTerm]
id6s wires = [] : [id6 sixwires | sixwires <- choosen 6 wires]
id7s :: [Int] -> [ZXTerm]
id7s wires = [] : [id7 sevenwires | sevenwires <- choosen 7 wires]
-- | when calling this function, make sure there are 5 distinct
-- indexes in the first argument.
id45s :: [Int] -> [ZXTerm]
id45s w =
[ fuseHomoGs (e4 ++ e5)
| ff <- choosen 5 w,
e4 <- id4s ff,
e5 <- id5s ff
]
id45s234 w = id45s2 w ++ id45s3 w ++ id45s4 w
id45s5 :: [Int] -> [ZXTerm]
id45s5 w =
[ fuseHomoGs (e1 ++ e2 ++ e3 ++ e4 ++ e5 ++ e6)
| ff <- choosen 5 w,
let c4 = id4s ff,
let e1 = c4 !! 1,
let e2 = c4 !! 2,
let e3 = c4 !! 3,
let e4 = c4 !! 4,
let e5 = c4 !! 5,
let c5 = id5s ff,
let e6 = c5 !! 1
]
id45s3 :: [Int] -> [ZXTerm]
id45s3 w =
[ fuseHomoGs (e3 ++ e4 ++ e5 ++ e6)
| ff <- choosen 5 w,
let c4 = id4s ff,
let e1 = c4 !! 1,
let e2 = c4 !! 2,
let e3 = c4 !! 3,
let e4 = c4 !! 4,
let e5 = c4 !! 5,
let c5 = id5s ff,
let e6 = c5 !! 1
]
id45s4 :: [Int] -> [ZXTerm]
id45s4 w =
[ fuseHomoGs (e2 ++ e3 ++ e4 ++ e5 ++ e6)
| ff <- choosen 5 w,
let c4 = id4s ff,
let e1 = c4 !! 1,
let e2 = c4 !! 2,
let e3 = c4 !! 3,
let e4 = c4 !! 4,
let e5 = c4 !! 5,
let c5 = id5s ff,
let e6 = c5 !! 1
]
id45s2 :: [Int] -> [ZXTerm]
id45s2 w =
[ fuseHomoGs (e4 ++ e5 ++ e6)
| ff <- choosen 5 w,
let c4 = id4s ff,