
// Make newform 1200.4.a.bt in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1200_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_1200_4_a_bt();".
// 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_1200_4_a_bt();".
// 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 := [-10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_1200_a();"
function MakeCharacter_1200_a()
    N := 1200;
    order := 1;
    char_gens := [751, 901, 401, 577];
    v := [1, 1, 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_1200_a_Hecke(Kf)
    return MakeCharacter_1200_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, 0], [3, 0], [0, 0], [3, 3], [21, -3], [-39, -3], [-51, 5], [-28, -12], [-24, -4], [-159, -21], [-26, -6], [-153, 27], [-204, 6], [60, -48], [90, 46], [-201, -41], [93, -3], [170, -48], [366, -30], [18, 90], [-666, 54], [-190, 150], [-492, 104], [558, 72], [384, -120], [-561, 93], [-1545, -33], [-1080, -44], [-332, 102], [-153, 271], [-909, -45], [1455, -177], [651, -157], [38, -18], [-111, -249], [-182, -90], [21, 273], [-1458, 90], [-12, -32], [-1443, -419], [2925, 45], [3356, 6], [2046, 222], [-678, -174], [-2517, 131], [-3454, 54], [1054, 534], [-2541, 123], [-732, -32], [-8, -402], [-3915, 253], [642, 258], [-1846, 348], [243, 315], [-285, 59], [72, -100], [2223, 837], [-2834, -798], [-5997, -129], [2778, 84], [3414, 498], [-3477, -365], [-1440, -1044], [-1074, -978], [858, 210], [-2895, -1111], [628, 1260], [6978, 66], [4896, 460], [-3194, -276], [9621, 397], [108, -828], [-573, -861], [-1155, 1833], [-1090, -1650], [282, 950], [9957, -597], [-3465, -981], [5340, -1038], [-3608, -42], [7167, 1383], [-5392, -426], [-3276, 1404], [4698, -1710], [-5950, 1590], [8184, -292], [-936, -1314], [4092, 852], [5757, 75], [6105, 57], [6720, 76], [15270, -690], [4401, 1305], [10455, -537], [-12448, 168], [3774, -1462], [7017, 1443], [7416, 1926], [4950, -1998], [-2644, 1566], [948, -672], [-23301, 395], [4608, 404], [10128, 222], [5356, -1068], [15264, 0], [-3360, 796], [6495, 823], [12756, -516], [3284, -1002], [23181, -75], [-10413, -2889], [8301, -427], [6338, -1638], [3898, 30], [-10344, 2226], [4530, 4062], [7206, -3110], [-15627, 445], [-2145, -3345], [10622, -2340], [174, 1254], [-10647, -2719], [6132, -1480], [-9584, -528], [-16335, 27], [-19892, 882], [17496, 1584], [-12111, 1497], [4155, 663], [2708, 2652], [-3330, -2998], [-30734, -618], [-18549, 1863], [-132, -4566], [18424, 2226], [22893, 805], [-12990, -1434], [165, 3749], [6660, 1350], [18358, 1350], [2913, 3459], [-18807, -951], [-13404, -1040], [-5240, -1350], [17520, -600], [-9537, -3165], [10425, -5071], [-34570, 150], [19740, 2192], [-31443, 2937], [-16722, 1584], [-15750, -5418], [-12180, 2056], [24240, 3036], [18048, -1200], [650, -1890], [-6072, -3378], [14868, -1404], [-9519, -3009], [-26616, 3892], [-13149, -2933], [-27129, 2535], [-9981, 459], [24129, 2105], [-37374, 1886], [16138, 3990], [-12999, -1947], [-33830, 1740], [-24663, 1561], [-15303, -3687], [20150, 672], [-1488, -5424], [18498, 3090], [2294, -4854], [-5502, 12], [-2366, 1434], [41409, 1143], [21285, 117], [-14870, -6300], [3513, -6207], [-21489, 5127], [-38973, -849], [-7965, 1259], [-39390, -1138], [45255, 465], [-23751, -5715], [-24186, 3138], [49006, -3516], [4482, -1854], [3330, -2142], [48108, 3344], [55810, -582], [-15681, -447], [-27264, 2380], [-38793, -689], [1934, 2688], [-24423, 3261], [-25605, 899], [-13878, -10], [-27921, 7041], [2950, 2178], [28533, -519], [-11042, 8112], [-35019, -1251], [41607, -6193], [-4858, -702], [7212, 4640], [-45726, 636], [26152, -7704], [-14634, 1998], [-32613, 2805], [-66369, 3831], [-4824, -12860], [-11382, 9762], [-8290, 6792], [-32241, 1887], [6540, 10722], [-16518, -9986], [45915, -6917], [-9412, -6606], [-55306, -3414], [-10920, -4830], [84933, -891], [-2280, 11956], [-14750, 12900], [47643, 1795], [-7848, -9792], [-19635, 1461], [-71583, 3201], [53709, -1551], [-5158, 1338], [-15374, 6822], [23250, 4092], [84498, -3666], [-7464, 2740], [9856, 4854], [-33897, -4145], [-44043, -1587], [6570, 7938], [15408, -11116], [2872, -9744], [-19923, 6285], [7534, -2364], [7353, -1295], [-61662, 4602], [41607, 10359], [-68331, -1131], [7868, 9972], [58152, 3020], [327, 1587], [-67518, -2880], [-56532, -9032], [-58688, -4722], [45843, 1075], [-87201, -3969], [77192, -1470], [24006, -14550], [46623, -3649], [-31662, 3546], [43395, -10533], [52908, -9032], [18496, 9174], [21447, 8091], [-61701, -9085], [23996, 6084], [-33597, 3717], [-87330, -1068], [103566, 426], [35217, -3239], [-17002, 5424], [-15840, 9756], [-5442, 9390], [11294, 7746], [-76470, -10086], [-4833, 8055], [86892, -5576], [43390, -5820], [13094, 17808], [-1041, 16719], [79236, 4616], [46162, -12714], [91698, -5882], [-946, 2688], [61260, -1704], [107514, 2394], [20808, 12240], [6201, 7073], [59354, 4326], [-116550, -1080], [10059, -1347], [-7680, 20236], [-23967, 12745], [-38523, 6501], [30963, -11625], [-75675, 9075], [-83402, -5550], [17721, -20663], [22365, 19125], [-47256, -6108], [54762, -7374], [47541, 7853], [-37366, -8154], [-41712, -20956], [45460, 20388], [5364, 1980], [-62280, 1396], [22708, -14478], [105762, -10902], [-22275, -6327], [10740, -8968], [30573, -14193], [38976, -9834], [-53808, -5100], [9870, 10786], [83278, -3048], [-125931, 741], [45258, 14610], [-42306, -6306], [-16374, -14136], [6724, 13404], [2082, -23478], [40869, 63], [30465, 8577], [-87015, -1967], [83594, 4428], [108170, -6150], [-14088, 19500], [96534, 4042], [-26463, -5999], [-39508, 17370], [44379, 8315], [-81790, -4770], [-144216, 10268], [95470, 13878], [48384, -10628], [16894, 696], [-37803, -1859], [-66760, 19962], [77931, 1755], [51285, -12687], [-66543, 7817], [-8553, -1707], [-51182, -7530], [-49293, 9091], [-42795, 21645], [-70660, -18318], [12, -1896], [40674, -18246], [76593, -21199], [-83954, -7218], [-114372, 4356], [59601, 1131], [-79221, -4557], [718, 1692], [-46263, -9599], [29352, -22152], [-125523, -11619], [-44937, -19009], [-132792, -6916], [-35751, -21675], [21678, -4236], [-80298, -14246], [3813, 237], [-8730, -23814], [-51576, 24024], [-18501, -4405], [-157257, 2799], [-2536, 2538], [-177963, 1581], [-122698, 3318], [96186, 2246], [174603, -3783], [-33038, -14514], [-68373, 2007], [90957, -17787], [13140, 31428], [-107244, 12852], [-14256, -23994], [-30360, 24864], [-45003, -18285], [43575, -18977], [-120393, 18999], [-152331, -1075], [74774, -21834], [-158220, 15272], [-179018, -6054], [-71385, 17859], [187740, 8352], [159660, -8504], [-65198, -12672], [37167, 14431], [-15471, 10881], [-70602, 6618], [66540, -19092], [-84252, -22260], [54350, 26610], [-120408, 17178], [-2096, 6384], [90723, 19149], [45214, 20376], [-158949, -16973], [94623, 1743], [-153693, 4427], [-40797, -17343], [222274, 1974], [71799, -24285], [99204, -4902], [-148938, -9870], [-11577, -18033], [62436, -3948], [110775, 239], [61536, -34204], [-35864, 8472], [-61890, 2334], [-24057, -1971], [13932, -14292], [114195, -1149], [63327, 29687], [804, 10328], [84549, 7251], [150093, 1881], [-148998, 94], [181443, 7467], [-9594, -3618], [89535, -13801], [-85524, -10624], [96930, 14040], [129916, -7188], [-77232, 12792]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1200_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1200_4_a_bt();".
// 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_1200_4_a_bt(:prec:=2)
    chi := MakeCharacter_1200_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_1200_4_a_bt();".
// 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_1200_4_a_bt( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-360, -6, 1]>,<11,R![72, -42, 1]>],Snew);
    return Vf;
end function;