
// Make newform 1800.3.v.m in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1800_v();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1800_v_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_1800_3_v_m();".
// 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_1800_3_v_m();".
// 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 := [9, 0, 0, 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, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 3, 3];
    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_1800_v();"
function MakeCharacter_1800_v()
    N := 1800;
    order := 4;
    char_gens := [1351, 901, 1001, 577];
    v := [4, 4, 4, 3];
    // 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_1800_v_Hecke();"
function MakeCharacter_1800_v_Hecke(Kf)
    N := 1800;
    order := 4;
    char_gens := [1351, 901, 1001, 577];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [0, 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, 0, 0, 0], [2, 0, -2, 1], [2, -2, 0, 2], [12, -5, 12, 0], [-2, 0, 2, 2], [0, 2, -5, 2], [-18, -6, -18, 0], [0, -14, 2, -14], [11, -6, 0, 6], [28, 0, -28, -12], [8, 2, 0, -2], [26, 19, 26, 0], [-20, 0, 20, -14], [-26, 32, -26, 0], [0, -32, 2, -32], [-45, -24, 0, 24], [66, 0, -66, 15], [-64, 14, 0, -14], [28, -20, 28, 0], [0, -4, -78, -4], [4, -70, 4, 0], [0, -28, -28, -28], [80, 0, -80, 21], [124, -30, 0, 30], [36, -8, 36, 0], [66, 0, -66, 60], [0, -48, 23, -48], [-8, 80, -8, 0], [52, 0, -52, 12], [-80, -46, 0, 46], [60, 0, -60, -86], [0, -104, -2, -104], [0, 24, 134, 24], [143, -18, 0, 18], [-8, 0, 8, -91], [-62, 35, -62, 0], [82, 0, -82, -12], [114, 54, 114, 0], [0, 0, -134, 0], [-103, -28, 0, 28], [106, -54, 0, 54], [-68, -5, -68, 0], [60, 0, -60, 10], [0, -90, -135, -90], [-23, -50, 0, 50], [-114, -95, -114, 0], [82, 0, -82, 100], [0, -16, -171, -16], [218, 64, 218, 0], [0, 6, -104, 6], [199, -32, 0, 32], [80, 48, 0, -48], [72, 0, -72, -124], [66, -128, 66, 0], [0, -18, 406, -18], [-158, -24, 0, 24], [116, 0, -116, -73], [-330, -2, 0, 2], [42, -95, 42, 0], [-232, 94, -232, 0], [-14, 0, 14, 99], [298, -24, 0, 24], [84, 153, 84, 0], [16, 0, -16, 156], [-350, 88, 0, -88], [-36, 0, 36, 83], [-236, 0, 236, 106], [0, 40, -238, 40], [-314, 86, -314, 0], [0, -158, -196, -158], [-42, 0, 42, -135], [-4, 285, -4, 0], [0, 210, -93, 210], [-276, -56, -276, 0], [0, -22, 540, -22], [12, 0, -12, -245], [-360, -94, 0, 94], [0, 204, 237, 204], [0, 138, -300, 138], [-302, -12, 0, 12], [554, 118, 0, -118], [180, -25, 180, 0], [0, 198, 61, 198], [-244, 236, -244, 0], [0, -64, -164, -64], [-208, 0, 208, 320], [-128, 206, 0, -206], [84, -244, 84, 0], [-314, 0, 314, 122], [0, -12, -386, -12], [-66, 0, 66, -85], [28, -168, 0, 168], [0, 170, -335, 170], [186, -292, 186, 0], [0, -4, 462, -4], [-54, 338, 0, -338], [-390, -69, -390, 0], [-125, 260, 0, -260], [-276, 0, 276, 80], [-252, 0, 252, 138], [-118, 90, -118, 0], [0, 222, -70, 222], [-331, 86, 0, -86], [-304, 0, 304, -31], [170, 0, -170, 232], [258, 252, 258, 0], [0, 308, 248, 308], [-403, 156, 0, -156], [-536, 0, 536, -188], [-168, 12, -168, 0], [174, 0, -174, -84], [0, -290, 321, -290], [101, 194, 0, -194], [52, -340, 0, 340], [-140, 444, -140, 0], [-108, 0, 108, -400], [-216, 54, -216, 0], [0, 10, 528, 10], [-118, -64, 0, 64], [-492, -108, -492, 0], [-18, 0, 18, -18], [708, 168, 708, 0], [522, 312, 0, -312], [-46, 234, 0, -234], [0, 168, -207, 168], [0, 218, -22, 218], [54, 0, -54, -129], [-120, -476, -120, 0], [0, -28, -770, -28], [-164, -652, -164, 0], [-170, 312, 0, -312], [-528, 0, 528, -105], [392, -212, 0, 212], [0, -300, 35, -300], [554, 60, 554, 0], [-206, 0, 206, 129], [72, 0, -72, 472], [0, -430, -112, -430], [-425, -442, 0, 442], [770, 80, 0, -80], [-318, 187, -318, 0], [342, 0, -342, 504], [0, 40, 254, 40], [0, 130, 1090, 130], [-56, 87, -56, 0], [-108, 0, 108, -260], [0, 288, 550, 288], [508, 408, 508, 0], [384, 0, -384, 83], [176, 508, 0, -508], [74, 895, 74, 0], [88, 0, -88, -546], [360, 0, -360, -476], [946, 96, 0, -96], [0, -206, 31, -206], [0, -526, 194, -526], [492, 0, -492, -133], [282, -428, 0, 428], [-318, 0, 318, 6], [36, -4, 36, 0], [104, 0, -104, -172], [-638, 364, 0, -364], [-216, 0, 216, 298], [-592, -116, -592, 0], [-407, 418, 0, -418], [64, 0, -64, 428], [0, 304, -553, 304], [-572, -462, -572, 0], [0, 66, -334, 66], [131, -532, 0, 532], [-166, -440, 0, 440], [612, 175, 612, 0], [0, -58, -201, -58], [0, 272, 208, 272], [-669, 62, 0, -62], [-350, 434, 0, -434], [1050, 69, 1050, 0], [0, -128, -925, -128], [898, 0, -898, -423], [-1412, -192, 0, 192], [604, -431, 604, 0], [84, 0, -84, 518], [-508, 570, -508, 0], [0, -268, -910, -268], [972, 0, -972, -23], [454, 233, 454, 0], [0, 156, -695, 156], [1446, 318, 0, -318], [-132, -153, -132, 0], [-134, 1008, -134, 0], [-585, -242, 0, 242], [-334, -626, 0, 626], [-910, 0, 910, 42], [-760, -26, -760, 0], [-242, 388, 0, -388], [160, 660, 160, 0], [320, 0, -320, 986], [822, -158, 822, 0], [0, -126, -964, -126], [-158, -488, 0, 488], [976, 0, -976, 256], [0, -644, -646, -644], [0, -668, -564, -668], [198, 0, -198, -258], [0, -162, 1829, -162], [-114, 94, -114, 0], [0, 84, 192, 84], [-1849, 54, 0, -54], [-144, 0, 144, -995], [-1346, -232, 0, 232], [-678, -57, -678, 0], [-264, 0, 264, 624], [0, 228, 1606, 228], [-158, -644, 0, 644], [1230, 0, -1230, -355], [-458, 706, 0, -706], [450, 0, -450, -1064], [-1170, -390, -1170, 0], [1471, 276, 0, -276], [0, -758, 115, -758], [0, -428, 854, -428], [-276, -668, -276, 0], [902, 0, -902, 160], [0, -100, 1267, -100], [510, 250, 510, 0], [0, -24, -210, -24], [-326, 0, 326, -521], [534, -374, 0, 374], [-1004, -61, -1004, 0], [0, 56, -1222, 56], [-471, -766, 0, 766], [-186, -948, 0, 948], [828, -708, 828, 0], [1272, 0, -1272, 444], [0, -92, -2090, -92], [1862, -96, 1862, 0], [0, 912, -606, 912], [692, 502, 0, -502], [-134, 510, -134, 0], [-2013, 186, 0, -186], [-370, 667, -370, 0], [0, -304, 459, -304], [-48, -930, -48, 0], [0, 104, -914, 104], [-718, 0, 718, 443], [-1986, -58, 0, 58], [0, 130, -59, 130], [740, -226, 740, 0], [-1000, 0, 1000, 628], [470, 50, 0, -50], [-1816, 0, 1816, -248], [0, -196, -881, -196], [14, -1074, 14, 0], [0, 312, 324, 312], [1169, 424, 0, -424], [-276, 0, 276, -756], [226, 0, -226, -620], [-208, 0, 208, -484], [-326, -1357, -326, 0], [790, 0, -790, 386], [0, -240, 706, -240], [-420, -391, -420, 0], [892, 0, -892, 454], [0, 184, 38, 184], [0, -216, -1510, -216], [1168, 372, 0, -372], [-360, -236, -360, 0], [-336, 1562, -336, 0], [-463, 580, 0, -580], [-372, 0, 372, 1296], [-24, 932, -24, 0], [0, 546, 1343, 546], [-696, 0, 696, -311], [-94, 1841, -94, 0], [-240, 0, 240, 594], [0, 260, 857, 260], [631, -84, 0, 84], [-2508, 140, 0, -140], [-1066, -16, -1066, 0], [1326, 772, 0, -772], [-678, 0, 678, -1114], [-1395, -608, 0, 608], [806, 0, -806, 1077], [158, 1288, 0, -1288], [-1000, 57, -1000, 0], [230, 0, -230, -944], [0, 880, -910, 880], [0, -506, 288, -506], [934, -688, 0, 688], [24, 0, -24, 1316], [-652, 608, -652, 0], [4, 136, 0, -136], [856, -781, 856, 0], [0, 290, -1312, 290], [1769, 110, 0, -110], [-1622, 580, -1622, 0], [0, -518, -1898, -518], [-168, 0, 168, -372], [-1272, -932, -1272, 0], [-1316, 0, 1316, 216], [0, 806, -1441, 806]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1800_v_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1800_3_v_m();".
// 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_1800_3_v_m(:prec:=4)
    chi := MakeCharacter_1800_v();
    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_1800_3_v_m();".
// 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_1800_3_v_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_v();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![25, -40, 32, -8, 1]>,<11,R![-20, -4, 1]>,<17,R![16, -32, 32, 8, 1]>],Snew);
    return Vf;
end function;