
// Make newform 7504.2.a.k in Magma, downloaded from the LMFDB on 16 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7504_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_7504_2_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_7504_2_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_7504_a();"
function MakeCharacter_7504_a()
    N := 7504;
    order := 1;
    char_gens := [2815, 1877, 2145, 337];
    v := [1, 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_7504_a_Hecke(Kf)
    return MakeCharacter_7504_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 := 2;
    raw_aps := [[0], [-1], [3], [-1], [6], [5], [6], [-2], [3], [-9], [-5], [11], [3], [10], [12], [-6], [0], [-10], [-1], [3], [2], [-8], [-6], [6], [-10], [3], [-14], [12], [-16], [-6], [7], [-12], [6], [-5], [-6], [19], [-4], [7], [6], [12], [-12], [2], [-12], [5], [-12], [-20], [13], [28], [-12], [-13], [-24], [-12], [8], [-3], [0], [12], [30], [7], [26], [-30], [4], [-12], [-20], [-9], [17], [3], [-8], [32], [-24], [26], [18], [-15], [1], [14], [34], [21], [-18], [20], [12], [5], [-18], [17], [0], [2], [-26], [12], [15], [17], [-6], [22], [18], [-18], [-38], [12], [22], [12], [-6], [-15], [-38], [38], [-8], [27], [-9], [-21], [-5], [47], [39], [-18], [-6], [-28], [22], [-25], [33], [10], [-20], [-6], [40], [-33], [-30], [9], [-49], [-28], [15], [-6], [-8], [6], [-19], [-36], [-17], [41], [-20], [9], [-32], [20], [12], [14], [-18], [-32], [30], [30], [25], [-15], [13], [24], [56], [0], [44], [6], [4], [3], [-31], [30], [16], [48], [37], [51], [-20], [27], [-25], [54], [27], [9], [-59], [-12], [-51], [-24], [-56], [-10], [-34], [-6], [3], [-22], [27], [-46], [40], [18], [-44], [-54], [-47], [8], [55], [48], [-49], [-30], [-6], [0], [-34], [19], [32], [-9], [-52], [-39], [-20], [-27], [12], [-24], [14], [-46], [45], [-18], [-6], [10], [-13], [17], [0], [-18], [16], [-33], [6], [4], [-34], [-63], [-62], [12], [-51], [-46], [-5], [-24], [-60], [30], [-58], [58], [6], [16], [33], [-1], [60], [-72], [-62], [-12], [-58], [43], [-5], [-30], [28], [-72], [68], [9], [39], [42], [-36], [-20], [49], [-34], [21], [-21], [-20], [-21], [40], [18], [-58], [-24], [36], [-28], [-57], [6], [-16], [-44], [42], [56], [-17], [69], [-49], [11], [-54], [-62], [-66], [-54], [76], [-72], [-58], [-56], [-37], [-59], [-58], [43], [-30], [-19], [47], [-39], [18], [49], [-27], [53], [-32], [57], [29], [69], [64], [30], [-75], [63], [-3], [-30], [8], [-24], [55], [-21], [24], [-17], [50], [-45], [7], [15], [40], [2], [-45], [-4], [-72], [-70], [27], [30], [51], [-59], [24], [29], [6], [30], [26], [6], [-44], [50], [54], [-2], [15], [2], [-20], [-8], [30], [48], [35], [-66], [1], [-12], [-20], [48], [38], [-42], [-22], [-20], [-55], [78], [-51], [-35], [-30], [42], [65], [10], [30], [30], [40], [2], [57], [1], [-40], [39], [-24], [69], [-24], [-90], [-10], [-48], [-36], [-69], [70], [-10], [78], [-56], [-70], [30], [-20], [15], [-42], [40], [2], [-60], [36], [56], [-15], [26], [78], [-24], [16], [18], [40], [39], [-26], [-58], [52], [-21], [-46], [-15], [75], [73], [-24], [-94], [-38], [-84], [40], [30], [-58], [45], [58], [78], [-33], [-56], [44], [15], [58], [36], [26], [21], [12], [-44], [-76], [30], [-63], [-44], [-60], [78], [-54], [38], [54], [-33], [-79], [54], [-36], [15], [-2], [-45]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7504_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7504_2_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_7504_2_a_k(:prec:=1)
    chi := MakeCharacter_7504_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    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_7504_2_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_7504_2_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7504_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 1]>,<5,R![-3, 1]>,<11,R![-6, 1]>,<13,R![-5, 1]>],Snew);
    return Vf;
end function;