
// Make newform 832.4.a.z in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_832_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_832_4_a_z();".
// 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_832_4_a_z();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_832_a();"
function MakeCharacter_832_a()
    N := 832;
    order := 1;
    char_gens := [703, 261, 769];
    v := [1, 1, 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;

function MakeCharacter_832_a_Hecke(Kf)
    return MakeCharacter_832_a();
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 := 4;
    raw_aps := [[0, 0], [1, 3], [1, 1], [-1, 11], [46, -12], [13, 0], [1, 17], [-58, 32], [-92, -12], [-26, 96], [60, -34], [-107, 5], [-104, -22], [215, -143], [-157, -121], [44, 30], [-122, -124], [624, -190], [-82, 232], [181, -231], [358, -260], [484, 40], [888, 182], [-554, 388], [-210, -508], [-700, 142], [456, -304], [1076, 140], [-739, -43], [1010, 236], [16, -344], [1171, -567], [-2124, -202], [171, -847], [2378, -244], [1665, 441], [-878, -924], [2180, 430], [816, 902], [2756, -1114], [-109, 29], [-200, 558], [-2042, -874], [1000, -206], [911, 1395], [-1350, 670], [747, 537], [1477, 1737], [1712, -1018], [-369, -101], [713, 621], [1999, -993], [-1070, 2536], [-2424, -1092], [1045, -151], [-4476, 480], [-3024, 2190], [2067, -1193], [572, -3402], [2774, -484], [-4260, -1056], [3169, -1487], [-4578, 1748], [-3442, 2858], [4779, -3345], [2202, -2580], [-4444, 122], [155, -1841], [5579, 1753], [-6927, 409], [-4916, -1650], [2616, 54], [-5238, 858], [236, 2010], [-2456, -378], [-6587, 2721], [2662, -4392], [9022, -696], [2912, 530], [-900, 5646], [2793, -6781], [-123, -6139], [-7065, -1417], [-11189, -1909], [-426, -2190], [9917, 111], [-2554, -1276], [10298, -2216], [-9403, 1669], [-10928, 1734], [10396, 1008], [11283, -2137], [8128, -1070], [-953, 6329], [2312, -178], [10206, -4394], [838, -112], [-12333, 1303], [-9068, 4580], [-8593, 5763], [8473, -1301], [-737, -797], [-281, 2025], [11347, -8085], [-1907, 3555], [-814, -4152], [-1428, -1566], [-17094, -4416], [-3806, 5578], [7193, -1559], [-8438, -1134], [8894, -9088], [10248, 4610], [9692, 1534], [21901, -1235], [19614, 3976], [-5442, -6848], [-3994, 11282], [9600, -7682], [-5668, 7028], [-11934, 9636], [1769, -6007], [-5716, -1538], [21404, -1986], [-12624, 5846], [-18220, 10266], [8594, 1964], [-3802, -4854], [-21010, -1238], [-6125, 1199], [14964, -8978], [18007, -729], [22856, -1704], [10644, -4218], [8694, 7068], [-6360, 474], [-12475, -131], [12760, 5978], [-4078, -10156], [2531, -10489], [15180, 1522], [-12775, 4201], [4234, 1350], [-6146, 540], [12718, -12764], [14104, 6446], [-7185, 595], [1806, 15436], [7660, -16580], [11939, -1397], [16575, 9371], [3465, 2725], [-15859, 13307], [34184, -4164], [-18077, -4875], [34534, -690], [-8504, -4756], [51908, -2450], [-8714, -3532], [11519, 13027], [23662, -2964], [-6373, 3859], [30585, 2509], [38101, -7249], [11922, 7136], [10959, 10859], [4926, 8902], [802, 18784], [-22910, 1680], [-31874, 17852], [15046, 13632], [-48245, 6607], [-10768, 14792], [-33904, 13418], [750, 4466], [34947, -10693], [18004, 10350], [-20326, -3692], [-39740, 6348], [3220, 18394], [12296, -24218], [-16156, 16456], [-16414, -880], [-16070, 25848], [-21428, -6022], [10170, 3364], [31418, -2884], [24482, -7548], [-42204, 7814], [62040, 1390], [1721, -25679], [6060, -24318], [-28855, 12595], [71498, -4316], [-25739, -3909], [-42302, 680], [-9896, 4130], [-36232, -7258], [24028, -17834], [41934, -18554], [28929, -27119], [17852, -27960], [32687, -3045], [5445, -10731], [10368, 11194], [-23050, 23540], [-48087, 45], [18924, 3876], [-59462, 1096], [-14775, -4025], [20726, 25100], [-14914, 17828], [-10348, -9576], [-3982, -7656], [45529, -14707], [-34448, 2586], [-8020, -19528], [-26671, 15453], [-35588, 37406], [11111, -31293], [-70524, 2470], [41305, 1713], [30348, 17150], [32081, 19981], [65857, -10521], [15190, -25692], [10603, -4413], [-56456, 20556], [-70606, 6350], [55726, -7012], [63482, 15932], [-55124, -4860], [38456, -36518], [-35769, -12645], [30253, -5993], [76455, -20401], [48894, 14068], [31931, -18641], [-13040, 1860], [34806, -49810], [31106, -32364], [55567, 18257], [9176, 35596], [-38921, -4949], [-34, -12724], [-35840, 9368], [46821, 8013], [22508, 9358], [-50598, 24036], [-20234, 10530], [18469, -8531], [-68470, -9816], [28021, -30251], [-5549, 17791], [43796, 28634], [39706, -22672], [-26772, -9382], [-38090, -2336], [-4536, 44078], [41234, -21568], [-86756, 28180], [-35309, 31369], [-10013, 25631], [74178, -37240], [48624, -9750], [75659, -3367], [-30603, -39075], [28, 41350], [40092, -17530], [-1140, -11898], [22256, 26234], [112174, -9832], [-9278, 33296], [17812, 37980], [-24850, -31664], [-71360, -13054], [105014, -10736], [-24346, 40640], [-125892, 1918], [3121, 33791], [-91984, 40324], [39021, 22557], [-62906, 21318], [70410, 10100], [-9356, -1298], [62950, -41958], [-28339, -25631], [-30133, 53951], [-1313, -33157], [90746, -7496], [98412, 1958], [49119, -7011], [73472, -2446], [47774, -54276], [9074, -54348], [9644, 7186], [16746, 49458], [-4044, -37374], [1729, -38589], [-46930, 244], [-92621, 43643], [84349, -46899], [-137074, 8170], [86772, -7268], [7001, 25843], [86352, -59982], [-111441, -23063], [-104900, -10954], [-53188, 40042], [-61292, 20642], [72976, -4164], [8851, -54633], [-51061, -57], [49084, 26236], [-104127, -30351], [135553, -12703], [-91018, 56616], [64880, -44374], [-80336, -11830], [19638, -22656], [-27436, -30000], [70312, -51214], [109176, 19274], [-16747, -40035], [14360, -32414], [-70142, -23136], [121862, 11332], [-17848, -3578], [99952, -34000], [-76356, -7110], [15934, 17352], [119208, 24102], [-70788, -8456], [11520, 72602], [-32360, 80606], [-5744, 29806], [132774, -16776], [-108004, 35526], [-19912, -14214], [-62094, -23370], [122297, 4929], [-68849, 20059], [-135711, -16863], [-26042, 48514], [-33781, 85911], [-134557, -18139], [27290, 11220], [98808, -61510], [-32231, -37807], [-24014, 12044], [60686, -12600], [44574, 16132], [-97919, 57913], [-65456, 43000], [33110, 38468], [-35190, 3580], [10941, 7493], [-14258, -42120], [1623, 90191], [-99295, 46629], [113234, -13620], [-92746, -19736], [-346, 33910], [-75292, 8850], [71988, -16424], [-91571, 13029], [-88869, -36129], [69128, 19510], [57821, -86643], [4945, -1421], [-3047, 39151], [15631, 50835], [-60358, 10216], [-123816, -12676], [-34214, 55024], [-160446, -12148], [-101290, 7514], [-74812, 92638], [-93174, -22168], [110582, -28520], [2902, -77192], [24822, -57036], [88604, 12114], [72386, -86856], [-12976, 83386], [-70221, -24657], [-57589, -49485], [124840, -77238], [83506, -24468], [-13604, -48208], [74410, -96336], [-63013, -3777], [-68362, 15116], [39219, 84297], [29271, -31637], [177285, 33281], [-10723, 57537], [89897, 63729], [83212, -90660], [35389, -71707], [-31107, 92093], [177026, -45196], [210093, -17755], [187184, -34478], [208099, -15257], [142326, -58778], [-39009, -87917], [-24816, 77386], [43566, -70180], [4808, -44518], [20573, 9169], [-219654, -14408], [184733, 9951], [98615, -25183], [-18299, 51953], [83788, -7994], [138665, -29547], [15784, -85508], [162730, -6600], [-1894, -55994], [42308, -83546], [13418, -72596], [-54696, -67566], [-7719, 2283], [-121156, 100318], [-186278, 29292], [97747, -120731], [114256, -32150], [-69840, -14806], [21970, -30246]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_832_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_832_4_a_z();".
// 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_832_4_a_z(:prec:=2)
    chi := MakeCharacter_832_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_832_4_a_z();".
// 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_832_4_a_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_832_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-32, -5, 1]>,<5,R![-2, -3, 1]>],Snew);
    return Vf;
end function;