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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
Transformers, parallel computation, and logarithmic depth
Clayton Sanford1, Daniel Hsu1, and Matus Telgarsky2
1Department of Computer Science, Columbia University, New York, NY, USA
2Courant Institute, New York University, New York, NY, USA
February 15, 2024
Abstract
We show that a constant number of self-attention layers can efficiently simulate—and be simulated
by—a constant number of communication rounds of Massively Parallel Computation. As a consequence,
we show that logarithmic depth is sufficient for transformers to solve basic computational tasks that
cannot be efficiently solved by several other neural sequence models and sub-quadratic transformer
approximations. We thus establish parallelism as a key distinguishing property of transformers.
1
Introduction
The transformer (Vaswani et al., 2017) has emerged as the dominant neural architecture for many sequential
modeling tasks such as machine translation (Radford et al., 2019) and protein folding (Jumper et al., 2021).
Reasons for the success of transformers include suitability to modern hardware and training stability: unlike
in recurrent models, inference and training can be efficiently parallelized, and training is less vulnerable to
vanishing and exploding gradients. However, the advantages of transformers over other neural architectures can
be understood more fundamentally via the lens of representation, which regards neural nets as parameterized
functions and asks what they can efficiently compute.
Many previous theoretical studies of transformers establish (approximation-theoretic and computational)
universality properties, but only at large model sizes (Yun et al., 2020; Pérez et al., 2021). These results
are not unique to transformers and reveal little about which tasks can be solved in a size-efficient manner.
Several other works (e.g., Hahn, 2020; Merrill and Sabharwal, 2022; Sanford et al., 2023) give fine-grained
representational results in the scaling regime where context length grows but model depth is constant. In this
regime, basic algorithmic tasks like matching parentheses and evaluating Boolean formulas are impossible.
In this work, we identify parallelism as a key to distinguishing transformers from other architectures. While
recurrent architectures process their inputs serially, transformers allow independent interactions between the
input tokens, mediated by the inner products between query and key embeddings in self-attention units. We
leverage this property of self-attention to establish a formal connection between transformers and Massively
Parallel Computation (MPC) (Karloff et al., 2010). Concretely, we design transformers that simulate MPC
protocols (and vice versa), and in doing so, we exhibit a wide range of computational tasks that are solved by
logarithmic-depth transformers, including tasks that cannot be efficiently solved with other architectures
such as graph neural nets and recurrent models.
1.1
Our results
We advance the understanding of transformers’ representational capabilities with the following results.
1. The algorithmic capabilities and limitations of logarithmic-depth transformers are captured by the MPC
model (Section 3).
2. There is a simple sequential task that (i) is solved by (and, empirically, learned from data using) logarithmic-
depth transformers, but (ii) cannot be efficiently solved by several alternative architectures (Sections 4
and 5).
1
arXiv:2402.09268v1  [cs.LG]  14 Feb 2024

In more detail, our first collection of results, Theorems 3.1 and 3.4, show that any R-round MPC protocol
can be implemented by a transformer of depth O(R), and that any depth-L transformer can be simulated by an
O(L)-round MPC protocol. The former implies that several graph problems are solved by logarithmic-depth
transformers (Corollary 3.3); the latter implies the near-optimality of these transformers (Corollary 3.5)
conditional on a well-known conjecture about the limitations of MPC algorithms (Conjecture 2.4). A key
technical step (Lemma 3.2) shows how transformers can implement the simultaneous message-passing used in
MPC protocols to communicate between machines. While previous works (Sanford et al., 2023) have used
communication complexity to understand the representational limitations of self-attention layers, our results
show the benefits of the communication lens for understanding the strengths of transformers as well.
Our second set of results concern the k-hop induction heads task, a synthetic sequential task that draws
inspiration from the induction heads primitive of Elhage et al. (2021). The theoretical results of Section 4 prove
that depth L = Θ(log k) is necessary and sufficient for efficient transformer representation. An accompanying
empirical investigation reveals that transformers trained on the task obey the same threshold and recover
a similar model to the theoretical construction. In contrast, Section 5 illustrates that non-parallelizable
recurrent architectures—including state-space models like Mamba (Gu and Dao, 2023)—are unable to solve
the task in a size-efficient manner. Moreover, well-known transformer models with computationally-efficient
alternatives to self-attention, like Performer (Choromanski et al., 2022) and Longformer (Beltagy et al.,
2020), and shallow transformers with chain-of-thought prompting sacrifice their abilities to implement parallel
algorithms, as evidenced by their proven inability to solve this task.
1.2
Related work
Some of the types of lower bounds we sought in this work were inspired by the literature on depth-separation
for feed-forward neural networks (e.g., Eldan and Shamir, 2016; Daniely, 2017; Telgarsky, 2016), which exhibit
functions that are efficiently approximated by deep networks, but not by shallower networks.
Many theoretical approaches have been used to understand the representational capabilities of transformers
and self-attention units in various scaling regimes. Some works model (variants of) transformers as machines
for recognizing formal languages, such as the Dyck languages (Hahn, 2020; Bhattamishra et al., 2020; Yao
et al., 2021; Hao et al., 2022) and star-free regular languages (Angluin et al., 2023). These approaches reveal
inability of fixed-size transformers to handle arbitrarily long inputs. Other works show how transformers
can simulate finite-state automata Liu et al. (2022) with logarithmic depth, and Turing machines with
(unrolled) depth (or chain-of-thought length) scaling polynomially with total runtime Wei et al. (2021);
Malach (2023); Merrill and Sabharwal (2023b). However, it is unclear if these results are near optimal or
even transformer-specific.
Theoretical results about the limitations of constant-depth transformers have been articulated by way of
analogy to circuit complexity (Merrill and Sabharwal, 2023a; Merrill et al., 2022; Merrill and Sabharwal, 2022;
Strobl, 2023; Strobl et al., 2023), implying the inability of constant-depth transformers to solve tasks like
graph connectivity and Boolean formula evaluation. Other works characterize the representational capabilities
of one-layer transformers (Likhosherstov et al., 2021; Sanford et al., 2023), but these approaches do not apply
to deeper models. Sanford et al. study multi-headed attention using communication complexity, a framing
that informs this work’s connection to distributed computing.
The MPC model Karloff et al. (2010); Beame et al. (2017); Goodrich et al. (2011); Andoni et al. (2014);
Im et al. (2023) was introduced to study distributed computing frameworks such as MapReduce Dean and
Ghemawat (2004). A major goal is to design protocols that use few rounds of communication for setups
in which each machine’s local memory is sublinear in the input size. Many advances have been made in
MPC algorithms for important problems (see, e.g., Im et al., 2023, for a recent survey). However, a basic
problem that has resisted progress is connectivity in sparse graphs, where all MPC protocols in this memory
regime appear to require Ω(log n) rounds for input graphs on n vertices. Lower bounds in MPC and related
models were studied by Beame et al. (2017), Roughgarden et al. (2018), and Charikar et al. (2020). The
conjectured impossibility of o(log n)-round protocols for connectivity is now used as basis for conditional
lower bounds (Ghaffari et al., 2019).
Simulation of transformers by recurrent models (Oren et al., 2024) and simulation of graph neural nets
(GNNs) by transformers (Kim et al., 2022) offer some coarse-grain insight into the relationship between these
2

architectures, but separations are not implied by these previous works. Our connection between transformers
and MPC is most similar to that established by Loukas (2019) between GNNs and the Congest model of
distributed computation. Both works establish positive and negative results by identifying neural architectures
with communication protocols. In Section 5.1, we show that the MPC connection allows transformers solve
graph connectivity more efficiently than GNNs.
Our k-hop induction heads task is designed as a k-fold composition of its standard analogue (Elhage
et al., 2021). It is similar to a special case of the LEGO reasoning task Zhang et al. (2023), which reveals
the super-linear benefit of depth with respect to k; in our case, we theoretically and empirically exhibit an
exponential benefit. We also draw a connection to the well-studied problem of pointer-chasing (Papadimitriou
and Sipser, 1982; Duris et al., 1984; Nisan and Wigderson, 1993), which enables the proof of our separation
between parallel and serial architectures. Our fine-grained empirical interpretability analysis for synthetic
tasks draws inspiration from similar approaches for the analysis of sequential algorithms like sorting and
reversal (Li and McClelland, 2022).
2
Preliminaries
2.1
Transformers
We first define a self-attention head, the core primitive of a transformer. The softmax operator is softmax(v) =
(exp(v1), . . . , exp(vN))/ PN
j=1 exp(vj) for v ∈RN. We apply softmax to matrices A ∈RN×N row-wise, i.e.
softmax(A)i = softmax((Ai,1, . . . , Ai,N)).
Definition 2.1 (Self-attention head). A self-attention head is a mapping fQ,K,V : RN×m →RN×m defined
by
fQ,K,V (X) = softmax(Q(X)K(X)T)V (X)
and parameterized by row-wise query, key, and value embeddings Q, K, V : RN×m →RN×m (e.g., Q(X) =
(Q1(X1), . . . , QN(XN)). Let AttnN
m denote the set of all self-attention heads with embedding dimension m
and context length N.
A transformer composes L layers of H self-attention heads per layer, plus an output multi-layer perceptron
(MLP).
Definition 2.2 (Transformer). A transformer is a mapping T : RN×din →RN×dout specified by self-attention
heads (fℓ,h ∈AttnL
m)ℓ∈[L],h∈[H] and an element-wise output MLP ψ = (ψ1, . . . , ψN) : RN×m →RN×dout.
Upon input X ∈RN×din, the transformer computes intermediate embeddings X0, . . . , XL ∈RN×m with
X0 = X and
Xℓ= Xℓ−1 +
XH
h=1fℓ,h(Xℓ−1),
and returns T(X) = ψ(XL) as output. Let TransformerN
m,L,H,din,dout denote the set of all such transformers,
and TransformerN
m,L,H := TransformerN
m,L,H,1,1.
Modeling assumptions.
We treat the transformer as a computational model that permits arbitrary
element-wise computation, but restricts the manner in which multiple elements are processed together.
This manifests in our decisions to model query/key/value embeddings and MLPs as arbitrary functions
on the embedding space; Loukas (2019) employs a similar modeling assumption for GNNs. Note that the
element-wise embeddings and MLPs may be index-specific, obviating the need for positional embeddings.
Our theoretical results cover the scaling regime where the context length N is the main asymptotic
parameter; while the embedding dimension m, the number of heads H, and the depth L grow sub-linearly in
N. This reflects real-world trends in large-language models, where context length has sharply increased in
recent years.
Throughout, we assume all intermediate computations in transformers are represented by p-bit precision
numbers for p = Θ(log N). Limiting the precision is consistent with recent practice of using low-precision
arithmetic with transformers (e.g., Wang et al., 2022; Dettmers et al., 2022). We discuss this precision
assumption in greater detail in Appendix A.1, along with other minor technical assumptions (such as the
inclusion of a “start token” for mathematical convenience).
3

• Input = (Input1, . . . , Inputnin) ∈Znin
2p is distributed across local memories of machines 1 ≤i ≤⌈nin
s ⌉:
MachineIn(1)
i
= {(Inputι, ι) : ι ∈{(s−1)i+1, . . . , min {nin, si}}}.
• For round r = 1, . . . , R:
– Each machine i computes messages (MsgOut(r)
i,j )j=1,2,... to send to machines (Dest(r)
i,j )j=1,2,... as function of
MachineIn(r)
i
:
MachineOut(r)
i
= Localr,i(MachineIn(r)
i
) = {(MsgOut(r)
i,j , Dest(r)
i,j ) ∈Z
dj
2p × [q] : j = 1, 2, . . . };
X
jdj ≤s is ensured.
– All messages are simultaneously transmitted; the messages in local memory of machine i for round r + 1 are:
MachineIn(r+1)
i
= {(Msg, Src) : (Msg, i) ∈MachineOut(r)
Src};
X
(Msg,Src)∈MachineIn(r+1)
i
|Msg| ≤s is ensured.
• Output = f(Input) comes from
MachineIn(R+1)
i
= {(Outputι, Src) : ι ∈{(s −1)i+1, . . . , min {nout, si}}}
for 1 ≤i ≤⌈nout
s ⌉.
Figure 1: Formal execution of an MPC protocol for computing f : Znin
2p →Znout
2p
. (|Msg| is the number of
words in Msg.)
Masked transformers.
We also consider masked self-attention, where only certain inner products influence
the softmax output. Let Λ ∈{−∞, 0}N×N be a masking matrix with at least one zero entry in every row.
Then, a Λ-masked self-attention unit is defined by
f Λ
Q,K,V (X) = softmax(Q(X)K(X)T + Λ)V (X).
Let Λ-AttnN
m and Λ-TransformerN
m,L,H, respectively, denote the sets of all Λ-masked self-attention heads and
all transformers comprised of those heads. We define causally-masked transformers by MaskAttnN
m := Γ-AttnN
m
and MaskTransformerN
m,L,H := Γ-TransformerN
m,L,H, where Γ is the lower-triangular mask with Γi,j = 0 iff
i ≥j.
2.2
Massively Parallel Computation model
We use the definition of MPC from Andoni et al. (2018).
Definition 2.3 (MPC protocol). For any global and local memory constants γ, δ > 0, a (γ, δ)-MPC protocol
for a function f : Znin
2p →Znout
2p
specifies a distributed computing protocol for q = Θ(n1+γ−δ
in
) machines,
each with s = O(nδ
in) words1 of local memory to jointly compute f(Input) for any given Input ∈Znin
2p as
follows. The Input ∈Znin
2p is distributed across the local memories of the first ⌈nin/s⌉machines. Computation
proceeds in rounds. In each round, each machine computes an arbitrary function of its local memory to
prepare at most s words to send to other machines; messages are simultaneously transmitted, and the protocol
ensures that each machine receives at most s words at the end of the round. After the final round, the
Output = f(Input) ∈Znout
2p
is in the local memories of the first ⌈nout/s⌉machines. See Figure 1 for details.
Our negative results in Section 3.2 are conditional on the well-known “one-versus-two cycle” conjecture
(Beame et al., 2017; Roughgarden et al., 2018; Ghaffari et al., 2019).
1We assume the word size is p = Θ(log nin) bits. For convenience, we regard words as elements of Z2p (integers mod 2p).
4

Conjecture 2.4 (see, e.g., Ghaffari et al., 2019). For any γ > 0, δ < 1, and N, if π is an (γ, δ)-MPC
protocol that distinguishes a single cycle on N nodes and a union of two cycles each on N/2 nodes, then π
uses Ω(log N) rounds.
2.3
Graphs as sequential inputs
When providing a graph G = (V, E) as input to transformers or MPC protocols, we serialize G as a sequence
in [|V |]2|E| that encodes each edge as a pair of vertex tokens. The resulting transformer has N = 2|E| and
din = 1, and the resulting MPC protocol has nin = 2|E|.
3
Relating transformers and MPC
We coarsely characterize the computational power of transformers in a certain size regime by establishing a
bidirectional relationship between transformers and MPC. Theorems 3.1 and 3.4 show that any MPC protocol
can be simulated by a transformer, and vice versa. As corollaries (Corollaries 3.3 and 3.5), we obtain tight
upper and lower bounds on the depth of bounded-size transformers for computing connected components in
graphs.
3.1
Simulation of MPC protocols by transformers
The following theorem shows that any MPC protocol π with sublinear local memory can be simulated by
a transformer whose depth L is linear in the number of rounds R of π, and embedding dimension m is
polynomial in the local memory size s = O(N δ) of machines used by π.
Theorem 3.1. For constants 0 < γ < δ < 1 and any deterministic R-round (γ, δ)-MPC protocol π
on nin input words and nout ≤nin output words, there exists a transformer T ∈TransformerN
m,L,H with
N = nin, m = O(n4δ
in log nin), L = R + 1, H = O(log log nin) such that T(Input):nout = π(Input) for all
Input ∈ZN
2p.
The theorem provides a non-trivial construction in the strongly sub-linear local memory regime when
s = O(N 1/4−ϵ) for any ϵ > 0.2 Whether the simulation can be improved to m = O(N 1−ϵ′) for some ϵ′ > 0
whenever s = O(N 1−ϵ) is an interesting question for future work.
Theorem 3.1 proof overview.
At a high level, the proof in Appendix B.2 entails simulating each round
of parallel computation with a single-layer transformer and applying those constructions serially to Input.
The local computation on each machine (represented by MachineOut(r)
i
= Localr,i(MachineIn(r)
i )) is directly
encoded using element-wise query/key/value embeddings.
The crux of the proof involves the simulation of a routing protocol to determine MachineIn(r+1) from
MachineOut(r). We construct a self-attention unit that ensures that an encoding of a sequence of addressed
messages from each machine are properly routed to their destinations.3
For any message size β, message count bound s, and number of tokens N, we say that (Sent, Rcvd) ∈
RN×m × RN×m is a valid (β, s)-routing if, for each i ∈[N], the i-th row of Sent (resp. Rcvd) is the vector
encoding of some Senti ⊂Zβ
2p × [N] (resp. Rcvdi ⊂Zβ
2p × [N]) such that
Rcvdi = {(Msg, Src) : (Msg, i) ∈SentSrc} ,
and each of Rcvdi and Senti has cardinality at most s.4
Lemma 3.2. For any β, s, N ∈N, there exists a transformer routeβ,s ∈TransformerN
m,1,1 with m =
O(s4β log N) satisfying routeβ,s(Sent) = Rcvd for any valid (β, s)-routing (Sent, Rcvd).
2Applying Theorem 3.1 when δ ≥1
4 yields transformers with embedding dimension m ≥N, which trivializes the transformer
architecture and negates any advantages of depth under our MLP universality assumption. This is due to the fact a transformer
with N-dimensional embeddings could aggregate the entire input sequence X ∈RN in a single embedding and use its output
MLP to compute any arbitrary function on that input.
3This routing between machines uses the all-pairs structure of self-attention and may not admit a subquadratic approximation.
4We abuse notation by writing Dest ∈Senti to mean there exists some Msg such that (Msg, Dest) ∈Senti.
5

The proof of Lemma 3.2 appears in Appendix B.1 and combines two key techniques: sparse propagation
and multiple hashing. The former is a simple variant of the “sparse averaging” task of Sanford et al. (2023),
which simultaneously computes N averages over subsets of inputs; this task is solved a single self-attention
head with small embedding dimension (Proposition B.1). Using sparse propagation, we construct a self-
attention head that averages the ≤s encodings of each RcvdSrc for every Src ∈Rcvdi. In order to ensure that
we can decode that average of encodings, we apply error-correction by encoding each Outputi in a sparse and
redundant manner, where each outgoing messages appears as multiple copies of the same addressed “packet.”
Application: connectivity with log-depth transformers.
As an immediate consequence of Theorem 3.1,
any graph problem solvable with a logarithmic number of rounds of MPC computation (and local memory s)
is also computable by a logarithmic depth transformer (and embedding dimension ˜O(s4)). The following
result—which bounds transformer depth needed to compute connected components of a graph G—follows
from Theorem 6.2 of Coy and Czumaj (2022), which derandomizes an MPC algorithm of Behnezhad et al.
(2019), and Theorem 3.1.
Corollary 3.3. For any constant ϵ ∈(0, 1) and any D ≤N, there exists a transformer in TransformerN
m,L,H
with m = O(N ϵ), H = O(log log N), and L = O(log D) that identifies the connected components of any input
graph G = (V, E) with |V |, |E| = O(N) where each connected component has diameter at most D.
Coy and Czumaj also give efficient MPC algorithms for other related problems (e.g., spanning forest), so
we obtain efficient transformers for these problems, too (Appendix B.3).
3.2
Simulation of transformers by MPC protocols
The following theorem shows that MPC protocols can simulate transformers and prove depth lower bounds
on transformers, conditioned on Conjecture 2.4. We get, as a corollary, the conditional optimality of the
transformer depth bound in Corollary 3.3.
Theorem 3.4. For any transformer T ∈TransformerN
m,L,H (or Λ-TransformerN
m,L,H) with mH = O(N δ) for
δ ∈(0, 1) and any δ′ ∈(δ, 1), there exists a O(
L
δ′−δ)-round (1+δ′, δ′)-MPC protocol with q = O(N 2) machines
with s = O(N δ′) local memory for computing T.
Theorem 3.4 demonstrates that the algorithmic capabilities of transformers are no stronger than those of
MPC protocols with a quadratic scaling in the number of machines. While Theorems 3.1 and 3.4 do not
jointly provide a sharp characterization of the two computational models, the reductions are tight enough to
provide strong evidence for the optimality of the connected components construction of Corollary 3.3.
Theorem 3.4 proof overview.
At a high-level, the proof constructs an MPC protocol that simulates
a self-attention layer by separating the computation of MLPs and attention matrices into three separate
categories of machines.
• Each input token is provided to its own token machine, responsible for preparing the query/key/value
embeddings.
• Each pair of tokens is associated with an inner product machine that will compute the inner product
between their respective query and key embeddings.
• Propagation machines ensure that embeddings are routed to the proper inner product machine and compute
outputs of each softmax unit.
The proof gives the communication protocol for these machines, shows how they simulate a layer of self-
attention in O(1/(δ′ −δ)) rounds, and establishes the sufficiency of O(N 2) machines with O(N δ′) local
memory.
Application: conditional optimality of Corollary 3.3.
Assuming the well-established Conjecture 2.4,
we prove an Ω(log D) lower bound on the depth of parameter-efficient transformers for determining connectivity
of graphs where connected components may have diameter up to D.
Corollary 3.5. Let ϵ ∈(0, 1) be any constant, and let D ≥N ϵ. Assume Conjecture 2.4, and suppose there
exists T ∈TransformerN
m,L,H with mH = O(D1−ϵ) that decides connectivity of any input graph with connected
components having diameter ≤D. Then L = Ω(log D).
6

4
Transformers for k-hop induction heads
We complement the generality of Section 3 by studying, both empirically and theoretically, a specific toy
sequential modeling task which will also serve (in Section 5) as a problem to separate the representational
capabilities of transformers from that of other neural architectures.
This task, called the k-hop induction heads task, draws inspiration from the original induction heads task
defined and analyzed on trained language models and in synthetic environments by Elhage et al. (2021) (see
also Bietti et al., 2023). The standard induction heads task completes bigrams auto-regressively by predicting
the token that follows the last previous occurrence of the final token in the sequence. For example, given the
input X = baebcabebdea, the standard induction heads task is to complete the final bigram by predicting b
for the final token.
The k-hop induction heads tasks generalizes this mechanism by repeatedly using the completion of a
bigram to determine the next bigram to complete. In the previous example, the 2-hop induction heads task
is to predict c for the final token:
baebcabebdea.
Definition 4.1. For any finite alphabet Σ, define the map hopk : ΣN →(Σ ∪{⊥})N by hopk(X)i = Xfindk
X(i)
if findk
X(i) ̸= 0 and ⊥otherwise, where
find1
X(i) = max({0} ∪{j ∈N : j ≤i, Xj−1 = Xi});
findk
X(i) = find1
X(findk−1
X
(i))
for k ≥2.
The k-hop induction heads task is to compute, for each i = 1, . . . , N, the value of hopk(X)i from (X1, . . . , Xi).
We note a similarity to the LEGO tasks of Zhang et al. (2023), who empirically study the ability of
transformers to learn sequential operations on Abelian groups and observe the ability to perform more
operations than the depth of the network.
4.1
Log-depth transformer for k-hop induction heads
Although hopk appears to requires k steps to solve, we show that it is solved by a transformer of depth
O(log k).
Theorem 4.2. For any k ∈N and alphabet Σ with |Σ| ≤N, there exists T ∈MaskTransformerN
m,L,H that
computes hopk : ΣN →(Σ ∪{⊥})N with m = O(1), L = ⌊log2 k⌋+ 2, and H = 1.
In contrast to Corollary 3.3, this construction has constant embedding dimension and is achieved by a
causally-masked transformer. As such, its proof in Appendix D.1 depends on other techniques that exploit
the simplicity of the problem and build on the induction heads construction of Bietti et al. (2023), rather
than simply applying Theorem 3.1.
We give evidence for the optimality of this construction by proving a conditional lower bound using
Theorem 3.4, as was done in Corollary 3.5.
Corollary 4.3. Assuming Conjecture 2.4, for any constants ξ ∈(0, 1/2] and ϵ ∈(0, 1), and any even
k = Θ(N ξ), every transformer T ∈MaskTransformerN
m,L,H with mH = O(k1−ϵ) that computes hopk has depth
L = Ω(log k).
4.2
Log-depth transformer learned from data
We empirically assess whether the representational trade-offs elucidated by tasks efficiently solved by
parallelizable algorithms have implications for optimization and generalization properties of transformers. To
that end, we trained auto-regressive transformer architectures of varying sizes to solve hopk(X) for a variety
of values of k in order to understand how changing depth impacted the performance of the learned models,
the goal being to verify the sufficiency of logarithmic depth, just as in our theory.
7

1
2
4
8
16
k
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Error
L-layer transformer token-wise classification error on hopk
L = 2
L = 3
L = 4
L = 5
L = 6
Figure 2: Evaluation of transformers of depths L ∈{2, 3, 4, 5, 6} trained on a mixture of hopk for k ∈
{0, . . . , 16} evaluated on n = 100 samples of size N = 100 from each hopk. Incrementing depth approximately
doubles the largest k such that hopk is learnable with small error.
In brief, we trained transformers with 500K to 5M parameters and depths {2, 3, 4, 5, 6} with Adam
to solve hopk(X) for k ∈{0, . . . , 16} with context length |N| = 100 and alphabet size |Σ| = 4.
We
trained the transformers in a multi-task setting, where a single model was trained to predict the sequence
hopk(X) auto-regressively when provided with X and k drawn at random. Further experimental details
can be found in Appendix G.1, and the experimental code is available at https://github.com/chsanford/
hop-induction-heads.
We found that transformers are indeed capable of learning hopk given sufficient training time, and that the
largest learnable k grows exponentially with the depth. As can be seen in Figure 2, a six-layer neural network
performs well on all k ≤16, a five-layer on k ≤8, a four-layer on k ≤4, and so forth. We further explore
these experimental results in Appendix G.2 and observe a performance threshold appears to specifically lie at
⌊log2 k⌋+ 2 that coincides with Theorem 4.2. This logarithmic dependence of the depth on k persists in a
larger-width regime, which is explored in Appendix G.3. In the finite sample regime where neural networks
are prone to overfit, our investigations in Appendix G.5 note improved generalization in deeper models, which
suggests that deeper models have a favorable inductive bias for tasks like hopk.
Moreover, the learned models are surprisingly interpretable. We examined the activation patterns of
attention matrices, and found close correspondences to useful intermediate products such as findj
X. Taken
together, these indicate that the learned models mechanistically resemble the construction employed in the
proof of Theorem 4.2. See Appendix G.4 for our investigation of model interpretability.
5
Separations between transformers and alternative architectures
Sections 3 and 4 characterize the representational capability of transformers by providing algorithmic problems
they can solve with logarithmic depth and small polynomial or constant width. In contrast, other well-known
architectures are unable to solve those same problems in a parameter-efficient manner. This section provides
lower bounds on the parameter complexity of graph neural networks (GNNs), recurrent neural architectures,
transformers with computationally efficient alternatives to softmax self-attention, and single-layer transformers
with autoregressive chain-of-thought tokens needed to solve graph connectivity and the k-hop task.
8

5.1
GNNs need polynomial depth for graph connectivity
The bidirectional relationship between transformers and MPC draws inspiration from past work drawing a
similar connection between message passing graph neural networks (GNNmp) and the Congest distributed
computing model Loukas (2019). Their computation model of GNNmp for width m and depth L closely
resembles our TransformerN
m,L,H in providing a general framework for the analysis of graph neural networks
by allowing unbounded computation in each vertex with bounded communication on edges. On some input
graph G, vertices send neighbors messages of size at most m—which are aggregated and crafted into new
messages with MLPs—over L rounds of communication.
By restating Corollary 4.2 of Loukas (2019), we demonstrate a sharp contrast in the abilities of GNNs
and transformers to solve graph algorithmic tasks.
Theorem 5.1 (Corollary 4.2 of Loukas (2019)). There exists a graph G with N edges such that any GNNmp
with width m and depth L that determines whether an input subgraph H either (1) is connected or (2) forms
a spanning tree of G requires L√m = ˜Ω(N 1/4).
While Corollaries 3.3 and B.8 demonstrate the ability of transformers to determine whether any input
graph is connected5 or to identify a spanning tree with logarithmic depth and small polynomial width (i.e.
m = O(N ϵ)), GNNs require depth L = ˜Ω(N 1/4−ϵ/2) in the same regime. This gap is explainable by the fact
that transformers on graph inputs G are not bound to pass messages exclusively along the edges of G. By
“rewiring” the graphical structure in each layer, transformers can perform aggregation and “pointer passing”
tasks with greater parametric ease than GNNs.
5.2
Suboptimality of recurrent architectures for hopk
The logarithmic-depth and constant-width transformer implementation of hopk in Theorem 4.2 cannot be
replicated by recurrent neural architectures (Chung et al., 2014; Bengio et al., 1994; Turkoglu et al., 2021),
including not just multi-layer recurrent neural networks (RNNs) but any sequential prediction procedure
equivalent to them at inference time, which includes state space models such as Mamba (Gu and Dao, 2023).
We first consider a family of multi-layer RNNs of depth L and width m, consisting of arbitrary MLP units
gℓ: Rm×m →Rm×m, which on input X ∈RN×din produce output Y ∈RN×dout as follows using intermediates
X = Z0, Z1, . . . , ZL−1, ZL = Y ∈RN×m6and hidden states H1, . . . , HL ∈{0, 1}N×m with Hℓ
0 = ⃗0:
(Zℓ
i , Hℓ
i ) = gℓ(Zℓ−1
i
, Hℓ
i−1), ∀i ∈[N], ℓ∈[L].
We provide a polynomial bound on the width and depth of a multi-layer RNN solving hopk.
Corollary 5.2. A multi-layer RNN of depth L and width m as above with YN = hopk(X)N satisfies either
L ≥k or m = Ω( N
k6 ).
In contrast to Theorem 4.2, which demonstrates that depth O(log k) transformers with constant width
suffice to solve hopk for any k, Corollary 5.2 demonstrates that all multi-layer RNNs with width O(N 1/7)
require depth k when k = O(N 1/7).
Mamba (Gu and Dao, 2023) can be seen as the combination of three ideas: (1) a continuous-time
dynamics model of sequential prediction, powerful enough to model Kalman filters, hidden markov models,
and many others; (2) a family of time-discretization schemes; (3) an unrolling technique to enable efficient
linear-time training, using ideas similar to FlashAttention (Dao et al., 2022). Ultimately, at inference time,
the time-discretization step results in an RNN (see Gu and Dao, 2023, Algorithm 2 and Theorem 1), and is
therefore directly handled by Corollary 5.2.
This corollary is a near immediate application of a communication complexity fact about the hardness
of solving multi-player pointer-chasing problems with limited communication among players (Guha and
McGregor, 2009; Assadi and N, 2021). We provide the communication model and this result in Appendix E.1,
and the reductions necessary to prove the above hardness results in Appendix E.2.
5While the problem of subgraph connectivity for GNNs may at first glance appear more difficult than general graph connectivity
for transformers, an implementation of this exact task can be implemented by modifying the protocol Corollary 3.3 to remove all
edges from the graph that do not belong to H.
6We assume that din, dout ≤m and treat X and Y as if they are padded with zeros.
9

5.3
Suboptimality of sub-quadratic attention transformers for hopk
Due to the quadratic computational cost of computing the attention matrix softmax(Q(X)K(X)T ) ∈RN×N
and the continued desire for ever-larger context lengths, there is substantial interest in improving the
computational complexity of the transformer architecture while preserving its expressive capabilities and
inductive biases. As a result, a rich literature has emerged that proposes computationally-efficient alternatives
to standard softmax attention. In this section, we demonstrate how several representative examples of
sub-quadratic attention mechanisms lose the ability to perform efficient parallel computation under a
logarithmic-depth scaling.
Kernel-based sub-quadratic attention.
One approach to computationally-efficient approximation of
transformers are kernel-based sub-quadratic attention mechanisms such as Performer (Choromanski et al., 2022),
and Poly-Sketchformer (Kacham et al., 2023). Both approximate the attention matrix softmax(Q(X)K(X)T)
with a low-rank matrix Q′(X)K′(X)T where Q′, K′ : Rm →Rm′ are applied element-wise. For sufficiently
small m′ ≪N, Q′(X)K′(X)TV (X) can be computed efficiently by first computing K′(X)TV (X) ∈Rm′×m,
bounding the total runtime as O(Nmm′), rather than O(N 2m).
Let KernelFormerN
m,m′,L,H denote all H-headed L-layer transformer whose softmax attention modules are
replaced by kernel-based sub-quadratic attention. We demonstrate the limitations of KernelFormerN
m,m′,L,H
by showing that, unlike TransformerN
m,L,H, they have no depth-efficient implementation of hopk.
Corollary 5.3. Any T ∈KernelFormerN
m,m′,L,H with T(X)N = hopk(X)N satisfies either L ≥k or mm′Hp =
Ω( N
k6 ).
Under a parameter-efficient regime where mpHL = O(N ϵ), solving hopk for k = Θ(N ϵ) necessitates
kernel feature dimension m′ = Ω(N 1−9ϵ), which forces each attention unit to compute an N × N 1−9ϵ matrix,
yielding a nearly quadratic runtime. We prove Corollary 5.3 in Appendix E.3 using a similar pointer chasing
reduction.
Masking-based sub-quadratic attention.
Another method that reduces the computational cost of
transformers is to used masked models of Λ-TransformerN
m,L,H for a sparse mask Λ.
The Longformer
architecture (Beltagy et al., 2020) introduces a particular masked architecture that combines sliding windows
with sparse unmasked global tokens. Put concretely, for window radius w and global frequency g, let
Λw,g ∈{−∞, 0}N×N be masking matrix with
Λw,g
i,j =
(
0
if |i −j| ≤w or j ≡0
(mod g),
−∞
otherwise.
Then, the output of a single unit of Λw,g-masked attention is computable in time O((w + N
g )Nm).
Corollary 5.4. Any T ∈Λw,g-AttnN
m,L,H with T(X)N = hopk(X)N satisfies either L ≥k or (w+ N
gk)mHp =
Ω( N
k6 ).
Like kernel-based attention, sparsely-masked attention models fail to efficiently compute hopk. Similarly,
in the same parameter-efficient regime, a Longformer must have either w = Ω(N 1−9ϵ) or g = O(N 9ϵ), which
jointly ensures that the masked matrix has at least Ω(N 2−9ϵ) entries and diminishes any computational
advantages. This proof also appears in Appendix E.3.
5.4
Limitations of 1-layer transformers with chain-of-thought
While most of the paper considers transformers as sequence-to-sequence models, we can also frame them as
auto-regressive models performing next-token-prediction with chain-of-thought prompting. In this regime, a
single causally-masked transformer aims to compute a function of its input by repeatedly predicting the next
token, appending previously predicted tokens to the end of the input. In doing so, a function is computable if
there exists an intermediate chain-of-thought produced by the model that eventually reaches the answer.
10

Definition 5.5. We say that T ∈MaskTransformerN+NCoT
m,L,H
computes f : ΣN+NCoT →ΣN, where the
additional N tokens denote chain-of-thought, if for every X ∈dom(f), there exists XCoT ∈ΣNCoT such that
T(X ◦XCoT)N:N+NCoT = (XCoT ◦f(X)).
The theoretical capabilities of chain-of-thought augmented transformers to simulate finite-state automata
and Turing machines have been studied (Malach, 2023; Merrill and Sabharwal, 2023b), but the comparative
capabilities of shallow models with chain-of-thought prompting and deep sequential models are unknown. In
contrast to the fact that any transformer with NCoT tokens can be simulated by a sequential model with
depth scaled by NCoT, we show that deep transformers cannot necessarily be efficiently simulated by shallow
chain-of-thought models. We do so by demonstrating that a linear amount of chain-of-thought prompting in
k is necessary to solve hopk(X)N, and also sufficient.
Corollary 5.6. Any T ∈MaskTransformerN+NCoT
m,1,H
that computes hopk(X)N with NCoT tokens of chain-of-
thought requires either NCoT ≥k or mHp = Ω( N
k6 ).
The proof appears in Appendix E.4. For future work, it remains to consider the comparative powers of
chain-of-thought models of depths greater than one.
6
Conclusion and future work
This work highlights parallelism as a central feature of transformers that sets them apart from other neural
architectures. The focus on the log-depth and sublinear-width regime and specific computational tasks allows
us to accentuate the benefits of parallelism, even for tasks like k-hop that appear inherently serial at first
glance.
There is some efficiency loss in the “compilation” of MPC protocols to transformers that we hope to
understand better in future work. Furthermore, although we have empirically demonstrated the learnability
of transformers that exploit parallelism in crucial ways, a theoretical understanding of learning such solutions
remains an open question.
References
Alekh Agarwal, Olivier Chapelle, Miroslav Dudík, and John Langford. A reliable effective terascale linear
learning system. Journal of Machine Learning Research, 15(1):1111–1133, 2014.
Alexandr Andoni, Aleksandar Nikolov, Krzysztof Onak, and Grigory Yaroslavtsev. Parallel algorithms
for geometric graph problems. In Proceedings of the forty-sixth annual ACM symposium on Theory of
computing, pages 574–583, 2014.
Alexandr Andoni, Zhao Song, Clifford Stein, Zhengyu Wang, and Peilin Zhong. Parallel graph connectivity in
log diameter rounds. In 2018 IEEE 59th Annual Symposium on Foundations of Computer Science (FOCS).
IEEE, October 2018. doi: 10.1109/focs.2018.00070. URL http://dx.doi.org/10.1109/FOCS.2018.00070.
Dana Angluin, David Chiang, and Andy Yang. Masked hard-attention transformers and boolean rasp
recognize exactly the star-free languages, 2023.
Sepehr Assadi and Vishvajeet N. Graph streaming lower bounds for parameter estimation and property
testing via a streaming xor lemma.
In Proceedings of the 53rd Annual ACM SIGACT Symposium
on Theory of Computing, STOC ’21. ACM, June 2021.
doi: 10.1145/3406325.3451110.
URL http:
//dx.doi.org/10.1145/3406325.3451110.
Paul Beame, Paraschos Koutris, and Dan Suciu. Communication steps for parallel query processing. Journal
of the ACM (JACM), 64(6):1–58, 2017.
Soheil Behnezhad, Sebastian Brandt, Mahsa Derakhshan, Manuela Fischer, MohammadTaghi Hajiaghayi,
Richard M Karp, and Jara Uitto. Massively parallel computation of matching and mis in sparse graphs. In
Proceedings of the 2019 ACM Symposium on Principles of Distributed Computing, pages 481–490, 2019.
11

Iz Beltagy, Matthew E. Peters, and Arman Cohan. Longformer: The long-document transformer, 2020.
Y. Bengio, P. Simard, and P. Frasconi. Learning long-term dependencies with gradient descent is difficult.
IEEE Transactions on Neural Networks, 5(2):157–166, 1994. doi: 10.1109/72.279181.
Satwik Bhattamishra, Kabir Ahuja, and Navin Goyal. On the ability and limitations of transformers to
recognize formal languages. In Proceedings of the 2020 Conference on Empirical Methods in Natural
Language Processing, 2020.
Alberto Bietti, Vivien Cabannes, Diane Bouchacourt, Herve Jegou, and Leon Bottou. Birth of a transformer:
A memory viewpoint, 2023.
Moses Charikar, Weiyun Ma, and Li-Yang Tan. New lower bounds for massively parallel computation from
query complexity, 2020.
Krzysztof Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Andreea Gane, Tamas Sarlos,
Peter Hawkins, Jared Davis, Afroz Mohiuddin, Lukasz Kaiser, David Belanger, Lucy Colwell, and Adrian
Weller. Rethinking attention with performers, 2022.
Junyoung Chung, Caglar Gulcehre, KyungHyun Cho, and Yoshua Bengio. Empirical evaluation of gated
recurrent neural networks on sequence modeling. arXiv preprint arXiv:1412.3555, 2014.
Kevin Clark, Urvashi Khandelwal, Omer Levy, and Christopher D Manning. What does bert look at? an
analysis of bert’s attention. arXiv preprint arXiv:1906.04341, 2019.
Sam Coy and Artur Czumaj. Deterministic massively parallel connectivity. In Proceedings of the 54th Annual
ACM SIGACT Symposium on Theory of Computing, STOC 2022, page 162–175, New York, NY, USA,
2022. Association for Computing Machinery. ISBN 9781450392648. doi: 10.1145/3519935.3520055. URL
https://doi.org/10.1145/3519935.3520055.
Amit Daniely. Depth separation for neural networks. In Satyen Kale and Ohad Shamir, editors, Proceedings
of the 2017 Conference on Learning Theory, volume 65 of Proceedings of Machine Learning Research, pages
690–696. PMLR, 07–10 Jul 2017. URL https://proceedings.mlr.press/v65/daniely17a.html.
Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra, and Christopher Ré. Flashattention: Fast and memory-
efficient exact attention with io-awareness. In NeurIPS, 2022.
Jeffrey Dean and Sanjay Ghemawat. Mapreduce: Simplified data processing on large clusters. In OSDI,
pages 137–150, 2004.
Tim Dettmers, Mike Lewis, Younes Belkada, and Luke Zettlemoyer. Llm.int8(): 8-bit matrix multiplication
for transformers at scale. In Advances in Neural Information Processing Systems, volume 35, 2022.
Pavol Duris, Zvi Galil, and Georg Schnitger. Lower bounds on communication complexity. In Proceedings of
the Sixteenth Annual ACM Symposium on Theory of Computing, page 81–91, 1984.
Ronen Eldan and Ohad Shamir. The power of depth for feedforward neural networks. In Vitaly Feldman,
Alexander Rakhlin, and Ohad Shamir, editors, 29th Annual Conference on Learning Theory, volume 49 of
Proceedings of Machine Learning Research, pages 907–940, Columbia University, New York, New York,
USA, 23–26 Jun 2016. PMLR. URL https://proceedings.mlr.press/v49/eldan16.html.
Nelson Elhage, Neel Nanda, Catherine Olsson, Tom Henighan, Nicholas Joseph, Ben Mann, Amanda Askell,
Yuntao Bai, Anna Chen, Tom Conerly, Nova DasSarma, Dawn Drain, Deep Ganguli, Zac Hatfield-Dodds,
Danny Hernandez, Andy Jones, Jackson Kernion, Liane Lovitt, Kamal Ndousse, Dario Amodei, Tom Brown,
Jack Clark, Jared Kaplan, Sam McCandlish, and Chris Olah. A mathematical framework for transformer
circuits. Transformer Circuits Thread, 2021. https://transformer-circuits.pub/2021/framework/index.html.
12

Mohsen Ghaffari, Fabian Kuhn, and Jara Uitto. Conditional hardness results for massively parallel computation
from distributed lower bounds. In IEEE 60th Annual Symposium on Foundations of Computer Science,
pages 1650–1663, 11 2019. doi: 10.1109/FOCS.2019.00097.
Michael T Goodrich, Nodari Sitchinava, and Qin Zhang. Sorting, searching, and simulation in the mapreduce
framework. In International Symposium on Algorithms and Computation, pages 374–383. Springer, 2011.
Albert Gu and Tri Dao. Mamba: Linear-time sequence modeling with selective state spaces, 2023.
Sudipto Guha and Andrew McGregor. Stream order and order statistics: Quantile estimation in random-
order streams. SIAM Journal on Computing, 38(5):2044–2059, 2009. doi: 10.1137/07069328X. URL
https://doi.org/10.1137/07069328X.
Michael Hahn. Theoretical limitations of self-attention in neural sequence models. Trans. Assoc. Comput.
Linguistics, 8:156–171, 2020. doi: 10.1162/tacl\_{a}{\_{0}{0}{3}}{0}6. URL https://doi.org/10.
1162/tacl_a_00306.
Yiding Hao, Dana Angluin, and Robert Frank. Formal language recognition by hard attention transformers:
Perspectives from circuit complexity. Trans. Assoc. Comput. Linguistics, 10:800–810, 2022. URL https:
//transacl.org/ojs/index.php/tacl/article/view/3765.
Sungjin Im, Ravi Kumar, Silvio Lattanzi, Benjamin Moseley, Sergei Vassilvitskii, et al. Massively parallel
computation: Algorithms and applications. Foundations and Trends® in Optimization, 5(4):340–417, 2023.
John Jumper, Richard Evans, Alexander Pritzel, Tim Green, Michael Figurnov, Olaf Ronneberger, Kathryn
Tunyasuvunakool, Russ Bates, Augustin Žídek, Anna Potapenko, et al. Highly accurate protein structure
prediction with alphafold. Nature, 596(7873):583–589, 2021.
Praneeth Kacham, Vahab Mirrokni, and Peilin Zhong. Polysketchformer: Fast transformers via sketches for
polynomial kernels, 2023.
Howard Karloff, Siddharth Suri, and Sergei Vassilvitskii. A model of computation for mapreduce. In
Twenty-first Annual ACM-SIAM Symposium on Discrete Algorithms, pages 938–948, 12 2010. doi: 10.1137/
1.9781611973075.76.
Jinwoo Kim, Tien Dat Nguyen, Seonwoo Min, Sungjun Cho, Moontae Lee, Honglak Lee, and Seunghoon
Hong. Pure transformers are powerful graph learners, 2022.
Diederik P. Kingma and Jimmy Ba. Adam: A method for stochastic optimization, 2014.
Yuxuan Li and James L. McClelland. Systematic generalization and emergent structures in transformers
trained on structured tasks, 2022.
Valerii Likhosherstov, Krzysztof Choromanski, and Adrian Weller. On the expressive power of self-attention
matrices. arXiv preprint arXiv:2106.03764, 2021.
Bingbin Liu, Jordan T. Ash, Surbhi Goel, Akshay Krishnamurthy, and Cyril Zhang. Transformers learn
shortcuts to automata, 2022.
Andreas Loukas. What graph neural networks cannot learn: depth vs width. arXiv preprint arXiv:1907.03199,
2019.
Eran Malach. Auto-regressive next-token predictors are universal learners, 2023.
William Merrill and Ashish Sabharwal. A logic for expressing log-precision transformers, 2022.
William Merrill and Ashish Sabharwal. The parallelism tradeoff: Limitations of log-precision transformers.
Transactions of the Association for Computational Linguistics, 11:531–545, 2023a. ISSN 2307-387X. doi:
10.1162/tacl_a_00562. URL http://dx.doi.org/10.1162/tacl_a_00562.
13

William Merrill and Ashish Sabharwal. The expressive power of transformers with chain of thought, 2023b.
William Merrill, Ashish Sabharwal, and Noah A. Smith. Saturated transformers are constant-depth threshold
circuits. Transactions of the Association for Computational Linguistics, 10:843–856, 2022. ISSN 2307-387X.
doi: 10.1162/tacl_a_00493. URL http://dx.doi.org/10.1162/tacl_a_00493.
MPICH. Mpi allreduce, 2023. URL https://www.mpich.org/static/docs/latest/www3/MPI_Allreduce.
html.
Noam Nisan and Avi Wigderson. Rounds in communication complexity revisited. SIAM Journal on Computing,
22(1):211–219, 1993. doi: 10.1137/0222016. URL https://doi.org/10.1137/0222016.
Matanel Oren, Michael Hassid, Yossi Adi, and Roy Schwartz. Transformers are multi-state rnns, 2024.
Christos H. Papadimitriou and Michael Sipser. Communication complexity. In Proceedings of the Fourteenth
Annual ACM Symposium on Theory of Computing, page 196–200, 1982.
Jorge Pérez, Pablo Barceló, and Javier Marinkovic. Attention is turing complete. Journal of Machine
Learning Research, 22(1):3463–3497, 2021.
Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. Language models
are unsupervised multitask learners. OpenAI blog, 1(8):9, 2019.
Anna Rogers, Olga Kovaleva, and Anna Rumshisky. A primer in bertology: What we know about how bert
works. Transactions of the Association for Computational Linguistics, 8:842–866, 2021.
Tim Roughgarden, Sergei Vassilvitskii, and Joshua Wang. Shuffles and circuits (on lower bounds for modern
parallel computation). Journal of the ACM, 65:1–24, 11 2018. doi: 10.1145/3232536.
Clayton Sanford, Daniel Hsu, and Matus Telgarsky. Representational strengths and limitations of transformers,
2023.
Lena Strobl. Average-hard attention transformers are constant-depth uniform threshold circuits, 2023.
Lena Strobl, William Merrill, Gail Weiss, David Chiang, and Dana Angluin. Transformers as recognizers of
formal languages: A survey on expressivity, 2023.
Matus Telgarsky. Benefits of depth in neural networks. In Vitaly Feldman, Alexander Rakhlin, and Ohad
Shamir, editors, 29th Annual Conference on Learning Theory, volume 49 of Proceedings of Machine Learning
Research, pages 1517–1539, Columbia University, New York, New York, USA, 23–26 Jun 2016. PMLR.
URL https://proceedings.mlr.press/v49/telgarsky16.html.
Mehmet Ozgur Turkoglu, Stefano D’Aronco, Jan Dirk Wegner, and Konrad Schindler. Gating revisited: Deep
multi-layer rnns that can be trained. IEEE Transactions on Pattern Analysis and Machine Intelligence, 44
(8):4081–4092, 2021.
Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser,
and Illia Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems 30,
2017.
Ziwei Wang, Changyuan Wang, Xiuwei Xu, Jie Zhou, and Jiwen Lu. Quantformer: Learning extremely
low-precision vision transformers. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2022.
Colin Wei, Yining Chen, and Tengyu Ma. Statistically meaningful approximation: a case study on approxi-
mating turing machines with transformers, 2021.
14

Shunyu Yao, Binghui Peng, Christos H. Papadimitriou, and Karthik Narasimhan. Self-attention networks can
process bounded hierarchical languages. In Proceedings of the 59th Annual Meeting of the Association for
Computational Linguistics and the 11th International Joint Conference on Natural Language Processing,
2021.
Chulhee Yun, Srinadh Bhojanapalli, Ankit Singh Rawat, Sashank Reddi, and Sanjiv Kumar. Are transformers
universal approximators of sequence-to-sequence functions?
In International Conference on Learning
Representations, 2020.
Yi Zhang, Arturs Backurs, Sébastien Bubeck, Ronen Eldan, Suriya Gunasekar, and Tal Wagner. Unveiling
transformers with lego: a synthetic reasoning task, 2023.
15

A
Supplemental Preliminaries
A.1
Further details about transformers
We discuss a few minor technicalities and modifications of the self-attention unit (Definition 2.1) and
transformer model (Definition 2.2) defined in Section 2.1 that are necessary for readers looking for a
comprehensive understanding of the proofs of our theoretical results.
Fixed-bit precision arithmetic.
As discussed in Section 2.1, we assume that all numbers that appear in
the intermediate products and outputs of self-attentions are representable with p-bit precision arithmetic,
where p = Θ(log N). While the details of fixed-precision arithmetic will be uninteresting to most readers, it
is necessary to explain precisely what we mean in order to ensure that proofs of results like Theorem 3.4 are
sound. Throughout the paper, we allow p to depend on of constants, such as γ, δ, and ϵ.
Concretely, we assume that all query, key, and value embeddings Q(X), K(X), V (X) evaluated on all
inputs contain scalar values z ∈R that are polynomially bounded (i.e. |z| ≤exp(O(p)) = N ζ for sufficiently
large constant exponent ζ > 0) and are inverse-polynomially discretized (i.e. z · N ζ ∈Z). Depending on the
desired exponent ζ, some p = Θ(log N) can be chosen to guarantee this property. While we do not formally
analyze the precision needed to approximate the particular embeddings employed by our proofs, we note
that our recurring sinusoidal embeddings (e.g. Lemma D.1) can be discretized without losing their central
properties and that discretizations of the restricted isometry embeddings of Proposition B.1 are analyzed by
Sanford et al. (2023).
Rather than stipulating a particular bounded-precision implementation that computes the output of a self-
attention unit must be implemented, we specify a rounding constraint that any computational implementation
of a self-attention unit must satisfy. Precisely, we require that any output round to the same inverse-polynomial
discretization as the true mathematical attention.
Definition A.1. For a self-attention unit f ∈AttnN
m, let ˆf be an finite-precision implementation of that unit.
We say that ˆf is a valid implementation if
sup
X∈RN×m



f(X) −ˆf(X)



∞= O
 1
2p

.
This definition is only to establishing the fact that self-attention units with sufficient margins can precisely
compute hardmax outputs in Lemma A.2 and to showing that MPC models can indeed compute the outputs
precisely in Theorem 3.4.
Hardmax attention.
While we exclusively consider attention units with the softmax, our constructions
periodically rely on the exact computation of averages of embeddings. We define the hardmax operator to
allow the consideration of discrete averaging operations. For some v ∈RN, let
hardmax(X)i =
(
1
|Imax(v)|,
if i ∈Imax(v)
0
otherwise,
where Imax(v) = {i ∈[N] : vi = maxi′ vi′}.
We show that bounded-precision softmax self-attention units that satisfy a margin property can be
modified slightly to have identical outputs to an analogous hardmax unit.
Lemma A.2. Let f ∈AttnN
m be a self-attention unit with precision p = Θ(log N) and embedding functions
Q, K, V such that for some fixed 1 ≥ξ = N −O(1) and every X ∈RN×m and i ∈[N]:
A(X)i,i′ ≤max
i′′ A(X)i,i′′ −ξ, ∀i′ ̸∈Imax(A(X)i),
where A(X) = Q(X)K(X)T. Then there exists a self-attention unit f ′ ∈AttnN
m with a valid p′-bit implemen-
tation with p′ = O(p) satisfying
f ′(X) = hardmax(A(X))V (X).
The proof of Lemma A.2 is provided in Appendix F.
16

Start tokens.
Our technical proofs are occasionally simplified by including a “dummy token” whose value
is passed in self-attention layers as a default or null value. For example, in the proof of Lemma D.2, the
dummy token handles the case where the reference token does not appear previously in the sequence. While
we believe that this extra token is not necessary for our technical arguments, we include it for the sake of
simplicity.
We model this dummy token as a start-of-sequence token X0. Concretely, if we employ X0 in a self-
attention f ∈AttnN
m which takes as input X, we instead treat f as an attention unit in AttnN+1
m
that operates
on (X0, X1, . . . , XN). We assume that X0 is constant-valued, and therefore never both to pay attention to its
outputs; it’s only relevance is via its key and value embeddings K0(X0), V0(X0) ∈Rm. If X0 is unmentioned,
we assume that it does not exist, or is set such that its key embedding inner products are all zero.
Supplemental chain-of-thought tokens.
We periodically (see Theorem B.3 and the proofs of Corollar-
ies 3.5 and 4.3) consider transformers with supplemental blank “chain-of-thought” tokens appended to the
end of the sequence. Unlike the start token, these are only constant at initialization and may be used deeper
in the model to perform meaningful computations.
Let TransformerN,M
m,L,H,din,dout denote transformers with M −N extra blank elements appended to the input
sequence. Concretely, we represent T ∈TransformerN,M
m,L,H,din,dout as some T ′ ∈TransformerM
m,L,H,din,dout and
define the output T(X) for X ∈RN×din by letting Y ∈RM×din for Y1:N = X and YN+1:M = ⃗0, and letting
T(X) = T ′(Y ).
B
Proofs from Section 3.1
B.1
Proof of Lemma 3.2
Lemma 3.2. For any β, s, N ∈N, there exists a transformer routeβ,s ∈TransformerN
m,1,1 with m =
O(s4β log N) satisfying routeβ,s(Sent) = Rcvd for any valid (β, s)-routing (Sent, Rcvd).
The proof relies on a sparse propagation sequential primitive, which complements the sparse averaging
primitive of Sanford et al. (2023). For any Q ≤d, N, on input X = (X1, . . . , XN) ∈RN×d with Xi =
(zi, Si) ∈Rd−Q × [N]Q and bi = |{Sj ∋i : j ∈[N]}| ≤Q, we define
sparsePropagateQ,d(X)i =
(
1
bi
P
Sj∋i zj
if bi > 0,
0
otherwise.
Closely following the argument of Sanford et al. (2023), we show in Proposition B.1 that there is a self-
attention unit with embedding dimension m = max(d, O(q log N)) that computes sparsePropagateQ,d. This
construction is a key component of the single-layer transformer used in the proof of Lemma 3.2.
Proposition B.1. For any b ≤N and d, there exists a self-attention unit sparsePropagateQ,d ∈AttnN
m,p for
m = d+O(Q log N) and p = O(log N), which, given any input X with Xi = (zi, Si,⃗0) ∈Rd×
[N]
≤Q

×{0}m−Q−d
such that bi = |{Sj ∋i : j ∈[N]}| ≤Q for all i, has output sparsePropagateQ,d(X) satisfying
sparsePropagateQ,d(X)i = 1
bi
X
Sj∋i
zj.
The proof of Proposition B.1 appears in Appendix F.
Proof of Lemma 3.2. We construct a single-layer single-headed transformer with query, key, and value
embeddings Q, K, V and output MLP ψ. Q, K, V can be decomposed as Q = Q′ ◦ϕ, K = K′ ◦ϕ, V = V ′ ◦ϕ,
for some input MLP ϕ and embeddings Q′, K′, V ′. We fix Q′, K′, V ′ to be the respective embeddings of the self-
attention unit with embedding dimension m from Proposition B.1 that computes Y = sparsePropagates,m(X)
for XSrc = (zSrc, SSrc) for every Src ∈[N] to be determined. Hence, the proof entails designing element-
wise encoders ϕ = (ϕ1, . . . , ϕN) and decoders ψ = (ψ1, . . . , ψN) that compute Rcvd from Sent, using
17

sparsePropagate
2Y2 = 2 · sparsePropagate((z, S))2
2¯α
2Src
2Dest
Y1 = (0, 2)
ϕ
g
Dest
g
Msg
g
Src
˜α
z1
1
0
1
0
1
0
1
0
0
2
2
1
1
1
1
hey
yo
hey
yo
S1 = (0, 2)
S3 = (2, 4)
ϕ
Dest
Msg
yes
no
2
4
Sent3
g
Dest
g
Msg
g
Src
˜α
z3
0
1
0
1
1
0
3
3
3
3
2
2
4
4
yes
yes
no
no
Dest
Msg
hey
yo
0
2
Sent1
2Msg
= z1 + z3
1
1
2
1
2
0
1
hey
yes
asd
no
wyz
yo
1
3
3
1
0
2
2
4
Src
Msg
yo
yes
0
2
Rcvd2
ψ
1
Sent
ϕ
(z, S)
Y
Rcvd
ψ
Machine 0
Machine 4
Machine 1
Machine 3
Machine 2
Figure 3: A visualization of the construction used to prove Lemma 3.2 in three phases—the encoding of
each input SentSrc as embedding zSrc and subset SSrc with ϕ; the combination of those embeddings into
YDest via the simulation of sparsePropagates,m((z, S)); and the decoding of each YDest into output RcvdDest
with ψ. The figure provides an example of the encoding and decoding where machines 1 and 3 transmit
messages to machine 2. “Multiple hashing” is used to compute z1 and z3 by encoding each message in multiple
fixed-location “packets” in embedding space space. This redundancy ensures the possibility of machine 2
decoding Rcvd2 from Y2, due to each message occurring alone at least once in the encoding.
sparsePropagates,m as an intermediate step. A high-level overview of the proof construction is visualized in
Figure 3.
On input SentSrc, we use the encodings QSrc, KSrc, VSrc to specify that all tokens Dest with Dest ∈SentSrc
(or equivalently, all Dest with Src ∈RcvdDest) should receive a copy of the encoding of SentSrc. That is, we
set SSrc := {Dest ∈SentSrc} for each Src ∈[N]. This ensures that Y satisfies
YDest =
1
|RcvdDest|
X
Src∈RcvdDest
zSrc.
While it’s tempting to simply set each zSrc ∈Rm equal to a (βs)-dimensional vectorization of SentSrc, it
is unclear how to extract RcvdDest from each YDest, since each average performed by sparsePropagates,m will
combine multiple vector embeddings in a shared space. In order to avoid these troubles, we employ a multiple
hasing-based encoding that treats messages as “packets” identified by a message, a source, a destination, and
a “validity token” that can be used to determine whether a message is uncorrupted. We include multiple
18

copies of each packet in the encoding zSrc. For notational ease, we represent each zSrc ∈Rm as a collection of
packets
zSrc = (g
MsgSrc,j, g
SrcSrc,j, ]
DestSrc,j, αSrc,j)j∈[m′] ∈(Zβ
2p × [N] × [N] × {0, 1})m′,
where m = m′(3 + β).
To sparsely and redundantly encode each SentSrc as zSrc, we encode outgoing messages as packets
by utilizing the matrix A guaranteed by the following fact (which we use with n := N 2, b := s2, and
m′ := d = O(s4 log N)).
Fact B.2. For any n, b ≤n, and d ≥

12b2 ln n

, there exists a binary matrix A ∈{0, 1}n×d such that, for
every subset S ⊆[n] with |S| ≤b, the columns of the sub-matrix AS ∈{0, 1}|S|×d contains all S-dimensional
elementary vectors, i.e.,

e1, . . . , e|S|
	
is a subset of the columns of AS.
The proof of Fact B.2 is at the end of the section. We use the following rule to determine which (if any)
message to encode as a packet at each Src ∈[N] and j ∈[m′]. We let A(Src,Dest),j = AN(Src−1)+Dest,j for
notational convenience.
zSrc,j =





(Msg, Src, Dest, 1)
if (Msg, Dest) ∈SentSrc and A(Src,Dest),j = 1
and A(Src,Dest′),j = 0, ∀Dest′ ∈SentSrc \ {Dest} ,
(⃗0, 0, 0, 0)
otherwise.
In Figure 3, this encoding is visualized in the tables of “Machine 1” and “Machine 3,” where the entirety of
each message is encoded in two fixed and distinct locations in the embeddings z1 and z3, alongside metadata
about the source of message and the validity ˜α. Each message is encoded as multiple identical packets in
different embedding dimensions and a large fraction of embedding locations are left blank. These features are
critical for the proper evaluation of the decoding step ψ.
We analyze the Y = sparsePropagateβ,m(X) outputs, letting
YDest = (YDest,1, . . . , YDest,m′),
YDest,j ∈(Rβ × R × R × R)m′,
with all numbers represented with p-bit fixed precision. This analysis shows that there exists an element-wise
decoder MLP ψ satisfying ψDest(YDest) = RcvdDest for all Dest ∈[N]. For any j ∈[m′], observe from the
definition of zSrc and sparsePropagates,m that
YDest,j =:
MsgDest,j, SrcDest,j, DestDest,j, ¯αDest,j

=
1
|RcvdDest|
X
Src∈RcvdDest

g
MsgSrc,j, g
SrcSrc,j, ]
DestSrc,j, αSrc,j

.
Before formally analyzing this construction, we motivate its utility with Figure 3. The encoding 2Y2 of
Machine 2 contains four “clean” rows j with 2¯α2,j = 1, two “corrupted” rows with 2¯α2,j = 2, and one “blank”
row with 2¯α2,j = 0.
• The blank row contains no information about any incoming messages, since neither Machine 1 nor
Machine 3 encoded messages as packets in these locations. The fact that 2¯α2,j = 0 certifies the blankness
of this row, and hence, the decoder ψ can ignore it.
• The corrupted rows correspond to locations where both Machine 1 and Machine 3 saved messages as
packets. As a result, the corresponding embedding Y2,j = 1
2(z1,j + z3,j) is an average of two non-zero
embeddings and is hence “corrupted.” Because 2¯α2,j = 2, the decoder ψ detects the corruption and
ignores it when computing Rcvd2.
• The clean rows are locations where exactly one of Machine 1 and Machine 3 encoded a message. Hence,
these messages can be cleanly understood by the decoder ψ, which simply validates the “cleanliness” of
the row with 2¯α2,j = 1, determines whether Machine 2 is indeed the target recipient of the respective
message, and saves all such messages in the decoding Rcvd2.
19

We prove the validity of this intuition by ensuring that the encoding scheme successfully encodes each
incoming message in a clean row and that the category of each row (blank, corrupted, or clean) can be
detected by the decoder ψ. We observe the following sequence of facts about every YDest. Let
RelevantDest := {(Msg, Src′, Dest′) : Src′ ∈RcvdDest, (Msg, Dest′) ∈SentSrc′}
denote the set of all messages sent by sources of messages sent to Dest.
1. Consider any outgoing message (Msg, Src′, Dest′) ∈RelevantDest. By the property of A guaranteed by
Fact B.2, there exists some j such that A(Src′,Dest′),j = 1 and A(Src′′,Dest′′),j = 0 for every (Src′′, Dest′′) ∈
RelevantDest \ {(Src′, Dest′)} . As a result of the definition of the encoding z and the averaged
representation of YDest:
YDest,j =
1
|RcvdDest| (Msg, Src′, Dest′, 1) .
(1)
2. Conversely, if ¯αDest,j = 1/|RcvdDest|, then there exists a unique (Msg, Src′, Dest′) ∈RelevantDest such
that (1) is satisfied.
3. If at least one message is received, then the minimal nonzero value of ¯αDest is 1/|RcvdDest|.
We design ψDest to uniquely identify RcvdDest from YDest as follows. If at least one message is received,
then 1/|RcvdDest| can be identified by finding the smallest nonzero value of ¯αDest. The decoder ψ inspects
every YDest,j satisfying ¯αDest,j = 1/|RcvdDest|, which therefore satisfies
|RcvdDest| · (MsgDest,j, SrcDest,j, DestDest,j) ∈RelevantDest.
Thus, if |RcvdDest| · DestDest,j = Dest, then |RcvdDest| · (MsgDest,j, SrcDest,j) ∈RcvdDest, and ψ encodes it as
such.
Fact B.2. For any n, b ≤n, and d ≥

12b2 ln n

, there exists a binary matrix A ∈{0, 1}n×d such that, for
every subset S ⊆[n] with |S| ≤b, the columns of the sub-matrix AS ∈{0, 1}|S|×d contains all S-dimensional
elementary vectors, i.e.,

e1, . . . , e|S|
	
is a subset of the columns of AS.
Proof. Let col(A) denote the set of columns of A. We use the probabilistic method and consider A with iid
entries Ai,j ∼Bernoulli(
1
b+1). We bound the probability of failure:
Pr

∃S ∈
 [n]
≤b

s.t.

e1, . . . , e|S|
	
̸⊂col(AS)

≤b · nb Pr [ei ̸∈col(AS)]
≤nb+1
 
1 −
1
b + 1 ·

1 −
1
b + 1
b!d
≤nb+1

1 −
1
e(b + 1)
d
≤nb+1 · exp

−
d
e(b + 1)

< exp

(b + 1) ln n −
d
3(b + 1)

≤1.
Therefore, there exists a matrix A with the claimed property.
20

Attention head
Attention head
Sparse propagation
Local
Softmax attention
Attention head
Local
Q(·)
K(·)⊤
V (·)
Multiple
hashing
Figure 4: To simulate MPC, the local computation within each machine is pushed inside Q(·), K(·), V (·), and
then the pairwise attention matrix performs message routing. To ensure proper routing and also that the
outputs of Q(·), K(·), V (·) are all tall-and-skinny matrices, the construction carefully utilizes both multiple
hashing and sparse propagation.
B.2
Proof of Theorem 3.1
We give a generalization of Theorem 3.1 that simulates a broader family of MPC protocol, including those
with more than n machines (i.e. γ ≥δ). We accommodate this generalization by simulating MPC protocols
with the generalized transformer family TransformerN,M
m,L,H detailed in Appendix A with supplemental blank
“chain-of-thought” tokens.
Theorem B.3 (Generalization of Theorem 3.1). For constant γ, δ > 0 and any potentially randomized
R-round (γ, δ)-MPC protocol π on nin input words and nout ≤nin output words, there exists a transformer T ∈
TransformerN,M
m,L,H with N = nin, M = max(nin, O(n1+γ−δ
in
)), m = O(n4δ
in log nin), L = R+1, H = O(log log nin)
such that
T(Input):nout = π(Input).
Theorem 3.1 is an immediate consequence of Theorem B.3 by noting that M = N for sufficiently large
nin when γ < δ. Its central construction is summarized in Figure 4.
Proof. Consider any MPC protocol π with q = O(n1+γ−δ
in
) machines and s = O(nδ
in) local memory
that, following the notation of Definition 2.3, maps Input ∈Znin
2p
to Output ∈Znout
2p
with interme-
diates MachineIn(1), . . . MachineIn(R) and MachineOut(1), . . . , MachineOut(R) and deterministic functions
(Localr,i)r∈[R],i∈[q] with
MachineOut(r)
i
= Localr,i(MachineIn(r)
i ).
To simulate the protocol, we let every machine i ∈[q] correspond to a particular position in the transformer’s
context. A transformer that simulates π can then be constructed that consolidates Input onto ⌈nin/s⌉machines
to match MachineIn(1); computes MachineIn(r+1) from MachineIn(r) for each r = 1, . . . , R−1; and computes
and properly distributes Output from MachineIn(r). These three elements of the construction exist due to
the following lemmas, which are proved later.
21

Lemma B.4. For any MPC protocol π with local memory s and q machines with nin-word inputs, there
exists a transformer init ∈Transformernin,max(nin,q)
s,1,1,din,dout
with din = 1 and dout = s, which, given Input ∈Zn
2p, has
output satisfying init(Input) = MachineIn(1).
Lemma B.5. For any R-round MPC protocol π with local memory s and q machines and any r ∈[R −1],
there exists a transformer round(r) ∈Transformerq
m,1,H,din,dout with H = O(log log q), m = O(s4 log q), and
din = dout = s which, given any valid input X = MachineIn(r) ∈Zq×m
2p
under the MPC protocol in vectorized
form, has output satisfying round(r)(X) = MachineIn(r+1).
Lemma B.6. For any R-round MPC protocol π with local memory s and q machines with nout-word output,
there exists a transformer final ∈Transformerq,max(nout,q)
s,1,1,din,dout
for din = s and dout = 1, which, given input
X = MachineIn(R), has output final(X) with final(X)i,1 = Outputi ∈Z2p.
The proof immediate from the three lemmas. We construct the final transformer T by stacking the
single-layer constructions as a single transformer with embedding dimension m:
T = final ◦round(R−1) ◦· · · ◦round(1) ◦init.
The proofs of Lemmas B.4 and B.6 rely on simple constructions with fixed attention matrices and appear
in Appendix F. The proof of Lemma B.5 relies on Lemma 3.2 and is proved in the following section.
Proof of round(r) construction.
To prove the existence single-layer transformer that simulates round(r),
we separate the computational task into two steps: (i) obtaining MachineOut(r) from MachineIn(r) and
(ii) obtaining MachineIn(r+1) from MachineOut(r). Because the former requires no communication between
machines, we can encode that conversion in the input MLP to the transformer.
The nontrivial part of the reduction is thus the latter step, which we obtain by utilizing multiple single-
headed attention units routeβ,s of Lemma 3.2 to route messages of different sizes to their recipients. The
difficulty in this task is the mismatch in functionality between the two computational models: while the MPC
model ensures that each recipient automatically receives its intended messages, transformers must implement
this functionality manually, while ensuring that multiple messages do not overwrite one another.
The following lemma implements that routing functionality for all messages, using different attention
heads depending on the size of the message. We prove Lemma B.5 at the end of the section as a simple
modification of Lemma B.7.
Lemma B.7. For any R-round MPC protocol π with local memory s and q machines and any r ∈[R −1],
there exists a transformer route(r) ∈Transformerq
m,1,H with H = O(log log q) and m = O(s4 log q), which,
given any valid input X = MachineOut(r) ∈Zq×m
2p
under the MPC protocol in vectorized form, has output
satisfying route(r)(X) = MachineIn(r+1).
Because at most s messages can be shared and received by each machine, and each message is of size at
most s, we can prove an single-headed alternative to Lemma B.7 with a somewhat suboptimal dependence on
embedding dimension. By applying by Lemma 3.2 with message size β = s, bounded number of messages s,
and context length N = q, there exists a transformer routes,s with H = 1 and m = O(s5 log q) that computes
MachineIn(r+1) from MachineOut(r+1) by regarding each outgoing message as belonging to Zs
2p by adding
padding dimensions as needed.
We improve the embedding dimension to m = O(s4 log q) by running in parallel O(log log N) transformers
guaranteed by Lemma 3.2 that encode differently sized messages. The number of heads H increases at a
doubly-logarithmic rate because of a doubling trick employed on the size of message encodings used by
constituent part.
22

Proof. We describe an implementation of route(r) by considering any fixed input MachineOut(r) ∈Zq×m
2p
. For
each i ∈[q] and some integer sequence 1 = β0 < β1 < · · · < βH = s + 1, we partition MachineOut(r)
i
into H
disjoint subsets as follows. For any h ∈[H], let
Senth
i :=
n
(Msg, Dest) ∈MachineOut(r)
i
: dim(Msg) ∈[βh−1, βh]
o
,
Rcvdh
i :=
n
(Msg, Src) ∈MachineIn(r+1)
i
: dim(Msg) ∈[βh−1, βh]
o
,
and note that MachineOut(r)
i
= ˙SH
h=1Senth
i and MachineIn(r+1)
i
= ˙SH
h=1Rcvdh
i .
For each h ∈[H], note that dim(Msg) ≤βh, and
Senth
i
 =
Rcvdh
i
 ≤s/βh−1. As a result, Lemma 3.2
guarantees the existence of a single-headed transformer route(r)
h
such that route(r)
h (Senth) = Rcvdh) with
embedding dimension mh ≤Cs4βh log(q)/β4
h−1 for some sufficiently large universal constant C.
We defined route(r) as the computation of route(r)
1 , . . . , route(r)
H as H parallel heads of self-attention with
disjoint embeddings concatenated into in m-dimensional embedding space with m = PH
h=1 mh. We conclude
by letting
βh =
(
1
if h = 0,
min(2β3
h−1, q + 1)
if h ∈[H],
noting that βH = q + 1 for H = O(log log q), and bounding m:
m ≤
H
X
h=1
Cs4 log(q)βh
β4
h−1
≤2Cs4 log(q) ·
H
X
h=1
1
βh−1
≤2Cs4 log(q) ·
H
X
h=1
1
2h−1 = O(s4 log q).
Proof of Lemma B.5. To simulate a round of MPC protocol π by mapping MachineIn(r) and ρr to MachineIn(r+1),
the single-layer transformer round(r) first computes MachineOut(r) element-wise and then properly routes
messages in MachineOut(r) to their proper destination. We can define round(r) = route(r) ◦Localr for route(r)
in Lemma B.7 and Localr,i(MachineIn(r)
i , ρr,i) = MachineOut(r)
i . This can be immediately constructed as a
single-layer transformer by prepending the embeddings Q, K, V of the construction of route(r) with Localr,
using Q ◦Localr, K ◦Localr, V ◦Localr as the embeddings of round(r).
B.3
Additional graph problems solvable by log-depth transformers
Theorem 8.1 and Corollary 8.2 of Coy and Czumaj (2022) give efficient MPC protocols for other graph problems
besides connectivity, and therefore, as corollaries of Theorem 3.1, we also obtain log-depth transformers for
these problems.
Corollary B.8 (Spanning forest construction). For any constant ϵ ∈(0, 1) and any D ≤N, there exists
a transformer in TransformerN
m,L,H with m = O(N ϵ), H = O(log log N), and L = O(log D) that computes a
rooted spanning forest of any input graph G = (V, E) with |V |, |E| = O(N) where each connected component
has diameter at most D.
Corollary B.9 (Minimum spanning forest construction). For any constant ϵ ∈(0, 1) and any DMSF ≤N,
there exists a transformer in TransformerN
m,L,H with m = O(N ϵ), H = O(log log N), and L = O(log DMSF )
that identifies the connected components of any input graph G = (V, E) with |V |, |E| = O(N) and poly(N)-
bounded integer weights whose minimum spanning forest has diameter at most DMSF .
23

(Qh,i, Kh,i, Vh,i)
Token machines
Key/value
propagation
machines
Query
propagation
machines
Q⊤
h,iKh,i′
Inner product machines
Figure 5: This construction employs M 2 inner product machines to compute the entries of the softmax
matrix, and M token machines to compute all values of Q(·), K(·), V (·). What is most complex about the
construction are the additional machines and message routing needed to propagate these values efficiently
between the inner product machines and the token machines, in particular carefully aggregating the output of
the attention mechanism and computing its normalization. To this end, the protocol uses additional machines,
organized into a tree with branching factor b = O(N δ′−δ) and depth D = O( 1+α
δ′−δ).
C
Proofs from Section 3.2
C.1
Proof of Theorem 3.4
As in Appendix B.2, we give and prove a generalized version of Theorem 3.4 that broadens the family of
considered transformers to include masked models and those that contain extra blank chain-of-thought tokens,
using notation from Appendix A.
Theorem C.1 (Generalization of Theorem 3.4). For any transformer T ∈TransformerN,M
m,L,H (or MaskTransformerN,M
m,L,H)
with mH = O(N δ) for δ ∈(0, 1) and M = Θ(N 1+α) for α ≥0 and for any δ′ ∈(δ, 1), there exists an
O( L(1+α)
δ′−δ )-round (1 + 2α + δ′, δ′)-MPC protocol with q = O(M 2) machines with s = O(N δ′) local memory
that outputs the same sequence as T(X) for all X ∈RN.
Theorem 3.4 is an immediate consequence by setting M := N and α := 0.
Proof. It suffices to show that an O( 1+α
δ′−δ)-round MPC protocol π that simulates a single-layer transformer
T ∈TransformerM
m,m,m,1,H with m-dimensional input and output embeddings since a depth-L transformer
can be constructed by applying L such protocols sequentially. Moreover, we can ignore the difference between
the input context length N and the context length with padding M by assuming that the input contains M
tokens.
Concretely, we consider H heads with embeddings (Qh, Kh, Vh)h∈[H], element-wise output MLP ψ =
(ψ1, . . . , ψM), and any fixed masks Λ1, . . . , ΛH ∈{−∞, 0}M×M. We show that there exists some π such that
24

for any Input = X ∈RM×m,
π(X) = ψ
 
X +
H
X
h=1
softmax(Qh(X)Kh(X)T + Λh)Vh(X)
!
,
where numbers in X and all intermediate products of the transformer computation can be represented with
p = O(log M) bit precision.
Our MPC protocol π, which will use q = O(M 2) machines and s = Θ(N δ′) words of local memory per
machine, assigns each of the q machines to one of four possible roles: token machine, inner product machine,
query propagation machine, and key/value propagation machine. We describe these machines below. For the
sake of readability, we identify machines with easily interpretable descriptions and use the bijection ID to map
each of those to a token in [q] that is used for routing messages. Our protocol has two important parameters:
b = ⌊s/(4mH)⌋= O(N δ′−δ) is the branching factor of the protocol, and D = ⌈logb(M)⌉= O( 1+α
δ′−δ) is the
depth of the protocol.
At a high level (see Figure 5 for a corresponding diagram), the protocol involves computing all intermediate
products of the of a transformer unit by performing MLP computations in N token machines, computing
inner products in N 2 inner product machines, and using O(N 2) other propagation machines arranged in trees
to share information between the two in O(D) rounds. The protocol draws inspiration from Appendix C.6.1
of Sanford et al. (2023), which uses a similar construction to simulate transformers with Congest protocols
on fixed graphs. It is also similar to the MPC implementation of the MPI AllReduce functionality (MPICH,
2023) described by Agarwal et al. (2014).
• Machine i ∈[M] is a token machine that performs all element-wise computation on the ith token
embedding, including the computation of (Qh,i(Xi), Kh,i(Xi), Vh,i(Xi))h∈[H] and the final MLP output
ψi. Let ID(i) = i.
• Machine (i, i′) ∈[M]2 is an inner product machine designed to compute the inner products (Qh,i(Xi)TKh,i′(Xi′))h∈[H].
• Machine (Q, i, d, k) for token i ∈[M], depth d ∈[D −1] and position k ∈[bd] is a query propagation
machine. This machine is responsible for handling communication of query tokens (Qh,i(Xi))h∈[H] and
of all partially-computed attention outputs for the ith token between token machine i and inner product
machines (i, i′) for
i′ ∈Descendantsd,k :=

bD−d(k −1), . . . , bD−dk
	
∩[M].
Concretely, if ℓ= 1, then the machine communicates with token machine i and query propagation
machines (Q, i, d + 1, k′) for
k′ ∈Childrenk := {b(k −1) + 1, . . . , bk} .
If ℓ= D −1, then it communicates with inner product machines (i, i′) for i′ ∈Childrenk ∩[M] and
query propagation machine (Q, i, d −1, ⌊k/b⌋). Otherwise, it communicates with query propagation
machines (Q, i, d −1, Parentk), for Parentk := ⌊k/b⌋, and (Q, i, d + 1, k′) for k′ ∈Childrenk.
• Machine (KV, i, d, k) is a key/value propagation machine.
This machine is analogous to a query
propagation machine, except that it is responsible for the communication of key and value to-
kens (Qh,i(Xi), Vh,i(Xi))h∈[H] between token machine i and inner product machines (i, i′) for i′ ∈
Descendantsd,k.
Since the total number of machines is q = M + M 2 + M PD−1
d=1 bd = O(M 2), we conclude that the global
memory of the protocol is qs = O(N 2+2α+δ′), which means the protocol is (1 + 2α + δ′, δ′)-MPC. We simulate
the transformer using a four stage protocol using 2D + 3 = O( 1+α
δ′−δ) rounds of MPC computation.
25

Stage 1: Token dispersion.
Because the input to an MPC protocol Input = X is divided equally
among machines 1, . . . , ⌈MmH/s⌉, the first round of MPC computation routes each input token Xi to its
respective token machine. This is completed by setting (i, Xi) ∈MachineOut(1)
i′
if (i, Xi) ∈MachineIn(1)
i′ .
Thus, MachineIn(2)
i
= {(Src, Xi)} for all token machines i ∈[M].
Stage 2: Embedding propagation.
In rounds 2, . . . , D + 1, π computes the respective key, query, and
value embeddings in each token machine and propagate them to respective inner product machines using the
query and key/value propagation machines. Concretely:
• In round 2, each token machine i (whose memory contains Xi) computes m-dimensional embeddings
embeddings Qi := (Qh,i(Xi))h∈[H], Ki := (Kh,i(Xi))h∈[H], Vi := (Vh,i(Xi))h∈[H]. It transmits each
embedding to the respective depth-1 query and key/value propagation machine nodes, while also
preserving knowledge of its own Xi. (In all further rounds, we assume that ((i, Xi)) ∈MachineOut(r)
i
to ensure that token machine i can compute the skip-level connection at the end.) That is,
MachineOut(2)
i
= {(i, Xi)}
∪{(ID(Q, i, 1, k′), Qi) : k′ ∈Children1}
∪{(ID(KV, i, 1, k′), (Ki, Vi)) : k′ ∈Children1} .
Note that the total amount of messages sent is b · mH + 2b · mH + m ≤s and that the only machines
receiving messages are size m-messages by token machines and size ≤4mH messages by query and
key/value propagation machines.
• In rounds r ∈{3, . . . , D}, each query and key/value propagation machine of depth d = r −2 passes
embeddings onto their successors. That is,
MachineOut(r)
ID(Q,i,d,k) = {(ID(Q, i, d + 1, k′), Qi) : k′ ∈Childrenk} ,
MachineOut(r)
ID(KV,i,d,k) = {(ID(KV, i, d + 1, k′), (Ki, Vi)) : k′ ∈Childrenk} .
• In round D + 1, the depth-(D −1) query and key/value propagation machines pass their embeddings
onto their respective inner product machines. That is,
MachineOut(D+1)
ID(Q,i,D−1,k) = {(ID(i, k′), Qi) : k′ ∈Childrenk ∩[M]} ,
MachineOut(D+1)
ID(KV,i,D−1,k) = {(ID(k′, i), (Ki, Vi)) : k′ ∈k′ ∈Childrenk ∩[M]} .
Stage 3: Softmax computation.
In rounds D+2, . . . , 2D+2, computes each inner product and iteratively
builds up each attention output by accumulating partial softmax computations. For each query propagation
machine (Q, i, d, k) and h ∈[H], we let Si,d,k,h and Zi,d,k,h denote its partial normalization and softmax
computations respectively. That is,
Zi,d,k,h =
X
i′∈Descendantsd,k
exp(Qh,i(Xi)TKh,i′(Xi′))1 {Λi,i′ = 0}
=
(P
k′∈Childrenk Zi,d+1,k′,h
if d ≤D −1,
exp(Qh,i(Xi)TKh,k(Xk))1 {Λi,k = 0}
if d = D.
Si,d,k,h =
1
Zi,d,k,h
X
i′∈Descendantsd,k
exp(Qh,i(Xi)TKh,i′(Xi′))Vh,i′(Xi′)1 {Λi,i′ = 0}
=
(P
k′∈Childrenk
Zi,d+1,k′,h
Zi,d,k,h
· Si,d+1,k′,h
if d ≤D −1,
Vh,k(Xk)1 {Λi,k = 0}
if d = D;
Note that Si,0,1,h = (softmax(Qh(X)Kh(X)T + Λh)Vh(X))i and let Si,d,k = (Si,d,k,h)h∈[H] ∈RH×m and
Zi,d,k = (Zi,d,k,h)h∈[H] ∈RH
26

• In round D + 2, each inner product machine computes its respective inner products and passes its
partial softmax computations to its parent query propagation machine. As a result of round D + 1,
each inner product machine (i, i′) recently received the embeddings necessary to compute the relevant
inner product:
MachineIn(d+2)
ID(i,i′) = {(ID(Q, i, D −1, Parenti), Qi), (ID(KV, i′, D −1, Parenti′), (Ki′, Vi′))} .
It propagates the respective partial computations Si,D,i′ and Zi,D,i′ as follows:
MachineOut(D+2)
ID(i,i′) = {(ID(Q, i, D −1, Parenti), (Si,D,i′, Zi,D,i′))} .
Note that each depth-(D−1) query propagation machine receives messages of size at most b·(m+1)H ≤s.
• In rounds r ∈{D + 3, . . . , 2D}, partial softmax computations are received by query propagation
machines of depth d = 2D + 1 −r, added together, and passed along to their parent machines. That is,
given
MachineIn(r)
ID(Q,i,d,k) = {(ID(Q, i, d + 1, k′), (Si,d+1,k′, Zi,d+1,k′)) : k′ ∈Childrenk} ,
each respective machine computes Si,d,k and Zi,d,k recursively and propagates
MachineOut(r)
ID(Q,i,d,k) = {(ID(Q, i, d −1, Parentk), (Si,d,k, Zi,d,k)} .
• In round 2D + 1, the top-most query propagation tokens pass their partial sums to the token machines:
MachineOut(2D+1)
ID(Q,i,1,k) = {(i, (Si,1,k, Zi,1,k))} .
• In round 2D + 2, the token machines compute their respective output of the transformer, T(X)i. Given
input
MachineIn(2D+2)
i
= {(k′, (Si,1,k′, Zi,1,k′)) : k′ ∈Children1} ∪{(i, Xi)} ,
the token machine i computes Si,0,1 and Hi,0,1 and then
T(X)i = ψi
 
Xi +
H
X
h=1
softmax(Qh(X)Kh(X)T + Λh)T
i Vh(X)
!
= ψi
 
Xi +
H
X
h=1
Si,0,1,h
!
.
This quantity is used as an intermediate product for the final phase of computation.
Stage 4: Token compression.
We invert Stage 1 by properly compressing the MPC output in the final
round 2D + 3. That is, we let MachineOut(2D+2)
i
= {(⌊imH/s⌋+ 1, T(X)i)} for each token machine i ∈[M],
which ensures that the outputs are condensed in the proper order in machines 1, . . . , ⌈MmH/s⌉.
Precision analysis.
In order for the proof to be fully sound, care must be taken to ensure that the
computation of each self-attention output Si,0,1,h is handled with proper numeric precision, as discussed in
Appendix A. We show that each Si,0,1,h is a valid implementation of its corresponding self-attention unit, per
Definition A.1.
To do so, we let ˆSi,d,k,h and ˆZi,d,k,h denote the p-bit representations of Si,d,k,h and Zi,d,k,h, where scalars
of ˆSi,d,k,h and log( ˆZi,d,k,h) are represented as discretized rational numbers z satisfying |z| ≤1
22p/2 and
z · 2p/2 ∈Z. For some sufficiently small p′ = Θ(p), we assume that all embeddings Qh(X), Kh(X), Vh(X)
have scalars z satisfying |z| ≤1
22p′/2 and z · 2p′/2 ∈Z. We prove that for each h ∈[H],



Si,0,1,h −ˆSi,d,k,h



∞= O
 1
2p′

.
27

Boundedness of intermediate representations is not an issue because
log(Zi,d,k,h) ≤O(log(N) + max
i,i′ |Q(X)T
i K(X)i′|) = exp(O(p′)),
and
∥Si,d,k,h∥∞≤∥V (X)∥∞≤2p′/2.
It remains to show that that all intermediate representations are sufficiently close to their exact counterparts.
We prove the following via an inductive argument for d = D, D −1, . . . , 0:
log(Zi,d,k,h) −log( ˆZi,d,k,h)
 ≤(2b)D−d
2p/2
,
(2)



Si,d,k,h −ˆSi,d,k,h



∞≤2p′/2(8b)D−d
2p/2
.
(3)
If (3) holds for d = 0, then the claim holds for sufficiently large p = Θ(p′).
For the base case D, we verify (3) by



Si,D,k,h −ˆSi,D,k,h



∞=



Vh,k(Xk)1 {Λi,k = 0} −ˆSi,D,k,h



∞≤
1
2p/2 ,
due to the ability to access Vh,k(Xk) and round it directly. We verify (2) due to the immediate access to and
boundedness of Qh,i(Xi)TKh,k(Xk):
|log(Zi,d,k,h)| ≤
Qh,i(Xi)TKh,k(Xk)
 ≤∥Qh,i(Xi)∥2 ∥Kh,k(Xk)∥2 ≤N · 2p′/2.
We prove the inductive step for d −1, assuming that the inductive hypothesis holds for d. We first address
ˆZi,d−1,k,h by employing the Lipschitzness of the log-sum-exp function.
log(Zi,d−1,k,h) −log( ˆZi,d−1,k,h)
 ≤
1
2p/2 +
log
 X
k′
exp(log(Zi,d,k′,h))
!
−log
 X
k′
exp(log( ˆZi,d,k′,h))
!
≤
1
2p/2 +
X
k′
log(Zi,d,k′,h) −log( ˆZi,d,k′,h)

≤
1
2p/2 + b · (2b)D−d
2p/2
≤(2b)D−d+1
2p/2
.
To obtain (3) for d −1, we first note that for sufficiently large p:
1 −
ˆZi,d,k′,hZi,d−1,k′,h
Zi,d,k,h ˆZi,d−1,k′,h
 =
1 −exp
 
log
 ˆZi,d,k′,h
Zi,d,k′,h
!
+ log
 
Zi,d−1,k,h
ˆZi,d−1,k,h
!!
≤1 + 2
 log
ˆZi,d,k′,h
Zi,d,k′,h
 +
log Zi,d−1,k,h
ˆZi,d−1,k,h

!
≤4 · (2b)D−d+1
2p/2
.
28

We conclude by using the fact that each Si,d−1,k,h is a convex combination of other Si,d,k,h.



Si,d−1,k,h −ˆSi,d−1,k,h



∞≤
1
2p/2 +
X
k′





Zi,d,k′,h
Zi,d−1,k′,h
Si,d,k′,h −
ˆZi,d,k′,h
ˆZi,d−1,k′,h
ˆSi,d,k′,h





∞
≤
1
2p/2 +
X
k′
Zi,d,k′,h
Zi,d−1,k′,h





Si,d,k′,h −
ˆZi,d,k′,hZi,d−1,k′,h
Zi,d,k,h ˆZi,d−1,k′,h
ˆSi,d,k′,h





∞
≤
1
2p/2 +
X
k′
Zi,d,k′,h
Zi,d−1,k′,h



Si,d,k′,h −ˆSi,d,k′,h



∞
+
X
k′
Zi,d,k′,h
Zi,d−1,k′,h



 ˆSi,d,k′,h



∞
1 −
ˆZi,d,k′,hZi,d−1,k′,h
Zi,d,k,h ˆZi,d−1,k′,h

≤
1
2p/2 + 2p′/2(8b)D−d
2p/2
+ 2p′/2 X
k′
Zi,d,k′,h
Zi,d−1,k′,h
1 −
ˆZi,d,k′,hZi,d−1,k′,h
Zi,d,k,h ˆZi,d−1,k′,h

≤2 · 2p′/2(8b)D−d
2p/2
+ 2p′/2 · 4 · (2b)D−d+1
2p/2
≤2p′/2(8b)D−d+1
2p/2
.
Owing to the fact that D and p′ are constants and b = N O(1), a sufficiently large choice of p guarantees
that the implementation is valid.
C.2
Proof of Corollary 3.5
Corollary 3.5. Let ϵ ∈(0, 1) be any constant, and let D ≥N ϵ. Assume Conjecture 2.4, and suppose there
exists T ∈TransformerN
m,L,H with mH = O(D1−ϵ) that decides connectivity of any input graph with connected
components having diameter ≤D. Then L = Ω(log D).
We prove Corollary 3.5 by combining Theorem C.1 and Conjecture 2.4.
Proof. Fix any D ≤N with D ≥N ξ for some ξ ∈(0, 1]. Let C1 denote a cycle graph on D vertices, and let
C2 denote the union of two cycle graphs each with D/2 vertices.
Suppose there is a transformer T ∈TransformerN
m,L,H with mH = O(D1−ϵ) that determines the connectiv-
ity of graphs with at most N edges and connected components with diameter at most D. We will show that
it can be used to design an Θ(L)-round MPC protocol π that distinguishes graphs C1 and C2 with n = D
edges.
Let π′ be an MPC protocol that exactly computes the output of T using taking R = O(L) rounds with
local memory s = O(D1−ϵ/2) and q = O(N 2) machines, which is guaranteed to exist by Theorem C.1.
Let n := 2
 D
4

and k :=
 N
n

. We design π with the same local memory and machine count to determine
the identity of input graph G = (V, E) ∈{C1, C2} provided as an arbitrary sequence of n edges. Let u ∈V
be an arbitrary vertex in G.
Using a constant number of MPC rounds, π converts G into a graph G′ = (V ′, E′) with |E′| = kn+k ≤N
and diameter n + 2 ≤D such that G′ is connected if and only if G = C1. We do so by letting G′ be composed
of k copies G1, . . . , Gk of G on separate vertices, along with k extra edges connecting the vertex corresponding
to u in each Gj (say uj ∈Gj) to u1 ∈G1. This ensures that the connectivity correspondence and edge
count diameter bounds are met. Since G′ can be produced by simply copying edges from G and adding an
additional edge each time an edge containing u is copied, π can produce G′ in O(1) rounds.
Then, π simulates π′ on G′ and returns its output. Since G′ is connected if and only if G = C1, this
protocol suffices to distinguish C1 and C2. Because the protocol uses s = O(n1−ϵ/2) local memory and
q = O(n2/ξ) machines, Conjecture 2.4 implies that π (and hence T) only exists if L = Ω(log n) = Ω(log N).
29

D
Proofs from Section 4.1
D.1
Proof of Theorem 4.2
Theorem 4.2. For any k ∈N and alphabet Σ with |Σ| ≤N, there exists T ∈MaskTransformerN
m,L,H that
computes hopk : ΣN →(Σ ∪{⊥})N with m = O(1), L = ⌊log2 k⌋+ 2, and H = 1.
Proof. We design a masked transformer that implements hopk in two phases. The first two layers compute
find1
X(i) for each i ∈[N] using a similar approach to the induction heads construction of Bietti et al. (2023).
The subsequent layers employ a doubling trick to compute each find2ℓ−2
X
(i) after ℓlayers.
To do so we employ two technical lemmas (which are proved in Appendix F.4) that describe the
implementation of masked self-attention units that copy .
Lemma D.1. For some m ≥d + 2, τ : [N] × Rm →[N], and ρ : Rm →Rd, there exists an attention head
lookUpτ,ρ ∈MaskAttnN
m with precision p = O(log N) and m ≥d+2 satisfying lookUpτ,ρ(X)i,:d = ρ(Xτ(i,Xi)).
Lemma D.2. For any finite alphabet Σ, m ≥d + 2, µ1, µ2 : Rm →Σ, and ρ : Rm →Rd, there exists an
attention head lastOccurrenceµ,ρ ∈MaskAttnN
m with precision p = O(log(N |Σ|)) such that,
lastOccurrence(X)i,:d =
(
ρ(⃗0)
if ∀i′ < i : µ1(Xi′) ̸= µ2(Xi),
ρ(Xi′)
if i′ = max {i′ < i : µ1(Xi′) = µ2(Xi)} .
The first layer obtains the previous token Xi−1 from each Xi. This is accomplished via the self-attention
head lookUpτ,ρ with τ(i, Xi) = i −1 and ρ(Xi) = Xi.
The second layer retrieves (find1
X(i), Xfind1
X(i)) for each i ∈[N] by finding the most recent token whose
preceding token is Xi. It does so by employing the lastOccurrenceµ1,µ2,ρ primitive on the intermediate state
X1
i = (Xi, Xi−1) with µ1(X1
i ) = Xi−1, µ2(X1
i ) = Xi, and ρ(X1
i ) = (i, Xi).
• If find1
X(i) > 0, then lastOccurrenceµ1,µ2,ρ(X1
i ) = (find1
X(i), Xfind1
X(i)).
• Otherwise, it obtains ⃗0 and performs no further passing, returning ⊥after all L layers.
If k = 1, the transformer returns T(X)i = Xfind1
X(i) = hopk(X)i.
Otherwise, let k := P⌊log2 k⌋
j=0
kj2j for some kj ∈{0, 1}, and let k:ℓ= Pℓ
j=0 kj2j. Construct a transformer
inductively to ensure that the ith output of the ℓth layer Xℓ
i ∈Rm for ℓ≥2 contains an encoding of

Xi, find2ℓ−2
X
(i), Xfind2ℓ−2
X
(i), findk:ℓ−2
X
(i), Xfind
k:ℓ−2
X
(i)

.
Note that the base case holds for ℓ= 2, since findk:0
X (0) = find1
X(0) if k0 = 0 and is i otherwise.
For each ℓ= 1, . . . , ⌊log2 k⌋+ 1, we assume that the inductive hypothesis holds up to layer ℓand prove
that it also holds for layer ℓ+ 1. To do so, we use a lookUpτ,ρ self-attention head with τ(i, Xℓ
i ) = find2ℓ−2
X
(i)
and
ρ(Xℓ
i ) = (find2ℓ−2
X
(i), Xfind2ℓ−2
X
(i), findk:ℓ−2
X
(i), Xfind
k:ℓ−2
X
(i)),
which ensures that Xℓ+1
i
can encode
find2ℓ−1
X
(i) = find2ℓ−2
X
(find2ℓ−2
X
(i))
Xfind2ℓ−1
X
(i) = Xfind2ℓ−2
X
(find2ℓ−2
X
(i))
findk:ℓ−1
X
(i) =
(
findk:ℓ−2
X
(find2ℓ−2
X
(i))
if kℓ−1 = 1
findk:ℓ−2
X
(i)
if kℓ−1 = 0
Xfind
k:ℓ−1
X
(i) =



Xfind
k:ℓ−2
X
(find2ℓ−2
X
(i))
if kℓ−1 = 1
Xfind
k:ℓ−2
X
(i)
if kℓ−1 = 0.
30

As a result, the output of layer L = ⌊log2 k⌋+ 2 contains an encoding of
Xfind
k:L−2
X
(i) = Xfindk
X(i) = hopk(X)i
for each i ∈[N]. This is returned as the output of T(X).
D.2
Proof of Corollary 4.3
Corollary 4.3. Assuming Conjecture 2.4, for any constants ξ ∈(0, 1/2] and ϵ ∈(0, 1), and any even
k = Θ(N ξ), every transformer T ∈MaskTransformerN
m,L,H with mH = O(k1−ϵ) that computes hopk has depth
L = Ω(log k).
Proof. The proof is analogous to that of Corollary 3.5. Let C1 be a cycle on k vertices, and C2 be the
union of two cycles each on k/2 vertices. So both C1 and C2 have k edges. We show that the existence of
T ∈TransformerN
m,L,H with mH = O(k1−ϵ) such that T(X) = hopk(X) can be used to design an Θ(L)-round
MPC protocol π to solve the task.
As a result of Theorem C.1, there exists an MPC protocol π′ that exactly computes T with R = Θ(L)
rounds with local memory s = O(D1−ϵ/2) and q = O(N 2) machines. On input G = (V, E) ∈{C1, C2}, we
design a constant-round protocol that computes an sequence X ∈ΣN such that hopk(X)N exactly determines
the identity of G.
Since the k edges are passed to π in an unknown ordering with unknown labelings, we let V = [k]
and denote the edges as e1 = {u1, v1} , . . . , ek = {uk, vk}. We define an operator next over the domain
{(u, v), (v, u) : {u, v} ∈E} as follows: for {u, v} ∈E, let next(u, v) := (v′, u) where v′ ∈V is the unique
vertex v′ ̸= v such that {u, v′} ∈E. Notice that next is well-defined because all vertices in a cycle have
degree 2. If G = C2, then nextk/2(ui, vi) = (ui, vi) for any i ∈[k].
To set up our encoding of G as a sequence X, we first construct a gadget for each edge ei that will be used
to compute a single next(ui, vi). Under the alphabet Σ = [k] ∪{†, ⋆, _}, we define the nine-token sequence
ei = ⋆ui † vi ui † vi ⋆_.
This gadget ensures that two hops will swap the values of ui and vi. That is
find2
ei◦ui(10) = find1
ei◦ui(6) = 4,
Xfind2
ei◦ui(10) = vi,
find2
ei◦vi(10) = find1
ei◦vi(8) = 2,
Xfind2
ei◦vi(10) = ui.
Likewise, concatenating sequences corresponding to overlapping edges facilitates multiple hops. For example,
if e1 = (1, 2), e2 = (3, 4), e3 = (2, 3), then
find2
e1◦e2◦e3◦2(28) = 22,
Xfind2
e1◦e2◦e3◦2(28) = 3,
find4
e1◦e2◦e3◦2(28) = 13,
Xfind4
e1◦e2◦e3◦2(28) = 4,
find4
e1◦e2◦e3◦3(28) = 2,
Xfind4
e1◦e2◦e3◦3(28) = 1.
Let
E := (e1 ◦e2 ◦· · · ◦ek)k/2 ◦1
be a length Nk := 9k · k
2 + 1 sequence and let X = (_)N−Nk ◦E. We show that hopk(X)N = hopk(E)Nk = 1
if and only if G = C2.
Without loss of generality, let {j, j + 1} = eij ∈E for all j ∈[ k
2 −1]. Let ei0 = {1, v∗}, where v∗= k
2 if
G = C2 and v∗= k if G = C1. Assume without loss of generality that i1 > i0. We argue inductively that for
any j ∈[ k
2]:
31

1. Every two hops simulates a single step of next:
hop2j(E)Nk = nextj(1, v∗)1 =
(
j
if j + 1 < k
2 or G = C1,
1
if j = k
2, G = C2;
2. Every two hops never “jumps” by more than one repetition of all edges gadgets:
find2j
E (Nk) ≥find2j−2
E
(Nk) −9(k −1);
3. The executed gadget corresponds to the correct edge and the gadget is executed correctly:
find2j
E (Nk) ∈{9kj′ + 9ij + ι : j′ ∈N, ι ∈{2, 4}} .
If all three conditions are met, then hopk(X)N = 1 if and only if G = C1 from condition 1.
We first show that the base case holds for j = 1. Since i1 > i0, the second-last time 1 appears in the E is
in the final encoding ei1. By the two-case analysis of the ei1 gadget, we validate that hop2(E)Nk = 2 and
conditions (1) and (3) hold. Since ei1 cannot be the first edge encoding appearing in e1 ◦e2 ◦· · · ◦ek, owing
to it following ei0), condition (2) is satisfied.
Suppose that the inductive hypotheses holds up to j <
k
2. Then, we argue that it holds for j + 1.
Since hop2j(E)Nk = j + 1 (from condition (1)) and find2j
E (Nk) resides at the left-most side of the gadget
for eij (from condition (3)), the two subsequent findE iterations must occur in the gadget eij+1. Because
find2j
E (Nk) ≥9k(k −j) (from condition (2)), all edges appear in the k gadgets to the left of find2j
E (Nk),
and all other edges (including eij+1) must occur before the next occurrence of eij. Thus, the two hops
occur in the eij+1 gadget (within distance 9(k −1)) and results in a properly positioned find2j+2
E
(Nk) with
hop2j+2(E)Nk = nextj+1(1, v∗)1.
Since an MPC protocol can convert G to X using a constant number of layers, and because π′ outputs
T(X)N = 1 if and only if G = C1, we can construct a protocol of π by simulating π′. Because the protocol π
uses s = O(k1−ϵ/2) local memory and q = O(k2/ξ) machines, Conjecture 2.4 implies that the existence of T
requires L = Ω(log k).
E
Proofs from Section 5
E.1
Multi-player pointer chasing communication complexity
We introduce the multi-pass multi-player blackboard communication model studied by Guha and McGregor
(2009) and Assadi and N (2021) to prove lower bounds for multi-pass streaming algorithms. A protocol in this
model specifies how k players, each possessing a portion of a shared input, can jointly compute a function on
the input over the course of R rounds of communication. In each round, all players take turns to broadcast
an s-bit message to all other players. We provide a formal definition of the model as described in Section 6 of
Assadi and N (2021).
Definition E.1. A k-player R-round s-space sequential blackboard communication protocol includes k players
P1, . . . , Pk. On input Z that can be partitioned into (Z1, . . . , Zk), each player Pj is provided with its respective
Zj. In each round, players communicate via a shared blackboard. That is, in round r and in order Pk, . . . , P1,
each player Pj writes a message Πr
j ∈{0, 1}s on the blackboard (which can be viewed by all players) as a
potentially randomized function of input Zj and all information on the blackboard. After the conclusion of R
rounds, the final message ΠR
1 is the output of the protocol.
Assadi and N (2021) proves a lower bound on the round complexity necessary to solve the well-studied
multi-party pointer chasing problem of Nisan and Wigderson (1993). We present the problem as defined by
Assadi and N (2021).
32

Definition E.2. For q, k ∈Z+, let an (q, k)-layered graph G = (V, E) have disjoint vertex layers V1, . . . , Vk+1
with V = V1 ∪· · · ∪Vk+1 and each |Vj| = q and edge layers E1, . . . , Ek with E = E1 ∪· · · ∪Ek and each Ej
being a perfect matching between Vj and Vj+1. The pointer chasing task is provides a (q, k)-layered graph G,
an arbitrary v ∈V1, and an arbitrary equipartition V 1
k+1 and V 2
k+1 of Vk+1 as input and asks whether v is
connected to a vertex in V 1
k+1 or V 2
k+1.
Assadi and N (2021) give the following lower bound.
Proposition E.3 (Proposition 4.12 of Assadi and N, 2021). Consider a k-player R-round s-space sequential
blackboard protocol that solves the (q, k)-pointer chasing task where each player Pj is provided with the
matching Ej and v and V 1
k+1, V 2
k+1 are globally known. Then, the protocol succeeds with probability at least 2
3
only if R ≥k or s = Ω( q
k5 ).
All of the lower bounds in Section 5 are most naturally proved by reducing from hopk, rather than
pointer chasing. So we first prove a lower bound for hopk using the lower bound for pointer chasing from
Proposition E.3.
Proposition E.4. Consider a k-player R-round s-space sequential blackboard protocol that computes
hopk(X)N on any X ∈ΣN for Σ = [2q + 2] with q =
 N
2k

where each player Pj is provided with
Xj := (X2(k−j)q+1, . . . , X2(k−j+1)q), except for P1, who is given X1 := (X2(k−1)q+1, . . . , XN). Then, the
protocol succeeds with probability at least 2
3 only if R ≥k or s = Ω( N
k6 ).
Proof. Assuming the existence of a k-player R-round s-space sequential blackboard protocol for hopk(X)N
as described above, we design a protocol for solving (q, k)-pointer chasing with R rounds and s-size messages.
The claimed lower bound will then follow by Proposition E.3.
Consider any pointer chasing input with universally known V1, . . . , Vk+1, v ∈V1, and V 1
k+1 and V 2
k+1, and
each player Pj knowing matching Ej. We recursively define v1, . . . , vk +1 such that v1 = v and (vj, vj+1) ∈Ej,
noting that the output hinges on whether vk+1 ∈V 1
k+1.
Without loss of generality, let v = 1 and
Vj =
(
{1, . . . , q}
if j is odd,
{q + 1, . . . , 2q}
if j is even.
Each player independently determines their substring Xj of a input X to hopk before running the aforemen-
tioned protocol:
• Player P1 encodes X1 by letting XN = s = 1 and for any i ∈1, . . . , 2q, letting
X1
i =
(
i+1
2
∈V1
if i is odd,
i′ ∈V2
if i is even, ( i
2, i′) ∈E1.
This ensures that that every integer in {1, . . . , 2q} appears exactly once in X1
1, . . . , X1
2q, which in turn
guarantees that find1
X(N) = (k −1 + 1)q + 2 and that Xfind1
X(N) = v2 where (1, i′) ∈E1.
• For any j ∈{2, . . . , k −1}, player Pj encodes Ej as Xj as follows.
If j is odd, then for every
i ∈{1, . . . , 2q},
Xj
i =
(
i+1
2
∈Vj
if i is odd,
i′ ∈Vj+1
if i is even, ( i
2, i′) ∈Ej.
Alternatively, if j is even,
Xj
i =
(
q + i+1
2
∈Vj
if i is odd,
i′ ∈Vj+1
if i is even, ( i
2, i′) ∈Ej.
33

Since every odd token corresponds to a vertex in Vj and each subsequent token corresponds to the
vertex it’s connected to by Ej, we can ensure that for every i ∈[2q]:
(X2(k−j+1)+i, Xfind1
X(2(k−j+1)+i)) ∈Ej.
Hence, it follows inductively that Xfindj
X(N) = vj+1.
• Player Pk encodes Xk if k is odd by letting
Xk
i = Xi =





i+1
2
∈Vk
if i is odd,
2q + 1
if i is even, ( i
2, v) ∈Ek, and v ∈V 1
k+1,
2q + 2
if i is even, ( i
2, v) ∈Ek, and v ∈V 2
k+1.
Likewise, if k is even,
Xk
i = Xi =





q + i+1
2
∈Vk
if i is odd,
2q + 1
if i is even, ( i
2, v) ∈Ek, and v ∈V 1
k+1,
2q + 2
if i is even, ( i
2, v) ∈Ek, and v ∈V 2
k+1.
These jointly ensure that
hopk(X)N = Xfindk
X(N) =
(
2q + 1
if vk+1 ∈V 1
k+1,
2q + 2
if vk+1 ∈V 2
k+1.
Therefore, by formatting E1, . . . , Ek appropriately as X, running the protocol for hopk(X)N, and observing
that the final output of player P 1 is 2q + 1 if and only if vk+1 ∈V 1
k+1, there exists a k-player R-round s-space
protocol for pointer chasing. Hence, by Proposition E.3, the protocol for hopk(X)N must use R ≥k rounds
or s = Ω( N
k6 ) space.
E.2
Proofs of Section 5.2
Corollary 5.2. A multi-layer RNN of depth L and width m as above with YN = hopk(X)N satisfies either
L ≥k or m = Ω( N
k6 ).
Proof. Suppose there exists a multi-layer RNN computing output Y with YN,1 = hopk(X)N from input X
with intermediate states Z1, . . . , ZL−1 and hidden states H1, . . . , HL. For any ℓ∈[L] and i ≤i′, note that
Zℓ
i , . . . , Zℓ
i′ can be determined exactly from Hℓ
i−1 and Zℓ−1
i
, . . . , Zℓ−1
i′
. Given this RNN, we provide a multi-
player blackboard communication protocol for solving hopk(X)N under the input model of Proposition E.4.
In round r, we assume inductively that each player Pj knows Zℓ−1,j = (Zℓ−1
2(k−j)q+1, . . . , Zℓ−1
2(k−j+1)q),
except for P1, who knows Zℓ−1,1 = (Zℓ−1
2(k−1)q+1, . . . , Zℓ−1
N
). In descending order, each player Pj computes
Zℓ,j and Hℓ
2(k−j+1)q—writing the latter on the blackboard—from Zℓ−1,j and Hℓ
2(k−j)q,which was written on
the blackboard by the previous player. Thus, player P 1 after round L knows and outputs ZL
N,1 = YN,1 =
hopk(X)N, which provides an L-round protocol m-space protocol.
So the claimed lower bounds on width and depth follow from Proposition E.4.
E.3
Proofs of Section 5.3
Corollary 5.3. Any T ∈KernelFormerN
m,m′,L,H with T(X)N = hopk(X)N satisfies either L ≥k or mm′Hp =
Ω( N
k6 ).
Proof. Under the distribution of input X = (X1, . . . , Xk) to players P1, . . . , Pk stipulated in the statement
of Proposition E.4, we explain how the players can all compute the outcome of a single layer of H-headed
34

kernelized attention in a single round of a blackboard protocol. It is immediate that a depth L network can
be simulated in L rounds.
On input X, consider H kernelized self-attention units with embeddings (Q′
1, K′
1, V1), . . . , (Q′
H, K′
H, VH)
and output MLP ψ. Each player Pj immediately computes its embeddings (Q′
h(Xj), K′
h(Xj), Vh(Xj))h∈[H],
followed by (K′
h(Xj)TVh(Xj)) ∈Rm′×m for each h ∈[H]. Because the object is to compute for each h
ψ(Q′
h(X)K′
h(X)TVh(X)) = ψ(Q′
h(X)
k
X
j=1
K′
h(Xj)TVh(Xj)),
each player writes their (K′
h(Xj)TVh(Xj))h∈[H] using message size s = Θ(mm′Hp). Each can then construct
K′
h(X)TVh(X)) by reading the board, and use it to compute its respective outputs without requiring
supplemental communication.
Hence, T (and thus hopk(X)N) can be simulated using an L-round blackboard protocol with message
size s = Θ(mm′Hp), and the corollary follows from Proposition E.4.
Corollary 5.4. Any T ∈Λw,g-AttnN
m,L,H with T(X)N = hopk(X)N satisfies either L ≥k or (w+ N
gk)mHp =
Ω( N
k6 ).
Proof. As in the proof of Corollary 5.3, we explain how each player can compute their respective outputs of a
single unit of self-attention masked by Λw,g.
To compute the output corresponding to Xi, note that it is necessary to only know the embeddings
corresponding to Xi−w, Xi−w+1, . . . , Xi+w and Xg, X2g, . . . , X⌊N/g⌋g. Thus, player Xj can compute the
outputs of all of their inputs Xj = (X2(k−j)q+1, . . . , X2(k−j+1)q) given access to
X2(k−j)q+1−w, . . . , X2(k−j)q, X2(k−j+1)q+1, . . . , X2(k−j+1)q+w,
as well as Xg, X2g, . . . , X⌊N/g⌋g.
Therefore, the protocol can be simulated if each player Xj writes inputs
X2(k−j)q+1, . . . , X2(k−j)q+w, X2(k−j+1)q−w+1, . . . , X2(k−j+1)q ∈Rm,
in addition to all Xi ∈Xj such that i ≡0 (mod g). This can be accomplished by a protocol where each
player writes s = O((w + N
gk)mp) bits of information on the blackboard.
By repeating this protocol in parallel for every head and sequentially for every layer, T and hopk(X)N
can be simulated, and hence the claim follows from Proposition E.4.
E.4
Proofs of Section 5.4
Corollary 5.6. Any T ∈MaskTransformerN+NCoT
m,1,H
that computes hopk(X)N with NCoT tokens of chain-of-
thought requires either NCoT ≥k or mHp = Ω( N
k6 ).
Proof. We reduce to Proposition E.4. Consider some input X ∈RN partitioned into X1, . . . , Xj as specified
by the proof of Proposition E.4 with chain-of-thought XCoT and hopk(X)N determined by some masked
transformer T.7 Suppose T has embeddings (Qh, Kh, Vh)h∈[H] and output MLP ψ. We provide an (NCoT +1)-
round blackboard protocol to compute hopk(X)N from X.
Suppose in the rth round of the protocol, all players know XCoT,1, . . . , XCoT,r−1 and aim to compute
T(X ◦XCoT)N+r−1 =
(
XCoT,r
if r ≤NCoT
hopk(X)N
if r = NCoT + 1
= ψN+r−1
 
XN+r−1 +
H
X
h=1
PN+r−1
i=1
exp(Qh
N+r−1(XN+r−1)TKh
i (Xi)T)V h
i (Xi)
PN+r−1
i=1
exp(Qh
N+r−1(XN+r−1)TKh
i (Xi))
!
.
7We abuse notation to index XN+i = XCoT,i and let Xi ∈Xj be true if i ∈{2(k −j)q + 1, . . . , w(k −j + 1)q}.
35

If we let
Sr,h,j =
X
Xi∈Xj
exp(Qh
N+r−1(XN+r−1)TKh
i (Xi)T)V h
i (Xi) ∈Rm,
Sr,h,CoT =
N+r−1
X
i=N+1
exp(Qh
N+r−1(XN+r−1)TKh
i (Xi)T)V h
i (Xi) ∈Rm,
Zr,h,j =
X
Xi∈Xj
exp(Qh
N+r−1(XN+r−1)TKh
i (Xi)T) ∈R,
Zr,h,CoT =
N+r−1
X
i=N+1
exp(Qh
N+r−1(XN+r−1)TKh
i (Xi)T) ∈R,
then we observe that
T(X ◦XCoT)N+r−1 = ψN+r−1
 
XN+r−1 +
H
X
h=1
Pk
j=1 Sr,h,j + Sr,h,CoT
Pk
j=1 Zr,h,j + Zr,h,CoT
!
.
Each player Pk computes (Sr,h,j, Zr,h,j)h∈[H] and writes them on the blackboard with O(mHp)-bit messages.
Since Sr,h,CoT and Zr,h,CoT are known by all players, every player can individually T(X ◦XCoT)N+r−1.
By induction, all players know hopk(X)N after NCoT + 1 rounds. The claim now follows from Proposi-
tion E.4.
F
Proofs of low-level attention constructions
F.1
Hardmax simulation proof of Appendix A.1
Lemma A.2. Let f ∈AttnN
m be a self-attention unit with precision p = Θ(log N) and embedding functions
Q, K, V such that for some fixed 1 ≥ξ = N −O(1) and every X ∈RN×m and i ∈[N]:
A(X)i,i′ ≤max
i′′ A(X)i,i′′ −ξ, ∀i′ ̸∈Imax(A(X)i),
where A(X) = Q(X)K(X)T. Then there exists a self-attention unit f ′ ∈AttnN
m with a valid p′-bit implemen-
tation with p′ = O(p) satisfying
f ′(X) = hardmax(A(X))V (X).
Proof. For some p′ = Θ(p + log 1
ξ ) and c = Θ( p′+ζ
ξ
· log N) where ζ is as in Appendix A.1), let f ′ have query
embedding Q′(X) = cQ(X) and identical key K and value V embeddings as f. Therefore, by construction,
these embeddings can be written with precision p′ = O(ln(c) + p) = O(log 1
ξ + log log N + p) = O(p).
Let ˆf ′ be a valid p′-bit implementation of f ′, meaning that the two ∥ˆf ′ −f ′∥∞= O(1/2p+1) (thus ˆf ′
rounds f ′ to p′ bits of precision), and fix some X. We first show that the softmax matrix is sufficiently close
to that of the hardmax and is also a valid p′-bit implementation of the hardmax. Without loss of generality,
let 1 ∈Imax(A(X)i). First, note that
X
i′̸∈Imax(A(X)i)
exp(cA(X)i,i′) ≤
N
exp(cξ) exp(cA(X)i,1) =
1
N O(p′+ζ) exp(cA(X)i,1).
Then,
|softmax(cA(X))i,1 −hardmax(A(X))i,1| =
1
|Imax(A(X)i)| −
exp(cA(X)i,1)
PN
i′=1 exp(cA(X)i,i′)
≤
P
i′̸∈Imax(A(X)i) exp(cA(X)i,i′)
|Imax(A(X)i)| exp(cA(X)i,1)
=
1
N Ω(p′+ζ) .
36

Likewise, for any i′′ ̸∈Imax(A(X)i):
|softmax(cA(X))i,i′′ −hardmax(A(X))i,i′′| ≤
exp(cA(X)i,i′′)
PN
i′=1 exp(cA(X)i,i′)
=
1
N Ω(p′+ζ) .
Therefore,
∥softmax(cA(X))i −hardmax(cA(X))i∥2 ≤
√
N·max
i′′ |softmax(cA(X))i,i′′ −hardmax(cA(X))i,i′′| =
1
N Ω(p′+ζ) .
We conclude that the approximation is sufficiently close, meaning it is O(1/2p′), whereby it is exact after
rounding:



 ˆf ′(X) −hardmax(Q(X)K(X)T)V (X)



∞≤


f ′(X) −hardmax(Q(X)K(X)T)V (X)


∞+



 ˆf ′(X) −f ′(X)



∞
≤max
i,j
softmax(cA(X))T
i V (X)·,j −hardmax(A(X))T
i V (X)·,j
 + O
 1
2p′

≤max
i,j


softmax(cA(X))T
i −hardmax(A(X))T
i


2 ∥V (X)·,j∥2 + O
 1
2p′

≤
1
N Ω(p′+ζ) ·
√
N · N ζ + O
 1
2p′

= O
 1
2p′

.
Therefore, ˆf ′ is a valid p′-bit implementation of hardmax(Q(X)K(X)T)V (X).
F.2
Constructions for Appendix B.1
Proposition B.1. For any b ≤N and d, there exists a self-attention unit sparsePropagateQ,d ∈AttnN
m,p for
m = d+O(Q log N) and p = O(log N), which, given any input X with Xi = (zi, Si,⃗0) ∈Rd×
[N]
≤Q

×{0}m−Q−d
such that bi = |{Sj ∋i : j ∈[N]}| ≤Q for all i, has output sparsePropagateQ,d(X) satisfying
sparsePropagateQ,d(X)i = 1
bi
X
Sj∋i
zj.
Proof. Following the proof of Theorem 2 of Sanford et al. (2023), there exist p-bit precision vectors u1, . . . , uN ∈
{±1/√m}m and wS with wS ≤2√Q for all S ∈
 N
≤Q

such that
uT
i wS = 1, for all i ∈S
uT
i wS ≤1
2, for all i ̸∈S.
We then design the embeddings of sparsePropagateQ,d with
Q(X)i = (ui, 1),
K(X)i =
(
(wSi, 0)
if i > 0,
(⃗0, 3
4)
if i = 0,
V (X)i =
(
zi
if i > 0,
⃗0
if i = 0.
As a result,
Q(X)T
i K(X)i′ = 1
if i ∈Si′, i′ > 0,
Q(X)T
i K(X)i′ ≤1
2
if i ̸∈Si′, i′ > 0,
Q(X)T
i K(X)0 = 3
4.
37

Hence, the largest inner products for query i correspond to i′ for all Si′ ∋i if any exist, and 0 otherwise.
There exists a margin of at least 1
4 between the largest inner product in each row and all others. By applying
Lemma A.2, we conclude that there exists a self attention unit f ′ with embedding dimension p = Θ(log N)
that computes
f ′(X) = hardmax(Q(X)K(X)T)V (X) = sparsePropagate(X).
F.3
Constructions for Appendix B.2
Lemma B.4. For any MPC protocol π with local memory s and q machines with nin-word inputs, there
exists a transformer init ∈Transformernin,max(nin,q)
s,1,1,din,dout
with din = 1 and dout = s, which, given Input ∈Zn
2p, has
output satisfying init(Input) = MachineIn(1).
Proof. Let M = max(nin, q) and Q, K, V : ZM
2p →RM×s be the query, key, and value embeddings of the
attention unit f in init, and let ψ : RM×s →Zs
2p × [N] be its output MLP. Let qin =
 nin
s

denote the number
of machines used to store the inputs.
Let Desti′ =
l
i′
s
m
∈[qin] denote the machine that stores the input token index i′ ∈[nin] in the MPC
protocol, and let
Rcvdi = {(s −1)i + 1, . . . , min(si, nin)}
denote the set of all input tokens indices belonging to MachineIn(1)
i
for machine i ∈[qin].
For each machine i ∈[qin], we define the query embedding as
Q(Input)i =

cos
2πi
M

, sin
2πi
M

, . . . , cos
2πi
M

, sin
2πi
M

.
Likewise, for each token index i′ ∈[nin], the key and value vectors are
K(Input)i′,(2ι−1,2ι) =
(
cos

2π·Desti′
M

, sin

2π·Desti′
M

if i′ ≤nin, i′ ≡ι
(mod s),
(0, 0)
otherwise,
V (Input)i′,(2ι−1,2ι) =
(
(Inputi′, i′)
if i′ ≤nin, i′ ≡ι
(mod s),
(0, i′)
otherwise.
These definitions guarantee that large inner products only occur between machine queries Q(Input)i and
tokens keys K(Input)i′ when Inputi′ is allocated to MachineIn(1)
i . That is,
Q(Input)T
i K(Input)i′ = 1,
if i′ ∈Rcvdi
Q(Input)T
i K(Input)i′ ≤1 −Ω
 1
M 2

,
otherwise.
By applying Lemma A.2 with ξ = Ω( 1
N2 ), there exists some self-attention unit f ′ such that
f ′(Input)i = hardmax(Q(Input)K(Input)T) = (Inputi′, i′)i′∈Rcvdi
|Rcvdi|
.
A proper choice of ψ and an invocation of the definition of MachineIn(1) ensures that init(Input)i =
ψ(f(Input))i = MachineIn(1)
i .
Lemma B.6. For any R-round MPC protocol π with local memory s and q machines with nout-word output,
there exists a transformer final ∈Transformerq,max(nout,q)
s,1,1,din,dout
for din = s and dout = 1, which, given input
X = MachineIn(R), has output final(X) with final(X)i,1 = Outputi ∈Z2p.
38

Proof. This argument inverts that of Lemma B.4, after applying the LocalR to transform MachineIn(R) to
MachineOut(R). Let Q, K, V : ZM
2p →RM×s be the query, key, and value embeddings of the only attention
unit f in final, and let ψ : RM×s →Zs
2p × [N] be its output MLP. Let qout =
 nout
s

denote the number of
machines storing relevant information for the output of the MPC protocol.
For each machine i′ ∈[qout], let
Senti′ = {(s −1)i′ + 1, . . . , min(si′, nout)}
denote the set of all token indices receiving its output. Likewise, for each token index i ∈[nout], let Srci = ⌈i/s⌉
be the machine containing its relevant token. We define Q = Q′ ◦LocalR, K = K′ ◦LocalR, V = V ′ ◦LocalR
as follows.
Q′(MachineOut(R))i,(2ι−1,2ι) =
(
cos

2π⌊Srci⌋
M

, sin

2π⌊Srci⌋
M

if i ≤nout, i ≡ι
(mod s)
(0, 0)
otherwise.
K′(MachineOut(R))i′ =

cos
2πi′
M

, sin
2πi′
M

, . . . , cos
2πi′
M

, sin
2πi′
M

.
V ′(MachineOut(R))i′ = MsgOut(R)
i′ .
Applying Lemma A.2 as before yields
f(MachineIn(R))i =
(
MachineOut(R)
i′
if i ∈Senti′,
0
otherwise.
A properly chosen ψ ensures that final(MachineIn(R))i = ψ(f(MachineIn(R)))i = Outputi.
F.4
Constructions for Appendix D.1
Lemma D.1. For some m ≥d + 2, τ : [N] × Rm →[N], and ρ : Rm →Rd, there exists an attention head
lookUpτ,ρ ∈MaskAttnN
m with precision p = O(log N) and m ≥d+2 satisfying lookUpτ,ρ(X)i,:d = ρ(Xτ(i,Xi)).
Proof. We let V (Xi) = (ρ(Xi),⃗0) and define sinusoidal embeddings Q and K with
Q(X)i =

cos
2πτ(i, Xi)
N

, sin
2πτ(i, Xi)
N

,⃗0

,
K(X)i =

cos
2πi
N

, sin
2πi)
N

,⃗0

.
Note that
Q(X)T
i K(X)i′ = 1,
if τ(i, Xi) = i′,
Q(X)T
i K(X)i′ ≤cos
2π
N

= 1 −Ω
 1
N 2

,
otherwise.
By applying Lemma A.2 with ξ = Ω( 1
N2 ), we conclude that a satisfactory self-attention unit exists.
Lemma D.2. For any finite alphabet Σ, m ≥d + 2, µ1, µ2 : Rm →Σ, and ρ : Rm →Rd, there exists an
attention head lastOccurrenceµ,ρ ∈MaskAttnN
m with precision p = O(log(N |Σ|)) such that,
lastOccurrence(X)i,:d =
(
ρ(⃗0)
if ∀i′ < i : µ1(Xi′) ̸= µ2(Xi),
ρ(Xi′)
if i′ = max {i′ < i : µ1(Xi′) = µ2(Xi)} .
39

Proof. Let N ′ = N|Σ|. We define token embeddings as follows, including start token “dummy embeddings”
as discussed in Appendix A.1.
Q(X)i =

cos
2π(Nµ2(Xi) + i)
N|Σ|

, sin
2π(Nµ2(Xi) + i)
N|Σ|

, 1,⃗0

,
K(X)i =

cos
2π(Nµ1(Xi) + i)
N|Σ|

, sin
2π(Nµ1(Xi) + i)
N|Σ|

, 0,⃗0

,
K(X)0 =

0, 0, cos
2π(N −1
2)
N|Σ|

,⃗0

,
V (X)i = (ρ(Xi),⃗0),
V (X)0 = ⃗0.
Taken together, these embeddings provide the following characterization of the inner products (with causal
masking matrix Γ):
Q(X)T
0 K(X)i′ + Γi,i′ = cos
2π(i −i′)
N|Σ|

if i ≥i′ > 0, µ1(Xi′) = µ2(Xi),
Q(X)T
i K(X)i′ + Γi,i′ ≤cos
2π
N

if i ≥i′ > 0, µ1(Xi′) ̸= µ2(Xi),
Q(X)T
i K(X)i′ + Γi,i′ = −∞
if i < i′,
Q(X)T
i K(X)i + Γi,0 = cos
2π(N −1
2)
N|Σ|

.
As a result, the largest inner product Q(X)T
i K(X)i′ for some i is the largest i′ with µ1(Xi′) = µ2(Xi) if one
exists and i′ = 0 otherwise. Furthermore, there exists a margin of Ω(
1
N2|Σ|2 ) between this inner product and
all others. We conclude by applying Lemma A.2.
G
Further empirical analysis of k-hop induction heads
This appendix presents in-depth explanations of the empirical results of Section 4.2, along with further
experiments. Taken together, these results suggest that the relationship between the number of hops k and
the depth L of transformers trained on the task is well-characterized by the representational thresholds of
Theorem 4.2 and Corollary 4.3; that the construction described in the proof of Theorem 4.2 is attainable by
trained models; and deep models likely exhibit an inductive bias that favors compositional learning rules in
the finite sample regime.
We define our experimental methodology precisely in Appendix G.1 and provide supporting evidence for
our claims in the subsequent sections.
Exponential powers of depth.
Our principal empirical claim is that incrementing the depth L of a
transformer exponentially increases the model’s capabilities to learn k-hop induction heads tasks. We explore
this claim primarily in Appendix G.2, where we compare this empirical claim with the relevant theoretical
results (Theorem 4.2 and Corollary 4.3), which suggest a similar dependence. We further study the impacts
of increasing the embedding dimension m of the transformer in Appendix G.3 and find that doubling the
width is roughly equivalent in performance to incrementing the depth by one.
Empirical Claim G.1. A transformer T ∈MaskTransformerN
m,L,H trained with Adam to solve hopk has
small token-wise classification error if L log(m) = Ω(log k) and large error if L log m = O(log k).
Mechanistic alignment with theoretical construction.
We further demonstrate the empirical salience
of our theoretical construction by conducting a study of the interpretability of learned transformers in
Appendix G.4. This investigation reveals that the attention matrices of sufficiently deep transformers exhibit
40

an implementation of a circuit that relies on the same “doubling” principle of the construction in the proof of
Theorem 4.2. The resulting circuit is comprised of the same intermediate products that are used in that hopk
construction.
Empirical Claim G.2. The outputs of individual attention matrices of a transformer T ∈MaskTransformerN
m,L,H
trained with Adam to solve hopk with L = Ω(log k) and evaluated on input X ∈ΣN (i) correspond to the
findj
X intermediate products of the Theorem 4.2 construction and (ii) demonstrate a “doubling” phenomenon
where the each head layer ℓcorresponds to findj
X for some j = O(2ℓ).
Beneficial inductive biases of depth.
While most of our experiments belong to the “infinite-sample”
regime where new samples are randomly generated on each training step, we also evaluate our models in two
finite-sample regimes in Appendix G.5. We find that a small number of samples is sufficient to approach the
performance of the infinite-sample regime. When the amount of training data is small, we find that deeper
models perform better than shallower models, possibly due to an inductive bias that favors compositional
hypotheses.
Empirical Claim G.3. hopk can be learned in a sample-efficient manner by transformers T ∈MaskTransformerN
m,L,H
trained with Adam with L = Ω(log k). If T overfits to hopk tasks for some k, then increasing the depth L
while holding k fixed leads superior performance.
The experiments detailed here were conducted under limited computational resources. The authors are
interested in future work that would evaluate whether these scaling rules persist on larger architectures and
more complex tasks.
G.1
Experimental details
Task details.
We study a multi-task variant of k-hop induction heads that predicts hopk(X) = (0, hopk(X′))
from input X = (k, X′) for k ∈{0, 1, . . . , kmax}8 and X′ ∈ΣN−1. We refer to this task as multi-hop and
provide the task hyper-parameters in Table 1.
Hyperparameter
Value
Context length N
100
Alphabet size |Σ|
4
Max hops kmax
16
Table 1: Multi-hop task hyper-parameters
We define the distribution Dmulti−hop over labeled samples for the multi-hop task and DX over input
sequences X ∈ΣN−1. We draw a labeled sample (X, hopk(X)) ∼Dmulti−hop by independently sampling
k ∼Unif({0, 1, . . . , kmax}) and X′ ∼DX . Input sequences X′ ∼DX are drawn uniformly from inputs with no
repeating elements. That is, we sample X′
1 ∼Unif(Σ) and each X′
j+1 ∼Unif(Σ \

X′
j
	
). For each k ∈[kmax],
let Dhopk denote the conditional distribution ((k′, X′), (0, hopk′(X′))) ∼Dmulti−hop | (k = k′). Also, let
dom(hopk) = {(k, X′) : Pr [X′ ∼DX ] > 0}.
For Σ := Σ ∪[kmax], we define the n-sample empirical token-wise classification error of a transformer
T : Σ
N →Σ
N on a task hopk as
errn
k(T) = 1
n
n
X
ι=1
1
| {i : hopk(Xι)i ̸=⊥} |
N
X
i=1
1 {T(Xι)i ̸= hopk(Xι)i ̸=⊥} ,
for iid samples (X1, hopk(X1)), . . . , (Xn, hopk(Xn)) ∼Dhopk. We ignore null ⊥outputs of hopk when no
k-hop induction head exists in order to avoid inadvertently over-estimating the performance of transformers
on large k tasks, which have a large fraction of null outputs.
8The task hop0 is simply the identity mapping: hop0(X′) = X′.
41

Training details.
We trained a variety of causally-masked GPT-2 transformers (Radford et al., 2019) from
HuggingFace to solve the multi-hop task. The model has an absolute positional encoding.
The transformers are trained with Adam (Kingma and Ba, 2014) on the cross-entropy loss. In the
infinite-sample regime, we draw 32 new iid samples from Dmulti−hop on each training step. Otherwise, ntrain
samples are drawn before training commences and all samples are rotated through batches, before repeating.
We use the hyper-parameters in Table 2 to train all of the models identified in Table 3.
Hyperparameter
Value
Embedding dimension m
{128, 256}
Depth L
{2, 3, 4, 5, 6}
Number of heads H
{4, 8}
Vocabulary size
30
Activation function
GeLU
Layer norm ϵ
10−5
Training samples ntrain

103, 3 · 103, ∞
	
Learning rate
10−4
Training steps
105
Batch size
32
Table 2: Model and training hyper-parameters
Identifier
Heads H
Embedding dimension m
Depth L
Training samples ntrain
Total parameters
T ∞
4,2
4
128
2
∞
413,440
T ∞
4,3
4
128
3
∞
611,712
T ∞
4,4
4
128
4
∞
809,984
T ∞
4,5
4
128
5
∞
1,008,256
T ∞
4,6
4
128
6
∞
1,206,528
T ∞
8,2
8
256
2
∞
1,613,312
T ∞
8,3
8
256
3
∞
2,403,072
T ∞
8,4
8
256
4
∞
3,192,832
T ∞
8,5
8
256
5
∞
3,982,592
T ∞
8,6
8
256
6
∞
4,772,352
T 3000
4,2
4
128
2
3000
413,440
T 3000
4,3
4
128
3
3000
611,712
T 3000
4,4
4
128
4
3000
809,984
T 3000
4,5
4
128
5
3000
1,008,256
T 3000
4,6
4
128
6
3000
1,206,528
T 1000
4,2
4
128
2
1000
413,440
T 1000
4,3
4
128
3
1000
611,712
T 1000
4,4
4
128
4
1000
809,984
T 1000
4,5
4
128
5
1000
1,008,256
T 1000
4,6
4
128
6
1000
1,206,528
Table 3: Hyper-parameters of all MaskTransformerN
m,L,H trained for the empirical analysis.
Computational resources.
All experiments were run on a 2021 Macbook Pro with an M1 chip.
42

G.2
Exponential increases in k-hop capacity with depth (Empirical Claim G.1;
Figures 6 to 8)
1
2
4
8
16
k
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Error: errk
n(T)
Evaluation of L-depth, 4-headed, infinite-sample intransformers on hopk
L = 2
L = 3
L = 4
L = 5
L = 6
Figure 6: Zoomed in version of Figure 2. Evaluation of transformers errn
k(T ∞
4,L) with depths L ∈{2, 3, 4, 5, 6},
heads H = 4, and embedding dimension m = 128 trained on the multi-hop task. This figure plots errn
k(T ∞
4,L)
on n = 100 samples as a function of k for each choice of L.
We visualize the relationship between the depth L of a transformer and the largest k such that errn
k(T)
is small in Figure 6, Figure 7, and Figure 8. We exhibit the relationship in its simplest form by considering
transformers with heads H = 4, embedding dimension m = 128, and new training samples on every epoch.
The figures provide alternate views of errn
k(T ∞
4,L) for each L ∈{2, 3, 4, 5, 6} with n = 100 samples for each
k ∈[kmax].
Together, these plots illustrate a sharp phase transition when D = ⌊log2 k⌋+ 2, which identically matches
the depth scaling in Theorem 4.2. Increasing the depth of a transformer by one approximately doubles
the number of values k ∈[kmax] with bounded error. For instance, following the theoretical and empirical
intuition of Bietti et al. (2023), the depth L = 2 transformer T ∞
4,2 succeeds in solving the standard induction
heads task, but attains at least 10% error on all other tasks. Likewise, a depth L = 3 model has error bounded
by 1% for k ∈{1, 2}, which increases rapidly for larger values of k.
This doubling phenomenon suggests that simple compositional tasks with a larger number of compositions
than the depth of the model are easily learnable if the model can employ a doubling trick, similar to the one
used in the proof of Theorem 4.2. This relationship between compositionality and depth reflects the results
of Zhang et al. (2023), where the learnable task complexity also scales super-linearly in depth.
Given the lower bounds of Corollary 4.3, one may ask why models with depth L < ⌊log2 k⌋achieve
non-trivial success on hopk tasks that cannot be represented in a compositional manner. There are several
relevant explanations:
1. In these experiments, the embedding dimension m = 128 is actually larger than the context N = 100,
which may enable the model to memorize more of its preceding samples and offload logical work to the
MLP, rather than executing a pointer-doubling strategy. While practical models regularly have the
opposite (and our theoretical results are oriented around that parametric scaling), we used a larger
43

2
3
4
5
6
Depth L
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Error: errk
n(T)
Evaluation of L-Depth, 4-headed, infinite-sample transformers on hopk
k = 1
k = 2
k = 3
k = 4
k = 5
k = 6
k = 7
k = 8
k = 9
k = 10
k = 11
k = 12
k = 13
k = 14
k = 15
k = 16
Figure 7: Alternate view of Figure 6 including errn
k(T ∞
4,L) plotted as a function of L for each k.
m than is necessary for representational purpose to improve the optimization landscape and speed
convergence.
2. This is made further plausible by the small alphabet size |Σ| and randomly drawn sequences X′, which
place effective bounds on how much look-back from each token i is necessary to compute hopk(X)i.
Nonetheless, these results provide strong support that models are substantially easier to train to low
classification error in the regime where the depth is sufficient to implement a pointer-doubling construction.
In the following subsection, we further investigate this phenomenon by examining the intermediate attention
matrices produced by trained models.
44

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
k
2
3
4
5
6
Depth L
0.01
0.14
0.35
0.42
0.54
0.59
0.62
0.66
0.69
0.69
0.71
0.72
0.73
0.73
0.74
0.74
0.003 0.008 0.048
0.15
0.28
0.36
0.42
0.46
0.52
0.57
0.6
0.64
0.67
0.67
0.69
0.71
0.001 0.003 0.005 0.015 0.034 0.062
0.11
0.22
0.28
0.36
0.4
0.47
0.53
0.53
0.58
0.61
0.001 0.001 0.001 0.003 0.012 0.015 0.017 0.037 0.058
0.1
0.15
0.22
0.28
0.34
0.38
0.41
0
0
0.001 0.002 0.003 0.003 0.007 0.006 0.007
0.01
0.011 0.012 0.021 0.027 0.035 0.062
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Figure 8: Alternate views of Figure 6 including errn
k(T ∞
4,L) as a table with one cell for each (L, k) pair.
G.3
Width variation (Empirical Claim G.1; Figure 9)
While the primary focus of these empirical results and the paper as a whole is on the role of depth in the
ability of transformer to learn parallelizable and compositional tasks, we also aim to understand the interplay
of depth and width in learning the multi-hop task. Here, we contrast the previous transformers T ∞
4,L with
models T ∞
8,L that have more heads (H = 8) and larger embedding dimensions (m = 256). We plot the
classification errors of all 10 architectures over 16 hopk sub-tasks in Figure 9.
Here, we observe a rough correspondence in performance between the transformers T ∞
H,L and T2H,L−1 and
the same doubling phenomenon as is evident models with H = 4 heads. That is, while increasing the width
improves the classification error of learned models, it does so in a far less parameter-efficient manner than
incrementing the depth. As mentioned before, the relative success of wide and shallow transformers is likely
contingent on the relatively short context length N and alphabet size |Σ|. However, these results still suggest
an important role for wider models to play beyond representational capabilities of transformers.
45

1
2
4
8
16
k
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Error: errk
n(T)
Evaluation of L-depth, H-headed, infinite-sample intransformers on hopk
L = 2, H = 4
L = 2, H = 8
L = 3, H = 4
L = 3, H = 8
L = 4, H = 4
L = 4, H = 8
L = 5, H = 4
L = 5, H = 8
L = 6, H = 4
L = 6, H = 8
Figure 9: Comparison between the errors errn
k(T ∞
H,L) of transformers with embedding dimension and heads
(m, H) = (4, 128) (dashed line, same plots as Figure 6) and (m, H) = (8, 256) (solid line) trained on the
multi-hop task, evaluated on n = 100 samples per hopk task.
46

G.4
Mechanistic alignment with theoretical construction (Empirical Claim G.2,
Figures 10 to 15)
We use standard attention-based interpretability techniques to better understand what particular logical
circuits are implemented by transformers trained to solve the multi-hop task. By qualitatively inspecting
the attention matrices produced by trained models and by measuring the alignment between those inner
products and partial solutions findj of hopk, we uncover a striking correspondence between the behaviors
of the trained models and the transformer construction designed in the proof of Theorem 4.2. We further
observe that trained transformers with high accuracy have “decisive” self-attention units with particularly
strong correlations to some findj intermediate, while poorly performing models have less predictable attention
activations.
For a fixed trained model T ∈TransformerN
m,L,H, we let Aℓ,h[T](X) represent the output of the hth self-self
attention matrix in the ℓth layer for h ∈[H] and ℓ∈[L], evaluated at some input X ∈dom(hopk). That is,
we let
Aℓ,h[T](X) = softmax
Qℓ,h(Xℓ−1)Kℓ,h(Xℓ−1)T + Γ

∈RN×N,
where Xℓ−1 is the intermediate state representing the output of layer ℓ−1 of T on input X and Γ is the
causal masking matrix. Each row i in the matrix represents the coefficients of the convex combination of
value vectors affiliated with each query, which can be used as a signifier of which embeddings i receives
information from.
Visualization of findj alignment for hop16 and depth L = 6 (Figure 10).
The outputs of self-attention
matrices are often highly structured matrices that reveal which relationships between tokens are encoded and
how information is shared within the model (Li and McClelland, 2022; Clark et al., 2019; Rogers et al., 2021).
We plot several self-attention matrices associated with a depth L = 6, heads H = 4 transformer trained in
the infinite-sample regime and evaluated on a single sample X ∈dom(hop16) in Figure 10.
By looking at the six self-attention matrices, one can infer that all heads are “decisive” and obtain nearly
all of their relevant information from a single value embedding, rather than averages of a large number
of embeddings. The top-left self-attention matrix, which belongs to the first self-attention head, clearly
associates elements with their predecessors, which is identical the to the function of our lookUp attention
head in the first layer of the hopk construction of Theorem 4.2.
While the roles of the other heads are not immediately obvious, they can be understood by overlaying
colored matrices with non-zero cells at (i, findj
X(i)) for some j ≤k. For instance, the top-right attention matrix
in layer ℓ= 2 corresponds almost exactly with find1
X (as suggested by the second-layer of our construction),
and the others are closely associated with find1
X, find2
X, find3
X, and find8
X for layers ℓ= 3, 4, 5, 6 respectively.
This is a remarkably close correspondence to our construction, which includes a self-attention matrix in the
ℓth layer whose activations correspond to find2ℓ−2
X
.
While not conclusive, this experiment suggests a strong alignment between the behaviors of this particular
transformer and our theoretical construction. This suggests a high likelihood that the transformer successfully
learns to solve hop16 by employing a pointer-doubling primitive. However, these results apply to only a single
model, a single task, and a single input; in the subsequent section, we generalize this interpretability analysis.
Alignment between attention heads and findj for a single hopk sub-task (Figures 11 to 13).
To
broaden and quantify the analysis of the previous section, we measure the extent to which each self-attention
head mimics the functionality of findj, which are partial computations of hopk that are employed in the proof
of Theorem 4.2. We use cell-wise matrix inner products to quantify the strength of correlation between a
self-attention matrix and a fixed function potentially relevant to interpretability.
For two matrices A, B ∈RN×N, let
⟨A, B⟩= ∥A ⊙B∥2
F
∥A∥F ∥B∥F
be their normalized element-wise inner-product, where ∥·∥F is the Frobenius norm and ⊙denotes element-wise
47

= 1, h = 1, find0
X highlighted
= 2, h = 4, find1
X highlighted
= 3, h = 2, find1
X highlighted
= 4, h = 2, find2
X highlighted
= 5, h = 3, find3
X highlighted
= 6, h = 1, find8
X highlighted
Self-attention matrix A , h[T4, 6](X), X
dom(hop16)
Figure 10: The outputs of several internal self-attention matrices Aℓ,h[T ∞
4,6](X) ∈R100×100 of a trained
multi-task transformer of depth D = 6 evaluated on a single sample X ∼Dhop16 are plotted in grayscale. In
each cell, the matrix with non-zero entries (findj
X(i), i)i∈[N] for some j is included in transparent color to
visualize the function of each self-attention unit.
48

multiplication. For some function g : [N] →{0} ∪[N], we let ⟨g, B⟩:= ⟨Ag, B⟩, where
Ag
i,j =
(
1
if g(j) = i,
0
otherwise.
We use this notation to analyze experimentally how closely the self-attention matrices Aℓ,h encode the
intermediate products of the proof of Theorem 4.2, findj
X. For n iid samples X1, . . . , Xn ∈∼Dhopk, let

Aℓ,h, findj
n,k := 1
n
n
X
ι=1
D
findj
Xι, Aℓ,h(Xι)
E
.
Due to the non-negativity of Aℓ,h and findj,

Aℓ,h, findj
n,k ∈[0, 1], and

Aℓ,h, findj
n,k = 1 only if ∀ι ∈[n]:
Aℓ,h(Xι)i,i′ = 1
⇐⇒
findj
Xι(i) = i′.
These inner products make it possible to visualize the strength of correlations of all heads in a particular
model T ∈MaskTransformerN
m,L,H with all target functions findj on a collection of random samples drawn
from some Dhopk. Figure 11 visualizes the functionality of all attention units in the 4-layer, 4-head transformer
T ∞
4,4 when evaluated on the sub-task hop4. The figure gives several clues about how hop4 is successfully
computed by the trained model: the second layer and third layer both utilize find1 to determined find2 jointly
by the end of the third layer. The fourth layer uses the ability to create a stable find2 construction to obtain
find4 and hence hop4.
This plot also indicates the relative stability of this circuit interpretation of the procedure: a large number
of heads are very strongly correlated with find1 or find2 across the 10 samples, which indicates they are likely
utilized consistently to compute those intermediates regardless of input.
Figure 12 is a similar plot for the transformer T ∞
4,6 with depth L = 6, evaluated on the task hop16. The
functionalities of the heads visualized in Figure 10 can be observed in the corresponding inner products. The
collection of all inner products presents further evidence that the pointer-doubling phenomenon occurs in the
trained models, due to the increase in compositions present in the largest inner products of deeper attention
units.
While Figures 11 and 12 showcase the decisive alignment between self-attention heads and particular
partial computations findj in successfully trained models, Figure 13 demonstrates the loss of that decisiveness
in poorly performing transformers. There, we visualize the alignments of the trained depth-4 transformer
T ∞
4,4 evaluated on hop16, in which it attains a 61% token error. While a self-attention units in the second
layer coincides with find1, no strong correlations emerge deeper in the model. Unlike the other figures, the
deeper self-attention units are “indecisive,” lacking any large inner products and failing in particular to
correlate with any highly compositional targets. This provides a visual explanation of the transformer’s
failure, since it lacked the effective representational capacity needed to learn a circuit with consistent and
highly-compositional outputs.9
Alignment between attention heads and findj for all hopk sub-tasks (Figures 14 and 15).
For
an even more global lens on the mechanistic interpretability of these trained models, we visualize how the
maximum inner products of each self-attention unit change for a fixed transformer for different sub-tasks
hopk. Figures 14 and 15 do so for the depth-4 and depth-6 networks respectively. The hue of each cell (and its
numerical label) corresponds to the j∗with the most correlated inner product with corresponding attention
unit Aℓ,h in samples from dom(hopk), and the opacity corresponds to the magnitude of that inner product.
The takeaways of the previous inner product figures are apparent in these: the approximate doubling
for the depth L = 6 transformer can be visualized by the vertically changing opaque colors. Conversely, a
9Since these experiments are in the small alphabet size |Σ| = 4 regime, this task performs better than random guessing due to
inferential capabilities that are are powered by the high embedding dimension and do not require implementing a pointer-chasing
algorithm. We suspect that the “checkerboard” patterns are powered by this inference.
49

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
j
= 1, h = 1
= 1, h = 2
= 1, h = 3
= 1, h = 4
= 2, h = 1
= 2, h = 2
= 2, h = 3
= 2, h = 4
= 3, h = 1
= 3, h = 2
= 3, h = 3
= 3, h = 4
= 4, h = 1
= 4, h = 2
= 4, h = 3
= 4, h = 4
Layer , head h
0.32
0.17
0.1
0.01
0.01
0.32
0.32
0.15
0.08
0.05
0.03
0.02
0.01
0.01
0.04
0.19
0.08
0.08
0.04
0.03
0.01
0.01
0.93
0.77
0.05
0.11
0.02
0.02
0.52
0.04
0.14
0.04
0.04
0.02
0.02
0.01
0.01
0.01
0.8
0.07
0.94
0.01
0.19
0.18
0.15
0.08
0.05
0.02
0.01
0.23
0.09
0.15
0.05
0.04
0.02
0.01
0.18
0.77
0.03
0.8
0.17
0.01
0.93
0.01
0.87
0.04
A , h, findj n, 4 for depth-4 transformer and X
dom(hop4)
0.0
0.2
0.4
0.6
0.8
1.0
Figure 11: Plots of all inner products

Aℓ,h[T ∞
4,4], findj
10,4 for n = 10 samples X1, . . . , X10 ∈dom(hop4) for
the 4-layer transformer T ∞
4,4.
separation can be observed between the tasks where the depth L = 4 transformer performs well and has
“decisive” self-attention units deeper in the network and those where it does not.
Moreover, the figures (especially Figure 15) demonstrate that several self-attention units have a consistent
function among samples from the same task, while adapting in function to different hopk tasks. This is most
apparent in head h = 4 of layer ℓ= 6, where the self-attention head functions as find1, find3, find5 or find7
depending on the complexity of the task.
50

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
j
= 1, h = 1
= 1, h = 2
= 1, h = 3
= 1, h = 4
= 2, h = 1
= 2, h = 2
= 2, h = 3
= 2, h = 4
= 3, h = 1
= 3, h = 2
= 3, h = 3
= 3, h = 4
= 4, h = 1
= 4, h = 2
= 4, h = 3
= 4, h = 4
= 5, h = 1
= 5, h = 2
= 5, h = 3
= 5, h = 4
= 6, h = 1
= 6, h = 2
= 6, h = 3
= 6, h = 4
Layer , head h
0.33
0.33
0.16
0.09
0.05
0.03
0.02
0.01
0.01
0.34
0.01
0.32
0.24
0.08
0.05
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.88
0.06
0.01
0.08
0.22
0.06
0.06
0.02
0.01
0.01
0.92
0.01
0.93
0.93
0.26
0.06
0.07
0.03
0.03
0.03
0.02
0.02
0.02
0.03
0.03
0.03
0.03
0.03
0.03
0.02
0.21
0.14
0.13
0.06
0.04
0.02
0.01
0.01
0.01
0.01
0.93
0.9
0.14
0.11
0.08
0.05
0.03
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.07
0.79
0.06
0.93
0.04
0.81
0.04
0.03
0.89
0.01
0.02
0.9
0.01
0.02
0.07
0.77
0.03
0.02
0.01
0.12
0.01
0.65
0.04
0.03
0.01
0.14
0.74
0.13
0.01
0.01
0.01
0.01
0.04
0.82
0.02
A , h, findj n, 16 for depth-6 transformer and X
dom(hop16)
0.0
0.2
0.4
0.6
0.8
1.0
Figure 12: Plots of all inner products

Aℓ,h[T ∞
4,6], findj
10,16 for n = 10 samples X1, . . . , X10 ∈dom(hop16)
for the 6-layer transformer T ∞
4,6.
51

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
j
= 1, h = 1
= 1, h = 2
= 1, h = 3
= 1, h = 4
= 2, h = 1
= 2, h = 2
= 2, h = 3
= 2, h = 4
= 3, h = 1
= 3, h = 2
= 3, h = 3
= 3, h = 4
= 4, h = 1
= 4, h = 2
= 4, h = 3
= 4, h = 4
Layer , head h
0.32
0.23
0.13
0.01
0.01
0.33
0.21
0.09
0.05
0.03
0.02
0.01
0.01
0.01
0.04
0.22
0.1
0.11
0.06
0.05
0.03
0.02
0.01
0.01
0.92
0.02
0.64
0.05
0.19
0.03
0.05
0.01
0.01
0.01
0.51
0.05
0.17
0.05
0.07
0.03
0.03
0.02
0.02
0.01
0.01
0.01
0.01
0.46
0.29
0.08
0.01
0.68
0.21
0.06
0.01
0.05
0.06
0.15
0.08
0.15
0.07
0.09
0.04
0.03
0.02
0.01
0.01
0.11
0.12
0.1
0.11
0.08
0.06
0.04
0.03
0.02
0.01
0.01
0.02
0.14
0.25
0.21
0.1
0.03
0.01
0.01
0.01
0.01
0.07
0.01
0.16
0.02
0.17
0.03
0.11
0.02
0.05
0.01
0.02
0.61
0.32
0.11
0.03
0.01
0.01
0.03
0.21
0.31
0.01
0.17
0.01
0.06
0.01
A , h, findj n, 16 for depth-4 transformer and X
dom(hop16)
0.0
0.2
0.4
0.6
0.8
1.0
Figure 13: Plots of all inner products

Aℓ,h[T ∞
4,4], findj
10,16 for n = 10 samples X1, . . . , X10 ∈dom(hop16)
for the 4-layer transformer T ∞
4,4.
52

1 (0.00)
2 (0.00)
3 (0.01)
4 (0.01)
5 (0.03)
6 (0.05)
7 (0.09)
8 (0.17)
9 (0.21)
10 (0.26)
11 (0.27)
12 (0.30)
13 (0.33)
14 (0.32)
15 (0.32)
16 (0.32)
k (Error errk
n(Tn
5, 5))
= 1, h = 1
= 1, h = 2
= 1, h = 3
= 1, h = 4
= 2, h = 1
= 2, h = 2
= 2, h = 3
= 2, h = 4
= 3, h = 1
= 3, h = 2
= 3, h = 3
= 3, h = 4
= 4, h = 1
= 4, h = 2
= 4, h = 3
= 4, h = 4
Layer , head h
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
3
3
3
3
3
3
3
3
3
3
5
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
1
1
1
3
3
3
3
3
3
5
5
5
5
5
5
5
1
2
3
2
3
4
5
4
5
6
7
6
7
6
7
8
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
4
4
4
4
6
4
6
6
6
6
argmaxj A , h, findj n, k for depth-4 transformer and X
dom(hopk)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
j
Figure 14:
Plots of all the maximum inner products

Aℓ,h[T ∞
4,4], findj
n,k for n = 10 fixed samples
X1, . . . , X10 ∈dom(hopk) for each k ∈[16] for the 4-layer transformer T ∞
4,4.
The hue corresponds to
the index of the largest inner product j∗= arg maxj

Aℓ,h[T ∞
4,4], findj
n,k, while the opacity is determined by
the magnitude of the correlation.
53

1 (0.00)
2 (0.00)
3 (0.00)
4 (0.00)
5 (0.00)
6 (0.00)
7 (0.01)
8 (0.00)
9 (0.01)
10 (0.01)
11 (0.01)
12 (0.01)
13 (0.01)
14 (0.02)
15 (0.02)
16 (0.03)
k (Error errk
n(Tn
5, 7))
= 1, h = 1
= 1, h = 2
= 1, h = 3
= 1, h = 4
= 2, h = 1
= 2, h = 2
= 2, h = 3
= 2, h = 4
= 3, h = 1
= 3, h = 2
= 3, h = 3
= 3, h = 4
= 4, h = 1
= 4, h = 2
= 4, h = 3
= 4, h = 4
= 5, h = 1
= 5, h = 2
= 5, h = 3
= 5, h = 4
= 6, h = 1
= 6, h = 2
= 6, h = 3
= 6, h = 4
Layer , head h
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
3
2
1
3
3
3
3
3
3
3
3
3
3
3
3
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
3
3
3
3
3
3
5
5
5
5
5
1
1
1
1
1
1
1
1
1
3
3
3
3
3
3
3
1
1
1
1
1
1
1
3
3
3
3
3
3
3
3
3
1
2
1
2
3
2
3
4
5
4
5
6
7
6
7
8
2
1
2
3
2
3
4
5
4
5
6
7
6
7
8
9
2
1
1
1
1
1
1
1
1
3
3
3
3
5
5
5
2
1
1
1
1
3
3
3
3
5
5
5
5
7
7
7
argmaxj A , h, findj n, k for depth-6 transformer and X
dom(hopk)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
j
Figure 15:
Plots of all the maximum inner products

Aℓ,h[T ∞
4,6], findj
n,k for n = 10 fixed samples
X1, . . . , X10 ∈dom(hopk) for each k ∈[16] for the 6-layer transformer T ∞
4,6.
54

G.5
Finite-sample experiments (Empirical Claim G.3; Figures 16 to 19)
While most of our multi-hop experiments reside in the infinite-sample regime (where new samples are
generated for every batch), we also trained several transformers on ntrain ∈{1000, 3000} samples to evaluate
whether generalization is possible in this domain, especially when the number of model parameters far exceeds
the number of training samples. The two training set sizes expose a sharp threshold between two different
generalization modes: low accuracy due to overfitting for most models on most tasks when ntrain = 1000 and
high accuracy approaching the infinite-sample regime when ntrain = 3000.
Figure 16 compares the infinite-sample transformers T ∞
4,L with the 3000-sample models T 3000
4,L . 3000 training
samples are sufficient to obtain comparable (if slightly worse) generalization error rates across model depths
L and task complexities k. This supports a hypothesis that the existence of a small transformer that perfectly
fits the data enables larger transformers to actually realize such architectures in the over-parameterized
regime.
On the other hand, Figure 17 demonstrates that transformers trained on ntrain = 1000 samples suffer
poor performance on most tasks due to overfitting. While all models perform poorly on hopk sub-tasks for
large k, a depth-separation exists for simpler sub-tasks like hop3. This suggests a positive inductive bias of
deep transformers for simple compositional decision rules, which enables far better performance than other
models in the overfitting regime.
To investigate this gap in performance, we contrast the self-attention inner products of depth-4 T 1000
4,4
and
depth-6 T 1000
4,6
on the task hop3 in Figures 18 and 19. The 6-layer model obtains a far superior classification
error on the sub-task, and the interpretability plot establishes a plausible circuit it implements: It uses
self-attention heads with find1 functionality consecutively in layers 4, 5, and 6, which enables the robust
retrieval of find3 and hop3. On the other hand, the 4-layer plot exhibits poor performance and only has two
layers with find1 functionality; this justifies the relatively strong performance of T 1000
4,4
on hop2 and its poor
performance on hop3.
While neither model learns any kind of pointer-doubling construction, the 6-layer model is still able to
learn a simple construction of hop3 that the 4-layer model misses. The representational suitability of deeper
models to compositional reasoning may thus provide a favorable inductive bias for learning the task in a
setting with little data.
55

1
2
4
8
16
k
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Error: errk
n(T)
Evaluation of L-depth, 4-headed, 3000-sample intransformers on hopk
L = 2, n = 3000
L = 2, n =
L = 3, n = 3000
L = 3, n =
L = 4, n = 3000
L = 4, n =
L = 5, n = 3000
L = 5, n =
L = 6, n = 3000
L = 6, n =
Figure 16: Comparison between the errors errn
k(T n
4,L) of transformers trained in the infinite sample regime
(dashed line) and on ntrain = 3000 samples (solid line) on the multi-hop task, evaluated on n = 100 samples
per hopk task.
1
2
4
8
16
k
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Error: errk
n(T)
Evaluation of L-depth, 4-headed, 1000-sample intransformers on hopk
L = 2, n = 1000
L = 2, n =
L = 3, n = 1000
L = 3, n =
L = 4, n = 1000
L = 4, n =
L = 5, n = 1000
L = 5, n =
L = 6, n = 1000
L = 6, n =
Figure 17: Comparison between the errors errn
k(T n
4,L) of transformers trained in the infinite sample regime
(dashed line) and on ntrain = 1000 samples (solid line) on the multi-hop task, evaluated on n = 100 samples
per hopk task.
56

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
j
= 1, h = 1
= 1, h = 2
= 1, h = 3
= 1, h = 4
= 2, h = 1
= 2, h = 2
= 2, h = 3
= 2, h = 4
= 3, h = 1
= 3, h = 2
= 3, h = 3
= 3, h = 4
= 4, h = 1
= 4, h = 2
= 4, h = 3
= 4, h = 4
Layer , head h
0.15
0.09
0.1
0.08
0.07
0.06
0.05
0.05
0.04
0.04
0.03
0.03
0.03
0.02
0.02
0.02
0.31
0.06
0.04
0.03
0.02
0.02
0.02
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.04
0.04
0.03
0.03
0.03
0.02
0.02
0.02
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.32
0.07
0.05
0.04
0.03
0.03
0.02
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.22
0.1
0.05
0.04
0.03
0.02
0.01
0.01
0.01
0.09
0.12
0.07
0.09
0.06
0.06
0.05
0.05
0.05
0.04
0.04
0.04
0.03
0.03
0.03
0.03
0.28
0.11
0.12
0.08
0.07
0.05
0.05
0.04
0.03
0.03
0.02
0.02
0.02
0.02
0.02
0.02
0.31
0.13
0.11
0.06
0.05
0.03
0.02
0.02
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.19
0.13
0.12
0.09
0.07
0.05
0.04
0.03
0.02
0.02
0.01
0.01
0.01
0.01
0.05
0.2
0.06
0.07
0.03
0.02
0.01
0.01
0.01
0.01
0.88
0.06
0.01
0.86
0.07
0.01
0.85
0.09
0.01
0.61
0.04
0.12
0.02
0.03
0.01
0.01
0.33
0.06
0.17
0.06
0.08
0.04
0.04
0.03
0.02
0.01
0.01
0.01
0.03
0.4
0.02
0.09
0.02
0.03
0.01
0.01
A , h, findj n, 3 for depth-4 transformer and X
dom(hop3), trained on ntr = 1000 samples
0.0
0.2
0.4
0.6
0.8
1.0
Figure 18: Plots of all inner products

Aℓ,h[T 1000
4,4 ], findj
10,3 for n = 10 samples X1, . . . , X10 ∈dom(hop3)
for the 4-layer transformer T 1000
4,4 .
57

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
j
= 1, h = 1
= 1, h = 2
= 1, h = 3
= 1, h = 4
= 2, h = 1
= 2, h = 2
= 2, h = 3
= 2, h = 4
= 3, h = 1
= 3, h = 2
= 3, h = 3
= 3, h = 4
= 4, h = 1
= 4, h = 2
= 4, h = 3
= 4, h = 4
= 5, h = 1
= 5, h = 2
= 5, h = 3
= 5, h = 4
= 6, h = 1
= 6, h = 2
= 6, h = 3
= 6, h = 4
Layer , head h
0.33
0.04
0.03
0.02
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.24
0.14
0.11
0.09
0.07
0.06
0.05
0.04
0.04
0.03
0.03
0.02
0.02
0.02
0.02
0.02
0.26
0.09
0.07
0.06
0.05
0.05
0.04
0.03
0.02
0.02
0.02
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.18
0.12
0.09
0.06
0.05
0.04
0.03
0.03
0.02
0.02
0.02
0.02
0.02
0.02
0.02
0.02
0.32
0.13
0.12
0.06
0.05
0.04
0.03
0.02
0.02
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.26
0.15
0.09
0.06
0.04
0.02
0.02
0.01
0.01
0.01
0.16
0.1
0.11
0.08
0.07
0.06
0.05
0.05
0.04
0.04
0.03
0.03
0.03
0.03
0.02
0.02
0.15
0.14
0.04
0.03
0.01
0.01
0.25
0.09
0.06
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.32
0.13
0.11
0.06
0.05
0.03
0.02
0.02
0.02
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.34
0.13
0.11
0.08
0.06
0.05
0.04
0.03
0.02
0.02
0.02
0.02
0.01
0.01
0.01
0.01
0.01
0.93
0.01
0.92
0.02
0.13
0.19
0.09
0.08
0.04
0.03
0.02
0.01
0.01
0.01
0.42
0.08
0.1
0.03
0.03
0.02
0.01
0.01
0.01
0.93
0.02
0.91
0.04
0.9
0.04
0.92
0.03
0.11
0.07
0.16
0.07
0.09
0.05
0.04
0.03
0.02
0.02
0.01
0.01
0.01
0.01
0.91
0.03
0.12
0.55
0.04
0.1
0.02
0.02
0.01
0.01
0.01
A , h, findj n, 3 for depth-6 transformer and X
dom(hop3), trained on ntr = 1000 samples
0.0
0.2
0.4
0.6
0.8
1.0
Figure 19: Plots of all inner products

Aℓ,h[T 1000
4,6 ], findj
10,3 for n = 10 samples X1, . . . , X10 ∈dom(hop3)
for the 6-layer transformer T 1000
4,6 .
58