
// Make newform 75.4.a.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_75_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_75_4_a_e();".
// 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_75_4_a_e();".
// 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
        poly := [-19, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_75_a();"
function MakeCharacter_75_a()
    N := 75;
    order := 1;
    char_gens := [26, 52];
    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_75_a_Hecke(Kf)
    return MakeCharacter_75_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 := 4;
    raw_aps := [[1, 1], [-3, 0], [0, 0], [-13, 4], [14, -4], [-9, -16], [34, -20], [3, 4], [-66, -12], [46, 28], [61, -28], [142, 24], [196, 52], [-345, -4], [310, -32], [424, 28], [62, -64], [375, -56], [179, 100], [412, -20], [54, 8], [-440, -160], [-78, 192], [-432, 144], [-521, 0], [504, 36], [-380, -264], [840, -132], [1013, 24], [1492, -128], [-456, -40], [-960, -276], [-1014, -24], [-1108, 216], [1474, -488], [-273, -380], [-1019, -264], [-1067, 420], [1152, 324], [942, -228], [-1690, -520], [-79, 432], [-326, 916], [1357, 312], [-1302, -168], [-2301, 172], [1571, 372], [-1949, 804], [5492, 164], [1297, 776], [-1620, 1116], [-712, -676], [-231, 496], [-3228, -600], [-2100, -552], [-2812, -580], [2618, 44], [1464, 376], [6203, -368], [1578, 228], [161, -1316], [-3702, -480], [585, 188], [-2946, -264], [3733, -1080], [-4240, 1448], [292, -1480], [2823, -1288], [454, -320], [-2334, -272], [366, -1236], [6132, 156], [-6067, 532], [-915, 416], [-3015, -1460], [-492, 2280], [1092, -2004], [6225, 1328], [-11520, 684], [-12163, -24], [10768, 1084], [-1242, 2008], [-3174, -2868], [8733, 200], [525, -1580], [1056, -456], [-14116, -1048], [-918, 2864], [7632, 2700], [6200, -1784], [3770, -1612], [11430, -720], [3349, -1860], [-7880, 2704], [2643, -1316], [16916, 284], [-7378, 2216], [-12734, -908], [2985, 3236], [13501, -1888], [-4128, -2536], [-2826, -2160], [-9018, -1188], [-5862, 3444], [22379, 276], [5509, -2160], [360, 5868], [-3460, 356], [724, -968], [-21301, 696], [-20256, 2000], [-18138, -688], [-14784, -204], [9167, 3156], [6057, 700], [7236, 2952], [-8620, 616], [11404, 640], [-3922, 2000], [9020, -1060], [3522, 4720], [22034, 1288], [18138, 2172], [4488, 2400], [-3216, 2776], [22570, -2756], [18273, 1624], [-2886, 2892], [16891, 2436], [-8870, 3696], [-23268, 1696], [21460, 976], [4344, -3224], [-6369, 3656], [1068, -3072], [-18661, 4872], [-6732, 3060], [-13575, -652], [9140, -1192], [1480, -4460], [-173, -2980], [16878, 2208], [-21113, 3252], [-4496, -8420], [14650, -3520], [-21050, 3340], [6173, -1160], [-33260, -2552], [-13200, -2840], [5720, 1256], [-16003, 4984], [-6472, -6472], [3175, -9444], [14490, 3168], [6020, 2608], [19022, 1040], [-14265, 1900], [3298, 3964], [-7567, 4312], [11926, 6112], [3606, -1884], [34696, -2096], [-24296, -3120], [-9414, -8568], [-13706, 2440], [-14436, -432], [-20263, 5820], [13646, -4784]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_75_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_75_4_a_e();".
// 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_75_4_a_e(:prec:=2)
    chi := MakeCharacter_75_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_75_4_a_e();".
// 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_75_4_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_75_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-18, -2, 1]>],Snew);
    return Vf;
end function;