
// Make newform 3525.2.a.p in Magma, downloaded from the LMFDB on 23 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_p();".
// 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_p();".
// 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 := [-3, 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 := [[0, 1], [1, 0], [0, 0], [1, 0], [-4, 0], [-4, -1], [2, -3], [0, 1], [1, 2], [-3, 2], [0, -2], [-8, -2], [-3, -2], [8, -2], [1, 0], [-2, 7], [-10, -3], [1, -4], [2, 4], [-2, 3], [-4, 0], [2, 2], [-4, 4], [-10, 2], [2, 2], [0, -6], [9, 0], [0, -4], [0, -6], [0, 4], [10, -6], [0, 2], [2, -6], [4, 9], [0, 10], [-4, -1], [4, 12], [4, 8], [-21, -2], [-10, -5], [0, 8], [-2, -8], [-12, 6], [-8, -4], [6, -11], [12, -1], [0, -2], [10, 8], [1, -10], [-2, -2], [18, 0], [-24, 2], [-19, 4], [-14, 7], [10, 8], [2, 8], [-6, -12], [-10, -6], [8, -6], [-5, -6], [-8, -8], [-12, 2], [5, 0], [-4, -6], [-8, 7], [6, 2], [-4, 0], [4, 18], [-18, 6], [-2, 12], [4, 0], [-10, 14], [6, 16], [-20, -4], [-12, 8], [0, 0], [17, 2], [2, -18], [-4, -2], [18, 2], [14, 6], [8, 8], [-18, 3], [0, 1], [-10, -6], [-27, 2], [1, -6], [-24, -4], [18, -4], [6, 0], [-33, 2], [18, -5], [33, -4], [-38, 3], [-24, 3], [7, -6], [3, 6], [20, 4], [33, 0], [-7, -8], [12, 10], [6, 14], [-12, 8], [-6, 0], [8, -6], [-8, -9], [-16, 4], [6, -12], [4, -2], [23, 8], [8, -6], [-16, 10], [-36, 0], [10, 16], [32, -2], [-6, -20], [-19, -8], [10, -14], [-26, -3], [4, -2], [41, 0], [20, -1], [0, 22], [-32, 2], [12, -21], [-13, 10], [-2, -12], [6, -17], [4, -10], [-10, 0], [4, -6], [45, -2], [16, 11], [-4, 20], [-16, -18], [14, 12], [12, 0], [-14, -6], [10, -20], [30, 4], [-6, -4], [-15, -10], [8, 8], [-26, -10], [-8, -14], [6, -20], [-26, -10], [40, -2], [12, 9], [32, -6], [8, -17], [23, 10], [1, 12], [-8, -16], [-9, -16], [16, 6], [-12, 1], [-24, -6], [16, -16], [0, -16], [-44, 8], [8, -26], [12, 24], [-6, -22], [34, -11], [-9, -26], [-14, 20], [-8, -9], [-22, 0], [20, -4], [18, 19], [11, 16], [-8, -14], [-8, -9], [12, 17], [29, -18], [-2, 10], [-36, 0], [-4, -4], [10, -18], [8, -8], [24, -2], [26, -8], [14, -5], [5, 30], [-38, -10], [24, 6], [-13, -8], [9, 12], [6, -20], [32, 12], [-57, 6], [-60, 1], [-16, 22], [2, -10], [-4, -24], [-12, 0], [-40, 11], [54, -1], [-12, 14], [18, 8], [22, 14], [-4, 11], [13, -4], [-42, -11], [0, -24], [-32, -9], [-6, -34], [-30, 8], [-20, 2], [-4, -18], [-44, -8], [28, 12], [-11, -26], [-2, 3], [38, -2], [16, 18], [27, 6], [-54, -2], [-22, 12], [-14, -32], [38, -4], [66, -4], [18, -2], [30, -24], [-4, 14], [2, -30], [-12, -8], [-16, 24], [-14, 14], [-16, -29], [-16, -16], [0, 20], [-2, -4], [46, -10], [-16, 8], [-46, 8], [18, -17], [18, -9], [-14, 29], [7, -22], [-22, 14], [-16, -12], [10, -38], [20, 16], [-40, -10], [-15, -20], [20, 12], [16, -8], [-24, 0], [20, 15], [2, 16], [-2, 18], [18, 10], [-16, 14], [18, -23], [26, 16], [-48, 16], [-4, 10], [18, -10], [53, 12], [17, 18], [-27, -4], [36, -18], [-34, 26], [52, 8], [-40, -18], [27, -14], [36, -2], [-8, -32], [-5, 12], [-13, -12], [10, -4], [-4, 22], [12, 9], [18, -8], [-2, 6], [-17, 20], [20, 2], [14, -5], [42, -4], [16, 3], [-36, -16], [-10, 20], [-61, -12], [50, -20], [64, 11], [-24, 18], [-4, 7], [-16, 22], [50, -16], [-10, 32], [-4, 22], [34, 13], [-62, -6], [-31, -2], [-16, -26], [-2, 28], [-6, 24], [-24, 26], [24, -29], [-24, -18], [-16, 4], [24, -4], [-44, 12], [-60, 17], [-34, 8], [-53, 16], [-10, -5], [4, 16], [14, 4], [44, -8], [-13, 30], [0, 38], [-35, 30], [-1, -44], [-16, -14], [6, 0], [-28, -25], [34, -6], [-30, 10], [40, 9], [-50, 0], [-13, -16], [-6, 22], [-4, 16], [-28, -20], [40, 6], [-52, -12], [36, 16], [1, -32], [34, 27], [20, 7], [-70, 14], [42, -12], [9, 34], [-68, 10], [-34, 27], [-23, -12], [16, 14], [-14, 6], [-6, -50], [54, -4], [-44, -18], [82, -8], [-2, 25], [12, -2], [-48, 22], [-10, -29], [26, 27], [-6, -22], [-2, -24], [-10, 16], [0, -32], [28, -4], [-60, 8], [16, 42], [-6, -1], [14, 30], [9, 10], [-40, 13], [-49, 26], [24, -10], [-46, -22], [4, -38], [72, -8], [2, -28], [27, 28], [14, -8], [-46, 0], [-14, -36], [4, -20], [-30, 20], [8, -39], [76, -7], [34, 4], [-38, -9], [-46, -6], [38, -16], [-12, 8], [24, 0], [-14, 35], [-20, -38], [26, -21], [4, 32], [-41, -22], [-20, -27], [-20, -19], [-17, -8], [12, 40], [20, 30], [78, 9], [0, 40], [-43, -16], [30, -7], [-8, -32], [12, 25], [-42, 12], [-4, 14], [31, -22], [68, 12], [2, -3], [-38, -24], [-26, -33], [56, -8], [-74, 2], [86, -8], [-38, -28], [14, -26], [66, 14], [80, 11], [30, 15], [-44, -16], [16, 26], [20, 40], [-54, 4], [54, 7], [-34, 36], [-10, -14], [62, 16], [4, -14], [-40, 24], [29, -6], [-12, -46], [-48, 21], [64, 2], [20, -14], [38, 2], [0, -17], [-36, -26]];
    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_p();".
// 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_p(: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_p();".
// 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_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-3, 0, 1]>,<7,R![-1, 1]>,<11,R![4, 1]>],Snew);
    return Vf;
end function;