
// Make newform 2700.2.a.i in Magma, downloaded from the LMFDB on 29 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2700_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_2700_2_a_i();".
// 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_2700_2_a_i();".
// 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_2700_a();"
function MakeCharacter_2700_a()
    N := 2700;
    order := 1;
    char_gens := [1351, 1001, 2377];
    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_2700_a_Hecke(Kf)
    return MakeCharacter_2700_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], [-2], [3], [1], [-6], [2], [3], [6], [-4], [7], [0], [-2], [-3], [6], [15], [5], [-2], [9], [-2], [-10], [12], [18], [-17], [-6], [4], [3], [14], [12], [16], [15], [-18], [14], [0], [14], [10], [16], [-15], [6], [15], [-25], [24], [-2], [-12], [-4], [8], [-26], [9], [-13], [18], [3], [17], [3], [-6], [-21], [-24], [-16], [-26], [-6], [-14], [18], [28], [-3], [10], [6], [8], [22], [36], [-10], [18], [3], [-32], [22], [20], [-15], [-30], [7], [-18], [5], [-12], [35], [27], [-23], [-22], [-15], [-24], [-17], [-36], [-14], [9], [-12], [22], [12], [-16], [-24], [-36], [-18], [28], [-13], [-8], [18], [-21], [-24], [-28], [37], [0], [24], [-36], [-25], [4], [-29], [-36], [-4], [38], [18], [4], [21], [-42], [-12], [5], [1], [48], [3], [8], [-42], [-1], [-9], [-32], [13], [-34], [27], [-4], [-35], [-12], [-10], [-6], [-20], [6], [54], [2], [-24], [-26], [33], [11], [-9], [31], [-12], [-22], [-24], [19], [0], [-2], [3], [46], [-9], [-10], [24], [-23], [-30], [-12], [12], [40], [51], [36], [57], [8], [55], [-19], [-24], [24], [38], [3], [7], [26], [42], [-28], [60], [58], [-7], [-26], [-3], [25], [-42], [-24], [-30], [-26], [28], [-31], [3], [-65], [-33], [50], [18], [-63], [60], [59], [1], [-60], [24], [-12], [26], [13], [53], [9], [30], [-52], [51], [54], [14], [-38], [12], [-32], [27], [57], [-10], [10], [42], [-51], [0], [-49], [-34], [48], [-2], [-27], [29], [18], [45], [64], [60], [37], [-34], [-46], [60], [64], [-33], [5], [36], [0], [-57], [-12], [26], [-56], [-19], [42], [-27], [-2], [-51], [-40], [69], [-23], [48], [33], [-31], [-24], [33], [26], [10], [30], [-47], [28], [-72], [-58], [-41], [-60], [62], [-30], [-18], [22], [18], [17], [-20], [55], [74], [31], [-62], [-60], [62], [11], [-15], [-51], [-76], [-39], [5], [-38], [51], [67], [78], [-10], [-24], [36], [-24], [-66], [-57], [58], [6], [-28], [-36], [0], [82], [49], [60], [-58], [63], [68], [-41], [45], [-70], [-45], [-74], [-48], [-6], [30], [-86], [-72], [-31], [-60], [57], [-26], [30], [-28], [1], [-36], [52], [-90], [-43], [-28], [40], [75], [-84], [-49], [54], [-64], [81], [80], [-36], [-10], [-36], [-19], [-20], [19], [72], [-54], [-16], [-48], [-48], [-46], [52], [-33], [48], [62], [-29], [-60], [-50], [74], [66], [-15], [-48], [24], [-45], [-17], [36], [81], [21], [-2], [34], [54], [34], [-49], [-12], [32], [-21], [-84], [14], [-2], [-60], [-15], [-14], [42], [22], [30], [6], [-56], [30], [14], [-24], [50], [-23], [70], [-72], [-82], [-6], [-12], [-8], [-36], [-2], [-16], [-18], [-64], [42], [-103], [-48], [4], [84], [6], [38], [-71], [-66], [16], [-45], [-35], [-12], [-39], [-58], [46], [66], [-24], [-80], [-42], [24], [-30], [22], [-27], [-12], [34], [0], [-36], [48], [-46], [-75]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2700_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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