
// Make newform 1800.3.v.n in Magma, downloaded from the LMFDB on 25 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_n();".
// 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_n();".
// 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, 0, 1, 0], [0, 3, 0, 1], [0, 3, 0, -1]];
    Rf_basisdens := [1, 3, 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, -1, 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 := 3;
    raw_aps := [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [3, -3, 1, -1], [4, 0, 0, -1], [-12, -12, 1, 1], [-6, 6, -7, 7], [0, -2, 6, 0], [-14, -14, -3, -3], [0, 22, 9, 0], [-20, 0, 0, -10], [-28, 28, -3, 3], [14, 0, 0, 14], [2, 2, 14, 14], [-4, 4, -19, 19], [-30, -30, -10, -10], [0, 4, -21, 0], [-6, 0, 0, -22], [2, -2, 34, -34], [-68, 0, 0, -8], [-27, -27, -20, -20], [0, 112, -6, 0], [68, 68, -11, -11], [0, -62, 4, 0], [37, -37, 0, 0], [-38, 0, 0, 23], [-31, -31, 17, 17], [-40, 40, 11, -11], [0, -14, -34, 0], [-36, -36, 27, 27], [-93, 93, -11, 11], [-104, 0, 0, 7], [24, -24, 39, -39], [0, -82, 24, 0], [0, 42, 39, 0], [-262, 0, 0, -12], [-38, 38, -37, 37], [0, 0, -48, -48], [-90, 90, 23, -23], [16, 16, -5, -5], [0, 16, 25, 0], [-50, 0, 0, 86], [-100, 0, 0, -62], [-95, -95, -32, -32], [42, -42, 18, -18], [0, 138, 68, 0], [38, 0, 0, 96], [-231, -231, 23, 23], [-156, 156, -32, 32], [0, 138, -60, 0], [-146, -146, 39, 39], [0, -24, 124, 0], [-64, 0, 0, -136], [-120, 0, 0, 27], [224, -224, -35, 35], [-146, -146, 7, 7], [0, -2, -45, 0], [246, 0, 0, -32], [232, -232, -27, 27], [18, 0, 0, 130], [166, 166, -76, -76], [-178, -178, -28, -28], [-238, 238, 52, -52], [76, 0, 0, 32], [63, 63, 80, 80], [-20, 20, -7, 7], [-238, 0, 0, -106], [-69, 69, 84, -84], [-216, 216, 102, -102], [0, 158, -34, 0], [46, 46, -33, -33], [0, -76, -22, 0], [187, -187, 11, -11], [-90, -90, 49, 49], [0, -150, -112, 0], [372, 372, -19, -19], [0, -534, -67, 0], [58, -58, 129, -129], [122, 0, 0, 96], [0, -12, 32, 0], [0, -40, -153, 0], [410, 0, 0, 144], [-232, 0, 0, 86], [-137, -137, -62, -62], [0, -322, -36, 0], [8, 8, 104, 104], [0, -562, -114, 0], [161, -161, 56, -56], [110, 0, 0, -63], [29, 29, 67, 67], [468, -468, 37, -37], [0, -172, 116, 0], [15, -15, -11, 11], [52, 0, 0, 357], [0, -190, 50, 0], [-276, -276, 39, 39], [0, 546, 153, 0], [270, 0, 0, 26], [258, 258, 50, 50], [230, 0, 0, -30], [42, -42, 12, -12], [366, -366, 158, -158], [532, 532, -70, -70], [0, -26, -188, 0], [158, 0, 0, 118], [-21, 21, -110, 110], [364, -364, -75, 75], [-52, -52, -11, -11], [0, 64, -182, 0], [-26, 0, 0, -84], [-65, 65, 13, -13], [78, 78, -75, -75], [-402, 402, -147, 147], [0, 258, 72, 0], [400, 0, 0, 170], [742, 0, 0, 80], [40, 40, -42, -42], [-368, 368, -115, 115], [72, 72, 91, 91], [0, 444, 291, 0], [610, 0, 0, 122], [-143, -143, -282, -282], [248, -248, 183, -183], [36, 36, 49, 49], [966, 0, 0, -78], [-562, 0, 0, 115], [0, -378, -224, 0], [0, -772, -68, 0], [-177, 177, 93, -93], [64, 64, 237, 237], [0, 266, 374, 0], [-240, -240, -135, -135], [-60, 0, 0, 98], [-168, 168, -145, 145], [-94, 0, 0, -334], [0, -94, -44, 0], [-356, -356, 85, 85], [330, -330, -48, 48], [-72, 72, 23, -23], [0, -758, 24, 0], [370, 0, 0, -188], [-410, 0, 0, 65], [-235, -235, 107, 107], [732, -732, 58, -58], [0, -14, -638, 0], [0, -116, -346, 0], [150, 150, -165, -165], [-6, 6, 283, -283], [0, 766, -212, 0], [-882, -882, -69, -69], [222, -222, 103, -103], [-1202, 0, 0, 184], [324, 324, 140, 140], [-326, 326, -23, 23], [-652, 652, -30, 30], [32, 0, 0, -50], [0, 404, 434, 0], [0, 638, 110, 0], [331, -331, 200, -200], [-546, 0, 0, 495], [460, -460, -236, 236], [-240, -240, -9, -9], [-477, 477, 327, -327], [-1192, 0, 0, -183], [-906, 906, -59, 59], [144, 144, 29, 29], [-398, 0, 0, -344], [-456, 456, 181, -181], [0, 308, -208, 0], [48, 48, 101, 101], [0, 716, -91, 0], [-1742, 0, 0, 104], [92, 0, 0, 28], [767, 767, 230, 230], [0, -264, -210, 0], [0, 1190, -120, 0], [990, 0, 0, -288], [202, 0, 0, -137], [-255, -255, 373, 373], [0, 598, 556, 0], [-85, 85, 187, -187], [1244, 0, 0, 33], [-246, -246, -247, -247], [832, -832, -37, 37], [-440, -440, -337, -337], [0, 446, 309, 0], [70, -70, 71, -71], [-624, -624, -112, -112], [0, -1018, -184, 0], [728, 0, 0, 534], [-763, -763, 298, 298], [-28, -28, -288, -288], [-546, 0, 0, -304], [-518, 0, 0, -123], [896, -896, 13, -13], [48, 48, -449, -449], [76, 0, 0, 260], [532, 532, -363, -363], [-408, 408, -335, 335], [-1332, -1332, -65, -65], [0, 466, -69, 0], [-1268, 0, 0, -322], [-252, 252, -95, 95], [0, 340, 440, 0], [0, 312, 629, 0], [18, -18, -316, 316], [0, 872, -590, 0], [-288, -288, 414, 414], [0, -1206, 488, 0], [-246, 0, 0, -346], [-1489, 1489, -120, 120], [806, 0, 0, -121], [-741, -741, -77, -77], [-1188, 1188, -198, 198], [0, -352, -166, 0], [-80, 0, 0, 852], [-11, 11, -559, 559], [-1046, 0, 0, -424], [412, -412, 75, -75], [466, 466, 216, 216], [374, 0, 0, 32], [0, 458, -244, 0], [0, 554, 478, 0], [-189, -189, 141, 141], [1212, -1212, 135, -135], [0, -50, 488, 0], [-352, -352, -7, -7], [0, -1416, 208, 0], [-653, 653, -305, 305], [-480, 0, 0, 545], [-600, -600, 337, 337], [0, -674, -128, 0], [246, 0, 0, 28], [486, 0, 0, -110], [-354, -354, -398, -398], [14, -14, 641, -641], [0, 448, 360, 0], [414, 414, -280, -280], [0, 192, 691, 0], [-760, 0, 0, -424], [-12, -12, -838, -838], [-506, 0, 0, 366], [-863, -863, -369, -369], [0, -1074, -34, 0], [366, 366, 369, 369], [0, -220, -670, 0], [553, -553, -515, 515], [996, 0, 0, -615], [0, -1442, -618, 0], [-10, -10, -287, -287], [-526, 526, 197, -197], [2, 0, 0, -648], [-550, 550, -377, 377], [0, 140, -948, 0], [-146, -146, 552, 552], [0, -380, -831, 0], [826, 0, 0, 78], [200, -200, 492, -492], [1338, -1338, 28, -28], [33, -33, -534, 534], [-1121, -1121, 421, 421], [-1364, 1364, 176, -176], [0, -754, -20, 0], [996, 996, 59, 59], [-1364, 1364, 39, -39], [0, 238, 866, 0], [0, -1674, 137, 0], [470, 0, 0, -850], [906, 906, -456, -456], [716, 716, -559, -559], [-1810, 0, 0, -272], [-1362, 1362, 292, -292], [-867, -867, 386, 386], [0, 1088, 274, 0], [835, -835, 302, -302], [353, 353, -191, -191], [608, -608, -350, 350], [0, 442, -350, 0], [-576, 0, 0, 732], [1944, 0, 0, 57], [-1426, -1426, 123, 123], [1134, 0, 0, 116], [-416, 416, -275, 275], [1582, 0, 0, -420], [-768, 768, -462, 462], [-32, 0, 0, -578], [-947, -947, -58, -58], [320, -320, 7, -7], [0, -494, 496, 0], [0, -1790, 498, 0], [-742, 0, 0, 27], [240, -240, -509, 509], [570, 570, -187, -187], [2624, 0, 0, 59], [2208, 2208, 25, 25], [0, -290, 477, 0], [-964, 0, 0, -998], [-432, -432, 275, 275], [0, -256, -1295, 0], [890, -890, 498, -498], [-227, -227, 536, 536], [996, -996, -365, 365], [0, -754, 876, 0]];
    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_n();".
// 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_n(: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_n();".
// 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_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_v();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![36, -72, 72, -12, 1]>,<11,R![10, -8, 1]>,<17,R![266256, -12384, 288, 24, 1]>],Snew);
    return Vf;
end function;