
// Make newform 2475.4.a.k in Magma, downloaded from the LMFDB on 19 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_k();".
// 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_k();".
// 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_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 := [[5], [0], [0], [-3], [11], [-32], [33], [47], [113], [54], [178], [-19], [-139], [308], [195], [152], [625], [320], [-200], [947], [448], [-721], [142], [-404], [-79], [545], [1306], [1938], [-576], [-1104], [1739], [-1818], [870], [-636], [239], [1208], [1874], [1904], [-1180], [-3177], [-1787], [-835], [-3613], [-4204], [-4517], [4164], [4660], [-3560], [-4678], [-4447], [411], [6380], [7282], [4728], [5418], [-3354], [-1062], [-4821], [-4], [-4647], [4283], [-6811], [460], [-8328], [5929], [5040], [10396], [7236], [1468], [5690], [5376], [-3734], [10274], [-13662], [-7906], [-3168], [-10770], [-5670], [-832], [-5712], [4559], [6855], [-10770], [-8498], [9835], [-10745], [-8356], [7058], [-646], [8982], [-13476], [-12996], [6026], [-11698], [-17052], [-932], [-4384], [2322], [9749], [4208], [-10179], [-2314], [24330], [-3445], [-13056], [17347], [8379], [1958], [-23583], [-15328], [-160], [5948], [334], [-7202], [10306], [1228], [18454], [17647], [25918], [-12864], [-11419], [-15784], [-26050], [-15095], [15896], [-10529], [-16087], [-24336], [-13960], [-9252], [28453], [512], [772], [-8058], [-18650], [-7144], [-1904], [-7555], [24950], [-19893], [34503], [-16890], [-34692], [41424], [-18494], [-6680], [-43358], [15585], [-17036], [28064], [22654], [22380], [-35174], [30868], [-10070], [-1885], [23703], [-53804], [-1326], [27109], [31143], [-879], [14824], [-34089], [33446], [-52025], [-41260], [190], [1688], [-19740], [-40274], [33374], [-61550], [43798], [-27334], [48952], [-54933], [41466], [35539], [-43306], [-15306], [67570], [9953], [-37002], [-24168], [31370], [-45294], [31260], [-18026], [49090], [4458], [-59460], [53794], [46158], [52712], [60458], [5204], [76918], [-38251], [43448], [-5545], [67088], [51583], [-21116], [14733], [-1558], [51110], [-38410], [-18297], [24532], [13002], [-35980], [90402], [-15947], [-37926], [-35829], [-30583], [3781], [-38007], [39162], [-14454], [-78464], [39152], [104090], [29026], [-50662], [-71464], [-35457], [-26231], [16668], [34105], [-50923], [-23995], [23487], [44488], [34500], [73903], [-70947], [27851], [47247], [-71431], [72031], [59272], [89181], [-23925], [-11472], [-67724], [71217], [21176], [33144], [17170], [-61007], [-36468], [-122990], [113166], [-117150], [95791], [-24816], [8414], [-65900], [-58007], [-8766], [-119900], [-94102], [-106750], [12490], [54990], [-78482], [-74839], [49167], [-69715], [-114208], [-1430], [3187], [112714], [110702], [-67151], [93586], [-37050], [-56848], [-6882], [15856], [-41236], [28726], [244], [-12225], [129585], [45751], [117206], [145557], [139896], [-141503], [70323], [131598], [-42970], [69862], [47616], [-75910], [40820], [-26717], [8018], [-49035], [75389], [107948], [-161148], [48414], [149731], [-140249], [-104669], [114136], [157078], [-64044], [7169], [45562], [59022], [74616], [-47595], [-62906], [-30467], [-175198], [144325], [-50258], [42051], [-7062], [-12714], [-82451], [51302], [194942], [107806], [128679], [192472], [-153886], [143279], [11958], [77923], [30881], [-87186], [46526], [48093], [25837], [-204953], [-9544], [57074], [138924], [138486], [-68684], [-31683], [54342], [155700], [47696], [-106799], [43643], [-134934], [-213763], [105092], [191637], [-60795], [-17528], [-131551], [179072], [70990], [-85071], [-10003], [-177772], [-201712], [-157181], [168753], [-208128], [-181932], [96140], [130808], [-61378], [79669], [168975], [-11943], [21648], [43498], [112504], [195606], [189088], [436], [-65712], [120461], [-141522], [144776], [563], [160078], [-9471], [-63205], [-212504], [102615], [149028], [40053], [-118302], [-220320], [-166592], [106503], [255166], [2610], [-24267], [35008], [-82968], [-78016], [-151746], [-28293], [190901], [180086], [115086], [-92308], [118943], [-56546], [12261], [-155531], [-10667], [6250], [-86618], [-21960], [-37670], [19518], [-116950], [1814], [-3494], [28655], [167202], [129109], [-196960], [-200211], [-76359], [-275406], [-133122]];
    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_k();".
// 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_k(:prec:=1)
    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_k();".
// 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_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2475_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-5, 1]>,<7,R![3, 1]>,<29,R![-54, 1]>],Snew);
    return Vf;
end function;