
// Make newform 3380.2.a.m in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3380_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_3380_2_a_m();".
// 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_3380_2_a_m();".
// 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, -6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, 0, 1]];
    Rf_basisdens := [1, 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_3380_a();"
function MakeCharacter_3380_a()
    N := 3380;
    order := 1;
    char_gens := [1691, 677, 1861];
    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_3380_a_Hecke(Kf)
    return MakeCharacter_3380_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, 0, 0], [0, 1, 0], [-1, 0, 0], [0, 0, -1], [-2, 1, -1], [0, 0, 0], [0, 0, 0], [0, -3, 1], [2, -1, 2], [-2, -2, 1], [-2, 1, 1], [-4, 2, 1], [2, 2, -2], [-2, -3, 0], [-4, -4, 1], [-2, -2, -2], [8, -1, 1], [-2, 0, -3], [4, -2, 3], [0, -3, -3], [-8, -2, -1], [-4, 4, 2], [-4, 2, 1], [-8, 4, 2], [-6, 0, 2], [-2, -2, -2], [-4, 1, 2], [10, 1, -2], [-10, -4, 2], [8, -4, 2], [-8, -1, -2], [-4, -4, 2], [2, 2, -2], [4, 8, -2], [-2, 4, 2], [-12, 3, -1], [12, -2, 2], [8, 8, -3], [-12, -6, 3], [6, -6, 0], [4, -2, 4], [-6, 2, 1], [4, -8, 4], [-6, 6, -2], [6, 6, 0], [-4, 6, 0], [0, 2, 4], [-8, 4, -5], [8, 2, 1], [-8, -2, 4], [-2, 4, -2], [-2, 7, -7], [-10, 2, 0], [0, 6, -6], [-2, 4, 4], [-12, 3, 0], [10, 10, -2], [4, -5, 5], [-2, 6, -6], [6, 6, 0], [6, 1, -4], [0, 6, 3], [-16, 2, -1], [8, 2, -4], [-8, -12, 6], [-4, -10, 7], [-2, -5, 5], [20, 0, 0], [-8, 7, -2], [4, -2, 2], [12, -6, 9], [4, 1, -7], [20, -3, 0], [4, -6, -6], [2, 5, 3], [16, -2, -1], [-14, -8, 4], [-16, 2, 5], [0, 12, 0], [-22, 2, -6], [-20, -2, -2], [-2, 4, -10], [-14, 1, 5], [2, 0, 0], [12, 2, -2], [12, -3, 6], [-14, -2, -4], [-6, 0, -6], [-4, -10, 4], [-4, -4, 1], [28, 1, -2], [4, 13, -7], [4, -8, -3], [-4, 8, -4], [28, 1, 1], [2, 5, -10], [0, 6, -12], [-14, -2, 1], [-12, 1, -4], [0, -18, 2], [14, -3, -6], [4, -2, -7], [10, 1, 4], [-2, 4, -5], [0, -8, 2], [0, 6, -5], [0, 12, -3], [22, -8, 2], [-16, -10, 8], [-2, -12, 0], [-10, 3, 6], [-10, 8, -8], [-2, -2, -10], [-12, -9, 1], [-26, -5, -3], [-22, -4, -4], [-12, 0, -3], [-24, -9, 6], [-12, 6, 0], [4, -2, -2], [26, -4, 4], [-8, 0, 6], [14, 2, -4], [16, -2, -1], [6, 3, 3], [-14, 10, -2], [-24, 6, 2], [-4, -4, -10], [26, 9, -6], [18, -6, 0], [42, 3, -3], [-16, 14, 7], [-16, -2, 2], [18, 14, -8], [-4, -4, 10], [-8, -8, 6], [20, 2, 1], [-12, 6, -5], [-4, 2, 8], [-18, 18, 3], [26, -1, -1], [-6, -12, 6], [-32, -3, 0], [16, 10, 5], [10, 8, 1], [10, 1, 5], [-16, 2, -9], [14, -16, 2], [-8, -12, 0], [20, -4, 7], [-42, 0, 4], [10, -8, -11], [-22, 9, -6], [12, -3, -6], [4, 5, -2], [-4, 14, 8], [24, -10, 4], [18, 6, 6], [22, 0, -6], [-12, -18, 0], [4, -2, 5], [18, 12, -6], [4, -2, -7], [-12, -6, -12], [0, -6, 3], [16, 4, 5], [-16, 6, -18], [-14, 14, -8], [-24, 12, 2], [2, 14, -10], [10, 1, -7], [-16, 14, -4], [-8, 16, 4], [-36, -6, 1], [4, 6, 6], [10, -8, -8], [32, 5, -7], [20, 2, 10], [22, 3, 0], [-18, 8, -8], [-16, 8, -3], [24, -6, 0], [-18, 14, 4], [-14, 10, -10], [-16, -10, 7], [-10, -22, 11], [4, -6, -12], [4, -8, -3], [-18, 6, -8], [-16, 11, -5], [12, 16, -4], [-12, -6, -3], [-12, 10, -4], [2, -4, -8], [-18, 3, -12], [6, 12, 0], [2, 2, 16], [16, 26, -8], [-16, 14, -11], [18, 21, -12], [4, -2, 2], [32, -12, 6], [2, -4, 4], [10, 2, -5], [-18, -9, 9], [22, 10, 4], [-18, 3, 1], [-8, 13, 10], [32, -4, 4], [0, 16, -16], [-6, 4, 8], [-30, 0, 9], [6, -7, 4], [44, -4, -5], [12, -9, 9], [-34, 2, -8], [16, -15, 12], [-30, -6, 6], [-40, -4, 7], [6, -6, 12], [-22, -12, -3], [-22, 5, 5], [-12, 0, -12], [-24, 18, -3], [4, 13, -2], [-26, -12, -3], [-22, -16, 2], [12, -6, 6], [30, -11, 8], [-28, -7, -5], [-32, -6, 0], [-8, 8, 4], [-8, 1, -5], [-18, -6, 6], [-4, -3, 12], [-16, 8, 1], [-2, -14, 2], [-32, -2, 11], [0, -6, 0], [28, -2, 10], [48, 6, 3], [-16, -6, 0], [-38, -3, -6], [-16, -22, 6], [10, -2, -10], [-16, 14, -22], [-24, -12, 13], [-10, -7, 1], [-14, -11, 1], [8, -7, -10], [-24, -18, 9], [8, -4, -2], [16, 4, 11], [14, 0, 12], [28, -2, 16], [36, 15, -9], [-2, -6, 3], [36, -12, -9], [-16, 14, 2], [-12, -6, 3], [-10, 15, 0], [8, -1, 2], [-28, -10, -8], [14, 18, -12], [20, -22, 1], [-20, 6, -12], [4, 10, -4], [0, 0, 12], [0, -6, -15], [38, 14, 2], [2, -6, 18], [-20, 16, 5], [-18, 18, 6], [4, 6, 0], [16, 12, 0], [12, 6, -5], [-36, -6, -3], [-28, 2, -4], [10, -26, 4], [-20, 4, 10], [2, 17, -16], [-6, -21, 9], [-6, 3, 0], [-32, -14, 12], [-32, -2, -9], [16, -14, -2], [-26, 0, -6], [-14, 4, 8], [-32, -23, 11], [-38, 4, -17], [30, 12, -15], [30, -3, -6], [-14, -8, -10], [14, -7, -11], [-4, 6, -12], [42, -12, 0], [0, -2, 8], [0, -6, 12], [12, -6, 12], [4, -26, -7], [2, -20, 2], [10, 16, -16], [40, 6, -12], [68, 5, -4], [28, -22, -2], [-32, 10, 7], [12, 21, -12], [2, -6, 6], [-50, 1, 5], [40, 2, 10], [-4, 11, -10], [-28, 2, -8], [-14, -2, -11], [-14, 3, 0], [-48, -6, 3], [10, -6, 15], [-44, 1, -1], [-16, 29, -5], [28, -2, -5], [-14, -2, 10], [32, 22, -10], [32, -22, -9], [-42, -12, -3], [8, -28, 17], [4, 10, -1], [-10, -8, 11], [-8, 7, 13], [4, -14, 1], [-32, 19, 4], [-28, 14, 8], [-46, -4, 6], [-24, -30, 18], [28, 6, -12], [32, -10, 25], [32, 11, -1], [-8, -2, -1], [30, 0, 16], [26, -16, -2], [-38, 22, 10], [-20, 27, 12], [6, -6, 4], [-12, 12, 6], [-22, 20, -14], [28, 12, -6], [-14, 22, -4], [32, -16, 2], [22, 6, 6], [-8, -20, 13], [0, -21, 21], [-8, -14, -2], [-18, -9, 5], [22, 10, -10], [2, 20, 4], [-24, 13, -16], [-10, 24, -12], [32, -28, -4], [-26, 13, -1], [14, -1, 7], [-34, -4, -16], [20, -4, 1], [-24, 30, -1], [-6, -30, 3], [-40, 5, 8], [26, -7, 7], [14, 7, 8], [44, -12, 12], [30, 12, -12], [-68, -2, 5], [-62, 0, 0], [-16, 2, -16], [-20, 12, -12], [32, 14, -17], [26, 8, -13], [-20, -24, 6], [-18, -14, -10], [-16, -7, 1], [0, -24, -6], [26, 32, -6], [-30, 12, -15], [-8, -24, -6], [8, -10, 10], [20, 14, -5], [4, 10, -13], [-12, -6, -9], [-34, 11, -17], [-20, 4, -19], [2, -7, -7], [-38, 2, 10], [8, -10, 1], [2, 35, -4], [-22, -10, -16], [0, -30, 9], [12, 15, 9], [-14, 9, 0], [-8, -5, -7], [10, 0, 18], [10, -17, -9], [6, 18, -15], [28, 6, 18], [34, -8, -4], [-6, 12, 0], [-32, 16, -14], [-28, 8, 5], [52, -2, 5], [-42, -24, 6], [32, -2, -10], [-24, -6, -5], [20, -16, 10], [28, -32, -3], [56, 11, -11], [30, 20, -14], [-26, -2, 4], [10, -29, 16], [60, 2, -2], [6, -4, -14], [18, 12, -12], [-38, 7, 5], [-2, -9, 0], [16, -2, 17], [40, -23, 4], [-42, 12, -15], [46, -2, 16], [-24, 24, -15], [56, 8, 8], [6, -12, 30], [32, 2, 7], [-18, 21, 12], [34, 10, -4], [8, -19, 11], [8, 14, -4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3380_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3380_2_a_m();".
// 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_3380_2_a_m(:prec:=3)
    chi := MakeCharacter_3380_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_3380_2_a_m();".
// 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_3380_2_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3380_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, -6, 0, 1]>,<7,R![-12, -12, 0, 1]>,<19,R![-114, -48, 0, 1]>],Snew);
    return Vf;
end function;