
// Make newform 624.4.d.b in Magma, downloaded from the LMFDB on 04 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_624_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_624_d_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_624_4_d_b();".
// 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_624_4_d_b();".
// 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 := [254016, 0, 976752, 0, 702900, 0, 96803, 0, 5196, 0, 120, 0, 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], [-208515312, 0, -112501200, 0, -9478141, 0, -532644, 0, -22548, 0, -335, 0], [114851937312, 89497903824, 142463426112, 134044901520, 27478589362, 20677540541, 1908111912, 1177630788, 54476520, 28334004, 543494, 243823], [5516717472, -6827426928, 8409129120, -3066171120, 1086060234, -442006663, 46343304, -26600460, 678888, -708252, 1806, -6845], [5703423264, 6827426928, 8409129120, 3066171120, 1086060234, 442006663, 46343304, 26600460, 678888, 708252, 1806, 6845], [0, -1369886448, 0, -1099988520, 0, -147021553, 0, -7577172, 0, -168396, 0, -1355], [-114851937312, 89497903824, -142463426112, 134044901520, -27478589362, 20677540541, -1908111912, 1177630788, -54476520, 28334004, -543494, 243823], [0, -39817168272, 0, -29264942520, 0, -4111524179, 0, -223427388, 0, -5150244, 0, -42337], [-114851937312, -437071129488, -142463426112, -548299090848, -27478589362, -78344845565, -1908111912, -4379772612, -54476520, -108387684, -543494, -985711], [-252319384800, -790771271472, 368786752992, -797131265424, 77043901970, -115415499563, 5593588392, -6414033756, 174755784, -153347532, 1921318, -1324297], [63207372816, 110033646912, 77426594532, 116397020868, 8356668495, 17011630013, 309146796, 948958068, 3533544, 22710192, -4011, 196015], [0, -190007244, 0, -261099639, 0, -38905616, 0, -2138736, 0, -49629, 0, -412]];
    Rf_basisdens := [1, 2222688, 14376345984, 186705792, 186705792, 31117632, 4792115328, 653470272, 14376345984, 14376345984, 1797043248, 1667016];
    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_624_d();"
function MakeCharacter_624_d()
    N := 624;
    order := 2;
    char_gens := [79, 469, 209, 145];
    v := [1, 2, 1, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_624_d_Hecke();"
function MakeCharacter_624_d_Hecke(Kf)
    N := 624;
    order := 2;
    char_gens := [79, 469, 209, 145];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 4;
    raw_aps := [[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, -1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0, 0, 0, 0, 1, 1, 0], [-13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, -1, 1, 2, 0, 0, 0, 0, 0, 0], [0, 0, 5, 0, 0, 0, 2, 0, -1, 0, 0, 0], [0, 0, -4, 0, 0, 0, -3, 3, 3, -2, 4, 0], [-2, 0, 0, -2, 2, 6, 0, 0, 0, 0, 0, -2], [0, 0, 7, 0, 0, 0, 4, 6, -5, 0, 0, 0], [53, -4, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0], [-3, 0, 0, -3, 3, 15, 0, 0, 0, 0, 0, 4], [0, 0, 17, 0, 0, 0, 3, 10, 8, 0, 0, 0], [0, 0, -22, 0, 0, 0, 4, 3, 3, -5, 1, 0], [0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 2], [0, 0, -41, 0, 0, 0, 22, -6, -6, 5, -7, 0], [80, 5, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0], [0, 0, 61, 0, 0, 0, 18, 4, 7, 0, 0, 0], [0, 0, -36, 0, 0, 0, 18, -3, -3, -3, -9, 0], [268, -6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 70, 0, 0, 0, 25, -17, -5, 0, 0, 0], [0, 0, -71, 0, 0, 0, -8, 24, 24, -25, 23, 0], [7, 0, 0, 7, -7, -35, 0, 0, 0, 0, 0, -20], [400, -10, 0, 16, 16, 0, 0, 0, 0, 0, 0, 0], [16, 0, 0, 16, -16, 32, 0, 0, 0, 0, 0, -2], [0, 0, 60, 0, 0, 0, 37, -17, -51, 0, 0, 0], [0, 0, -112, 0, 0, 0, 56, -12, -12, 4, -20, 0], [643, 2, 0, 49, 49, 0, 0, 0, 0, 0, 0, 0], [4, 0, 0, 4, -4, -36, 0, 0, 0, 0, 0, 32], [0, 0, 74, 0, 0, 0, 19, -65, 17, 0, 0, 0], [0, 0, -101, 0, 0, 0, 48, -21, -21, 62, 20, 0], [-37, 0, 0, -37, 37, 9, 0, 0, 0, 0, 0, -10], [0, 0, 155, 0, 0, 0, 45, 40, 20, 0, 0, 0], [-1, 0, 0, -1, 1, -73, 0, 0, 0, 0, 0, -24], [0, 0, -52, 0, 0, 0, -26, 51, 26, 0, 0, 0], [938, -21, 0, -33, -33, 0, 0, 0, 0, 0, 0, 0], [0, 0, 81, 0, 0, 0, 46, -108, -57, 0, 0, 0], [0, 0, 103, 0, 0, 0, -32, -12, -12, 53, 29, 0], [-20, 0, 0, -20, 20, 84, 0, 0, 0, 0, 0, 6], [0, 0, -19, 0, 0, 0, -8, 15, 15, -32, -2, 0], [610, -3, 0, -87, -87, 0, 0, 0, 0, 0, 0, 0], [0, 0, 100, 0, 0, 0, 47, -45, -45, -16, -106, 0], [1856, 12, 0, 54, 54, 0, 0, 0, 0, 0, 0, 0], [8, 0, 0, 8, -8, 11, 0, 0, 0, 0, 0, 2], [0, 0, -406, 0, 0, 0, -165, 99, 89, 0, 0, 0], [0, 0, 9, 0, 0, 0, -9, 40, 36, 0, 0, 0], [0, 0, -312, 0, 0, 0, -78, 67, -78, 0, 0, 0], [0, 0, 143, 0, 0, 0, 48, -78, -78, 103, -53, 0], [1039, 26, 0, -11, -11, 0, 0, 0, 0, 0, 0, 0], [9, 0, 0, 9, -9, -154, 0, 0, 0, 0, 0, 44], [0, 0, 336, 0, 0, 0, -160, 27, 27, 9, 63, 0], [862, -24, 0, -108, -108, 0, 0, 0, 0, 0, 0, 0], [0, 0, 260, 0, 0, 0, -99, 33, 33, -128, -62, 0], [129, 0, 0, 129, -129, -22, 0, 0, 0, 0, 0, -12], [0, 0, 276, 0, 0, 0, -72, -6, -6, -30, -42, 0], [44, 0, 0, 44, -44, -114, 0, 0, 0, 0, 0, -102], [0, 0, -552, 0, 0, 0, -134, -293, -150, 0, 0, 0], [682, 6, 0, -30, -30, 0, 0, 0, 0, 0, 0, 0], [-13, 0, 0, -13, 13, 521, 0, 0, 0, 0, 0, -26], [0, 0, -58, 0, 0, 0, -15, 193, -13, 0, 0, 0], [-126, 0, 0, -126, 126, 293, 0, 0, 0, 0, 0, 42], [0, 0, 317, 0, 0, 0, 124, -60, -55, 0, 0, 0], [0, 0, 368, 0, 0, 0, -161, 9, 9, 70, 88, 0], [635, 76, 0, -121, -121, 0, 0, 0, 0, 0, 0, 0], [127, 0, 0, 127, -127, 91, 0, 0, 0, 0, 0, -54], [0, 0, -49, 0, 0, 0, -74, -74, 173, 0, 0, 0], [3115, 34, 0, 221, 221, 0, 0, 0, 0, 0, 0, 0], [0, 0, -607, 0, 0, 0, 207, 18, 18, -104, -68, 0], [3173, 22, 0, 179, 179, 0, 0, 0, 0, 0, 0, 0], [119, 0, 0, 119, -119, 355, 0, 0, 0, 0, 0, -78], [0, 0, -169, 0, 0, 0, 110, -66, -66, 169, 37, 0], [0, 0, -4, 0, 0, 0, -17, -285, 47, 0, 0, 0], [-88, -66, 0, -72, -72, 0, 0, 0, 0, 0, 0, 0], [0, 0, 181, 0, 0, 0, 50, 148, 31, 0, 0, 0], [0, 0, 300, 0, 0, 0, -252, 87, 87, 21, 195, 0], [-92, 0, 0, -92, 92, -52, 0, 0, 0, 0, 0, -18], [-346, 16, 0, -244, -244, 0, 0, 0, 0, 0, 0, 0], [135, 0, 0, 135, -135, -391, 0, 0, 0, 0, 0, -2], [1438, -30, 0, -138, -138, 0, 0, 0, 0, 0, 0, 0], [0, 0, -937, 0, 0, 0, 196, 87, 87, -86, 88, 0], [-2789, 52, 0, -229, -229, 0, 0, 0, 0, 0, 0, 0], [0, 0, 472, 0, 0, 0, -16, -105, -105, 101, -109, 0], [4769, -55, 0, 22, 22, 0, 0, 0, 0, 0, 0, 0], [0, 0, -76, 0, 0, 0, 13, -465, -115, 0, 0, 0], [0, 0, -925, 0, 0, 0, 228, 51, 51, -14, 88, 0], [-211, 0, 0, -211, 211, 49, 0, 0, 0, 0, 0, -98], [2590, 48, 0, 204, 204, 0, 0, 0, 0, 0, 0, 0], [-108, 0, 0, -108, 108, 471, 0, 0, 0, 0, 0, 44], [0, 0, 1583, 0, 0, 0, 524, -22, 11, 0, 0, 0], [0, 0, -660, 0, 0, 0, 277, -51, -51, 84, -18, 0], [0, 0, -180, 0, 0, 0, -426, 363, 363, -357, 369, 0], [0, 0, -479, 0, 0, 0, -54, -40, -317, 0, 0, 0], [0, 0, -667, 0, 0, 0, 447, -132, -132, -14, -278, 0], [0, 0, 723, 0, 0, 0, 316, 190, -225, 0, 0, 0], [0, 0, -1324, 0, 0, 0, 136, 270, 270, -434, 106, 0], [155, 0, 0, 155, -155, -233, 0, 0, 0, 0, 0, 126], [-331, 0, 0, -331, 331, -332, 0, 0, 0, 0, 0, -4], [0, 0, 2132, 0, 0, 0, 693, -103, 53, 0, 0, 0], [-3077, 34, 0, 209, 209, 0, 0, 0, 0, 0, 0, 0], [0, 0, -79, 0, 0, 0, -115, 130, 266, 0, 0, 0], [434, 0, 0, 434, -434, -391, 0, 0, 0, 0, 0, -44], [0, 0, 555, 0, 0, 0, -284, 105, 105, -228, -18, 0], [93, 0, 0, 93, -93, 1462, 0, 0, 0, 0, 0, -188], [0, 0, 1013, 0, 0, 0, 245, 560, 278, 0, 0, 0], [2960, 80, 0, 82, 82, 0, 0, 0, 0, 0, 0, 0], [0, 0, 91, 0, 0, 0, -450, 264, 264, -61, 467, 0], [141, 0, 0, 141, -141, 161, 0, 0, 0, 0, 0, -176], [0, 0, -50, 0, 0, 0, 588, -432, -432, 446, -418, 0], [-3607, -78, 0, -417, -417, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2134, 0, 0, 0, 707, 677, 13, 0, 0, 0], [-3418, 12, 0, 264, 264, 0, 0, 0, 0, 0, 0, 0], [-25, 0, 0, -25, 25, 927, 0, 0, 0, 0, 0, 184], [0, 0, 2853, 0, 0, 0, 878, 152, 219, 0, 0, 0], [0, 0, -2282, 0, 0, 0, -1004, 417, 730, 0, 0, 0], [-10, 0, 0, -10, 10, 738, 0, 0, 0, 0, 0, 140], [0, 0, -505, 0, 0, 0, -104, -834, -193, 0, 0, 0], [0, 0, -72, 0, 0, 0, -656, 456, 456, -240, 672, 0], [66, 0, 0, 66, -66, -498, 0, 0, 0, 0, 0, -162], [0, 0, -1294, 0, 0, 0, 313, -39, -39, 550, 472, 0], [-9646, 126, 0, -426, -426, 0, 0, 0, 0, 0, 0, 0], [-5209, -45, 0, -138, -138, 0, 0, 0, 0, 0, 0, 0], [314, 0, 0, 314, -314, -1286, 0, 0, 0, 0, 0, -110], [0, 0, 927, 0, 0, 0, -26, -234, -234, 321, -147, 0], [0, 0, -2255, 0, 0, 0, -568, -692, -551, 0, 0, 0], [-298, 0, 0, -298, 298, 252, 0, 0, 0, 0, 0, -6], [-8714, -18, 0, 426, 426, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1920, 0, 0, 0, -991, 147, 147, 318, 612, 0], [0, 0, -412, 0, 0, 0, -9, 1085, -385, 0, 0, 0], [-8315, -248, 0, 605, 605, 0, 0, 0, 0, 0, 0, 0], [0, 0, -1173, 0, 0, 0, -672, -434, 843, 0, 0, 0], [0, 0, 2248, 0, 0, 0, -608, 15, 15, -499, -469, 0], [0, 0, 266, 0, 0, 0, -75, -1167, 491, 0, 0, 0], [-5864, -259, 0, 175, 175, 0, 0, 0, 0, 0, 0, 0], [-351, 0, 0, -351, 351, 1133, 0, 0, 0, 0, 0, -232], [-700, -168, 0, -138, -138, 0, 0, 0, 0, 0, 0, 0], [-110, 0, 0, -110, 110, -933, 0, 0, 0, 0, 0, -390], [0, 0, -4973, 0, 0, 0, -1676, 650, 55, 0, 0, 0], [-122, 0, 0, -122, 122, 792, 0, 0, 0, 0, 0, -90], [227, 0, 0, 227, -227, 60, 0, 0, 0, 0, 0, -16], [0, 0, -2039, 0, 0, 0, -532, -124, -443, 0, 0, 0], [-464, 0, 0, -464, 464, 175, 0, 0, 0, 0, 0, -242], [0, 0, -2176, 0, 0, 0, -735, -749, 29, 0, 0, 0], [0, 0, -2563, 0, 0, 0, 1380, -270, -270, -227, -767, 0], [2212, -189, 0, -207, -207, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3903, 0, 0, 0, -786, -414, -414, 525, -303, 0], [-26629, 66, 0, -303, -303, 0, 0, 0, 0, 0, 0, 0], [338, 0, 0, 338, -338, -786, 0, 0, 0, 0, 0, 184], [0, 0, -1152, 0, 0, 0, -305, -1077, -237, 0, 0, 0], [0, 0, -1322, 0, 0, 0, 734, -201, -201, 125, -277, 0], [-22087, 152, 0, 433, 433, 0, 0, 0, 0, 0, 0, 0], [-399, 0, 0, -399, 399, 966, 0, 0, 0, 0, 0, 332], [0, 0, -2041, 0, 0, 0, -1183, 854, 1508, 0, 0, 0], [0, 0, -2, 0, 0, 0, -699, 447, 447, -136, 758, 0], [0, 0, -1105, 0, 0, 0, -415, 978, 140, 0, 0, 0], [0, 0, 1060, 0, 0, 0, -537, 279, 279, -844, -286, 0], [0, 0, 2154, 0, 0, 0, 577, 1375, 423, 0, 0, 0], [31, 0, 0, 31, -31, 747, 0, 0, 0, 0, 0, -52], [20036, 57, 0, -45, -45, 0, 0, 0, 0, 0, 0, 0], [-202, 0, 0, -202, 202, -1345, 0, 0, 0, 0, 0, -244], [0, 0, 2983, 0, 0, 0, -362, -330, -330, -247, -907, 0], [683, 0, 0, 683, -683, -1098, 0, 0, 0, 0, 0, -180], [0, 0, -1828, 0, 0, 0, -638, 111, 86, 0, 0, 0], [0, 0, -1241, 0, 0, 0, -267, 414, 414, -28, 800, 0], [745, 0, 0, 745, -745, -97, 0, 0, 0, 0, 0, -236], [0, 0, -5122, 0, 0, 0, 1498, 117, 117, 43, 277, 0], [0, 0, 3064, 0, 0, 0, 1223, -9, -605, 0, 0, 0], [-12184, -282, 0, 348, 348, 0, 0, 0, 0, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_624_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_624_4_d_b();".
// 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_624_4_d_b(:prec:=12)
    chi := MakeCharacter_624_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_624_4_d_b();".
// 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_624_4_d_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_624_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![766584, 0, 44334, 0, 477, 0, 1]>],Snew);
    return Vf;
end function;