
// Make newform 735.4.a.n in Magma, downloaded from the LMFDB on 03 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_735_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_735_4_a_n();".
// 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_735_4_a_n();".
// 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 := [-2, 0, 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_735_a();"
function MakeCharacter_735_a()
    N := 735;
    order := 1;
    char_gens := [491, 442, 346];
    v := [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_735_a_Hecke(Kf)
    return MakeCharacter_735_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 := [[-2, 1], [3, 0], [5, 0], [0, 0], [-16, -38], [-7, 26], [10, 34], [-9, 64], [-34, -26], [-166, 6], [-33, -36], [9, -222], [-76, 122], [-421, 38], [106, 120], [-184, 56], [70, -186], [366, 60], [533, -250], [-604, 246], [-827, -10], [567, 32], [-484, -102], [-102, -1046], [-846, -736], [-736, -142], [-563, 478], [-806, 402], [-1151, -180], [-134, 84], [335, -1382], [-802, 1496], [14, -1858], [-361, 1828], [-2072, -1036], [-672, 652], [-462, -644], [2604, 608], [-492, 1430], [-1624, 172], [-2830, -300], [-4113, 320], [-982, 2092], [-347, 558], [1062, -170], [2032, 700], [2964, 612], [60, -44], [5036, -30], [2547, 40], [-2450, -2900], [-2734, 28], [-730, 2936], [2914, 2078], [-4116, 430], [724, 976], [1874, 3504], [1840, -1572], [7943, -290], [880, 2896], [-1679, -4338], [5764, -1644], [2475, 318], [-2012, -2594], [2007, 170], [-4818, 922], [-165, -4968], [5139, 670], [4944, -2684], [-3858, -2560], [-4272, 602], [-5422, 2958], [1543, 4818], [6737, 4938], [-6189, 2780], [-472, 2080], [-3756, -6122], [6987, 1822], [3184, -2152], [9547, 584], [8358, 3076], [12857, -468], [-3290, -4060], [-3165, 4402], [-10356, -3144], [3108, 972], [22, -11164], [-301, 4790], [-1146, 4690], [5837, -3854], [-11102, 5348], [2808, -2456], [13, -4774], [8116, -3688], [1157, -7484], [7918, -8876], [-18022, -824], [-4888, 7764], [1263, 8426], [-875, 824], [-3624, 11284], [5538, 6188], [-19166, 780], [5192, 2146], [-9411, 2728], [-10265, 2430], [-78, 13166], [-780, -10654], [-6276, -1312], [-10823, 10172], [13759, -6102], [-650, -3744], [3606, -10036], [-1447, -1152], [13728, -7576], [-4246, -14586], [14429, -5618], [-3680, -1834], [14048, -3334], [-3636, 7132], [-9707, 616], [20817, 6970], [-14038, 6178], [-2502, -16026], [-1615, 10384], [-8018, -1678], [-1242, 3892], [946, -5536], [2619, 9710], [9925, -13290], [12133, -6004], [2496, 2626], [14265, -7568], [-15558, 12168], [-430, 12598], [-2875, 8680], [-7008, -13958], [5980, -18428], [16526, 12606], [2842, -9152], [29380, 1384], [11312, 4074], [-11336, 2468], [-25526, -324], [13515, -3608], [-8826, 194], [19703, -16890], [9246, -18398], [10524, -3416], [-22558, -9904], [12874, -25448], [-5636, -20336], [11069, -4126], [18284, -17914], [-13019, 18786], [-8418, 19778], [-24333, -20704], [-42588, 7686], [-11445, -7234], [16566, 3062], [-26264, 2670], [-9104, 34808], [-4291, -26518], [43104, 6840], [44188, -3686], [11750, 16458], [-17623, -13064], [-32225, 8910], [24721, -5404], [-27662, -3354], [-1100, 27404], [-10178, 27976], [8890, -6554], [-16077, -6042], [9135, -1840], [-28076, 15780], [227, 10156], [18982, 17304], [16072, 13992], [-12383, 12064], [7299, -5370], [16202, 18050], [27151, -21154], [3920, 33416], [-3614, -24656], [20208, -13236], [32650, -4068], [-9049, -23162], [26385, -5388], [19560, -20310], [-29003, -12162], [-45612, -21590], [10968, 4240], [-10724, -24700], [5226, 9494], [1938, 15246], [11763, -11160], [-71734, 632], [-25266, -20544], [23698, 3518], [-20482, 2824], [34345, -5756], [-7690, 9236], [-2402, 23204], [-50388, -10510], [33338, 38292], [67384, -2016], [13802, 2116], [28260, -3024], [15056, -43296], [34641, 18874], [-43394, 5166], [-26080, 20492], [-15352, -44272], [-33806, 4906], [1377, -11428], [5344, -37504], [-19300, -49696], [-3780, -11972], [-14510, 43508], [23265, -21952], [20731, -39912], [44812, 18502], [39544, -2112], [16830, -34504], [-42006, -16988], [16216, 20688], [3546, -35480], [-40913, 3534], [24020, -56090], [48031, 29798], [-32156, 1304], [56675, 10612], [33316, 8806], [-19119, -42966], [58880, 18962], [48679, 6908], [-49604, 17666], [-2080, 61908], [6208, 21422], [-49032, 33386], [5711, -29976], [24813, 27710], [-65406, 14720], [-30952, -9088], [36524, -12732], [15215, 58138], [14464, 22422], [46508, -2608], [-48012, -42228], [36755, 47470], [45868, 39736], [7074, -11576], [-2429, 19284], [25556, 4132], [44318, -34386], [-35715, -35992], [20439, -798], [82140, 25950], [-38870, 38680], [44669, 16642], [69700, 780], [-81501, -4992], [24311, -29278], [9022, -4988], [19851, -54984], [-1712, 13926], [-56838, -47912], [-32788, 63532], [924, 4370], [61853, 1052], [8444, 42812], [36421, 56014], [92199, -1596], [-61942, -24940], [-42048, -2908], [-52012, 27666], [343, 80872], [46095, -21240], [-60180, -25472], [-42972, -39164], [25115, 34108], [71194, 39372], [-18087, -95228], [10432, -32444], [-2812, 21534], [11067, 8654], [52396, 20734], [17743, -72348], [-72532, 10130], [-96968, -25028], [87780, -48096], [-25104, -19222], [57366, 54434], [221, 7526], [30714, -2160], [119051, 14612], [-16006, 2062], [36672, 72466], [-23297, -83666], [-1142, 65168], [-115882, -8196], [-816, -87672], [-89308, -15040], [-8971, -35476], [31935, -35382], [30130, -33524], [32419, 21612], [20208, 33448], [15733, -33062], [10922, -40122], [-24784, 93466], [-99868, 33082], [34100, -75284], [-6036, 94340], [48043, 22964], [-26756, -16486], [-106266, 47194], [-33755, 72846], [-31348, 19546], [92235, -15300], [-42955, -4790], [-181102, 8640], [77101, -23966], [-2618, 46616], [32035, -80576], [34639, -47280], [20297, 570], [-24528, -30348], [-56386, 81804], [-10211, 21236], [16284, 94318], [66323, 73296], [34040, 76902], [81015, -26868], [78746, 23056], [96690, 54564], [-85786, 9822], [96075, 58500], [-47091, 70890], [63393, -64230], [-69246, -18362], [44320, 26244], [-71439, 52184], [12152, 28834], [-152842, -10896], [-4013, -113144], [45492, 62264], [-39044, -23478], [36970, 67956], [80732, -33108], [-53718, 81592], [42806, 3460], [-108912, 74752], [-69457, -78572], [-74930, -87564], [57382, 66888], [-52548, -72444], [103272, -28780], [55888, 77814], [-77154, 23448], [53556, 9718], [-32714, -3064], [-126398, 5184], [-6983, 134966], [-29022, -39680], [-33282, 19266], [-79789, 72826], [-94394, 43700], [-189972, 34100], [-131521, -53420], [111452, 4570], [102068, -22330], [-50231, 71860], [54655, 17830], [-36254, -66242], [19284, 48120], [-78602, -55628], [-84386, 44994], [-56627, -24398], [-87368, 64364], [83458, -9614], [20688, -155768], [-59592, 72040], [-38912, -99472], [-55164, -72936], [78827, 400], [-159486, -79768], [-10735, 94938], [112600, -77914], [-160879, -15832], [-27156, -111970], [-116402, -103102], [-76397, 127538], [110168, 64518], [40990, -18032], [-102996, -67944], [-3098, -40928], [-65081, 12784], [95854, -44612], [-23818, 76160], [78706, -34818], [-169536, 14956], [-164292, 24202], [-126144, 54866], [-15297, -47020], [-101438, -92428], [-2332, 1432], [-73351, 38490], [-100824, 53868], [326, 122792], [185920, 72884], [126150, -114318], [-183532, -7208], [44467, 118458], [-42648, 97714], [179240, -55026], [-119171, 75722], [-224836, -32568], [-30048, -140516], [164400, -39268], [-69265, 95018], [32598, 90906], [-156642, -23788], [-141026, 25260], [203868, -52178], [52906, 36580], [-244380, 16740], [115340, -60504], [90478, -5642]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_735_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_735_4_a_n();".
// 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_735_4_a_n(:prec:=2)
    chi := MakeCharacter_735_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_735_4_a_n();".
// 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_735_4_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_735_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![2, 4, 1]>,<11,R![-2632, 32, 1]>,<13,R![-1303, 14, 1]>],Snew);
    return Vf;
end function;