
// Make newform 6028.2.a.a in Magma, downloaded from the LMFDB on 07 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6028_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_6028_2_a_a();".
// 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_6028_2_a_a();".
// 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
        poly := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_6028_a();"
function MakeCharacter_6028_a()
    N := 6028;
    order := 1;
    char_gens := [3015, 2741, 3565];
    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_6028_a_Hecke(Kf)
    return MakeCharacter_6028_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], [-3, 1], [-3, -1], [1, 0], [-3, 2], [-5, 2], [-2, 1], [-4, 3], [-4, -2], [-3, -4], [-1, -3], [-3, 0], [-7, 6], [1, -8], [-5, -2], [2, -5], [-13, 2], [1, -7], [-5, -3], [11, -8], [-11, 6], [1, 9], [4, -5], [1, 8], [-11, -3], [-5, -8], [-1, 9], [1, -2], [2, -8], [-11, -4], [6, 6], [1, 0], [5, 6], [5, -7], [-6, 7], [3, 3], [-8, 12], [-8, 5], [-4, -7], [-2, 8], [-11, 10], [3, 6], [2, 6], [6, -2], [9, -2], [2, 5], [3, 16], [16, -21], [6, -8], [-16, -1], [-1, 0], [-14, -2], [-3, -11], [-1, -1], [-4, 5], [1, -8], [-4, 1], [13, -14], [-7, -2], [-13, 4], [5, -6], [4, -1], [-22, 12], [12, -15], [18, 0], [-9, 13], [-8, -2], [5, 6], [-7, 23], [9, -18], [-12, 8], [4, -6], [11, 0], [-21, 6], [25, -6], [-14, 30], [3, 17], [-26, 17], [-6, -7], [0, -10], [3, -19], [-2, -14], [14, 8], [-18, -2], [18, -5], [-6, 10], [-20, -10], [-28, -6], [-24, 26], [-31, 5], [29, -3], [16, 6], [-17, -13], [2, -12], [6, 9], [-31, 21], [-25, 20], [-3, 1], [-41, 2], [18, -15], [-35, 14], [-1, -22], [27, -5], [-22, -6], [-10, -7], [-9, 18], [9, 15], [9, 12], [-28, 18], [-21, 39], [-6, -10], [20, 4], [33, -16], [-25, 2], [21, -20], [32, -6], [15, 12], [-11, 4], [20, 5], [-4, 29], [-1, 4], [36, -4], [-16, -10], [-2, 15], [-31, 16], [7, -9], [-27, 11], [-4, -9], [24, -23], [-35, 9], [38, -24], [3, 20], [-22, -15], [5, 10], [17, -6], [-7, 19], [-13, 12], [-22, 28], [24, -39], [-35, 19], [-27, -18], [10, 11], [-4, 17], [-27, 32], [15, -28], [-1, -28], [-7, 18], [-18, -9], [-10, 26], [-42, 10], [16, 9], [-11, -14], [11, 21], [24, -23], [32, -28], [12, -16], [38, -33], [14, -4], [37, -9], [-28, 12], [4, -30], [-30, 16], [-9, -8], [15, 0], [-19, -10], [-41, 22], [-5, -26], [11, 15], [-16, 44], [27, -25], [-10, -21], [12, -30], [-38, 29], [-17, 12], [-15, -16], [-49, 0], [-10, -4], [3, -33], [-1, 21], [26, -36], [-13, 14], [-18, 19], [-13, -19], [-24, 27], [-16, 6], [-37, 21], [17, -39], [21, -5], [46, -33], [-17, 22], [39, -23], [8, -10], [-18, -30], [6, 9], [39, -16], [23, -25], [-11, -10], [10, 31], [22, -25], [-12, 7], [12, -3], [-18, -18], [-9, -22], [-18, 24], [8, 23], [30, -61], [-29, 50], [11, -16], [-16, 38], [-27, 43], [-7, -28], [-1, -6], [-35, 4], [3, -39], [13, -35], [-47, 28], [43, 8], [22, -3], [-61, 12], [-31, -20], [-2, 30], [31, -40], [-1, -28], [39, -52], [41, -21], [48, -6], [-29, 0], [-34, 49], [31, 14], [-5, 32], [-51, -15], [24, 14], [-44, -3], [51, -6], [6, 17], [15, -34], [-55, 31], [17, 24], [48, -7], [-29, -15], [14, -33], [-27, 40], [-13, 8], [-11, 39], [6, 42], [10, -35], [22, 11], [-17, -27], [21, -4], [-36, 1], [-41, -3], [-23, 2], [-19, -21], [2, -44], [-14, 26], [-45, 14], [-1, -40], [4, 38], [6, -27], [-4, 35], [0, 25], [-44, 33], [-32, -10], [36, 9], [33, -40], [-76, 1], [15, -13], [-10, -45], [38, -8], [31, 29], [40, -8], [-24, -23], [29, -2], [22, 28], [19, -56], [34, -5], [-23, -19], [-43, 12], [-8, -31], [13, -26], [-12, 30], [-29, 28], [34, 25], [22, 10], [-28, -2], [34, 25], [-49, 16], [-35, 8], [4, 5], [49, -51], [-40, 44], [18, -18], [0, -10], [-70, 28], [-3, 15], [70, -24], [53, 10], [6, -25], [-71, 0], [8, 3], [-9, 42], [-14, -6], [-21, -17], [27, 11], [54, 1], [41, -18], [-11, 16], [32, -10], [-53, 29], [20, -33], [2, -2], [8, -38], [0, -38], [-8, 23], [-65, 33], [23, 2], [-3, -38], [-12, 31], [-21, 38], [-72, -4], [-55, -17], [-51, 42], [31, 14], [43, 18], [-57, 49], [27, -19], [-35, 17], [-30, 18], [-27, -15], [13, -46], [-6, 44], [5, -14], [23, -47], [-19, 26], [-24, -25], [6, -29], [-33, -5], [44, 20], [61, 4], [11, -3], [39, -46], [-16, 1], [49, -8], [-38, 40], [-43, 52], [6, 49], [51, -15], [-34, 25], [17, 5], [2, -7], [48, 0], [35, -45], [34, -5], [49, -28], [68, -38], [10, -61], [-38, 33], [-40, -21], [29, 18], [-19, -7], [43, 15], [-25, -16], [17, 48], [-67, -16], [23, -29], [-9, -41], [24, -61], [48, -68], [-26, 22], [37, -9], [5, 26], [-31, 75], [-9, -37], [28, -46], [-9, -5], [37, -1], [-6, 28], [46, -20], [43, -46], [61, -6], [-51, -4], [-23, -12], [64, 2], [-48, 20], [11, -42], [-16, 8], [45, -54], [-19, 0], [82, -9], [40, -25], [3, 47], [50, -27], [-48, 38], [53, -3], [1, -41], [-82, -6], [46, -61], [71, -13], [-38, -8], [46, 16], [33, -68], [-82, 23], [42, 19], [47, -7], [11, -18], [63, 2], [-73, 10], [-19, 59], [-4, 10], [26, 4], [12, 24], [25, -72], [-79, -3], [-6, 25], [-19, 52], [68, -33], [-34, 45], [-6, 0], [-7, 42], [55, -63], [72, -2], [19, -34], [40, -54], [-74, 23], [5, -49], [-3, 18], [-32, 6], [5, -47], [62, 5]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6028_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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