
// Make newform 1600.3.h.f in Magma, downloaded from the LMFDB on 11 February 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1600_h();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1600_h_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_1600_3_h_f();".
// 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_1600_3_h_f();".
// 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 := [1, 0, 3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 4, 0, 2], [0, 8, 0, 2], [3, 0, 2, 0]];
    Rf_basisdens := [1, 1, 1, 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_1600_h();"
function MakeCharacter_1600_h()
    N := 1600;
    order := 2;
    char_gens := [1151, 901, 577];
    v := [1, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1600_h_Hecke();"
function MakeCharacter_1600_h_Hecke(Kf)
    N := 1600;
    order := 2;
    char_gens := [1151, 901, 577];
    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]];
    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], [-1, 0, 0, 1], [0, 0, 0, 0], [-1, 0, 0, 1], [0, -1, 3, 0], [0, -4, 3, 0], [0, -1, 2, 0], [0, -6, -4, 0], [-1, 0, 0, 9], [30, 0, 0, -4], [0, 15, 1, 0], [0, -6, 7, 0], [0, 0, 0, -26], [-65, 0, 0, 1], [-21, 0, 0, -19], [0, -20, -13, 0], [0, -32, 10, 0], [48, 0, 0, -22], [-33, 0, 0, 17], [0, 31, 5, 0], [0, 13, 10, 0], [0, 22, 18, 0], [-145, 0, 0, -7], [-82, 0, 0, 16], [0, 13, 24, 0], [14, 0, 0, 16], [-29, 0, 0, -75], [-41, 0, 0, 25], [72, 0, 0, 46], [0, 21, -2, 0], [11, 0, 0, 37], [0, 65, -11, 0], [0, -29, -30, 0], [0, -28, 14, 0], [-88, 0, 0, -50], [0, 87, -27, 0], [0, 34, -25, 0], [-21, 0, 0, -75], [-93, 0, 0, -75], [0, 30, -7, 0], [0, 88, -18, 0], [-2, 0, 0, 80], [0, -7, 55, 0], [0, -35, -22, 0], [0, -18, 15, 0], [0, -44, -8, 0], [0, -3, 9, 0], [-241, 0, 0, 17], [-145, 0, 0, -39], [-226, 0, 0, 28], [0, -57, 28, 0], [0, -86, -10, 0], [-152, 0, 0, 46], [0, 63, 35, 0], [0, 15, 38, 0], [-89, 0, 0, -71], [0, 0, 0, 6], [0, 53, -37, 0], [0, -204, -23, 0], [136, 0, 0, 158], [47, 0, 0, 73], [0, 102, 1, 0], [-41, 0, 0, 121], [0, -111, -29, 0], [0, -93, -52, 0], [0, 142, 15, 0], [0, -103, -95, 0], [0, 205, -28, 0], [63, 0, 0, 25], [294, 0, 0, -140], [0, 75, -12, 0], [0, 88, -36, 0], [455, 0, 0, -7], [0, -28, -65, 0], [0, -90, 116, 0], [319, 0, 0, -79], [-208, 0, 0, 134], [0, 20, 77, 0], [138, 0, 0, -248], [-420, 0, 0, -154], [0, 108, -22, 0], [336, 0, 0, 42], [0, -135, -73, 0], [0, 223, 52, 0], [0, 64, 44, 0], [235, 0, 0, -83], [84, 0, 0, 46], [0, -99, -100, 0], [-458, 0, 0, 200], [431, 0, 0, 73], [11, 0, 0, -115], [0, 330, 14, 0], [507, 0, 0, -11], [0, -5, 55, 0], [0, -242, -24, 0], [483, 0, 0, 101], [238, 0, 0, 252], [-54, 0, 0, 152], [455, 0, 0, 17], [710, 0, 0, 88], [423, 0, 0, -239], [0, 372, -63, 0], [-113, 0, 0, 337], [-724, 0, 0, -42], [0, -327, 41, 0], [0, 539, -6, 0], [-261, 0, 0, -3], [0, -41, 56, 0], [0, 130, 82, 0], [-480, 0, 0, 54], [275, 0, 0, 181], [0, -10, -163, 0], [0, -143, -148, 0], [0, -242, -132, 0], [0, -17, 245, 0], [-160, 0, 0, 294], [307, 0, 0, 133], [-597, 0, 0, -43], [0, -262, -95, 0], [0, -16, 206, 0], [320, 0, 0, 154], [0, -9, -92, 0], [0, -202, 15, 0], [-409, 0, 0, -183], [0, -33, -65, 0], [-144, 0, 0, 42], [-314, 0, 0, -172], [0, 74, 22, 0], [719, 0, 0, -207], [0, 214, 105, 0], [0, -228, 162, 0], [-981, 0, 0, 165], [0, 391, -143, 0], [0, -176, 221, 0], [538, 0, 0, 24], [286, 0, 0, -128], [0, 406, -11, 0], [-357, 0, 0, -427], [0, 378, 131, 0], [358, 0, 0, -136], [0, -193, 91, 0], [-160, 0, 0, 234], [-953, 0, 0, -239], [-665, 0, 0, -127], [-80, 0, 0, 534], [0, -66, 62, 0], [0, -218, 69, 0], [0, -105, -82, 0], [0, 52, -138, 0], [-893, 0, 0, 53], [0, -558, -49, 0], [392, 0, 0, -162], [-233, 0, 0, 57], [-425, 0, 0, 217], [531, 0, 0, -307], [0, -113, -103, 0], [0, -522, -66, 0], [444, 0, 0, 86], [0, 149, -136, 0], [-786, 0, 0, -240], [-297, 0, 0, 457], [0, 167, -8, 0], [247, 0, 0, 1], [0, 69, 45, 0], [0, 69, -40, 0], [-265, 0, 0, 121], [0, 135, 289, 0], [0, -312, 297, 0], [734, 0, 0, -320], [0, 302, -283, 0], [0, 126, 236, 0], [790, 0, 0, -488], [0, 337, 83, 0], [0, 165, 122, 0], [0, -340, -156, 0], [518, 0, 0, 280], [0, 421, 133, 0], [134, 0, 0, 312], [-537, 0, 0, 497], [128, 0, 0, 246], [815, 0, 0, -335], [0, 625, -163, 0], [0, 268, 123, 0], [0, -397, 246, 0], [-805, 0, 0, -83], [334, 0, 0, 124], [0, 228, 49, 0], [99, 0, 0, 437], [132, 0, 0, -50], [0, 263, 249, 0], [0, 173, 238, 0], [-1405, 0, 0, -59], [0, -105, -177, 0], [1088, 0, 0, 298], [-1173, 0, 0, 21], [0, -409, -92, 0], [184, 0, 0, 910], [0, 562, 193, 0], [0, -239, -32, 0], [-365, 0, 0, -651], [-138, 0, 0, -12], [0, 341, 75, 0], [0, 88, -327, 0], [-682, 0, 0, -184], [0, 404, -106, 0], [0, -674, 27, 0], [0, 76, 324, 0], [-925, 0, 0, -475], [-202, 0, 0, -888], [0, -131, 285, 0], [0, -545, 26, 0], [-432, 0, 0, -470], [615, 0, 0, -23], [-245, 0, 0, 669], [0, 530, -118, 0], [-616, 0, 0, 222], [315, 0, 0, 853], [-1790, 0, 0, 192], [115, 0, 0, 53], [0, 540, -261, 0], [192, 0, 0, 154], [0, 406, 142, 0], [-314, 0, 0, 248], [435, 0, 0, 413], [-1869, 0, 0, -259], [1056, 0, 0, -26], [0, 1153, -42, 0], [0, 128, 168, 0], [215, 0, 0, -63], [0, -791, -47, 0], [0, -1144, 23, 0], [0, -338, 112, 0], [0, -567, 63, 0], [1048, 0, 0, 142], [-1477, 0, 0, -75], [283, 0, 0, 549], [-1780, 0, 0, 134], [0, 16, 463, 0], [0, 582, -196, 0], [0, -451, 263, 0], [351, 0, 0, -679], [0, -193, 19, 0], [-341, 0, 0, -43], [190, 0, 0, -980], [0, -637, 172, 0], [0, 796, 256, 0], [-413, 0, 0, -659], [0, -889, -105, 0], [0, 576, 130, 0], [1799, 0, 0, 609], [0, 724, -147, 0], [-646, 0, 0, -24], [-1477, 0, 0, -267], [588, 0, 0, -586], [0, -1362, -63, 0], [0, -130, -408, 0], [-1354, 0, 0, 88], [-1105, 0, 0, 185], [0, 836, -103, 0], [0, -431, -288, 0], [995, 0, 0, -939], [303, 0, 0, -951], [270, 0, 0, 684], [0, 940, -105, 0], [0, -545, 250, 0], [0, 422, 216, 0], [422, 0, 0, -268], [1210, 0, 0, -136], [1099, 0, 0, 397], [0, 986, 301, 0], [-1658, 0, 0, -504], [1659, 0, 0, 733], [0, 99, 344, 0], [0, -412, 468, 0], [0, -153, 454, 0], [2299, 0, 0, 229], [-1597, 0, 0, -275], [-1802, 0, 0, 308], [112, 0, 0, 134], [0, -1099, -119, 0], [-1437, 0, 0, 293], [0, -595, -257, 0], [-1689, 0, 0, 257], [-290, 0, 0, -1008], [251, 0, 0, 493], [0, -813, 333, 0], [0, -799, -322, 0], [0, -242, -185, 0], [0, 322, -198, 0], [-260, 0, 0, -170], [-1392, 0, 0, -646], [-949, 0, 0, -331], [0, -27, 170, 0], [0, 223, 403, 0], [0, -1330, 33, 0], [-2888, 0, 0, 174], [0, -517, -83, 0], [0, 150, 33, 0], [0, 322, 312, 0], [659, 0, 0, 821], [0, -787, 30, 0], [0, -906, -85, 0], [0, 6, 26, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1600_h_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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