
// Make newform 3025.2.a.h in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3025_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_3025_2_a_h();".
// 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_3025_2_a_h();".
// 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 := [-3, -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_3025_a();"
function MakeCharacter_3025_a()
    N := 3025;
    order := 1;
    char_gens := [727, 2301];
    v := [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_3025_a_Hecke(Kf)
    return MakeCharacter_3025_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, -1], [1, -1], [0, 0], [-2, -1], [0, 0], [-5, 0], [-3, 3], [1, 0], [-6, 1], [3, 3], [5, -4], [5, 2], [3, -2], [-2, 4], [-3, 0], [0, 1], [-9, 4], [4, -3], [-4, 0], [0, 2], [4, -3], [7, -3], [-3, -5], [3, 1], [14, -1], [-6, -5], [-1, -3], [3, 0], [-5, 5], [-3, 6], [1, 7], [6, -3], [-9, 3], [1, -4], [-12, 4], [7, 6], [14, -4], [8, -1], [-3, 8], [-3, -6], [6, -5], [-16, 3], [9, -1], [-8, 4], [-12, 1], [-13, -5], [7, -14], [-7, 12], [-3, -1], [-7, 9], [-12, 3], [-12, 7], [-5, 13], [3, -3], [-18, 0], [15, -6], [-3, -9], [-5, -4], [-17, -2], [9, 6], [-5, 1], [-6, -4], [13, -3], [-3, -6], [8, 6], [3, 3], [-19, 2], [10, -16], [6, -5], [13, 6], [3, -12], [-6, -4], [-22, -1], [-17, 8], [11, 6], [6, -12], [12, 0], [23, 1], [-18, -4], [1, -4], [9, 2], [2, 1], [-33, 0], [5, 0], [-23, 1], [-6, 2], [30, 5], [22, 1], [-27, 4], [17, 4], [-3, 12], [27, -6], [-1, -4], [15, 4], [-10, -5], [-12, -2], [-24, -1], [-18, 18], [22, -8], [-14, 9], [-2, -7], [-9, 8], [-12, -3], [24, -17], [-8, 11], [17, -21], [-3, -15], [9, 2], [-21, 3], [-2, -3], [-2, 4], [25, 7], [6, 2], [-1, 8], [-10, -13], [33, 4], [-22, 0], [-15, 14], [-3, -7], [27, -3], [-1, 6], [-17, 10], [-6, 14], [27, -16], [8, -15], [36, -4], [-16, 12], [15, 6], [-25, 11], [-17, 2], [-26, 7], [-42, -1], [-31, 11], [23, -20], [24, 8], [13, 6], [-6, -7], [-5, 4], [-3, -5], [-24, 12], [-5, 26], [-12, 0], [8, -8], [-6, 6], [5, -19], [0, 7], [1, -9], [3, 0], [44, 2], [-15, -2], [-20, 0], [0, -15], [29, -18], [-15, -14], [-4, 0], [-30, -4], [-32, -4], [51, -2], [4, -4], [-57, 2], [-9, -12], [-6, 24], [-11, 3], [18, -21], [-39, 10], [-12, -16], [-13, 3], [-35, 9], [31, -12], [-6, -6], [6, 17], [8, 21], [15, -19], [16, -9], [-31, -6], [-18, 4], [16, -4], [-21, 0], [-20, -6], [-20, 24], [2, -14], [0, 5], [17, 14], [42, 0], [-33, -12], [33, 8], [4, 2], [2, 7], [13, -26], [12, -4], [5, 13], [-24, 0], [5, 8], [15, -15], [6, 23], [39, 10], [-14, 18], [-25, -18], [-6, -13], [-15, -1], [-6, 25], [22, -9], [47, 3], [37, 1], [18, -12], [-12, 31], [-28, 0], [-45, 2], [-6, -24], [2, 23], [-5, 8], [-15, 2], [-16, -11], [-6, 26], [27, -24], [20, -2], [40, 4], [9, -1], [-18, 3], [6, -33], [1, -19], [37, 10], [-12, 8], [-37, -1], [-45, 4], [19, -12], [-6, -5], [-18, 30], [-44, -12], [-45, -9], [-10, 15], [-11, -6], [37, -6], [-57, 0], [-7, -3], [-27, -18], [8, -10], [36, 3], [3, -31], [-12, 21], [-3, 34], [-8, 10], [20, 18], [-13, 4], [-60, 6], [-36, 3], [-40, 15], [18, 9], [-29, 9], [-6, 6], [22, -6], [27, 2], [60, -6], [23, -16], [6, -21], [-36, 6], [-25, 2], [25, -10], [-24, -5], [-2, -12], [52, 12], [-36, 6], [-5, 22], [-59, 13], [-21, -14], [-40, 2], [21, -12], [-42, 13], [61, -8], [27, -36], [26, -30], [5, 2], [-46, -6], [25, -8], [-59, -9], [17, -16], [0, 8], [-47, 1], [-50, -13], [9, 22], [-3, -15], [20, 8], [-18, 17], [-5, 4], [-68, 3], [24, 12], [-31, 13], [-12, 25], [74, -3], [-9, 21], [-51, 12], [15, 20], [-12, -12], [-9, 15], [7, -32], [0, -25], [65, 4], [51, 10], [-6, -8], [25, -6], [37, -14], [18, 12], [40, -15], [63, 4], [53, -11], [23, 22], [-42, 2], [26, 11], [-33, 1], [37, 12], [-15, 1], [-45, -3], [24, -35], [17, 0], [-51, 24], [4, -34], [-18, -24], [-12, 26], [38, -18], [-42, 7], [10, -5], [-40, -21], [15, -18], [-49, 22], [-21, 9], [-34, 8], [-1, -27], [44, -19], [18, -14], [6, -24], [40, -38], [57, -20], [-17, 21], [39, 12], [4, -38], [-54, 28], [-22, 34], [-36, -10], [-10, 31], [52, -3], [20, -18], [33, 4], [33, -38], [38, -23], [-15, 12], [-39, 29], [23, -35], [-7, 22], [-27, 21], [-21, 4], [4, -5], [14, 23], [-9, -6], [43, -11], [-32, 0], [39, -24], [-30, 0], [48, 17], [33, -10], [36, -8], [4, -9], [-21, 42], [-39, -2], [63, 1], [-40, 17], [11, -30], [18, -30], [13, 8], [76, -16], [3, -31], [-28, 0], [-18, -7], [-27, 23], [1, 5], [-13, 28], [-54, -9], [-90, 5], [34, 24], [-60, -15], [-50, 9], [18, 22], [57, -6], [-20, -2], [-15, 27], [-29, 30], [15, -35], [-16, 11], [44, -20], [91, -2], [54, -28], [2, -5], [24, -24], [-15, 0], [-34, 10], [-3, 6], [37, 18], [-5, 5], [24, -38], [-1, 16], [-24, 3], [-20, -32], [-24, 45], [10, -35], [-9, -12], [-9, 18], [61, -18], [-16, -10], [33, 12], [20, 32], [-42, 26], [49, -21], [27, -24], [-51, -10], [-32, 37], [-26, 0], [-33, -14], [-57, 6], [23, 9], [21, -18], [-45, -19], [15, -46], [43, 18], [15, -38], [-9, 18], [56, -18], [0, 28], [18, -48], [75, 9], [50, -20], [-21, -3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3025_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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