
// Make newform 2160.3.c.l in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2160_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_2160_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_2160_3_c_l();".
// 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_2160_3_c_l();".
// 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, 15, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [14, 19, 2, 1], [0, 11, 0, 1], [14, -19, 2, -1]];
    Rf_basisdens := [1, 4, 2, 4];
    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_2160_c();"
function MakeCharacter_2160_c()
    N := 2160;
    order := 2;
    char_gens := [271, 1621, 2081, 1297];
    v := [2, 2, 1, 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_2160_c_Hecke();"
function MakeCharacter_2160_c_Hecke(Kf)
    N := 2160;
    order := 2;
    char_gens := [271, 1621, 2081, 1297];
    char_values := [[1, 0, 0, 0], [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 := 3;
    raw_aps := [[0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 0, 0], [0, 0, -1, 0], [0, 2, 3, -2], [0, -3, -3, 3], [1, -1, 0, -1], [-3, -3, 0, -3], [7, -1, 0, -1], [0, 3, 9, -3], [-7, -6, 0, -6], [0, -6, -2, 6], [0, 1, 3, -1], [0, 9, 1, -9], [-14, -4, 0, -4], [-51, -6, 0, -6], [0, 11, 9, -11], [11, 3, 0, 3], [0, 6, -8, -6], [0, -15, -3, 15], [0, 12, 17, -12], [-3, -9, 0, -9], [67, -10, 0, -10], [0, 11, -9, -11], [0, -3, -28, 3], [0, -13, 6, 13], [0, 0, -4, 0], [6, 21, 0, 21], [-61, -9, 0, -9], [-138, 6, 0, 6], [0, -9, -16, 9], [0, 15, 6, -15], [129, 15, 0, 15], [-98, 6, 0, 6], [0, 4, -3, -4], [2, 3, 0, 3], [0, 33, 23, -33], [0, 30, 56, -30], [-57, -27, 0, -27], [-203, 14, 0, 14], [0, -31, -6, 31], [-13, -21, 0, -21], [0, 18, 24, -18], [0, 24, -19, -24], [125, -20, 0, -20], [138, -3, 0, -3], [69, -3, 0, -3], [0, -30, -62, 30], [-25, 1, 0, 1], [235, -15, 0, -15], [-338, 8, 0, 8], [0, -8, -60, 8], [19, -27, 0, -27], [0, -54, -30, 54], [201, -33, 0, -33], [202, 2, 0, 2], [0, 6, 54, -6], [-151, -12, 0, -12], [0, -3, 43, 3], [0, 57, 81, -57], [0, -3, -49, 3], [-327, -33, 0, -33], [0, 30, 0, -30], [0, 57, 75, -57], [0, -3, -34, 3], [229, 20, 0, 20], [-58, -36, 0, -36], [0, 45, 55, -45], [78, -9, 0, -9], [-109, 51, 0, 51], [-314, -10, 0, -10], [0, 18, 48, -18], [0, 72, 35, -72], [0, -66, 0, 66], [317, -15, 0, -15], [23, -59, 0, -59], [0, 44, 3, -44], [0, -81, -77, 81], [0, 74, 18, -74], [631, -6, 0, -6], [0, 13, 63, -13], [331, 39, 0, 39], [0, -19, -123, 19], [0, 24, 41, -24], [177, 36, 0, 36], [63, 57, 0, 57], [0, -93, -15, 93], [0, 69, 124, -69], [0, -27, -96, 27], [0, 27, 66, -27], [339, 12, 0, 12], [0, -113, -105, 113], [0, -69, -75, 69], [0, -33, -174, 33], [-603, 3, 0, 3], [-369, -57, 0, -57], [0, 9, -120, -9], [0, -1, 51, 1], [0, -81, 23, 81], [274, 42, 0, 42], [0, -81, -25, 81], [474, 87, 0, 87], [-514, 19, 0, 19], [0, 77, 111, -77], [317, 75, 0, 75], [0, 3, -71, -3], [603, -42, 0, -42], [153, 135, 0, 135], [0, 171, 51, -171], [263, -78, 0, -78], [0, -117, -35, 117], [0, -60, 26, 60], [49, -55, 0, -55], [326, 84, 0, 84], [-143, 108, 0, 108], [0, -98, -78, 98], [0, -111, -93, 111], [519, -45, 0, -45], [533, -14, 0, -14], [0, 8, 117, -8], [-286, 66, 0, 66], [0, 114, 33, -114], [310, -16, 0, -16], [-425, 89, 0, 89], [221, 93, 0, 93], [0, -23, 66, 23], [-318, 90, 0, 90], [0, -74, -234, 74], [0, -81, 30, 81], [0, 36, 52, -36], [637, 3, 0, 3], [-702, -48, 0, -48], [265, -30, 0, -30], [0, 120, 310, -120], [0, -57, -75, 57], [879, -30, 0, -30], [849, 15, 0, 15], [0, -93, -247, 93], [-59, -88, 0, -88], [0, -147, -207, 147], [-514, 66, 0, 66], [0, 116, 132, -116], [0, 120, 177, -120], [695, 61, 0, 61], [-150, 156, 0, 156], [0, 110, 216, -110], [0, -198, -92, 198], [681, 147, 0, 147], [-739, 45, 0, 45], [-1065, 27, 0, 27], [0, -243, -115, 243], [0, 51, 135, -51], [0, 21, -45, -21], [711, -27, 0, -27], [0, 54, 42, -54], [0, 15, 15, -15], [738, -105, 0, -105], [0, -87, -237, 87], [0, 21, -22, -21], [0, 121, 270, -121], [483, -126, 0, -126], [-170, -202, 0, -202], [0, -87, -98, 87], [0, -93, -36, 93], [1086, 72, 0, 72], [-361, 97, 0, 97], [-343, -180, 0, -180], [0, 33, 261, -33], [-497, -72, 0, -72], [945, -93, 0, -93], [0, 171, -78, -171], [-741, 33, 0, 33], [0, 161, -87, -161], [0, 18, 106, -18], [-647, -108, 0, -108], [0, -15, -45, 15], [973, -27, 0, -27], [0, 312, 153, -312], [0, -114, -95, 114], [-614, -72, 0, -72], [0, 156, 41, -156], [0, 43, -42, -43], [0, -78, -110, 78], [630, -102, 0, -102], [-721, -47, 0, -47], [0, 75, 102, -75], [0, -69, 49, 69], [0, 12, -130, -12], [631, -72, 0, -72], [0, 181, 327, -181], [0, 300, 168, -300], [-1061, -154, 0, -154], [-403, -153, 0, -153], [0, -243, 24, 243], [591, 117, 0, 117], [-711, 165, 0, 165], [-369, -126, 0, -126], [0, -36, -126, 36], [198, 30, 0, 30], [122, 118, 0, 118], [0, -162, -243, 162], [402, 15, 0, 15], [0, 234, -60, -234], [-769, -36, 0, -36], [0, 94, 123, -94], [198, -228, 0, -228], [606, 84, 0, 84], [835, 224, 0, 224], [0, -134, 36, 134], [-154, -36, 0, -36], [0, 78, -73, -78], [0, 15, 141, -15], [0, 105, 368, -105], [-18, -69, 0, -69], [0, 134, 90, -134], [-185, -240, 0, -240], [0, -39, -197, 39], [0, 152, -30, -152], [319, -199, 0, -199], [281, 115, 0, 115], [-894, 54, 0, 54], [325, 207, 0, 207], [0, 87, 285, -87], [0, 411, 125, -411], [-141, 300, 0, 300], [-429, -285, 0, -285], [-2359, -23, 0, -23], [0, 191, 369, -191], [0, -180, -152, 180], [0, 290, 162, -290], [0, 201, 505, -201], [-251, -147, 0, -147], [-1634, -36, 0, -36], [0, -90, 42, 90], [0, -123, 169, 123], [1031, 91, 0, 91], [-261, -219, 0, -219], [-839, -25, 0, -25], [0, 57, 408, -57], [0, 129, -141, -129], [954, -60, 0, -60], [1165, 147, 0, 147], [0, 75, 148, -75], [755, -99, 0, -99], [-1570, -56, 0, -56], [0, -30, 252, 30], [0, 21, -54, -21], [0, 300, 411, -300], [1166, -174, 0, -174], [823, -187, 0, -187], [0, 156, -180, -156], [0, -194, -360, 194], [-1025, 221, 0, 221], [-409, 30, 0, 30], [757, 8, 0, 8], [0, 99, -84, -99], [259, 201, 0, 201], [0, -165, -347, 165], [-355, 148, 0, 148], [0, 0, -157, 0], [0, 72, -153, -72], [179, -134, 0, -134], [-301, 45, 0, 45], [0, 54, 16, -54], [801, 69, 0, 69], [-706, -126, 0, -126], [0, 210, -6, -210], [0, 214, 474, -214], [0, 18, 256, -18], [-906, 156, 0, 156], [443, -291, 0, -291], [0, -24, -404, 24], [0, -54, 301, 54], [553, -336, 0, -336], [0, -318, 37, 318], [0, 120, 371, -120], [475, 92, 0, 92], [163, 129, 0, 129], [-985, 156, 0, 156], [0, -153, -591, 153], [1242, 66, 0, 66], [-863, -78, 0, -78], [247, 191, 0, 191], [-269, -33, 0, -33], [0, -330, -272, 330], [0, 59, -273, -59], [0, -279, -48, 279], [650, 175, 0, 175], [-955, 87, 0, 87], [0, -232, 144, 232], [0, 100, -180, -100], [-1389, -192, 0, -192], [-1002, 30, 0, 30], [0, -561, -204, 561], [0, -273, -487, 273], [0, -330, -222, 330], [1929, -126, 0, -126], [498, -195, 0, -195], [0, 109, -174, -109], [0, -21, 267, 21], [0, -105, -443, 105], [357, 24, 0, 24], [-526, -177, 0, -177]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2160_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2160_3_c_l();".
// 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_2160_3_c_l(:prec:=4)
    chi := MakeCharacter_2160_c();
    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_2160_3_c_l();".
// 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_2160_3_c_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2160_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![400, 0, 59, 0, 1]>,<17,R![-50, -3, 1]>],Snew);
    return Vf;
end function;