
// Make newform 1450.4.a.c in Magma, downloaded from the LMFDB on 31 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1450_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_1450_4_a_c();".
// 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_1450_4_a_c();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1450_a();"
function MakeCharacter_1450_a()
    N := 1450;
    order := 1;
    char_gens := [1277, 901];
    v := [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_1450_a_Hecke(Kf)
    return MakeCharacter_1450_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]];
    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 := [[-2], [2], [0], [-12], [-48], [2], [24], [-48], [-8], [-29], [-328], [280], [-154], [206], [102], [-546], [548], [50], [480], [816], [-124], [296], [408], [1558], [-304], [-1330], [-848], [-736], [-1706], [-1172], [2270], [1468], [1952], [1268], [-882], [2056], [3036], [-2678], [-1732], [1858], [-2580], [1610], [2764], [-2420], [2946], [416], [-1688], [1728], [-36], [-4846], [2718], [2096], [-1458], [-3144], [3498], [7974], [-1514], [2340], [-1490], [-230], [2008], [612], [1722], [928], [-910], [5952], [7972], [-520], [10348], [2298], [-6106], [-2596], [-110], [8898], [8524], [-12936], [6174], [7762], [1046], [5122], [13276], [-12070], [-8240], [10784], [5592], [-7730], [1178], [-4522], [1190], [-8020], [6850], [15408], [5492], [-15588], [-9756], [-18718], [20286], [11738], [-14948], [-8890], [13944], [-15186], [514], [-24622], [-25276], [-20452], [4244], [14686], [3384], [-13186], [3846], [-8330], [21408], [-13396], [-3848], [-4898], [1600], [-1104], [-9432], [15968], [-3758], [-1486], [25268], [2196], [-23836], [-32294], [15966], [25680], [-23998], [-14284], [-5240], [31794], [4696], [23296], [-954], [27182], [-2448], [-9772], [-26496], [20686], [4804], [-17218], [27294], [-35430], [-38770], [-3888], [-46196], [26906], [-2956], [8648], [14294], [-25978], [35084], [-22602], [12402], [22392], [8504], [54610], [-37210], [25750], [31226], [-38618], [-44886], [-12460], [27826], [48778], [14072], [-22496], [47646], [30068], [9820], [6870], [47328], [51776], [-52832], [-40854], [-30108], [-34194], [-21466], [-19982], [26422], [31924], [-65078], [-25326], [52760], [-9266], [-71904], [-10474], [-5622], [-59640], [-2430], [70614], [16220], [33106], [21398], [-24702], [48422], [-74678], [71858], [-3952], [114], [4648], [4076], [-53834], [9488], [31834], [-85444], [-22484], [19194], [42176], [46784], [-21450], [56398], [85414], [68616], [48914], [-4688], [-40854], [-98312], [-216], [29162], [67024], [10774], [-54298], [33924], [-23234], [-16520], [34712], [-84258], [76564], [15472], [-70684], [37172], [-29546], [-4428], [4850], [27410], [96828], [-72836], [9184], [-81874], [-42468], [90368], [-51342], [-54882], [-22176], [-102876], [-68212], [43300], [-66802], [59420], [17718], [29698], [28730], [62460], [43356], [-121338], [122230], [-73474], [-50134], [28430], [25766], [86430], [-118616], [73872], [2740], [-37206], [-86198], [74622], [67086], [-31334], [46276], [143378], [-73912], [109836], [-100322], [109054], [-129318], [44950], [52356], [-55316], [65416], [-43716], [2398], [129746], [70064], [12072], [49428], [-4688], [51326], [13418], [-62084], [-34374], [76064], [77852], [120738], [-89440], [-76794], [155388], [-40670], [22280], [-35074], [92164], [-11338], [147204], [-109566], [-31646], [-966], [136920], [28450], [36172], [141090], [31774], [-25328], [-123424], [107798], [104300], [31632], [-125606], [164522], [145776], [-5158], [-38090], [56726], [-3498], [-36322], [17764], [89628], [-70130], [-5378], [-3998], [-86422], [-25680], [40670], [-10516], [-93396], [-116302], [-2772], [-208170], [130820], [120820], [161058], [85686], [124936], [-153102], [4020], [151874], [-28486], [124444], [194780], [202084], [-59506], [-61678], [182028], [167282], [5772], [31596], [-4188], [129148], [128532], [188226], [-172742], [127794], [68780], [68294], [66160], [83976], [18916], [158214], [-120252], [-23692], [-154608], [-175010], [-84584], [-191154], [74208], [-215764], [-128980], [-173466], [-133558], [-188722], [108722], [153154], [123724], [-170764], [-49624], [-100716], [234394], [185746], [-113114], [42858], [238846], [182352], [178950], [98916], [-11454], [-31704], [-226490], [180308], [66450], [229846], [-54000], [229098], [-75894], [-81702], [144776], [-11482], [33258], [-182602], [282940], [215658], [188486], [114640], [109468], [94940], [202078], [220880], [-43128], [120976], [184026], [-7978], [109480], [73334], [-175180], [-135578], [253238], [33980], [288250], [-23180], [-226620]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1450_4_a_c();".
// 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_1450_4_a_c(:prec:=1)
    chi := MakeCharacter_1450_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_1450_4_a_c();".
// 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_1450_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-2, 1]>,<7,R![12, 1]>],Snew);
    return Vf;
end function;