
// Make newform 2752.2.a.f in Magma, downloaded from the LMFDB on 07 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2752_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_2752_2_a_f();".
// 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_2752_2_a_f();".
// 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_2752_a();"
function MakeCharacter_2752_a()
    N := 2752;
    order := 1;
    char_gens := [2495, 517, 2497];
    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_2752_a_Hecke(Kf)
    return MakeCharacter_2752_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 := 2;
    raw_aps := [[0], [2], [4], [0], [-3], [5], [-3], [2], [-1], [6], [-1], [0], [5], [1], [4], [5], [12], [-2], [3], [2], [2], [-8], [-15], [-4], [7], [9], [1], [12], [-7], [-20], [1], [-8], [6], [-19], [-12], [-20], [10], [-14], [-9], [-6], [-20], [-10], [-16], [3], [-2], [14], [-2], [-28], [4], [15], [6], [16], [-12], [23], [-24], [-18], [25], [23], [32], [19], [-21], [26], [7], [15], [22], [-9], [26], [-3], [-28], [-14], [-31], [19], [-32], [-32], [-11], [32], [-6], [6], [5], [-24], [28], [10], [-21], [-12], [17], [4], [30], [-18], [-30], [4], [-6], [21], [36], [6], [8], [6], [15], [14], [-12], [-1], [29], [3], [-37], [7], [14], [-20], [-2], [-16], [-1], [-4], [-4], [18], [-21], [-36], [-6], [12], [36], [-12], [14], [19], [-31], [14], [-34], [9], [40], [2], [1], [8], [16], [-32], [10], [-24], [-6], [-28], [20], [-42], [4], [-4], [42], [26], [14], [-49], [-1], [36], [-44], [-40], [29], [-10], [32], [-6], [-41], [37], [-31], [-22], [-47], [-22], [-49], [-6], [32], [-33], [33], [22], [37], [13], [34], [-24], [2], [-4], [-18], [22], [30], [14], [46], [13], [34], [6], [60], [40], [12], [-32], [20], [-40], [46], [12], [54], [0], [-4], [-60], [-26], [-30], [21], [-32], [52], [40], [48], [32], [-55], [59], [-30], [-6], [-3], [-26], [20], [-50], [12], [20], [20], [37], [2], [9], [-38], [-39], [39], [27], [-18], [7], [66], [0], [-12], [45], [-52], [32], [42], [29], [12], [-1], [-35], [-42], [22], [50], [10], [23], [-1], [52], [-19], [24], [40], [-21], [-26], [41], [-60], [0], [-56], [-14], [12], [-44], [32], [-33], [19], [9], [74], [13], [37], [14], [80], [36], [-36], [-47], [56], [1], [-26], [-24], [14], [26], [-18], [-50], [50], [-45], [-58], [-45], [59], [52], [4], [28], [-62], [34], [65], [-78], [73], [26], [-35], [-8], [29], [16], [-14], [72], [-55], [-16], [54], [-45], [-3], [53], [-54], [50], [-31], [-33], [-17], [81], [-44], [-56], [45], [-22], [63], [53], [24], [22], [19], [-32], [-20], [4], [-6], [0], [-61], [-26], [1], [-91], [-20], [-40], [-81], [-6], [-3], [52], [78], [64], [12], [-43], [-4], [7], [16], [-92], [64], [37], [42], [6], [-68], [-93], [-56], [-14], [0], [-38], [-75], [-22], [36], [58], [-57], [81], [72], [20], [-24], [11], [-4], [46], [-34], [-56], [-10], [-4], [8], [12], [27], [49], [-46], [32], [36], [-6], [93], [36], [-28], [8], [-20], [-90], [-96], [0], [36], [45], [32], [18], [-24], [-67], [18], [52], [-59], [17], [-49], [-8], [-73], [49], [24], [59], [32], [-47], [89], [36], [-56], [-47], [-38], [2], [-19], [54], [68], [62], [-77], [6], [-39], [82], [18], [14], [90], [62], [36], [25], [46], [-94], [2], [-73], [92], [87], [-45], [-52], [42], [-66], [58], [-34], [62], [51], [-30], [84], [-86], [-2], [-45], [20]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2752_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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