
// Make newform 1392.2.a.j in Magma, downloaded from the LMFDB on 04 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1392_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_1392_2_a_j();".
// 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_1392_2_a_j();".
// 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_1392_a();"
function MakeCharacter_1392_a()
    N := 1392;
    order := 1;
    char_gens := [175, 1045, 929, 1249];
    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_1392_a_Hecke(Kf)
    return MakeCharacter_1392_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 := 2;
    raw_aps := [[0], [1], [-2], [-1], [-3], [5], [-1], [-6], [-4], [-1], [0], [8], [-10], [-4], [-7], [-2], [-6], [-8], [-3], [4], [4], [-6], [14], [-7], [-2], [7], [16], [-10], [11], [-21], [-14], [-3], [18], [11], [0], [4], [6], [18], [-4], [12], [-8], [-23], [-16], [14], [-6], [25], [6], [5], [-6], [-14], [26], [6], [-13], [9], [-8], [-24], [-9], [-14], [-5], [-30], [32], [-7], [4], [29], [-27], [9], [26], [-14], [32], [6], [-14], [28], [-16], [6], [22], [-14], [21], [34], [-6], [30], [10], [38], [40], [-10], [-35], [-37], [23], [-35], [-34], [5], [-36], [-28], [-8], [-12], [-13], [-19], [6], [-40], [-21], [-2], [-17], [22], [11], [-3], [-32], [-4], [26], [42], [17], [14], [-30], [-19], [-18], [-22], [-43], [13], [5], [32], [-23], [-21], [-39], [-27], [-1], [-36], [-23], [36], [-18], [20], [-8], [-48], [8], [37], [-32], [-40], [-30], [4], [14], [4], [34], [-21], [21], [-30], [4], [20], [40], [-15], [-40], [-6], [10], [-32], [-14], [33], [-4], [39], [-22], [49], [-3], [42], [43], [4], [45], [8], [-22], [-20], [-32], [20], [-25], [-52], [47], [37], [-24], [-23], [-64], [44], [0], [60], [-7], [-45], [-26], [55], [-4], [-63], [29], [8], [-8], [-56], [-12], [-26], [-60], [54], [-25], [-15], [-48], [-43], [-45], [12], [12], [-27], [18], [54], [10], [27], [18], [-30], [-47], [22], [6], [-42], [-24], [40], [-30], [24], [64], [35], [51], [57], [-25], [53], [-10], [-67], [-4], [-1], [-13], [-60], [18], [-34], [-54], [-12], [-28], [56], [-12], [52], [-32], [-26], [-21], [3], [-4], [-2], [64], [9], [1], [-20], [-5], [52], [74], [24], [48], [-2], [55], [25], [-22], [40], [-3], [34], [-6], [36], [50], [42], [30], [-27], [8], [39], [53], [-32], [18], [-44], [31], [-78], [4], [54], [29], [-49], [-34], [10], [-14], [50], [-60], [43], [30], [-36], [-66], [-39], [46], [19], [-42], [-3], [4], [-49], [29], [-68], [-64], [-38], [24], [12], [20], [80], [-20], [-12], [52], [74], [-4], [-28], [76], [-48], [-12], [-42], [-63], [46], [-14], [-25], [38], [5], [-42], [15], [-12], [-55], [68], [-72], [43], [69], [46], [-59], [-12], [-16], [-72], [58], [-52], [-44], [11], [-66], [-76], [24], [56], [-41], [14], [42], [27], [-15], [54], [-79], [-52], [28], [51], [3], [4], [-36], [-36], [-74], [-45], [-39], [76], [-3], [30], [-20], [46], [-62], [-5], [-52], [-9], [-66], [27], [72], [-87], [-10], [-48], [-6], [5], [85], [-14], [-84], [-97], [-12], [13], [15], [18], [1], [33], [6], [52], [38], [6], [48], [-62], [-51], [-56], [42], [4], [13], [14], [-5], [-68], [72], [41], [40], [9], [11], [-40], [-26], [-61], [-89], [98], [-22], [38], [-52], [44], [32], [67], [41], [76], [-2], [29], [30], [-24], [44], [70], [-41], [93], [-27], [-75], [56], [36], [58], [48], [-36], [-53], [-12], [30], [-17], [45], [28]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1392_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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