Black Box Galois Representations

We develop methods to study $2$-dimensional $2$-adic Galois representations $\rho$ of the absolute Galois group of a number field $K$, unramified outside a known finite set of primes $S$ of $K$, which are presented as Black Box representations, where we only have access to the characteristic polynomials of Frobenius automorphisms at a finite set of primes. Using suitable finite test sets of primes, depending only on $K$ and $S$, we show how to determine the determinant $\det\rho$, whether or not $\rho$ is residually reducible, and further information about the size of the isogeny graph of $\rho$ whose vertices are homothety classes of stable lattices. The methods are illustrated with examples for $K=\mathbb{Q}$, and for $K$ imaginary quadratic, $\rho$ being the representation attached to a Bianchi modular form. These results form part of the first author's thesis.


Introduction
Let K be a number field. Denote by K the algebraic closure of K and by G K = Gal(K/K) the absolute Galois group of K. By an -adic Galois representation of K we mean a continuous representation ρ : G K → Aut(V ), where V is a finite-dimensional vector space over Q , which is unramified outside a finite set of primes of K. Such representations arise throughout arithmetic geometry, where typically V is a cohomology space attached to an algebraic variety. For example, modularity of elliptic curves over K can be interpreted as a statement that the 2-dimensional Galois representation arising from the action of G K on the -adic Tate module of the elliptic curve is equivalent, as a representation, to a representation attached to a suitable automorphic form over K. In this 2-dimensional context and with = 2, techniques have been developed by Serre [15], Faltings, Livné [13] and others to establish such an equivalence using only the characteristic polynomial of ρ(σ) for a finite number of elements σ ∈ G K . Here the ramified set of primes S is known in advance and the Galois automorphisms σ which are used in the Serre-Faltings-Livné method have the form σ = Frob p where p is a prime not in S, so that ρ is unramified at p.
Motivated by such applications, in this paper we study Galois representations of K as "Black Boxes" where both the base field K and the finite ramified set S are specified in advance, and the only information we have about ρ is the characteristic polynomial of ρ(Frob p) for certain primes p not in S; we may specify these primes, but only finitely many of them. Using such a Black Box as an oracle, we seek to give algorithmic answers to questions such as the following (see the following section for definitions): • Is ρ irreducible? Is ρ trivial, or does it have trivial semisimplification?
• What is the determinant character of ρ?
• What is the residual representation ρ? Is it irreducible, trivial, or with trivial semisimplification?
• How many lattices in V (up to homothety) are stable under ρ -in other words, how large is the isogeny class of ρ?
In the case where dim V = 2 and = 2, we give substantial answers to these questions in the following sections. In Section 2 we recall basic facts about Galois representations and introduce key ideas and definitions, for arbitrary finite dimension and arbitrary prime . From Section 3 on, we restrict to = 2, first considering the case of one-dimensional representations (characters); these are relevant in any dimension since det ρ is a character. Although in the applications det ρ is always a power of the -adic cyclotomic character of G K , we will not assume this, and in fact the methods of Section 3 may be used to prove that the determinant of a Black Box Galois representation has this form. From Section 4 we restrict to 2-dimensional 2-adic representations, starting with the question of whether the residual representation ρ is or is not irreducible (over F 2 ), and what is its splitting field (see Section 2 for definitions); a complete solution is given for both these questions, which we can express as answering the question of whether or not the isogeny class of ρ consists of only one element. In Section 5 we consider further the residually reducible case and determine whether or not the isogeny class of ρ contains a representative with trivial residual representation, or equivalently whether the size of the class is 2 or greater. In Section 6 we assume that ρ is trivial modulo 2 k for some k ≥ 1 and determine the reduction of ρ (mod 2 k+1 ) completely, in particular whether it too is trivial. Hence, for example, we can determine ρ (mod 4) when ρ is trivial, and also as a final application, in Section 7 we give a (finite) criterion for whether ρ has trivial semisimplification.
For each of these tasks we will define a finite set T of primes of K, disjoint from S, such that the Black Box information about ρ(Frob p) for p ∈ T is sufficient to answer the question under consideration. In each case except for the criterion for ρ to have trivial semisimplification, only finite 2-adic precision is needed about the determinant and trace of ρ(Frob p), though we note that in the applications the 2-adic representation inside the Black Box is always part of a compatible family of -adic representations, so that in practice these are rational or algebraic integers and will be known exactly.
The following theorem summarises our results; we refer to later sections for the definitions of the sets T 0 , T 1 and T 2 and for algorithms to compute them.
Here F p (t) denotes the characteristic polynomial of ρ(Frob p) (see (1) below), for a prime p / ∈ S. Theorem 1.1. Let K be a number field and S a finite set of primes of K.
There exist finite sets of primes T 0 , T 1 and T 2 , disjoint from S, depending only on K and S, such that for any 2-dimensional 2-adic Galois representation ρ of G K which is continuous and unramified outside S, 1. the reducibility of the residual representation ρ, and its splitting field when irreducible, are uniquely determined by the values of F p (1) (mod 2), i.e., by the traces of ρ(Frob p), for p ∈ T 0 ; 2. the determinant character det ρ is uniquely determined by the values of F p (0) = det ρ(Frob p) for p ∈ T 1 ; 3. when ρ is reducible, • the existence of an equivalent representation whose residual representation is trivial is determined by the values of F p (1) (mod 4) for p ∈ T 2 ; • if ρ (mod 2 k ) is trivial for some k ≥ 1, the reduction ρ (mod 2 k+1 ) is uniquely determined by the values of F p (1) (mod 2 2k+1 ) for p ∈ T 2 ; in particular, there is an equivalent representation which is trivial modulo 2 k+1 if and only if F p (0) ≡ 1 (mod 2 k+1 ) and F p (1) ≡ 0 (mod 2 2k+2 ) for all p ∈ T 2 ; • ρ has trivial semisimplification if and only if F p (t) = (t − 1) 2 for all p ∈ T 2 ; that is if and only if tr ρ(Frob p) = 2 and det ρ(Frob p) = 1 for all p ∈ T 2 .
In each section we give examples to illustrate the methods, first from elliptic curves defined over Q, and then in the final section, we give two examples arising from Bianchi modular forms, and elliptic curves over imaginary quadratic fields.
In the examples we refer to elliptic curves and Bianchi modular forms using their LMFDB labels (see [14]) giving links to the relevant object's home pages at www.lmfdb.org.

Remarks on complexity
Although Theorem 1.1 only states the existence of sets of primes with certain properties, we will provide algorithms to compute these, which we have implemented in order to produce examples (see below). It is natural, therefore, to ask about the complexity of these algorithms. We will not make a precise statement here: as with essentially all algorithms in algebraic number theory, our algorithms are exponential in the size of the input, as they require basic knowledge of the ground field K such as its rings of integers, class group and unit group. Computing these from a polynomial defining K was shown to be exponential by Lenstra in [12]. Secondly, our residual reducibility test requires us to be able to enumerate all extensions of K unramified outside S and with Galois group C 2 , C 3 , or S 3 . As this is a standard problem we do not give details of this here, but note that except for fields of small degree and discriminant, and small sets of primes S, this is likely to be the slowest step in the overall algorithm. Computing the 2-Selmer group K(S, 2) of a number field K (see (2) below) can be highly non-trivial, even for fields K of moderate degree and assuming the Generalised Riemann Hypothesis. Lastly, even if all the necessary arithmetic data for K is provided as part of the input, our algorithms rely on being able to find primes satisfying the conditions for the sets T i . In all cases, there are infinitely many primes with the desired properties, and below we give the (positive) Dirichlet density of the sets concerned as an informal indication of how hard finding the primes will be. Explicit estimates exist (at least for K = Q) for how large the smallest primes with the desired property may be, but in practice, for examples where the previous steps are possible in reasonable time, we are able to find these primes easily. Both the number of primes in the sets T i and their size (or norm) are relevant in applying these algorithms, since in practice the work which the Black Box needs to carry out can be considerable 1 .

Implementation
We have implemented all the algorithms described in the paper in Sage (see [7]). The code, some of which will be submitted for inclusion into a future release of Sage, is available at [1]. This includes general-purpose code for computing the test sets T 0 , T 1 and T 2 from a number field K and a set S of primes of K, and also worked examples which reproduce the examples we give in the text.

Background on Galois representations
Fix once and for all a number field K and a finite set S of primes of K. Definition 2.1. An -adic Galois representation over K is a continuous homomorphism ρ : G K → Aut(V ) ∼ = GL 2 (Q ), where V is a finite-dimensional vector space over Q . Such a representation is said to be unramified outside S, if its restriction to the inertia subgroup at each p / ∈ S is trivial.
We do not assume that the representation ρ is irreducible. The condition that ρ is unramified outside S means that for each p / ∈ S, it factors through the Galois group Gal(L/K) of the maximal extension L of K unramified at p. Since L/K is unramified at p, there is a well-defined conjugacy class of Frobenius automorphisms at p, denoted Frob p, in Gal(L/K), so that for all σ ∈ Frob p, the values of ρ(σ) are conjugate in Aut(V ) and hence the characteristic polynomial of ρ(σ) is well-defined. By abuse of notation, we write ρ(Frob p) for ρ(σ) for any choice of σ in this class, and denote its characteristic polynomial by F p (t). Moreover, by theČebotarev Density Theorem, for every automorphism σ ∈ G K there are infinitely many p / ∈ S for which ρ(σ) = ρ(Frob p).
From now on we only consider 2-dimensional representations. Choosing a basis for V we may express each ρ(σ) as a matrix, and hence consider ρ to be a matrix representation G K → GL 2 (Q ). Moreover with different choices of bases we obtain equivalent matrix representations. For σ ∈ G K define F σ (t) to be the characteristic polynomial of ρ(σ), which is a well-defined monic quadratic polynomial in Z [t], and for each prime p / ∈ S we set F p = F Frob p , the Frobenius polynomial at p, which is also well-defined: The fact that these polynomials have integral coefficients follows from the existence of a stable lattice in V , as we recall below. The information about the representation ρ that we assume will be provided consists of the set S and the values of det(ρ(σ)) and tr(ρ(σ)) for σ = Frob p ∈ G K and p ∈ S. We encapsulate this setup as an oracle, or Black Box : 2. An -adic Black Box Galois representation over K with respect to S is an oracle which, on being presented with a prime p of K, responds with either "ramified" if p ∈ S, or with the value of the quadratic Frobenius Equivalently, the Black Box delivers for each p / ∈ S the values of the trace tr(ρ(Frob p)) ∈ Z and the determinant det(ρ(Frob p)) ∈ Z * .

Stable lattices and the Bruhat-Tits tree
It is well known [16, p.1] that continuity of ρ implies the existence of at least one stable lattice Λ, i.e., a free Z -submodule of V of full rank such that ρ(σ)(Λ) ⊆ Λ for all σ ∈ G K . With respect to a Z -basis of Λ, ρ determines an integral matrix representation ρ Λ : G K → GL 2 (Z ). Any lattice homothetic to a stable lattice is also stable and induces the same integral matrix representation. Changing to a different Z -basis of Λ gives rise to an equivalent integral representation (conjugate within GL 2 (Z )). The existence of a stable lattice shows that the Frobenius polynomials F p (t) have coefficients in Z .
If we change to a different stable lattice Λ ⊂ V which is not homothetic to Λ, however, the integral representation ρ Λ we obtain, while rationally equivalent to ρ Λ (conjugate within GL 2 (Q )), is not necessarily integrally equivalent (conjugate within GL 2 (Z )). Integral representations related in this way (rationally but not necessarily integrally equivalent) are called isogenous. As we are assuming that the only information we have about ρ (for fixed K and S) are the characteristic polynomials of ρ(Frob p) for primes outside S provided by the Black Box, we cannot distinguish isogenous integral representations, but still hope to be able to say something about the set of all of those isogenous to a given one. Definition 2.3. The isogeny class of ρ is the set of pairs (Λ, ρ Λ ) where Λ is a stable lattice and ρ Λ the induced map G K → Aut(Λ), modulo the equivalence relation which identifies homothetic lattices.
For each choice of stable lattice and induced integral representation we can define its associated residual representation.
Definition 2.4. Let ρ : G K → Aut(V ) be an -adic Galois representation. To each stable lattice Λ ⊂ V the associated residual representation ρ Λ is the com- In matrix terms, ρ Λ : G K → GL 2 (F ) is obtained by composing the integral matrix representation ρ Λ : G K → GL 2 (Z ) with reduction modulo .
We cite the following facts (see [16, p.3] for the second one): • ρ is irreducible if and only if the number of stable lattices, up to homothety, is finite; that is, if and only if the isogeny class of ρ is finite.
• Let Λ be any stable lattice. Then the residual representation ρ Λ is irreducible over F if and only if Λ is the only stable lattice up to homothety. In other words, the residual representation is irreducible if and only if the isogeny class consists of a single element, in which case there is of course only one residual representation up to conjugacy in GL 2 (F ).
From the second fact we see that either all the residual representations are reducible, or none of them are; in the latter case there is only one stable lattice up to homothety anyway. Thus it makes sense to describe ρ as "residually reducible" or "residually irreducible" respectively. Recall that the -adic Bruhat-Tits tree is the infinite graph whose vertices are the homothety classes of lattices in V ∼ = Q 2 , with two vertices joined by an edge if their classes have representative lattices Λ 1 , Λ 2 such that Λ 1 contains Λ 2 with index . (This is a symmetric relation since then Λ 2 contains Λ 1 with index .) Each vertex has degree exactly + 1. Restricting to lattices which are stable under our representation ρ, we obtain the following: Definition 2.5. The stable Bruhat-Tits tree or isogeny graph of an -adic representation ρ is the full subgraph BT(ρ) of the Bruhat-Tits tree whose vertices are stable lattices.
It is easy to see that if [Λ] and [Λ ] are stable homothety classes, all vertices in the unique path between them are also stable: we may choose representatives Λ, Λ in their homothety classes such that Λ ⊆ Λ and the quotient Λ /Λ is cyclic, of order n for some n ≥ 0. Now this quotient has a unique subgroup of each order k for 0 ≤ k ≤ n, corresponding to a lattice Λ with Λ ⊆ Λ ⊆ Λ , and by uniqueness, each such Λ is stable.
Hence the stable Bruhat-Tits tree is indeed a tree. Its vertex set is the isogeny class of ρ as defined above, and we may refer to its edges as -isogenies. Given two adjacent stable lattices, we may choose bases so that the associated integral matrix representations are conjugate within GL 2 (Q ) via the matrix 0 0 1 . In BT(ρ) it is no longer the case that every vertex has degree + 1; considering the action of GL 2 (F ) on P 1 (F ) we see that for = 2 the possible degrees are 0, 1 and 3 while for ≥ 3 the possible degrees are 0, 1, 2 and + 1.
We define the width of the isogeny class BT(ρ) to be the length of the longest path in BT(ρ); by the facts above, this is finite if and only if ρ is irreducible, and is positive if and only if ρ is residually reducible.

Characters and quadratic extensions
The problem of distinguishing continuous 2-adic characters (1-dimensional representations) χ : G K → Z * 2 reduces to that of distinguishing quadratic extensions of K, since Z * 2 is an abelian pro-2-group. Moreover, the image of ρ in GL 2 (Z 2 ) is itself a pro-2-group in the case that the residual representation is reducible, so the technique we describe in this section will be used later to study both det ρ and ρ itself in the residually reducible case.
There are only finitely many quadratic extensions L of K unramified outside S; their compositum is the maximal extension of K unramified outside S and with Galois group an elementary abelian 2-group. Each has the form L = K( √ ∆) for a unique ∆ ∈ K(S, 2) ≤ K * /(K * ) 2 , where K(S, 2) is the subgroup (often called the 2-Selmer group of K, or of K * ) given by Moreover, when S contains all primes of K dividing 2, every extension K( √ ∆) with ∆ ∈ K(S, 2) is unramified outside S. In general the ∆ such that K( √ ∆) is unramified outside S form a subgroup K(S, 2) u of K(S, 2). We will call elements of K(S, 2) u discriminants, and always regard two discriminants as equal when their quotient is a square in K * . It is convenient here to consider ∆ = 1 as a discriminant, corresponding to the trivial extension L = K.
The group of discriminants K(S, 2) u is an elementary abelian 2-group, of cardinality 2 r with r ≥ 0, and may also be viewed as an r-dimensional vector space over F 2 . Fixing a basis {∆ i } r i=1 for K(S, 2) u , we may identify

Linearity follows from the relation [∆∆ |p] = [∆|p] + [∆ |p].
For any prime p / ∈ S, we define Conversely, for each subset I ⊆ {1, ..., r}, we denote by p I any prime such that I(p I ) = I, so that When I = {i} or I = {i, j} with i = j, we simply write p i = p {i} and p ij = p {i,j} . By theČebotarev Density Theorem applied to the compositum of the extensions K( √ ∆) for ∆ ∈ K(S, 2) u , the set of primes of the form p I has density 1/2 r for each subset I, and in particular is infinite.
Each set of primes of the form {p i | 1 ≤ i ≤ r} determines a basis {α pi | 1 ≤ i ≤ r} for the dual space K(S, 2) * u = Hom F2 (K(S, 2) u , F 2 ), and may be used to distinguish between two characters unramified outside S. More generally we make the following definition.
Definition 3.1. A set T 1 of primes of K is linearly independent with respect to S if T 1 is disjoint from S and the linear functions {α p | p ∈ T 1 } form a basis for the dual space K(S, 2) * u .
As observed above, such a set always exists, for example any set of the form defined above with respect to a basis of K(S, 2) u , is a linearly independent set of primes. We fix once and for all a linearly independent set of primes, and denote it by T 1 , and can assume that {α p | p ∈ T 1 } is a dual basis for the chosen basis {∆ i | 1 ≤ i ≤ r} for K(S, 2) u . In practice this is most easily done by computing T 1 = {p 1 , . . . , p r } first, and then taking {∆ i } to be the basis dual to {α pi } (see Algorithm 1 below). We then see by (5) that for all I ⊆ {1, 2, . . . , r}, Algorithm 1: To determine a linearly independent set T 1 of primes of K. Input : A number field K.
A finite set S of primes of K. Output: T 1 = {p 1 , . . . , p r }, a set of primes of K linearly independent with respect to S, and a basis for K(S, 2) u dual to T 1 .
Let p be a prime not in S ∪ T 1 ; In line 5 of the algorithm, and similarly with later algorithms to determine other special sets of primes, we systematically consider all primes of K in turn, for example in order of norm, omitting those in S.
In line 10, we adjust the initial basis for K(S, 2) u to one which is dual to the computed set T 1 ; this is more efficient than fixing a basis for K(S, 2) u and looking for primes which form a dual basis.
Methods for computing K(S, 2) are based on the short exact sequence where O * K,S is the group of S-units and C K,S [2] is the 2-torsion subgroup of the S-class group C K,S of K. They therefore rely on being able to compute the unit group and class group.

Identifying quadratic extensions
As an easy example of how to use a set T 1 of primes linearly independent with respect to S, we may identify any extension L/K known to be of degree at most 2 and unramified outside S. Enumerating T 1 = {p 1 , . . . , p r } and the dual basis . The proof is clear from the fact that L is uniquely determined by the set of primes which split in L/K. In particular, L = K if and only if all primes in T 1 split.

1-dimensional Galois representations
We first consider additive quadratic characters α : G K → F 2 which are unramified outside S, and see that a linear independent set T 1 can determine whether such a character is trivial, and more generally when two are equal.
Proof. If α = 0, then the fixed field of ker(α) is a quadratic extension K( √ ∆) for some non-trivial ∆ in K(S, 2). But [∆|p] = α(Frob p) = 0 for all p ∈ T 1 , which implies that ∆ = 1. For the second part, consider α = α 1 − α 2 . Now let χ : G K → Z * 2 be a 2-adic character unramified outside S. For example we may take χ = det ρ where ρ is a 2-adic Galois representation unramified outside S. Again, to show triviality of χ, or equality of two such characters, it is enough to consider their values on Frob p for p ∈ T 1 . Theorem 3.4. Let χ, χ 1 , χ 2 : G K → Z * 2 be continuous characters unramified outside S. Let T 1 be a linearly independent set of primes with respect to S.

Determining the residual representation
Given a Black Box Galois representation ρ, we would like to determine whether its residual representations are irreducible or reducible. Recall that this is a well-defined question, even when there is more than one stable lattice. In the irreducible case, we will moreover determine the (unique) residual representation completely, both its image (which has order 3 or 6, and is isomorphic to either C 3 (the cyclic group of order 3) or S 3 (the symmetric group of degree 3)), and the fixed field of its kernel. Note that GL 2 (F 2 ) ∼ = S 3 , the isomorphism coming from the action of GL 2 (F 2 ) on P 1 (F 2 ). This is our initial step in determining the size and structure of the attached Bruhat-Tits tree BT(ρ), as we will determine whether it has only one vertex (and width 0) or is larger (positive width).
Fixing one stable lattice Λ with residual representation ρ Λ , we define the splitting field of ρ Λ to be the fixed field of its kernel. This is an extension L of K which is unramified outside S such that Gal hence Gal(L/K) is isomorphic to one of: C 1 (the trivial group), C 2 (cyclic of order 2), C 3 or S 3 . The first two cases occur when ρ Λ is reducible, in which case a different choice of stable lattice may change the image between being trivial and of order 2, while in the residually irreducible case the image and kernel are both well-defined.
We now show how to identify the residual splitting field, leaving until a later section the task of saying more in the reducible case.

Identifying cubic extensions
The key to our method is that there are only finitely many Galois extensions L/K, unramified outside S, and with Galois group either C 3 or S 3 , and we may determine these algorithmically. We will not discuss here details of this, except to remark that in the S 3 case we can first construct all possible quadratic extensions K( √ ∆) using ∆ ∈ K(S, 2) u as in the previous section, and then use either Kummer Theory or Class Field Theory to construct all cyclic cubic extensions of K or K( √ ∆). Full details of the Kummer Theory method, using special cases of results by Cohen [5], can be found in [11, §3] (see also Koutsianas's thesis [10]); we have an implementation of this method in Sage. An alternate implementation, using Class Field Theory, was written in Pari/GP by Pacetti, as used in [8] in the case where K is an imaginary quadratic field. These implementations were used for the examples below.
For present purposes, we assume that, given K and S, we can write down a finite set F of irreducible monic cubic polynomials in O K [x], whose splitting fields are the Galois extensions L/K unramified outside S with Gal(L/K) isomorphic to either S 3 or C 3 . Note that the discriminants of the polynomials in F may be divisible by primes not in S, and these primes will need to be avoided, so we denote by S(F) the union of S with all prime divisors of We can characterise the fields L by examining the splitting behaviour of primes p ∈ S(F), which depends only on the factorisation of the respective f ∈ F modulo p.
This definition is motivated by the observation that elements of GL 2 (F 2 ) have trace 1 (respectively, 0) if their order is 3 (respectively, 1 or 2), combined with the following result from elementary algebraic number theory.
Hence, if our Black Box representation ρ has irreducible residual representation with residual splitting field defined by the cubic f , we will have This underlies our algorithm for testing residual irreducibility: see Proposition 4.5. To this end, we now define a finite set of primes which can distinguish between the possible splitting fields L. (2) the vectors (λ(f, p 1 ), ..., λ(f, p t )) ∈ F t 2 for f ∈ F are distinct and non-zero.
Lemma 4.4. A distinguishing set of primes for (F, S) exists.
be the set of monic cubic polynomials defining the S 3 and C 3 extensions of K. Set f 0 = x 3 and define λ(f 0 , p) = 0 for all p. It is enough to show that for all 0 ≤ j < i ≤ n there exists a prime p ∈ S(F) such that λ(f i , p) = λ(f j , p). For i ≥ 1 let L i be the splitting field of f i . We divide the proof into three cases. (For more details of the density calculations, see [2, p. 21, Lemma 3.2.5].) Case 1: When j = 0, we require for each i ≥ 1 the existence of a prime p such that λ(f i , p) = 1. By theČebotarev Density Theorem, there are infinitely many such primes, with density 1 3 when Gal(L i /K) ∼ = S 3 , or 2 3 when Gal(L i /K) ∼ = C 3 . Case 2: When i > j ≥ 1 and disc(L i ) ≡ disc(L j ) (mod (K * ) 2 ), the fields L i and L j are disjoint. Then there are three possibilities for the Galois group of their compositum, according to whether the discriminants are trivial (i.e., square). In each case there are infinitely many primes which fulfill the condition, with density 4 9 when Gal(L i L j ) ∼ = S 3 × S 3 , and 5 9 when Gal(L i L j ) is S 3 × C 3 . Case 3: When i, j ≥ 1 and disc(L i ) ≡ disc(L j ) (mod (K * ) 2 ) we have two possibilities; the density is 4 9 when both Galois groups are isomorphic to C 3 and is 2 9 when both are isomorphic to S 3 . A distinguishing set T 0 of primes can be computed using the following algorithm. The size t of T 0 depends on the total number n of C 3 and S 3 extensions of K unramified outside S, and there exists such a set for which log 2 (n) ≤ t ≤ n − 1.

Algorithm 2:
To determine a distinguishing set T 0 of primes of K.
. . , f n } of cubics defining C 3 and S 3 extensions of K unramified outside S. Output: T 0 , a distinguishing set of primes for (F, S).

Determining residual irreducibility and splitting field
As above, let ρ be a Black Box 2-adic Galois representation over K unramified outside S, let F = {f 1 , . . . , f n } be a set of irreducible cubics defining all C 3 and S 3 extensions of K unramified outside S, and let T 0 be a distinguishing set of primes for (F, S). For 1 ≤ i ≤ n let L i be the splitting field of f i over K, and let L be the residual splitting field of ρ with respect to one stable lattice.
Proposition 4.5. With notation as above, 1. If [L : K] = 6 or 3 then, for exactly one value i ≥ 1, we have L = L i and for all p ∈ S(F). Moreover, for infinitely many primes p we have tr(ρ(Frob p)) ≡ 1 (mod 2).

[L : K] ≤ 2 if and only if
Proof. Suppose that [L : K] = 6 or 3. Then the image of ρ is C 3 or S 3 and L = L i , the splitting field of f i , for some i, 1 ≤ i ≤ n. Hence for all p / ∈ S(F), by Lemma 4.2, we have On the other hand, if [L : K] ≤ 2, the image of ρ is either C 1 or C 2 . Hence tr(ρ(Frob p)) ≡ 0 (mod 2) for all p ∈ S.
Note that irreducibility of the residual representation can be established with a single prime p such that tr(ρ(Frob p)) is odd. Using this proposition, we can achieve more: first, that for ρ to be reducible it suffices to check that tr(ρ(Frob p)) is even for a finite set of primes, those in T 0 ; secondly, that when they are not all even, the values of tr(ρ(Frob p)) (mod 2) for p ∈ T 0 identify the residual image precisely as C 3 or S 3 , and also identify the splitting field exactly. Moreover both the set of cubics F and the distinguishing set T 0 depend only on K and S and so may be computed once and then used to test many representations ρ with the same ramification restrictions. The main result of this section is as follows.
Theorem 4.6. Let K be a number field, S a finite set of primes of K, and let ρ be a continuous 2-dimensional 2-adic Galois representation over K unramified outside S. Let T 0 be a distinguishing set for S in the sense of Definition 4.3.
1. The finite set of values of tr(ρ(Frob p)) (mod 2), for p ∈ T 0 , determine the residual representation ρ up to semisimplification. Hence (up to semisimplification) ρ may be identified from its Black Box presentation.
2. In particular, the residual representation ρ has trivial semisimplification (equivalently, is reducible over F 2 ), if and only if for 1 ≤ i ≤ n are distinct and non-zero by definition of T 0 . Using the Black Box, we compute the vector v = (tr(ρ(Frob p 1 )), ..., tr(ρ(Frob p t ))) ∈ F t 2 .
By Proposition 4.5, we have (with L and L i as defined there) Hence ρ is irreducible if and only if v = v i for some i, in which case its splitting field is that of f i and its image is isomorphic to S 3 , unless disc f i ∈ (K * ) 2 in which case the image is C 3 . Otherwise, v = 0 and ρ is reducible, with trivial semisimplification.
Algorithm 3: To determine the residual image of an integral 2-adic Galois representation, up to semisimplification. Input : A number field K.
A finite set S of primes of K.
A Black Box Galois representation ρ unramified outside S.
Here we could have considered the curves up to isogeny and up to quadratic twist, since quadratic twists obviously have the same mod 2 representation. The number of cases then reduces to 22 (6 reducible and 1, 11, and 4 for each irreducible case).

Determining triviality of the residual representation up to isogeny
Let ρ : G K → GL 2 (Z 2 ) be a continuous Galois representation unramified outside S with reducible residual representation. Depending on the choice of stable lattice Λ, the order of ρ Λ (G K ) ≤ GL 2 (F 2 ) is either 1 or 2, though the semisimplification of ρ Λ is always trivial. In this section we will give a method to decide whether within the isogeny class of ρ there is an integral representation ρ Λ whose residual representation ρ Λ is trivial. If this is the case, it follows from the remarks about the isogeny graph at the end of Section 2 that the corresponding vertex in the isogeny graph BT(ρ) has degree 3, the width of the graph is at least 2, and it contains at least 4 vertices; otherwise, its width is 1 and it consists of just two vertices linked by a single edge. We call these large and small isogeny classes respectively. Vertices of BT(ρ) either have degree 1, non-trivial residual representation, and quadratic splitting field with non-trivial discriminant in K(S, 2) u ; or degree 3 and trivial residual representation. So each vertex of BT(ρ) has an associated discriminant, and we would like to describe the graph structure of BT(ρ)the number of vertices, and width-as well as the discriminants of its extremal (degree 1) vertices.
In this section we show how to distinguish the small and large cases; in Section 6 we will continue under the assumption that the class is large. The following notation will be useful for the tests we will develop; note that since we are now assuming that ρ is residually reducible, tr(ρ(Frob p)) ≡ 0 (mod 2) for all p / ∈ S so that F p (1) ≡ 0 (mod 2). Define v(p) = ord 2 (F p (1)).
so that t k (p) = 0 if and only if v(p) ≥ k + 1. Write t k (σ) = t k (p) when σ = Frob p.

The test function for small isogeny classes
Let Λ 1 be a stable lattice under the action of ρ. Since ρ is reducible, there is an index 2 sublattice Λ 2 which is also stable under ρ. Choosing the bases Λ 1 = v, w and Λ 2 = v, 2w we have that for all σ ∈ G K . (Here we are showing matrices with respect to the basis v, w , and our convention is that a b c d maps v → av +cw and w → bv +dw.) There are two ways in which the graph Λ 1 -Λ 2 could be extended within BT(ρ), either or both of which could happen: and Λ 3 = v, 4w is also stable, extending the stable graph to Λ 1 -Λ 2 -Λ 3 . The lattice Λ 4 = 2v, v + 2w is also stable and adjacent to Λ 2 , so Λ 2 has degree 3 in BT(ρ).
These two situations are not essentially different, since by conjugating with the matrix 2 0 0 1 we interchange the roles of Λ 1 and Λ 2 , and the two cases.
The following maps are easily seen to define two additive quadratic characters of G K , unramified outside S: In order to turn this criterion into an algorithm we must see how to obtain information about these two characters using only the Black Box and a finite set of primes p / ∈ S. Taking k = 1 in (9) we use the test function (1 − tr(ρ(σ)) + det(ρ(σ))) (mod 2).
So the Black Box reveals the value of the product of the two additive characters.
Proof. The equivalence of the first two statements is because ker χ b and ker χ c are subgroups of G K , and no group is the union of two proper subgroups. For the second equivalence, note that the pair of values (χ b (Frob p), χ c (Frob p)) depends only on the restriction of Frob p to the maximal elementary 2-extension of K unramified outside S whose Galois group consists of these Frob p I .
Although the corollary already reduces the current problem to a finite number of tests, we will show in the next subsection how to use some linear algebra over F 2 to reduce the test set of primes from a set of size 2 r (one for each subset I) to a set of r(r +1)/2 quadratically independent primes (with respect to S). Using these, we will be able to determine not only whether at least one of ∆ b , ∆ c is trivial, in which case the class is large; when both characters are non-trivial, we will also be able to determine the unordered pair {∆ b , ∆ c } exactly.

Quadratically independent sets of primes
Let {∆ i } r i=1 be a basis for V = K(S, 2) u . The discriminants ∆ b , ∆ c ∈ V may be expressed as with unknown exponent vectors x = (x i ) and y = (y i ) in F r 2 . We will determine the vectors x and y in the restricted sense of knowing whether either (a) at least one of x and y is zero, or (b) they are both non-zero, in which case we will identify them precisely, as an unordered pair.
Let T 1 = {p 1 , ..., p r } be a linearly independent set of primes chosen so that the α pi are a dual basis to {∆ i } r i=1 . Then by (7) we have χ b (p i ) = x i and χ c (p i ) = y i . Hence, by Proposition 5.2, we have that t 1 (p i ) = x i y i . More generally for a prime p I (defined in Section 3) we have, by (7), where we set x I = i∈I x i and similarly for y I .
For fixed α, the map ψ α = ψ(−, −, α) is a symmetric bilinear function V × V → F 2 , i.e., an element of the space Sym 2 (V ) * which has dimension r(r + 1)/2 and basis the functions x i y i and x i y j + x j y i for i = j. This leads us to define our third (and last) set of test primes: The simplest quadratically independent sets consist of primes p i for 1 ≤ i ≤ r (these already form a linearly independent set, previously denoted T 1 ), together with p ij for 1 ≤ i < j ≤ r. We will call quadratically independent sets of this form special.
Remark 5.5. If we fix instead (∆, ∆ ) in (11) we obtain a quadratic function ψ (∆,∆ ) = ψ(∆, ∆ , −) on V * : It is not hard to show that when T 2 is a quadratically independent set of primes, the set {α p | p ∈ T 2 } is a non-quadratic subset of V * in the sense of Livné [13].
We now proceed to show that the values of the test function t 1 (p) for p in a special quadratically independent set of primes are sufficient to solve our problem concerning the identification of the vectors x and y. Define v = (v 1 , ..., v r ) ∈ F r 2 to be the vector with entries v i = x i y i = t(p i ).
Next let W = (w ij ) be the r × r matrix over F 2 with entries w ii = 0 and, for i = j, Then the i-th row of W is given by so that the rank of W is either 0 or 2. Moreover, • if x = 0 or y = 0, then v = 0 and W = 0; • if x = 0 and y = 0 and x = y, then v = x = y = 0 and W = 0; • if x = 0 and y = 0 and x = y, then W = 0. Moreover, at least two out of x, y, x + y (which are non-zero and distinct) appear as rows of W, and if v = 0, then the rows of W for which v i = 1 are x + y and the remaining non-zero rows are equal to either x or y; if v = 0, then the non-zero rows of W are all equal to either x and y.
It follows that by inspecting v and W, whose entries we can obtain from our Black Box test function on r(r + 1)/2 primes, we can indeed determine whether x or y is zero, and if both are non-zero then we can determine their values, and hence determine the unordered pair of the discriminants {∆ b , ∆ c }.
Proposition 5.6. Let ρ be residually reducible. From the set of values {t 1 (p) | p ∈ T 2 } of the test function t 1 defined in (10), for T 2 a quadratically independent set of primes with respect to S, we may determine whether the isogeny class of ρ is small or large, and in the first case we can determine the unordered pair formed by the associated non-trivial discriminants.
See Algorithm 6, where we follow the procedure above, assuming that we take for T 2 a special set In practice it might not be efficient to insist on using a quadratically independent set of this form, because we may need to test many primes p before finding primes of the form {p ij } for all i < j; also, the resulting primes are likely to be large. In applications, it may be computationally expensive to compute the trace of ρ(Frob p) for primes p of large norm. This is the case, for example, when ρ is the Galois representation attached to a Bianchi modular form (see [8] for numerical examples when K is an imaginary quadratic field of class number 3). In our implementation we adjust the procedure to allow for arbitrary quadratically independent sets. The details are simply additional book-keeping, and we omit them here.
We give two algorithms to compute quadratically independent sets. In both cases we consider the primes of K systematically in turn (omitting those in S), by iterating through primes on order of norm. The first algorithm returns the smallest such set (in terms of the norms of the primes), while the second only uses primes for which #I(p) ∈ {1, 2} and returns a set of the special form.
In Algorithm 4, we construct a matrix A whose columns are indexed by the subsets of {1, 2, ..., r} of size 1 and 2, i.e., the sets {i} for 1 ≤ i ≤ r and {i, j} for 1 ≤ i < j ≤ r, initially with 0 rows. For each prime p we compute I(p) and define v(p) in We add v(p) as a new row of A, provided that this increases the rank of A, and we stop when rk A = r(r + 1)/2.

Algorithm 4:
To determine a quadratically independent set T 2 of primes of K. Input : A number field K.
A finite set S of primes of K. Output: A finite quadratically independent set T 2 of primes of K. Compute I = I(p) using (4); 7 Compute v(p) from (13); This variant produces a special quadratically independent set by only including primes p for which I(p) has size 1 or 2.

Algorithm 5:
To determine a special quadratically independent set T 2 of primes of K.
Input : A number field K.
A finite set S of primes of K. Output: An indexed special quadratically independent set T 2 of primes. We leave it to the reader to explain why in every case the Hilbert Symbol (∆ 1 , ∆ 2 ) = +1.

Algorithm 6:
To determine whether the stable Bruhat-Tits tree of ρ has width exactly 1 or at least 2, together with the associated discriminants.
Input : A number field K.
A finite set S of primes of K.
A Black Box Galois representation ρ unramified outside S whose residual image is reducible. Output: If BT (ρ) has width 1, return: If BT (ρ) has width ≥ 2, return: False. Let z be the ith row of W, where i is such that t 1 (p i ) = 1; 14 Let x be any non-zero row of W distinct from z; 15 Let y = x + z. 16 The methods of this section give an algorithm to determine whether the isogeny class of ρ contains an integral representation whose residual representation is trivial.
Theorem 5.7. Let K be a number field, S a finite set of primes of K, and let ρ be a continuous 2-dimensional 2-adic Galois representation over K unramified outside S. Assume that ρ has reducible residual representation. Then there exists a stable lattice with respect to which the residual representation ρ is trivial, if and only if that is, where T 2 is any quadratically independent set of primes for S.

Large isogeny classes
From now on we will assume that ρ has trivial residual representation, so that its isogeny class BT(ρ) consists at least of ρ together with the three 2-isogenous integral representations: recall that each lattice Λ has three sublattices, and the condition that ρ Λ is trivial is equivalent to each of these being stable. The next step is to determine whether the class is larger than this, i.e., whether it has width greater than 2. This is not the case if and only if each of the 2-isogenous representations has a non-trivial discriminant (as defined in the previous section), in which case we would like to determine this (unordered) set of three discriminants. Furthermore, we would like to determine ρ (mod 4) completely.
It turns out that it is no more work to deal with the more general situation, where we assume that ρ (mod 2 k ) is trivial for some k ≥ 1, and determine ρ (mod 2 k+1 ) completely. The description of ρ (mod 2 k+1 ) will be in terms of a collection of four additive quadratic characters, which we will be able to determine using only the values of F p (1) for p in the same quadratically independent set T 2 used in the previous section. The reason for this is that GL(Z/2 k+1 Z) is an extension of GL(Z/2 k Z) by M 2 (F 2 ), which is (as additive group) an elementary abelian of order 2 4 , as can be seen by the following short exact sequence: Thus let ρ : G K → GL 2 (Z 2 ) be an integral Galois representation unramified outside S, and assume that ρ is trivial modulo 2 k for some positive integer k. Write where Then F σ (1) = 2 2k det µ(σ) ≡ 0 (mod 2 2k ), and we can use the test function t 2k (p) = 1 2 2k F p (1) = det µ(σ) ≡ ad − bc (mod 2) for p / ∈ S. Secondly, with the same notation, . Thus we see that the Black Box gives us the values of both tr µ(σ) and det µ(σ) (mod 2) for σ = Frob p ∈ G K . Now the map σ → µ(σ) (mod 2) is a group homomorphism G K → M 2 (F 2 ); composing with the four characters we obtain four additive characters of G K all unramified outside S, which we denote by χ a , χ b , χ c and χ d . To each character there is associated a discriminant, named ∆ a , ∆ b , ∆ c , ∆ d ∈ K(S, 2) u . Set χ abcd = χ a + χ b + χ c + χ d and χ det = χ a + χ d ; the latter has discriminant ∆ det = ∆ a ∆ d (the reason for this notation will be clear after the following lemma). Our task is to use the values of a + d and ad − bc at suitably chosen primes to obtain information about these four characters.
The previous computation of determinants gives the following result linking tr µ(σ) = a + d with det ρ(σ) (mod 2 k+1 ). Recall that by equality of discriminants we always mean modulo squares. Lemma 6.1. Assume that ρ is trivial modulo 2 k . With notation as above, the following are equivalent: The characters we have just defined depend not only on the stable lattice (here Λ = Z 2 2 , since we are treating ρ as an integral matrix representation) but also on a choice of basis. If we change basis via U ∈ GL 2 (Z 2 ), the result is to conjugate the matrices ρ(σ) and µ(σ) by U and replace the four characters χ a , . . . , χ d by F 2 -linear combinations. By using suitable matrices U of orders 2 and 3 we may obtain all 6 permutations of {b, c, a + b + c + d}: Of course the determinant character a + d (which is the sum of these three) is unchanged. We will make use of this symmetry in what follows. More generally, if U ∈ GL 2 (Q 2 ) ∩ M 2 (Z 2 ) is such that conjugation by U maps the image of ρ into GL 2 (Z 2 ), then σ → U ρ(σ) U −1 is another integral representation isogenous to ρ. We will use this construction below with U = 2 0 0 1 .

Stable sublattices of index 2 k+1
We continue to assume that ρ is trivial modulo 2 k and use the notation introduced in the previous subsection. Clearly all sublattices of index 2 k in Λ = Z 2 the condition of whether they are also stable may be expressed in terms of the characters {χ b , χ c , χ a+b+c+d }. In terms of the isogeny graph BT(ρ), it contains all paths of length k (of which there are 3 · 2 k−1 ) starting at the "central" vertex associated with Λ-so the graph has width at least 2k-and we are determining whether any such paths may be extended within BT(ρ) by one edge. This turns out to depend only on the first edge in the path (adjacent to Λ itself). When considering sublattices we restrict to those which are cocyclic, i.e. for which the quotient is cyclic, or equivalently are not contained in 2Λ. The cocyclic sublattices Λ of index 2 k+1 in Λ = Z 2 2 are given by where x, y are not both even, and Λ only depends on the image of v in For example, when k = 1, the generic stable Bruhat-Tits tree of width at least 2 looks like Figure A1: Tree of width at least 2.
Here, each vertex has been labelled with its discriminant in K(S, 2) u , as defined in the previous section. Note that the three discriminants at the vertices adjacent to the central one (which has trivial discriminant) have product ∆ det , only depending on det ρ. In the case k = 1 we deduce the following. Corollary 6.3. When ρ is trivial modulo 2, the isogeny graph BT(ρ) has width at least 3 if and only if at least one of the characters χ b , χ c , χ a+b+c+d is trivial.
Below we will see how to determine all four characters (up to S 3 symmetry). In the case k = 1, we will determine when all three characters in the Corollary are non-trivial, so that the graph has width exactly 2, and in this case we will determine precisely the unordered set of three discriminants in the diagram.
• If det(ρ(Frob p)) ≡ 1 + 2 k (mod 2 k+1 ), then a + d ≡ 1 (mod 2), so ad ≡ 0 (mod 2), and Note that we will know from the Black Box which case we are in from the value of det ρ(Frob p). We also note for later reference that from tr(ρ(Frob p)) = 2 + 2 k (a + d) we can obtain the exact value of a + d: later we will need a + d (mod 4). Now it is convenient to divide into two cases, depending on whether or not det ρ is trivial modulo 2 k+1 ; equivalently, whether or not ∆ det = 1.

Determining the four characters: the case ∆ det = 1
In this case the character χ det is trivial, ∆ a = ∆ d , and u = v. Moreover, ∆ abcd = ∆ b ∆ c , so x + y + z = 0. By S 3 symmetry, only the set {x, y, z} is well-defined. Taking and construct the matrix W = (w ij ) ∈ M r (F 2 ). Each non-zero row of W is equal to one of x, y or z, and as in Section 5, if W = 0 then W has at least two distinct non-zero rows and has rank 2. Case 1. rk W = 2. Now W contains at least two distinct non-zero rows, which by symmetry we can take to be the values of x and y. Then z = x + y, and we obtain the value of u (which equals v), using (19) and the now known values of x and y. Therefore we have computed all the exponent vectors u, v, x, y, z and obtained ∆ a , ∆ b , ∆ c , ∆ d and ∆ abcd .
Case 2. W = 0. Now at least one of x, y or z is zero; by symmetry we may take y = 0, and x = z, but we do not yet know the common value of x and z. However we have t 2k (p i ) = u i + x i y i = u i , so we recover u.
To determine x and hence obtain the final discriminant ∆ b , we need to go a step further and consider the values of F p (1) (mod 2 2k+2 ). At the end we may need to replace ρ by a 2-isogenous representation; recall that the Black Box only determines ρ up to isogeny, so this is valid.
Recalling the notation of (14), since y = 0 we observe that the entry c is always even; put c = 2c 1 . Denote by χ c1 the character σ → c 1 (σ) (mod 2) and let ∆ c1 be its discriminant. From the information already known and further tests using the Black Box with the same primes in T 2 but to higher 2-adic precision, we can determine the values of the product χ b χ c1 . As in Section 5, we can then determine whether either ∆ b or ∆ c1 is trivial, and their values if both are non-trivial. In the first case we may assume (conjugating if necessary) that ∆ b = 1 (equivalently, x = 0). In the second case, we may take either of the non-trivial discriminants to be ∆ b . This apparent ambiguity is illusory, since we are free to replace the initial integral representation ρ by an isogenous one.
For p / ∈ S we have In order to proceed, we will need the value of ad (mod 4). Recall that we know the exact value of a + d from (18), and we also know the common parity of a and d, namely u I if p = p I .
2. If p is such that a ≡ d ≡ 1 (mod 2) and a + d ≡ 0 (mod 4), then ad ≡ −1 (mod 4), so (21) becomes Hence we define a modified test function as follows: 3. If p is such that a ≡ d ≡ 1 (mod 2) and a + d ≡ 2 (mod 4), then ad ≡ 1 (mod 4) and (21) becomes In summary, when ρ is trivial modulo 2 k and has trivial determinant modulo 2 k+1 , we can use the test function values t 2k (p) for p ∈ T 2 (where T 2 is a quadratically independent set of primes for S), together with either t 2k+1 or one of the modified testst 2k+1 depending on p, to determine the full set of characters χ a , χ b , χ c , χ d , satisfying χ a + χ d = 0, if necessary replacing ρ by a GL 2 (Z 2 )-equivalent representation, or by a 2-isogenous representation. In particular, if all the characters are trivial then (up to a 2-isogeny) we conclude that ρ is trivial modulo 2 k+1 .

Determining the four characters: the case ∆ det = 1
Now assume that the determinant character χ det is non-trivial, i.e. that det ρ is not identically 1 (mod 2 k+1 ). To ease notation, we choose a basis {∆ i } r i=1 of K(S, 2) u such that ∆ 1 = ∆ det . The unknown vectors in F r 2 then satisfy where e 1 = (1, 0, ..., 0). Denote by x , y etc. the vectors in F r−1 2 obtained by deleting the first coordinate. These satisfy x + y + z = u + v = 0 and we will determine them first.
Take primes p i , p ij ∈ T 2 with i, j ≥ 2 and i = j. For such primes (as for all p I when 1 / ∈ I) we have det ρ(Frob p) ≡ 1 (mod 2 k+1 ), so from (16) and using u i = v i for i ≥ 2 we see that and hence we can compute Just as in Section 6.3 we can determine the shortened vectors x , y , z , u , v (possibly replacing ρ by an isogenous representation). The final step is to determine the first coordinates u 1 , v 1 , x 1 , y 1 and z 1 with x 1 + y 1 + z 1 = u 1 + v 1 = 1, using the remaining primes in T 2 and test values t 2k (p 1 ) and t 2k (p 1i ), for 2 ≤ i ≤ r. We first note the following symmetries: (1) u and v , and hence u and v, are interchangeable (by conjugation); hence we can arbitrarily set u 1 = 1 and v 1 = 0; (2) concerning x , y and z : (a) if all are non-zero, and hence also distinct, then we can permute them arbitrarily; (b) if all are zero, then again we can permute x, y and z arbitrarily; (c) otherwise, one of them is zero and the others equal and non-zero; we have chosen them so that y = 0 and x = z , so we can still swap x and z.
Otherwise, x 1 y 1 = 0 and we need to determine which one of x 1 , y 1 or z 1 is 1, the other two being 0. We can compute for i ≥ 2 (using u 1 + u i = v 1 + v i ) and hence get the values y 1 x i + x 1 y i for i ≥ 2, since we already know x 1 y 1 and all x i y i for i ≥ 2. Define Consider the three cases under (2) above: • In (2)a, x and y are linearly independent so q determines x 1 and y 1 uniquely; • In (2)b, we have complete symmetry and may set x = y = 0 and z = e 1 ; • In (2)c, since y = 0 we have q = y 1 x and x is not zero, so if q = 0 then y 1 = 1 and x 1 = z 1 = 0. On the other hand, if q = 0 then y 1 = 0 and we can set x 1 = 0, z 1 = 1 (or vice versa, it does not matter since x = z ).
This completes the method to determine the vectors u, v, x, y, z and hence the discriminants ∆ a , ∆ b , ∆ c , ∆ d and ∆ abcd and the associated characters.
In summary, when ρ is trivial modulo 2 k and has non-trivial determinant modulo 2 k+1 , we can again use the test function values t 2k (p) for p ∈ T 2 (where T 2 is a quadratically independent set of primes for S), together with either t 2k+1 or one of the modified testst 2k+1 depending on p, to determine the full set of characters χ a , χ b , χ c , χ d , satisfying χ a + χ d = χ det = 0, if necessary replacing ρ by a GL 2 (Z 2 )-equivalent representation, or by a 2-isogenous representation. Unlike subsection 6.3, it is not possible for all the characters to be trivial, and ρ is certainly not trivial modulo 2 k+1 as det ρ is nontrivial modulo 2 k+1 .
We now summarise the results of this section.
Theorem 6.4. Let K be a number field, S a finite set of primes of K, and ρ a 2-dimensional 2-adic Galois representation over K unramified outside S.
Suppose that there exists a stable lattice under the action of ρ with respect to which ρ (mod 2 k ) is trivial, for some k ≥ 1. Then, using the output of the Black Box for ρ for a set T 2 of primes which are quadratically independent with respect to S, we can determine whether there exists a (possibly different) stable lattice with respect to which ρ (mod 2 k+1 ) is trivial. More generally we can completely determine the representation ρ (mod 2 k+1 ) on some stable lattice for ρ.

Detecting triviality of the semisimplification
In the past three sections we have given algorithms for determining the following properties of a continuous 2-dimensional 2-adic Galois representation ρ, unram-ified outside a given finite set of primes S, using only the output from a Black Box oracle giving for any prime p / ∈ S the Frobenius polynomial F p (t): 1. whether or not ρ is residually reducible (Theorem 4.6: using the primes in a distinguishing set T 0 for S); 2. if ρ is residually reducible, whether or not ρ is residually trivial up to isogeny (Theorem 5.7: using the primes in a quadratically independent set T 2 with respect to S); 3. if ρ is trivial modulo 2 k up to isogeny, whether or not ρ is trivial modulo 2 k+1 up to isogeny (Theorem 6.4: again using the primes in a quadratically independent set T 2 ).
We also showed in Section 3 how to verify that det ρ was equal to a given 2-adic character (Theorem 3.4, using the primes in a linearly independent set T 1 with respect to S). So far we have only needed finite 2-adic precision from our Black Box oracle. In this section we assume that the oracle can provide us with the Frobenius polynomials F p (t) exactly, which is usually the case in practice when they are monic polynomials in Z[t]. By putting together the previous results we can determine whether ρ has trivial semisimplification; since we only know ρ through the characteristic polynomials of the ρ(σ), this is as close as we can get to showing that ρ is trivial.
We start with a lemma taken from the proof of Theorem 3.4: Lemma 7.1. Let χ : G K → Z * 2 be a continuous character unramified outside S. If 1. χ(σ) ≡ 1 (mod 2 k−1 ) for all σ ∈ G K , and 2. χ(Frob p) ≡ 1 (mod 2 k ) for all p ∈ T 1 , where T 1 is a linearly independent set with respect to S, then χ(σ) ≡ 1 (mod 2 k ) for all σ ∈ G K . Proposition 7.2. Let ρ : G K → GL 2 (Z 2 ) be a Galois representation unramified outside S such that Suppose that 1. det(ρ(Frob p)) ≡ 1 (mod 2 k+1 ) for all p ∈ T 1 , and where T 1 is a linearly independent set and T 2 a quadratically independent set with respect to S. Then there exists an isogenous representation ρ such that ρ (σ) ≡ I (mod 2 k+1 ) for all σ ∈ G K . Proof. First, by Lemma 7.1, the first condition implies that det(ρ(σ)) ≡ 1 (mod 2 k+1 ) for all σ ∈ G K . Next we use the notation of the previous section, specifically (14). The determinant condition just established shows that a + d ≡ 0 (mod 2) and we are in the case ∆ det = 1 as in subsection 6.3 with u = v. Next, F p (1) ≡ 0 (mod 2 2k+2 ) means that all the test function values are 0. This gives in turn W = 0, y = 0 and u = v = 0. Finally we have bc 1 ≡ 0 (mod 2) so (applying a 2-isogeny if necessary) we may assume that b ≡ 0, so x = 0. Hence all the characters are trivial, as required.
Using this proposition, we can prove our final result. Theorem 7.3. Let ρ : G K → GL 2 (Z 2 ) be a continuous Galois representation unramified outside S which is residually reducible. If 1. det(ρ(Frob p)) = 1 for all p ∈ T 1 , and 2. tr(ρ(Frob p)) = 2 for all p ∈ T 2 , (in particular, if Frob p has characteristic polynomial (t − 1) 2 for all p ∈ T 2 ), then ρ is reducible, with trivial semisimplification, and is of the form with respect to a suitable basis.
Proof. Suppose that ρ were irreducible; then BT(ρ) is finite, and none of the finitely many integral forms ρ Λ is trivial (otherwise ρ would be) so there is a maximal k ≥ 1 such that ρ Λ is trivial modulo 2 k for some stable lattice Λ. This contradicts Proposition 7.2. Hence ρ is reducible. With respect to a suitable basis all the matrices ρ(σ) are upper triangular. The diagonal entries determine characters of G K , which are both trivial on Frob p for all p ∈ T 1 (since the product of their values is 1 and their sum 2). By Theorem 3.4 both diagonal characters are trivial.

Further examples
We finish by presenting two examples with base field K = Q( √ −1), where the Black Box Galois representations come from Bianchi modular newforms with rational Hecke eigenvalues. The existence of suitable Galois representations in this case was first developed by Taylor et al. in [9], [17] with subsequent results by Berger and Harcos in [3]. For our purposes we only need the existence of the representation and the knowledge that it is unramified outside the primes dividing the level of the newform, with the determinant and trace of Frobenius at an unramified prime p equal to the norm N (p) and the Hecke eigenvalue a p respectively. These eigenvalues were computed in these examples using the methods of [6]. The newforms we use here are in the LMFDB [14] and may be found at http://www.lmfdb.org/ModularForm/GL2/ImaginaryQuadratic/.
In both these examples (as in several hundred thousand others we have) there exist elliptic curves defined over K whose 2-adic Galois representation can be proved to be equivalent to the representation attached to the newform, using the Serre-Faltings-Livné method as detailed in [8]. However in preparing the examples we did not use the elliptic curves themselves, but used modular symbol methods to obtain the traces of Frobenius as Hecke eigenvalues. As det(ρ(Frob p)) = N (p) and we include the prime above 2 in S, for K = Q( √ −1) we always have N (p) ≡ 1 (mod 4), and hence the determinant of the representation is trivial modulo 4.
In this way we can obtain information about the elliptic curves conjecturally associated to a rational Bianchi newform, even in cases where we have not been able to find a suitable elliptic curve. There is one C 3 extension of K unramified outside S, and 5 S 3 extensions, so we have a set F of 6 possible cubics. Using Algorithm 2 we find that a suitable distinguishing set is T 0 = {2 + i, 2 + 3i, 3 + 2i, 1 + 4i}. Checking that a p is even for all p ∈ T 0 shows that the mod-2 representation is reducible.
Using Algorithm 5 we find the following set of ten primes forms a special quadratically independent set. (We only use primes of degree 1 here, noting that the cost of computing a p grows with N (p).)  Applying the test t 1 (p), given by (10), amounts to testing whether each a p ≡ 0 or 2 (mod 4); here, all a p ≡ 2 (mod 4). (In the notation of subsection 5.2, we have v = 0.) This implies that the width of the isogeny class is at least 2; we have a large isogeny class.
We find T 2 as before and obtain the following data from the newform, acting as our Black Box: Since t k (p) = 0 for all p ∈ T 2 for k = 1, 2, 3 we see that not only is ρ residually reducible, it is even trivial modulo 4 (up to isogeny). Fixing a stable lattice with respect to which ρ is trivial mod 4, we will determine ρ (mod 8), noting that it does not have trivial determinant, as some primes have norm ≡ 1 (mod 8).