
// Make newform 667.2.a.d in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_667_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_667_2_a_d();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_667_2_a_d();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [64, 336, -505, -3011, 1842, 6612, -2496, -5877, 1860, 2592, -795, -597, 187, 68, -22, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-5285248, 14985488, 82287639, -150942644, -218624434, 295392450, 238939362, -247933907, -125237015, 106985521, 32910414, -24534615, -4124788, 2801696, 194810, -124169], [26486912, 70510224, -310735913, -486230356, 659418286, 1076238434, -417755646, -891751731, 105825449, 357397585, -9187314, -74718487, -279828, 7810176, 55514, -320937], [9101888, 82151376, 18055599, -647488676, -121294226, 1319983010, 281768162, -1062555835, -199268623, 424971913, 59863870, -89853839, -8005092, 9549392, 390970, -399265], [-22861184, -83614256, 221078775, 636921244, -412374178, -1394129102, 125345330, 1135959741, 50528745, -451780703, -31443954, 94577321, 5268764, -9954704, -286326, 412871], [-29967232, -128155856, 240369543, 902289932, -405092882, -1866965854, 41030562, 1484699485, 118277337, -582618367, -52379826, 121020601, 8084172, -12681760, -423750, 524711], [-482240, -2582832, 2851149, 23503844, -2466278, -51974890, -6272874, 43543519, 6505683, -17880021, -2217254, 3856563, 315428, -416256, -15970, 17613], [-25501376, -165493584, 105743457, 1301242372, -37531118, -2644257954, -371571234, 2103849867, 334114239, -832081593, -108143006, 174451711, 14936836, -18434160, -741754, 767889], [-9694400, -120432048, 4288591, 1166520668, 95845550, -2550207070, -467484126, 2083463077, 373891409, -834663895, -117193986, 176274769, 15967900, -18711408, -787334, 781759], [12619200, 112498544, -5825419, -1069127244, -130836902, 2346845462, 478390486, -1954600569, -371328085, 799917747, 116053706, -172213973, -15860300, 18568432, 785182, -785211], [1090240, 4130640, -6494857, -39174116, 8993566, 86000690, 6098098, -70040835, -8752791, 27912865, 3136078, -5863511, -451684, 619504, 22922, -25785], [8409984, 37586128, -51140001, -296442140, 64022150, 627687626, 41832298, -517413267, -61808511, 210501617, 22541886, -45092591, -3291564, 4840280, 168786, -203897], [5982064, 48368920, -17897027, -406520288, -15085386, 855515802, 137042970, -698535541, -114014061, 281841111, 36315186, -59968933, -4997680, 6403548, 248146, -268687], [-23649344, -120861728, 139655233, 1101186116, -224585838, -2384502434, -119133362, 1960071611, 198902831, -790224857, -74079278, 167505279, 10903780, -17803568, -561258, 743697]];
    Rf_basisdens := [1, 1, 1, 1247936, 1247936, 1247936, 1247936, 1247936, 40256, 1247936, 1247936, 1247936, 40256, 311984, 311984, 623968];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_667_a();"
function MakeCharacter_667_a()
    N := 667;
    order := 1;
    char_gens := [465, 553];
    v := [1, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

function MakeCharacter_667_a_Hecke(Kf)
    return MakeCharacter_667_a();
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..(prec+1)]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 2;
    raw_aps := [[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0], [1, 1, -1, 1, 0, 0, 0, 0, 0, 1, -1, -1, -1, 1, 0, 0], [1, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, -1, -1, 1, 0, 0, 0, 0], [1, 0, -1, -1, -1, 0, -1, 2, -2, -1, 0, -1, -1, 0, 0, -1], [1, 0, -1, -1, 0, 0, -1, 1, -1, 0, 0, -1, -1, 0, 1, -1], [-1, 1, -2, 0, -1, 0, -2, 1, -2, -1, 0, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0, 0, 1, -1, 0, -1, -1, 1, 0, 0, 0], [3, -1, 0, 0, 0, 0, -1, -2, 1, -1, 1, 1, 0, -1, 0, -1], [2, 0, -1, -1, 0, -2, 0, 0, 0, 0, -1, -1, -1, 0, 1, 1], [-1, 1, 0, -2, -1, 0, 0, -1, -1, -2, 2, 0, -1, 0, -1, -1], [0, -1, 2, -1, 0, 0, 0, 2, 0, 1, -1, -1, 0, 0, 1, 1], [-1, 0, 0, -1, -1, -1, 0, 2, 0, 0, -1, 1, -1, 0, 0, 0], [-2, 1, 1, 1, 1, -1, 2, -2, 3, 0, 2, 0, 2, 0, 1, 0], [-2, -3, 0, -1, 0, 2, -2, 0, -1, -2, 3, 2, 0, -3, 2, 0], [2, -1, -2, 0, 0, -1, 0, -2, 0, 1, 0, 0, 0, -1, 2, 0], [-1, 1, 0, 0, -2, -2, -1, 2, -1, -1, -1, 0, -2, 1, -1, -1], [-2, -1, 2, 0, 0, 3, -1, 2, -1, -1, 0, 1, 1, 0, 1, 0], [6, 0, -1, -2, 1, -2, 3, 0, 0, 1, -2, -1, 0, 2, -1, 1], [-2, 2, 1, 3, 0, -1, 1, -1, 0, 1, -2, -1, 0, 2, -2, -1], [1, -3, 1, -2, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 1, 0], [0, -1, -1, 1, 1, 1, 0, 2, 0, 3, -2, -3, 0, 1, 1, 1], [-3, 0, 0, -1, 0, 0, 1, -2, 0, -1, 2, 1, 0, -2, 1, 1], [-3, 0, -3, -1, -2, -1, -1, -1, 1, 2, 0, 0, -1, 1, 1, -1], [-4, 1, 0, 0, -1, -1, -1, 1, -1, -1, 0, 0, 0, 0, -1, -1], [2, 0, 2, 0, -1, 0, 0, -1, -1, -1, 0, -3, -1, 0, -1, -2], [-2, 2, 1, 1, -2, -1, -2, -1, -1, 1, -1, -1, -3, 1, -1, -3], [-2, -1, 1, 3, 0, 1, 1, -3, 1, 1, 2, 2, 3, -2, 0, 0], [-2, 5, -4, 1, -2, -3, -3, -1, -2, 0, -2, -1, -3, 1, 2, -1], [0, 1, -2, 0, 1, 2, -1, -3, -2, -2, 1, 1, -1, -2, -2, 0], [2, 0, 2, 2, 3, 0, 0, 1, 2, 0, 0, 0, 1, -2, 0, 1], [2, -1, 2, -1, -1, 2, -1, 2, -2, -2, -1, -2, 0, 0, -2, 0], [7, -2, -2, 1, 1, 3, -2, 0, -2, 0, 2, -3, -2, -1, 0, -2], [0, -2, 2, 0, 1, 3, -2, 0, 1, 1, 2, 0, 2, -1, 0, -1], [-2, 0, 2, 0, 0, 2, 2, -2, -1, -1, 2, 4, 3, -2, 0, 3], [2, 6, -2, 0, -2, -1, 0, 0, -3, -1, 1, -2, -2, 2, -1, -1], [-1, -2, -2, -2, -2, 0, -3, 4, -4, -1, 0, -1, -1, -2, 2, 0], [0, 4, 4, -1, 0, 0, -1, 1, 0, -3, 2, 0, 2, -1, -2, -1], [3, -1, 3, -1, 1, -2, 3, 2, 3, 1, -2, -1, 2, 2, 1, 2], [-2, 0, -1, 2, 0, 2, -2, -1, -3, -1, 1, 2, 1, 1, -2, 0], [3, -3, 1, -1, 3, 0, 0, 1, 3, 2, 0, -5, -1, 0, 0, 0], [0, -3, -2, 2, 0, 0, 1, 2, 1, 3, -1, 1, 1, 0, 3, 2], [1, -1, 3, 1, 1, -1, 3, 0, 0, 0, -1, -3, 0, -1, 0, 1], [4, 4, -3, -3, -2, 1, -1, 0, -2, -1, 3, -3, -3, 0, 0, -4], [3, -1, -3, -1, 1, 0, -1, -1, 4, 2, 4, 1, 1, -2, 3, 2], [2, -3, 0, 2, 4, 0, 0, 0, 3, 2, 2, 1, 3, -2, 2, 1], [0, 3, 1, 3, -1, 0, -3, 2, -3, -1, -3, -1, 0, 0, -3, 1], [7, -3, 4, 2, 3, -1, 1, 0, 4, -2, 1, 4, 3, -1, -2, 0], [1, 1, 3, 1, -1, -1, 2, 0, -4, -3, -2, 2, 1, 1, -2, 0], [3, -3, -3, 0, 0, -1, 1, -1, 3, 3, -1, 2, 0, -1, 4, 2], [0, -2, -1, -2, -1, 2, 0, 0, -3, 1, -3, 2, -1, 2, 0, -1], [0, -3, 1, -4, 0, 0, -1, 2, 1, 1, -2, 1, -2, 1, 3, 0], [0, 1, -6, 2, 2, 1, -1, 0, 0, 2, -2, -5, -2, 0, 1, -1], [-3, -2, 3, -3, 1, -1, 1, -2, 1, -4, 3, 2, 0, -2, -3, -2], [4, -2, 2, 1, 4, 1, 4, 0, 3, 5, 0, 2, 2, 2, 0, 4], [0, 1, -4, 0, -2, 0, -5, 4, -1, -1, 1, -2, -1, -3, 5, -2], [0, -1, -2, 2, 2, 0, 1, 2, -1, 3, -2, -1, 2, 3, 1, 2], [4, 5, -4, 0, -3, -3, -1, -1, -4, -2, -1, 2, -4, 3, 1, -2], [9, -1, 0, -1, 0, -2, -1, 6, -2, -2, -5, -2, 1, 5, -1, 1], [2, -1, -4, 2, 0, -1, 0, 0, 4, 3, -3, -2, 0, 2, 0, 0], [-5, -1, -1, 1, 0, 3, -1, 1, -4, 4, -2, -2, 0, -3, 0, 2], [5, 1, -3, 3, -1, -4, 1, -1, 2, -2, 1, -1, 2, 1, 1, 0], [0, 2, 2, -1, 0, 1, 0, -1, 0, 2, 0, -3, 1, 1, 1, -2], [14, 0, 0, 1, 1, 0, 0, 3, 0, 0, 1, 0, 2, 3, 1, 2], [1, 4, -6, 3, 1, -1, 0, -1, 2, 2, 0, 2, 1, 1, 3, 1], [-7, -6, -4, -2, 1, 6, -4, 1, -1, 1, 6, 1, 1, -5, 5, -1], [4, -4, 2, -3, 1, -3, 4, 3, -1, 1, -2, 0, 1, 3, -1, 3], [-12, 5, 2, -3, -5, -3, -1, 1, -2, -2, -3, 1, -3, 5, -1, -3], [1, -1, -4, -2, -2, -5, -1, 0, 2, 0, 1, 2, -1, -1, 2, 0], [-5, 3, 4, 0, -2, -3, 2, -2, 0, -1, -4, 7, -1, 5, -4, -1], [4, 0, 0, 0, -2, -1, 1, 0, 0, -1, 0, -5, 1, -1, 1, -1], [3, 7, -4, 0, -4, 5, -3, 4, -7, -1, -5, -5, -3, 1, -2, -1], [-7, 4, 1, 1, -3, -1, -1, -2, -5, -2, -3, 4, -2, 3, -5, 0], [-4, 2, -2, 2, 2, 0, -1, 0, -3, 0, 0, 0, 0, -2, -1, 2], [-5, 0, 2, -3, -2, -3, -4, 4, 2, -2, 5, 0, 1, 0, 1, -2], [2, -1, 5, 1, 1, -2, 3, 2, 2, 0, -3, 4, 4, 2, -2, 6], [-2, -3, 3, -2, -2, -2, 2, -3, 3, 0, 3, 1, 4, 1, -2, 2], [2, -4, -1, 2, 4, 3, 0, 0, 2, 4, 1, -1, -1, -2, 4, 2], [2, -7, -1, -2, 1, 5, 0, 4, 1, 2, 4, -2, -1, -3, 4, -1], [7, -1, 5, 0, 3, 1, 2, 6, 0, 1, -2, 0, 1, 2, 3, 1], [-1, 0, 2, 3, 1, -3, 6, -3, 1, 1, -4, -4, 0, 1, -2, 2], [5, -1, 1, -3, -1, -3, 2, 0, 2, 1, -5, -3, 0, 2, 2, 0], [5, 3, 0, -3, -4, -3, -2, 3, -2, -1, -2, 1, 1, 0, -2, 3], [-1, 5, 5, -3, -3, 0, -1, 2, -2, -4, 0, 0, 2, -1, -2, 1], [-5, 1, 2, 4, -2, -3, -3, -4, 0, -4, 1, 0, 0, -2, -2, -4], [-4, -4, 0, 2, 1, -1, -1, 1, -1, -2, -1, 3, -3, 1, -1, -1], [3, -2, 3, 0, 2, 2, 2, -1, 2, 0, 1, 1, 0, -5, -1, 0], [-6, 3, -1, 3, 0, 1, -3, 0, -1, 1, -2, -2, 1, -1, 0, 1], [2, 0, -2, -1, 1, -3, -4, 1, -1, -1, -1, 2, -4, 3, -2, -3], [-3, 0, 4, -3, -1, 4, -2, 0, -1, -3, 5, 6, 2, -4, 0, 1], [3, 3, -6, -8, -3, -5, -4, 5, -6, -3, -2, -4, -5, 3, 1, -6], [-2, -2, -3, -6, 2, -1, 5, -3, 2, 3, -2, -3, -3, 1, 3, 2], [1, -10, 0, -3, 1, -1, 6, -3, 7, 7, 1, 7, 2, 5, 0, 4], [-4, 0, -4, 3, 1, -1, 2, -4, 3, 1, -2, -5, -2, 1, 1, 0], [1, -8, 6, 0, 3, 3, 2, -5, 5, 1, 2, 8, 3, -3, -3, 3], [-6, 1, 5, 2, 2, 7, 0, -3, -2, -3, 2, 1, -1, 0, -5, -1], [-2, 6, -3, 3, 2, 4, 1, 3, 0, 5, -2, -4, -2, 1, 2, 1], [-1, -1, -2, 0, 5, 0, 4, -1, 1, 4, -4, -6, 1, 5, 1, 1], [-6, 0, 1, 3, -1, 5, -1, 2, -6, -1, -1, 1, 1, 3, -6, -2], [5, 1, 1, -2, 3, -4, 2, -1, 3, 0, -2, 0, 1, 4, 1, 1], [-2, -1, 8, 0, 1, -2, 3, -6, 5, -5, 7, 8, 6, -2, -1, -2], [-2, -6, 3, -1, 0, -5, 5, -1, 4, 3, -3, 7, 2, 4, -2, 3], [2, 6, -4, 4, 0, -2, -1, 6, -3, 4, -8, -11, -1, 1, 3, 2], [-1, -8, 3, 2, 3, 2, 5, -2, 7, 4, 0, -1, -1, -1, 2, 3], [4, -7, 5, 0, 3, -1, 3, -4, 5, -3, 3, 10, 5, -2, -3, 2], [0, 3, -3, 3, 0, 2, 0, 1, -1, 0, -1, 1, 1, -4, 1, 3], [-5, 0, -5, -2, -3, -1, -5, 4, -2, -5, 3, -2, 0, -4, 3, -4], [0, -2, -5, -1, 0, 7, 0, 5, -3, 5, -5, -4, 2, -3, 3, 7], [-11, 3, -3, 2, -3, -7, 1, -4, 0, 0, -4, -3, -4, 5, -1, 0], [3, -1, -3, 4, -1, -2, 2, 0, 0, 5, -9, -3, -2, 5, -1, 5], [6, -3, 4, 2, 0, 3, 5, -1, 4, 4, -3, 4, 4, 4, -3, 6], [8, -6, 8, -4, 2, 2, 2, -4, 6, 0, 5, 5, 4, -5, 2, 2], [-14, -6, 1, 1, 2, 6, -4, -1, 2, 2, 3, 1, -1, -4, -2, -4], [-5, 0, 6, 0, -2, 2, -1, 0, -2, -3, -2, 6, 0, -2, -4, 2], [2, -4, 2, 6, 4, 7, 4, 1, 2, 6, 0, 3, 4, 4, 0, 3], [13, -3, -4, 3, 0, 0, -3, -2, 0, 2, 1, 3, -4, 2, 3, -3], [-2, 1, 2, 2, 4, 1, 3, 0, -1, 1, -9, -3, -2, 3, -3, 2], [7, -1, 1, 0, -1, 2, -1, 2, -1, 3, 3, -6, -1, 1, 2, 3], [-6, 3, 5, 5, -2, 0, 2, 1, 2, 3, 0, -1, -1, 2, 1, 0], [2, -4, -2, 2, 2, 5, 0, 4, 1, 5, -2, -5, -1, 1, 4, 3], [2, -12, -1, -1, 5, 3, -1, -3, 5, 6, 7, 3, 4, -6, 4, 4], [-4, -2, 3, -3, 0, 2, -1, -3, -2, -5, 2, 5, -1, 0, -10, -1], [1, -1, 2, 0, -3, -2, -6, 1, -3, -4, -2, -1, -2, -4, 1, -7], [4, 3, 1, 1, 1, -5, 4, -2, 1, -2, -2, -3, 0, 1, -1, 0], [-2, 9, -7, 8, -3, 0, -5, 2, -9, -1, -3, -2, -5, 5, -2, -2], [-4, -9, 1, -2, 5, 1, 6, -6, 6, 3, 1, 5, 1, 3, -1, 0], [8, -4, -4, 3, 3, -2, 3, -1, 6, 9, -5, -3, -5, 5, 3, 1], [4, -2, 0, -1, 3, -5, 1, -2, 4, 1, -2, 4, -3, 2, -4, 0], [-9, 3, 5, -2, -1, 3, -5, 6, -4, -4, 1, -2, 4, 2, 1, -2], [24, 0, -4, -3, -1, -5, -5, 5, -1, -4, -1, 0, -3, 3, -2, -4], [-4, -5, 8, 1, -1, -1, 0, -3, 4, -3, 1, -1, 1, -3, -1, 0], [21, -2, -1, 1, 4, 6, 2, -1, -2, 0, -4, -8, 0, 2, -4, 1], [-9, -2, 8, -3, -3, 0, -2, -3, 3, -3, 5, 5, -1, -3, -2, -6], [11, -5, -5, -3, 0, -2, -4, -3, -4, -7, 5, -1, -3, -1, 0, -5], [3, -1, -1, 2, 0, 6, 0, 6, -2, 1, 1, -2, 7, -1, 5, 7], [-3, 6, 1, -7, -3, -6, 4, 2, -2, 0, -6, -6, -4, 3, -2, 0], [-4, -7, 8, 1, 5, 3, 2, 1, 3, 4, 0, 5, 3, -1, -2, 7], [7, -2, 1, -2, 3, 3, -5, -2, -1, -2, 6, -1, 1, -5, 2, -5], [-2, 0, 4, 0, -2, -4, -4, 4, -2, -6, -1, -5, -1, -4, 2, -4], [-4, -2, -4, -2, 0, 1, 0, -2, 2, 4, 1, -9, -3, 0, 4, -4], [-5, 2, -2, -2, -3, 1, -4, 5, -6, -2, -3, 0, 1, 4, -1, 0], [6, 1, 6, 6, 1, 3, 5, -3, 3, 5, 1, 4, 10, -3, -1, 7], [5, 3, 0, -2, 1, 3, -2, 1, 1, -2, 3, -4, 5, -4, 5, 5], [10, 6, -7, 0, -3, 1, -5, 5, -2, -3, 0, -1, 1, -5, 1, 0], [6, 0, 3, -7, -2, -2, -3, -1, -1, -8, -1, -2, -7, -5, 1, -4], [9, -1, 3, -2, 5, -5, 9, 3, 6, 4, -4, -10, 2, 7, 2, 3], [-1, 5, 1, -3, 0, -5, 3, -9, 1, -3, 2, 7, 0, 5, -5, -3], [8, 1, -10, -1, -4, -3, -6, 0, -3, -2, 2, -1, -2, 1, 4, -2], [5, -6, 2, 3, 4, -2, 2, -2, 4, -2, 3, 1, 0, -1, 5, -2], [-18, 6, -3, -3, -7, -2, -4, 0, -7, -5, -2, 6, -2, 3, -7, -4], [5, 8, 2, -3, 0, -2, 2, 1, 4, -4, 4, 2, 2, 0, -2, -3], [-4, 1, 4, 3, 0, 0, 1, -6, 5, -3, 2, 6, 4, -4, -4, -3], [1, -2, -1, -4, 4, 1, 0, -1, -3, -3, 3, 3, -3, -6, 1, 1], [5, 6, 4, -3, -1, -4, 7, 3, 2, -1, -7, -5, 2, -1, 3, 4], [6, 19, -3, 3, 0, 1, 3, 1, -1, 5, -4, 3, -2, 9, -2, 4], [16, 1, 5, 0, 6, -3, 7, -3, 6, -2, 5, -7, 0, 2, 3, -4], [6, -2, -2, 1, -3, 0, 0, 1, -4, 6, -5, -2, -4, 5, 3, 0], [-2, -8, 9, 0, 0, 2, 4, -3, 4, 2, 1, 2, 3, 1, -8, -1], [5, 7, -2, 2, -3, 3, -7, 7, -5, -1, -1, 3, 3, 2, -1, 2], [11, 3, 2, 4, 7, -1, 0, 7, -1, -4, -2, -2, 2, 2, -1, -1], [4, 10, 0, -5, -3, -2, 5, 1, -1, -2, -2, 6, 1, 4, -2, 4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_667_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_667_2_a_d();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_667_2_a_d(:prec:=16)
    chi := MakeCharacter_667_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_667_2_a_d();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_667_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_667_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![64, 336, -505, -3011, 1842, 6612, -2496, -5877, 1860, 2592, -795, -597, 187, 68, -22, -3, 1]>],Snew);
    return Vf;
end function;