
// Make newform 414.3.b.c in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_414_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_414_b_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_414_3_b_c();".
// 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_414_3_b_c();".
// 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 := [1, 0, 16, 0, 20, 0, 8, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [2, 0, 4, 0, 1, 0, 0, 0], [0, 4, 0, 5, 0, 1, 0, 0], [0, 6, 0, 5, 0, 1, 0, 0], [2, 0, -7, 0, -6, 0, -1, 0], [2, 0, 9, 0, 6, 0, 1, 0], [0, 5, 0, 13, 0, 7, 0, 1], [0, 11, 0, 15, 0, 7, 0, 1]];
    Rf_basisdens := [1, 1, 1, 1, 1, 1, 1, 1];
    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_414_b();"
function MakeCharacter_414_b()
    N := 414;
    order := 2;
    char_gens := [47, 235];
    v := [2, 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_414_b_Hecke();"
function MakeCharacter_414_b_Hecke(Kf)
    N := 414;
    order := 2;
    char_gens := [47, 235];
    char_values := [[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, 0, 0, 0, 0], [0, 0, 1, -2, 0, 0, 1, 0], [0, 0, 2, 3, 0, 0, -1, 2], [0, 0, 4, 2, 0, 0, 0, -2], [2, 2, 0, 0, 3, -2, 0, 0], [0, 0, 0, 3, 0, 0, 4, -6], [0, 0, 3, -4, 0, 0, 7, 11], [-2, 3, 7, 5, -4, -5, -8, 5], [18, -4, 0, 0, -6, 8, 0, 0], [-16, 8, 0, 0, -4, 6, 0, 0], [0, 0, 8, -4, 0, 0, 10, -14], [2, 20, 0, 0, 4, 0, 0, 0], [0, 0, -6, -19, 0, 0, 9, -14], [14, 16, 0, 0, 2, -1, 0, 0], [0, 0, 4, 3, 0, 0, 36, 10], [-10, 8, 0, 0, -22, 7, 0, 0], [0, 0, -36, 12, 0, 0, 14, -26], [0, 0, 13, -16, 0, 0, 29, 5], [-4, -18, 0, 0, -16, -14, 0, 0], [8, 0, 0, 0, -16, -36, 0, 0], [0, 0, 3, -4, 0, 0, -13, 19], [0, 0, 18, 0, 0, 0, -20, -8], [0, 0, -27, -50, 0, 0, 29, -4], [0, 0, -50, -4, 0, 0, 2, -24], [-58, -28, 0, 0, 20, 24, 0, 0], [0, 0, -19, 20, 0, 0, -7, -23], [0, 0, -68, 30, 0, 0, -24, -62], [0, 0, -44, 10, 0, 0, -22, -50], [0, 0, 7, -54, 0, 0, 19, 40], [-12, -20, 0, 0, -44, 66, 0, 0], [-20, -62, 0, 0, 20, -62, 0, 0], [0, 0, -16, 65, 0, 0, -40, 42], [64, -56, 0, 0, 28, 58, 0, 0], [0, 0, -36, 57, 0, 0, -56, -14], [-28, -48, 0, 0, 60, 4, 0, 0], [0, 0, 54, -38, 0, 0, 24, -10], [-20, 44, 0, 0, 52, 76, 0, 0], [96, -68, 0, 0, -44, -28, 0, 0], [70, -12, 0, 0, 82, -4, 0, 0], [126, 64, 0, 0, 58, -41, 0, 0], [0, 0, -30, -60, 0, 0, 52, 62], [0, 0, 64, -6, 0, 0, -86, 0], [30, 10, 0, 0, -113, 58, 0, 0], [30, 24, 0, 0, -78, 8, 0, 0], [0, 0, -2, 43, 0, 0, -129, -6], [148, 76, 0, 0, -28, 94, 0, 0], [24, -4, 0, 0, 8, -170, 0, 0], [0, 0, 96, 40, 0, 0, -22, 42], [0, 0, 56, 42, 0, 0, 42, 6], [-178, 20, 0, 0, -42, -64, 0, 0], [-80, 20, 0, 0, 140, 12, 0, 0], [0, 0, -92, 74, 0, 0, 20, 4], [0, 0, -24, -80, 0, 0, 54, -130], [190, -52, 0, 0, 40, 20, 0, 0], [0, 0, 64, -18, 0, 0, 114, 136], [-74, 16, 0, 0, -6, -28, 0, 0], [204, -120, 0, 0, -80, -110, 0, 0], [26, -88, 0, 0, 56, 40, 0, 0], [0, 0, 28, -61, 0, 0, 4, -130], [0, 0, 83, 108, 0, 0, 55, 43], [0, 0, 49, 82, 0, 0, 33, -72], [-104, -84, 0, 0, 20, 118, 0, 0], [58, -40, 0, 0, 102, 237, 0, 0], [0, 0, -54, -146, 0, 0, -6, -96], [278, 72, 0, 0, 96, -128, 0, 0], [-80, -84, 0, 0, -92, 44, 0, 0], [0, 0, 56, -86, 0, 0, 152, -36], [290, 48, 0, 0, -18, 69, 0, 0], [-18, 10, 0, 0, -69, 230, 0, 0], [-162, 88, 0, 0, 12, 84, 0, 0], [0, 0, 46, -68, 0, 0, 98, 134], [0, 0, -131, -52, 0, 0, -231, -87], [0, 0, 234, -66, 0, 0, 104, 170], [0, 0, 222, 43, 0, 0, -229, 146], [0, 0, 172, 46, 0, 0, -66, 160], [0, 0, -59, 190, 0, 0, -63, 20], [-50, -96, 0, 0, 52, -88, 0, 0], [0, 0, -148, 61, 0, 0, -104, -98], [46, 70, 0, 0, -55, -234, 0, 0], [0, 0, -38, -40, 0, 0, -164, 92], [0, 0, -190, 40, 0, 0, -168, 34], [0, 0, 18, -250, 0, 0, 84, 22], [0, 0, -218, -82, 0, 0, 262, -132], [76, -132, 0, 0, 72, -26, 0, 0], [160, -28, 0, 0, -120, -96, 0, 0], [-18, -272, 0, 0, 22, 8, 0, 0], [0, 0, -86, -240, 0, 0, 86, 132], [-202, -60, 0, 0, -60, -60, 0, 0], [-24, 296, 0, 0, -28, -104, 0, 0], [0, 0, -316, 176, 0, 0, -130, -158], [0, 0, -84, -252, 0, 0, 44, -152], [0, 80, 0, 0, -44, 276, 0, 0], [-570, 88, 0, 0, 10, 163, 0, 0], [-44, -140, 0, 0, -28, -232, 0, 0], [0, 0, -198, 70, 0, 0, 36, -254], [-374, -152, 0, 0, 96, -120, 0, 0], [0, 0, -283, -198, 0, 0, 133, -108], [0, 0, -3, -328, 0, 0, 133, 133], [198, 166, 0, 0, 21, 130, 0, 0], [-68, 24, 0, 0, 48, -262, 0, 0], [0, 0, 97, 250, 0, 0, 13, 180], [0, 0, 98, 26, 0, 0, 50, -44], [0, 0, 99, -102, 0, 0, 151, 256], [0, 0, 106, -281, 0, 0, 79, -246], [-30, 54, 0, 0, -111, 126, 0, 0], [-28, -122, 0, 0, -84, -174, 0, 0], [274, 176, 0, 0, -10, -236, 0, 0], [136, 228, 0, 0, 156, -120, 0, 0], [-262, 102, 0, 0, -83, -482, 0, 0], [-372, 8, 0, 0, 68, -240, 0, 0], [0, 0, 130, -126, 0, 0, 28, -26], [0, 0, 87, 2, 0, 0, -33, 180], [0, 0, -162, 273, 0, 0, -131, 34], [0, 0, -146, 9, 0, 0, 9, 10], [0, 0, -128, 83, 0, 0, 136, -18], [0, 0, 6, -251, 0, 0, 353, 186], [-230, -264, 0, 0, -10, -67, 0, 0], [42, 336, 0, 0, -118, 256, 0, 0], [0, 0, 38, 126, 0, 0, 46, -100], [0, 0, 204, -64, 0, 0, -198, 62], [590, -118, 0, 0, -85, -430, 0, 0], [0, 0, -4, 167, 0, 0, -404, -110], [-76, 278, 0, 0, -60, -282, 0, 0], [-420, -72, 0, 0, -64, 14, 0, 0], [0, 0, -49, -262, 0, 0, 31, 168], [0, 0, 246, 180, 0, 0, -100, 374], [138, -64, 0, 0, 46, 53, 0, 0], [0, 0, 257, -8, 0, 0, -59, 41], [0, 0, 52, 310, 0, 0, -302, -214], [-352, 284, 0, 0, -36, -416, 0, 0], [0, 0, 354, -88, 0, 0, 6, 58], [0, 0, -422, 251, 0, 0, -197, -146], [0, 0, 332, 14, 0, 0, -274, 330], [-546, -104, 0, 0, 176, -228, 0, 0], [0, 0, -120, 92, 0, 0, -60, 60], [0, 0, 564, -143, 0, 0, 196, 246], [0, 0, 42, -63, 0, 0, 193, 422], [0, 0, 192, -167, 0, 0, -8, 206], [170, 108, 0, 0, -190, 524, 0, 0], [-484, 412, 0, 0, -184, -582, 0, 0], [-74, -188, 0, 0, -48, -296, 0, 0], [20, -324, 0, 0, 44, -364, 0, 0], [0, 0, -192, -416, 0, 0, -30, -274], [518, -314, 0, 0, -71, -14, 0, 0], [0, 0, -80, -178, 0, 0, -134, -308], [-44, 536, 0, 0, -4, 180, 0, 0], [106, 4, 0, 0, 402, -368, 0, 0], [-252, -256, 0, 0, 40, 534, 0, 0], [554, 272, 0, 0, -258, 109, 0, 0], [188, -296, 0, 0, 128, -116, 0, 0], [0, 0, -332, 293, 0, 0, -312, -338], [120, 144, 0, 0, 156, -104, 0, 0], [630, -240, 0, 0, 234, 107, 0, 0], [0, 0, -1, -132, 0, 0, -33, 35], [0, 0, -266, 318, 0, 0, 8, 218], [0, 0, 382, -255, 0, 0, -47, 138], [562, -268, 0, 0, -204, -388, 0, 0], [0, 0, -408, 168, 0, 0, 108, -48], [0, 0, 257, 178, 0, 0, -303, 152], [-590, -104, 0, 0, -2, 41, 0, 0], [0, 0, 115, -390, 0, 0, 607, 504], [-816, -292, 0, 0, 128, -462, 0, 0], [0, 0, -534, -226, 0, 0, -262, -272], [0, 0, -567, 226, 0, 0, 113, -412], [0, 0, -46, 126, 0, 0, 128, -486], [-452, -196, 0, 0, -352, 244, 0, 0], [66, 166, 0, 0, 169, 722, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_414_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_414_3_b_c();".
// 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_414_3_b_c(:prec:=8)
    chi := MakeCharacter_414_b();
    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_414_3_b_c();".
// 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_414_3_b_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_414_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![2116, 0, 3392, 0, 1100, 0, 64, 0, 1]>],Snew);
    return Vf;
end function;