
// Make newform 275.4.a.a in Magma, downloaded from the LMFDB on 15 November 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_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_275_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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]];
    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 := [[-1], [3], [0], [9], [11], [-2], [-21], [-85], [-22], [-165], [-83], [-1], [-478], [8], [-126], [683], [-290], [257], [-776], [-313], [-902], [830], [-842], [25], [1784], [-298], [-1832], [1404], [1050], [1668], [2384], [1167], [1164], [1260], [-55], [-598], [-1321], [-577], [1169], [-1542], [-560], [-3058], [-1828], [-577], [2164], [-4425], [-1793], [-1142], [-4906], [1130], [5403], [5090], [-6578], [3102], [-4866], [2163], [7020], [4812], [-5176], [1242], [-7402], [3578], [9094], [-7443], [-2822], [1869], [-11408], [-10251], [11494], [5690], [4398], [-8840], [5564], [-9222], [4670], [378], [10110], [-12186], [-4573], [2280], [-3700], [3612], [792], [4888], [15100], [11188], [-12070], [12449], [2957], [9738], [13779], [16320], [2744], [-853], [-6840], [5128], [-18160], [6462], [-5932], [12647], [13524], [-25066], [-12102], [-20860], [20637], [-3266], [-3351], [20258], [20445], [-1498], [-23461], [1718], [-26276], [-15560], [-28433], [9847], [-2177], [-4466], [-11507], [12825], [-8818], [9263], [1184], [1693], [13022], [1177], [-24130], [13785], [17654], [-14412], [16480], [-30127], [36577], [-19386], [-18218], [9650], [-12617], [22364], [17594], [-45030], [-2943], [-4038], [5688], [16824], [-22940], [12040], [14338], [17619], [-25550], [-36922], [-11486], [-2958], [5173], [33424], [-27101], [-23893], [-34980], [21595], [-31446], [-24353], [22089], [37893], [-40601], [-1188], [17024], [-43262], [-18328], [-34196], [-30610], [-27537], [-14165], [37262], [-19958], [19543], [-24280], [-5165], [30252], [-44268], [33883], [-32395], [-22446], [33247], [33353], [-24801], [-23922], [-52870], [-7596], [-19572], [63610], [-40148], [36708], [5568], [11062], [-38808], [-59116], [-12802], [67952], [-81782], [19814], [22763], [-42685], [44942], [2689], [-45080], [3420], [74879], [34040], [-712], [88830], [-79328], [-55311], [-10648], [65688], [80089], [-45000], [65187], [46619], [-89618], [-13416], [3513], [-80958], [-91370], [92525], [-24052], [-67736], [-6775], [42698], [2955], [-57056], [107052], [-14702], [3785], [45962], [48342], [48028], [-25221], [70435], [-69762], [-41560], [-17343], [-607], [-33308], [56188], [-21870], [25758], [10290], [-63896], [41862], [-46705], [85443], [81934], [-66848], [27594], [45115], [-50892], [-43545], [-47588], [-28146], [-30946], [-38291], [47848], [-44496], [-21635], [101558], [41624], [-53480], [-80340], [42937], [94148], [129858], [18122], [-109291], [-85832], [-41150], [-23141], [-114982], [-1136], [35710], [-24198], [-4843], [-119367], [99892], [32264], [-48743], [-9716], [237], [22158], [-3806], [22955], [-113910], [-121848], [65284], [151863], [-87183], [-85402], [86830], [46752], [-85927], [-49300], [-113726], [70193], [115944], [137240], [120548], [-129918], [-12936], [150364], [-85280], [-27215], [-67232], [-79172], [-17550], [130892], [-9137], [969], [112950], [66330], [107032], [-101162], [68420], [85417], [9994], [62022], [167418], [-37347], [3307], [-156550], [-89572], [-41891], [102348], [-186113], [-45526], [94220], [-172542], [-44573], [-146101], [-176610], [65723], [7317], [34909], [-171302], [92834], [134375], [-14793], [-86757], [-121715], [-105228], [16329], [-157248], [-216571], [-112913], [-98146], [124092], [123563], [-3295], [81573], [-113175], [43057], [86834], [101108], [-115586], [177672], [-172756], [107345], [-23641], [-8912], [-57126], [-116787], [-150288], [19892], [-93520], [49568], [144265], [-50898], [222174], [44520], [142222], [-36437], [-2820], [216649], [-118088], [46638], [5204], [193149], [187640], [115988], [118912], [218769], [69068], [89194], [102645], [-248307], [-193440], [-254856], [-123768], [3958], [-218070], [-47825], [174642], [90897], [-146225], [180078], [190604], [-39216], [175170], [33122], [-89851], [-95598], [109133], [207290], [107758], [59184], [-59252], [109852], [-134246], [149032], [129240], [4564], [-161046], [216773], [249920], [192544], [249104], [18555], [37438], [-137611], [8433], [105600], [-163788], [-31890]];
    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_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_275_4_a_a(:prec:=1)
    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_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_275_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_275_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![1, 1]>],Snew);
    return Vf;
end function;