
// Make newform 684.3.y.h in Magma, downloaded from the LMFDB on 26 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_684_y();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_684_y_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_684_3_y_h();".
// 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_684_3_y_h();".
// 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 := [4971, -3528, 4294, -1582, 917, -154, 56, -4, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [13, -1, 1, 0, 0, 0, 0, 0], [-6477, 16740, -8470, 6314, -1015, 434, -28, 8], [38739, -19689, 17612, -4186, 1022, -217, 14, -4], [70, -25, 26, -2, 1, 0, 0, 0], [-187170, 21531, -57169, -14714, -2569, -1778, -7, -47], [-1251, 519, -562, 87, -46, 3, -1, 0], [-21439, 56739, -29309, 22204, -3885, 1673, -119, 34]];
    Rf_basisdens := [1, 1, 1029, 1029, 1, 2058, 6, 343];
    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_684_y();"
function MakeCharacter_684_y()
    N := 684;
    order := 6;
    char_gens := [343, 533, 325];
    v := [6, 6, 5];
    // 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_684_y_Hecke();"
function MakeCharacter_684_y_Hecke(Kf)
    N := 684;
    order := 6;
    char_gens := [343, 533, 325];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 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+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], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [-2, 1, 0, 0, 0, 0, 0, 0], [1, -1, 0, 0, -1, 0, 1, 0], [0, 0, 0, 1, -2, 1, 1, 0], [-6, 1, 6, 0, 0, -1, 0, -1], [-6, -1, 5, -2, 2, -1, 2, 0], [0, 0, 8, 1, 0, -3, 3, -1], [20, 0, -10, -2, 4, -1, -1, 0], [0, -1, 0, 4, -2, 0, 0, 2], [16, 0, -32, -2, 1, -4, 2, 0], [-1, -1, -1, 1, 1, -2, 4, -1], [-12, 0, 12, 5, -5, -3, 0, 0], [0, 0, -22, 7, 0, -1, 1, -3], [-4, -8, 2, 1, -2, 1, 1, 4], [-31, 1, -31, -2, -2, -2, 4, 1], [0, 0, -12, -4, 0, -3, 3, -4], [-74, -2, 37, 4, -8, -2, -2, 1], [20, 0, 20, 1, 1, -3, 6, 0], [3, -3, -3, -1, 1, 12, 0, 3], [6, -4, 6, -1, -1, -7, 14, -4], [7, -2, 0, 0, -10, 0, -3, 0], [32, 10, -16, -2, 4, 1, 1, -5], [13, 4, 13, 2, 2, 8, -16, 4], [0, 0, 80, 10, 0, 3, -3, 2], [-38, 2, 76, 16, -8, 4, -2, -4], [20, 2, -40, 16, -8, 8, -4, -4], [-30, 0, -30, 3, 3, -3, 6, 0], [-45, -4, 90, 18, -9, -6, 3, 8], [-36, 12, 18, -15, 30, -9, -9, -6], [-115, 6, 115, -1, 1, 4, 0, -6], [0, 0, 29, -8, 0, 2, -2, -12], [0, 0, -131, -8, 0, 0, 0, -7], [-52, -14, 52, -16, 16, 5, 0, 14], [58, -1, -116, -4, 2, -28, 14, 2], [40, -10, -40, -13, 13, -3, 0, 10], [47, 1, 0, 0, -13, 0, -21, 0], [112, -12, -56, 5, -10, 11, 11, 6], [-32, 12, -32, 5, 5, 17, -34, 12], [-25, 6, 50, -32, 16, -18, 9, -12], [-160, -12, 80, -8, 16, -1, -1, 6], [-112, 0, 0, 0, -2, 0, -10, 0], [0, -1, 0, 10, 10, -7, 14, -1], [-20, 10, 0, 0, 17, 0, -12, 0], [0, 0, -42, 1, 0, -3, 3, 12], [74, 7, 74, -10, -10, -1, 2, 7], [40, 5, 40, 1, 1, -9, 18, 5], [71, -8, -142, 4, -2, -26, 13, 16], [-86, 16, 0, 0, 18, 0, 12, 0], [-37, -29, 37, -1, 1, 14, 0, 29], [38, 6, 0, 0, 10, 0, -4, 0], [-98, 2, 49, 13, -26, 4, 4, -1], [0, 0, 31, 29, 0, 34, -34, 4], [-122, 2, 61, -1, 2, -2, -2, -1], [-74, 13, 74, 37, -37, 5, 0, -13], [-40, 14, -40, -5, -5, -3, 6, 14], [-44, -9, 44, 39, -39, 45, 0, 9], [34, 4, 0, 0, -21, 0, -6, 0], [-62, -2, 31, -25, 50, -12, -12, 1], [65, -24, -65, 7, -7, 30, 0, 24], [4, 2, -8, -10, 5, 4, -2, -4], [-19, 11, -19, 10, 10, -12, 24, 11], [144, -9, 0, 0, 0, 0, -34, 0], [0, 0, -35, -11, 0, -6, 6, -25], [276, -36, -138, 15, -30, 33, 33, 18], [195, 6, -390, 4, -2, -50, 25, -12], [79, -10, 79, 16, 16, 10, -20, -10], [201, 15, -201, -42, 42, -38, 0, -15], [6, 0, 0, 0, -34, 0, 0, 0], [49, -2, 0, 0, -19, 0, 9, 0], [-24, -9, 24, 21, -21, 31, 0, 9], [0, 0, 22, 21, 0, -39, 39, -21], [-18, -2, 36, -12, 6, -28, 14, 4], [-64, -25, 128, 14, -7, 20, -10, 50], [208, -15, 208, -7, -7, -19, 38, -15], [0, 0, -116, 59, 0, 1, -1, -14], [-344, -12, 344, -6, 6, 27, 0, 12], [153, -2, 153, 36, 36, 6, -12, -2], [70, 42, -35, -1, 2, -4, -4, -21], [-14, -38, 0, 0, -4, 0, 60, 0], [68, 10, 68, 10, 10, -23, 46, 10], [-120, -24, 60, 15, -30, 3, 3, 12], [144, 54, -72, 2, -4, -9, -9, -27], [56, -5, 56, -1, -1, -21, 42, -5], [0, 0, -339, -3, 0, -76, 76, -12], [-51, -17, 102, 96, -48, 18, -9, 34], [-247, -27, 0, 0, -96, 0, 27, 0], [-204, 22, 204, -9, 9, 35, 0, -22], [-38, 12, 0, 0, 22, 0, 12, 0], [315, 35, 0, 0, 51, 0, 19, 0], [0, 0, -226, 7, 0, -57, 57, 14], [74, 1, -148, -68, 34, 20, -10, -2], [-244, 56, 244, 5, -5, -9, 0, -56], [-261, 8, 261, -5, 5, -48, 0, -8], [0, 0, -268, -41, 0, -51, 51, -1], [200, 20, -100, 19, -38, 19, 19, -10], [-81, 20, 162, -66, 33, -22, 11, -40], [12, -20, -6, -47, 94, 7, 7, 10], [0, 0, -320, -27, 0, 51, -51, 6], [-44, 24, 22, -3, 6, -5, -5, -12], [0, 0, -470, 35, 0, 11, -11, 48], [-3, 14, 6, 24, -12, 74, -37, -28], [162, 19, -324, 42, -21, 0, 0, -38], [83, -48, 0, 0, 48, 0, -39, 0], [-29, -32, 0, 0, 63, 0, 75, 0], [-176, -26, 176, -11, 11, -13, 0, 26], [0, 0, -709, -29, 0, -42, 42, 23], [-532, -42, 266, 19, -38, -23, -23, 21], [59, -15, -118, 36, -18, 6, -3, 30], [-94, 17, 188, -16, 8, 44, -22, -34], [390, 26, -390, -17, 17, 51, 0, -26], [0, 0, -341, -76, 0, -4, 4, 24], [-166, 10, 0, 0, -28, 0, -48, 0], [0, 0, -198, -91, 0, -3, 3, 5], [439, -23, 439, 17, 17, 14, -28, -23], [-669, -18, 669, 53, -53, -12, 0, 18], [-194, -4, 0, 0, 86, 0, -44, 0], [-76, 0, 0, 0, -20, 0, 86, 0], [260, -16, -130, -23, 46, 13, 13, 8], [516, -16, -258, 30, -60, -11, -11, 8], [-154, 29, 308, -42, 21, -80, 40, -58], [-216, 22, 432, 96, -48, 80, -40, -44], [144, 20, -288, -24, 12, -32, 16, -40], [206, 24, 0, 0, -24, 0, 36, 0], [-76, 8, 76, -124, 124, -51, 0, -8], [0, 0, -122, 84, 0, 75, -75, 12], [-824, -8, 824, 25, -25, 11, 0, 8], [136, 6, -136, 63, -63, 45, 0, -6], [134, 24, 0, 0, -27, 0, 90, 0], [-263, 65, 263, -82, 82, -48, 0, -65], [-238, -1, -238, -65, -65, -65, 130, -1], [-336, -24, 168, -25, 50, 53, 53, 12], [-242, 8, 242, -7, 7, 39, 0, -8], [-415, -10, 0, 0, -113, 0, 85, 0], [0, 0, -34, -42, 0, 123, -123, 29], [280, -56, -140, 14, -28, -15, -15, 28], [211, -32, -422, -72, 36, -26, 13, 64], [-102, -24, 204, -30, 15, 120, -60, 48], [-115, -25, 0, 0, -152, 0, 43, 0], [-500, 28, 250, 17, -34, -57, -57, -14], [0, 0, -338, -7, 0, -85, 85, -18], [0, 0, -314, -29, 0, -87, 87, -22], [-314, -44, 157, -61, 122, 10, 10, 22], [-234, -20, 468, 4, -2, -28, 14, 40], [246, -13, 246, 27, 27, 67, -134, -13], [604, 30, -604, 3, -3, -111, 0, -30], [-147, -16, -147, -78, -78, 38, -76, -16], [0, 0, -699, 47, 0, 42, -42, 50], [208, 33, -416, 20, -10, -48, 24, -66], [386, -50, 386, -28, -28, -17, 34, -50], [271, 51, 0, 0, 50, 0, 41, 0], [0, 0, 173, 51, 0, 42, -42, 74], [-244, 84, 122, -89, 178, -51, -51, -42], [-249, 1, -249, -18, -18, 10, -20, 1], [268, -55, -536, -40, 20, 16, -8, 110], [266, -116, 0, 0, -34, 0, 12, 0], [-331, -4, 331, 104, -104, -138, 0, 4], [0, 0, -815, 63, 0, 114, -114, 33], [-544, 36, 272, -41, 82, -41, -41, -18], [-628, 14, 628, -79, 79, -9, 0, -14], [555, 29, 555, -51, -51, 2, -4, 29], [-62, -52, 62, -151, 151, -45, 0, 52], [-309, 21, -309, 90, 90, 28, -56, 21], [357, 38, -714, 114, -57, -82, 41, -76], [120, 26, 120, 21, 21, -7, 14, 26], [-70, 34, -70, -63, -63, 65, -130, 34], [0, 0, -524, -32, 0, 93, -93, 2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_684_y_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_684_3_y_h();".
// 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_684_3_y_h(:prec:=8)
    chi := MakeCharacter_684_y();
    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_684_3_y_h();".
// 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_684_3_y_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_684_y();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![1028196, -79092, 93288, 8736, 6304, 242, 87, -1, 1]>,<7,R![6940, -498, -158, 6, 1]>],Snew);
    return Vf;
end function;