
// Make newform 4275.2.a.c in Magma, downloaded from the LMFDB on 29 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4275_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_4275_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_4275_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_4275_a();"
function MakeCharacter_4275_a()
    N := 4275;
    order := 1;
    char_gens := [1901, 1027, 1351];
    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_4275_a_Hecke(Kf)
    return MakeCharacter_4275_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 := [[-1], [0], [0], [-4], [-3], [0], [0], [1], [1], [5], [9], [2], [-6], [8], [-8], [-1], [12], [5], [5], [-10], [-11], [11], [-9], [-15], [-18], [12], [-1], [6], [6], [3], [-7], [11], [-4], [14], [0], [-16], [14], [-2], [-14], [-15], [-4], [4], [-25], [-18], [0], [10], [25], [19], [-22], [5], [-20], [0], [-24], [24], [17], [9], [-6], [-14], [-25], [-5], [8], [-3], [-19], [8], [29], [-27], [7], [0], [-28], [31], [-16], [8], [14], [0], [-16], [-34], [-34], [-27], [17], [-10], [-12], [-18], [-18], [-2], [-9], [39], [35], [6], [-12], [20], [-39], [-33], [16], [20], [-36], [36], [-21], [-35], [-20], [-21], [35], [12], [6], [-22], [6], [13], [43], [-4], [-40], [10], [29], [26], [-2], [44], [-4], [-22], [-2], [-49], [-24], [-24], [-40], [24], [-9], [42], [2], [0], [-35], [15], [-38], [25], [-20], [48], [-40], [17], [18], [-5], [6], [-17], [-14], [-8], [23], [42], [2], [36], [18], [-32], [34], [-50], [-22], [12], [-18], [24], [-38], [0], [16], [-18], [14], [12], [-42], [31], [-60], [21], [-22], [56], [18], [-34], [47], [-35], [-38], [34], [44], [24], [28], [27], [-7], [38], [-44], [38], [16], [-23], [58], [10], [-14], [-27], [-21], [-4], [12], [-1], [60], [5], [16], [1], [63], [-19], [-28], [-38], [-23], [-51], [62], [11], [9], [40], [28], [12], [-9], [12], [-42], [-12], [54], [-20], [-43], [30], [16], [22], [-12], [14], [-66], [-15], [54], [14], [-26], [37], [-38], [-42], [-10], [-58], [-51], [-30], [-16], [19], [-26], [-75], [-51], [17], [-10], [-48], [6], [-6], [-12], [-70], [-20], [0], [-34], [26], [-30], [-19], [-60], [-62], [-57], [27], [-7], [78], [-19], [46], [12], [51], [-42], [27], [2], [-42], [61], [68], [79], [-62], [-38], [-45], [54], [-72], [11], [-16], [-32], [57], [49], [-66], [28], [-48], [-49], [-20], [4], [-55], [44], [28], [-40], [22], [40], [-20], [31], [33], [-24], [19], [30], [75], [-58], [-70], [-64], [10], [28], [-28], [-26], [6], [-1], [-57], [-50], [-24], [50], [-20], [44], [-16], [-35], [-81], [-49], [-86], [-39], [19], [72], [-12], [-75], [-54], [-66], [50], [-48], [62], [2], [-48], [-64], [10], [-12], [-36], [-92], [-26], [-25], [19], [4], [-37], [82], [-51], [-42], [39], [49], [-76], [-28], [42], [45], [-17], [11], [18], [35], [-21], [-16], [-24], [3], [16], [-96], [67], [32], [-61], [-73], [-77], [-78], [36], [-75], [0], [62], [-30], [8], [40], [82], [-16], [-56], [55], [49], [-16], [-27], [-76], [-38], [-6], [-65], [1], [4], [6], [-78], [54], [-56], [-32], [45], [4], [28], [-30], [56], [54], [60], [67], [-75], [22], [-82], [-58], [80], [15], [-23], [40], [42], [-18], [28], [-35], [-33], [-50], [-97], [75], [9], [31], [48], [66], [64], [-88], [61], [-90], [80], [99], [4], [-6], [-90], [-22], [29], [54], [36], [-74], [-48], [76], [-64], [1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4275_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4275_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_4275_2_a_c(:prec:=1)
    chi := MakeCharacter_4275_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_4275_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_4275_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4275_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, 1]>,<7,R![4, 1]>,<11,R![3, 1]>],Snew);
    return Vf;
end function;