
// Make newform 624.4.q.i in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_624_q();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_624_q_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_q_i();".
// 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_q_i();".
// 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 := [6084, 1872, 2526, -288, 595, 2, 29, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [87160788, 54255204, 104173009, 5492514, 5976355, -568842, 261773, -5924], [5315076, 10968108, -11402021, 3020182, -346833, 182186, -26943, 5984], [-201355050, 343464684, -70589441, 18697822, -5302947, 1127906, -166803, 4151], [73106644, 1395576, 983208, 1410046, 128084, 85058, -12579, 3550], [266656650, 39080772, 93482353, -24761726, 4583667, -1493698, 220899, -44524], [-182114400, 72590028, -63844208, 16911136, -2812083, 1020128, -150864, 31238], [201818916, 273536628, -22042613, 64570858, 103215, 3305704, -222399, 108812]];
    Rf_basisdens := [1, 37839126, 37839126, 18919563, 6306521, 37839126, 18919563, 12613042];
    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_q();"
function MakeCharacter_624_q()
    N := 624;
    order := 3;
    char_gens := [79, 469, 209, 145];
    v := [3, 3, 3, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_624_q_Hecke();"
function MakeCharacter_624_q_Hecke(Kf)
    N := 624;
    order := 3;
    char_gens := [79, 469, 209, 145];
    char_values := [[1, 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, 1, 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, -3, 0, 0, 0, 0, 0], [-2, 0, 0, 0, 1, 0, 0, 0], [-3, 0, 3, -1, 0, 0, 0, 0], [0, -1, 10, 0, 0, 0, 0, 1], [4, -2, -23, 0, 2, 1, 0, -1], [-29, 0, 29, -1, 0, -5, -5, 0], [31, 0, -31, -1, 0, 3, -4, 0], [0, 2, 23, 0, 1, 0, 1, 3], [0, 4, -56, 0, 5, 0, 5, 6], [-18, 15, 0, 0, 8, -15, 0, 0], [0, 6, -31, 0, 4, 0, 4, 1], [0, 10, 255, 0, 10, 0, 10, -3], [123, 0, -123, 1, 0, 18, 4, 0], [37, 9, 3, 3, -38, -9, 0, -3], [81, -3, -2, -2, -26, 3, 0, 2], [89, 0, -89, -14, 0, -7, 17, 0], [234, 0, -234, -3, 0, -15, 16, 0], [0, -36, -254, 0, -22, 0, -22, -1], [262, 0, -262, -11, 0, -34, 15, 0], [183, 42, 2, 2, 66, -42, 0, -2], [194, -3, -2, -2, -10, 3, 0, 2], [134, -36, 5, 5, -35, 36, 0, -5], [0, -17, -377, 0, -67, 0, -67, 28], [-538, 0, 538, -22, 0, -39, 24, 0], [0, 61, -759, 0, -38, 0, -38, -6], [225, 30, -45, -45, -4, -30, 0, 45], [0, 56, 7, 0, 33, 0, 33, -7], [-378, 33, 2, 2, 0, -33, 0, -2], [-371, 0, 371, -53, 0, -5, -7, 0], [0, -39, -210, 0, -128, 0, -128, -26], [-498, 108, 20, 20, 62, -108, 0, -20], [283, 0, -283, 9, 0, 67, -3, 0], [-104, 0, 104, 4, 0, 33, 54, 0], [948, 0, -948, 40, 0, 64, 135, 0], [1489, -117, 43, 43, -134, 117, 0, -43], [224, 51, 21, 21, 96, -51, 0, -21], [-612, 0, 612, -20, 0, -105, -74, 0], [0, 32, 1582, 0, 6, 0, 6, 42], [-1077, 0, 1077, 4, 0, -149, -57, 0], [0, -16, -65, 0, -183, 0, -183, 119], [320, -84, -69, -69, -168, 84, 0, 69], [396, 0, -396, -78, 0, 26, -118, 0], [0, -72, -173, 0, -6, 0, -6, 74], [0, 115, 515, 0, -75, 0, -75, -16], [-2729, 0, 2729, 19, 0, 108, 210, 0], [0, -15, 430, 0, -4, 0, -4, -146], [0, -84, 1244, 0, 252, 0, 252, 0], [-1108, 0, 1108, 17, 0, 110, 373, 0], [-1022, -36, 100, 100, -36, 36, 0, -100], [2307, 93, -16, -16, 281, -93, 0, 16], [-1755, 111, 31, 31, 82, -111, 0, -31], [303, 0, -303, 70, 0, 123, 258, 0], [-1739, 0, 1739, 134, 0, 59, -175, 0], [0, -8, 195, 0, -194, 0, -194, 183], [0, 20, 3555, 0, -31, 0, -31, 95], [-4084, 0, 4084, -56, 0, -176, -218, 0], [0, 111, -3280, 0, 402, 0, 402, 68], [-1112, 0, 1112, -97, 0, -264, -434, 0], [-1484, -132, 9, 9, -134, 132, 0, -9], [0, 36, -1304, 0, -40, 0, -40, 145], [2251, 0, -2251, -2, 0, -113, 2, 0], [2177, -366, -1, -1, -192, 366, 0, 1], [1288, 66, 57, 57, -221, -66, 0, -57], [92, -315, 50, 50, 458, 315, 0, -50], [2919, 15, 126, 126, 204, -15, 0, -126], [3472, 0, -3472, -100, 0, -219, -130, 0], [3207, -90, 70, 70, -310, 90, 0, -70], [2430, 0, -2430, 27, 0, 200, -199, 0], [0, -147, -6728, 0, 372, 0, 372, -50], [0, 91, 7730, 0, -171, 0, -171, 77], [1989, 459, -99, -99, -144, -459, 0, 99], [0, -462, 262, 0, 110, 0, 110, 139], [-806, 0, 806, -19, 0, 165, 916, 0], [0, 465, 750, 0, 304, 0, 304, 74], [4705, 0, -4705, 184, 0, -73, -201, 0], [2193, 9, 188, 188, -256, -9, 0, -188], [3454, 0, -3454, 78, 0, -297, -120, 0], [0, 292, 1451, 0, -282, 0, -282, -233], [-5555, 0, 5555, 52, 0, -90, -100, 0], [0, 146, 4778, 0, -110, 0, -110, 76], [-312, -75, -171, -171, -596, 75, 0, 171], [0, -142, 3829, 0, -237, 0, -237, -189], [-5761, 0, 5761, -150, 0, 30, -340, 0], [0, 330, -362, 0, 494, 0, 494, -311], [-2781, -477, -110, -110, -767, 477, 0, 110], [334, 0, -334, 184, 0, -188, -496, 0], [0, -24, 9755, 0, -158, 0, -158, 256], [2593, 0, -2593, -316, 0, -53, 94, 0], [-2921, 138, -231, -231, -60, -138, 0, 231], [-459, 345, 113, 113, 344, -345, 0, -113], [0, -280, -9578, 0, -330, 0, -330, -198], [-347, 0, 347, 95, 0, 381, 566, 0], [0, -217, 2556, 0, 146, 0, 146, 279], [10010, 318, -182, -182, -484, -318, 0, 182], [2264, 0, -2264, -165, 0, 20, 423, 0], [0, -341, 3003, 0, 64, 0, 64, -106], [-4657, 465, -379, -379, 373, -465, 0, 379], [0, -105, 874, 0, -4, 0, -4, -333], [-652, 273, -59, -59, -848, -273, 0, 59], [1629, -276, 505, 505, -150, 276, 0, -505], [0, -137, 1343, 0, 984, 0, 984, -332], [-14579, 0, 14579, 174, 0, -859, -47, 0], [0, -197, -3967, 0, 1551, 0, 1551, 140], [11605, 519, -343, -343, -904, -519, 0, 343], [10127, -147, -150, -150, -756, 147, 0, 150], [0, -223, 4671, 0, 59, 0, 59, -4], [-4686, -738, 21, 21, -1020, 738, 0, -21], [8609, 1107, -588, -588, -487, -1107, 0, 588], [0, -189, 10607, 0, 556, 0, 556, 22], [-8878, 0, 8878, -102, 0, -822, -132, 0], [0, 927, -3173, 0, 972, 0, 972, -61], [9820, 0, -9820, 453, 0, 136, 828, 0], [6540, -3, -16, -16, -998, 3, 0, 16], [1654, 0, -1654, -148, 0, -15, 140, 0], [2250, 0, -2250, -115, 0, -1082, -262, 0], [8946, 0, -8946, -516, 0, 945, 452, 0], [0, 26, -6640, 0, -668, 0, -668, -52], [0, -875, -7739, 0, -1501, 0, -1501, -136], [-5512, 0, 5512, 440, 0, 380, 448, 0], [0, -543, -2317, 0, -200, 0, -200, -43], [0, 576, -4941, 0, 1310, 0, 1310, -358], [-3017, 195, -208, -208, -1095, -195, 0, 208], [5125, 0, -5125, 124, 0, 821, -933, 0], [0, 192, -4492, 0, 1548, 0, 1548, -193], [-12360, 1284, 544, 544, 418, -1284, 0, -544], [-10626, 0, 10626, -461, 0, -261, -1410, 0], [-11216, 0, 11216, -414, 0, 62, 1738, 0], [2429, 1350, -465, -465, 2020, -1350, 0, 465], [4014, 387, -11, -11, 110, -387, 0, 11], [0, -1458, -2646, 0, -350, 0, -350, 96], [0, 1154, 17918, 0, 1606, 0, 1606, 162], [0, -519, -1728, 0, 226, 0, 226, -733], [0, -426, 19184, 0, -74, 0, -74, 440], [-3031, 0, 3031, 4, 0, -245, 1357, 0], [0, -90, -1564, 0, 1330, 0, 1330, 548], [7174, 0, -7174, 68, 0, 580, -1004, 0], [-6326, 0, 6326, -792, 0, -591, -1556, 0], [-12747, 0, 12747, 496, 0, 1063, -1143, 0], [0, -1541, 7802, 0, -315, 0, -315, -17], [6162, 267, 120, 120, -1468, -267, 0, -120], [0, 448, -7002, 0, 496, 0, 496, 864], [-2110, 0, 2110, 750, 0, 474, -1704, 0], [-6906, -1482, 1058, 1058, -784, 1482, 0, -1058], [0, 1245, 15417, 0, 638, 0, 638, 665], [3609, 0, -3609, 120, 0, -1927, -1585, 0], [-10058, 405, 889, 889, 258, -405, 0, -889], [4394, -1590, 461, 461, -488, 1590, 0, -461], [23799, 612, -359, -359, 228, -612, 0, 359], [-7093, 1035, 13, 13, 702, -1035, 0, -13], [19014, 0, -19014, 219, 0, -18, -764, 0], [0, -578, -7669, 0, 1482, 0, 1482, 225], [9482, -1245, 340, 340, -316, 1245, 0, -340], [0, 1175, -1685, 0, 351, 0, 351, 118], [0, 1530, 3000, 0, -44, 0, -44, 1034], [12615, -1917, 334, 334, -1883, 1917, 0, -334], [-20634, 0, 20634, -950, 0, 606, 88, 0], [5772, 0, -5772, 237, 0, -782, 640, 0], [-1091, -189, -750, -750, 1550, 189, 0, 750], [25162, 840, 872, 872, 2256, -840, 0, -872], [0, -190, -28868, 0, 1524, 0, 1524, 22], [-18924, 0, 18924, 384, 0, -914, 1606, 0], [33077, -141, -337, -337, -210, 141, 0, 337], [-6541, 0, 6541, 256, 0, -787, -295, 0], [0, -578, 13261, 0, 464, 0, 464, -637], [-24674, 1032, -86, -86, -112, -1032, 0, 86], [0, -1251, -5422, 0, 228, 0, 228, -895], [-17248, 0, 17248, -125, 0, 1299, 640, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_624_q_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_624_4_q_i();".
// 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_q_i(:prec:=8)
    chi := MakeCharacter_624_q();
    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_q_i();".
// 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_q_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_624_q();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![6084, -156, -203, 6, 1]>,<7,R![42523388944, -2608994224, 391649180, 8434260, 1232045, 9582, 1319, 14, 1]>],Snew);
    return Vf;
end function;