
// Make newform 69.6.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_69_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_69_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_69_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
        poly := [-7, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_69_a();"
function MakeCharacter_69_a()
    N := 69;
    order := 1;
    char_gens := [47, 28];
    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_69_a_Hecke(Kf)
    return MakeCharacter_69_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 := [[0, -2], [-9, 0], [47, -1], [-59, 11], [160, -108], [-144, 74], [-905, -13], [365, 311], [529, 0], [4104, -266], [886, 1514], [-11556, -206], [2758, 1372], [5161, 2667], [21476, 1152], [-12675, 4369], [9172, 508], [18612, 3946], [-3741, -4607], [63424, -2088], [68830, -2212], [31143, -1479], [41560, -11124], [34885, 2317], [-85052, -10274], [91970, -908], [10035, 1477], [-102196, -4696], [-81834, -10136], [-112375, 1553], [31470, 31994], [-38176, 18356], [84037, 1933], [308880, 17572], [258499, 23403], [-135424, -57024], [-59564, 55762], [138234, -58758], [-167156, 35780], [196920, 93766], [167988, -85588], [-352974, 58316], [305286, -49774], [-10628, -5910], [-127436, 39882], [527727, 104001], [-1030878, 578], [390280, -111400], [-186894, -29750], [-161754, -58000], [680818, -113904], [-384292, -45940], [-433416, -27598], [-13434, -236746], [173906, -70344], [-116326, 99382], [69988, -289054], [-66046, -110042], [169750, 12400], [-1727307, 12029], [-49417, 188709], [888073, -180219], [-833474, 242254], [1164496, -35348], [-159946, 67564], [741592, -344946], [530554, 289578], [1018352, -21662], [-222352, -243208], [715388, 105502], [-1436668, -561378], [1409330, 606430], [208471, 412953], [19660, 251602], [-411551, 451523], [2651574, -119446], [-834811, 758633], [652462, 888480], [96435, 589703], [-1023236, -100230], [-1621792, -582956], [-403666, -773648], [-243280, -565560], [2592802, -88160], [-1627960, 443144], [2698312, -380292], [-3005202, -849724], [-1549820, -1206194], [5250344, 71574], [-326116, 318964], [-1142534, 964346], [4472864, 386696], [-5340792, 622368], [5509792, 460944], [-3391382, -1232918], [-2985940, -341692], [-3669636, 707114], [2030045, 482485], [2284551, -711899], [-5420684, -205442], [9012690, 310514], [2514065, -1038427], [11277114, -44670], [-4507225, -883141], [-5318353, -1461963], [1335540, -488926], [5948816, -266804], [-2081846, 2108520], [-2333244, -740740], [-2551148, 1065706], [-9075876, 626124], [897984, 2021390], [-5041575, 1199193], [-5042917, 123561], [-4721009, -2131135], [-7644025, -1485533], [-7317135, -1567237], [-9919716, 1719432], [1402354, 2047972], [-3421510, 632810], [7872836, -247142], [3085048, 2291766], [204163, 947131], [7104292, 1507608], [411534, 1868006], [-18834961, -752521], [8963742, 1773192], [4571716, 1484856], [-7778947, 2120539], [11124442, -2880468], [6384096, 2451468], [-14930618, -2702366], [2344305, 1925735], [5919538, 1945804], [18147308, -1789858], [15859838, 214332], [9166651, -1026429], [2487857, -1446405], [17756853, -661327], [5321148, -3932170], [979910, -2784090], [16803822, -961144], [-31179558, 660310], [-20191262, -1415622], [-22952244, 1965830], [-16899314, -3351966], [-10954874, 177408], [-3125170, 2383876], [24616400, 2288300], [-27276340, -1086696], [5049186, 1625116], [-920059, -1268043], [28146246, 1826790], [2501488, -3281900], [-13411733, 4065777], [5237260, 4529660], [-23156661, 1940261], [-35111546, -1846140], [-24084706, -163140], [-24044985, -1776945], [-20524324, 2819796], [-21516893, -2863825], [-14964150, -5534578], [-11681834, -5396258], [-1127415, 2206993], [-2516524, -4077876], [-2828958, 137062], [24298028, -1733578]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_69_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_69_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_69_6_a_a(:prec:=2)
    chi := MakeCharacter_69_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(997) - 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_69_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_69_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_69_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-116, 0, 1]>],Snew);
    return Vf;
end function;