
// Make newform 735.6.a.a in Magma, downloaded from the LMFDB on 03 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_735_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_735_6_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_735_6_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_735_a();"
function MakeCharacter_735_a()
    N := 735;
    order := 1;
    char_gens := [491, 442, 346];
    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_735_a_Hecke(Kf)
    return MakeCharacter_735_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 := 6;
    raw_aps := [[-2], [9], [25], [0], [472], [686], [1562], [2180], [264], [170], [-7272], [-142], [16198], [-10316], [-18568], [21514], [-34600], [35738], [-5772], [-69088], [70526], [47640], [-74004], [90030], [33502], [-78882], [82036], [-41652], [104870], [-153746], [-59372], [98808], [306918], [36820], [-138070], [-362408], [-246098], [170084], [-274008], [281886], [-110240], [-693182], [374792], [247754], [373578], [482840], [-708748], [211036], [-920828], [71130], [1000494], [-550520], [-543682], [659568], [1546002], [-96856], [-83530], [857888], [647538], [-2214798], [156276], [56406], [1760612], [1713888], [1428766], [-744382], [-136908], [-2435942], [1161268], [-725830], [3948666], [1211880], [-3929988], [1085194], [4066540], [1534536], [1907370], [1711622], [2462682], [3697030], [1930600], [-4839098], [-2743248], [-6058234], [-5210440], [1172484], [4143610], [-5413382], [-5366802], [-5332836], [-5568308], [1570920], [-7744972], [1977152], [-6559940], [5928496], [1030550], [-8482802], [-8936764], [4143942], [2631148], [-12491742], [-7638924], [455250], [-259228], [13363582], [12233172], [-11758814], [8584040], [1593718], [-15280108], [-16700366], [10398558], [12263140], [12250912], [-6859038], [3311196], [-9918208], [-13910206], [-3278840], [7003298], [10974714], [8904822], [16195644], [1510148], [18050762], [15791830], [-897600], [-8333108], [6056326], [5196460], [2672224], [14998072], [-25684622], [-6079602], [28250110], [21143046], [24230732], [-1443218], [29918570], [5301828], [4550082], [-24277516], [3639988], [-19867350], [35866600], [-22579074], [-17803918], [302900], [-4373056], [22418898], [14046998], [-24118876], [-20545368], [-7374252], [-22380608], [30474400], [-18792890], [9773862], [-12402242], [-17705172], [2372134], [567548], [23313888], [3948598], [-50141664], [3486752], [13237302], [-25943230], [44188966], [14527320], [-22276702], [25135752], [-39626766], [-8478280], [61843950], [49547052], [-65327238], [-47605124], [-17475070], [-2702212], [-26270552], [33307234], [22447162], [46129464], [19061750], [27954258], [-29585044], [-44750470], [45281048], [-33068074], [82166884], [-13111548], [-10888882], [25600788], [-690374], [-49410638], [8891874], [-41503518], [49999456], [75561090], [40560408], [101578662], [87591470], [100859640], [21673422], [4831480], [-58583156], [-107737950], [-87152372], [-62372662], [-113965082], [98551644], [-103479268], [-64000320], [13680838], [-119093132], [-94796442], [24769568], [-102715086], [36511942], [15572200], [-89352510], [-94605716], [-15437828], [94632470], [-4523334], [62225600], [21465692], [-126897528], [-122205486], [35887580], [104826752], [83114482], [9473716], [71945952], [-94497330], [18475994], [122785560], [100226448], [-37030116], [32103228], [-86992324], [-180312330], [3497466], [133020800], [-148732388], [109943408], [99962180], [-48055376], [-155366342], [-101624002], [49781448], [-14680890], [-118980434], [57743880], [194820622], [-83160188], [69030822], [107159902], [-56375036], [-101280772], [-100506230], [88424406], [117689202], [-11043820], [-89046830], [-154925162], [-84982756], [-131546006], [230734738], [183825148], [-65973074], [-11378040], [-193815258], [22498276], [-61107132], [-160617930], [-18196278], [33587928], [-59503184], [-102198968], [-173485088], [-10909542], [157150332], [29041752], [107055154], [-199380102], [-64766120], [171331230], [226449842], [169872172], [36557694], [-15536472], [180809834], [-161892450], [91557448], [248079846], [137009400], [238012852], [83356206], [-60079742], [-244226000], [-309013836], [220233172], [-4028302], [-236859732], [-49721630], [-73596000], [-231466566], [295693296], [201468690], [98385642], [273412604], [-93249952], [-331283770], [-304956960], [-32928648], [-273839034], [-143847870], [-87805052], [152374178], [-146532442], [-69030596], [275596254], [-264315202], [74112260], [143149436], [-270298632], [12728074], [-203681298], [-170704622], [-139740440], [-3305924], [-17690068], [47966212], [373404110], [-61667414], [4963798], [408254892], [246596794], [418111598], [135036510], [-164105688], [284873314], [230460960], [303187018], [-129307292], [-287800632], [-447014138], [-455279892], [-535019622], [-40569478], [-350874964], [1901310], [-375576894], [375082480], [-197293032], [-359003682], [-294285416], [-304511702], [406101398], [369603048], [-491541080], [-383449268], [315040234], [-22024338], [197840604], [-114025798], [245296992], [-257345820], [-11204216], [75812130], [429404088], [-383090822], [-610972480], [114548352], [402457966], [464721750], [-274281658], [376262398], [-114661146], [-581966852], [256063958], [-200395860], [207156776], [-620551768], [-431226578], [282070164], [-306925248], [62624130], [-638634154], [-714584840], [-130222628], [-185955128], [-464137846], [-164748800], [-392696010], [-557218268], [569880762], [-169804030], [-677039106], [174977668], [-442591958], [211570990], [-239034352], [360382298], [232077722], [484484316], [-355916040], [205137726], [-603350022], [-421560116], [331435452], [-273229822], [307371158], [767575520], [36265412], [480450642], [152529016], [563542850], [245027702], [-23301192], [-99781360], [11223646], [57182462], [800802644], [31627290], [177617308], [114054200]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_735_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_735_6_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_735_6_a_a(:prec:=1)
    chi := MakeCharacter_735_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_735_6_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_735_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_735_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![2, 1]>,<13,R![-686, 1]>],Snew);
    return Vf;
end function;