
// Make newform 6615.2.a.h in Magma, downloaded from the LMFDB on 18 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6615_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_6615_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_6615_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_6615_a();"
function MakeCharacter_6615_a()
    N := 6615;
    order := 1;
    char_gens := [3431, 2647, 1081];
    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_6615_a_Hecke(Kf)
    return MakeCharacter_6615_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 := [[1], [0], [1], [0], [-3], [6], [-1], [4], [-4], [-8], [-2], [-2], [-12], [4], [-4], [-11], [1], [10], [7], [15], [4], [-4], [-4], [6], [-6], [2], [-13], [12], [-6], [9], [-19], [-19], [-22], [-6], [-4], [-10], [-20], [-21], [14], [-9], [-21], [-17], [1], [0], [15], [-4], [10], [-9], [-22], [13], [-9], [8], [-18], [-9], [-15], [-8], [-10], [24], [8], [6], [5], [-13], [15], [9], [-22], [5], [-18], [10], [16], [35], [-33], [12], [37], [-4], [-4], [22], [-12], [32], [30], [5], [3], [-35], [28], [-32], [-26], [-24], [24], [18], [-32], [33], [10], [11], [-4], [24], [38], [-44], [-8], [28], [-7], [-45], [3], [17], [10], [42], [-6], [-2], [12], [30], [32], [-3], [-1], [-18], [27], [-36], [0], [-24], [40], [18], [-34], [12], [26], [-28], [22], [30], [6], [-26], [1], [-13], [16], [-4], [-34], [-12], [-28], [2], [-18], [5], [-39], [28], [-21], [30], [-18], [-18], [-40], [48], [15], [36], [6], [39], [20], [-24], [2], [36], [43], [22], [7], [27], [-6], [-26], [4], [6], [-46], [-14], [-17], [8], [11], [14], [60], [-34], [-9], [-37], [-52], [5], [-5], [46], [-18], [-40], [26], [30], [-16], [-14], [32], [25], [-12], [-14], [14], [22], [56], [-13], [26], [25], [20], [56], [-64], [20], [-18], [21], [-63], [4], [-31], [14], [60], [-44], [-56], [-17], [-25], [-70], [-30], [14], [-56], [42], [22], [46], [-8], [-38], [-3], [41], [32], [-42], [-8], [-67], [49], [20], [18], [31], [48], [-10], [-23], [31], [-16], [-21], [32], [-52], [-32], [22], [-12], [2], [33], [-13], [-9], [-72], [-52], [0], [-11], [-29], [-10], [23], [40], [9], [-12], [-22], [56], [-42], [48], [22], [-42], [-65], [-9], [19], [65], [-26], [-8], [-4], [-11], [-40], [13], [28], [36], [-10], [49], [26], [-66], [23], [16], [-70], [-72], [-35], [-14], [-13], [-47], [20], [-6], [-50], [0], [-82], [-23], [29], [48], [45], [-32], [38], [-36], [30], [59], [33], [44], [-66], [-32], [7], [39], [-25], [-40], [-18], [52], [-6], [-36], [72], [52], [-67], [-79], [0], [48], [6], [-18], [69], [2], [7], [35], [-48], [58], [54], [-46], [-38], [-42], [85], [71], [83], [66], [-44], [54], [3], [22], [2], [-2], [-42], [74], [6], [-7], [3], [-73], [52], [38], [-57], [-8], [-44], [21], [-59], [13], [-53], [49], [-54], [40], [-26], [-60], [-52], [55], [-21], [87], [21], [74], [-26], [6], [-48], [-12], [-60], [32], [-38], [33], [40], [-71], [-12], [-50], [90], [-58], [30], [74], [-33], [-36], [34], [-94], [38], [-24], [82], [-32], [75], [88], [96], [-34], [-62], [81], [-102], [-55], [-71], [-57], [13], [56], [94], [-78], [-70], [-18], [68], [62], [-27], [67], [-7], [84], [-20], [-30], [-82], [35], [-57], [-26], [35], [54], [52], [32], [-70], [49], [88], [-86], [-54], [-30], [-16], [98], [19], [-68], [39], [20], [-48], [88], [9]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6615_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6615_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_6615_2_a_h(:prec:=1)
    chi := MakeCharacter_6615_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_6615_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_6615_2_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6615_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1]>,<11,R![3, 1]>,<13,R![-6, 1]>,<17,R![1, 1]>],Snew);
    return Vf;
end function;