
// Make newform 2100.2.a.o in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2100_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_2100_2_a_o();".
// 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_2100_2_a_o();".
// 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_2100_a();"
function MakeCharacter_2100_a()
    N := 2100;
    order := 1;
    char_gens := [1051, 701, 1177, 1501];
    v := [1, 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_2100_a_Hecke(Kf)
    return MakeCharacter_2100_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], [0], [1], [-3], [-4], [-6], [-4], [3], [3], [-10], [-7], [0], [-1], [-12], [6], [12], [-4], [-7], [9], [2], [17], [-6], [0], [2], [6], [-4], [12], [-7], [-15], [-7], [-6], [-18], [14], [9], [-13], [-4], [-4], [-24], [24], [12], [14], [12], [-25], [-3], [-16], [-4], [2], [0], [-10], [-9], [24], [-16], [6], [-6], [-3], [-30], [-16], [2], [15], [26], [0], [26], [-6], [20], [-3], [17], [26], [9], [-28], [18], [33], [-4], [-37], [-31], [12], [-33], [-22], [27], [8], [30], [-1], [0], [-16], [-4], [12], [-39], [35], [0], [-4], [18], [12], [11], [33], [20], [-6], [-36], [-18], [8], [-25], [-19], [-27], [42], [15], [41], [8], [18], [-12], [-9], [44], [-40], [29], [27], [-40], [5], [-45], [-4], [-42], [-6], [12], [32], [-46], [-6], [-15], [-28], [-30], [38], [0], [14], [-4], [-25], [0], [-40], [17], [12], [32], [-42], [2], [-30], [45], [-22], [42], [5], [-3], [-34], [54], [-4], [-12], [14], [-51], [14], [-54], [41], [12], [8], [27], [-19], [-42], [-52], [-42], [60], [57], [-40], [-24], [-45], [-42], [-19], [-28], [-1], [30], [-33], [20], [-57], [-46], [14], [-6], [-7], [-42], [20], [26], [-61], [-60], [-7], [30], [-33], [-6], [-1], [-34], [53], [6], [14], [-33], [47], [18], [45], [-12], [41], [17], [-60], [6], [30], [26], [-22], [-28], [0], [-60], [-22], [-12], [9], [8], [-67], [-30], [23], [36], [6], [-10], [23], [-60], [3], [-9], [17], [-34], [-3], [29], [-36], [-10], [18], [63], [2], [-51], [5], [-34], [32], [-51], [44], [30], [68], [9], [-63], [-60], [15], [44], [-34], [35], [24], [-54], [-22], [42], [8], [-48], [50], [24], [-48], [50], [-24], [-60], [-19], [26], [-60], [20], [-16], [9], [50], [38], [30], [-64], [57], [18], [-49], [-9], [68], [-52], [8], [-7], [26], [-82], [57], [-34], [-49], [42], [66], [-40], [-12], [50], [74], [57], [47], [33], [44], [-66], [-27], [66], [51], [-42], [59], [30], [-52], [36], [-36], [26], [50], [78], [-79], [9], [-67], [-70], [-45], [-16], [-9], [2], [6], [-30], [15], [44], [27], [-34], [6], [60], [20], [-21], [26], [-22], [-36], [41], [-63], [38], [-55], [86], [3], [-21], [-22], [-45], [2], [18], [8], [-72], [-55], [0], [-4], [-34], [-70], [27], [72], [53], [87], [-15], [-46], [-73], [-48], [-42], [14], [47], [78], [-4], [11], [48], [6], [-42], [-30], [72], [83], [-90], [-36], [-39], [-52], [-10], [-54], [-61], [-61], [57], [-34], [15], [-42], [50], [-49], [60], [33], [38], [84], [86], [78], [33], [-43], [21], [-22], [-24], [95], [-22], [47], [-72], [-43], [-6], [57], [2], [9], [29], [32], [0], [68], [-33], [32], [-39], [17], [84], [84], [-52], [-61], [-78], [-88], [54], [-88], [-57], [96], [-31], [-67], [60], [24], [38], [-60], [42], [66], [-70], [-72], [-24], [74], [54], [-27], [-66], [-46], [-6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2100_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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