
// Make newform 1694.4.a.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1694_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_1694_4_a_a();".
// 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_1694_4_a_a();".
// 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_1694_a();"
function MakeCharacter_1694_a()
    N := 1694;
    order := 1;
    char_gens := [969, 365];
    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_1694_a_Hecke(Kf)
    return MakeCharacter_1694_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 := [[-2], [-10], [-14], [-7], [0], [16], [-108], [-116], [68], [-122], [-262], [130], [-204], [396], [166], [442], [702], [-196], [-416], [492], [-408], [-600], [1212], [1146], [-482], [-1216], [1406], [588], [-154], [-1902], [-64], [1584], [998], [-276], [-1318], [984], [1706], [1168], [-72], [4328], [-1924], [2230], [2176], [3126], [1122], [-5586], [-3372], [606], [-144], [-1010], [-3790], [-2184], [4268], [7922], [4002], [3960], [1878], [4740], [-710], [90], [3448], [2804], [-1320], [-1066], [-9254], [-9722], [2620], [-2806], [-5564], [-10060], [-5102], [-7976], [-1234], [-8030], [-5184], [7570], [-5370], [11442], [2362], [16], [9462], [-6302], [-7816], [-9506], [8228], [7668], [-922], [-3386], [3300], [14236], [3770], [-17796], [-3684], [17236], [13176], [-15428], [-7842], [-17250], [-1032], [-94], [11676], [1858], [23028], [17066], [10252], [2142], [3474], [17424], [6916], [-16468], [17176], [-11402], [3654], [-11318], [-23872], [-27026], [6498], [-6422], [23670], [9812], [-5190], [-94], [12432], [-2308], [26446], [-26450], [17102], [-16854], [-34670], [-11716], [-29772], [24928], [-4652], [-1802], [808], [-23144], [-27466], [-23604], [4122], [9110], [28352], [14002], [-14848], [-10500], [23890], [-670], [4776], [13024], [-32998], [22272], [30398], [1630], [-20228], [-38908], [-20936], [48204], [27304], [30], [-4736], [-19996], [-1252], [-17986], [-14256], [-50214], [-35814], [-19274], [59996], [-24344], [24326], [-11130], [29644], [-37310], [-25328], [34562], [-54002], [-4050], [-18852], [38706], [52964], [46744], [-17136], [12996], [-27370], [46964], [62976], [-58034], [-2374], [13290], [-58246], [8304], [-13682], [-47988], [-54640], [6026], [-13684], [52698], [62034], [39370], [-73536], [-8916], [17682], [-59048], [-11322], [-58408], [-4062], [-41798], [24366], [-20780], [17550], [47430], [-11990], [-46034], [12416], [-306], [77308], [34498], [-69136], [-41872], [-33956], [-34362], [-70706], [55324], [-21426], [23384], [104824], [-28490], [-25002], [64440], [-32404], [-44220], [-52534], [92080], [65224], [-76770], [110002], [96244], [-12850], [32994], [3312], [-60326], [-48744], [72572], [73778], [35114], [48636], [-5880], [-75254], [-31898], [20836], [-14520], [-53510], [-2352], [-121812], [120770], [-37588], [-68932], [-87694], [-53548], [79818], [-61260], [-58680], [69236], [75740], [-107272], [28194], [-15414], [52578], [61190], [57540], [-3474], [-58486], [4072], [-34410], [-440], [63296], [1894], [5948], [-29294], [139958], [119404], [-134448], [-29340], [140404], [-140432], [-12436], [-40676], [103742], [44626], [4534], [137956], [139482], [69650], [2002], [-77284], [-15494], [157316], [141370], [-72602], [37444], [-104292], [-22160], [-31282], [146096], [111608], [-2088], [-104722], [31604], [72586], [26904], [74018], [-159784], [148678], [109290], [78076], [-31400], [4400], [30802], [-63800], [130814], [164386], [-19080], [-92366], [74964], [-88240], [-66402], [-78598], [25016], [-46166], [-90784], [90502], [50578], [-87078], [146456], [18436], [76460], [-112374], [-145958], [-126908], [-198134], [-92620], [1790], [11398], [113520], [-78560], [80566], [8436], [-5322], [97040], [85640], [99342], [98540], [152814], [9270], [-58620], [-48230], [44860], [-57594], [-194200], [26614], [186440], [-128302], [-23540], [47088], [-208404], [80906], [-176746], [-50584], [211312], [177270], [-135496], [-75986], [96904], [66170], [-106040], [-78246], [-151550], [144696], [191900], [-218796], [-63140], [176562], [44350], [-20472], [153870], [-108444], [176398], [209464], [-114974], [-18084], [-122066], [53182], [155190], [32360], [30010], [88536], [108250], [59372], [100762], [71600], [241862], [-115148], [-5774], [289808], [-263574], [12168], [-141048], [-97338], [-130890], [-66922], [156366], [-215312], [-61754], [56372], [-65060], [24018], [-78142], [-215232], [-110806], [56362], [-113344], [-762], [-163532], [59820], [-70208], [-77278], [134158], [28048], [196834], [-198394], [-96020]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1694_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1694_4_a_a();".
// 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_1694_4_a_a(:prec:=1)
    chi := MakeCharacter_1694_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_1694_4_a_a();".
// 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_1694_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1694_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![10, 1]>,<5,R![14, 1]>,<13,R![-16, 1]>],Snew);
    return Vf;
end function;