
// Make newform 1200.3.e.m in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1200_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1200_e_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_1200_3_e_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_1200_3_e_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 := [121, 0, 11, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 44, 0, 2], [11, 0, 2, 0], [0, 0, 0, -6]];
    Rf_basisdens := [1, 11, 11, 11];
    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_1200_e();"
function MakeCharacter_1200_e()
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    v := [1, 2, 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_1200_e_Hecke();"
function MakeCharacter_1200_e_Hecke(Kf)
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    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, 1, 0], [0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0], [-12, 0, 0, -1], [0, -1, -1, 0], [0, 1, 12, 0], [-24, 0, 0, 1], [0, -1, -15, 0], [-22, 0, 0, 2], [-6, 0, 0, 3], [0, -1, 21, 0], [0, -4, 6, 0], [30, 0, 0, 3], [0, 4, -30, 0], [-37, 0, 0, -2], [0, -3, -43, 0], [0, 1, -6, 0], [70, 0, 0, -2], [0, 4, -28, 0], [0, 0, 42, 0], [-96, 0, 0, 0], [-35, 0, 0, -4], [-114, 0, 0, -1], [0, 2, -20, 0], [0, 11, 18, 0], [-95, 0, 0, 6], [108, 0, 0, -4], [0, 6, -48, 0], [0, 1, 102, 0], [-78, 0, 0, 6], [0, -10, -32, 0], [-42, 0, 0, -6], [0, -1, -97, 0], [-61, 0, 0, -6], [0, -3, -5, 0], [0, -7, 126, 0], [-96, 0, 0, -9], [0, 22, -42, 0], [-11, 0, 0, 12], [0, -21, -24, 0], [71, 0, 0, 10], [-222, 0, 0, 6], [0, 21, 19, 0], [0, 3, 43, 0], [0, 5, -39, 0], [0, 1, 138, 0], [13, 0, 0, -18], [-30, 0, 0, 11], [0, -19, -90, 0], [193, 0, 0, 0], [0, -2, 216, 0], [-72, 0, 0, -10], [0, 19, 54, 0], [204, 0, 0, 9], [0, 22, -136, 0], [181, 0, 0, 0], [0, 0, 0, 11], [0, 19, 99, 0], [-402, 0, 0, -4], [0, 31, -81, 0], [0, 34, -18, 0], [-421, 0, 0, -6], [-84, 0, 0, -14], [0, -22, 40, 0], [265, 0, 0, -18], [0, 0, 126, 0], [158, 0, 0, -4], [-96, 0, 0, 7], [0, 17, -78, 0], [0, -3, 163, 0], [215, 0, 0, 16], [0, 45, 113, 0], [0, 2, -168, 0], [414, 0, 0, 1], [431, 0, 0, 12], [-294, 0, 0, 21], [145, 0, 0, -30], [0, -3, 78, 0], [190, 0, 0, -2], [0, -31, 60, 0], [-37, 0, 0, -30], [0, -13, -15, 0], [0, -14, 60, 0], [744, 0, 0, 2], [-26, 0, 0, 0], [330, 0, 0, -7], [0, 14, -344, 0], [0, -35, 72, 0], [0, 36, -54, 0], [0, -9, -29, 0], [0, -48, 192, 0], [0, -11, 231, 0], [0, 3, -162, 0], [-318, 0, 0, -2], [-288, 0, 0, -25], [0, 5, -13, 0], [-23, 0, 0, 20], [0, 50, -20, 0], [-78, 0, 0, -4], [0, 23, 72, 0], [96, 0, 0, -9], [0, 59, 215, 0], [-265, 0, 0, 16], [0, 63, -30, 0], [246, 0, 0, -43], [0, 30, -216, 0], [47, 0, 0, 6], [0, 8, 124, 0], [590, 0, 0, -16], [18, 0, 0, -7], [0, 23, 35, 0], [0, -3, -139, 0], [-552, 0, 0, -22], [0, 6, 24, 0], [0, 8, -228, 0], [-702, 0, 0, -16], [0, -3, 426, 0], [-106, 0, 0, 8], [242, 0, 0, 38], [-612, 0, 0, 7], [0, 20, 504, 0], [0, -54, -396, 0], [612, 0, 0, 21], [-647, 0, 0, -10], [0, 5, 108, 0], [0, -55, -87, 0], [538, 0, 0, -12], [0, 24, -204, 0], [0, 16, 300, 0], [0, -74, 56, 0], [-239, 0, 0, 2], [12, 0, 0, 8], [-697, 0, 0, 6], [150, 0, 0, -39], [0, -31, 263, 0], [-432, 0, 0, 26], [-810, 0, 0, 11], [0, 13, 15, 0], [30, 0, 0, 28], [0, -15, 365, 0], [0, 7, -798, 0], [166, 0, 0, -20], [0, 65, -192, 0], [-337, 0, 0, -42], [336, 0, 0, -46], [0, 14, -500, 0], [0, -30, -276, 0], [-853, 0, 0, -2], [-756, 0, 0, 46], [0, -41, -383, 0], [0, 64, -558, 0], [0, 28, 212, 0], [0, -4, -270, 0], [0, 1, -909, 0], [12, 0, 0, 25], [455, 0, 0, -26], [918, 0, 0, 28], [0, 21, -276, 0], [792, 0, 0, -28], [0, 112, -172, 0], [0, -14, -630, 0], [-162, 0, 0, -14], [0, 80, 156, 0], [0, 25, 793, 0], [-1018, 0, 0, -12], [-167, 0, 0, -64], [-426, 0, 0, 46], [0, -9, -420, 0], [-817, 0, 0, 48], [0, 62, 318, 0], [-611, 0, 0, -34], [0, 51, 79, 0], [-156, 0, 0, 22], [0, -35, -213, 0], [792, 0, 0, 23], [0, 3, -247, 0], [83, 0, 0, 6], [0, -51, 857, 0], [0, 44, -480, 0], [589, 0, 0, 36], [1578, 0, 0, 12], [0, 0, -570, 0], [-90, 0, 0, 32], [-395, 0, 0, 12], [0, -51, 463, 0], [997, 0, 0, 38], [0, -79, 480, 0], [-779, 0, 0, 62], [0, -19, -126, 0], [0, -101, 265, 0], [360, 0, 0, -65], [0, 67, 660, 0], [366, 0, 0, -48], [434, 0, 0, 62], [-1502, 0, 0, 28], [1662, 0, 0, -2], [0, -69, 456, 0], [-342, 0, 0, 15], [0, 118, 68, 0], [2086, 0, 0, 4], [-242, 0, 0, 10], [0, 92, 684, 0], [-312, 0, 0, 49], [0, -91, 239, 0], [0, 17, -456, 0], [912, 0, 0, 2], [0, 171, -319, 0], [179, 0, 0, -96], [330, 0, 0, -76], [0, -3, 1121, 0], [0, 104, -324, 0], [0, -92, 30, 0], [842, 0, 0, 38], [0, 95, 369, 0], [768, 0, 0, 17], [0, -19, -102, 0], [-156, 0, 0, -75], [-155, 0, 0, -28], [0, 1, 39, 0], [978, 0, 0, 16], [0, 138, -120, 0], [0, 139, 390, 0], [671, 0, 0, 60], [1380, 0, 0, 19], [0, -14, 1242, 0], [0, -63, -725, 0], [0, 75, -684, 0], [-839, 0, 0, -64], [0, -114, 24, 0], [0, -29, 1359, 0], [30, 0, 0, 28], [0, -34, 1096, 0], [0, -20, 312, 0], [70, 0, 0, 58], [-1770, 0, 0, -9], [0, 60, -186, 0], [0, -73, -222, 0], [0, -99, -336, 0], [0, -111, -631, 0], [0, -163, 359, 0], [1163, 0, 0, -90], [-1650, 0, 0, 4], [0, 16, 186, 0], [0, -151, -169, 0], [0, -1, 204, 0], [0, 59, -1203, 0], [0, 128, 234, 0], [-470, 0, 0, 84], [-1236, 0, 0, 31], [0, -118, -648, 0], [-203, 0, 0, -42], [192, 0, 0, 29], [0, 212, 108, 0], [-335, 0, 0, 26], [0, 186, 336, 0], [954, 0, 0, 57], [1238, 0, 0, 48], [0, -143, 709, 0], [0, -171, 12, 0], [-62, 0, 0, 4], [563, 0, 0, -8], [-2190, 0, 0, 0], [0, -6, 1260, 0], [-1626, 0, 0, 50], [-1068, 0, 0, 38], [0, 96, -36, 0], [6, 0, 0, 14], [-205, 0, 0, 52], [0, -82, -236, 0], [-1862, 0, 0, 48], [0, -69, 77, 0], [-1679, 0, 0, 24], [0, 31, -1019, 0], [0, -156, 762, 0], [35, 0, 0, -60], [-1837, 0, 0, -42], [0, 38, -780, 0], [0, 11, 462, 0], [0, -36, 564, 0], [0, 131, -132, 0], [275, 0, 0, 90], [0, 123, -857, 0], [0, 128, 750, 0], [2833, 0, 0, 0], [-3366, 0, 0, -1], [0, -70, 112, 0], [-54, 0, 0, 147], [1470, 0, 0, 2], [0, 198, 768, 0], [984, 0, 0, -22], [0, 82, -36, 0], [2843, 0, 0, -6], [42, 0, 0, 47], [0, 163, -851, 0], [642, 0, 0, -53], [0, -129, -996, 0], [0, 28, 1052, 0], [-1114, 0, 0, -4], [-588, 0, 0, 32], [0, 17, -303, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1200_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1200_3_e_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_1200_3_e_m(:prec:=4)
    chi := MakeCharacter_1200_e();
    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_1200_3_e_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_1200_3_e_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1200_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![16641, 0, 270, 0, 1]>,<11,R![132, 0, 1]>,<13,R![-1, 1]>],Snew);
    return Vf;
end function;