
// Make newform 275.4.a.c in Magma, downloaded from the LMFDB on 01 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_275_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_275_4_a_c();".
// 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_275_4_a_c();".
// 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_275_a();"
function MakeCharacter_275_a()
    N := 275;
    order := 1;
    char_gens := [177, 101];
    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_275_a_Hecke(Kf)
    return MakeCharacter_275_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 := [[4, -1], [2, -1], [0, 0], [8, 9], [-11, 0], [20, 10], [84, -17], [-24, 45], [-22, -4], [-146, 71], [12, 117], [258, 43], [6, -156], [-48, 156], [-26, 100], [26, -169], [36, -158], [-18, -119], [-58, -150], [824, -61], [-64, 58], [-704, 114], [144, 270], [-910, 43], [394, -454], [-234, -460], [534, -218], [-276, -100], [-210, -400], [162, 446], [-840, -128], [1240, 121], [-126, 1002], [1028, -1128], [986, -67], [1776, 738], [302, -1161], [-62, 699], [684, -267], [2160, -134], [1664, 280], [210, 416], [-4488, 308], [380, -629], [-1640, 356], [-972, -265], [-1264, 1113], [226, 692], [-1840, -926], [214, 452], [4928, -1253], [1192, -1166], [3894, 504], [-1968, -726], [5694, -1180], [1356, -3129], [4226, 1658], [-512, -832], [-1068, 568], [-3586, 968], [4024, -2026], [-2588, 2434], [-2724, 1382], [2960, 73], [-3050, 3176], [-1082, 2297], [620, -1256], [4044, -2631], [5628, 1410], [2290, 612], [-1458, 1888], [-9104, -308], [222, -2154], [-9072, 502], [-7468, 2158], [-2834, -3112], [-4102, -2000], [-1950, -4456], [-11966, 2317], [9738, -3438], [-5928, -2824], [2454, -1398], [-8792, 1720], [-10470, -170], [-5776, 732], [7694, 3062], [-2030, -560], [3752, 4161], [5754, -3503], [-9430, 4204], [482, 4583], [-14880, -2112], [22, -6786], [-9208, 5597], [-1540, 5680], [-6052, 812], [8966, 862], [-14762, -1504], [132, -1532], [8346, -1233], [1072, 5688], [5416, -8282], [-1796, -1262], [7170, 6646], [-10344, 843], [7810, -3264], [-18206, 5905], [-5304, 18], [-14320, 5129], [-922, -10524], [-2772, 2839], [-1632, -2862], [8170, 478], [7880, -1196], [-5736, -7461], [-27354, -1227], [-2526, -1125], [-24414, 896], [13034, -67], [-6864, 7839], [-7534, 15472], [21916, -765], [11156, -3776], [-26530, 1289], [1248, -3350], [5742, -9847], [10002, 1876], [22448, 173], [1594, -10116], [26824, 3168], [4028, -6516], [3092, -539], [12056, -6723], [8306, 12640], [-10230, 14364], [3910, 7992], [25290, -2477], [8164, -216], [-24686, 8180], [750, -11076], [-10792, -7497], [16282, 700], [33686, -2718], [-32372, -1724], [17598, -7362], [22576, -10384], [11256, -20286], [-7556, -6545], [-9128, 10166], [-7322, 12928], [8520, -11190], [-25250, 2740], [44434, -3883], [-16584, 12736], [-678, 9255], [5172, -5613], [-20360, 13152], [-6862, 3389], [8268, -4794], [578, 3071], [-48126, 1097], [7944, -3139], [21220, -11277], [-9084, 1508], [24842, 8170], [20198, -2116], [-17952, 456], [-11936, 8064], [-898, 9796], [9186, 13299], [35680, -11611], [9570, -4028], [-2112, 7598], [-12424, -15401], [5188, -13188], [-26810, 18697], [-43628, 4848], [37974, -6850], [-44784, 12051], [28938, -12567], [-19542, 2144], [16520, -3935], [-35170, -4971], [-33824, 11135], [5474, -24532], [-24174, 30624], [-11376, -4748], [-55542, 6042], [22266, 1828], [62096, -5752], [-23982, 8238], [-10528, -7660], [9416, 15186], [-28990, -1670], [1296, 14828], [-41458, 15200], [-1482, 10794], [13662, -1848], [-16956, -12358], [56316, 9471], [-6346, -19345], [35296, -10002], [4906, -28623], [31374, -18438], [-23224, -6916], [34390, 16039], [42288, 4600], [31908, -16812], [886, -4868], [-20292, -6644], [-54432, -14007], [-29586, 10054], [23126, 12334], [24282, -25911], [-69016, 2072], [10506, -36019], [-3176, 23979], [51258, -3268], [27786, 3582], [53010, -16343], [-17638, -17012], [38472, -26030], [-38874, 3419], [-57962, -7506], [-27236, 724], [-9470, -21939], [5362, 24220], [40548, -25925], [32976, -6072], [-24412, 22208], [41690, -13380], [62592, -777], [-19520, -19258], [-62978, -2120], [-26294, -12118], [-47224, -23813], [47462, -31455], [-42116, -11858], [3844, -6328], [-35300, 26057], [16050, -23151], [15868, -10320], [-37762, 35478], [1850, -6308], [34444, -50926], [52560, -36514], [17510, -11210], [-3984, -10542], [-18176, -4287], [-18988, 11959], [20540, 15574], [-40046, 30386], [-5254, 50456], [50034, 1917], [108888, -3584], [31096, 16577], [-14126, 15594], [92840, -14930], [-8558, 50120], [90672, 1933], [-79368, -10472], [58128, -4044], [-79546, -12171], [15364, -44098], [17862, -16186], [90396, 1076], [-71742, 19294], [-57146, 13631], [32920, -22912], [28900, 10906], [-14794, 37320], [-80142, 33933], [-82614, 30894], [-3616, -1866], [-63096, 27771], [36570, -39976], [29102, 8842], [-91110, 25032], [-63154, -21264], [-5008, -6469], [42284, -6515], [-15544, -19284], [-37572, 372], [69362, 14517], [114904, -17172], [91668, -17131], [17530, 18888], [55164, -10650], [91992, -17049], [-18262, -22568], [48258, -39646], [7930, -51430], [67208, 1927], [32544, -5985], [114116, -5238], [-42170, -14540], [-30372, 15108], [19538, 6905], [7508, 22904], [-58676, -16026], [-12592, -6911], [-54864, 34572], [44920, -8380], [-40422, -2526], [70516, 25158], [83854, -50302], [-18466, -48602], [80862, 28578], [-61384, 27413], [133472, 15768], [-55956, 30184], [54526, -62164], [43066, -58550], [-86834, 24095], [22036, 48709], [-15754, 36192], [-52264, 19558], [94520, 13888], [24946, 34272], [-62118, -17406], [-70280, 77615], [-103894, -21704], [-15534, 20736], [23610, -82548], [-89336, -28499], [48502, -6279], [22760, -84546], [-74882, 15246], [-4000, 11261], [-38144, 22064], [168886, -6549], [68634, -34620], [-74640, 32712], [-6444, 61458], [28352, -12659], [27094, -24853], [16274, -15888], [-10272, 62075], [-139578, -14293], [-54712, 12477], [-25278, 47412], [-48058, 4016], [101722, 33319], [-67068, -23001], [176002, -21233], [48024, 54443], [32298, 36330], [-108026, 60333], [-33200, -7492], [-148486, 22621], [48096, 25385], [-73090, -6588], [68454, -58962], [-7888, 36531], [80038, -27255], [-65988, -52311], [79700, -52255], [-41192, 32351], [26284, 21070], [13350, -56018], [35148, 29406], [87122, -23474], [-95466, 20342], [-36920, 82487], [82358, 1143], [24058, 1830], [-13576, -40810], [20068, 21377], [-13914, 34922], [58016, 488], [50168, -25020], [-624, 58432], [914, 65861], [-93816, 44390], [-56454, 79632], [102392, -3952], [-23360, -23830], [47664, 53371], [-102750, 20710], [52544, 39969], [78222, 6394], [47150, 1364], [73808, -76932], [-64468, 17657], [44556, -48300], [54030, 7290], [-58924, 78772], [-35082, 10845], [7284, -65928], [53066, 39128], [88398, 29995], [-16022, -1859], [94020, -11100], [-10218, -41670], [-19756, -35068], [58876, -57438], [-60160, 68130], [18542, -66619], [-26664, 49282], [6598, -64951], [140266, -51609], [84898, 48940], [27260, 15720], [217134, -23358], [-79698, 107496], [-100120, 72546], [45958, -42775], [-34742, 69916], [144302, 8457], [-6300, -44522], [-32196, -71454], [-32908, -43924], [139702, 20030], [167748, 2336], [31352, 95530], [70714, -38258], [-14560, 74492], [-169718, -21714], [142230, -59652], [59664, 21229], [104542, -99178], [-118548, 67068], [81458, -146222], [-171088, -26779], [-30650, 66012], [-195678, 74637], [-137054, 75137], [15338, 8558], [-85920, 97740], [221448, 28894]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_275_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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