
// Make newform 43.3.d.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_43_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_43_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_43_3_d_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_43_3_d_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 := [1849, 0, 7253, 0, 6923, 0, 2718, 0, 483, 0, 37, 0, 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], [3053, 124, 10271, 0, 6752, 0, 1563, 0, 137, 0, 4, 0], [3053, -124, 10271, 0, 6752, 0, 1563, 0, 137, 0, 4, 0], [18940167, -3213627, 70377670, -7162682, 46125971, -3624075, 10473897, -695669, 904290, -54558, 26101, -1485], [11827709, -3213627, 55263514, -7162682, 39890025, -3624075, 9649587, -695669, 861118, -54558, 25327, -1485], [-18940167, -3213627, -70377670, -7162682, -46125971, -3624075, -10473897, -695669, -904290, -54558, -26101, -1485], [9110281, 5730264, 31612912, 6488098, 21503999, 2975030, 5030871, 595576, 441352, 48798, 12857, 1370], [5332, 73310, 0, 201197, 0, 125769, 0, 28402, 0, 2455, 0, 71], [-3556229, 1369793, -7557078, 25470362, -3117973, 19760933, -412155, 4765455, -21586, 422014, -387, 12339], [27766433, -7859677, 82695794, -39401330, 53241869, -27515185, 12125183, -6440307, 1049286, -564102, 30315, -16407], [22903649, 7859677, 81885330, 39401330, 53241869, 27515185, 12125183, 6440307, 1049286, 564102, 30315, 16407], [-6970343, 5334036, -22536644, 23282006, -14590717, 15569630, -3379585, 3567988, -296356, 309330, -8643, 8946]];
    Rf_basisdens := [1, 248, 248, 810464, 810464, 810464, 405232, 10664, 810464, 810464, 810464, 405232];
    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_43_d();"
function MakeCharacter_43_d()
    N := 43;
    order := 6;
    char_gens := [3];
    v := [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_43_d_Hecke();"
function MakeCharacter_43_d_Hecke(Kf)
    N := 43;
    order := 6;
    char_gens := [3];
    char_values := [[0, 0, 0, 0, 0, 0, 0, 1, 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, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1], [1, 0, 0, -1, 1, 1, 0, -1, -1, 0, 1, 0], [5, 0, 0, -1, 2, -1, 0, 0, 0, -2, -2, 0], [2, 1, 0, 0, 2, 0, -3, 4, -2, 0, -1, 1], [-2, -5, 1, 4, -2, 1, 1, -2, 0, 0, -1, -3], [4, -7, 0, 1, 3, -3, 0, 4, 3, 0, 0, 0], [-4, -3, 2, -4, -4, -8, 5, 1, 1, -5, 1, -2], [-16, 2, -4, 5, -6, 7, -2, 10, 5, 4, -2, 2], [-3, -2, 10, 4, 1, 14, -2, 2, -2, 2, 4, 3], [8, 10, 0, -3, -1, 4, 1, 6, -3, 1, 1, 3], [11, 2, -1, 7, 3, -7, 0, 0, 0, 1, -2, 3], [0, -7, -5, 0, 0, -6, -7, 6, 6, 1, -6, 1], [2, 6, 2, -9, 2, 11, 0, 0, 0, 3, -1, 4], [-11, -2, -8, -5, -3, -21, 5, 12, 4, -5, -7, -6], [32, 3, 5, 1, -3, 0, 0, 0, 0, -6, -4, -2], [20, 7, 3, -7, 8, 8, -7, -13, -7, 14, 13, 7], [18, 4, -24, 3, 4, 0, 7, -17, -3, -7, -9, -8], [-7, 5, 14, -16, 15, 2, -5, -5, -16, 10, 22, 5], [23, 5, -16, 7, -3, -9, -5, -6, 7, 10, -6, 5], [-7, -19, 6, 14, -7, 8, 7, 33, -2, 0, 0, -7], [6, -13, 40, -6, 1, 14, 2, -15, -10, -2, 16, 7], [-4, 38, 0, -17, -4, 4, 7, 3, 3, 7, 7, 0], [-47, 4, 6, 10, -26, 14, 0, 0, 0, 5, 7, -2], [14, -24, 16, -3, 14, -7, -20, -38, -1, 0, -6, 8], [10, -10, 12, 9, 10, 13, -6, 18, -9, 0, 4, 14], [-61, 0, -2, 4, 22, -24, 0, 0, 0, -3, -5, 2], [-43, 12, -24, -13, 33, 5, -1, 44, -32, 1, -1, 0], [-1, -14, 20, 15, 0, 9, -12, 14, 12, 6, 0, 6], [25, 15, 14, 7, -22, 16, 0, 0, 0, 6, 5, 1], [48, 21, -15, -16, 15, -29, -34, -62, 4, 17, -11, 6], [-29, -21, 26, -19, -12, -6, 20, 38, 4, -10, 15, 5], [-47, 21, -32, 7, 3, 36, 2, 40, -10, -2, 12, 5], [16, -14, 0, 56, -1, -15, -14, 18, 1, -14, -14, -16], [-13, 9, -2, -38, -10, -11, 30, -4, -10, -15, 22, 7], [30, -23, 13, 13, -2, -40, 23, -3, 13, -46, -47, -23], [-27, 16, 13, 9, -19, 42, -16, 13, 9, 32, 17, 16], [94, -13, -8, 9, 6, -35, -4, -73, 15, 4, -38, -17], [-5, -5, 15, -14, 15, -21, 0, 0, 0, -16, 4, -20], [-85, 0, -20, -10, 11, -2, 0, 38, -10, 0, 9, 0], [4, -69, 30, 42, 4, -2, -17, -104, 20, 0, -13, -9], [-12, 64, 0, -34, 3, 27, 16, -26, -11, 16, 16, 30], [-92, -14, 7, 23, -23, -21, 0, 0, 0, -28, -7, -21], [3, -44, 21, -54, 3, -37, -8, 56, 10, 0, -5, -2], [1, 17, -5, 16, -15, 33, 20, -22, 10, -10, 22, 12], [3, -25, -46, 19, -32, -60, 24, -30, 40, -12, -59, -71], [-104, 32, -60, -36, -18, -90, -8, 216, 44, 4, -32, -28], [-37, 69, 0, 5, -21, 6, -10, -32, -16, -10, -10, -15], [-8, -8, 11, -34, -8, 9, 30, -9, -8, 0, 22, 14], [66, 3, -64, 15, -26, -13, -3, -31, 15, 6, -1, 3], [5, 48, -42, 6, -7, 54, -16, -16, -4, 16, 38, 27], [124, 0, 53, 17, -4, -7, 0, -47, 17, 0, -30, 0], [-34, -58, 10, 18, -34, -2, 30, 151, 14, 0, -4, -38], [-20, 63, -78, 4, -6, -5, 12, 28, 0, -6, -9, -15], [98, -33, 0, 12, 26, -12, -21, 63, -9, -21, -21, 14], [-50, -54, -41, -4, 29, -38, 0, 0, 0, -3, 10, -13], [12, 95, -40, 4, 12, 0, -9, 18, 10, 0, 3, 15], [19, -28, 0, 20, 41, -28, -24, -18, 4, -24, -24, 13], [-127, 45, -88, -17, 17, -22, -4, 130, -14, 4, -2, 1], [28, -42, 51, -11, 28, 66, 4, -138, -79, 0, 32, 60], [36, -46, -8, -41, 20, -17, 0, 0, 0, -41, -3, -38], [91, 4, 122, -35, 66, 113, -39, -117, -92, 39, 91, 65], [90, -21, 40, -15, -6, 41, 40, -129, -33, -40, 38, -1], [72, 55, 0, 57, 61, -17, -19, 9, -2, -19, -19, 44], [-24, 12, 6, 66, -46, -14, 0, 0, 0, -38, -44, 6], [-80, 18, -80, 22, -38, 14, -18, 43, 22, 36, 12, 18], [15, -68, 33, 143, 15, 50, -32, 129, 9, 0, -17, -2], [57, 54, 0, -117, 34, 5, 19, 37, 14, 19, 19, 39], [22, 19, 0, -133, -40, 15, 16, 63, 1, 16, 16, -25], [-29, 80, -41, 33, -29, 68, 56, -247, -49, 0, 27, -2], [20, -6, 13, -16, 20, -19, -20, 53, 22, 0, 0, 20], [52, -33, 20, -35, -42, -121, 30, -59, 35, -30, -16, -23], [-202, 14, 143, -8, 8, 65, -14, 97, -8, 28, 22, 14], [-118, 35, 3, -2, 7, 27, 0, 0, 0, 45, 13, 32], [-1, -81, 79, -34, -57, -89, 4, -2, 110, -2, 0, -2], [-3, 69, -33, 76, 17, 125, -4, 10, -30, 2, 34, 36], [114, 98, -116, -56, 47, -77, -66, -88, -21, 66, 14, 40], [40, 127, -35, 110, 40, 106, -23, -77, -68, 0, 17, 57], [-10, 83, -37, -13, 33, 70, 4, 16, -70, -2, 48, 46], [-2, -44, 47, -27, 39, -25, -40, 44, -38, 20, -17, 3], [-246, 2, -32, 5, 16, -81, -2, 136, 5, 4, -24, 2], [85, 3, -5, 19, 9, -20, 0, 0, 0, 33, 25, 8], [-55, 36, 0, 16, -98, 22, 1, 22, -21, 1, 1, -76], [1, -161, 87, -95, 1, 0, 11, 88, -71, 0, 12, 13], [24, 3, 9, 48, 24, 36, -27, -293, -30, 0, -3, 21], [-224, 118, 0, 0, -94, 87, 56, -161, -31, 56, 56, -7], [-81, -20, -56, 110, -88, -36, 18, 144, 158, -9, -67, -76], [27, -90, 98, 100, -59, 66, 24, -10, 76, -24, -58, -41], [-74, -46, 0, 94, -69, -25, 20, 40, 45, 20, 20, -94], [-50, -30, 0, 4, 26, -49, -46, -73, 3, -46, -46, -23], [603, 37, -70, 27, -16, -4, -24, -581, 38, 24, -20, 2], [-26, -27, -47, 51, -26, -100, -69, 79, 61, 0, -95, -121], [-187, -6, -86, -36, 97, -64, 6, 106, -36, -12, -31, -6], [28, -83, -46, 7, -96, -177, 83, -55, 7, -166, -1, -83], [-51, -42, 34, -81, 13, -19, 42, -49, -81, -84, 107, -42], [-37, -76, 44, -1, -37, 49, 86, -39, -1, 0, 49, 12], [180, 94, 0, -39, -46, 78, 5, 153, -73, 5, 5, 32], [170, 6, 44, 28, 64, -40, -6, -25, 28, 12, -114, 6], [1, 52, -46, -169, 1, -175, -42, 281, 99, 0, -41, -40], [245, -64, 116, -46, 82, -6, 11, -250, -87, -11, -1, -6], [101, -27, -38, 4, 52, -45, 0, 0, 0, 13, 2, 11], [51, -95, -64, 36, 56, -123, 0, 0, 0, -43, -12, -31], [307, -82, -108, 38, -82, -222, 96, -267, 122, -96, -176, -136], [-91, -40, 0, -110, -40, 34, 51, -34, 17, 51, 51, -6], [-319, -38, 28, -92, 79, -73, 38, 107, -92, -76, 67, -38], [436, -1, 126, -5, -52, 203, 1, -249, -5, -2, 61, -1], [-611, -20, -105, 41, 17, 72, 20, 355, 41, -40, -119, -20], [12, -15, 192, -59, 56, 69, -56, -37, -81, 56, 106, 81], [333, 28, 114, -98, 136, 70, -110, -556, -162, 55, 87, 142], [151, -48, 0, 217, -69, -19, 11, 250, 30, 11, 11, -88], [127, -23, -57, 35, 51, -52, 0, 0, 0, 47, 13, 34], [-41, -119, 45, 112, -41, 86, 53, 394, -36, 0, 12, -29], [-29, 60, -67, -57, -29, -61, -16, 426, -25, 0, -45, -74], [-71, 21, 26, -46, 11, 54, -21, -5, -46, 42, 102, 21], [334, -77, 75, 114, 31, 185, 42, -710, -104, -21, 19, -2], [333, -36, -34, -45, 34, 9, 0, 0, 0, -76, -74, -2], [-65, -141, -27, 163, -59, 18, 82, 48, 36, -41, -127, -168], [-125, -3, 13, 118, -19, 117, 8, 242, 30, -4, 14, 10], [-59, -63, 24, -157, -59, -64, 103, -249, 59, 0, 44, -15], [-338, 34, 136, -43, -128, 69, 0, 0, 0, 15, 117, -102], [144, 58, 64, -26, 86, 62, -58, -55, -26, 116, 24, 58], [-119, 153, -161, -196, -31, -87, 148, 90, -86, -74, 66, -8], [124, 8, -58, 82, -140, 27, 33, -136, 128, -33, -9, -21], [271, -17, 0, 226, 133, -37, -49, 126, -12, -49, -49, 96], [173, 119, 18, 116, 173, 94, -191, -1, -108, 0, -18, 155], [-55, 189, 131, -64, 51, 71, 0, 0, 0, 92, 34, 58], [-273, 82, -148, 1, -91, -79, -7, 272, 90, 7, 9, 8], [164, 88, -130, -141, -6, -115, 74, -402, -62, -37, -5, -42], [86, 16, -6, 2, 72, 128, 44, -216, -188, -22, 32, 10], [-106, -120, 189, -49, -21, 47, 48, 164, -6, -24, 93, 69], [154, 116, 0, -246, -19, 53, 26, 146, -27, 26, 26, 34], [-8, 88, 0, -113, 27, 82, 91, -26, 9, 91, 91, 109], [-83, 65, -164, 62, -89, 242, -65, 59, 62, 130, 30, 65], [-604, 26, 18, -14, -4, 147, -26, 286, -14, 52, 58, 26], [-144, -39, 10, -87, -11, -147, 70, 108, -25, -70, 2, -34], [-160, -138, 50, -22, -162, -192, 80, 240, 244, -40, -48, -88], [-43, -68, 41, -63, -43, -25, 100, -152, 101, 0, 57, 14], [-174, -85, -8, 123, -34, 153, 104, 159, 19, -104, -74, -89], [-507, -45, -8, 12, -66, 17, 0, 0, 0, 79, 116, -37], [-261, 13, 0, 278, -67, 129, 67, -256, -62, 67, 67, 62], [133, 31, 67, -79, 9, 34, 0, 0, 0, 63, 99, -36], [248, -119, 200, -35, -168, -91, 102, -331, 85, -102, 64, -19], [-491, 68, 104, 52, -6, 90, -184, 555, 70, 184, 56, 120], [-162, -206, 0, -79, -77, 66, 21, -130, -45, 21, 21, -11], [180, -270, 306, -56, -60, -116, -36, -324, 156, 18, 18, 36], [-77, 141, -155, 173, -77, -6, -15, 30, 1, 0, -92, -169], [36, 47, 42, -195, 25, -71, 45, -149, -138, -45, 181, 68], [-103, 32, -18, 48, 90, -10, -162, 368, -18, 81, -67, 14], [174, -154, 0, 163, -83, -34, -65, 226, -31, -65, -65, -117], [15, 274, -66, -181, 15, 21, 112, 13, 31, 0, 127, 142], [-220, -197, -169, -250, 173, 49, 0, 0, 0, -65, -37, -28], [-32, -113, -74, 19, 7, -287, 59, 123, 84, -59, -241, -150], [-93, -81, 311, 4, 107, 173, -168, 354, -46, 84, 146, 230], [203, 120, 16, -78, -20, 202, 0, 0, 0, 93, -11, 104], [-101, 251, -319, -165, 57, -254, -78, 280, -36, 39, -107, -68], [-13, -13, 10, 58, 40, -121, 0, 0, 0, -99, -76, -23], [422, 32, 105, -191, 180, -32, -32, -312, -191, 64, 234, 32], [373, -69, -69, -68, 91, 53, 69, -209, -68, -138, -24, -69], [756, -21, -44, 111, 66, -5, -82, -631, 59, 82, -168, -43], [64, 9, 141, -182, 23, 27, 0, 0, 0, 9, 141, -132], [-301, -119, 84, 47, -69, -6, 119, 163, 47, -238, -144, -119], [111, -139, -131, 39, 217, -264, 0, 0, 0, -87, -79, -8], [175, 223, 20, -35, 175, 154, -87, -115, -167, 0, 88, 263], [134, 192, -394, -312, 98, -389, 76, -205, -169, -76, 66, -5], [161, -417, 0, -21, 138, -98, 6, 127, 104, 6, 6, 40], [-35, -107, -97, 290, -129, 29, 72, -2, 186, -36, -168, -204], [-275, 161, -211, 321, -57, 184, -30, 580, 144, 15, -65, -50]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_43_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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