
// Make newform 3525.2.a.s in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3525_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_3525_2_a_s();".
// 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_3525_2_a_s();".
// 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_3525_a();"
function MakeCharacter_3525_a()
    N := 3525;
    order := 1;
    char_gens := [2351, 1552, 2026];
    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_3525_a_Hecke(Kf)
    return MakeCharacter_3525_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, 1], [-1, 0], [0, 0], [3, 0], [0, 2], [5, 1], [3, -3], [-3, -3], [3, 2], [-3, -2], [2, 0], [2, -4], [1, 4], [2, 2], [1, 0], [-3, 5], [5, -1], [-3, 0], [2, -10], [-9, -3], [0, 6], [-4, 0], [4, 4], [-4, -8], [-4, 6], [10, 4], [11, -2], [4, -4], [6, 0], [-12, 2], [12, 6], [-6, 0], [-12, -2], [5, 7], [10, -2], [-1, -5], [8, 4], [20, 0], [1, -16], [-3, -1], [12, 0], [-6, -6], [-6, 4], [-8, -6], [-9, 9], [7, 3], [-6, -12], [-2, -14], [-1, 2], [-4, 16], [2, -8], [-14, -8], [25, 0], [3, -5], [-6, -10], [6, -2], [-10, -4], [8, 10], [30, 0], [-1, -14], [0, 0], [-2, -22], [7, -18], [2, -8], [-11, 3], [-24, -2], [-24, 0], [14, -16], [0, -18], [-22, 6], [-8, 2], [-16, 2], [22, 0], [4, -18], [24, -6], [0, 18], [-23, 2], [12, -6], [-6, 6], [-20, 4], [0, -6], [16, -16], [-9, 17], [-17, -1], [-20, -4], [15, 8], [-15, 2], [0, 12], [18, 12], [-2, -10], [1, 26], [-9, 7], [-1, 18], [-21, 9], [11, -3], [-15, 2], [3, 26], [12, -16], [-13, -4], [25, -10], [-10, -6], [0, 22], [12, 4], [-10, -20], [14, -12], [-19, 11], [-12, -8], [-18, 18], [10, -14], [-17, 6], [18, -6], [26, -8], [0, -2], [2, 0], [26, 0], [26, -4], [31, 8], [20, 10], [-9, -15], [-6, 20], [17, 6], [-27, 9], [-6, 2], [6, -6], [-13, -25], [15, -4], [34, -12], [3, 5], [14, 22], [18, -6], [2, -26], [-21, 12], [-25, -9], [20, 10], [18, -22], [-14, 0], [-8, -10], [-12, 30], [-42, -2], [-18, -12], [6, 0], [13, 28], [32, 0], [20, 8], [-18, 6], [-18, -12], [8, 10], [-6, -8], [9, 9], [38, -10], [33, 9], [27, -6], [-17, -18], [8, 20], [-11, 18], [30, -16], [-31, -3], [-14, -2], [4, 6], [0, -28], [-8, 22], [6, -18], [12, -12], [-12, 10], [27, -19], [-35, -8], [14, 12], [-15, -15], [-26, 12], [-4, -22], [-21, -11], [3, 24], [22, 26], [-31, -3], [37, -5], [-7, 10], [-4, 18], [-4, -32], [-32, -20], [28, 14], [24, 0], [18, 6], [38, 2], [-15, 21], [35, -4], [24, 16], [22, -6], [9, 0], [21, 24], [-30, 12], [16, -18], [-11, 14], [-3, 39], [-14, 10], [0, -16], [24, 18], [-28, -14], [13, 33], [9, -1], [2, 16], [-22, -14], [4, 4], [-11, 23], [-15, -18], [21, -29], [20, -34], [31, 21], [-24, 30], [30, -16], [18, -36], [-38, -12], [-12, -34], [32, 24], [-53, 8], [15, -3], [-44, 2], [38, 12], [27, -12], [48, -6], [-30, -18], [-38, -12], [22, 0], [-22, 8], [4, 42], [42, -4], [38, -10], [44, 16], [-12, -6], [16, -8], [-12, -22], [-31, -13], [0, 42], [4, 34], [-2, 46], [-20, 0], [32, -16], [18, 0], [-27, -5], [-21, -9], [21, 5], [33, -24], [-16, -32], [-36, 6], [-4, 26], [-8, -2], [-50, 8], [7, -2], [20, -2], [20, -22], [44, -2], [-15, 39], [-22, -10], [-4, -50], [-44, -14], [-18, 4], [-7, 29], [2, -42], [-12, 18], [22, 14], [56, -10], [-5, -28], [-37, -20], [-7, -36], [42, 24], [60, -8], [28, 38], [-18, 4], [-33, -14], [6, 36], [16, -10], [-1, 14], [-43, 16], [-26, 24], [-26, 0], [-17, 45], [-10, 34], [72, 4], [-5, -28], [-22, 28], [15, 17], [18, 0], [7, 15], [-8, 32], [2, 8], [-11, 6], [-54, -6], [-31, 3], [6, 42], [11, 5], [-6, 4], [34, 20], [70, -2], [-42, -12], [21, -3], [44, 6], [-43, -16], [-42, -24], [-70, -8], [42, -26], [-34, -12], [5, -15], [-18, 36], [32, -2], [20, 8], [32, -12], [19, -25], [18, -2], [-61, -2], [11, 11], [-40, 24], [30, 14], [12, 20], [-21, 2], [2, -16], [19, -28], [35, -32], [-14, 2], [-74, 2], [-11, -47], [-48, 28], [32, 32], [-1, -13], [-46, 8], [-71, 8], [-44, 22], [12, 6], [68, 12], [62, -14], [48, -24], [-40, 14], [-23, -18], [-51, -15], [47, -29], [-40, -14], [-14, -12], [-5, -8], [-34, -6], [9, -15], [29, -16], [46, 8], [56, -4], [0, 36], [30, 14], [-14, 12], [42, 20], [-15, 31], [-38, -16], [-42, -6], [-17, 29], [9, -25], [8, 30], [-42, 18], [-22, 16], [16, 34], [4, 16], [-20, 8], [-22, 40], [27, 35], [-40, -16], [19, 46], [-9, -15], [51, 6], [-30, -26], [4, -10], [18, 24], [44, -18], [-10, 34], [-59, -12], [-34, 18], [42, -22], [-2, 2], [24, -16], [-78, 0], [-15, 39], [7, -55], [42, 36], [7, 17], [48, 6], [-62, -4], [-16, -14], [60, 22], [-51, -3], [14, 0], [9, 23], [-56, 8], [17, -50], [-39, 39], [-5, 17], [-27, 6], [-48, 24], [-38, 24], [23, 47], [48, 2], [-49, -16], [-19, 17], [28, 24], [25, 21], [42, -26], [-18, 60], [51, -4], [28, 20], [3, -15], [6, 0], [-19, 17], [32, -10], [48, 0], [-6, 0], [18, 36], [-64, -8], [36, 40], [-3, 21], [37, -7], [-36, -28], [14, 8], [-28, 16], [2, 8], [-9, 3], [66, 0], [-48, -12], [6, -56], [18, 18], [16, -36], [31, 26], [54, -20], [-41, 17], [-42, 12], [-22, 44], [32, -14], [23, 1], [-46, 32]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3525_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3525_2_a_s();".
// 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_3525_2_a_s(:prec:=2)
    chi := MakeCharacter_3525_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_3525_2_a_s();".
// 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_3525_2_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -2, 1]>,<7,R![-3, 1]>,<11,R![-8, 0, 1]>],Snew);
    return Vf;
end function;