
// Make newform 2475.4.a.n in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2475_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_2475_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_2475_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 := [-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_2475_a();"
function MakeCharacter_2475_a()
    N := 2475;
    order := 1;
    char_gens := [551, 2377, 2026];
    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_2475_a_Hecke(Kf)
    return MakeCharacter_2475_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], [4, -4], [11, 0], [44, 2], [-30, 44], [-74, -22], [-32, -60], [96, -34], [36, -12], [130, 112], [-96, 154], [196, 124], [4, 216], [334, -196], [-4, -240], [-146, 364], [380, -16], [-1008, -44], [272, -58], [474, -306], [70, -426], [-186, 128], [298, -428], [-308, 26], [512, -656], [-1282, -322], [-746, 484], [170, 0], [1440, -192], [368, 436], [-186, 340], [-230, 414], [1936, -282], [-46, 30], [1038, -540], [804, -1064], [-714, 346], [-1138, 44], [268, -752], [1882, -1524], [-16, -556], [2588, 82], [2334, -732], [1584, -1544], [2286, 794], [1768, 808], [-4558, -174], [3442, -1452], [2690, -164], [1904, -112], [3290, 920], [3820, 936], [6350, 532], [1482, -498], [-5022, 1292], [3022, -1366], [-7260, 1162], [800, -1670], [7972, -548], [350, 3124], [-2392, -1168], [4936, -1228], [1014, -80], [6062, 1828], [-4388, 3040], [6640, 2030], [-842, -482], [2118, 1452], [3970, -2496], [-1620, 2148], [6096, -4592], [2812, -1166], [4136, -1516], [3740, -5760], [-10538, 952], [3406, -1164], [-3758, 3772], [-730, 820], [-3236, 768], [4818, -6660], [444, -3316], [15162, 548], [4506, 78], [-552, 6108], [-6322, 2088], [-6236, 2410], [11400, 182], [5952, 2808], [4004, -5536], [5360, -3432], [-3376, 2424], [-8040, 4180], [-7100, -1576], [-4258, 5090], [-11374, -868], [-5958, -3140], [15672, -360], [982, 196], [-1840, 7184], [-7510, -512], [-15202, 3598], [-712, 1626], [-11018, -4086], [-3950, 6732], [-11604, 7144], [-13170, 1144], [7712, 6316], [12950, -9484], [16688, 3648], [-4884, 3690], [-358, -4840], [7140, -3232], [7608, 152], [15758, -5928], [19532, -1368], [-18156, 6064], [-7718, 4224], [25492, -1816], [-13090, 12232], [8684, 1586], [15002, -8856], [-6120, -5964], [14672, 4476], [-21564, 3194], [-3250, 8360], [-1192, -3308], [17976, 4608], [-7544, -10730], [15710, 2962], [-8866, 11882], [3800, 9664], [-5282, -988], [8616, -4486], [14526, -16468], [12690, -6488], [26300, -2020], [-12618, 9492], [-2276, -4698], [27154, -2130], [-24920, 8318], [-12880, 6888], [-39202, 2198], [-21242, 15312], [-3704, 17116], [-620, 6242], [11954, -636], [-22932, -1632], [17164, 5192], [3708, 538], [11394, -300], [-25756, 4936], [-3966, -4090], [40740, 1656], [19624, -10332], [9002, -5370], [-1478, 3508], [6752, -5970], [-3020, -2374], [39968, 2956], [5894, 16192], [-4096, 15720], [24172, 2944], [39758, -6620], [-7916, -14320], [4916, -15500], [13388, 2722], [13738, 10152], [-12930, 10196], [42396, -12400], [-25778, 11264], [-38428, 14748], [10420, -16814], [-4056, 8616], [3930, 6932], [-19602, 25826], [23258, -3404], [-52408, 5896], [-24502, -14760], [-41056, 15528], [6012, 12424], [30014, -3068], [8950, -13424], [-1412, 2328], [20770, -21140], [10752, 12294], [-13004, -15776], [5590, -15868], [-17308, -3004], [-58190, 8444], [9670, -4882], [22868, -24424], [-24746, 26064], [6686, -9090], [37254, -3004], [-19426, 27460], [-58590, 2352], [13094, 12824], [8150, 10906], [-3052, -15046], [-58330, 10458], [-16134, 7728], [-4670, 10536], [-12484, 9208], [-36746, -4420], [26188, 17148], [-2834, -4298], [-6148, 12118], [32184, 9300], [7208, -10234], [82354, -3060], [-4888, 12600], [-13884, 2760], [62716, 1956], [-49738, -13388], [8616, 25536], [49276, -26186], [20272, 9884], [34634, 13264], [-29182, 4040], [-27630, 28174], [14914, -10564], [-14320, -9520], [-76718, 2970], [9314, -38152], [-28170, -5748], [-49672, 12836], [39764, 25692], [46628, -23624], [-7154, 11100], [-75542, 3438], [76014, -13534], [-32404, -14394], [63212, -8896], [12126, -38230], [24510, -40652], [23126, -20116], [83628, -12328], [-80496, 14820], [34672, 21636], [45490, -42602], [-23184, 23328], [21274, -14540], [37042, 6196], [51492, -2916], [3224, -25720], [54724, -24464], [1726, 39618], [-36690, -16814], [-5428, -13414], [-30612, -11994], [36912, 12052], [9238, -13324], [21834, 672], [-3816, 34404], [37198, -4112], [61668, -41804], [-74, 13044], [50144, -15018], [-31832, 7128], [27662, -25658], [-11086, -17440], [-45792, 10374], [61218, -34248], [-38196, 24856], [-5110, -28948], [-80430, -18916], [-35408, 45856], [-42718, 51968], [11962, 35364], [22468, 5184], [30274, -20156], [58506, -19450], [-13324, 3082], [-62880, -26120], [-39672, 8652], [-70922, 32500], [29814, -19084], [-82200, 19796], [29210, -20938], [48596, 19604], [85934, -10086], [-64798, -26280], [-11320, 10976], [-32376, 30908], [64834, -28980], [-112838, -10024], [-48412, 8020], [-18924, 64174], [90294, 22032], [-93672, 1908], [31866, -39228], [-25688, -43556], [88752, -27130], [4704, -30354], [46520, -6648], [-40742, 46528], [35120, 15684], [79328, -6592], [46088, -37634], [-49254, 6992], [49054, -30670], [33548, -5608], [-72816, -14148], [-103322, -1128], [-5056, 25348], [104494, -45608], [-40696, -40308], [44876, 5938], [-12402, 23226], [-45682, 65928], [-3396, -42394], [15676, -73368], [-3322, -29742], [17490, 4096], [63916, -25136], [-11108, 2372], [-22438, 66532], [-46184, 42402], [29646, -17886], [-162214, -3156], [108420, -46246], [102248, -37464], [87954, 25308], [-16586, -11316], [-22648, -12260], [2140, 70016], [15314, 40406], [-53098, 15356], [-63038, 32976], [41946, -81072], [20346, 53958], [-50094, -8846], [-4870, 68110], [-62552, -17644], [172138, 6260], [85242, -56388], [104110, 15004], [-53292, -564], [127806, -32932], [49978, -39176], [-64240, -38474], [-34784, 60216], [-105062, -5048], [11028, -64968], [63422, -66232], [-12452, 63352], [51112, -30768], [44602, 67280], [80706, -65722], [-11602, -33560], [165210, -37580], [-30720, -59168], [-190250, -5348], [-79670, 6908], [69392, -18468], [78524, -26144], [-37194, 67544], [-83824, -21628], [-194896, 10310], [-94684, 21798], [-16240, 51996], [10692, -21864], [-23428, 16512], [150394, 13052], [85474, -12728], [-45868, -46524], [-159354, -10996], [-110884, 53400], [-164492, 12680], [-66450, 2986], [70460, -7014], [-169854, 45670], [47806, -77780], [88660, -17296], [69336, 8712], [98936, 22078], [20672, -39014], [-87460, -2958], [97790, -38824], [-119370, -25860], [-127720, 9680], [54314, -19100], [91354, 38182], [38640, 40756], [-76776, -38864], [302, -37676], [55056, -26192], [-174016, 3068], [-175030, 14408], [64558, -63852], [-58156, -30352], [66748, 73864], [148216, 34044], [-43172, 17890], [137470, -12542], [-22722, 15168], [95720, -68204], [-124640, 38742], [172130, -904], [140170, -31464], [31572, 47652], [74662, -20772], [-90304, -64442], [-60614, 27134], [69366, -20076], [-55564, 4734], [88900, -63160], [156140, 27544], [131736, 15534], [185926, -58596], [-107700, 82280], [-163282, -35526], [-29008, 13670], [-59690, -59496], [-202308, 40644], [40672, 8496], [-22030, 67208], [-164218, -5606], [-5070, 53252], [44144, -84842], [9424, -84108], [-156540, 50344], [90078, -11112], [-225774, 8352], [-64196, 96800], [-172900, -28402], [219872, 32060], [73936, 45888]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2475_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2475_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_2475_4_a_n(:prec:=2)
    chi := MakeCharacter_2475_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_2475_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_2475_4_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2475_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-4, 1, 1]>,<7,R![-64, -4, 1]>,<29,R![1328, -158, 1]>],Snew);
    return Vf;
end function;