
// Make newform 1575.2.a.n in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1575_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_1575_2_a_n();".
// 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_1575_2_a_n();".
// 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 := [-1, -1, 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_1575_a();"
function MakeCharacter_1575_a()
    N := 1575;
    order := 1;
    char_gens := [1226, 127, 451];
    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_1575_a_Hecke(Kf)
    return MakeCharacter_1575_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], [0, 0], [0, 0], [1, 0], [-1, -2], [0, -2], [0, 4], [-2, 4], [-5, 2], [-5, 0], [0, -6], [3, 0], [-6, -2], [3, 2], [2, 0], [-6, 4], [-8, 6], [-6, 6], [-3, 2], [-5, 6], [-10, -2], [-5, 10], [4, -6], [-16, 2], [4, -2], [-6, -2], [6, -4], [-8, 0], [1, -12], [7, -12], [5, -14], [12, -8], [6, -8], [2, -14], [1, 8], [-19, 2], [2, 2], [-4, -4], [-4, 2], [14, 4], [16, -12], [2, -10], [-4, 4], [5, -12], [-1, -4], [6, -2], [12, 0], [14, -10], [-14, 12], [-2, 4], [-3, 8], [8, 4], [-6, -4], [-4, 4], [4, -14], [-15, 2], [8, -6], [20, -6], [-10, 16], [3, -20], [10, -12], [20, -18], [12, 12], [-12, 20], [22, 4], [-13, 20], [-21, 6], [-14, 4], [-19, 2], [2, -4], [-4, -10], [19, -18], [-26, 18], [-23, 24], [-5, 10], [32, -2], [7, 16], [14, 8], [-5, -4], [22, -4], [20, -10], [-13, 0], [-20, -4], [-16, 20], [-12, -6], [12, -12], [-23, -4], [-15, -4], [8, -10], [-4, 16], [-2, 8], [20, -10], [7, 2], [7, 2], [16, 8], [18, 16], [-32, 14], [-22, 0], [4, -20], [11, -8], [-11, -2], [19, 16], [-10, 12], [-1, -8], [23, -22], [-2, 0], [26, 2], [20, -28], [5, -10], [-32, 8], [4, 18], [-37, 12], [1, -8], [-8, 6], [19, -14], [-29, 24], [16, -4], [10, -16], [-30, -8], [-8, 16], [-18, 40], [22, 4], [2, -20], [-3, 18], [2, 10], [34, 8], [-22, -16], [-10, 10], [-8, -8], [4, 0], [17, -14], [8, -4], [8, 8], [27, 12], [-8, 32], [-22, 34], [-44, 10], [42, 2], [28, -12], [-27, 4], [-18, 40], [-14, 24], [-23, 14], [-23, 30], [-20, -20], [22, -14], [20, -12], [22, 10], [10, -20], [-27, -14], [18, -20], [-12, -10], [-15, -22], [30, 14], [20, -24], [-7, -10], [-29, -2], [-42, -6], [34, -2], [4, -2], [-20, 24], [-1, 4], [-24, -16], [18, 0], [9, -4], [16, -30], [7, -10], [-38, 12], [-1, -8], [-28, -12], [1, 38], [18, -32], [33, 10], [-6, 0], [38, 14], [-20, 0], [-17, -22], [14, -12], [-32, 42], [0, 10], [-33, 42], [24, -32], [-5, 8], [-30, 44], [15, 2], [-6, 12], [29, -12], [10, 8], [-3, -24], [18, -30], [-38, 24], [-13, -22], [17, -10], [26, -56], [1, -38], [-18, 18], [-3, 0], [-33, -16], [18, -12], [-8, -22], [26, -32], [-30, 4], [24, -2], [-38, 26], [34, 22], [-14, -18], [-10, 0], [16, 20], [-3, -24], [-2, 18], [-17, 40], [-20, 36], [3, 2], [0, -16], [-6, 2], [32, -40], [-41, 38], [-18, -8], [-25, 14], [-43, 28], [1, -8], [-4, 48], [9, -8], [-7, -18], [-16, 26], [26, 8], [-34, 30], [37, -14], [-32, 0], [59, -2], [43, -28], [4, 2], [40, -16], [-3, -8], [24, 30], [-12, 38], [46, -22], [23, -44], [19, -18], [8, 40], [7, -2], [-20, -6], [52, -26], [-29, 28], [36, -10], [56, -12], [-14, -16], [22, 12], [0, -20], [0, -48], [-46, 28], [-42, 50], [32, -40], [-4, -12], [-58, 28], [-20, 0], [-23, 40], [-36, -12], [54, -24], [6, -16], [-4, -44], [-71, 6], [48, -6], [-36, 10], [-30, 34], [0, 0], [-19, -12], [-58, 2], [-61, 10], [13, 16], [-12, 8], [36, -16], [-36, 20], [63, -6], [-12, -20], [4, -20], [41, -18], [-18, 56], [3, -12], [8, -40], [58, -14], [28, 8], [44, 6], [52, -20], [-54, 14], [43, -30], [29, 20], [-9, -28], [-28, -24], [6, 28], [45, -44], [36, -18], [13, 16], [-50, -14], [9, 20], [24, -48], [-18, 50], [-16, -26], [-34, 38], [18, 20], [2, -26], [26, -48], [-21, 42], [-3, -2], [-21, -14], [6, -36], [39, 26], [56, -42], [-71, 22], [18, -8], [-50, 42], [-10, -20], [-13, 52], [-4, 16], [-5, 34], [-32, 44], [2, 16], [16, 4], [-38, -6], [-25, 40], [48, -12], [-10, 16], [-10, 36], [-15, 58], [47, -32], [-48, 10], [-53, 6], [-22, 12], [27, -30], [-55, 12], [62, -20], [53, 8], [34, 12], [76, 0], [-36, -24], [-34, -8], [-27, 24], [-44, 30], [-24, -18], [-18, 42], [42, 24], [-19, -28], [-26, -18], [31, -38], [-47, -4], [-5, 30], [-30, 34], [-49, 14], [-50, -24], [26, 42], [-38, 30], [-23, 52], [-22, 40], [-70, 8], [7, -4], [14, 24], [52, 6], [-30, 6], [-14, -8], [-56, 24], [57, -48], [-52, -10], [-28, 40], [-37, -6], [2, 52], [-2, -8], [-18, 60], [-1, -50], [-49, -8], [-49, 14], [-16, 22], [55, 2], [30, 20], [-36, -14], [21, -56], [0, -40], [-57, 30], [24, -40], [22, 36], [66, 14], [-10, 46], [-21, -16], [-35, 46], [-37, 8], [-14, -22], [12, 48], [-11, 26], [40, -74], [43, -78], [46, -58], [-3, 16], [-28, 38], [-5, -10], [26, -56], [-41, 18], [39, -20], [-60, 0], [60, -70], [84, -4], [63, -20], [0, -10], [-29, 60], [61, -26], [-56, -14], [34, -8], [-76, 26], [85, -4], [38, -80], [38, -18], [24, -78], [-48, 34], [41, -8], [-36, 24], [43, -22], [-97, 0], [-34, 44], [-44, 48], [-70, -14], [-20, 24], [16, -50], [14, -28], [-18, -38], [-36, -24], [28, 4], [64, -30], [10, -26], [21, -10], [6, -12], [-44, 12], [-54, 8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1575_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1575_2_a_n();".
// 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_1575_2_a_n(:prec:=2)
    chi := MakeCharacter_1575_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_1575_2_a_n();".
// 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_1575_2_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1575_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1, 1]>,<11,R![-1, 4, 1]>,<13,R![-4, 2, 1]>],Snew);
    return Vf;
end function;