
// Make newform 7200.2.a.bj in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7200_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_7200_2_a_bj();".
// 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_7200_2_a_bj();".
// 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_7200_a();"
function MakeCharacter_7200_a()
    N := 7200;
    order := 1;
    char_gens := [6751, 901, 6401, 577];
    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_7200_a_Hecke(Kf)
    return MakeCharacter_7200_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], [0], [0], [1], [0], [1], [0], [3], [-4], [-4], [-7], [-6], [-6], [9], [-6], [-2], [-10], [-1], [-3], [14], [10], [8], [-18], [0], [-3], [6], [8], [-2], [-15], [12], [16], [-6], [-10], [12], [-14], [-17], [-9], [19], [-6], [4], [-6], [-11], [16], [11], [-18], [-13], [7], [-11], [14], [-23], [18], [-6], [-11], [-16], [16], [2], [-16], [-4], [-11], [-4], [-5], [-30], [-13], [10], [23], [-12], [32], [-19], [2], [-30], [36], [30], [3], [15], [13], [32], [-10], [-13], [-30], [5], [26], [6], [-36], [15], [-23], [20], [0], [-22], [18], [-20], [24], [-18], [-29], [-8], [-41], [18], [-34], [-20], [-37], [5], [-16], [6], [8], [20], [-5], [31], [-18], [22], [32], [-21], [0], [-10], [2], [19], [17], [24], [-12], [28], [-10], [30], [-10], [22], [-48], [24], [-28], [48], [-3], [-36], [-7], [-26], [-20], [-28], [48], [-47], [-44], [-1], [-18], [7], [48], [38], [7], [42], [41], [-34], [14], [8], [-37], [-32], [4], [4], [43], [12], [29], [38], [20], [-42], [-1], [8], [19], [-30], [-20], [8], [-8], [54], [42], [-28], [-31], [18], [5], [-30], [-60], [23], [-38], [-31], [59], [20], [-25], [-12], [41], [35], [41], [48], [-11], [6], [-46], [18], [-3], [11], [57], [24], [9], [-10], [-35], [60], [-12], [-46], [-2], [14], [18], [-56], [10], [56], [-2], [50], [4], [12], [51], [-40], [64], [-67], [55], [-66], [21], [-12], [-46], [14], [-39], [60], [-42], [-56], [45], [-41], [-42], [68], [-22], [23], [24], [-2], [-41], [-36], [5], [-8], [-41], [-46], [24], [48], [34], [6], [18], [-26], [24], [29], [11], [39], [-54], [38], [51], [52], [65], [6], [66], [48], [8], [21], [68], [-4], [-43], [-32], [-54], [14], [-51], [20], [26], [-61], [62], [-20], [34], [28], [-20], [-38], [35], [-12], [-74], [-59], [29], [-55], [-42], [-5], [35], [-20], [66], [32], [-12], [-21], [-41], [-30], [25], [34], [16], [18], [50], [48], [-32], [-68], [31], [-78], [-55], [66], [-52], [28], [-50], [68], [-75], [38], [68], [45], [48], [-31], [42], [-14], [44], [40], [60], [9], [8], [-7], [68], [52], [41], [-40], [76], [-73], [-2], [-35], [-46], [90], [11], [19], [-84], [-14], [-3], [74], [-43], [68], [31], [60], [55], [-14], [-63], [-88], [-17], [-50], [12], [55], [24], [10], [-23], [63], [-50], [-24], [7], [38], [-92], [-25], [51], [-66], [90], [-32], [44], [36], [-73], [70], [72], [60], [-80], [23], [64], [-16], [55], [-84], [29], [-64], [48], [-32], [-83], [-70], [90], [-49], [-44], [-7], [54], [-64], [48], [-38], [-44], [54], [-19], [58], [40], [-40], [-31], [2], [10], [-47], [-30], [29], [-11], [-66], [45], [-96], [-86], [-14], [47], [22], [-38], [-40], [69], [82], [23], [-96], [-17], [-84], [-14], [27], [-95], [-36], [66], [-57], [-2], [14], [4], [-57], [38], [14], [22], [58], [-70], [14], [-71], [-36]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7200_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7200_2_a_bj();".
// 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_7200_2_a_bj(:prec:=1)
    chi := MakeCharacter_7200_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_7200_2_a_bj();".
// 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_7200_2_a_bj( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-1, 1]>,<11,R![0, 1]>,<13,R![-1, 1]>,<17,R![0, 1]>,<19,R![-3, 1]>,<23,R![4, 1]>],Snew);
    return Vf;
end function;