
// Make newform 105.3.n.b in Magma, downloaded from the LMFDB on 09 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_105_n();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_105_n_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_105_3_n_b();".
// 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_105_3_n_b();".
// 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 := [36, -288, 1020, -2136, 2949, -2844, 1999, -1050, 456, -140, 39, -6, 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], [60, -168, 267, -216, 154, -58, 24, -4, 1, 0, 0, 0], [342, -1596, 3417, -4221, 3629, -2024, 1020, -314, 101, -15, 3, 0], [-15420, 90966, -245406, 398817, -425733, 325036, -175924, 81494, -25122, 7471, -1133, 206], [-19920, 116286, -314580, 513735, -551705, 423174, -229488, 106722, -32912, 9825, -1489, 272], [-19920, 120738, -327096, 532593, -568295, 432722, -234304, 108206, -33388, 9895, -1503, 272], [4542, -29604, 86226, -147846, 163730, -128273, 70140, -33110, 10226, -3096, 468, -87], [47532, -292458, 809130, -1332291, 1438675, -1103022, 599452, -278334, 85962, -25609, 3887, -708], [-28878, 177174, -487725, 803904, -865921, 666770, -361606, 168658, -51971, 15562, -2355, 432], [65460, -387678, 1048110, -1697013, 1808051, -1370858, 742336, -341502, 105458, -31123, 4735, -852], [-34290, 206160, -561435, 914673, -979237, 746383, -404628, 187012, -57733, 17121, -2601, 471], [41988, -248820, 674814, -1100976, 1180277, -902535, 489230, -226856, 69974, -20828, 3159, -575]];
    Rf_basisdens := [1, 6, 12, 168, 168, 168, 42, 168, 84, 168, 84, 84];
    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_105_n();"
function MakeCharacter_105_n()
    N := 105;
    order := 6;
    char_gens := [71, 22, 31];
    v := [6, 6, 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_105_n_Hecke();"
function MakeCharacter_105_n_Hecke(Kf)
    N := 105;
    order := 6;
    char_gens := [71, 22, 31];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 0, 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, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0], [2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [2, 0, 1, 0, 0, 1, 0, -1, 0, -1, 0, 0], [0, 0, 0, -4, 2, 0, 1, -2, 1, -2, 0, 2], [3, 0, 1, 5, 2, 2, 1, 2, 0, 1, 2, -1], [-10, 0, 0, -6, 1, 3, 3, -2, 1, 2, 0, -1], [0, 0, -2, 1, 0, -1, -2, 3, 1, 0, 2, 1], [2, -2, 7, 2, 0, -4, 0, 0, 0, 0, 7, 2], [-6, 0, 2, 1, 0, -2, 1, 1, -1, -4, 0, 1], [15, 7, 0, 8, -4, -3, -3, 1, 1, -1, 0, -3], [-3, 5, 3, -3, -6, -2, 0, 0, 0, 0, 3, -5], [8, -2, 6, 16, -8, -12, 0, 3, -3, 3, 12, 4], [-11, 0, -2, 0, -10, 10, 2, -1, -1, -1, 0, 0], [2, 3, -1, -6, 0, 4, -1, -3, -4, 9, 1, -1], [0, 0, 0, 10, -9, -5, 1, -2, 1, -2, -7, 1], [-31, -9, 4, -15, 4, -15, 0, 1, -2, -1, 2, 5], [-5, 0, 10, 0, 0, 5, 4, -9, -5, 6, -10, -5], [-3, 3, 0, 4, 11, 12, -2, -5, -8, 7, -4, -4], [-56, -10, -6, 1, -6, 4, -3, 3, 1, -2, 0, 1], [22, -8, 4, 9, 6, 0, 9, -4, -1, 4, 2, 2], [7, -9, -26, 9, 0, -16, -10, -4, 6, -6, -26, 11], [-2, 3, 2, -6, -29, -23, 2, 7, -3, 5, 4, -8], [-9, 1, 0, 10, 16, -1, -11, 12, 1, 9, 0, 2], [38, -1, -10, 77, 3, 1, -1, -8, 6, -7, -20, 3], [7, 5, 4, 5, -4, 39, 0, 3, -6, -3, 2, -1], [45, -8, 10, -41, -14, -4, -11, 15, 4, 3, -10, -4], [-10, 13, 16, -10, -14, -2, 1, 1, -2, 1, 16, -13], [0, 0, 0, -19, 63, 31, -2, 4, -2, 4, -16, 1], [38, 16, 34, -2, -12, 16, 26, -16, -12, -6, 0, -2], [37, -2, -35, 5, -26, 16, -29, 22, 12, -3, 0, 5], [9, 11, -22, -4, -4, -5, -10, 15, 5, 0, 22, 16], [2, -2, 0, -16, -7, -3, -1, 8, 3, 0, 20, -7], [-67, 9, -4, -132, -31, -13, -2, 14, -18, 16, -8, -16], [88, -4, -16, 86, -2, -14, -4, -10, 22, -8, -16, 2], [-3, 3, 0, -35, 35, 28, -13, 17, -19, 29, -8, -12], [86, 0, 26, 40, 3, 45, 21, -6, -9, 6, 13, -3], [-40, 26, -42, -42, -8, 34, 8, 2, -2, 4, -42, -28], [18, -6, -29, 30, 24, 12, 6, 6, 6, 0, -58, 6], [22, -19, 11, -28, -16, 6, -3, -3, -6, 15, -11, -25], [-3, 3, 0, -59, 24, 25, 13, -35, 7, -23, -4, -17], [-15, 1, -10, -20, 17, 19, -10, -26, 6, -16, -20, 8], [108, 24, -2, 118, -16, 26, -36, -6, 2, -16, -2, -14], [-2, 2, 0, -41, 40, 8, 9, -24, 5, -16, -4, 30], [92, -8, -15, -6, 18, -6, 22, -20, -8, 10, 0, -6], [-23, -3, -76, -11, 1, -18, -9, 1, 7, -1, -38, 2], [-70, 23, -58, 0, -7, 7, -8, 4, 4, 4, 0, 0], [-48, -2, 10, -82, -54, -58, -14, -4, -24, 10, 20, 18], [-96, 2, 12, -40, -9, -15, -39, 16, 7, -16, 6, 7], [-68, 17, -2, 71, -58, -3, -18, 21, 3, 12, 2, 20], [-100, -32, 40, -112, 50, 24, 26, -10, 32, 2, 40, 20], [0, 30, 44, -14, 16, 12, 74, -58, -30, 12, 0, -14], [-136, -2, 96, -72, 5, 21, 12, -8, 4, 8, 48, -3], [-26, -6, 36, -48, -20, -32, -4, 25, -33, 29, 72, 16], [-2, 3, 8, 12, 48, -10, 7, 3, 10, -27, -8, 13], [16, -16, 0, 82, 36, -2, -6, 60, 26, -4, 30, -8], [10, 6, 8, 6, -4, 84, -30, 2, 26, -2, 4, -2], [-35, -24, 0, 44, -36, -9, -18, 27, 9, 0, 0, -15], [0, 0, 0, -25, 84, 30, 15, -30, 15, -30, -36, 24], [-56, 26, -96, 1, 0, -2, 3, 0, -2, -5, 0, 1], [-80, 10, -40, -41, -4, -36, 21, -2, -17, 2, -20, -6], [68, -11, 9, 130, -41, -63, 6, 51, -39, 45, 18, 16], [43, 1, 30, 89, -17, -15, -3, -9, 3, -6, 60, 1], [-83, -61, 72, -49, 38, 15, -6, -15, 36, 15, 36, 23], [55, 16, -28, -41, 82, -14, 23, -9, 14, -51, 28, 30], [-202, 25, -86, -196, -52, -48, -31, -13, 20, -19, -86, -19], [-3, 20, -50, -1, 0, 42, 14, 20, -42, 18, -50, -18], [-23, 21, 32, -23, -17, 63, 77, -73, -27, 42, 0, -23], [10, -10, 0, -26, 112, 18, -14, 58, 6, 18, 30, 46], [-40, -36, 44, -104, 60, -12, 24, -12, 60, -36, 88, 48], [34, -4, -92, 26, -7, 81, -51, 18, 15, -18, -46, 11], [183, -45, -22, 174, 70, 41, 1, -26, 61, -17, -22, 36], [233, 29, -70, 110, -8, 63, -15, -13, 41, 13, -35, -21], [-114, 10, 58, -107, -70, -113, -9, 12, -31, 5, 58, -3], [61, -6, -86, 0, 14, -14, 8, -4, -4, -4, 0, 0], [92, -27, 67, -90, -6, -2, 29, -27, 2, -33, -67, -25], [-5, 5, 0, -33, 20, 31, -26, 37, -36, 57, 122, -27], [13, -14, -14, -27, 10, 14, 37, -51, -14, -9, 14, -28], [-57, 51, -70, -66, -50, -7, 40, 13, -17, 22, -70, -60], [191, -9, 104, 100, 0, 57, 15, 9, -33, -9, 52, 9], [142, 12, -8, 291, -158, -134, -7, -8, -6, -1, -16, -17], [-25, 15, -2, 16, 29, -61, 0, 24, -8, -56, 0, 16], [-14, 14, 0, -42, 4, 8, 18, -78, -10, -22, -184, 30], [169, 25, 4, 315, -1, 49, 23, 25, 21, 2, 8, -73], [129, 12, 44, -128, -144, -1, 28, -27, 1, -30, -44, 13], [-94, 28, 82, -94, -14, 28, 16, 16, -32, 16, 82, -28], [-140, -52, -86, 17, -80, 46, -121, 86, 52, 1, 0, 17], [-202, -12, -16, -217, -46, -131, 47, 2, 11, 17, -16, -3], [-186, 10, -44, -389, -82, -62, 17, 43, -9, 26, -88, -37], [-79, -42, 3, -3, -30, 36, -93, 42, 48, 57, 0, -3], [-142, 28, 4, 142, -92, 0, 36, -36, 0, -36, -4, 28], [-234, -22, 24, -124, 18, -114, 0, -14, 28, 14, 12, 4], [-11, 11, 0, 374, 5, 50, -4, -25, -26, 19, -126, -62], [-198, -60, 38, -2, 18, -14, -2, -2, 2, 8, 0, -2], [-112, -15, 52, -123, -46, -133, 48, 15, -19, 26, 52, 4], [-18, -58, -50, -46, 94, -22, 10, -34, 54, -44, -100, 106], [-14, 20, -44, -10, 92, 24, 30, -54, -24, 18, 44, -4], [287, 13, 12, 127, 10, 81, 57, -33, 9, 33, 6, -23], [8, 12, -34, -41, -144, 33, 51, -84, -33, 15, 34, -21], [268, 3, -46, 263, -78, -155, 40, 25, -45, 30, -46, -8], [154, 46, 16, 26, -2, -50, -74, 76, 24, -54, 0, 26], [-6, 6, 0, 192, -167, -55, 7, -32, -5, -8, -89, -39], [-36, -20, -52, -26, 18, -174, 24, -16, 8, 16, -26, 2], [-124, 34, -58, -92, -126, -152, -79, 17, -66, -15, -58, -2], [20, -20, 0, -201, -139, -115, 16, 28, 56, -52, 48, 31], [45, -89, -60, 24, 43, -6, -54, 3, 48, -3, -30, 46], [190, 7, 124, 358, 9, 23, 22, 101, -57, 79, 248, -36], [154, -35, 20, -116, 196, -38, -91, 129, 38, 15, -20, 3], [-6, 6, 0, -252, -30, 30, 36, -90, 24, -66, -92, -72], [-99, -23, -12, -176, 29, -17, -22, -50, 6, -28, -24, 68], [172, 3, 11, -149, -30, -23, -52, 75, 23, 6, -11, 26], [9, -9, 0, 157, 62, 21, 10, 7, 28, -29, 179, -7], [534, 0, -40, 16, -12, -20, 40, 4, -28, -76, 0, 16], [-418, -52, -92, -219, 36, -144, -6, -20, 46, 20, -46, 16], [-298, -6, -12, -30, 6, 54, 78, -84, -24, 66, 0, -30], [26, -26, 0, -296, -94, -94, 13, 52, 65, -52, -146, 16], [-107, 17, 28, -201, 51, 85, -13, -71, 45, -58, 56, -21], [110, 10, 234, 64, -14, -126, -48, 18, 12, -18, 117, 4], [348, 90, 43, 376, -64, 80, -72, 12, -52, -16, 43, -62], [-52, 118, -136, -4, -30, 38, 84, -48, -40, -28, 0, -4], [-124, 68, 248, -63, -33, 153, 66, -2, -62, 2, 124, -35], [-27, 43, 86, -13, 9, 17, -33, -3, 23, 62, 0, -13], [-134, 54, -39, 150, 84, -16, 10, 6, 16, -42, 39, 70], [2, -2, 0, 132, -169, -65, 3, 0, 7, -8, 174, -45], [22, -1, -12, -15, -262, -7, 28, -21, 7, -42, 12, 6], [-76, -2, 32, -7, -120, 134, 69, -45, -31, -10, 0, -7], [41, 0, 256, 0, 2, -37, 132, 9, 23, 50, 256, -41], [78, -48, -10, -60, 222, -18, -24, 42, 18, -12, 10, -30], [217, -11, 45, 454, 123, 101, -20, 38, -78, 58, 90, 42], [-88, 29, -45, 57, -82, 31, 2, -33, -31, 60, 45, -2], [7, -7, 0, 192, -57, -86, 3, 15, 17, -13, 98, 94], [398, 10, 167, 8, 24, -40, -48, 36, 20, -4, 0, 8], [202, 7, -254, 181, -14, -35, 40, -23, 67, -2, -254, -28], [174, 46, -76, -16, 102, -70, 96, -72, -40, 8, 0, -16], [-196, -8, -76, 184, 64, 12, 15, -27, -12, 9, 76, -20], [-73, -31, -24, -115, 135, 73, -31, -44, -18, -13, -48, 93], [294, -62, -38, 142, 36, -30, 6, -10, 14, 10, -19, 26], [-268, -136, 48, -124, 58, -126, -42, 20, 2, -20, 24, 78], [-78, 73, -54, -188, 299, 445, 32, 1, 63, -31, -108, -178], [23, -23, 0, -3, 218, 43, 3, 63, 49, -29, 0, 63], [-216, -23, -90, -460, 213, 167, 28, 14, 42, -14, -180, 18], [301, -169, 220, 294, 60, -225, 41, 20, -33, 27, 220, 162], [-27, 27, 0, -73, -369, -90, 3, -87, -51, 21, -66, -108], [368, -68, 60, -24, 90, -42, 136, -104, -56, 16, 0, -24], [-304, 16, -252, -127, -33, 105, -72, 50, -28, -50, -126, 17], [84, -88, -36, 167, -14, -190, 1, -85, 87, -86, -72, 175], [51, 11, 47, 176, 181, 203, -74, -94, -54, -20, 94, 52], [-344, 134, 76, -202, -37, 165, 195, -60, -75, 60, 38, -97], [79, -24, 8, -64, -348, -15, -24, 39, 15, -6, -8, -9], [118, -49, 99, 106, 178, 246, 37, 1, 10, 13, 99, 37], [-476, -45, -165, -488, -96, -294, 15, -21, 54, -9, -165, 33], [-230, 20, -104, -403, 116, 156, -57, -18, -96, 39, -208, 17], [361, 42, 114, -34, 168, -100, 236, -169, -101, 1, 0, -34], [-194, -69, 50, 192, -168, 2, -131, 129, -2, 135, -50, -71], [-8, 8, 0, -35, -32, 2, -117, 210, -133, 242, 86, -12], [-364, 124, -220, 29, 22, -80, -47, 67, 9, -78, 0, 29], [-274, 99, 12, -251, 2, 225, -62, 7, -37, -16, 12, -76], [94, -48, -138, -96, 258, 2, -101, 99, -2, 105, 138, -50], [-83, -82, -90, -224, 124, -40, 58, 11, 105, -47, -180, 106], [-73, -171, 208, -21, 70, -123, -12, 31, -50, -31, 104, 101], [-568, 115, -74, -580, -14, 190, 61, 25, -38, 37, -74, -127], [-284, -76, 206, 24, -80, 32, -72, 72, 24, -48, 0, 24], [43, 22, -252, -2, -16, 20, -140, 67, 71, 77, 0, -2], [-159, -29, -6, 226, -92, -67, -116, 183, 67, -18, 6, 38], [-18, 18, 0, -344, -41, 33, -25, -4, -61, 68, -76, -53], [114, -134, -138, 46, 78, -114, 126, -22, -82, 22, -69, 56], [24, -24, 0, -87, -161, -41, 6, 60, 54, -36, -162, -151], [-324, 30, -76, -149, -28, -156, -3, 26, -49, -26, -38, -2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_105_n_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_105_3_n_b();".
// 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_105_3_n_b(:prec:=12)
    chi := MakeCharacter_105_n();
    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_105_3_n_b();".
// 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_105_3_n_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_105_n();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![7056, -17136, 34728, -24456, 17872, -4964, 3598, -842, 451, -50, 25, -2, 1]>],Snew);
    return Vf;
end function;