
// Make newform 1008.3.dc.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1008_dc();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1008_dc_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_1008_3_dc_b();".
// 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_1008_3_dc_b();".
// 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 := [4, 0, -2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 3]];
    Rf_basisdens := [1, 1, 2, 2];
    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_1008_dc();"
function MakeCharacter_1008_dc()
    N := 1008;
    order := 6;
    char_gens := [127, 757, 785, 577];
    v := [6, 6, 3, 4];
    // 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_1008_dc_Hecke();"
function MakeCharacter_1008_dc_Hecke(Kf)
    N := 1008;
    order := 6;
    char_gens := [127, 757, 785, 577];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 0], [-1, 0, 1, 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 := 3;
    raw_aps := [[0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 0, 0], [7, 0, -7, 0], [0, -3, 0, 3], [-1, 0, 0, 0], [0, 4, 0, -4], [23, 0, -23, 0], [0, 4, 0, 0], [0, 0, 0, -8], [0, 0, 47, 0], [55, 0, -55, 0], [0, 0, 0, 11], [-23, 0, 0, 0], [0, 1, 0, 0], [0, 12, 0, -12], [0, 20, 0, -20], [-104, 0, 104, 0], [0, 0, -97, 0], [0, 0, 0, 23], [0, 0, -65, 0], [113, 0, -113, 0], [0, 0, 0, -7], [0, 32, 0, 0], [104, 0, 0, 0], [0, 35, 0, -35], [119, 0, -119, 0], [0, 28, 0, 0], [0, 0, 49, 0], [0, 0, 0, 23], [-113, 0, 0, 0], [0, -5, 0, 0], [0, -16, 0, 16], [103, 0, 0, 0], [0, -40, 0, 0], [0, 0, 104, 0], [0, 0, -152, 0], [56, 0, -56, 0], [0, 0, 0, -1], [0, -36, 0, 0], [0, 1, 0, -1], [-55, 0, 0, 0], [0, 15, 0, 0], [0, 0, 151, 0], [0, 0, 0, -4], [0, 0, -160, 0], [208, 0, 0, 0], [40, 0, 0, 0], [0, -53, 0, 53], [-377, 0, 377, 0], [0, 81, 0, 0], [0, 0, 0, -3], [0, 0, 130, 0], [0, 0, 0, -12], [0, -111, 0, 0], [0, -24, 0, 24], [0, -67, 0, 67], [-520, 0, 520, 0], [0, 0, -113, 0], [0, 0, 0, 108], [0, 0, 89, 0], [0, 0, 0, 16], [-233, 0, 0, 0], [0, -59, 0, 59], [151, 0, -151, 0], [0, -96, 0, 0], [-73, 0, 73, 0], [527, 0, 0, 0], [0, -100, 0, 100], [-112, 0, 0, 0], [0, 73, 0, -73], [0, -120, 0, 0], [0, 0, -319, 0], [-209, 0, 209, 0], [433, 0, 0, 0], [0, -92, 0, 0], [0, -87, 0, 87], [-113, 0, 113, 0], [0, 84, 0, 0], [0, 0, 319, 0], [0, 0, 0, 181], [65, 0, 0, 0], [0, -113, 0, 113], [-367, 0, 0, 0], [536, 0, -536, 0], [0, -20, 0, 0], [0, 0, 0, 145], [463, 0, -463, 0], [0, 0, 0, -64], [-47, 0, 0, 0], [0, -175, 0, 0], [0, 100, 0, -100], [0, 0, 239, 0], [0, 0, 0, 48], [-49, 0, 49, 0], [0, 0, 0, 139], [0, -57, 0, 0], [0, -200, 0, 200], [-391, 0, 391, 0], [73, 0, -73, 0], [-32, 0, 0, 0], [0, 11, 0, -11], [0, 209, 0, -209], [0, -75, 0, 0], [0, 0, -535, 0], [0, 0, -905, 0], [0, 0, 0, 136], [0, 131, 0, 0], [0, 48, 0, -48], [143, 0, 0, 0], [599, 0, -599, 0], [0, 0, 304, 0], [0, 0, 0, 69], [0, 0, -343, 0], [-272, 0, 0, 0], [0, 100, 0, -100], [679, 0, 0, 0], [0, 227, 0, -227], [0, 211, 0, 0], [0, 0, 0, 4], [0, 0, 433, 0], [737, 0, 0, 0], [0, 32, 0, 0], [0, -300, 0, 300], [-247, 0, 247, 0], [0, 0, 0, 76], [1048, 0, -1048, 0], [0, 59, 0, 0], [-641, 0, 0, 0], [25, 0, -25, 0], [0, 0, -535, 0], [0, 0, 0, 221], [41, 0, -41, 0], [-1114, 0, 0, 0], [0, -68, 0, 0], [1127, 0, 0, 0], [0, 51, 0, -51], [0, 0, 170, 0], [0, 0, 0, 276], [0, 79, 0, -79], [1114, 0, 0, 0], [0, -23, 0, 0], [0, 0, 1592, 0], [0, 0, 0, 241], [0, 0, -383, 0], [0, 0, 0, 136], [527, 0, 0, 0], [0, 312, 0, -312], [-1414, 0, 1414, 0], [0, -323, 0, 0], [-224, 0, 224, 0], [0, 0, 0, -380], [-329, 0, 0, 0], [0, -13, 0, 0], [0, 0, 311, 0], [0, 0, 0, 84], [-145, 0, 145, 0], [0, -73, 0, 0], [-487, 0, 0, 0], [0, 324, 0, -324], [0, 45, 0, 0], [0, 0, 0, 244], [1681, 0, 0, 0], [0, -284, 0, 0], [0, -277, 0, 277], [0, -452, 0, 452], [0, 0, -625, 0], [0, 0, 943, 0], [-553, 0, 0, 0], [0, -272, 0, 0], [0, 232, 0, -232], [-874, 0, 0, 0], [0, -160, 0, 0], [0, 0, 1825, 0], [0, 0, -271, 0], [0, 0, 0, -256], [559, 0, 0, 0], [0, 9, 0, -9], [448, 0, 0, 0], [-95, 0, 95, 0], [1865, 0, -1865, 0], [0, 0, 0, -88], [959, 0, 0, 0], [0, -212, 0, 0], [0, -27, 0, 27], [0, -240, 0, 240], [0, 0, 736, 0], [0, 0, -79, 0], [1567, 0, -1567, 0], [0, 277, 0, -277], [265, 0, -265, 0], [0, 0, 0, -137], [-1546, 0, 1546, 0], [0, -100, 0, 0], [0, 412, 0, -412], [0, 72, 0, -72], [0, 0, 1033, 0], [2056, 0, -2056, 0], [0, 0, 0, 371], [0, 292, 0, 0], [0, -331, 0, 331], [-1751, 0, 0, 0], [1288, 0, -1288, 0], [0, 0, 328, 0], [0, 0, 0, 557], [0, 93, 0, -93], [560, 0, -560, 0], [0, 259, 0, 0], [0, 0, 0, -384], [0, 0, 944, 0], [-1943, 0, 1943, 0], [0, 0, 0, -112], [-50, 0, 0, 0], [0, -172, 0, 0], [0, -468, 0, 468], [-2231, 0, 2231, 0], [0, 0, -1648, 0], [0, 56, 0, -56], [0, 332, 0, 0], [0, 0, 0, -255], [-2447, 0, 2447, 0], [-1697, 0, 0, 0], [0, -33, 0, 0], [-1600, 0, 1600, 0], [0, 0, 0, 3], [1184, 0, 0, 0], [0, -224, 0, 0], [0, 5, 0, -5], [2153, 0, -2153, 0], [0, -279, 0, 0], [0, 0, 2281, 0], [0, 0, -1168, 0], [433, 0, 0, 0], [0, 341, 0, -341], [1663, 0, 0, 0], [0, -31, 0, 31], [169, 0, -169, 0], [0, 653, 0, 0], [0, 0, 0, 176], [0, 0, 0, -447], [0, 465, 0, -465], [47, 0, -47, 0], [0, 0, -289, 0], [1654, 0, -1654, 0], [0, 0, 0, -216], [0, 172, 0, 0], [-1775, 0, 0, 0], [0, 631, 0, -631], [0, 0, 1574, 0], [0, 0, 0, 64], [1481, 0, 0, 0], [0, -236, 0, 0], [0, -229, 0, 229], [287, 0, 0, 0], [0, -464, 0, 464], [0, 352, 0, 0], [0, 0, 2551, 0], [0, 0, 215, 0], [0, 0, 0, 239], [2608, 0, -2608, 0], [0, 0, -1639, 0], [0, 0, 0, 248], [0, 0, -1361, 0], [-217, 0, 0, 0], [0, -203, 0, 203], [3257, 0, -3257, 0], [0, 0, 0, -357], [0, 0, 0, 39], [-1448, 0, 0, 0], [0, -269, 0, 269], [823, 0, -823, 0], [0, 0, -952, 0], [0, 0, 1729, 0], [-2599, 0, 2599, 0], [584, 0, 0, 0], [1010, 0, -1010, 0], [0, 135, 0, 0], [0, 0, 271, 0], [-209, 0, 209, 0], [0, -716, 0, 0], [0, 360, 0, -360], [0, 0, -511, 0], [0, 0, 0, 691], [-2233, 0, 0, 0], [440, 0, -440, 0], [0, 195, 0, 0], [0, 0, 1825, 0], [0, 0, 0, -55], [0, 0, 1655, 0], [0, 0, 0, -319], [0, 408, 0, -408], [0, -520, 0, 520], [0, 431, 0, 0], [0, 0, 0, 312], [-2455, 0, 0, 0], [0, -243, 0, 243], [689, 0, -689, 0], [0, 0, 0, -444], [0, -217, 0, 0], [1633, 0, 0, 0], [3448, 0, -3448, 0], [0, -573, 0, 0], [0, 0, 3458, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1008_dc_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1008_3_dc_b();".
// 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_1008_3_dc_b(:prec:=4)
    chi := MakeCharacter_1008_dc();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_1008_3_dc_b();".
// 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_1008_3_dc_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1008_dc();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![324, 0, -18, 0, 1]>,<11,R![26244, 0, -162, 0, 1]>],Snew);
    return Vf;
end function;