
// Make newform 1008.3.cg.l in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1008_cg();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1008_cg_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_1008_3_cg_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_1008_3_cg_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, 2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 1, 0], [0, 4, 0, 1], [0, 2, 0, -1]];
    Rf_basisdens := [1, 2, 2, 2];
    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_1008_cg();"
function MakeCharacter_1008_cg()
    N := 1008;
    order := 6;
    char_gens := [127, 757, 785, 577];
    v := [6, 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_1008_cg_Hecke();"
function MakeCharacter_1008_cg_Hecke(Kf)
    N := 1008;
    order := 6;
    char_gens := [127, 757, 785, 577];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [0, -1, 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], [2, 1, 0, 2], [-1, 2, -1, -2], [9, 9, -1, -1], [-6, -12, -2, 0], [5, -5, 2, -2], [-2, -1, 0, -1], [0, -15, -6, 3], [-12, 0, -2, 4], [7, -7, -15, 15], [0, 31, -16, 8], [-2, -4, -10, 0], [2, 0, -2, 4], [58, 29, 0, 1], [39, 39, 4, 4], [-13, 13, -25, 25], [-14, -7, 0, -32], [29, 29, -15, -15], [-6, 0, -10, 20], [53, -53, 16, -16], [0, 55, -10, 5], [68, 136, 4, 0], [126, 63, 0, -24], [-22, -44, -26, 0], [9, -9, -18, 18], [-102, -51, 0, -13], [0, -33, -38, 19], [35, 35, 26, 26], [-60, 0, -6, 12], [154, 0, -22, 44], [-162, -81, 0, -3], [-75, -75, 10, 10], [0, 0, 28, 0], [0, -33, -28, 14], [-113, -113, 5, 5], [-63, 63, -48, 48], [0, -65, -74, 37], [10, 20, -76, 0], [54, 27, 0, 48], [-147, -147, -9, -9], [16, 32, 52, 0], [0, 159, 42, -21], [-61, -61, -22, -22], [-48, 0, -54, 108], [-149, 149, 37, -37], [-118, 0, 58, -116], [156, 312, -60, 0], [45, -45, 63, -63], [158, 79, 0, 90], [0, 27, 116, -58], [-36, 0, 54, -108], [-11, 11, 28, -28], [190, 380, 68, 0], [-174, -87, 0, -102], [-201, -201, 55, 55], [115, -115, -44, 44], [34, 17, 0, 19], [61, 61, -80, -80], [72, 0, 110, -220], [47, -47, 93, -93], [-8, -16, 128, 0], [-80, -160, 48, 0], [115, -115, 7, -7], [34, 17, 0, -52], [0, 465, 8, -4], [0, -85, -66, 33], [-188, 0, 18, -36], [-93, -93, 67, 67], [-98, -196, 14, 0], [221, -221, 14, -14], [0, 63, 114, -57], [209, -209, 109, -109], [0, -1, 120, -60], [-364, 0, 34, -68], [266, 133, 0, 101], [9, 9, 38, 38], [-74, -37, 0, 126], [0, -117, 252, -126], [243, -243, 46, -46], [184, 368, -88, 0], [-4, 0, 38, -76], [-183, -183, -97, -97], [-2, -4, 18, 0], [-42, -21, 0, -45], [0, 171, -30, 15], [60, 0, 46, -92], [0, 7, 72, -36], [346, 692, -118, 0], [46, 0, -66, 132], [798, 399, 0, -39], [359, -359, 47, -47], [241, 241, -7, -7], [-12, 0, 182, -364], [0, 23, 70, -35], [-28, -56, 28, 0], [658, 329, 0, -38], [-233, 233, 184, -184], [54, 27, 0, 223], [0, 677, 84, -42], [-68, 0, 82, -164], [-423, -423, -38, -38], [123, -123, -285, 285], [0, -123, -272, 136], [-397, -397, -39, -39], [-3, 3, 268, -268], [0, 0, 336, 0], [826, 413, 0, -38], [-9, -9, 123, 123], [74, 148, -330, 0], [-370, -185, 0, 115], [-749, -749, 82, 82], [696, 0, -62, 124], [225, -225, -251, 251], [-182, 0, -134, 268], [-1077, -1077, 20, 20], [308, 616, 168, 0], [-45, 45, -33, 33], [0, 357, -16, 8], [-18, 0, -74, 148], [193, -193, 128, -128], [364, 0, -62, 124], [-366, -183, 0, 174], [-399, -399, -93, -93], [458, 229, 0, -237], [942, 0, -24, 48], [0, -149, -392, 196], [-370, -185, 0, -187], [-136, -272, -204, 0], [58, 29, 0, -216], [-109, -109, 21, 21], [510, 0, 110, -220], [0, 305, -250, 125], [520, 0, -98, 196], [-494, -247, 0, -398], [98, 196, -70, 0], [77, -77, 146, -146], [-107, 107, -47, 47], [270, 540, 342, 0], [627, 627, 32, 32], [396, 792, 216, 0], [0, 507, 36, -18], [161, 161, 205, 205], [-654, 0, -190, 380], [103, -103, -178, 178], [508, 1016, 272, 0], [682, 1364, 22, 0], [-49, 49, -484, 484], [-194, -97, 0, -173], [0, 525, -278, 139], [0, -703, 188, -94], [312, 624, 132, 0], [542, 0, -6, 12], [-1166, -583, 0, 49], [217, 217, 37, 37], [1278, 0, 34, -68], [0, -1063, 286, -143], [-10, -5, 0, 392], [24, 48, 512, 0], [823, -823, 28, -28], [0, 33, -350, 175], [-996, 0, -14, 28], [-1298, 0, 18, -36], [-322, -161, 0, 101], [-771, -771, 54, 54], [317, -317, 215, -215], [-599, -599, 301, 301], [421, -421, -60, 60], [-1192, 0, -110, 220], [494, 247, 0, -448], [99, 99, 275, 275], [-594, -1188, 306, 0], [0, 1245, 106, -53], [-311, -311, -168, -168], [735, -735, -71, 71], [-214, -428, 442, 0], [124, 0, 42, -84], [-585, -585, -252, -252], [556, 1112, 260, 0], [518, 259, 0, -102], [0, 139, -570, 285], [-172, -344, 316, 0], [-346, 0, -120, 240], [238, 119, 0, 256], [-1089, -1089, 199, 199], [139, -139, 508, -508], [1163, 1163, 2, 2], [7, -7, 461, -461], [0, -223, -396, 198], [-59, 59, 667, -667], [-1622, -811, 0, -76], [-750, 0, -2, 4], [0, -655, 134, -67], [722, 361, 0, -298], [189, 189, 47, 47], [-511, 511, -358, 358], [611, 611, -134, -134], [0, -103, 452, -226], [786, 1572, 66, 0], [230, 115, 0, 389], [-651, -651, 58, 58], [-1092, -2184, 28, 0], [730, 365, 0, 232], [167, -167, 482, -482], [664, 1328, -124, 0], [-329, 329, 328, -328], [74, 37, 0, -553], [0, -1317, -62, 31], [-282, 0, -112, 224], [29, -29, 113, -113], [0, 1121, 52, -26], [-642, -1284, 150, 0], [1094, 0, 110, -220], [278, 139, 0, 425], [-403, 403, -385, 385], [822, 411, 0, -350], [667, 667, -263, -263], [-231, 231, 174, -174], [0, 819, -54, 27], [-1554, 0, 160, -320], [0, 25, 860, -430], [-458, -916, 300, 0], [0, 777, -632, 316], [0, 533, -890, 445], [200, 400, -428, 0], [616, 0, 442, -884], [1178, 589, 0, 254], [363, 363, -545, -545], [-458, -229, 0, 455], [0, -2211, 178, -89], [1457, 1457, 184, 184], [-231, 231, -687, 687], [410, 0, 550, -1100], [-15, -15, 222, 222], [384, 768, 296, 0], [-177, 177, -465, 465], [638, 319, 0, 730], [0, 375, -180, 90], [282, 0, -238, 476], [-490, -980, 532, 0], [1383, 1383, -161, -161], [1286, 643, 0, 559], [697, -697, 245, -245], [0, 43, -1096, 548], [336, 672, -672, 0], [-26, -13, 0, 673], [444, 888, 596, 0], [-1127, 1127, 127, -127], [-1225, -1225, -19, -19], [-972, 0, 214, -428], [-1148, 0, 302, -604], [-354, -177, 0, -216], [633, 633, 255, 255], [858, 1716, -106, 0], [239, -239, -580, 580], [0, -1353, -686, 343], [-275, -275, -332, -332], [-437, 437, -651, 651], [378, 756, -378, 0], [-882, -441, 0, -18], [-463, -463, -359, -359], [1026, 0, -22, 44], [-165, 165, 602, -602], [294, 588, -602, 0], [-159, 159, -522, 522], [358, 179, 0, 3], [924, 0, 146, -292], [366, 732, -186, 0], [-314, 0, -250, 500], [2757, 2757, 82, 82], [1862, 931, 0, -158], [2203, 2203, -83, -83], [7, -7, -342, 342], [0, 1757, -2, 1], [-30, -60, -906, 0], [-1198, -599, 0, 635], [0, 129, 1202, -601], [929, 929, 368, 368], [0, -881, 248, -124], [418, 209, 0, -1031], [1837, -1837, -77, 77], [1211, 1211, -187, -187], [-808, -1616, -512, 0], [54, 108, 382, 0], [2702, 1351, 0, 95], [0, 1047, -302, 151], [-931, -931, -604, -604], [912, 0, -30, 60], [-795, 795, -667, 667], [-34, -68, 250, 0], [-951, -951, -330, -330], [173, -173, -661, 661], [0, 957, 472, -236], [130, 260, 692, 0], [704, 0, -302, 604], [-187, 187, -130, 130], [-1410, -705, 0, -161], [-1562, -3124, 338, 0], [-1034, -517, 0, -251], [-990, -1980, 20, 0], [1874, 937, 0, -604], [0, 2355, 316, -158], [1487, 1487, 105, 105]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1008_cg_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1008_3_cg_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_1008_3_cg_l(:prec:=4)
    chi := MakeCharacter_1008_cg();
    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_1008_3_cg_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_1008_3_cg_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1008_cg();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![441, 126, -9, -6, 1]>,<11,R![3969, -1134, 261, -18, 1]>,<13,R![7056, 0, 264, 0, 1]>],Snew);
    return Vf;
end function;