
// Make newform 28.3.g.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_28_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_28_g_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_28_3_g_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_28_3_g_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 := [4, -20, 60, -116, 164, -166, 155, -163, 86, 3, -4, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-9243685, 1537456, -5442024, -126880702, -20918128, 25497908, 160225554, 23867696, -21007396, -6191612, 1422116, 548052], [13204764, -46482276, 48635510, -177078348, 215038026, -122846749, 201471321, -175954938, 1459025, 11867940, 4608465, -2016555], [199145960, -519820470, 799718192, -855472904, 461315491, -787680086, 562380793, 490503169, -87898803, -64448111, 174798, 6080681], [-38518016, 66312934, -102428648, -177419776, 436258613, -67350324, 358968697, -688812905, 38422753, 58450763, 13062376, -8092731], [-70375800, 236999870, -526622432, 836256216, -981317799, 797312818, -927115697, 751559539, -8785933, -48834261, -20455402, 8864783], [15160294, -43781960, 160381312, -254949459, 278083421, -243549767, 282488251, -234558069, 3410783, 15510516, 6284192, -2781796], [51100076, -253397978, 476417312, -691987512, -195583759, -546730846, 805776575, 897253275, -167711837, -108332469, -2778978, 11588911], [-10748502, 151851740, -415827090, 921404444, -847212044, 650456281, -1232772201, 694698148, 36406939, -36322258, -23003531, 7577433], [162375652, -641927134, 1684290272, -2643323856, 2338940247, -2465476938, 2949221097, -1629791971, -56986907, 82312181, 54731322, -18854063], [-51147512, 248435884, -684256636, 1248314483, -1425602332, 1124752022, -1470041616, 1190477049, -8906454, -77826224, -32333536, 13906733], [44275732, -200722666, 462671520, -729655908, 792739733, -686835394, 811952879, -537499493, -6021165, 30974575, 16328866, -6254493]];
    Rf_basisdens := [1, 5128417, 10256834, 20513668, 20513668, 20513668, 5128417, 20513668, 10256834, 20513668, 10256834, 2930524];
    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_28_g();"
function MakeCharacter_28_g()
    N := 28;
    order := 6;
    char_gens := [15, 17];
    v := [3, 4];
    // 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_28_g_Hecke();"
function MakeCharacter_28_g_Hecke(Kf)
    N := 28;
    order := 6;
    char_gens := [15, 17];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, -1, 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, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, -1, 0, 1, 0, -1, 0, 0], [-1, 1, 0, 0, -2, -1, -2, -1, -1, -1, -1, -1], [0, -1, -2, 1, 1, 1, 0, 1, 1, 1, 0, 0], [-1, 1, 2, 1, 0, 0, 2, 0, 1, 0, 0, -1], [0, -1, -6, -3, 0, 2, 0, -1, -1, 1, 0, 0], [1, 0, 0, 0, 1, 1, 2, 3, 0, 3, 1, 1], [3, 0, 0, 0, -3, 3, 6, -2, 0, -2, -3, 3], [7, 3, -6, -3, 0, 0, -6, 0, 3, 0, 0, 3], [0, 3, 16, -8, -3, -8, 0, -3, -3, -3, 0, 0], [10, 0, 0, 0, 0, 10, -10, 4, 0, -4, 0, 5], [-1, -5, 10, 5, 0, 0, 10, 0, -5, 0, 0, -5], [-2, 0, -4, 2, 0, 0, -4, 0, 0, 0, -16, -2], [0, 0, 0, 0, -3, 0, 0, -7, 0, -7, -3, 0], [0, -6, 2, 1, 0, 16, 0, -6, -6, 6, 0, 0], [0, -8, 4, -2, -7, -2, 0, 8, 8, 8, 0, 0], [20, 0, 0, 0, 0, 20, 2, -8, 0, 8, 0, -1], [0, -2, -16, 8, 9, 8, 0, 2, 2, 2, 0, 0], [4, 6, 8, -4, 0, 0, 8, 0, -6, 0, 24, 4], [0, 2, 4, 2, 0, 37, 0, 2, 2, -2, 0, 0], [-7, 0, 0, 0, -27, -7, -14, -2, 0, -2, -27, -7], [2, 6, 4, -2, 0, 0, 4, 0, -6, 0, 8, 2], [-1, 0, 0, 0, 0, -1, 4, 4, 0, -4, 0, -2], [55, -3, -30, -15, 0, 0, -30, 0, -3, 0, 0, 15], [0, 11, 20, 10, 0, -61, 0, 11, 11, -11, 0, 0], [3, 0, 0, 0, 37, 3, 6, 16, 0, 16, 37, 3], [-21, 0, 0, 0, -7, -21, -42, -17, 0, -17, -7, -21], [0, 5, 0, 0, 0, 29, 0, 5, 5, -5, 0, 0], [-5, 17, 10, 5, 0, 0, 10, 0, 17, 0, 0, -5], [-20, -14, -40, 20, 0, 0, -40, 0, 14, 0, 8, -20], [2, 0, 0, 0, -23, 2, 4, 6, 0, 6, -23, 2], [0, 7, -26, -13, 0, -48, 0, 7, 7, -7, 0, 0], [34, -10, 68, -34, 0, 0, 68, 0, 10, 0, 24, 34], [139, 0, 0, 0, 0, 139, 24, -27, 0, 27, 0, -12], [0, -17, -52, 26, 21, 26, 0, 17, 17, 17, 0, 0], [0, -28, 30, 15, 0, -110, 0, -28, -28, 28, 0, 0], [10, 0, 0, 0, 17, 10, 20, 4, 0, 4, 17, 10], [1, 31, 2, -1, 0, 0, 2, 0, -31, 0, 32, 1], [76, 0, 0, 0, 0, 76, -22, 2, 0, -2, 0, 11], [0, 11, 10, -5, 25, -5, 0, -11, -11, -11, 0, 0], [-64, 4, -44, -22, 0, 0, -44, 0, 4, 0, 0, 22], [-4, 0, 0, 0, -19, -4, -8, -11, 0, -11, -19, -4], [0, -27, 58, 29, 0, -26, 0, -27, -27, 27, 0, 0], [107, -21, -14, -7, 0, 0, -14, 0, -21, 0, 0, 7], [0, -7, -28, 14, 29, 14, 0, 7, 7, 7, 0, 0], [18, 42, 36, -18, 0, 0, 36, 0, -42, 0, 88, 18], [8, -18, 16, -8, 0, 0, 16, 0, 18, 0, -24, 8], [0, -43, 18, -9, 49, -9, 0, 43, 43, 43, 0, 0], [-29, 0, 0, 0, 0, -29, 64, 7, 0, -7, 0, -32], [-172, 0, 0, 0, 0, -172, -26, -1, 0, 1, 0, 13], [47, 13, 94, -47, 0, 0, 94, 0, -13, 0, 32, 47], [0, 12, -56, -28, 0, 219, 0, 12, 12, -12, 0, 0], [-67, -19, -134, 67, 0, 0, -134, 0, 19, 0, -72, -67], [-22, 0, 0, 0, 0, -22, -46, -51, 0, 51, 0, 23], [0, 44, 26, -13, -107, -13, 0, -44, -44, -44, 0, 0], [0, -8, -34, -17, 0, -278, 0, -8, -8, 8, 0, 0], [-35, 0, 0, 0, -115, -35, -70, -28, 0, -28, -115, -35], [0, 46, 82, 41, 0, 16, 0, 46, 46, -46, 0, 0], [-161, -19, -14, -7, 0, 0, -14, 0, -19, 0, 0, 7], [0, -9, 22, -11, 97, -11, 0, 9, 9, 9, 0, 0], [-106, 8, 72, 36, 0, 0, 72, 0, 8, 0, 0, -36], [38, 44, 76, -38, 0, 0, 76, 0, -44, 0, -16, 38], [0, 50, 122, -61, -131, -61, 0, -50, -50, -50, 0, 0], [-1, 0, 0, 0, 0, -1, 12, 66, 0, -66, 0, -6], [132, 0, 0, 0, 0, 132, 26, 34, 0, -34, 0, -13], [60, 0, 0, 0, 65, 60, 120, 30, 0, 30, 65, 60], [91, 83, 18, 9, 0, 0, 18, 0, 83, 0, 0, -9], [0, -76, -4, 2, -7, 2, 0, 76, 76, 76, 0, 0], [-57, 63, -118, -59, 0, 0, -118, 0, 63, 0, 0, 59], [0, -51, -14, -7, 0, 338, 0, -51, -51, 51, 0, 0], [22, 0, 0, 0, 77, 22, 44, -25, 0, -25, 77, 22], [0, 0, -42, 21, -83, 21, 0, 0, 0, 0, 0, 0], [202, 0, 0, 0, 0, 202, 46, 14, 0, -14, 0, -23], [-1, 11, -2, 1, 0, 0, -2, 0, -11, 0, 24, -1], [64, 0, 0, 0, -27, 64, 128, 31, 0, 31, -27, 64], [0, -37, -84, -42, 0, 15, 0, -37, -37, 37, 0, 0], [293, 0, 0, 0, 0, 293, 44, -57, 0, 57, 0, -22], [-102, 0, 0, 0, 0, -102, 66, -23, 0, 23, 0, -33], [0, 7, 142, 71, 0, 100, 0, 7, 7, -7, 0, 0], [-38, -100, -76, 38, 0, 0, -76, 0, 100, 0, -208, -38], [191, -43, 146, 73, 0, 0, 146, 0, -43, 0, 0, -73], [0, 21, 16, -8, 117, -8, 0, -21, -21, -21, 0, 0], [167, -67, -94, -47, 0, 0, -94, 0, -67, 0, 0, 47], [-78, 0, 0, 0, 77, -78, -156, 11, 0, 11, 77, -78], [-77, 0, 0, 0, 17, -77, -154, 21, 0, 21, 17, -77], [163, -57, -78, -39, 0, 0, -78, 0, -57, 0, 0, 39], [-113, 0, 0, 0, 0, -113, -4, -34, 0, 34, 0, 2], [27, 39, -30, -15, 0, 0, -30, 0, 39, 0, 0, 15], [-84, 32, -168, 84, 0, 0, -168, 0, -32, 0, 32, -84], [-18, 0, 0, 0, -159, -18, -36, -96, 0, -96, -159, -18], [0, -2, -258, 129, 69, 129, 0, 2, 2, 2, 0, 0], [0, -64, -94, 47, 5, 47, 0, 64, 64, 64, 0, 0], [7, 83, 14, -7, 0, 0, 14, 0, -83, 0, -8, 7], [26, 0, 0, 0, 1, 26, 52, -84, 0, -84, 1, 26], [20, -10, 40, -20, 0, 0, 40, 0, 10, 0, 136, 20], [125, 0, 0, 0, 0, 125, 132, 37, 0, -37, 0, -66], [0, -56, -12, -6, 0, -159, 0, -56, -56, 56, 0, 0], [83, 0, 0, 0, 105, 83, 166, -17, 0, -17, 105, 83], [-127, 0, 0, 0, 0, -127, 76, -23, 0, 23, 0, -38], [-23, -115, -46, 23, 0, 0, -46, 0, 115, 0, -152, -23], [0, 9, 80, 40, 0, 205, 0, 9, 9, -9, 0, 0], [0, 94, 240, -120, -199, -120, 0, -94, -94, -94, 0, 0], [-165, 0, 0, 0, 0, -165, -44, 66, 0, -66, 0, 22], [0, 19, -130, 65, -95, 65, 0, -19, -19, -19, 0, 0], [0, 60, -64, -32, 0, 23, 0, 60, 60, -60, 0, 0], [-6, 24, -12, 6, 0, 0, -12, 0, -24, 0, 32, -6], [-218, 0, 0, 0, 0, -218, -174, 63, 0, -63, 0, 87], [0, 26, 106, -53, -3, -53, 0, -26, -26, -26, 0, 0], [-85, -39, 74, 37, 0, 0, 74, 0, -39, 0, 0, -37], [80, 0, 0, 0, 149, 80, 160, 79, 0, 79, 149, 80], [0, 113, -4, -2, 0, -517, 0, 113, 113, -113, 0, 0], [-133, 47, 66, 33, 0, 0, 66, 0, 47, 0, 0, -33], [0, 58, 20, -10, -95, -10, 0, -58, -58, -58, 0, 0], [-4, -122, -8, 4, 0, 0, -8, 0, 122, 0, 56, -4], [0, 140, 72, 36, 0, -405, 0, 140, 140, -140, 0, 0], [-114, -104, -228, 114, 0, 0, -228, 0, 104, 0, -176, -114], [0, 86, 202, -101, 45, -101, 0, -86, -86, -86, 0, 0], [-60, 0, 0, 0, 0, -60, -150, -122, 0, 122, 0, 75], [138, 10, 276, -138, 0, 0, 276, 0, -10, 0, 8, 138], [0, -68, -150, -75, 0, 464, 0, -68, -68, 68, 0, 0], [343, -61, 154, 77, 0, 0, 154, 0, -61, 0, 0, -77], [-617, 0, 0, 0, 0, -617, 24, 47, 0, -47, 0, -12], [0, -39, -242, 121, -23, 121, 0, 39, 39, 39, 0, 0], [138, 0, 0, 0, 73, 138, 276, 78, 0, 78, 73, 138], [-630, -76, 48, 24, 0, 0, 48, 0, -76, 0, 0, -24], [-102, 0, 0, 0, 0, -102, -74, -100, 0, 100, 0, 37], [-3, 0, 0, 0, 237, -3, -6, 68, 0, 68, 237, -3], [-28, 42, -56, 28, 0, 0, -56, 0, -42, 0, 168, -28], [496, 0, 0, 0, 0, 496, -222, 34, 0, -34, 0, 111], [0, -151, -22, 11, 161, 11, 0, 151, 151, 151, 0, 0], [64, -18, 128, -64, 0, 0, 128, 0, 18, 0, 200, 64], [8, 0, 0, 0, -307, 8, 16, -115, 0, -115, -307, 8], [287, 7, 26, 13, 0, 0, 26, 0, 7, 0, 0, -13], [804, 0, 0, 0, 0, 804, -82, -43, 0, 43, 0, 41], [139, 135, 66, 33, 0, 0, 66, 0, 135, 0, 0, -33], [0, -49, -180, -90, 0, 695, 0, -49, -49, 49, 0, 0], [0, -8, 88, -44, -63, -44, 0, 8, 8, 8, 0, 0], [559, -81, -38, -19, 0, 0, -38, 0, -81, 0, 0, 19], [0, 46, -212, -106, 0, -47, 0, 46, 46, -46, 0, 0], [-26, 132, -52, 26, 0, 0, -52, 0, -132, 0, 64, -26], [-1, 0, 0, 0, 0, -1, -152, 79, 0, -79, 0, 76], [0, 106, 106, -53, 253, -53, 0, -106, -106, -106, 0, 0], [-118, -60, -236, 118, 0, 0, -236, 0, 60, 0, -192, -118], [0, 81, 160, 80, 0, 37, 0, 81, 81, -81, 0, 0], [140, 0, 280, -140, 0, 0, 280, 0, 0, 0, 0, 140], [419, -51, 202, 101, 0, 0, 202, 0, -51, 0, 0, -101], [0, -50, 204, 102, 0, -943, 0, -50, -50, 50, 0, 0], [-129, 0, 0, 0, -239, -129, -258, -23, 0, -23, -239, -129], [-95, 0, 0, 0, -11, -95, -190, 46, 0, 46, -11, -95], [-767, 0, 0, 0, 0, -767, 124, -11, 0, 11, 0, -62], [-512, -32, -108, -54, 0, 0, -108, 0, -32, 0, 0, 54], [6, 134, 12, -6, 0, 0, 12, 0, -134, 0, -56, 6], [34, 0, 0, 0, 133, 34, 68, -31, 0, -31, 133, 34], [0, 0, 428, -214, -103, -214, 0, 0, 0, 0, 0, 0], [-196, -116, -392, 196, 0, 0, -392, 0, 116, 0, -256, -196], [34, 0, 0, 0, -211, 34, 68, 123, 0, 123, -211, 34], [-407, 0, 0, 0, 0, -407, 456, -70, 0, 70, 0, -228], [-442, -156, 104, 52, 0, 0, 104, 0, -156, 0, 0, -52], [0, 114, 46, 23, 0, 30, 0, 114, 114, -114, 0, 0], [74, 0, 0, 0, 73, 74, 148, -130, 0, -130, 73, 74], [-5, 109, 410, 205, 0, 0, 410, 0, 109, 0, 0, -205], [-40, 162, -80, 40, 0, 0, -80, 0, -162, 0, 136, -40], [124, 0, 0, 0, 129, 124, 248, 78, 0, 78, 129, 124], [0, -83, 66, 33, 0, -342, 0, -83, -83, 83, 0, 0], [0, -65, -188, 94, -155, 94, 0, 65, 65, 65, 0, 0], [0, -22, 470, -235, -235, -235, 0, 22, 22, 22, 0, 0], [0, -64, 50, 25, 0, 940, 0, -64, -64, 64, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_28_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_28_3_g_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_28_3_g_a(:prec:=12)
    chi := MakeCharacter_28_g();
    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_28_3_g_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_28_3_g_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_28_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;