
// Make newform 1568.3.d.l in Magma, downloaded from the LMFDB on 11 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1568_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1568_d_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_1568_3_d_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_1568_3_d_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, 36, 0, 12, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0], [0, 0, 6, 0, 1, 0], [0, 12, 0, 2, 0, 0], [0, 30, 0, 11, 0, 1], [16, 0, 10, 0, 1, 0]];
    Rf_basisdens := [1, 1, 1, 1, 2, 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_1568_d();"
function MakeCharacter_1568_d()
    N := 1568;
    order := 2;
    char_gens := [1471, 197, 1473];
    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_1568_d_Hecke();"
function MakeCharacter_1568_d_Hecke(Kf)
    N := 1568;
    order := 2;
    char_gens := [1471, 197, 1473];
    char_values := [[-1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 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]];
    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, -1, 0], [3, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 3, 0], [0, 0, 0, 0, 0, -1], [-1, 0, -5, 0, 0, 0], [0, 3, 0, 3, -9, 0], [0, -6, 0, 4, 3, 0], [0, 0, 7, 0, 0, 0], [0, -1, 0, -1, 5, 0], [19, 0, 0, 0, 0, 2], [0, 0, 7, 0, 0, -2], [0, -4, 0, -4, 16, 0], [0, -7, 0, 7, 3, 0], [3, 0, -7, 0, 0, -5], [0, 12, 0, 12, 7, 0], [53, 0, -8, 0, 0, 2], [0, 6, 0, 7, -3, 0], [0, 2, 0, -19, 20, 0], [57, 0, 5, 0, 0, 1], [0, 10, 0, 20, -5, 0], [0, -6, 0, 15, -4, 0], [25, 0, -8, 0, 0, -8], [0, 0, 0, 0, 0, -1], [83, 0, 9, 0, 0, -4], [0, 16, 0, 23, -39, 0], [0, 21, 0, -17, -7, 0], [53, 0, 14, 0, 0, 11], [-112, 0, 14, 0, 0, -5], [0, -6, 0, -41, -4, 0], [0, 22, 0, 29, 21, 0], [25, 0, -21, 0, 0, 6], [0, 22, 0, 15, -4, 0], [-19, 0, -35, 0, 0, -2], [0, 45, 0, -5, -5, 0], [-27, 0, -44, 0, 0, -6], [0, -64, 0, 2, 39, 0], [0, -31, 0, 4, 50, 0], [53, 0, 41, 0, 0, -9], [0, 17, 0, 30, -61, 0], [-38, 0, 27, 0, 0, 5], [0, 43, 0, 19, -11, 0], [81, 0, 28, 0, 0, -9], [-112, 0, 7, 0, 0, 4], [0, -15, 0, -64, 33, 0], [0, -62, 0, 15, -4, 0], [0, -2, 0, -37, -20, 0], [0, 29, 0, 57, -87, 0], [115, 0, -20, 0, 0, -1], [-103, 0, 0, 0, 0, 3], [0, -7, 0, -18, 42, 0], [-111, 0, -30, 0, 0, -14], [0, 3, 0, 38, -50, 0], [143, 0, -55, 0, 0, 6], [0, -16, 0, -43, 113, 0], [-27, 0, -2, 0, 0, 32], [0, -60, 0, -11, 41, 0], [3, 0, -21, 0, 0, 5], [0, 0, -84, 0, 0, -11], [0, -1, 0, 48, -51, 0], [38, 0, -62, 0, 0, -26], [0, 52, 0, 38, -40, 0], [0, -2, 0, -44, 35, 0], [-199, 0, 27, 0, 0, 11], [-149, 0, -49, 0, 0, 13], [0, 26, 0, -41, 99, 0], [-112, 0, -35, 0, 0, 2], [0, 60, 0, -30, 145, 0], [-224, 0, 7, 0, 0, -10], [-1, 0, -12, 0, 0, -27], [0, 5, 0, 16, 1, 0], [0, -48, 0, -83, -33, 0], [19, 0, -49, 0, 0, -11], [0, 35, 0, 46, 14, 0], [0, 87, 0, -32, -9, 0], [-227, 0, 35, 0, 0, -28], [-277, 0, -6, 0, 0, 37], [-271, 0, -7, 0, 0, -24], [-393, 0, 9, 0, 0, 22], [0, -88, 0, 10, 72, 0], [-224, 0, -42, 0, 0, -33], [0, 55, 0, -2, -129, 0], [-224, 0, -112, 0, 0, -9], [0, -65, 0, -58, 39, 0], [0, -65, 0, -138, 197, 0], [112, 0, 7, 0, 0, -20], [103, 0, 7, 0, 0, 35], [-112, 0, 35, 0, 0, 22], [0, 92, 0, 8, -32, 0], [0, -140, 0, -56, 81, 0], [0, -62, 0, -34, 51, 0], [0, -32, 0, -73, -103, 0], [0, -77, 0, 46, 14, 0], [0, 124, 0, 50, -41, 0], [0, -18, 0, 59, -180, 0], [-501, 0, 29, 0, 0, 12], [-279, 0, -2, 0, 0, -2], [0, 43, 0, -83, 55, 0], [37, 0, 105, 0, 0, 54], [0, 21, 0, 94, -14, 0], [-171, 0, 0, 0, 0, 69], [0, 102, 0, -31, -45, 0], [-233, 0, 161, 0, 0, -43], [0, -79, 0, -10, 43, 0], [1, 0, 138, 0, 0, 26], [0, 152, 0, -44, -48, 0], [255, 0, 78, 0, 0, -45], [0, -102, 0, -80, 205, 0], [-336, 0, -14, 0, 0, 13], [0, -25, 0, -32, 215, 0], [-115, 0, -70, 0, 0, 23], [560, 0, 63, 0, 0, -52], [0, 6, 0, -113, 3, 0], [0, 10, 0, -39, 100, 0], [591, 0, 126, 0, 0, 26], [0, -184, 0, -44, -48, 0], [0, 46, 0, 74, 11, 0], [-149, 0, -147, 0, 0, 31], [0, -126, 0, -49, 252, 0], [-419, 0, 82, 0, 0, -16], [-672, 0, 77, 0, 0, -34], [899, 0, 64, 0, 0, 31], [0, 123, 0, 73, -121, 0], [0, -102, 0, -39, -43, 0], [58, 0, -112, 0, 0, 0], [691, 0, -112, 0, 0, 26], [0, 132, 0, 13, -55, 0], [0, -6, 0, -27, 52, 0], [-731, 0, 69, 0, 0, -29], [0, -101, 0, -67, 271, 0], [0, 190, 0, 85, -172, 0], [0, 51, 0, -141, 293, 0], [-448, 0, 21, 0, 0, 78], [-25, 0, 211, 0, 0, 44], [112, 0, 21, 0, 0, 48], [867, 0, 23, 0, 0, -2], [0, -48, 0, -216, 79, 0], [-224, 0, -105, 0, 0, -74], [87, 0, 133, 0, 0, 5], [0, 40, 0, -142, 8, 0], [93, 0, 196, 0, 0, 33], [0, 90, 0, -28, 221, 0], [0, 12, 0, -58, -104, 0], [-533, 0, 156, 0, 0, -37], [0, 96, 0, 236, -48, 0], [-560, 0, -98, 0, 0, 9], [-55, 0, 75, 0, 0, -57], [0, -15, 0, 104, 147, 0], [0, 14, 0, -4, -21, 0], [485, 0, -105, 0, 0, 8], [-430, 0, -85, 0, 0, 5], [0, -126, 0, -175, 196, 0], [0, 49, 0, 315, -165, 0], [0, -92, 0, -224, 25, 0], [0, -104, 0, -6, 360, 0], [0, 25, 0, -6, 313, 0], [641, 0, -127, 0, 0, -71], [542, 0, 134, 0, 0, 2], [-139, 0, 117, 0, 0, -37], [0, 142, 0, 131, -197, 0], [336, 0, 112, 0, 0, -19], [0, -62, 0, -97, -228, 0], [0, -250, 0, 65, -67, 0], [-255, 0, -224, 0, 0, -53], [0, 135, 0, 289, 21, 0], [0, -114, 0, 188, 85, 0], [-83, 0, -268, 0, 0, 34], [-1120, 0, -70, 0, 0, 11], [893, 0, 6, 0, 0, 12], [0, 20, 0, 126, -255, 0], [-1008, 0, 56, 0, 0, -21], [0, -214, 0, -50, -229, 0], [-473, 0, -84, 0, 0, -24], [0, 235, 0, -17, 181, 0], [224, 0, -371, 0, 0, 28], [0, -35, 0, -214, 210, 0], [1123, 0, -63, 0, 0, 23], [0, 2, 0, -33, 188, 0], [507, 0, 197, 0, 0, 20], [0, 38, 0, 90, -285, 0], [0, -158, 0, -221, 44, 0], [-730, 0, -91, 0, 0, 91], [-311, 0, 6, 0, 0, -82], [0, -132, 0, -19, 297, 0], [1037, 0, -58, 0, 0, -56], [-59, 0, 266, 0, 0, 23], [0, -89, 0, -278, 77, 0], [121, 0, 84, 0, 0, 31], [0, -231, 0, 294, 225, 0], [865, 0, -64, 0, 0, 72], [0, -290, 0, -241, 124, 0], [0, -147, 0, 165, 105, 0], [-501, 0, -202, 0, 0, 29], [0, -15, 0, 96, 123, 0], [391, 0, 86, 0, 0, 115], [305, 0, -28, 0, 0, -21], [37, 0, -56, 0, 0, -75], [784, 0, -91, 0, 0, 16], [0, 160, 0, 97, 225, 0], [-731, 0, 203, 0, 0, -76], [0, -34, 0, -307, -172, 0], [557, 0, 265, 0, 0, 19], [-113, 0, 79, 0, 0, -148], [0, -82, 0, -61, -372, 0], [-139, 0, -268, 0, 0, 110], [0, 86, 0, -180, -235, 0], [0, -181, 0, -2, -291, 0], [450, 0, -14, 0, 0, 70], [0, 16, 0, -166, -177, 0], [1633, 0, -14, 0, 0, 13], [-1008, 0, -175, 0, 0, -12], [0, 108, 0, -144, -320, 0], [0, 56, 0, -140, -199, 0], [0, 155, 0, 253, -619, 0], [-1033, 0, -55, 0, 0, 90], [0, 155, 0, 140, -137, 0], [671, 0, -75, 0, 0, -54], [0, 139, 0, -39, -395, 0], [170, 0, 14, 0, 0, 42], [205, 0, -203, 0, 0, -22], [0, 81, 0, 18, -566, 0], [-65, 0, -189, 0, 0, 51], [0, 347, 0, -13, -219, 0], [0, -358, 0, 139, -52, 0], [-1008, 0, -70, 0, 0, -57], [-137, 0, -181, 0, 0, 136], [0, 32, 0, -415, 201, 0], [0, 37, 0, 163, -341, 0], [0, 142, 0, -135, -309, 0], [59, 0, -14, 0, 0, 56], [0, -284, 0, 80, 239, 0], [0, -128, 0, -212, 400, 0], [-87, 0, 231, 0, 0, -130], [0, 304, 0, -130, -264, 0], [0, 454, 0, 34, -109, 0], [-193, 0, 22, 0, 0, -181], [-467, 0, 336, 0, 0, -31], [0, -28, 0, 210, -728, 0], [0, -417, 0, -32, 62, 0], [0, -414, 0, 245, 389, 0], [0, -161, 0, -175, 311, 0], [0, -372, 0, -295, 647, 0], [1307, 0, 196, 0, 0, 114], [1550, 0, 50, 0, 0, -26], [0, -190, 0, -36, 253, 0], [0, -206, 0, -87, 292, 0], [0, 473, 0, -213, -239, 0], [0, -29, 0, -79, 39, 0], [0, -441, 0, -52, 574, 0], [1456, 0, 266, 0, 0, 79], [-479, 0, -106, 0, 0, 198], [0, 79, 0, -552, -1, 0], [-112, 0, 14, 0, 0, 129], [-1371, 0, -79, 0, 0, -109], [0, -161, 0, -458, 301, 0], [1795, 0, -154, 0, 0, -24], [0, 175, 0, -378, 197, 0], [1568, 0, -42, 0, 0, -3], [-473, 0, 99, 0, 0, 116], [0, -4, 0, -269, 177, 0], [0, -248, 0, 298, 40, 0], [-925, 0, -180, 0, 0, -85], [-1008, 0, 21, 0, 0, 144], [1007, 0, -215, 0, 0, 110], [0, -399, 0, 210, -221, 0], [1904, 0, 84, 0, 0, 1], [-896, 0, -105, 0, 0, 102], [0, -272, 0, 358, -200, 0], [-1459, 0, 189, 0, 0, 98], [-501, 0, 281, 0, 0, 156], [0, 19, 0, -255, 463, 0], [-1401, 0, 177, 0, 0, -110], [0, -319, 0, 140, -103, 0], [0, 0, -14, 0, 0, -23], [0, -8, 0, -547, 449, 0], [0, -346, 0, -91, -373, 0], [-725, 0, 294, 0, 0, -84], [-793, 0, -483, 0, 0, -95], [0, 215, 0, -415, -17, 0], [0, -403, 0, -340, 409, 0], [0, -663, 0, 71, 699, 0], [0, 20, 0, 426, -24, 0], [224, 0, -301, 0, 0, 114], [0, 379, 0, 15, -673, 0], [0, -143, 0, -118, 481, 0], [255, 0, 504, 0, 0, -60], [336, 0, -217, 0, 0, 132], [0, 140, 0, -553, 335, 0], [448, 0, 336, 0, 0, -225], [-507, 0, 161, 0, 0, 50], [0, 263, 0, 74, -547, 0], [-569, 0, -56, 0, 0, -24], [0, -339, 0, -122, 610, 0], [1120, 0, -378, 0, 0, -17], [-533, 0, -68, 0, 0, 107], [0, 181, 0, -533, 259, 0], [224, 0, 392, 0, 0, 127], [0, 614, 0, -233, -443, 0], [0, 395, 0, 248, -442, 0], [-1319, 0, -421, 0, 0, -89], [-299, 0, -245, 0, 0, 40], [0, -621, 0, -48, 615, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1568_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1568_3_d_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_1568_3_d_l(:prec:=6)
    chi := MakeCharacter_1568_d();
    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_1568_3_d_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_1568_3_d_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1568_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<3,R![1, 0, 75, 0, 27, 0, 1]>,<5,R![29, 3, -9, 1]>],Snew);
    return Vf;
end function;