
// Make newform 6625.2.a.c in Magma, downloaded from the LMFDB on 04 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6625_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_6625_2_a_c();".
// 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_6625_2_a_c();".
// 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_6625_a();"
function MakeCharacter_6625_a()
    N := 6625;
    order := 1;
    char_gens := [4877, 1751];
    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_6625_a_Hecke(Kf)
    return MakeCharacter_6625_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], [-2, 0], [0, 0], [-3, 0], [0, 0], [-3, -1], [-1, -4], [-5, 2], [-4, -1], [-4, -4], [3, -2], [-7, 6], [2, 5], [-1, -2], [-10, 2], [-1, 0], [7, -5], [8, 3], [-2, -3], [-5, -1], [-14, 2], [-9, 4], [-5, 8], [0, -1], [-10, 9], [-1, 1], [-1, 1], [-4, 8], [-17, 2], [-13, -1], [3, -15], [-9, -3], [-3, 1], [12, -12], [-6, 10], [9, 0], [-1, 10], [12, -6], [-8, 10], [-18, -1], [-15, 16], [-14, -4], [9, -10], [1, 9], [17, 4], [4, -1], [11, -12], [-15, 8], [-5, 8], [7, 3], [1, 2], [-14, 26], [-2, -15], [6, 4], [-20, 1], [6, -9], [0, -15], [1, -6], [-5, 12], [8, 2], [-3, -10], [-18, -6], [7, -3], [8, -4], [9, -18], [-7, -10], [12, 3], [5, -12], [-10, 23], [-3, -12], [6, -15], [17, 2], [30, -7], [14, -3], [-33, 4], [-21, 0], [-18, 5], [11, -18], [-3, -7], [2, -21], [28, -13], [2, 0], [11, 4], [-14, 21], [15, -6], [-30, 12], [1, 5], [3, 11], [-1, 13], [24, 9], [-19, -14], [-17, -16], [14, -30], [-17, 20], [6, 0], [-3, 12], [24, -18], [-23, 22], [-8, 15], [-11, 6], [-13, -9], [27, -25], [-5, -17], [18, -9], [-9, 11], [-12, -10], [21, -20], [24, -21], [2, -19], [18, -6], [-15, -9], [17, 18], [11, -20], [-33, 17], [-42, 8], [23, -10], [11, -32], [10, -17], [-8, -8], [20, -35], [-4, 3], [-11, 0], [-14, 10], [5, 16], [-29, 18], [-17, 7], [-8, -3], [-2, -5], [23, -3], [-5, -4], [5, -35], [11, -20], [-1, 33], [-9, 18], [-33, -3], [-22, 6], [9, -25], [-39, 17], [13, 13], [-17, -2], [-27, 34], [-15, 25], [28, -24], [-2, -17], [12, -15], [21, 4], [-8, 9], [-35, 11], [-21, 24], [22, -5], [-3, 26], [-36, 1], [36, 0], [-7, 38], [-7, 6], [-14, 28], [17, 4], [13, -2], [-54, 2], [-15, 0], [44, -2], [-14, -8], [-6, 6], [-45, 8], [-17, -19], [18, -45], [24, -24], [3, -36], [11, -45], [-24, 35], [-18, 15], [-24, -18], [10, 7], [-3, -22], [-12, 24], [-14, 43], [4, -13], [-13, -14], [-34, 28], [15, 8], [29, -12], [27, -49], [25, -6], [18, 24], [6, 7], [21, 4], [0, -12], [0, 27], [27, -17], [33, 6], [-35, -1], [-3, 16], [-34, -6], [-33, 48], [40, -11], [-18, -19], [-9, 3], [-16, 22], [-13, 7], [15, 30], [11, -28], [-42, -3], [-15, -30], [26, -12], [26, 17], [18, 0], [-16, 22], [-23, 52], [27, -46], [-23, 47], [-31, -18], [-34, -7], [34, -6], [26, -59], [39, -9], [49, 0], [-25, 57], [41, 10], [36, 17], [-27, -7], [9, -12], [-30, 6], [-32, 1], [-15, 48], [-30, 1], [-53, 26], [-30, 48], [-12, 3], [20, -5], [-42, 32], [-1, 28], [-3, -33], [11, -47], [-37, -2], [-15, 42], [-8, -8], [11, 3], [24, -30], [24, 3], [42, -24], [14, 4], [-12, 2], [1, -15], [-33, 16], [12, -12], [-20, 49], [-42, -20], [-37, -16], [-15, -33], [-54, -14], [-30, 15], [35, -50], [12, 2], [26, 0], [-19, 2], [-27, 30], [-5, -10], [27, 21], [5, 14], [0, 0], [-27, 56], [42, -3], [-10, -18], [40, -33], [-37, 50], [-62, 24], [-22, -29], [2, -10], [-29, 14], [56, -16], [3, 26], [5, 3], [37, -42], [-7, 0], [11, 4], [-8, 20], [-7, -10], [64, -6], [9, 21], [26, -67], [-7, 34], [39, -20], [-24, -34], [-56, -4], [-22, 28], [-19, 40], [12, -4], [1, 29], [5, -12], [-24, 24], [8, -52], [-1, 13], [42, -30], [5, 44], [-9, -21], [18, 3], [35, -42], [-39, 47], [-15, 19], [56, -29], [-59, 12], [-30, -33], [15, -12], [-25, 4], [-50, 9], [56, 9], [-25, 29], [-27, -4], [28, -62], [60, -7], [31, -50], [48, -13], [-27, 34], [-12, 46], [36, -45], [6, 3], [41, -7], [-10, -35], [17, -21], [-6, -38], [25, -33], [17, -3], [-21, 35], [27, 0], [42, -2], [-79, 12], [-60, 45], [33, 8], [69, -11], [-12, 49], [29, 12], [-11, 31], [3, 21], [27, 8], [46, -21], [46, -8], [33, -42], [39, 6], [-55, 37], [9, -48], [21, -23], [65, -2], [-21, -25], [53, 7], [-40, 11], [31, 28], [-42, 65], [21, -48], [23, 17], [18, -57], [38, -48], [37, 0], [-26, 11], [63, -30], [63, -29], [22, 19], [-13, 8], [49, -52], [-62, 44], [-42, 55], [43, -19], [-25, -31], [-8, 40], [38, -19], [35, -29], [72, -29], [-29, -5], [-21, 20], [-80, 23], [-58, 62], [-4, 21], [24, -4], [17, -16], [-62, 30], [-60, 63], [-15, -24], [23, 40], [22, -16], [-1, -25], [-69, 30], [1, 43], [-72, 6], [-45, -18], [-18, -47], [-55, 28], [18, 21], [63, -29], [24, -24], [-11, 12], [-25, 59], [-46, 46], [-47, 16], [-38, 44], [-44, -19], [-24, -33], [20, 13], [-2, 47], [33, -28], [-7, 24], [33, -14], [-25, 18], [53, 11], [-1, -18], [-31, 56], [54, -18], [-14, 53], [-39, 45], [-18, 20], [-84, -3], [10, 58], [65, -9], [-20, 37], [0, -18], [-19, 0], [-5, 12], [57, 5], [25, 2], [24, -17], [-9, -42], [48, 9], [-25, 22], [23, 0], [-91, 4], [-31, 20], [-76, 28], [24, 1], [13, -4], [76, -44], [30, -69], [43, -14]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6625_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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