
// Make newform 525.4.a.h in Magma, downloaded from the LMFDB on 11 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_525_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_525_4_a_h();".
// 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_525_4_a_h();".
// 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_525_a();"
function MakeCharacter_525_a()
    N := 525;
    order := 1;
    char_gens := [176, 127, 451];
    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_525_a_Hecke( : Kf := Kf)
    return MakeCharacter_525_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 := [[3], [3], [0], [-7], [-6], [-41], [-27], [-4], [-75], [-123], [-205], [262], [57], [-407], [60], [-327], [33], [-427], [628], [300], [-98], [686], [-1401], [714], [-494], [624], [769], [-1662], [188], [18], [1450], [2664], [-1692], [1268], [2169], [518], [886], [-3893], [-2046], [3540], [-3246], [1334], [-873], [1006], [-591], [-2584], [-1441], [-3827], [5421], [-5290], [-4908], [1056], [5342], [5805], [-543], [5193], [2154], [2396], [-4286], [2208], [-3620], [1392], [-9002], [6666], [2878], [-4611], [-7459], [-5843], [-2346], [5807], [5190], [8883], [-9965], [-11660], [3203], [8220], [-2226], [-10451], [-1320], [2402], [-3333], [-1462], [-10089], [-3242], [1799], [-8772], [1560], [-11615], [6960], [-13052], [-14013], [1056], [-7886], [10590], [-14899], [-21558], [-15240], [-16797], [-22520], [-12004], [16423], [-714], [-16293], [-17370], [-12589], [13318], [7551], [6402], [-15753], [9764], [-7772], [24262], [25818], [22430], [-2830], [-5202], [22030], [20370], [31626], [-11142], [-5518], [12517], [2604], [-25986], [-24610], [10725], [-34516], [17958], [-2255], [-9539], [37979], [20535], [-2452], [36850], [30258], [29288], [-40668], [-13118], [37278], [5268], [34994], [28818], [20962], [28266], [42491], [-40512], [40525], [7182], [-7864], [-28872], [47392], [17769], [-32549], [-6714], [-29693], [-8199], [-15388], [-411], [-26066], [24048], [22968], [10248], [43060], [-12348], [44190], [-60168], [8804], [-15302], [-51361], [30408], [45702], [24875], [-1905], [-14231], [32108], [-48027], [-44332], [-20001], [-37007], [6149], [-12746], [-195], [15154], [41343], [-6168], [23154], [-1064], [19582], [-40975], [-36072], [-19472], [33300], [-16288], [72846], [-29904], [72879], [72965], [-11450], [14238], [-21048], [57414], [-24883], [-13223], [-43846], [19701], [-52836], [-5257], [-49458], [52098], [-27562], [43426], [-1278], [18862], [-23289], [56610], [-79600], [58792], [4662], [-44469], [89265], [-1312], [3623], [-12282], [-35984], [20460], [5390], [75618], [50832], [-34364], [-29862], [71008], [-72664], [-45376], [82830], [10972], [-5844], [-58138], [-99606], [-78066], [-85902], [-3120], [83054], [84619], [-79126], [11073], [-108060], [17161], [7020], [7580], [-48168], [13012], [120837], [53523], [-121138], [4116], [-57534], [54650], [-4886], [-88986], [110122], [-2804], [-79584], [-11965], [-70202], [-16359], [92978], [-57099], [-47487], [-81371], [-8595], [13655], [50551], [106840], [68276], [-524], [-2732], [-33816], [-56050], [69815], [42453], [55308], [51236], [2160], [-26035], [-79292], [-105849], [-6899], [-60558], [-5251], [27426], [91398], [-51396], [-113652], [41760], [21370], [87276], [85925], [121482], [-83583], [-70994], [25828], [-231], [69890], [-152700], [105020], [76987], [10746], [-17785], [17865], [8962], [94686], [27225], [68358], [-53936], [58953], [-72466], [-116268], [-180909], [-152912], [-4296], [-116398], [-49646], [-41454], [-24428], [-156714], [106784], [-117889], [-136418], [168072], [144333], [-120490], [-35955], [-156067], [-130191], [161795], [163740], [96764], [93117], [93710], [-48683], [-111242], [-10254], [18300], [139592], [-6297], [-154488], [-36274], [-85469], [-89892], [213042], [-87568], [-74963], [19503], [79003], [-75382], [62691], [-60630], [56487], [235578], [-25719], [-82988], [-23922], [-37968], [-203484], [-60266], [189007], [-126306], [-228620], [49985], [-46908], [26876], [35781], [-239865], [174971], [8656], [159693], [159600], [-50624], [192795], [160372], [-83262], [92268], [100780], [-255636], [-239740], [62904], [-130918], [-251210], [126628], [22014], [175871], [85272], [-103086], [-144746], [180135], [-13586], [241529], [180387], [110132], [-247542], [161309], [133698], [215620], [-67161], [212460], [-258403], [-34046], [-35190], [-38], [-224064], [33820], [-150258], [11076], [-70513], [96397], [35376], [-293721], [185719], [38145], [-161634], [166851], [269395], [-101769], [-20685], [-300908], [-180024], [6114], [-133206], [1484], [19134]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_525_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_525_4_a_h();".
// 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_525_4_a_h(:prec:=1)
    chi := MakeCharacter_525_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_525_4_a_h();".
// 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_525_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-3, 1]>,<11,R![6, 1]>],Snew);
    return Vf;
end function;