
// Make newform 1475.4.a.a in Magma, downloaded from the LMFDB on 09 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1475_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_1475_4_a_a();".
// 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_1475_4_a_a();".
// 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 := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1475_a();"
function MakeCharacter_1475_a()
    N := 1475;
    order := 1;
    char_gens := [827, 651];
    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_1475_a_Hecke(Kf)
    return MakeCharacter_1475_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], [-1, 3], [0, 0], [5, -2], [6, 1], [52, -9], [-86, 3], [-67, 27], [36, 24], [-123, -61], [52, -48], [172, -53], [255, -58], [44, -53], [40, -106], [245, 151], [59, 0], [-242, -120], [746, -166], [-76, 441], [98, -244], [-99, -26], [-944, -75], [166, 356], [-514, 672], [-94, -611], [-820, 350], [-585, -25], [-950, 512], [-92, -540], [-1081, 557], [-152, -500], [-339, -134], [-1764, -326], [526, -59], [-194, -812], [-404, 722], [-384, 834], [1941, -1053], [138, 33], [816, -2047], [1337, 855], [-2474, 328], [777, 1526], [-1414, 994], [231, 1509], [474, 609], [-2508, -805], [2986, -609], [-3002, -891], [2412, -2484], [-2365, 833], [-3871, 654], [-229, 239], [-1421, 932], [1097, -452], [660, -2559], [3969, -378], [741, -2443], [1227, 2620], [-5472, -317], [-2281, -2491], [1153, -1777], [-9213, 48], [1918, -360], [-3966, 2022], [-6535, 599], [820, -1306], [3144, -3428], [-3888, -615], [-5428, 3374], [701, -1154], [-3276, 1404], [1902, -912], [-7593, 435], [3264, 2373], [402, 3690], [-11010, 1512], [-812, 5306], [-1452, 2894], [7752, 2301], [-9280, -1547], [13896, 76], [-5807, -3206], [2136, -3673], [-4796, 2419], [-8563, 690], [10208, -4886], [3510, 2024], [8988, 2422], [1154, 3533], [-2304, -848], [-1995, -6272], [-1221, -6989], [4169, 905], [6590, 4484], [-15616, -2262], [982, -748], [17541, -2563], [7268, 569], [-21284, 2230], [14421, -353], [-13960, 1236], [7240, 920], [-8314, -3394], [7879, 2076], [554, 429], [10283, 2695], [845, -4770], [-6684, 5150], [-3807, -2796], [6154, -5399], [-16885, 7260], [4623, 7797], [6836, -4781], [20146, -964], [-11789, -541], [2633, 6231], [5205, 1881], [8758, 1766], [6711, -137], [2418, 12088], [10490, -2102], [-2278, 6857], [2856, 9347], [-15692, 1023], [-6735, 9535], [3094, -9636], [-17508, 11591], [11366, -3288], [26456, -3721], [17264, 2256], [-294, -12542], [-1461, 4907], [7397, 4705], [-2870, 2278], [-5482, 15400], [2180, 2984], [19222, 1635], [-9116, 11094], [14488, -1183], [-3494, -2281], [17594, -11028], [-14740, -5256], [1433, -6937], [43150, -960], [17023, -4993], [-5870, 8832], [-43472, 372], [-15850, -760], [24811, 3765], [19840, -4944], [-9187, 9049], [-11590, -5916], [4499, -19349], [-32413, 9318], [-16688, 12142], [-1298, -1854], [1344, -2280], [8284, 17266], [-18857, 10419], [33714, -6597], [-39352, -2146], [-21905, 6275], [-37118, -814], [370, 12900], [18870, -9470], [-31905, -2743], [-58118, -1132], [20486, -8927], [14732, -22026], [7968, -10581], [-10353, 13710], [20008, -5396], [4449, 10426], [-11363, 11304], [-6701, 307], [9634, -3087], [-416, -7576], [17823, 16239], [19887, -7411], [-8407, 8455], [-7342, 1733], [44133, -3783], [38084, -19595], [16174, -13084], [3388, 11710], [49292, -857], [-52292, 6776], [32658, 11088], [-15192, 21510], [-73078, -1055], [15746, 5261], [-31518, 18292], [8579, 685], [-37718, 10424], [-54706, -488], [-35470, 451], [8378, 18536], [-7906, -12516], [-7822, -14700], [-58799, 1131], [-46714, 15378], [29484, -10884], [22091, 4767], [-22804, 15753], [-11360, -10642], [-29656, -13537], [8308, 14534], [46384, -8663], [19462, 13780], [19091, 14277], [12863, -39418], [-4835, -11811], [46975, -25232], [-56482, 506], [-41428, 18599], [-8114, -6831], [27766, 16694], [-7550, 20860], [-20556, 44325], [47580, -17850], [11538, -11358], [-11295, 18503], [53360, -3685], [-19522, 5171], [-35463, 8725], [-22120, -8784], [-6302, 30820], [-17359, 4373], [-7028, -4953], [2516, 6659], [7158, 37142], [-22974, 17494], [100534, -178], [65897, 7835], [-18582, -14346], [2828, 21898], [11706, -40526], [28496, 11495], [51619, -3419], [31616, -6205], [31945, 7520], [9385, 12887], [-68509, -196], [-23316, -34571], [10204, -1804], [-20340, -10183], [-53165, 29055], [-22725, 4358], [-34581, 15813], [12580, 23518], [14602, 24216], [-42975, 29324], [58643, -26299], [29628, 15218], [-44619, -15421], [24588, -43456], [-66350, 16], [37558, 4389], [-5604, 10044], [12263, 15893], [8587, -38987], [-7974, -23126], [32939, 35931], [34346, 34761], [11001, 34587], [-80200, 28928], [26575, 38247], [-26681, -7581], [-70404, 15858], [-109420, -11064], [49702, -29210], [-41277, -27000], [-50655, -11592], [-53634, 15278], [-68568, -23074], [-6269, -46207], [1532, -18660], [-38605, -21409], [80044, -6547], [10968, -39346], [-107216, -12208], [38378, -8351], [45750, 7910], [41746, -26396], [-10206, 30890], [29993, 1279], [12930, 736], [-65453, 2835], [70100, -1701], [-64868, 6978], [70778, 12516], [-25298, 61039], [-55045, -10009], [42712, 17973], [75004, 21189], [-53413, 235], [-22950, 50495], [-110804, 15824], [26031, 5547], [-52138, -45325], [-27192, -40230], [59148, -62707], [38249, 43107], [-60656, 7104], [21181, -9359], [-8446, -63253], [83036, -29776], [24280, 11810], [132251, -6752], [52083, -77519], [-19531, 35482], [69794, 6365], [54001, -80622], [-95150, 14432], [37386, -1318], [-116449, -12822], [-866, 24880], [51594, -39321], [-84628, -8530], [93930, -50598], [2335, -2027], [48711, 19281], [114679, -17745], [121810, -1820], [153188, -9417], [4636, -68476], [-95142, -30686], [-12058, -49048], [50148, -23099], [-46672, -46958], [72806, -53784], [-1659, 15233], [-74348, -40830], [-59723, 6921], [-49699, 57435], [-44014, 12142], [38236, 34290], [-53245, -53071], [-102554, -11468], [76828, -2046], [-113076, 41619], [-32492, -1788], [-143930, -4945], [-87626, -11273], [37888, 40287], [10713, 53361], [-113644, 9304], [-17770, -5264], [53910, 53046], [-203229, -846], [-92879, 42507], [46058, -57314], [-200626, -4466], [55642, -85320], [121166, 2986], [28117, 27885], [132643, -10605], [-21779, 67398], [-137296, 40443], [88075, -62828], [129627, 15320], [-78898, 45671], [39156, -25986], [-122932, 7500], [88276, 25743], [118033, -69400], [-99158, 3720], [-155348, -5406], [-39152, 19655], [24668, 10474], [-33066, 55216], [-161146, 55000], [153617, 17639], [162360, -16016], [-12, -49382], [-145206, 25728], [33444, 67718], [-45173, -26465], [-125379, -17495], [170256, 19456], [-54428, 80075], [-52042, -14632], [157979, -18729], [-177250, -2750], [74415, -46330], [-34650, -40694], [-1956, 66520], [108586, -76594], [-77406, 35920], [-57516, 80319], [102, 57507], [120660, 37049], [38546, 81002], [-151580, 194], [107203, -63367], [-136221, 42003], [42319, -93197], [18473, -10271], [111062, -28592], [63104, -47182], [-172425, -172], [107994, -9737], [30965, 68949], [76526, 45962], [-72488, 24550], [93115, -69054], [-48146, 34081], [4528, 80644], [-42143, 75528], [119286, 35332], [-40268, 114524], [-91637, 42275], [93013, 56860], [-3971, -41141], [-87018, 79808], [87832, -75066], [197796, -16626], [241199, -16584], [-180244, -2798], [142382, 43016], [167008, 35848], [-101771, -36179], [-85587, -72386], [118719, -35785], [-940, 78840], [209410, -61967], [193495, -63913], [171532, 24996]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1475_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1475_4_a_a();".
// 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_1475_4_a_a(:prec:=2)
    chi := MakeCharacter_1475_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_1475_4_a_a();".
// 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_1475_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1475_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-4, 1, 1]>],Snew);
    return Vf;
end function;