Holographic description of Narain CFTs and their code-based ensembles

We provide a precise relation between an ensemble of Narain conformal field theories (CFTs) with central charge $c=n$, and a sum of $(U(1) \times U(1))^n$ Chern-Simons theories on different handlebody topologies. We begin by reviewing the general relation of additive codes to Narain CFTs. Then we describe a holographic duality between any given Narain theory and a pure Chern-Simons theory on a handlebody manifold. We proceed to consider an ensemble of Narain theories, defined in terms of an ensemble of codes of length $n$ over ${\mathbb Z}_k \times {\mathbb Z}_k$ for prime $k$. We show that averaging over this ensemble is holographically dual to a level-$k$ $(U(1) \times U(1))^n$ Chern-Simons theory, summed over a finite number of inequivalent classes of handlebody topologies. In the limit of large $k$ the ensemble approaches the ensemble of all Narain theories, and its bulk dual becomes equivalent to"U(1)-gravity"- the sum of the pertubative part of the Chern-Simons wavefunction over all possible handlebodies - providing a bulk microscopic definition for this theory. Finally, we reformulate the sum over handlebodies in terms of Hecke operators, paving the way for generalizations.

C Narain c = 2 theories 43 C.1 All even self-dual n = 2 codes over Z p × Z p 44 C.2 Hecke operators and triality 44 C.3 Averaging over the moduli space 45 C.4 Large-p limit 48 1 Introduction In recent years, it has become evident that certain gravitational theories in anti-de Sitter (AdS) space are dual to ensemble averages, rather than to individual quantum field theories. A general argument for requiring an ensemble to describe gravitational bulk theories is based on the presence of bulk geometries with several disconnected boundaries [1], known as "wormholes". If the gravitational action of such configurations is non-trivial, then the dual field theory will not factorize on disconnected manifolds, necessitating an ensemble interpretation. The first explicit example of such a duality arose in 2d JT gravity, which was found to be dual to an average over an ensemble of quantum-mechanical systems [2]. In one dimension higher, an intriguing example that motivated our study is provided by a theory called "U(1) gravity", which is formulated as a sum over handlebody geometries in the bulk, and is dual to an average over the moduli space of Narain CFTs [3,4] (see also [5][6][7][8][9][10][11][12][13][14][15][16][17] for further developments). Yet the original example of a holographic correspondence, between the N = 4 supersymmetric Yang-Mills theory and type IIB string theory on AdS 5 × S 5 [18], has so far evaded an ensemble interpretation. This raises the question: when does an ensemble of field theories admit a holographic interpretation? In particular, can a finite ensemble have a gravitational dual, and which bulk geometries need to be summed over in this case?
In this paper, we address the latter question by studying finite ensembles of Narain theories composed of "code CFTs", which were introduced in [19][20][21]. We find that they are dual to a (U(1) × U(1)) n Chern-Simons theory of finite level, summed over a finite number of inequivalent handlebody topologies.
The relation between error-correcting codes and CFTs goes back all the way to the Golay code, which is associated with the Leech lattice, and which led to the discovery of the Monster CFT [22], followed by other developments connecting codes and chiral CFTs [23][24][25][26][27][28]. Motivated by these developments, as well as by the emergence of quantum error correction in the context of bulk reconstruction [29], two of us proposed a connection between quantum codes and non-chiral CFTs in [19]. Our work led to further activity connecting codes and CFTs, with applications to the modular bootstrap program and beyond [6,20,21,[30][31][32][33][34][35][36][37][38][39][40][41][42][43]. Ensembles of code CFTs were found in [6,21] to be self-averaging and to exhibit a large spectral gap, suggesting a possible holographic interpretation and motivating the current study.
We first consider the holographic description of an individual Narain CFT with c = n on a Riemann surface Σ. By explicitly evaluating the partition functions on both sides of the duality for Σ of genus one, we show that it is dual to a pure level-1 (U(1) × U(1)) n "AB" Chern-Simons (CS) theory on a 3-manifold M with boundary ∂M = Σ (any such 3-manifold can be chosen and gives the same results, there is no sum over 3-manifolds), and we establish the precise holographic dictionary. We note that the two U(1) n gauge fields are coupled at the level of large gauge transformations, and their boundary conditions determine the moduli of the Narain theory. The level k = 1 Chern-Simons theory avoids the factorization puzzle because it is trivial in the bulk -it has a unique wavefunction on any Σ, and in particular the partition function on a "wormhole" geometry connecting two disjoint boundaries is the same as that on the disconnected product of manifolds with the same boundaries.
For a (U(1) × U(1)) n CS theory of level k > 1, the field theory dual is no longer an individual Narain CFT. Rather, we find it to be dual to an ensemble average over a finite set of c = n Narain CFTs based on the set of all even self-dual codes of length n over the "alphabet" Z k × Z k . In this case the CS wavefunction depends on the topology of the bulk manifold M, and we find that the averaged CFT partition function is precisely reproduced by the corresponding Chern-Simons wavefunction, summed over a finite number of equivalence classes of handlebody topologies. The boundary conditions of the CS theory map to parameters of the Narain theories in the ensemble. Our main identity (4.17), valid for any fixed n and prime k = p, gives an explicit relation between the average over the code-based ensemble and the "Poincaré series" representing a (finite) sum over bulk geometries. The k = 1 duality of the previous paragraph may be viewed as a special case of this, where the ensemble contains just a single CFT.
As p → ∞, for n > 2 we will argue that the ensemble of code theories densely covers the whole of Narain moduli space with the canonical measure. We show explicitly how a similar limit works in the case of n = 2, by expressing the average in terms of Hecke operators, and applying a theorem [44] on the equidistribution of Hecke points. In the bulk, for n > 2 in the p → ∞ limit we recover the full Poincaré sum over all handlebody topologies, reproducing the "U(1)-gravity" of [3,4]. Thus, our construction provides a microscopic bulk definition for the latter, as a limit of CS theories.
Arguments of typicality suggest that for large ensembles of CFTs that are selfaveraging and possess a holographic description as a sum over geometries, random individual theories should also admit an approximate holographic description as a sum over geometries. Motivated by this, we propose a sum-over-geometries description for any individual Narain theory with n > 2, that in general is non-local in the bulk, but that becomes approximately local for typical (random) theories as n → ∞ (which is the limit in which the ensemble becomes self-averaging).
The plan of the paper is as follows. In Section 2, we briefly review the relation between additive codes, lattices, and Narain CFTs. In the course of this discussion, we generalize previous constructions by introducing arbitrary additive codes in Section 2.2. Section 3 reviews (U(1)×U(1)) n Chern-Simons theories on handlebody geometries, and constructs their wavefunctions for general boundary conditions. In Section 4 we discuss the holographic interpretation of Narain theories and their ensembles. First, in section 4.1 we show that the wavefunction of level-1 (U(1) × U(1)) n Chern-Simons theory, evaluated with given boundary conditions, is equal to the partition function of a Narain CFT. The point in the Narain moduli space is specified by the boundary conditions of the CS theory, establishing an explicit holographic dictionary. We briefly discuss the idea of averaging over these boundary conditions in section 4.2, and proceed to discuss level k > 1 CS theories summed over geometries in section 4.3. This section establishes our main technical result, equation (4.17). We discuss the k → ∞ limit and the emergence of "U(1)-gravity" in section 4.4. Section 4.5 is devoted to a detailed analysis of the n = 1 and n = 2 cases. It also establishes connections with Hecke operators, which we further discuss, together with related mathematical observations, in section 4.6. Section 5 explores the holographic description of an individual Narain theory as a sum over geometries. We conclude with a discussion in Section 6. Several appendices contain technical details.
2 Additive codes and Narain CFTs 2.1 Codes over Z k × Z k A classical additive code over an Abelian group F is a collection of F -valued strings (codewords) of length n closed under addition within F . Additive codes are naturally related to lattices [45], and thus to lattice-based chiral CFTs [23]. Recently, codes of more general type have been shown to be related to Narain CFTs, their orbifolds, and Abelian fermionic theories [19-21, 30, 31, 35, 37-43].
As an illustrative example, we briefly review the relation between additive even self-dual codes over Z k × Z k and Narain theories [20,21]. A code C over Z k × Z k can be thought of as a linear space within Z 2n k where all algebra is defined mod k. The space is equipped with the indefinite scalar product with respect to which all code vectors are "even", c T η c = 0 (mod 2k) for all c ∈ C. Furthermore, self-duality implies that any vector c ′ ∈ Z 2n orthogonal to C, in the sense that c T η c ′ = 0 (mod k) for any c ∈ C, also belongs to C. There are distinct codes of this type when k = p is prime (the expression for composite k is more involved). Starting from an even self-dual code C, we can define an even self-dual lattice Λ C ⊂ R n,n as follows: A lattice Λ C defines a Narain CFT. When k = p is prime, the CFT can be described, via a T -duality transformation 1 , as a compactification on an n-dimensional torus with metric γ = I/ √ p and with B-field given by an antisymmetric integer-valued matrix Here we use Λ C to denote both the lattice and the lattice-generating matrix. An important object characterizing a code is the complete enumerator polynomial W C . It counts the number of codewords of a code, that include a given "letter" with the specified multiplicity. In the present case, with the "alphabet" Z k × Z k , we regard a codeword c = (a 1 , . . . , a n , b 1 , . . . , b n ) as being composed of letters (a i , b i ) ∈ Z k × Z k . Introducing k 2 formal variables X ab with 0 ≤ a, b < k to represent the letters, one defines the complete enumerator polynomial (2.5) For self-dual C, W C satisfies the so-called Mac-Williams identity To better illustrate the notation, we consider a simple example -length n = 1 even self-dual codes over Z k × Z k . When k = 1 there is a unique code consisting of only one codeword (0, 0) ∈ C. When k = p is prime, there are two codes, one with codewords of the form (a, 0) ∈ C 1 and the other with (0, b) ∈ C 2 , with arbitrary 0 ≤ a, b < p. Their enumerator polynomials are When k > 1 is not prime, there are more codes. All length n = 2 codes for prime k = p are listed in Appendix C.1. A defining feature of the code construction of Narain theories is that for a Narain theory defined with the help of a code-based lattice (2.3), its torus partition function can be concisely written in terms of W C . Indeed, the torus partition function of a Narain theory is defined in terms of a Siegel theta series that sums over all lattice points. For Λ C as in (2.4), we can readily see that the lattice points organize into sets, each associated with a given codeword ( a, b) ∈ C: We can sum over these sets individually, yielding It can be readily seen that by virtue of C being even, each combination n i=1 Ψ a i b i in W C associated with an individual codeword ( a, b) ∈ C will be invariant under τ → τ +1, although individual factors Ψ ab (τ + 1) = Ψ ab (τ ) e 2πiab/k (2.10) are not. Furthermore, Z will be invariant under τ → −1/τ due to the Mac-Williams identity (2.6) and the fact that Ψ ab (−1/τ ) = Ψ ′ ab (τ ), where Ψ ′ are defined as X ′ in (2.6). The relation between the code's enumerator polynomial and the associated CFT partition function can be extended to higher genus [33,35].
The relation between codes and CFTs at the level of the partition function has proved to be a useful tool, which among other things provides an efficient way to solve modular bootstrap constraints, construct inequivalent isospectral CFTs [30] and modular invariant Z(τ ) which are "fake" (i.e., not associated with any bona fide CFT) [36], construct "optimal" CFTs maximizing the value of the spectral gap [21,31], etc.
One recent application was the calculation of the spectral gap of U(1) n ×U(1) n primaries for a typical code theory when k → ∞ while n is kept fixed [21]. The resulting gap, ∆ = n/(2πe), matches the value of the spectral gap in "U(1)-gravity" [3,6], a result we return to in section 5.
The results mentioned above mostly rely on a "rigid embedding" (2.3) or its analogues, in which a code, understood as a subset of Z 2n k , is mapped to a lattice Λ C , which is a sublattice of a cubic lattice of spacing n . This rigidity, which allows only very special Narain lattices to be obtained from codes, suggests a picture in which codes are related to a set of very special Narain theories, dubbed code CFTs. In this picture, there is a close relation between the underlying code and the algebraic properties of the CFT [32]. However, as we will see momentarily, these maps from codes to CFTs are a particular instance of a much more general relation.

General case
Reference [21] provides a general construction of codes over an Abelian group G defined as the quotient group of a self-orthogonal even "glue lattice" Λ, In [21] the focus was on Λ ⊂ R 1,1 and all such lattices were classified there. They are defined by with an arbitrary O + (1, 1) transformation acting on Λ. In particular, the case of Z k ×Z k codes discussed above corresponds to the glue matrix with r = 1. A nontrivial "embedding" r in (2.13) changes p L,R in (2.9) to while changing neither the relation between Z(τ ) and W C , nor the way in which Ψ ab (τ ) changes under modular transformations of τ . The group G is an "alphabet", while codes are collections of G-valued strings of length n closed under addition and equipped with the scalar product inherited from η. Then, even self-dual codes C over G define even self-dual (Narain) lattices Λ C in R n,n via a straightforward generalization of (2.3), If all n glue lattices Λ in (2.15) are the same, then the permutation of letters within the codeword -a code equivalence -is also a symmetry (an element of the T-duality group) at the level of the code CFT. But one can also choose n different parameters r i , in which case to preserve the relation between Z and W C , the enumerator polynomial should depend on n k 2 distinct auxiliary variables X i ab , More generally, one can consider O(n, n, R) transformations acting and mixing several or all Λ's within Λ, or combinations of completely different even self-orthogonal matrices Λ of different dimensions (leading to codes where different letters belong to different alphabets).
Thus, most generally one can consider a lattice Λ ⊂ R n,n , even and self-orthogonal with respect to the 2n-dimensional scalar product (2.1) within R n,n , with the "codewords" being elements of the Abelian quotient group c ∈ C ⊂ Λ * /Λ = G Λ . This group defines a "dictionary," a set of all possible "words". The "dictionary group" inherits the scalar product from (2.1). An even self-dual code would additionally satisfy while if c ′ / ∈ C then c T η c ′ is not an integer for some c ∈ C. Any even self-dual code then defines a Narain lattice, generalizing (2.3), (2.18) Here we denote by (v mod Λ) the equivalence class of v within Λ * /Λ. In general, the relation between the associated CFT partition function and the code enumerator polynomial remains essentially the same. The complete enumerator polynomial is defined in term of formal auxiliary variables X c for c ∈ G Λ , which are then promoted to "(code)word blocks" Ψ c with modular parameter τ and arbitrary fugacities ξ,ξ ∈ R n We emphasize that Ψ c are defined for all c ∈ G Λ , and not all of them are even. The path integral of the CFT is then given by where "BPI" stands for bulk path integral. This name is justified in Section 3. Z BP I is equal to the CFT partition function up to a theory-independent factor, as explained in Appendix A; see also [49]. The functions Ψ c change covariantly under modular transformations Ψ c (τ + 1, ξ,ξ) = Ψ c (τ, ξ,ξ)e πic T ηc , Modular invariance of Z PI follows from (2.22) and the algebraic properties of W C due to the evenness and self-duality (Mac-Williams identity) of the underlying code. The transformations (2.22) are defined solely in terms of the code and therefore can be defined already at the level of the formal variables X c . The same functions Ψ c , with ξ =ξ = 0, have been discussed in [12], where they appeared in a different context -as the partition functions of non-modular-invariant CFTs. There, an ensemble of such CFTs generated by the action of O(n, n, R) on a given Λ was discussed, together with its holographic interpretation. The focus in this paper is different: we sum over Ψ c for all c belonging to a suitable even self-dual code such that the resulting partition function corresponds to a modular-invariant Narain CFT.
We would like to emphasize that the action of O(n, n, R) on Λ does not affect the code, its enumerator polynomial, nor the transformation laws (2.22). It changes the "embedding" that maps the codes associated with a given Λ into the space of Narain CFTs. Explicitly, this means we define Ψ c exactly as in (2.20), but can introduce an arbitrary O ∈ O(n, n, R), where the change of notation can be absorbed into the definition of Λ. Choosing different "embeddings" O will change code theories, but the relation (2.21) between Z and W C will remain the same. Thus, starting from any Λ, e.g. as given by (2.15) and (2.13) with r = 1, and applying an appropriate O, we can represent any Narain lattice as a code lattice Λ C associated with any C over any alphabet. This, first of all, makes the notion that only certain Narain CFTs are associated with codes obsolete -any Narain theory can be thought of as a code CFT associated with any even self-dual code of any type, i.e. with any G, C ⊂ G n , or more generally with any G Λ ⊃ C. One can even associate several arbitrary Narain CFTs with several codes simultaneously, by making use of the n(2n − 1) parameters of O(n, n, R). Yet the notion of a code CFT ensemble is still relevant, since as n increases there are generally many more codes of a given type, see e.g. (2.2), than the number of adjustable parameters.
In the case of n = 1 codes with prime k = p discussed above, the construction based on (2.13) gives two possible codes; the corresponding CFTs are compact scalar theories with radii R = r √ 2p and R = r 2/p, respectively. Obviously, by taking different values of r, each code covers the full space of c = 1 Narain CFTs.
Another way to think about the relation of codes to CFTs is that codes provide a simple tool to represent the modular invariant partition function Z(τ ) of any given Narain theory as a sum of "codeword blocks" Ψ c transforming in a particular representation of the modular group specified by G (or more generally G Λ ) equipped with the scalar product. At a more technical level, the code -a collection of individual codewords -provides a division of a code-based Narain lattice into subsets S c . The sum over such a subset is Ψ c , which exhibits modular properties (2.22). Since all Narain lattices are related by the orthogonal group O(n, n, R), any code can be used to decompose any Narain lattice into subsets, such that the partial sums over the subsets will form a code-specified representation of the modular group.

A review of Abelian Chern-Simons theories on handlebodies
In this paper we discuss Abelian Chern-Simons theories on handlebodies, starting from a single Abelian factor, and then generalizing to many. Handlebodies are smooth 3manifolds M whose boundary ∂M is a genus-g Riemann surface Σ. Topologically, they are characterized by the set of one-cycles of Σ that are contractible in M, which form a Lagrangian sublattice of H 1 (M, Z) with respect to the intersection form. We will focus on the g = 1 case, for which two important examples of handlebodies are thermal global anti-de Sitter space and (related to it by a modular transformation of the torus) the BTZ black hole. Since Chern-Simons theories are topological, the bulk metric of M will not play any role, but its topology and the metric on the boundary ∂M are important.
We begin with a U(1) k theory, whose Euclidean action is for integer k. A natural way to study this theory on a handlebody is using radial quantization, where we view the handlebody M as a fibration of the Riemann surface Σ over a "radial" direction (which can be viewed as Euclidean time) running from the interior (where the Riemann surface shrinks to zero volume) to the boundary. In the above examples of asymptotically AdS 3 spaces, the radial direction coincides with the usual radial coordinate of AdS 3 . From this point of view, the quantum theory has a Hilbert space which is that of Chern-Simons theory on the Riemann surface, and the path integral over the handlebody evaluates Euclidean time evolution starting from some initial state |Ψ interior determined by boundary conditions in the interior, to some final state |Ψ boundary corresponding to the boundary conditions on ∂M. This Hilbert space contains |k| g states of zero energy, and any given state is a linear combination of these. The Euclidean time evolution is trivial, and the path integral on M is simply the overlap between the initial and final states inside this finite-dimensional Hilbert space, Ψ boundary |Ψ interior . Note that for |k| = 1 the Hilbert space is one-dimensional, so all handlebodies give rise to the same interior wavefunction.
In this radial quantization picture the two "spatial" components of A along the Riemann surface are canonically conjugate variables, so they cannot both be diagonalized at the same time. One can choose to write the wavefunctions as functions of one or the other of these variables. More precisely, we will express the wavefunctions in terms of holonomies of the gauge fields along g nonintersecting one-cycles of the Riemann surface γ A; W γ = exp(i γ A) is gauge-invariant, so the holonomies can be viewed as gauge-invariant coordinates up to shifts by 2π (which arise from large gauge transformations that preserve the wavefunction). The holonomies for a basis of dual cycles of Σ form a set of canonically conjugate variables. For any cycle γ that shrinks in the interior of the handlebody, the interior wavefunction must obey W γ |Ψ interior = |Ψ interior (while the Wilson lines on the conjugate cycles are completely smeared).
In the presence of a boundary, having a consistent variational principle for the action (3.1) requires that (involving both components of the gauge field along the boundary, and their variations). Equation (3.2) can be satisfied by setting one of the components of the gauge field to zero at the boundary, or by setting to zero a complex combination of the two components, A z or Az, defined using an appropriate complex structure on ∂M. Setting a field to zero at the boundary automatically sets its variation to be zero. In order to obtain more interesting possibilities for boundary conditions, one can add extra terms on the boundary. With an appropriate choice of a boundary term quadratic in A, one can cancel the terms in (3.2) that involve a given component of δA (either a spatial component or a complex combination), and then boundary conditions that set the other component of A to any fixed value are also allowed. In particular, if (with an appropriate choice of boundary terms) Az is frozen to a specific value at the boundary while A z on the boundary is allowed to fluctuate, then the Chern-Simons theory behaves as a chiral block of a 2d U(1) k CFT, with Az interpreted as a source for a chiral U(1) current J(z) at level k [46].

The wavefunction of U(1) k theory on a torus
As a warm-up example we construct the wavefunctions of level-k U(1) Chern-Simons theory on a torus, following the classic work of Bos and Nair [47]. Additional technical details can be found in Appendix B. We consider the CS theory (3.1) on a threedimensional manifold M with boundary ∂M, which in our case will be a torus with modular parameter τ . We parametrize the boundary torus by the coordinate z, with identifications z ∼ z + 1, z + τ . We choose a gauge where the radial component of the gauge field vanishes, and its equation of motion imposes F zz = 0. We can then further choose a gauge where the spatial components of the gauge fields, A z and Az, are constant on the torus.
Following [47,48] we will consider a holomorphic representation of the wavefunction on the torus. This representation arises naturally if we deform the action (3.1) by adding the boundary term so that the equation of motion δS ′ /δA z = 0 is trivially satisfied at the boundary. Then the path integral can be evaluated with boundary conditions of fixed Az and arbitrary A z . 3 The full path integral on the handlebody, including the boundary term, with a fixed value of Az at the boundary (which is equivalent to the overlap with a wavefunction that is a delta function imposing the boundary value of Az) is then This is a holomorphic function of Az.
Because of the extra factor in the path integral, the overlap between two wavefunctions in the holomorphic representation is given by This expression is schematic, since as we will discuss below one needs to remove degeneracies due to large gauge transformations; see Appendix B for details. The extra exponential factor in the overlap (3.5) can also be understood in the following way. Understood as quantum operators in radial quantization, the gauge field components on the torus with action (3.1) obey the commutation relation [A z , Az] = π kτ 2 , 4 so if we choose the wavefunctions to be functions of only Az, A z acts on them by π kτ 2 ∂ ∂Az . If we insert Az into the overlap (3.5), then on one hand it can act on Ψ 2 (Az) by just multiplying it by Az, but on the other hand by integration by parts it can act on (Ψ 1 (Az)) * , which is a function of A z , as π kτ 2 ∂ ∂Az , as expected from the canonical commutation relations.
We will parameterize the value of Az at the boundary by where ξ is a complex number. As described above, we can write the wavefunctions on the torus, in particular Ψ interior , as holomorphic functions of ξ. The normalization in (3.6) has been chosen so that large gauge transformations in the bulk A → A + ω, which are characterized by integer winding numbers n, m around the two basis cycles of the torus and preserve the gauge of A being constant on the torus, shift ξ by Any holomorphic wavefunction of Az gives a ground state of the Hamiltonian, so the only constraint on the wavefunctions comes from their required covariance under large gauge transformations. Under these transformations, the interior wavefunction Ψ interior should change as follows where we have introduced an additional cocycle ϕ to assure associativity of large gauge transformations Ψ interior (A + (ω + ω ′ )) = Ψ interior ((A + ω) + ω ′ ). This condition requires understood mod 2π. Note that the A z -dependent terms in (3.8) cancel, consistent with Ψ being holomorphic in Az.
Written explicitly in terms of ξ, see Appendix B for details, being invariant under large gauge transformations (3.8), as is expected from (3.5). For even k the CS theory does not require a spin structure, and we have φ 1 = φ 2 = 0. For odd k the definition of the theory requires a spin structure, and on the torus there are four possible spin structures, which give rise to the options φ 1,2 = 0, π. This statement can be justified by considering transformations of Ψ under modular transformations of τ .
For any choice of spin structure there are k distinct solutions for Ψ r (ξ) (labeled by r = 0, · · · , k − 1) since the space of level-k U(1) Chern-Simons wavefunctions on a torus is k-dimensional. They can be written explicitly as Here the appearance of η(τ ) in the denominator is due to small (topologically trivial) fluctuations of the gauge field in the bulk [53]. It can be checked straightforwardly that Ψ r satisfies (3.10) and is canonically normalized, see Appendix B.
In the holomorphic representation, the Wilson loop operator W (p, q) = exp (i p,q A) defined along the cycle p + qτ acts on Ψ r (ξ) as follows Note that the spin structure with φ 1 = φ 2 = π is one where the spinors are periodic along both basic cycles of the torus; this odd spin structure is modular invariant by itself, but it does not allow any of the cycles to shrink in the interior (so it does not appear for handlebodies). This is consistent with the fact that for k = 1 with this choice, the unique wavefunction Ψ 0 (ξ) has eigenvalues W (1, 0) = W (0, 1) = −1.

Wavefunction of the (U(1) × U(1)) k theory
Our next step is to study the "AB" theory with the action with invariance under all gauge transformations of A and B, that include the large gauge transformations This defines the theory in the bulk, which we will denote by (U(1) × U(1)) k to emphasize that this is not a direct product of two U(1) k Chern-Simons theories. As above, to describe the theory on a handlebody we also need to choose boundary terms and boundary conditions. Unlike the case of a single U(1) field, the U(1) × U(1) theory has a continuous family of choices of which variables can be kept fixed at the boundary. For any r we can define gauge fields A ± = (A/r ± B r) k/2 such that the action becomes This now becomes the action of two decoupled U(1) theories at levels 1 and (−1), but the dynamical fields are connected at the level of the large gauge transformations (3.15), so the theory is not equivalent to a product of two decoupled theories. In any case, since A + has positive level and A − has negative level, we can now choose boundary terms and boundary conditions as in the previous subsection such that we fix (A + )z and (A − ) z at the boundary to arbitrary values. Analogously to (3.6), we introduce two independent holomorphic coordinates and deform the action by the boundary term such that the equations of motion δS/δ(A + ) z = δS/δ(A − )z = 0 are trivially satisfied at the boundary. The wavefunction Ψ(ξ,ξ) associated with this action is holomorphic in ξ, and separately inξ. Next, we demand that under large gauge transformations with parameters (n, m) for A, and (p, q) for B, which take (2ξδξ * +|δξ| 2 +2ξδξ * +|δξ| 2 )+iπk(mp−nq) . (3.20) In this case the cocycle factor is simply ϕ = πk(mp − nq), so there is no need to introduce nontrivial phases φ i . There are k 2 wavefunctions given explicitly by We would like to emphasize that (3.21) for different r are different representations of the same k 2 bulk wavefunctions, expressed as functions of different variables (corresponding to the specific choice of boundary conditions we made). The result (3.21) resembles the partition function of a free scalar CFT, and we will discuss the precise relation in the next section.
Wilson loops of A along the n+mτ cycle, W A (n, m) = exp (i n,m A), with a similar definition for Wilson loops of B, act on (3.21) as follows In particular, Wilson lines of both A and B along the 1 cycle act on Ψ 0,0 trivially, so Ψ 0,0 is a consistent wavefunction on thermal AdS -the handlebody where this cycle shrinks in the interior.

General case
Before we proceed with the general (U(1) × U(1)) n theory we would like to revisit the U(1) × U(1) case, but instead of starting with the "AB" theory (3.14), we can start with (3.16) and (3.17) and just impose large gauge transformations generalizing (3.19) Here Λ defines an even self-orthogonal lattice in R 1,1 as in (2.12). The holomorphic functions of ξ andξ are parametrized by elements of the Abelian group c ∈ Z 2 /g Λ = Λ * /Λ = G, and under large gauge transformations (3.24) they change as follows : The generalization to the case of (U(1) × U(1)) n is now straightforward. The main ingredient is the even self-orthogonal lattice Λ ∈ R n,n , which defines large gauge transformations of U(1) n -valued gauge fields A ± as follows, 27) while the relation between ξ,ξ and A ± is as in (3.17), generalized to vector-valued quantities. The resulting wavefunction is parametrized by an element of the Abelian group c ∈ G Λ = Λ * /Λ, The wavefunction Ψ c coincides exactly with the "codeword blocks" (2.20). We will explore the holographic interpretation of this result in section 4.
4 Holographic description of the ensemble of code CFTs 4.1 Level k = 1 CS theories and conventional holographic correspondence As discussed above, for k = 1 the U(1) × U(1) CS theory has a unique wavefunction, which can be written as Ψ 00 (τ, ξ,ξ). It is given by the CS path integral on any handlebody M with the appropriate boundary conditions on ∂M = Σ of genus one. Our starting point is the observation that this unique wavefunction (3.21) with k = 1 is the same as the path integral of the two-dimensional CFT, the compact scalar of radius R = √ 2r, coupled to an external complex gauge field A parametrized by ξ,ξ We discuss the compact scalar in detail in Appendix A. From the bulk point of view ξ,ξ parametrize certain components of the fields A + , A − on the boundary of M, and the holographic dictionary relates them to sources in the CFT by such that Z BP I is the CFT path integral with these sources (as discussed in Appendix A). In the CFT the complex field A is a combination of two real fields A and B coupled to the two conserved U(1) currents, see (A. 19), and we have chosen notation such that the CFT source fields A, B are exactly the boundary values of the bulk gauge fields A, B introduced in subsection 3.3. At the same time we emphasize that the Chern-Simons theory is quantized with the boundary condition that fixes the fields (A + )z, (A − ) z at the boundary, while (A + ) z , (A − )z vary freely. This condition looks cumbersome when expressed in terms of A and B. While preserving the same boundary conditions, we can add an additional boundary term πξξ τ 2 to the bulk action (3.18) and obtain, after an integration by parts, The new action still satisfies δS 1 /δ(A + ) z = δS 1 /δ(A − )z = 0 at the boundary, because the added boundary term does not include fluctuating fields. It leads to a holomorphic bulk wavefunction which equals the first path integral introduced in Appendix A Note that unlike the bulk path integral discussed in the previous section (related to it by Z P I (τ, ξ,ξ) = Z BP I (τ, ξ,ξ)e − π τ 2 ξξ ), Z PI is manifestly invariant under large gauge transformations of A. Similarly, subtracting πξξ τ 2 from the bulk action leads to and which is manifestly invariant under large gauge transformations of B. To be precise, these bulk theories are actually complexifications of the path integrals considered in Appendix A, as ξ,ξ are treated here as two independent complex variables. To reduce precisely to the CFTs described by the actions (A.7) and (A.14), one would need to impose additional restrictions on the boundary conditions in (4.4) and (4.6), that respectively set B = 0 and A = 0 at the boundary, by choosing ξ * = ±ξ.
It is important to point out that the parameter r from the bulk point of view is a parameter changing the representation of the Chern-Simons wavefunction |Ψ . It defines the boundary conditions, but it does not affect the action in the bulk. Hence, for all r the quantum state |Ψ remains the same, which is already clear from the fact that the Hilbert space of level-1 Chern-Simons theory is 1-dimensional. From the boundary point of view, the parameter r -the radius of the compact circle -changes the CFT. This situation is not conceptually different from more conventional instances of the holographic correspondence, such as gauge/gravity duality, in which the path integral of the same bulk action with different boundary conditions describes different field theories. For example, exactly marginal deformations of a CFT correspond to changing the boundary conditions for massless scalars in anti-de Sitter space. Another even more direct analogy is with the dS/CFT correspondence [54], where the same quantum Hartle-Hawking wavefunction in the bulk is dual to different field theories, depending on the overlap of the unique bulk wavefunction with the wavefunction at the boundary.
The generalization of the above considerations to (U(1)×U (1)) n is straightforward. The general level k = 1 theory is (U(1) × U(1)) n Chern-Simons theory, quantized with large gauge transformations corresponding to points in an even self-dual lattice Λ (3.27). In this case G Λ = Λ * /Λ consists of a single element, and the unique wavefunction (3.28) is identified with the path integral of the Narain theory associated with Λ Z BP I (τ, ξ,ξ, Λ) = Ψ 0 (τ, ξ,ξ). (4.7) Similarly to the n = 1 case, there are many possible definitions of path integrals, generalizing (4.4) and (4.6); here we use the T -duality invariant definition of (3.28). One can rewrite the (U(1) × U(1)) n fields A ± in terms of the gauge fields A, B and the lattice Λ, which we parametrize by γ and B as in (2.4) with trivial O T , In terms of these fields, the action of large gauge transformations are canonical, A → A + ω A , B → B + ω B , but the boundary conditions in the path integral become Λdependent. This description provides the holographic dictionary for a general Narain CFT: the path integral of a Narain theory is equivalent to the path integral of level-1 (U(1) × U(1)) n Chern-Simons theory with boundary conditions (wavefunction representation) specified by Λ.
The construction above is an explicit realization of the AdS 3 /CFT 2 correspondence for Narain theories in terms of pure Chern-Simons theory in the bulk. The original treatment in [50], recently revisited in [12], was in terms of Maxwell-Chern-Simons theory in the limit of infinite Maxwell coupling. We have shown here that inclusion of the Maxwell term is not necessary, provided a more explicit treatment by evaluating the path integral on both sides of the duality, and established a holographic dictionary. Our approach is also related to the recent work [16], which constructs a bulk description for a Narain theory with decomposable Λ = Λ L ⊕ Λ R in terms of level k = 1 CS theory, obtained from k > 1 Chern-Simons theory by gauging all discrete symmetries.
It is important to note that the holographic description above does not include a sum over bulk geometries or topologies. Rather, all handlebodies yield the same wavefunction, obeying (4.7). This is analogous to the case of AdS 3 with k = 1 units of NS-NS flux (the "tensionless string") [55,56], where fluctuations in the bulk on a fixed background geometry are believed to account for the full partition function.
Codes, and code ensembles, play a rather trivial role in the holographic description of Narain CFTs in terms of level k = 1 Chern-Simons theory. Indeed, the k = 1 U(1) × U(1) theory is associated with the unique length n = 1 code over the alphabet Z 1 × Z 1 , consisting of the unique codeword c = (0, 0). The parameter r, the radius of the compact scalar on the CFT side, does not affect the code, but controls the embedding of the code into the space of n = 1 Narain CFTs. Similarly, whenever the lattice Λ is self-dual, the group G Λ is trivial, consisting of a single element, and there is a unique code consisting of a single codeword c = 0. As we saw above, this trivial code can be mapped to an arbitrary Narain theory by choosing an appropriate embedding. To summarize, we see that the conventional holographic correspondence emerges when the code ensemble consist of only one element, a unique code associated with a given Narain CFT.

Averaging over Narain CFTs
The holographic duality described above maps Narain theories to three dimensional bulk theories which are non-gravitational Chern-Simons theories living on a fixed spacetime, with no sum over geometries. This is consistent with the fact that in these CFTs the energy-momentum tensor is a product of U(1) currents, so we do not expect an independent graviton field in the bulk Motivated by [3,4] will now consider an average over a finite ensemble of Narain theories, or over the whole moduli space of Narain theories with some c = n. A priori, it is not clear if such an ensemble average would have a simple description in the bulk. The duality between Narain theories and level-1 CS theories on a fixed handlebody provides one way to evaluate it -by averaging over all possible boundary terms and boundary conditions, corresponding to all Narain CFTs. For n = 1 this is just an average over the values of r. One way to implement this is to write down the boundary terms as a function of γ and B using (4.8), and then to make these variables dynamical and to integrate over them with an O(n, n, R)-invariant measure. These variables live just on the boundary, but since they are constant on ∂M, integrating over them gives a non-local theory. This non-local theory (on a given handlebody) is, by construction, equivalent to the ensemble average over Narain theories, but this is not very satisfactory, and certainly more complicated than the dual description suggested in [3,4]. In the rest of this section we explore an alternative way to obtain the ensemble average over Narain theories, which will lead to bulk sums over geometries similar to those of [3,4], but described by a fully consistent Chern-Simons theory with compact gauge group. "U(1)-gravity" theory will then emerge as a limit.

Level k > 1 CS theory and ensemble averaging
Our next step is to consider codes over alphabets with more than one element. As we have seen in full generality in section 3.4, the "codeword blocks" Ψ c (2.20) appearing in the context of codes have a simple bulk interpretation. They are precisely the same as the wavefunctions of the (U(1) × U(1)) n Chern-Simons theory on a spatial torus. Indeed, the theory quantized with large gauge transformations specified by a lattice Λ has exactly G Λ = Λ * /Λ independent wavefunctions, in one to one correspondence with the codewords. As was emphasized in section 2, any given code C of length n can be associated with any Narain CFT of central charge n, by choosing an appropriate embedding. As a result we have the following expression for the CFT path integral This expression, though suggestive, has no apparent holographic interpretation. Indeed, the sum of wavefunctions on the right-hand side of (4.9) does not allow for a simple interpretation as the bulk path integral evaluated on a simple 3d geometry, or as a sum of such path integrals. This is because in general, path integrals on simple geometries such as solid tori with different shrinking cycles would lead to a subclass of Ψ c not nearly exhausting all possibilities. This is easiest to see in the case of codes over Z k × Z k and (U(1) × U(1)) n k Chern-Simons theory. The path integral over the solid torus with a shrinkable n + mτ cycle will lead to the unique combination of Ψ a 1 ,b 1 . . . Although associating individual CFTs with codes does not lead to a simple holographic interpretation, we note that codes -and hence also the associated CFTsnaturally appear in the context of ensembles. There is always an ensemble of all codes (CFTs) of a particular type (e.g. over a particular alphabet) and of given length (corresponding to CFT central charge n). It was initially suggested in [19] that such an ensemble of code CFTs should admit a holographic interpretation. A crucial observation building towards such an interpretation was made recently in [34]. There the authors considered an ensemble consisting of all length-n Z 2 × Z 2 codes with the glue matrix Λ = 1 1 1 −1 (4.10) in the notation of section 2 (the original paper used a different but equivalent description). It was conjectured, and then verified explicitly for small n, that the enumerator polynomial, averaged over the ensemble of all such codes, is proportional to the "Poincaré series" of all possible modular transformations acting on the auxiliary variable associated with the trivial codeword, g(X n 00 ). (4.11) We emphasize that the action of the modular group on the variables X ab , generated by (2.22), along with the equality (4.11), are defined and satisfied at the level of codes, before the map to CFTs and Chern-Simons theory. The variables X ab provide (for k = 2) a four-dimensional representation of the modular group SL(2, Z); hence the sum on the right-hand side of (4.11) over Γ * \SL(2, Z), where Γ * is the stabilizer of X 00 , includes a finite number of terms. Alternatively, one can sum over the whole modular group, with the infinite size of Γ * absorbed into the overall proportionality coefficient. While we leave a systematic justification of (4.11) and its generalizations to future work [57], we point out that the equality between the weighted average over codes and the Poincaré sum over the modular group will apply to other code constructions as well, and will extend to higher genus boundaries. To be explicit, in what follows we focus our attention on Z k × Z k codes with the glue matrix (2.13) and prime k = p, for which we establish the analogue of (4.11) for arbitrary n. We consider codes of length n, which define an ensemble of size (2.2). For prime p all codes should be averaged with equal weight. In this case, the average is straightforward -see footnote on page 31.
Next we consider the sum over the modular group in (4.11). We introduce p 2 variables X ab forming a representation of the modular group generated by (2.10) and by obtaining X ′ of (2.6) when taking τ → −1/τ . The full set of (p 2 ) n variables X a, b associated with codes of length n transform in the tensor product of n such representations.
The explicit action of the T and S generators of SL(2, Z) is, using (2.22), Our goal is to sum over Γ * \SL(2, Z), where Γ * is the stabilizer group of X 0, 0 . The sum can be performed in two steps: we first define a subgroup Γ ⊂ SL(2, Z) which leaves all X a, b invariant, and then additionally factorize over the stabilizer of X 0, 0 within Γ\SL(2, Z). The group Γ in the general case is known to be a congruence subgroup of SL(2, Z) [12,58]; for prime p it is the principal congruence subgroup Γ = Γ(p). The stabilizer of X 0, 0 in Γ\SL(2, Z) is the cyclic group Z 2 × Z p generated by S 2 (which takes X a,b to X −a,−b ) and by powers of T , so This quotient consists of (p 2 − 1)/2 elements, which can be parametrized by integer pairs (c, d) ∼ (−c, −d), corresponding to the modular transformation which has the following action on X 0, 0 : The equation above applies when c = 0; otherwise g(X 0, 0 ) = X 0, 0 . One can readily see that the (p 2 −1)/2 terms in the Poincaré sum split into p+1 terms labeled by elements of Γ 0 (p)\SL(2, Z) = {1, ST l } with 0 ≤ l < p, each appearing (p − 1)/2 times. Combining everything, we find the averaged enumerator polynomial for codes over Z p × Z p , Here N is given by (2.2), and the coefficient 1 + p 1−n in the denominator of the righthand side is chosen such that the coefficient in front of X 0, 0 associated with the trivial codeword is equal to one.
The identity (4.16) for code CFTs acquires a straightforward holographic interpretation which has been envisioned in [34]. We consider ((U(1) × U(1)) n k Chern-Simons theory, placed on an arbitrary handlebody geometry, and identify Ψ 0, 0 (τ, ξ,ξ) to be the wavefunction of this theory on thermal AdS, the solid torus with shrinkable a-cycle. Indeed, Wilson loops of both A and B fields over this shrinkable cycle should act on the boundary wavefunction trivially, which singles out Ψ 0, 0 , as follows from (3.22), (3.23). Hence, the sum in (4.16) can be interpreted as a sum over all possible handlebody topologies, or more accurately, as a sum over equivalence classes of topologies yielding the same boundary wavefunction, Ψ 0, 0 (g τ, g ξ, gξ) = (4.17) This equality between ensemble averaging over code CFTs on the field theory side, and summing over topologies on the bulk side, is preserved under the action of O(n, n, R), which changes the embedding of the codes in the space of Narain CFTs and the representation of the wavefunction of the dual Chern-Simons theory.
We expect an equality analogous to (4.17) to apply more broadly, to codes defined as even self-dual linear subspaces of the group G Λ defined by an even self-orthogonal lattice Λ and corresponding code CFTs/ Chern-Simons theories, although the averaging weights and the details of the "Poincaré sum" will be different. The equality will also extend to higher genus boundary geometries.
To summarize, we have obtained an infinite series of explicit examples of "holographic duality," in which an ensemble of CFTs is dual to a Chern-Simons theory coupled to topological gravity, and the bulk partition function is given by a sum over topologies. This sum is akin to a sum over saddle point configurations in conventional gravity, implementing the ideas of [59][60][61]. In spirit, our examples are similar to the original work [62] representing the Ising model partition function as a sum "over geometries," but crucially we explicitly outline the dual theory in the bulk.
Our code-based construction allows for many generalizations, to additive codes of other types, and potentially going beyond additive codes and Abelian CFTs. We expect that this approach may lead to many more explicit examples, potentially reformulating the results of [10,11,15] in terms of codes.
Although in this paper we only consider the CFTs living on a torus, we expect that the holographic duality will generalize to higher genera [57]. The ensembles we consider contain a finite number of CFTs, hence the ensemble is parameterized by a finite number of moments. This will imply that the dual Chern-Simons theory on M, with ∂M being a Riemann surface of sufficiently high genus, would be completely determined in terms of path integrals over lower genus boundary surfaces. This will require various factorization rules in the bulk, which deserves a better understanding.

Holographic correspondence in the k → ∞ limit
In the previous section we saw that the size of the ensemble is related to the number of classes of topologies appearing in the bulk sum. Bigger ensembles correspond to "more gravitational" theories in the bulk, distinguishing more topological features and thus leading to a sum over more classes of topologies. It is thus natural to ask, what would happen with the duality as the size of the code CFT ensemble becomes infinitely large. In what follows we take k = p to be prime for simplicity. To evaluate the right-hand side of (4.16) in the p → ∞ limit we go back to definition of Ψ 0, 0 (3.28), From (4.15) we know that we do not need to consider all possible co-prime pairs c, d, but only c = 0, d = 1, and p additional pairs yielding all possible values for dc −1 mod p. A crucial observation is that one can always pick a set of such pairs with positive c satisfying c, |d| ≤ √ p. While we could not prove this in full generality, we have numerically checked it for the first hundred primes. We first consider the case when c, |d| ≪ √ p with p ≫ 1. In this regime all vectors p L , p R summed over in Θ 0, 0 , except for p L , p R = 0, are of order | p L |, | p R | ∼ O(p 1/2 ). This is in fact a general result for any embedding, in the limit where the embedding is fixed while p → ∞. So for c, |d| ≪ √ p, the factor in (3.28) suppresses all other terms, and hence the only contribution is from p L , p R = 0, Outside of the c, |d| ≪ √ p regime, but provided c, |d| ≤ √ p is still satisfied, we notice that the combination τ ′ 2 (| p L | 2 + | p R | 2 ) is at least of order one, and |p L · ξ|, |p R ·ξ| are at most of order one, O(p 0 ). This means that Θ 0, 0 (τ ′ , ξ ′ ,ξ ′ ) O(p 0 ) for p ≫ 1. Now, going back to the sum over p + 1 pairs c, d, we split the sum into two groups, for c, |d| satisfying c, |d| ≤ p α for any 1/3 < α < 1/2, and the rest. The first group will yield while the second group, which has at most p terms, will give a contribution bounded by For n α > 1 this second term is negligible in the limit p → ∞. To conclude, for n ≥ 3, in the p → ∞ limit we recover the following expression for the averaged partition function matching the result of [7], which reduces to the partition function of [3,4] for ξ =ξ = 0. The special cases of n = 1, 2 are considered below. Our final expression (4.23) is manifestly independent of the embedding. From [3,4,7] we know this expression is equal to the Narain CFT path integral averaged with the Haar measure over the whole Narain moduli space. It is thus natural to speculate that for n > 2 in the p → ∞ limit, independently of the embedding, the ensemble of code CFTs densely covers the whole moduli space with the canonical measure. We will first discuss how this works in the n = 2 case in next section, and then provide additional arguments and formulate an underlying hypothesis in section 5.
The original works [3,4] identified the sum in the right-hand-side of (4.23) as a sum over handlebody topologies of the "perturbative sector of Chern-Simons," an Abelian Chern-Simons theory with only small (topologically trivial) fluctuations of gauge fields contributing to the path integral. This theory was dubbed "U(1)-gravity" [3], but apparently it has no well-defined microscopic description. As was pointed out in [4], genuine Chern-Simons theories with either non-compact or compact gauge groups would lead to different results. We are now ready to clarify this point. U(1)-gravity does not have a proper microscopic description in the bulk because it emerges as a limit of well-defined theories, namely the k → ∞ limit of level-k (U(1) × U(1)) n Chern-Simons theory, coupled to topological gravity (to give the sum over handlebodies).

Ensembles of n = 1 and n = 2 theories in the large p limit
The cases n = 1 and n = 2 are special. As discussed above, for n = 1 and k > 1 the ensemble consists of just two codes, one with the codewords of the form (a, 0) ∈ C 1 and the other with (0, b) ∈ C 2 , with arbitrary 0 ≤ a, b < p. When translated to CFTs, each of them maps to a single compact scalar, with radii R ± = √ 2 r p ±1/2 , respectively. The relation between the ensemble-averaged enumerator polynomial and the Poincaré series (4.16) is valid for all n; hence this ensemble can be represented "holographically" as follows Ψ 00 (g τ, g ξ, gξ, r), (4.24) where the sum is over p + 1 classes of three-dimensional topologies and Ψ 00 is given by (3.21). We have explicitly specified the embedding parameter r, which is arbitrary and can scale with p. This relation holds for any prime p, but in the limit p → ∞ it diverges. The sum in the right-hand side of (4.24) becomes the divergent real Eisenstein series of weight 1. The left-hand side of (4.24) also diverges, as at least one of the scalars decompactifies. Using the representation (A.10) of the partition function and T-duality, we find the limit for fixed r to be (for simplicity we consider vanishing fugacities ξ =ξ = 0) One can also consider the p → ∞ limit when R − = R remains fixed, while R + scales with p, in which case This is essentially the "modular sum" representation for the given compact scalar partition function Z R , except for the constant term R/ √ 2τ 2 |η(τ )| 2 . In this way it is similar to the representation (3.14) of [9]. In any case, the interpretation of the divergent equations that arise in these cases is not clear.
The case of n = 2 codes is similar but much richer. Narain lattices in R 2,2 are conventionally parametrized by two modular parameters t = t 1 + it 2 and b = b 1 + ib 2 , related to γ and the B-field by T-duality acts on (t, b) as SL(2, Z) × SL(2, Z) with an additional Z 2 exchanging t ↔ b. We denote the partition function of a c = 2 Narain theory by Z c=2 (τ, t, b). It is modular invariant with respect to all three variables. One can also introduce the partition function of primaries,Ẑ(τ, t, b) = τ 2 |η(τ )| 4 Z c=2 (τ, t, b), where here and in what follows we assume the fugacities vanish ξ =ξ = 0. The partition function of primaries remains modular invariant under τ , and exhibits triality -full symmetry under permutation of its three arguments [9,63]. There are 2(p + 1) n = 2 codes, see Appendix C.1 for a detailed discussion. If we choose an embedding, an orthogonal matrix from O(2, 2, R) introduced in the end of section 2, in the form parametrized by two modular parameters t = −1/t 0 , b = b 0 , then the 2(p + 1) self-dual lattices of the code theories (after appropriate T-dualities) are explicitly given by where 0 ≤ k < p. It is convenient to represent the average over code theories in terms of Hecke operators T p , defined as follows [64]. For a modular form f (τ ) of weight k and prime p Then, the average over codes is simply where we introduced an upper index to indicate the variable that each Hecke operator is acting on. The "sum over topologies" in the right-hand side of (4.16) can also be simplified for general n. Starting from an O(n, n, R) matrix O specifying a Narain lattice, the partition function of the corresponding Narain theory can be written as (2.20) Now, going back to (4.33), we notice that it can be rewritten as where Θ is defined with the same O as the embedding matrix of codes, introduced at the end of section 2. The last step in (4.35) is justified because Θ(τ ) is a modular form of weight n. Using the definition (4.31) we can express T p acting on a modular form f of weight n in terms of its action on the modular invariant τ n/2 Going back to the n = 2 case and noting that τ 2 Θ =Ẑ(τ, t, b) is exactly the partition function of primaries, we can now rewrite the identity (4.17) as follows: (4.37) In fact a stronger identity holds for any prime p, see Appendix C, which extends the triality -permutation symmetry ofẐ with respect to its arguments. In the limit p → ∞, the points t = k+t 0 p form a dense line close to t 2 = 0, that crosses infinitely many copies of the fundamental domain. Once these p points are mapped back to the standard keyhole domain of SL(2, Z), they will cover it densely with the standard covariant measure d 2 t/t 2 2 . The contribution of the point t = p t 0 in the full average will be 1/p suppressed, and can be neglected. Thus, the average over code theories when p → ∞, at least at leading order, would plausibly approach the average over the fundamental domain of t with the SL(2, Z) covariant measure, plus the same average over b (note that this is not the same as averaging over all Narain theories). Similarly, thanks to (4.35), the "bulk" sum in the p → ∞ limit will be proportional to the average ofẐ over the fundamental domain of τ with the measure d 2 τ /τ 2 2 . The same conclusion is supported by the general result of [44,65], that in the limit p → ∞, for any square-integrable modular function f , T p (f ) approaches the integral of f over the fundamental domain F with the canonical measure for large p, where ǫ is any real number > 0, and ||f || is the Weil-Petersson norm of f [65]. The caveat here is that in our caseẐ is not square-integrable, and the integral over the fundamental domain diverges. We therefore conjecture that in the p → ∞ limit, T x p (Ẑ) for x = τ , t or b would be given by the regularized average over the fundamental domain of x, plus an x-dependent term, which will not be dependent on other variables. The regularized average ofẐ over τ has been carried out in [66]. We discuss averaging over t, related to it by triality, in Appendix C. Using this result we conjecture for some unknown f (τ ). Since both (4.37) and (4.38) hold for any finite prime p, to preserve triality we must conclude f (τ ) = − 3 π ln(τ 2 |η(τ )| 4 ) and where p 0 is some constant.

Extensions and generalizations
The equality between averaging over length-n Z p ×Z p codes (with n ≥ 3) and "Poincaré series," which can be understood as sums over handlebody topologies, begs a deeper understanding. First, we expect it to hold for arbitrary genus g, where X c 1 ,...,cg are formal variables associated with the g-tuples of codewords [33,35,67]. We promote them to wavefunctions Ψ c 1 ,...,cg of Chern-Simons theory on a genus-g Riemann surface, hence their dependence on the period matrix Ω. Ψ (0,...,0) , associated with the zero codeword taken g times, is the wavefunction of the Chern-Simons theory computed on a 3d manifold M with all a-cycles of ∂M contractible in the interior, which is an analog of thermal AdS. As in section 4.3, the Poincaré sum in (4.41) can be reformulated as a sum over a coset Γ * \Sp(2g, Z), where Γ * is a congruence subgroup of the modular group Sp(2g, Z) leaving Ψ (0,...,0) (Ω) invariant. Extending the result of the g = 1 case, we conjecture this subgroup to be Γ Sp(2g, Z), which we define to be the group of matrices For prime p the coset Γ elements (we obtained this expression by generalizing [68,69]), which matches the result N Sp (2, 2) = 15 found in [34].
In a somewhat similar fashion, the sum over codes on the left-hand-side of (4.41) can also be represented as a coset. We recall that all even self-dual codes over Z k × Z k of the kind we are considering can be understood as a set of even self-dual lattices Λ C satisfying, see (2.15),  The coset description (4.46) is a generalization to arbitrary prime p of the coset construction for p = 2 outlined in [19]. The size of the coset is given by (2.2). To summarize, the equality (4.41) between the average over codes and the Poincaré series over topologies can be rewritten as a sum over similar cosets C∈Γ O(n,n) 0 (p)\O(n,n,Z) (Ψ (0,...,0) ). (4.48) The number of terms on both sides, N (n, p) (2.2) and N Sp (g, p) (4.44), and the overall similarity of the cosets, can be seen as an extension of the worldsheet/target space duality of the c = 2 case [63]. We have seen in the previous section that the Poincaré sum for genus one can be represented in terms of a Hecke operator. In general the Hecke operator T k is defined to act on functions f (Λ) on lattices Λ.
A modular form f (τ ) can be understood as a function on twodimensional lattices generated by 1 and τ . Then T k can be written as a sum over equivalence classes of 2 × 2 integer matrices of determinant k, (4.50) Here we introduced the modular invariant partition function of primariesẐ(τ ) = τ n/2 2 Θ(τ ), which is related toẐ 0, 0 (τ ) = τ n/2 It is tempting to speculate that an analogous representation is also possible for highergenus Poincaré series, in which the Hecke operator would be defined to act on modular forms f (Ω) of Sp(2g, Z).
The left-hand-side of (4.48), the sum over codes, is also very reminiscent of Hecke operators. While the standard Hecke operator includes the sum over all sublattices of index p, the sum over even self-dual codes can be readily rewritten as a sum over all even sublattices of (Z/ √ p) 2n of index p n . The Hecke form of code averaging, through a suitable generalization of (4.39), could potentially lead to a more straightforward and general proof that in the limit that the size of the code ensemble becomes infinite, the code average computes the average over the whole Narain moduli space with the Haar measure. We should note that formally the same logic can be applied to the Poincaré series, which would naively suggest that when p → ∞, the right-hand-side of (4.50) and hence (4.17) would be given by an integral over the fundamental domain of τ . This is not so because the corresponding modular formẐ is not square-integrable on the fundamental domain. As a result, in order to apply (4.39) the integral has to be covariantly regularized, eventually leading to the conclusion of section 4.4: in the p → ∞ limit the Poincaré series in (4.17) approaches the real Eisenstein series of weight n.

Ensemble averaging, typicality and holography
In section 4.4 we saw that averaging partition functions over the ensemble of code CFTs in the k → ∞ limit leads (for n > 2) to "U(1)-gravity," the sum over CS theories on all handlebody topologies. In particular, the answer does not depend on the embedding of the codes, and is equal to the average of the whole Narain moduli space with the Haar measure, as was outlined in [3,4]. This suggests that code CFTs in the k → ∞ limit, when the ensemble becomes infinitely large, densely cover the entire Narain moduli space with the canonical measure. This is in agreement with an earlier observation that the averaged code theory, in the k → ∞ limit, has the same spectral gap as the averaged Narain theory [6]. If we additionally take the large central charge limit, c ≫ 1, then averaging over the whole moduli space would be well approximated by a random Narain theory, because the ensemble of all Narain theories, as well as the ensemble of code CFTs in the c → ∞ limit, are self-averaging at large c, namely the variance is exponentially small e −O(c) [6,13,34].
To support the conclusion that the k → ∞ ensemble densely covers the entire moduli space, we first note that there are two code ensembles, but for large k they are similar. The first ensemble, which we used in our discussions above, is the ensemble of all N = n−1 i=0 (p i + 1) codes of length n (here we assume k = p is prime). The second ensemble is the ensemble of all N ′ = p n(n−1)/2 codes in the canonical form, also called the B-form [19]. Each code in the canonical form is parametrized by an antisymmetric matrix B defined mod p, which can be interpreted as an adjacency matrix of a graph with edges carrying an element of Z p . Every code from the first ensemble has an equivalent code in the canonical form, in the sense of code equivalences. It is a non-trivial question to determine the number of codes equivalent to the canonical one with a given B (noting that certain canonical form codes are equivalent to each other). At the level of CFTs, code equivalence is the same as T-duality only for the most symmetric "rigid" embedding, when the code with the matrix B is associated with the Narain lattice specified by γ = I/ √ p and B = B/p. When p → ∞ we expect averaging over both ensembles with each code entering with equal weight to be physically equivalent, which is reflected by N ′ /N → 1 and by the equivalence of the resulting Gilbert-Varshamov bounds (averaged spectral gap).
The ensemble of all codes in the canonical form, independently of the embedding, leads to the ensemble of CFTs with γ → 0 and with the B-field homogeneously covering the "T-duality cube" B ij ∼ B ij + 1. We conjecture that the region in the moduli space with the conventional flat measure for dB ij on the cube, covers (via T-duality) the whole Narain moduli space, with the canonical O(n, n, R)-invariant measure. By γ → 0 we mean that all singular values of γ approach zero. This is analogous to the observation in section 4.5 that the t 2 → 0, 0 ≤ t 1 < 1 region is T-dual to the entire fundamental domain of t with the canonical measure. Similarly here, it is straightforward to see that starting from an arbitrary pair (γ, B), via T-duality one can move it into the region (5.1). A non-trivial point, which we leave for the future, is whether the Haar measure on the Narain moduli space indeed results in the homogeneous measure for B ij . With this assumption, we would find that the ensemble of all canonical codes densely covers the entire Narain moduli space with the Haar measure. In particular, this would explain why the averaged spectral gap matches the one of the whole Narain ensemble [6].
The representation of the Narain moduli space via (5.1) provides a new easy way to obtain the original result of [3,4] and [7]. Starting from the conventional representation of the CFT path integral (3.28) with self-dual Λ parametrized by γ, B, and by performing Poisson resummation over half of the variables, we obtain Now we are ready to average Z γ,B over the region (5.1). Integration over B ij forces the vectors n, m to be collinear. We thus can parametrize n = c ℓ, m = d ℓ with ℓ ∈ Z n and with a co-prime pair (c, d) = 1. Using the explicit modular invariance of (5.2), we find In the limit γ → 0, the summation over ℓ can be replaced by an integration, giving matching (4.23). The calculation above hints towards a possible "holographic dual" for an individual Narain theory, understood as a "Poincaré sum" over all co-prime pairs (c, d) = 1, enumerating all handlebodies. The representation (5.2), valid for any γ, B, geometrizes the action of the modular group SL(2, Z) as an action on a lattice of vectors ( n, m) ∈ Z 2n . There is a trivial orbit of SL(2, Z), consisting of the origin n = m = 0, with a non-trivial action on all other elements (trivial stabilizer). Thus, only the contribution of the origin does not admit the Poincaré sum form, but we can make it as small as we want by using chains of T-dualities to render det(γ) arbitrarily small. The remaining contributions of Z 2n \ 0 may be conveniently split into "one-vector orbits", with collinear n = c ℓ, m = d ℓ, and "two-vector orbits", when n, m are not collinear. The contribution of the one-vector orbits leads naturally to a sum over co-prime pairs (c, d), as in (5.4). We can choose a representative in each orbit with n = 0, m = ℓ, leading to a concise expression for v = γ ℓ. Averaging over γ, even without assuming γ → 0, would lead to "U(1)-gravity" -the real Eisenstein series. 6 The contribution of the two-vector orbits can also be represented as a sum over co-prime (c, d) = 1, but here the choice of "gauge" -the choice of a representative in the orbit of SL(2, Z) -is less clear. There is no obvious choice admitting an apparent bulk interpretation. For a typical Narain theory with large central charge, when B can be considered random, the contribution of two-vector orbits will be exponentially small: for small γ the term −π|v| 2 /τ 2 in the exponent can be neglected, while many different pairs (n, m) will lead to random phases e −2πim T Bn canceling each other.
To summarize, we outlined a possible holographic "Poincaré sum" representation for an individual Narain theory, which fits the picture proposed in [6]. A typical theory (when c ≫ 1) will be described by U(1)-gravity with exponentially small corrections. There is a natural ambiguity of assigning these corrections to individual handlebodies, rooted in the ambiguity of choosing representatives among the two-vector orbits. This, together with the need to consider a limit of T-duality transformations yielding det(γ) → 0, precludes a simple microscopic local bulk interpretation.
The resulting picture is qualitatively similar to the one in JT gravity [70,71]. An attempt to extend a holographic duality based on a sum over topologies to describe an individual Narain theory leads to potentially non-local interactions in the bulk, responsible for "half-wormholes." After averaging over all theories these interactions vanish. The crucial difference with the JT gravity case is that in our case there is also a bona fide holographic description for an individual theory, described in section 4.1 above, though it does not involve a sum over topologies. It would be very interesting to make an explicit link between the two holographic descriptions for a given theory, by starting from CS theory on a given handlebody and deforming it into a sum over topologies with some non-local action.

Discussion
In this paper we considered Narain CFTs on Σ, and found that they are described by pure level-1 (U(1) × U(1)) n Chern-Simons theory on a 3d manifold M with ∂M = Σ. The details of M do not matter; all manifolds with ∂M = Σ lead to the same partition function because the Hilbert space of k = 1 CS theory is one-dimensional. The two U(1) n gauge fields are linked at the level of large gauge transformations. The choice of large gauge transformations, or, equivalently, the choice of boundary conditions changing the representation of the unique CS wavefunction, specifies the dual Narain theory. This provides a holographic duality, with the holographic dictionary as outlined in section 4.1. Our considerations were limited to genus one Σ, but it should be straightforward to extend the duality to arbitrary genus.
We then proceeded to consider an ensemble of Narain CFTs defined in terms of an ensemble of codes. We considered an ensemble of all even self-dual codes of length n over Z p × Z p for prime p, and then embedded (mapped) these codes into the c = n Narain moduli space. The embedding is specified by an arbitrary O ∈ O(n, n, R), thus any given code can be mapped to any given Narain theory. As n or p grows, the size of the ensemble given by (2.2) grows much faster than the dimension of O(n, n, R).
Hypothetically, in the p → ∞ limit, the ensemble of code theories densely covers the whole Narain moduli space with the canonical measure. For fixed n and p we find that the CFT partition function averaged over this ensemble is given by the level-p (U(1) × U(1)) n Chern-Simons theory summed over all classes of handlebody topologies that are distinguished by that theory. The main identity (4.17), valid for any fixed n, p and fixed embedding, establishes an explicit relation between averaging over the code-based ensemble and the "Poincaré series" representing the sum over topologies. Again, our explicit consideration was focused on genus one.
One of the questions our construction answers is why the "U(1)-gravity" of [3,4], though suggestive, has no well-defined microscopic bulk description. In section 4.4 we found that U(1)-gravity emerges as the p → ∞ limit of our construction, hence it is an infinite limit of a family of level-p pure Chern-Simons theories, which are all well-defined in the bulk. In our formalism the sum over bulk manifolds originates from a sum over SL(2, Z) transformations of a specific solid torus, and it is thus natural that we get a sum over just handlebodies and not other manifolds. Taking a leap to the holographic CFTs of [72], presumably dual to 3d quantum gravity with additional light matter, and the failure to find a dual to pure gravity due to intrinsic inconsistencies [60,61,[73][74][75][76], we can speculate that pure 3d quantum gravity might not be well defined by itself, but could emerge as an infinite limit of a family of well-defined theories.
From the mathematical point of view, our main technical result, equation (4.16), deserves a better understanding. It would be interesting to extend it to higher genus [57] and to disconnected manifolds. More generally, rewriting this equation in terms of sums over cosets or in terms of Hecke operators as was done in section 4.6 hints at a deeper mathematical structure. Beyond the Z k × Z k codes considered in this paper, the general code construction of [21] described in section 2.2 opens up possibilities for considering other types of code ensembles. Consideration of a variety of ensemble types could help answer a crucial question: when is an ensemble holographic, in the sense of admitting a bulk description in terms of a sum over geometries.
When the central charge is large c ≫ 1, ensembles of code CFTs or the ensemble of all Narain theories are self-averaging: a random theory faithfully captures the ensemble average up to exponentially small (in c) corrections. This suggests that individual theories, at least the sufficiently typical ones, should admit a bulk description in terms of a sum over topologies. We outline such a description in section 5, but notice that it suffers from ambiguities and possibly non-local interactions in the bulk. It would be very interesting to explicitly relate this bulk description, which includes the sum over topologies, to the conventional holographic description in terms of level-1 CS theory on a fixed topology, discussed in section 4.1.
Our work clarifies the role codes play in relation to CFTs and their holographic duals. We saw that all possible "words" label all possible wavefunctions in the bulk. We also saw that an ensemble of codes plays a crucial role in holography, although the reason why remains obscure. We emphasize that this is only one aspect of a more comprehensive story. We recall that the theory dual to the c = 1 compact scalar, the "AB" Chern-Simons theory, also emerges as a low energy limit of a 2+1 dimensional system describing Kitaev's toric code [77]. Is there a relation between the codes of this paper and the quantum codes underlying the "AB" theory? A first step connecting these two pictures was taken in [32] for the Z 2 × Z 2 case, where classical additive codes can be understood as quantum codes. More progress followed recently, relating quantum codes (connected to Z p × Z p classical codes in our nomenclature) to CFTs and Chern-Simons theories [37,39,43], but a complete picture is yet to emerge. The codes considered in this work are of additive type; consequently the corresponding CFTs are Abelian. There is a natural generalization of our story to non-Abelian codes, WZW theories and dual non-Abelian Chern-Simons theory [78]. Going in the direction of gradually generalizing the type of CFTs under consideration, one hopes to eventually arrive at codes associated with the conventional "Virasoro" CFTs, dual to quantum gravity. We can only speculate that at this point a direct link may emerge between the code structure on the CFT side and the holographic codes responsible for the locality in the bulk [29,79]. tute for Advanced Study for hospitality and sabbatical support, and the Simons Center for Geometry and Physics for hospitality during the 2023 Simons Summer Workshop.

A The compact scalar CFT
The compact scalar CFT of radius R is a two-dimensional theory of a real scalar field X, subject to the identification X ∼ X + 2πR, coupled to external gauge fields. The free scalar theory has a U(1) L × U(1) R global symmetry, and we call the corresponding charges Q andQ. We consider the Euclidean theory placed on a spacetime torus with modular parameter τ . The CFT partition function with fugacities (background gauge fields) ξ andξ is defined as a sum over the Hilbert space of the theory on a circle It can be readily evaluated [80] Z(τ, ξ,ξ, R) = n,m e iπτ p 2 The simultaneous reflection p R → −p R ,ξ → −ξ is a symmetry of Z, which is the T-duality exchanging R and 2/R, Z(τ, ξ,ξ, R) = Z(τ, ξ, −ξ, 2/R).
We would like to obtain the partition function (A.2) from the path integral formulation. We parametrize the spacetime torus by a complex coordinate z, with the notation where the integrals are over the torus. The scalar field X(z,z) is periodic up to identifications, The sign of n 2 is chosen for convenience. One way of coupling the theory to a background gauge field is by the action where A is an external U(1) gauge field coupling to a specific combination of the global symmetries and satisfying dA = 0. Using the background field gauge freedom we can choose to be constant on the torus. For a real background field A, ξ andξ are complex conjugate to each other, ξ * =ξ. The theory is free (quadratic), so the partition function can be computed straightforwardly. We should sum over on-shell configurations satisfying (A.6), and the small fluctuations around the classical solutions contribute a multiplicative factor, that includes the Dedekind eta-function [80]. The full expression for the path integral is then which is just the relabeling of spacetime coordinates, amended by a dilatation (which acts trivially since the theory is conformal). To find the relation between the path integral (A.10) and the partition function (A.1), we perform a Poisson resummation in (A.2) over n, which readily yields (A.13) Alternatively we can couple a background gauge field B to a different combination of the U(1) global symmetries by (A.14) We assume dB = 0 and use the background gauge symmetry to parametrize the background gauge field by In this case for real B we have ξ * = −ξ, and large gauge transformations take , and act as Clearly, the path integral is invariant under large gauge transformations (A. 16), and is also modular invariant. A comparison with Z PI yields Z PI = Z PI ′ e 2π τ 2 ξξ , and 18) in agreement with Appendix A of [49]. The two path integrals above are particular sections ξ * = ±ξ of a more general theory coupled to two gauge fields, A and B, combined into one complex combination The "symmetric" choice κ = 1 corresponds to the bulk path integral discussed in the bulk of the paper It is both modular-invariant and T-duality-invariant, and it changes covariantly (but is not invariant) under large gauge transformations of the form

B Chern-Simons theory: technical details
In this section we provide additional details accompanying section 3. Our starting point is the U(1) gauge field A living on a three-manifold M as in subsection 3.2. We focus on the case when ∂M is a two-dimensional torus, with the same notation as in Appendix A above. The bulk theory is invariant under large gauge transformations A → A + ω in (3.8) when ω is a canonically normalized cohomology on ∂M, namely ω = dφ where φ is a multi-valued function winding along the cycles of ∂M. When ∂M is a two-dimensional torus as above, we have explicitly φ = 2π (n+mτ )z−(n+mτ )z Thus the bulk theory is gauge-invariant for even k, while pure sign phase factors appear for odd k, related to the need to choose a spin structure.
In the U(1) × U(1) case of subsection 3.3, there are two gauge fields A, B subject to large gauge transformations A → A + ω A , B → B + ω B , where ω A,B = dφ A,B are defined in Appendix A above.
To obtain the explicit form of the Wilson loop operators acting on the wavefunction in the holomorphic representation (3.12), we take into account that Az (understood as a quantum operator) acts on ket vectors by multiplication, Az|Ψ = iπξ τ 2 Ψ(ξ), and hence A z acts on bra vectors analogously Ψ|A z = (Ψ(ξ) iπ τ 2 ξ) * . From here and by integrating by parts in (B.2) we find which is used in (3.12). As we explained in the main text, this is in agreement with A z being canonically conjugate to Az, as follows from the Chern-Simons equations of motion [47].

C Narain c = 2 theories
The partition function Z c=2 (τ, t, b) of a central charge c = 2 Narain theory depends on three modular parameters, τ and t, b introduced in (4.27). It can be written explicitly using the representation (5.2): Z c=2 (τ, t, b) = b 2 τ 2 |η(τ )| 4 n, m∈Z 2 e − π τ 2 |γ( nτ + m)| 2 −2πi b 1 n∧ m . (C.1) The moduli space of c = 2 Narain theories is a product of two fundamental domains of t and b, with the canonical SL(2, Z)-invariant measure, modulo Z 2 exchange symmetry. It is convenient to introduce which is modular invariant under t, b and is a weight 2 modular form with respect to τ . The modular invariant combinationẐ = τ 2 Θ c=2 is the partition function of primaries; it exhibits triality -full permutation symmetry under its arguments τ, t, b [9] -which is not manifest in the representation (C.1).

The origin
The contribution of the origin is simply b 2 τ 2 |η(τ )| 4 . (C.13) It is t-independent. Obviously, it remains the same after averaging over t.

Contribution of the single vector orbits
The starting point is to parametrize collinear n = c ℓ and m = d ℓ using a co-prime pair (c, d) = 1 and an arbitrary non-zero vector ℓ ∈ Z 2 . The resulting sum is (C.14) Next, we parametrize a non-zero ℓ = (d,c)k with co-prime (c,d) = 1 and an arbitrary non-zero integer k to find Here we readily recognize t ′ 2 (c,d) = t 2 /|ct +d| 2 as being generated by a modular transformation of t. Though originally t belonged to the fundamental "keyhole domain", the sum over co-prime pairs (c,d) = 1 extends the range of t ′ to the entire strip |t 1 | ≤ 1/2, t 2 ≥ 0. Averaging over t thus gives (C. 16) Going back to (C.14), we find the single-vector contribution, averaged over the fundamental domain of t, to be (c,d)=1 1 |η(τ )| 4 |cτ + d| 2 . (C.17) Of course this is merely a formal expression as it is divergent. Following [66] we can regularize it by multiplying (C.15) by (1 − e −Nt/t ′ 2 ) where N t → ∞ is a regulator. As a result we have instead of (C.17) ) .

Contribution of the two vector orbits
Our final step is the two-vector contribution with non-collinear n and m. We can start with the same parametrization as above, n = (d,c)k with co-prime (c,d) = 1 and nonzero k. Then by applying a (non-unique) SL(2, Z) transformation parametrized by (c,d) acting on the vectors n and m we can bring the first vector to the form n = (k, 0): Here the matrix γ ′ is defined the same way as in (4.27), but with t transformed by an SL(2, Z) matrix parametrized by (c,d). As in the previous subsection, the sum over (c,d) extends the domain of t from the "keyhole" region to the strip |t 1 | ≤ 1/2, t 2 > 0.
Let us now write m = (d ′ , c ′ ). Then the two-vector contribution averaged over the fundamental region of t is 3 π In the sum above we must keep c ′ = 0 lest the vectors n, m become collinear. The sum over d ′ is not restricted. We can represent it as d ′ = c ′ r + d ′′ where r ∈ Z and d ′′ is an integer between 0 and c ′ − 1. We can now combine 22) and the sum over r plus the integral over the strip |t 1 | ≤ 1/2, t 2 > 0 become an integral over the whole upper half-plane of t ′ . The dependence on d ′′ disappears and the sum over d ′′ simply gives a factor of |c ′ |, At this point we can integrate over t 2 , There are four "branches" with positive and negative k and c ′ , which we combine into a sum of the form 6 πτ 2 |η(τ )| 4 k>0 c ′ >0 e 2πi b kc ′ + e 2πib kc ′ k . (C.25) Now we introduce q b = e 2πib and sum over k using Finally, we find for the two-vector contribution, averaged over t, Combining everything together, we find that the first term in (C.27) exactly cancels the "origin" contribution (C.13). Hence, Z c=2 averaged over the modular parameter t and covariantly regularized is where N t → ∞ is a regulator and N 0 = 4πe −2γ . The final expression is in full agreement with (C.11).

C.4 Large-p limit
To evaluate the large-p limit of T pẐ we first approximate it by the regularized integral over the fundamental domain (C.29) The value of N can be fixed as follows. Modular transformations mapping (τ + k)/p back to the fundamental keywhole domain F will be more dense in the region of small τ ′ 2 , with only one point reaching the maximal value of τ ′ 2 = p/τ 2 . Thus we can take N ∝ p/τ 2 , leading to, c.f. (C.11),