
// Make newform 675.4.a.q in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_675_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_675_4_a_q();".
// 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_675_4_a_q();".
// 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 := [6, -23, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-15, -1, 1]];
    Rf_basisdens := [1, 1, 1];
    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_675_a();"
function MakeCharacter_675_a()
    N := 675;
    order := 1;
    char_gens := [326, 352];
    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_675_a_Hecke(Kf)
    return MakeCharacter_675_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 := 4;
    raw_aps := [[0, -1, 0], [0, 0, 0], [0, 0, 0], [-14, -2, 0], [-12, 2, -4], [-14, 10, 4], [-3, -2, -8], [59, 14, -4], [-39, 32, 4], [-42, -42, 8], [83, -30, 8], [-50, 64, 8], [132, -42, -16], [16, -78, 8], [-168, 28, 4], [165, 14, 12], [-78, 82, 12], [173, 60, 16], [-302, 52, -24], [192, -34, 60], [-404, -22, -60], [221, -22, -12], [-489, 120, 60], [-756, 66, 48], [-440, -64, -8], [180, 208, -64], [-140, -272, 56], [-120, -200, 20], [953, -224, -28], [-342, -116, -20], [322, 108, -16], [-1470, 144, -72], [-1845, 2, -68], [-844, -288, 144], [-1380, 210, 80], [-700, 0, 28], [-1112, 34, 140], [2350, 176, 112], [1257, 56, -128], [-909, -34, -80], [2436, -308, -72], [41, -592, 196], [-1182, 56, 24], [262, -430, -332], [-1905, -154, 4], [-880, 276, 136], [-3295, -242, -40], [970, -720, 0], [495, 812, 56], [-3049, -228, 20], [30, -64, -8], [-234, 188, -160], [1103, -1108, -220], [-792, 492, 216], [-1689, -690, 252], [-1188, -268, -268], [-294, -580, -16], [-85, -46, 152], [340, 498, -524], [-1254, 290, 184], [1084, -770, -144], [4227, 698, 28], [1066, -56, -128], [-1914, -662, -340], [-4256, 740, 256], [-7707, 90, -56], [-3772, -404, -104], [-5246, 1370, 156], [-4164, 168, -760], [4301, -152, 312], [-1134, 116, 256], [5358, -1660, -128], [5506, 558, -200], [2488, 364, 400], [-2491, 822, 232], [465, -1156, 232], [-264, 1886, 16], [-1586, -1254, -412], [-3930, 1120, 320], [7037, -248, 644], [6900, 2490, -580], [-2797, -48, 112], [-6774, 986, -44], [-7658, 38, -756], [515, -1746, -1064], [8823, 1444, 164], [-3306, -2138, -240], [-4148, -2500, 768], [4518, -1892, 368], [4642, 1668, -56], [-8865, -180, 592], [-3636, -1958, 380], [3868, -390, 1032], [-5154, -764, 376], [6155, -1754, -240], [-10983, -1112, 540], [-6636, 2928, 1072], [-708, 902, -48], [-5054, 2002, -32], [5210, -464, 604], [1504, 1538, -888], [-66, 3700, 776], [-1440, 2152, 44], [-4746, 146, -392], [-4849, 2550, -552], [-11552, 82, 596], [5913, -520, 700], [-741, -3098, 1476], [1878, 2334, 1100], [-13087, 532, -268], [664, -2334, -712], [22792, 1072, 232], [-531, 166, -364], [-2584, 4420, 248], [1949, 1202, 1484], [-360, -2096, -1432], [1750, 1690, 0], [-9651, -164, -1760], [-11343, -442, -1312], [-13698, 2770, 828], [-7966, -1880, -636], [-4430, -2574, -908], [-11406, 2364, -156], [9459, 1632, 1824], [-4711, 4358, -1192], [-7542, 1992, 776], [-18130, 2936, -292], [11034, 1368, 192], [3904, -3588, 1800], [8080, 4176, -1728], [2597, 1634, 1808], [-3216, 5144, 1464], [-3499, 498, -1004], [17422, 3660, 248], [17442, 698, -176], [-1687, 584, -2492], [8913, -4834, -1400], [-620, 3878, 1416], [-7809, -4230, -404], [-26412, -730, -648], [12896, -7472, -452], [19050, 4160, 880], [-6368, 1786, 80], [-3195, -7212, -256], [-8350, 3540, -2044], [4224, -4380, -2104], [7492, -6572, -1776], [8901, 2786, 864], [14933, -1614, -1088], [-7239, -4820, -2292], [20344, -2690, -1404], [-6222, -7718, 1896], [18898, -8442, -1272], [7689, -804, 396], [124, 1416, 2248], [-25710, -858, 4], [11864, -2424, 664], [-2292, 486, -16], [-1832, -5084, 24], [-4602, -7416, -880], [10443, 3976, -2428], [14742, -1344, -1600], [1150, -9120, -1680], [12090, 368, -1664], [-5598, 8116, -440], [26925, 2652, -180], [14153, 3938, 772], [17128, 542, 836], [14711, 3860, 652], [-16809, 6654, 688], [9780, -1648, 2224], [-15697, 6268, 2112], [-20118, -702, 684], [-25796, 7536, 568], [37721, -6870, -1364], [-36546, -2318, -520], [-3865, -2674, -372], [4242, 8090, -872], [10924, -6702, -2208], [-25858, -80, -2988], [-10208, 6102, -768], [-4944, -6220, -1416], [38062, -4336, 336], [30558, -2428, -1444], [31707, -8384, -496], [-3852, -8984, 1704], [7066, -3466, 812], [-22832, -628, -744], [19565, 3604, -820], [9318, -11374, -1036], [-10646, -6904, -552], [5013, -1528, 3120], [18269, 1114, -3740], [28032, -4312, 2504], [-6657, 6248, 556], [-4725, -3902, 2592], [9713, -6228, -2060], [-17768, -9900, -392], [-25914, -3636, 2832], [1644, -5768, 780], [-65844, 878, -920], [5444, -4196, -2288], [-4838, 4048, 744], [38435, -3544, 1304], [-16134, 2870, 4], [-19950, -5488, 2824], [-13348, 3436, -4576], [9771, -9508, -3456], [-34020, 160, 1280], [-4492, -2048, 2624], [-9374, 5818, -1660], [27960, 8274, -352], [-35144, -88, 2528], [21048, -5208, -2044], [16764, -2136, 4344], [-23491, 16852, 3296], [29164, -1886, -3176], [55416, 3768, -1200], [-1251, -3828, -632], [14649, -5998, 1576], [-406, -5192, -4656], [-21217, 4178, 820], [-73902, 1962, -144], [57628, -754, -1416], [-1581, 5112, 2092], [-21181, -14488, 1228], [-63033, -2294, 116], [48288, -2866, 4260], [13162, -884, -560], [20580, 6128, -2024], [25636, 4078, -1980], [-43093, -10382, -1788], [-38368, -800, -3520], [-1554, -2480, -4176], [-26798, -3494, 1400], [-2313, -3460, -3944], [9581, 6476, 204], [-26901, -1602, -4064], [38706, 4920, 504], [47628, 3582, 1476], [52080, 7848, 1116], [41543, -9470, 1468], [33610, -8012, -3944], [11609, -3344, -1364], [-2526, 10812, -5640], [6906, -1812, 3040], [-4904, 14132, -1832], [13350, -650, -5580], [10964, -5520, -1320], [14643, 14400, 536], [-56378, -7908, 2912], [20538, -8364, 1744], [21351, -684, -1932], [62417, 2892, 2000], [-5091, -5306, 4320], [43296, 16504, -3808], [-27823, 17768, -1720], [26518, -16838, 1856], [29865, 9062, -5324], [-26906, -6698, 20], [37492, 10974, -4624], [-3063, 4356, 5992], [5567, 12800, 3580], [2356, 14712, -3152], [43575, -7666, 5500], [26516, 10368, -2336], [-38352, -10376, -5640], [22614, -4864, 1968], [19762, 5880, 4728], [-49722, -9804, -16], [-36529, -7752, 3936], [-5486, -15404, 4888], [-32096, 13002, 5340], [-43909, -12438, 2720], [-79028, 2474, -1924], [-1898, 15002, -248], [-15291, -5132, -4780], [-42307, 11880, -1456], [39461, 1352, -2628], [-9000, -8942, -3484], [80076, -18144, -2324], [-3853, 18538, -60], [41193, 16892, -5896], [28835, 6376, 6568], [3892, 16816, 2880], [5118, -2150, -1708], [-67562, 44, -8880], [-59430, -3280, 2920], [24725, -3822, 6144], [42576, 14584, -4408], [-90312, 7128, -1792], [30333, -19444, -604], [-2022, -12552, 2088], [-36018, -10252, 4864], [-4544, 11366, 316], [84612, -2804, -1960], [-76057, 10242, 2100], [21030, -7440, 2040], [29664, 22056, 888], [5506, -414, 4896], [-94400, -4894, 2012], [-34815, -24374, 1624], [-65560, 12320, -2104], [17631, -8312, -7564], [43289, 16522, 5364], [-2528, 8894, 5116], [-103632, -16976, 3500], [-29089, 3388, -13132], [-23964, 17398, 2180], [-28016, 20774, 44], [58875, -13236, 3672], [32724, 8412, -960], [-6528, 5492, -9368], [48730, 18574, 2048], [-115869, -2264, -252], [59747, -7300, 3440], [23040, -33152, -1624], [-20712, -3186, -5940], [-32246, 4742, -3340], [-15450, 4960, 6920], [-67255, -9738, 2148], [-132416, -8404, 568], [-25980, -4588, -4456], [-7760, -1356, 8168], [102897, -1294, -3956], [82058, 17672, -2092], [-92479, 6794, 5020], [21088, 7052, -4464], [-82440, -2704, 832], [-94293, 1038, 5180], [21626, 11848, 9328], [-48174, 11112, 5288], [33356, -8472, -6324], [-38160, -6244, -12028], [-72136, -2276, 2216], [54696, 12680, 5804], [102059, 22036, -2860], [-18531, -6842, 4896], [3242, -9084, -9492], [-40928, -18350, 1608], [-54680, 8356, 5992], [24681, -8870, -3024], [82842, 3798, 1944], [55709, -8954, 2392], [-29910, 29364, 7988], [-126024, 20870, 2884], [24431, -9928, 5632], [11332, -6436, -4944], [89292, -22044, -7680], [13359, -8374, -5944], [-11080, -6152, -2156], [130378, -23180, -4848], [-38778, 29254, 6256], [120328, -4452, -2032], [-8290, 7732, 7540], [-23115, 30382, 5600], [-17910, -18022, -8004], [-146322, -7122, -5172], [8574, -21772, 2992], [72021, 12172, 3724], [-87470, -2914, 2292], [-51390, 9988, -10224], [26556, -22364, -3244], [106530, 2852, 2024], [22228, 18492, -6504], [125818, 2466, -676], [-93363, -3134, -7252], [5590, 5864, 4448], [-26206, 1320, -1776], [-16122, -18772, -3632], [-42073, 25806, 3872], [85179, -9276, -4900], [-50424, 24126, -624], [88139, -12246, -9760], [75232, -5956, 4896], [78882, -22224, -1400], [-10206, 33192, 5280], [-22604, -19418, 7268], [-22494, 7156, -2224], [3130, 6948, 11576], [-140940, -18548, 3664], [-136833, -21774, 3924], [-129518, 410, 648], [172737, -7210, -2224], [81668, -7668, -9640], [25440, -1868, 9724], [52541, -14378, -1948], [-14102, 17138, -10052], [-101792, -13950, -1928], [4560, -1552, -7664], [9446, 25568, -6156], [-3075, -9722, 6160], [-86766, -41488, 3680], [-74678, 27208, -736], [42774, -14260, -64], [102400, -23322, 2076], [-55579, 9038, 1528], [-91194, -3858, 2808], [158525, 18610, -4236], [-98028, -6700, -10352], [67994, -21800, -11088], [-25914, -32300, 11504], [147310, -13758, 6224], [31782, -53664, -80], [49470, 24178, -12464], [155999, -19734, -2528], [-20270, 11904, 10488], [-64278, -18788, -4208], [748, -27916, 1040], [-39918, 41294, 10996], [134338, 10960, 2952], [-957, -16698, 9048], [17049, -8020, 11892], [16871, -37846, -384], [33982, 11364, 1776], [79626, 25574, 8912], [134514, -14844, 968], [-6032, 11856, 1664], [49599, 24018, -2196], [97191, 18976, -7248], [-11676, -10156, -936], [106630, -21612, -1384], [-54417, 1560, 16080], [-96858, 42692, 1352], [-100718, 16172, 352], [-182109, 33986, 8124], [-165831, 14524, 7320], [43674, -53912, 32], [-93103, -2922, -420], [43968, 138, -6812]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_675_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_675_4_a_q();".
// 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_675_4_a_q(:prec:=3)
    chi := MakeCharacter_675_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_675_4_a_q();".
// 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_675_4_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_675_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-6, -23, 1, 1]>,<7,R![1800, 552, 44, 1]>],Snew);
    return Vf;
end function;