
// Make newform 2075.2.a.d in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2075_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_2075_2_a_d();".
// 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_2075_2_a_d();".
// 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_2075_a();"
function MakeCharacter_2075_a()
    N := 2075;
    order := 1;
    char_gens := [1827, 251];
    v := [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_2075_a_Hecke(Kf)
    return MakeCharacter_2075_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], [1], [0], [3], [3], [6], [-5], [2], [4], [-7], [5], [11], [-2], [8], [0], [-6], [5], [5], [2], [2], [0], [14], [1], [0], [8], [-6], [4], [18], [-17], [-15], [-13], [-4], [14], [-2], [-16], [9], [-10], [22], [-21], [-21], [-6], [-26], [-3], [-2], [-11], [0], [-8], [16], [28], [-10], [-18], [-8], [-1], [8], [6], [6], [10], [-32], [-10], [0], [-26], [6], [-20], [0], [-11], [-3], [-22], [-2], [-14], [23], [1], [33], [14], [11], [16], [29], [4], [-2], [-18], [-21], [27], [-38], [21], [16], [-8], [-13], [-2], [-30], [20], [5], [12], [21], [16], [-10], [-9], [0], [-33], [-14], [-29], [-26], [-13], [26], [-21], [-18], [16], [18], [12], [15], [12], [42], [-24], [8], [-11], [23], [-12], [8], [-8], [42], [-24], [-12], [0], [23], [8], [-28], [-35], [22], [6], [44], [-23], [1], [-16], [36], [40], [-23], [12], [-16], [-30], [-52], [24], [-28], [-20], [-32], [-36], [32], [-6], [-45], [-1], [49], [41], [-37], [14], [21], [46], [-48], [47], [3], [20], [-35], [-12], [-25], [-32], [27], [-22], [-22], [19], [44], [1], [9], [-26], [-6], [48], [47], [18], [55], [-10], [14], [20], [-26], [2], [8], [26], [19], [52], [28], [-26], [65], [2], [33], [-8], [-36], [-10], [-21], [19], [-22], [9], [35], [6], [-29], [-46], [43], [54], [-24], [13], [3], [-16], [6], [-56], [55], [-26], [-18], [-6], [40], [-2], [-6], [-30], [28], [12], [-51], [-52], [18], [-50], [-30], [-58], [20], [-8], [40], [36], [-33], [68], [45], [68], [19], [40], [57], [-48], [-24], [49], [-48], [-22], [-48], [16], [-28], [-25], [-20], [-54], [13], [10], [-25], [-22], [72], [-16], [52], [-27], [10], [-65], [-10], [-55], [40], [-2], [-2], [19], [-12], [10], [-22], [35], [-52], [-6], [-35], [-4], [-34], [-7], [8], [-46], [-29], [-64], [-81], [33], [-50], [30], [-69], [-50], [16], [-28], [-42], [23], [-40], [-32], [35], [64], [-47], [33], [-43], [-74], [26], [82], [-17], [-72], [13], [81], [8], [58], [-52], [65], [-23], [50], [-13], [-6], [-13], [-46], [39], [12], [-37], [-52], [-62], [-7], [42], [72], [88], [-69], [42], [32], [12], [-12], [16], [-31], [63], [-3], [-56], [68], [46], [41], [12], [-49], [-24], [25], [-23], [-33], [-2], [-10], [-34], [-32], [62], [-35], [-41], [-43], [-44], [-47], [96], [-27], [78], [60], [34], [50], [16], [-41], [-39], [12], [68], [-62], [-40], [-38], [-50], [-9], [38], [-16], [-58], [-21], [-12], [95], [12], [-24], [36], [97], [-8], [-8], [-64], [76], [-28], [-91], [-35], [66], [44], [-8], [18], [-65], [-3], [-14], [-19], [-4], [-27], [-17], [-86], [36], [33], [-12], [-46], [-75], [2], [-69], [-44], [7], [-48], [-11], [54], [84], [-42], [84], [8], [-4], [-54], [105], [-8], [-45], [-45], [-30], [96], [46], [13], [-27], [-23], [66], [47], [-42], [-60], [-65], [-18], [84], [54], [10], [-40]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2075_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2075_2_a_d();".
// 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_2075_2_a_d(:prec:=1)
    chi := MakeCharacter_2075_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_2075_2_a_d();".
// 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_2075_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2075_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1]>,<3,R![-1, 1]>],Snew);
    return Vf;
end function;