
// Make newform 1800.4.a.r in Magma, downloaded from the LMFDB on 06 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1800_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_1800_4_a_r();".
// 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_1800_4_a_r();".
// 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_1800_a();"
function MakeCharacter_1800_a()
    N := 1800;
    order := 1;
    char_gens := [1351, 901, 1001, 577];
    v := [1, 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_1800_a_Hecke( : Kf := Kf)
    return MakeCharacter_1800_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 := [[0], [0], [0], [-2], [34], [68], [-38], [4], [152], [46], [-260], [312], [-48], [200], [104], [-414], [2], [-38], [244], [-708], [378], [-852], [844], [1380], [-514], [702], [-898], [876], [602], [1350], [366], [-498], [-2026], [2460], [3362], [2096], [-2092], [-244], [2064], [1258], [3986], [2570], [-4684], [-214], [3014], [-1792], [-4540], [-6506], [-3696], [-3386], [3306], [4188], [5462], [3366], [1158], [8304], [7478], [-6792], [2296], [-3980], [1972], [9254], [5888], [4604], [8026], [2838], [-1020], [-814], [-4544], [6978], [2818], [-744], [6454], [5900], [-11876], [-552], [1722], [-4576], [-2892], [-230], [15438], [12294], [-17488], [8698], [8536], [-8712], [5484], [-19402], [13578], [-6222], [-15260], [-9812], [7226], [6750], [-4156], [14088], [-16970], [8500], [-20620], [5314], [-24104], [-23582], [-2680], [25004], [-11180], [15862], [15036], [-12786], [-13464], [8518], [11082], [26568], [3282], [-2308], [-24572], [-2136], [5508], [-4536], [-27914], [-22842], [16458], [16050], [-5314], [-15876], [-13372], [3230], [-6154], [-20264], [25354], [13344], [-28452], [-5784], [852], [5704], [24828], [-13298], [-642], [20236], [11562], [-18984], [-2332], [19126], [-37102], [-11304], [-974], [-16480], [-11192], [-34278], [-14020], [-30528], [-2932], [-7116], [35140], [-20296], [-19512], [16720], [7340], [-48932], [-30298], [-8414], [23912], [-22866], [-738], [-44098], [34426], [-30216], [4592], [24276], [11750], [27490], [-47326], [9070], [46472], [-20654], [14732], [-19404], [-40124], [-47014], [-45310], [-6242], [52282], [-7530], [-28712], [-28714], [-52592], [-25774], [316], [30460], [23846], [13564], [-46862], [70152], [43940], [71354], [3644], [40942], [-38622], [16164], [-15458], [35824], [25866], [34396], [-23924], [-83634], [64290], [-64130], [36556], [64472], [60276], [35012], [29090], [-45358], [88870], [38616], [-5252], [-68286], [34118], [-65548], [2904], [-44302], [-83602], [65800], [58792], [20850], [64572], [-72530], [-65522], [37064], [107626], [-92134], [15092], [-64188], [-25144], [89308], [73452], [12960], [67938], [61662], [-43262], [-115812], [54512], [101788], [83330], [28450], [104242], [92444], [-66874], [-23782], [-95180], [44824], [82032], [-67328], [-21672], [-91294], [96106], [-8922], [-14182], [-103716], [-60654], [21738], [-42514], [39136], [-17154], [-120512], [88342], [-55604], [89650], [87624], [33972], [39710], [106046], [-140848], [-11262], [124436], [-82190], [-57578], [65168], [27914], [63386], [-2634], [65304], [70968], [101992], [-103946], [-81088], [-113636], [87766], [53070], [43536], [-23232], [-94166], [-142908], [-97662], [143298], [66200], [-49854], [118124], [66066], [65194], [-56112], [-71598], [-61290], [-69064], [-89804], [25236], [-19234], [-31428], [-87746], [-69924], [-2036], [-38464], [-79074], [1860], [122648], [-53048], [-105002], [3802], [36420], [-80830], [-100904], [-71404], [121066], [48774], [15026], [47594], [-49578], [-98132], [-51536], [-142784], [66642], [119750], [12770], [31708], [-100348], [-42716], [-187764], [-142858], [75354], [158074], [-38610], [129412], [-1494], [-175754], [-55336], [-131494], [19546], [-75050], [-92080], [65316], [100338], [3988], [168150], [127846], [-183626], [-28678], [-77998], [-170736], [48274], [-150418], [-133136], [-38780], [-63680], [103408], [-201246], [-64764], [-88594], [-194646], [-105626], [-31690], [-74262], [-61348], [220600], [-81042], [-63960], [48784], [-53670], [-179992], [61078], [-41076], [-211346], [49466], [-34834], [245574], [-86166], [93996], [106928], [171940], [-32808], [-35256], [248096], [-231122], [126858], [186330], [-194236], [59408], [35710], [-5080], [-238392], [-139540], [118506], [234510], [-229458], [-442], [-83946], [75270], [16452], [-241144], [153540], [-91732], [-14562], [232742], [-48066], [124660], [105148], [36338], [65406], [-262328], [252158], [-37338], [-140256], [-54606], [145700], [-105856], [-127826], [-78798], [64110], [197052], [105360], [-268228], [282992]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1800_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1800_4_a_r();".
// 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_1800_4_a_r(:prec:=1)
    chi := MakeCharacter_1800_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_1800_4_a_r();".
// 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_1800_4_a_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![2, 1]>,<11,R![-34, 1]>,<17,R![38, 1]>],Snew);
    return Vf;
end function;