
// Make newform 69.4.a.b in Magma, downloaded from the LMFDB on 24 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_4_a_b();".
// 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_4_a_b();".
// 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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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 := 4;
    raw_aps := [[-1, 1], [-3, 0], [4, -4], [-14, 1], [-36, 7], [-30, 6], [48, -5], [-74, 24], [23, 0], [-102, 66], [-84, -54], [58, -43], [2, 26], [-210, -18], [-24, 88], [16, 10], [-20, -158], [-382, -49], [-494, -146], [-112, -286], [410, -56], [886, 59], [740, -211], [372, 251], [-130, 456], [822, 124], [-74, 373], [-348, -195], [-114, 645], [292, -485], [-548, 66], [-1956, 318], [1852, 149], [-628, -324], [-636, 460], [-856, -956], [-670, -255], [184, 280], [-600, 938], [1642, -118], [1716, -900], [-194, -791], [-1476, -496], [598, 292], [-1470, -724], [-250, 1527], [-2224, -144], [304, -1128], [1432, 137], [1590, -195], [-358, -380], [-5032, -536], [3750, -684], [-7176, -81], [-990, 278], [2460, 830], [-6550, -224], [3044, 1434], [-2914, 254], [1868, -889], [-2862, -60], [3984, -14], [896, -1520], [208, -1850], [-574, 2410], [-1878, 2442], [-712, 2576], [214, 2046], [-2108, 2108], [-3046, 2580], [4366, 2366], [-1444, 668], [5398, -497], [-2774, -1203], [110, -1124], [-436, 514], [-5400, -1708], [-1610, -2016], [504, -1189], [-8866, 2392], [-6252, -951], [-650, -3969], [4720, -794], [-12142, 1390], [7464, 2856], [-3420, -1116], [-2502, -1466], [-15546, 228], [4482, -460], [3544, 2580], [4216, 4475], [2336, 1180], [15064, 468], [2676, 4732], [1688, -2808], [16128, -722], [9714, -994], [-5100, -3087], [8130, -1410], [-14454, 3540], [-6320, 1224], [11208, 4740], [-6936, -5255], [-18592, 95], [3690, 1674], [-6466, -1096], [-22476, -1614], [-10830, -5030], [-2368, -788], [4598, 1136], [8536, 2336], [-3118, -6141], [9372, 5719], [13554, 600], [-13690, 637], [-3632, 5231], [-9146, -4706], [26136, 414], [-20834, -400], [-23432, -1481], [8362, -1189], [-23082, 1620], [7620, -3264], [13612, -3842], [14728, -2812], [13308, 2266], [12086, 4883], [2400, 4106], [8826, -5283], [-7178, -6325], [-5332, 7156], [6756, 3666], [4850, -7565], [10462, 8189], [11958, -3722], [-20022, -4554], [15508, -110], [-18250, -5406], [15192, -1676], [18534, 9146], [-16576, -236], [-14370, -2900], [-35700, 3534], [2112, -3109], [7962, 4320], [-12, 5358], [-26562, -888], [7314, -11276], [4916, 5460], [-21648, -3462], [42334, -3218], [27300, 6799], [-26456, 6168], [5448, 4004], [-20502, -7944], [8136, -4574], [11742, 6891], [6330, -10378], [17330, -10228], [1548, -7768], [-15020, 13096], [15464, 10879], [25740, 2370], [9672, 181], [468, -9607], [14016, -9322], [17796, 90], [-14254, 10092]];
    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_4_a_b();".
// 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_4_a_b(:prec:=2)
    chi := MakeCharacter_69_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(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_4_a_b();".
// 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_4_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_69_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-7, 2, 1]>],Snew);
    return Vf;
end function;