
// Make newform 7350.2.a.dm in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7350_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_7350_2_a_dm();".
// 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_7350_2_a_dm();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_7350_a();"
function MakeCharacter_7350_a()
    N := 7350;
    order := 1;
    char_gens := [4901, 1177, 2551];
    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_7350_a_Hecke(Kf)
    return MakeCharacter_7350_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 := [[1, 0], [1, 0], [0, 0], [0, 0], [2, 1], [3, 0], [3, 2], [0, -1], [-1, 1], [1, 0], [1, 1], [0, -5], [3, 2], [-3, 1], [4, -4], [-7, -4], [-3, -3], [3, -2], [4, 8], [2, -8], [8, 5], [-6, 5], [7, -5], [-4, 0], [-6, 4], [0, -4], [7, -5], [2, -6], [0, -8], [-8, 1], [6, -2], [16, 2], [2, 15], [0, 11], [-1, 4], [-2, 7], [0, -14], [-1, -3], [-6, -2], [10, 3], [2, -5], [12, 8], [9, 5], [4, 2], [-9, -10], [-14, -4], [-11, -11], [9, 11], [7, 13], [-18, -8], [-10, -3], [0, -8], [6, 0], [9, -5], [19, -4], [-5, 11], [-16, 11], [20, -6], [0, 17], [20, 0], [4, -3], [0, -8], [10, -1], [10, 1], [8, -17], [-3, -12], [-17, -5], [15, -14], [-10, 14], [-19, -4], [12, 6], [7, 19], [5, -3], [-8, 4], [-13, -15], [12, 11], [-16, 4], [19, 8], [22, -7], [-24, 1], [-9, -11], [-30, -4], [9, 17], [6, 16], [-3, 1], [20, -4], [-18, -5], [1, 2], [-20, 0], [-20, -7], [3, -3], [-16, -3], [-14, 6], [14, -10], [-19, -5], [2, -19], [-18, 17], [5, 4], [4, -20], [-30, -3], [-7, -19], [8, 8], [9, 13], [-24, -3], [-5, 29], [14, 4], [-9, -23], [-26, 0], [-29, -1], [-14, 9], [6, 24], [22, 0], [-4, -13], [-2, 10], [-38, -2], [36, -3], [-18, 3], [-22, 19], [24, -8], [6, -2], [-40, 4], [-19, 14], [14, -13], [-18, -5], [-2, -22], [25, 8], [10, 7], [-26, 5], [-11, -19], [-9, 6], [27, 19], [21, 11], [4, -12], [40, 3], [-32, 12], [4, 8], [-8, -8], [-18, -18], [12, 3], [-12, -16], [-38, 3], [16, -2], [-30, 1], [2, 7], [-19, 14], [-16, -1], [3, 8], [4, 18], [12, -24], [-8, -12], [32, -4], [-19, -16], [-1, 23], [-30, 3], [-11, -21], [15, 5], [20, -11], [3, 4], [-4, 3], [-40, -8], [4, 15], [-8, 28], [20, 17], [28, 12], [24, -11], [40, -8], [-24, 4], [-14, -8], [5, -8], [-14, -3], [22, 26], [-31, 16], [-15, 1], [-3, -20], [10, 0], [-3, 18], [-28, 10], [1, -16], [7, 13], [-1, -4], [-26, 17], [9, 17], [8, 5], [1, -34], [24, 0], [6, -32], [6, -13], [10, 2], [9, 20], [-12, 5], [-32, -20], [20, -15], [-38, -12], [-50, -4], [24, -23], [-35, 16], [15, -20], [-6, 20], [4, 12], [4, 27], [-8, 14], [37, 23], [-11, 36], [20, 9], [43, 15], [6, 25], [31, -21], [38, 7], [8, -21], [14, -1], [16, 16], [-20, -3], [-34, 3], [-43, -7], [2, -38], [-16, -36], [-4, -33], [-28, -14], [27, 11], [7, -2], [0, 40], [5, 33], [-34, 24], [-40, 9], [-18, 0], [-6, -16], [-12, -14], [16, 36], [-52, -2], [-2, -10], [-14, -25], [12, 24], [20, -16], [-4, -39], [32, 3], [-60, -9], [26, -12], [-22, 24], [22, -1], [-14, -34], [32, 5], [30, -2], [-19, -3], [0, -29], [-29, -12], [32, 15], [-17, -3], [38, 16], [-12, 28], [8, -4], [58, 11], [-11, 18], [9, -23], [22, -28], [-30, 5], [42, -22], [12, -33], [-34, 26], [-42, 8], [-18, -4], [-28, 24], [-16, 33], [-5, 20], [-8, -12], [-13, 12], [-6, -1], [-11, -10], [39, -4], [-21, -21], [3, -34], [-9, 8], [25, -11], [-18, 13], [-24, 11], [44, -20], [52, 2], [4, 4], [-6, 8], [-1, 24], [11, -3], [8, -15], [-12, -21], [-28, -24], [-19, 24], [-40, 16], [57, 3], [-19, -6], [8, 30], [-9, -5], [44, -4], [32, -22], [2, 48], [28, 20], [40, -26], [-6, 4], [-4, -36], [31, -11], [20, 43], [29, -21], [-18, 23], [-24, 16], [41, -16], [-34, 6], [76, 8], [-18, -8], [-35, 12], [-6, -30], [-21, -10], [-59, -7], [28, 25], [-18, -14], [-17, 0], [-12, 43], [48, 18], [33, 5], [54, -4], [-4, 22], [13, 17], [-34, -13], [-26, 9], [-6, -26], [-52, -10], [38, -36], [-28, -32], [44, -29], [-80, 4], [-17, 11], [6, -41], [8, 4], [-31, -30], [-6, -8], [-31, 10], [55, -25], [-55, -3], [-15, 39], [44, -24], [-8, 40], [25, -18], [26, 0], [-55, -21], [-30, -28], [-2, -20], [22, 45], [-24, -4], [-21, 42], [12, 8], [0, -18], [-9, -5], [-48, 5], [-24, -45], [0, 21], [-25, 22], [-27, -2], [47, 3], [-4, -19], [-7, 60], [-2, 39], [-7, 33], [-22, -4], [41, 5], [-80, -4], [36, 2], [80, 4], [0, 7], [2, -19], [-39, -20], [20, -5], [40, 4], [-41, -14], [-36, 8], [28, -5], [-3, -21], [-1, 58], [19, -3], [-12, -12], [75, -11], [-24, -32], [-66, -15], [43, -38], [38, 29], [-14, -12], [-28, 16], [-40, -8], [0, 8], [36, -21], [-4, -60], [38, 33], [68, 0], [12, -16], [2, 38], [51, 22], [-12, -52], [34, -9], [6, -42], [11, -63], [-4, 10], [73, 1], [75, 14], [60, -24], [-32, -18], [-29, -26], [-44, -37], [-20, -28], [63, 12], [6, 57], [61, 27], [-12, 53], [42, 12], [42, 34], [-16, 10], [-74, 19], [4, -12], [-24, -43], [7, -41], [13, -10], [-74, 13], [49, -15], [-13, 11], [39, -26], [58, 22], [21, -48], [45, -8], [47, -1], [23, 21], [26, 7], [46, 7], [26, -31], [-20, 35], [-8, -45], [-22, -34], [6, 44], [-38, 33], [13, -17], [-26, 18], [-9, -10], [-8, 28], [39, 2], [14, -31], [-44, 30], [40, 32], [5, 21], [0, 44], [-12, 16], [-75, -11], [10, 41], [16, 4], [-22, -21], [86, 6], [-66, 23], [29, -6], [-45, 21], [36, 48], [-26, 51], [15, -68], [-49, -10], [6, 32], [-34, -48], [49, -27], [55, 18], [34, -16], [36, -10], [70, -29], [-56, -24], [18, 32], [54, -10], [14, -40], [6, 58], [-19, 17], [64, -27], [28, -8], [-34, 23], [70, -18], [40, 19], [39, 38]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7350_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7350_2_a_dm();".
// 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_7350_2_a_dm(:prec:=2)
    chi := MakeCharacter_7350_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(3361) - 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_7350_2_a_dm();".
// 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_7350_2_a_dm( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![2, -4, 1]>,<13,R![-3, 1]>,<17,R![1, -6, 1]>,<19,R![-2, 0, 1]>,<23,R![-1, 2, 1]>,<31,R![-1, -2, 1]>],Snew);
    return Vf;
end function;