
// Make newform 825.4.c.j in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_825_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_825_c_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_825_4_c_j();".
// 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_825_4_c_j();".
// 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 := [16, 0, 9, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 5, 0, 1], [5, 0, 1, 0]];
    Rf_basisdens := [1, 1, 4, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_825_c();"
function MakeCharacter_825_c()
    N := 825;
    order := 2;
    char_gens := [551, 727, 376];
    v := [2, 1, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_825_c_Hecke();"
function MakeCharacter_825_c_Hecke(Kf)
    N := 825;
    order := 2;
    char_gens := [551, 727, 376];
    char_values := [[1, 0, 0, 0], [-1, 0, 0, 0], [1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := [[0, 1, 0, 0], [0, 0, -3, 0], [0, 0, 0, 0], [0, -4, -4, 0], [-11, 0, 0, 0], [0, -2, 44, 0], [0, -44, -30, 0], [96, 0, 0, -22], [0, -60, 32, 0], [62, 0, 0, 34], [24, 0, 0, 12], [0, 112, -130, 0], [-58, 0, 0, 154], [0, -124, 196, 0], [0, -216, 4, 0], [0, -196, -334, 0], [-244, 0, 0, 240], [218, 0, 0, -364], [0, -16, -380, 0], [1052, 0, 0, -44], [0, 58, 272, 0], [-168, 0, 0, -306], [0, -426, -70, 0], [-58, 0, 0, -128], [0, -428, -298, 0], [282, 0, 0, 26], [0, 656, 512, 0], [0, 322, -1282, 0], [262, 0, 0, 484], [0, 0, -170, 0], [0, -192, -1440, 0], [-804, 0, 0, 436], [0, -340, -186, 0], [-184, 0, 0, 414], [1654, 0, 0, 282], [-16, 0, 0, -30], [0, -540, -1038, 0], [0, 1064, 804, 0], [0, -346, -714, 0], [0, 44, 1138, 0], [-484, 0, 0, 752], [358, 0, 0, 1524], [572, 0, 0, -556], [0, -82, 2588, 0], [0, 732, 2334, 0], [-40, 0, 0, -1544], [3080, 0, 0, -794], [0, -808, 1768, 0], [0, 174, -4558, 0], [-1990, 0, 0, -1452], [0, -164, -2690, 0], [1792, 0, 0, 112], [4210, 0, 0, -920], [-4756, 0, 0, 936], [0, -532, 6350, 0], [0, -498, -1482, 0], [-3730, 0, 0, -1292], [1656, 0, 0, 1366], [0, 1162, 7260, 0], [870, 0, 0, -1670], [0, 548, 7972, 0], [0, 3124, -350, 0], [0, -1168, 2392, 0], [-3708, 0, 0, -1228], [0, 80, 1014, 0], [0, -1828, 6062, 0], [-1348, 0, 0, -3040], [0, 2030, -6640, 0], [0, 482, -842, 0], [-3570, 0, 0, 1452], [0, -2496, -3970, 0], [528, 0, 0, -2148], [0, -4592, -6096, 0], [0, 1166, 2812, 0], [-2620, 0, 0, -1516], [0, -5760, -3740, 0], [-9586, 0, 0, -952], [0, -1164, -3406, 0], [-14, 0, 0, 3772], [-90, 0, 0, 820], [-2468, 0, 0, -768], [-1842, 0, 0, 6660], [2872, 0, 0, -3316], [0, -548, 15162, 0], [-4584, 0, 0, 78], [0, 6108, 552, 0], [-4234, 0, 0, -2088], [0, 2410, 6236, 0], [-11582, 0, 0, 182], [0, -2808, 5952, 0], [0, 5536, 4004, 0], [1928, 0, 0, 3432], [0, 2424, 3376, 0], [3860, 0, 0, 4180], [8676, 0, 0, -1576], [0, 5090, 4258, 0], [-12242, 0, 0, 868], [9098, 0, 0, -3140], [0, 360, 15672, 0], [1178, 0, 0, -196], [0, 7184, 1840, 0], [0, 512, -7510, 0], [0, 3598, 15202, 0], [914, 0, 0, -1626], [-15104, 0, 0, 4086], [0, 6732, 3950, 0], [0, -7144, -11604, 0], [0, 1144, 13170, 0], [14028, 0, 0, -6316], [3466, 0, 0, 9484], [0, 3648, -16688, 0], [0, -3690, -4884, 0], [0, 4840, -358, 0], [-3908, 0, 0, -3232], [7760, 0, 0, -152], [-9830, 0, 0, -5928], [0, 1368, 19532, 0], [0, -6064, -18156, 0], [0, 4224, 7718, 0], [23676, 0, 0, 1816], [-858, 0, 0, -12232], [0, -1586, 8684, 0], [0, 8856, 15002, 0], [0, -5964, 6120, 0], [19148, 0, 0, -4476], [18370, 0, 0, 3194], [-5110, 0, 0, 8360], [-4500, 0, 0, 3308], [0, 4608, -17976, 0], [0, 10730, -7544, 0], [-18672, 0, 0, 2962], [0, 11882, 8866, 0], [13464, 0, 0, -9664], [0, -988, 5282, 0], [-4130, 0, 0, -4486], [1942, 0, 0, -16468], [0, -6488, -12690, 0], [0, -2020, -26300, 0], [0, -9492, -12618, 0], [-6974, 0, 0, 4698], [25024, 0, 0, 2130], [16602, 0, 0, 8318], [0, -6888, -12880, 0], [0, -2198, -39202, 0], [5930, 0, 0, 15312], [13412, 0, 0, -17116], [0, -6242, -620, 0], [0, 636, 11954, 0], [24564, 0, 0, -1632], [0, 5192, -17164, 0], [0, 538, -3708, 0], [-11094, 0, 0, -300], [0, -4936, -25756, 0], [0, 4090, -3966, 0], [0, 1656, -40740, 0], [-9292, 0, 0, -10332], [-3632, 0, 0, -5370], [2030, 0, 0, -3508], [0, -5970, -6752, 0], [5394, 0, 0, -2374], [0, -2956, 39968, 0], [0, 16192, -5894, 0], [0, 15720, 4096, 0], [-27116, 0, 0, 2944], [0, 6620, 39758, 0], [0, -14320, 7916, 0], [-10584, 0, 0, 15500], [0, 2722, -13388, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_825_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_825_4_c_j();".
// 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_825_4_c_j(:prec:=4)
    chi := MakeCharacter_825_c();
    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_825_4_c_j();".
// 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_825_4_c_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_825_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![16, 0, 9, 0, 1]>,<7,R![4096, 0, 144, 0, 1]>],Snew);
    return Vf;
end function;