
// Make newform 7595.2.a.i in Magma, downloaded from the LMFDB on 11 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7595_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_7595_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_7595_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_7595_a();"
function MakeCharacter_7595_a()
    N := 7595;
    order := 1;
    char_gens := [6077, 5736, 4901];
    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_7595_a_Hecke(Kf)
    return MakeCharacter_7595_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], [3], [1], [0], [4], [2], [1], [-3], [0], [2], [1], [7], [7], [-9], [-2], [-5], [9], [0], [2], [1], [-5], [-10], [13], [-12], [-14], [-5], [16], [6], [15], [0], [-8], [5], [5], [14], [1], [-2], [16], [-16], [-11], [20], [-24], [-6], [20], [18], [-18], [-20], [-20], [11], [6], [10], [20], [-18], [28], [-14], [14], [9], [-2], [-2], [-33], [15], [18], [6], [-8], [35], [17], [20], [-8], [-29], [-24], [-23], [-14], [24], [29], [18], [-21], [-27], [-18], [2], [28], [14], [19], [7], [15], [-18], [-25], [6], [-30], [38], [0], [28], [28], [24], [-13], [20], [-34], [-30], [20], [1], [-1], [10], [-8], [18], [-42], [24], [-30], [-14], [0], [-16], [-16], [32], [-38], [-35], [-12], [4], [-36], [-36], [-21], [15], [-28], [39], [23], [-35], [-9], [28], [13], [46], [-10], [12], [-16], [24], [30], [7], [4], [-11], [0], [-23], [10], [-28], [-26], [-18], [-25], [8], [-9], [-37], [18], [-33], [20], [-24], [44], [-3], [8], [-54], [-29], [-42], [-52], [12], [-9], [8], [12], [2], [-47], [-31], [-8], [-37], [28], [-32], [-60], [-16], [16], [-38], [-46], [-4], [-9], [40], [-43], [-22], [27], [18], [-10], [-44], [32], [-30], [34], [-31], [44], [-12], [38], [6], [-16], [15], [-10], [-42], [-50], [-36], [32], [46], [40], [-56], [42], [66], [-9], [22], [-6], [10], [68], [53], [-1], [39], [-45], [-13], [-9], [-36], [34], [-38], [52], [-69], [68], [50], [-45], [6], [-10], [48], [-33], [-4], [62], [-40], [14], [26], [37], [4], [41], [44], [-25], [-68], [52], [0], [-41], [-30], [48], [42], [-8], [44], [-9], [-36], [-1], [-16], [-65], [-66], [-6], [-14], [-18], [49], [-48], [31], [-60], [-51], [-10], [-7], [60], [64], [44], [40], [6], [-14], [42], [-68], [66], [-66], [-24], [-6], [11], [12], [-29], [-34], [-62], [26], [36], [-46], [48], [0], [-52], [31], [-48], [-39], [50], [-22], [-26], [-13], [60], [-78], [-75], [18], [-81], [-79], [50], [36], [62], [48], [4], [-57], [0], [63], [28], [-56], [-70], [38], [-75], [34], [-78], [62], [-15], [6], [-7], [-11], [-78], [34], [-36], [30], [-66], [-16], [26], [86], [-30], [-34], [-46], [20], [4], [54], [33], [-35], [-35], [-72], [16], [-60], [-23], [26], [56], [-78], [-83], [-65], [25], [54], [88], [-54], [-66], [85], [-53], [28], [66], [-38], [18], [45], [89], [-24], [46], [54], [-90], [-56], [31], [-16], [-44], [8], [33], [-20], [-30], [30], [78], [95], [-11], [36], [53], [-18], [9], [-88], [7], [10], [8], [28], [57], [73], [-42], [41], [31], [-9], [-40], [0], [49], [73], [36], [61], [64], [-69], [36], [84], [95], [-14], [-4], [-75], [-60], [22], [-74], [-54], [-10], [-32], [-10], [33], [14], [78], [-59], [-74], [3], [58], [-85], [-8], [-38], [-63], [78], [94], [-2], [4], [52], [13], [57], [-15], [50], [-45], [-24], [-46], [-34], [-70]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7595_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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