
// Make newform 60.3.c.a in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_60_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_60_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_60_3_c_a();".
// 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_60_3_c_a();".
// 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 := [16, -8, -8, 2, 3, 1, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [8, 0, -4, -5, 7, 0, -1, -1], [-24, -8, 16, -5, -5, -4, -1, 3], [-8, -8, 2, 3, 1, -2, -1, 1], [40, 8, -8, -5, 3, 4, -1, -5], [56, 24, -24, -5, 3, 4, -1, -5], [-12, -4, 4, 1, -1, -2, 1, 1], [-80, -8, 32, 15, -9, -12, 3, 7]];
    Rf_basisdens := [1, 8, 16, 4, 16, 16, 2, 8];
    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_60_c();"
function MakeCharacter_60_c()
    N := 60;
    order := 2;
    char_gens := [31, 41, 37];
    v := [1, 2, 2];
    // 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_60_c_Hecke();"
function MakeCharacter_60_c_Hecke(Kf)
    N := 60;
    order := 2;
    char_gens := [31, 41, 37];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 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, 1, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, -1, 0, 0, 0, 0, 0], [0, 1, 0, -1, 1, 1, 1, -1], [0, 0, 0, -2, 0, -2, 2, 0], [4, 3, 2, -5, -1, -3, -3, 1], [4, 1, -6, 1, 1, -5, -1, -1], [0, -3, 0, 1, -7, 3, -1, -5], [0, -3, 0, 1, 9, -9, -1, 7], [12, -4, -2, 12, 4, -4, 4, -4], [0, 11, 0, -1, -9, 5, 1, 5], [-24, -5, 14, 3, -1, 13, 5, 1], [-6, -6, 0, 10, 2, 6, 6, -2], [0, -8, 0, 8, 20, 0, -8, 0], [0, 11, 0, 3, -9, 5, -3, 9], [48, 6, 2, -10, -2, -6, -6, 2], [0, -4, 0, -6, -4, -6, 6, -4], [-10, -2, -4, 14, 6, -14, 2, -6], [0, -12, 0, -8, -8, -8, 8, -12], [0, 12, 0, -8, -20, 8, 8, -4], [-10, 10, -12, -6, 2, -26, -10, -2], [0, 9, 0, -11, 21, -25, 11, 23], [0, -28, 0, 0, 8, -8, 0, -20], [14, 6, 44, -10, -2, -6, -6, 2], [74, 0, -24, 16, 8, -24, 0, -8], [-44, -4, 6, -4, -4, 20, 4, 4], [0, 13, 0, 11, -19, 29, -11, -5], [0, 10, 0, 6, 6, 34, -6, -18], [22, 4, 20, -28, -12, 28, -4, 12], [-72, -19, 22, 13, -3, 47, 19, 3], [0, 21, 0, 11, -3, 13, -11, 19], [0, -26, 0, 16, 6, -12, -16, 2], [-64, 7, 22, -25, -9, 13, -7, 9], [0, -13, 0, 3, -57, -31, -3, 21], [-80, -4, -6, 12, 4, -4, 4, -4], [0, -33, 0, 15, 11, -19, -15, 1], [20, 9, 42, 1, 5, -33, -9, -5], [0, 28, 0, -8, 16, 48, 8, -28], [0, -43, 0, 9, -7, -33, -9, -1], [-56, -16, -14, 0, -8, 56, 16, 8], [0, -6, 0, 0, -62, 44, 0, -50], [-82, 20, 60, -44, -12, -4, -20, 12], [0, 4, 0, -8, 60, -16, 8, 12], [-154, 6, -44, 6, 6, -30, -6, -6], [160, 6, 2, 6, 6, -30, -6, -6], [0, -37, 0, -13, 31, -7, 13, -43], [0, -17, 0, 7, 107, -3, -7, -7], [0, 27, 0, -31, -69, -25, 31, 21], [0, -12, 0, -28, 48, -52, 28, 12], [-54, -34, 72, 14, -10, 98, 34, 10], [116, 11, -14, 11, 11, -55, -11, -11], [0, -18, 0, 34, 78, 6, -34, 10], [106, 28, -104, -4, 12, -92, -28, -12], [0, -14, 0, 20, 26, -56, -20, 62], [48, -35, 30, 61, 13, 31, 35, -13], [0, -73, 0, -5, -125, -19, 5, -59], [-124, 20, -74, -28, -4, -28, -20, 4], [0, 19, 0, 27, -65, 49, -27, -3], [-24, 21, -42, -19, 1, -45, -21, -1], [-114, -30, 44, 34, 2, 54, 30, -2], [0, 40, 0, 36, 84, 60, -36, 16], [-48, -6, -62, 26, 10, -18, 6, -10], [0, -10, 0, 38, -86, 82, -38, -54], [0, -34, 0, 2, -106, 38, -2, -70], [182, -38, -60, 90, 26, -2, 38, -26], [120, -46, 10, 82, 18, 38, 46, -18], [0, 115, 0, -17, -49, 13, 17, 85], [78, 2, 12, -14, -6, 14, -2, 6], [0, 30, 0, -34, -6, -14, 34, 10], [198, 2, 44, 50, 26, -82, -2, -26], [-36, 35, 26, -93, -29, 17, -35, 29], [0, -32, 0, -32, 248, 8, 32, -72], [0, -9, 0, -19, -73, -29, 19, 1], [60, 65, -110, -103, -19, -73, -65, 19], [0, 81, 0, -39, -115, 35, 39, 7], [0, -5, 0, 51, -65, 53, -51, -7], [-48, 72, 10, -120, -24, -72, -72, 24], [-304, -17, 102, 7, -5, 49, 17, 5], [-26, 44, 44, -36, 4, -100, -44, -4], [2, 32, -112, 0, 16, -112, -32, -16], [0, -18, 0, -32, -210, -4, 32, -46], [-38, -26, -152, 54, 14, 10, 26, -14], [0, 64, 0, -56, -144, 0, 56, 8], [78, 10, 28, -70, -30, 70, -10, 30], [0, -65, 0, 79, 211, -3, -79, 17], [0, -44, 0, 20, 216, 44, -20, -68], [-258, -92, 100, 68, -12, 220, 92, 12], [146, -40, -208, 136, 48, -64, 40, -48], [32, 24, 58, -24, 0, -48, -24, 0], [0, -7, 0, 67, -167, -19, -67, 79], [0, 14, 0, 34, -86, 86, -34, -38], [0, 52, 0, -8, -20, -8, 8, 52], [0, 59, 0, -59, 91, -61, 59, 61], [0, 164, 0, 14, 28, 158, -14, 20], [0, -29, 0, 39, -345, 117, -39, -107], [0, 43, 0, -5, -1, -83, 5, 121], [-12, -72, 70, 56, -8, 168, 72, 8], [-122, -36, -36, 28, -4, 84, 36, 4], [0, 46, 0, 2, 154, -98, -2, 146], [46, 36, 76, -124, -44, 60, -36, 44], [0, -28, 0, 28, -72, 28, -28, -28], [-8, 12, -206, 60, 36, -132, -12, -36], [0, -102, 0, -14, -18, -34, 14, -82], [718, -48, -12, 96, 24, 24, 48, -24], [0, -169, 0, -77, -93, -167, 77, -79], [618, 92, 168, -116, -12, -148, -92, 12], [0, -26, 0, 50, 194, -90, -50, 114], [272, -39, -114, 185, 73, -141, 39, -73], [0, 16, 0, -120, 168, -96, 120, -8], [-22, 128, -24, -288, -80, -16, -128, 80], [0, -21, 0, 45, -269, -29, -45, 53], [-152, -93, -146, 91, -1, 189, 93, 1], [-516, 27, -86, -69, -21, 9, -27, 21], [0, 115, 0, -5, 55, 185, 5, -75], [0, 93, 0, -47, -143, 27, 47, 19], [194, 42, -216, -22, 10, -114, -42, -10], [0, 104, 0, -44, -68, 244, 44, -184], [0, 101, 0, 77, 273, 123, -77, 55], [160, 12, -102, 76, 44, -156, -12, -44], [0, -108, 0, -82, -76, -178, 82, -12], [406, 10, -68, -38, -14, 22, -10, 14], [118, -98, 356, 142, 22, 130, 98, -22], [768, 92, 74, -100, -4, -172, -92, 4], [0, 98, 0, -58, 22, 82, 58, -42], [0, -81, 0, 155, 139, 97, -155, -23], [116, 52, -58, -236, -92, 172, -52, 92], [-142, 114, -176, -222, -54, -66, -114, 54], [0, -34, 0, 22, 102, -158, -22, 146], [0, -25, 0, 73, 199, -1, -73, 49], [-320, -3, -242, -11, -7, 27, 3, 7], [0, -121, 0, 107, 171, -159, -107, 145], [0, 13, 0, 85, -447, 147, -85, -49], [0, -117, 0, 47, 391, -219, -47, 149], [56, -39, -394, 145, 53, -81, 39, -53], [206, 36, 148, 68, 52, -228, -36, -52], [-318, 32, 304, -32, 0, -64, -32, 0], [-776, -38, 186, -6, -22, 142, 38, 22], [0, -42, 0, -86, 106, -170, 86, 42], [600, -28, -46, -44, -36, 164, 28, 36], [850, 146, 312, -206, -30, -202, -146, 30], [0, -9, 0, 103, -109, -115, -103, 209], [-156, 80, 182, -96, -8, -136, -80, 8], [0, 109, 0, 103, 69, 49, -103, 163], [0, -28, 0, 76, 240, 180, -76, -132], [118, -108, 52, 148, 20, 156, 108, -20], [0, 44, 0, 68, 292, 164, -68, -52], [56, -73, 46, -49, -61, 329, 73, 61], [-836, -35, 2, -35, -35, 175, 35, 35], [0, -243, 0, 69, 137, -121, -69, -53], [0, -55, 0, 13, -43, 171, -13, -213], [-356, -47, -30, 105, 29, 7, 47, -29], [-130, -174, 76, 34, -70, 558, 174, 70], [0, -56, 0, -20, 28, -164, 20, 88], [0, 17, 0, -195, 261, -293, 195, 115], [0, 238, 0, -26, 26, 186, 26, 26], [0, -66, 0, 30, 342, 34, -30, -70], [0, -153, 0, -13, -133, -207, 13, 41], [-194, -8, -460, -40, -24, 88, 8, 24], [602, 104, -8, -88, 8, -232, -104, -8], [-1184, -28, 10, 100, 36, -52, 28, -36], [0, -50, 0, -26, -534, -86, 26, 10], [216, 191, 254, -385, -97, -91, -191, 97], [0, -133, 0, -7, 115, -49, 7, -91], [0, 174, 0, -144, -682, -36, 144, 66], [-900, -167, 194, 25, -71, 547, 167, 71], [0, -51, 0, 29, 433, -133, -29, 111], [0, -111, 0, -79, 245, -61, 79, -129], [-396, 185, -294, -255, -35, -265, -185, 35]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_60_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_60_3_c_a();".
// 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_60_3_c_a(:prec:=8)
    chi := MakeCharacter_60_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(997) - 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_60_3_c_a();".
// 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_60_3_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_60_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;