
// Make newform 550.4.a.o in Magma, downloaded from the LMFDB on 17 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_550_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_550_4_a_o();".
// 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_550_4_a_o();".
// 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_550_a();"
function MakeCharacter_550_a()
    N := 550;
    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_550_a_Hecke( : Kf := Kf)
    return MakeCharacter_550_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 := [[2], [7], [0], [35], [11], [-26], [-101], [127], [58], [-27], [-177], [-191], [66], [-444], [-2], [669], [386], [-521], [-96], [-427], [-1006], [910], [818], [601], [228], [474], [-668], [-960], [686], [-456], [-2248], [1587], [436], [-3196], [3375], [942], [-1631], [-2845], [1643], [3546], [-608], [-1942], [-3012], [-1169], [-4140], [2589], [-2205], [-1182], [3686], [1186], [619], [654], [2838], [-5010], [-3702], [-8343], [-4668], [3760], [-492], [-2290], [594], [-2042], [3190], [-825], [9438], [5107], [8588], [5485], [1850], [-8890], [2982], [3212], [-12172], [4134], [-5866], [514], [-10558], [3914], [-2197], [15164], [10856], [-2672], [1296], [5504], [-2724], [-11076], [-2190], [7841], [-3357], [-5814], [9383], [9336], [8564], [12063], [18876], [17960], [-2108], [6102], [-13952], [10361], [25184], [13062], [25018], [13736], [13985], [4154], [9429], [-4622], [-3249], [-7742], [-9167], [-13126], [13416], [-2340], [14445], [13967], [-13925], [3678], [1915], [-18539], [-2686], [-7217], [-32724], [-29663], [6950], [23319], [11654], [2411], [-5350], [20312], [20136], [34739], [15235], [-28222], [-12290], [30470], [14753], [38604], [-16170], [-16150], [-20843], [-23210], [-44408], [42456], [23332], [-8808], [8802], [-6661], [-21014], [-1422], [10514], [2658], [-6167], [8760], [-19769], [-36375], [-10056], [17235], [31738], [-4895], [41749], [5901], [-21219], [-57184], [-16924], [18398], [-3600], [-39184], [46386], [-57447], [3359], [7262], [9882], [-22081], [-47336], [11739], [-2020], [7764], [11393], [9731], [-38858], [-15285], [14711], [63143], [64386], [-28454], [260], [61148], [25726], [8896], [40488], [-23988], [7926], [73540], [26700], [69198], [-16200], [3494], [-57770], [-1343], [-6339], [-40486], [-75481], [-20392], [-21740], [-40959], [23936], [-59736], [49554], [-25088], [64649], [-66084], [-77732], [-44595], [35800], [-36245], [-69599], [61078], [-91056], [-34305], [-62202], [-41650], [72701], [-60924], [-70896], [42247], [45982], [-92767], [45480], [41292], [87254], [-30651], [22738], [-101610], [29724], [-56407], [-18469], [13346], [55436], [-86957], [56565], [17732], [7900], [-3130], [34422], [83034], [113444], [-5938], [-87805], [-1799], [-38470], [93940], [-2826], [51219], [50592], [31755], [21612], [-15934], [53818], [-38123], [119488], [-112436], [-125389], [19602], [-121996], [-37464], [-14272], [61425], [68464], [-86906], [310], [-27815], [-88216], [-121702], [3779], [10774], [128984], [-79726], [-4322], [-65607], [114931], [42036], [35200], [101983], [21756], [-127233], [-53710], [61914], [148681], [95754], [24020], [50092], [48159], [-77147], [-83810], [33930], [-17880], [38607], [-76860], [-3802], [60193], [-32300], [-82612], [-14748], [38390], [-45640], [119932], [-34600], [156483], [52328], [3516], [12930], [-51028], [110347], [-94085], [154142], [-116862], [-96992], [121098], [51684], [-93595], [106610], [84418], [75298], [-132827], [102219], [169658], [-44588], [10103], [22928], [-40039], [200014], [-15872], [6850], [-50129], [-16073], [-154270], [34019], [52661], [40639], [-75418], [49854], [125433], [-1403], [32517], [75673], [-192188], [-36347], [71140], [-38781], [-119309], [-145846], [62460], [16633], [-149681], [-17243], [51091], [-131955], [13890], [-211196], [100234], [-7344], [4972], [-178155], [65531], [92968], [-143954], [-147345], [-69968], [-47704], [-62340], [-202272], [-64377], [178218], [31002], [38880], [-11026], [62195], [74792], [68177], [-154856], [258370], [2964], [-205515], [54640], [125872], [67280], [-101977], [186604], [154926], [129293], [197867], [-51704], [164864], [-168592], [-92490], [117230], [122319], [-32986], [39983], [170209], [-46426], [39484], [-195408], [122166], [11494], [204995], [94710], [92129], [-177786], [81926], [-29712], [-126772], [-167268], [-136838], [-222952], [75540], [-72224], [69474], [-62321], [-185172], [62048], [-179772], [-19993], [216042], [-206733], [-75147], [131624], [-150516], [133130]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_550_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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