
// Make newform 3825.2.a.v in Magma, downloaded from the LMFDB on 22 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3825_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_3825_2_a_v();".
// 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_3825_2_a_v();".
// 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_3825_a();"
function MakeCharacter_3825_a()
    N := 3825;
    order := 1;
    char_gens := [2126, 2602, 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_3825_a_Hecke(Kf)
    return MakeCharacter_3825_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]];
    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, -1], [-3, 1], [4, 0], [-1, 0], [2, 2], [-3, 3], [0, -2], [5, 1], [4, 2], [0, -2], [4, 2], [6, -4], [6, 0], [-6, -2], [2, 4], [10, 0], [-3, 5], [4, 6], [-1, -9], [12, 2], [6, 6], [-2, -4], [6, -2], [-2, 4], [9, -5], [-10, 0], [0, 10], [4, -6], [-3, -3], [0, 0], [5, 5], [6, 0], [2, 2], [-2, 4], [-5, -3], [-3, -9], [0, -2], [-6, -10], [8, 6], [12, 8], [-20, -2], [0, -10], [5, -3], [5, -3], [16, -6], [21, -1], [2, 6], [6, 0], [0, -12], [-16, -6], [0, 4], [0, 4], [-12, -6], [6, 4], [-4, -4], [-14, 4], [6, -4], [7, 1], [6, 4], [10, 0], [-3, -11], [16, -6], [-18, 4], [-10, -2], [-14, -12], [9, 3], [-10, -12], [6, -12], [18, -2], [13, 3], [-20, 0], [23, 3], [12, -2], [-6, -6], [-14, 0], [-6, 4], [26, 0], [-33, 3], [2, -2], [-15, -3], [4, -8], [-1, 11], [-6, 4], [24, -6], [16, -12], [18, -4], [10, -8], [12, 6], [3, -5], [1, 15], [30, 6], [-7, 5], [3, -7], [-6, 8], [-18, -8], [22, 0], [8, -18], [7, -19], [0, 4], [24, -2], [-6, 20], [-7, 17], [4, -20], [36, -6], [6, -8], [-12, 0], [-16, -14], [13, -5], [-2, 8], [-24, 2], [23, -9], [-22, 6], [0, 18], [19, -3], [-18, 12], [-36, -6], [12, -12], [-22, -8], [-20, 2], [-18, -12], [9, 23], [-13, 15], [6, 10], [8, 2], [21, 9], [-14, -8], [-2, 0], [-22, -6], [-21, 1], [35, -5], [4, 20], [18, -6], [26, -6], [-12, 20], [-11, 19], [-18, 4], [42, -8], [5, -23], [18, -4], [-17, -15], [-21, -3], [-10, -16], [-21, -1], [-8, -18], [0, -18], [-22, 2], [30, 4], [22, 12], [24, -10], [10, 0], [-9, -7], [-29, 1], [-45, -5], [-40, 0], [0, -2], [-2, -20], [-24, 14], [3, -3], [12, 12], [-8, 18], [-30, 14], [30, 0], [57, -1], [23, 15], [-8, -6], [2, -4], [-24, -6], [36, 16], [2, 34], [9, 29], [4, 20], [2, 6], [-30, -4], [-19, -7], [-36, -10], [16, 18], [-10, -2], [-2, 0], [-9, 19], [-2, 4], [18, 0], [-12, 26], [-30, -6], [22, -12], [-38, 0], [-4, 10], [3, -1], [-26, 16], [3, 1], [-10, 22], [6, 6], [-21, -11], [0, -34], [8, -2], [22, 0], [-12, 18], [-30, 0], [-12, 6], [23, -21], [-14, -4], [26, -2], [-48, 4], [36, -12], [20, -20], [-12, -18], [-18, 8], [-4, -12], [46, -12], [30, 14], [19, -27], [12, 14], [-3, -11], [-28, -10], [10, 28], [6, -24], [33, -5], [24, 20], [-10, 32], [11, -9], [-54, 0], [7, 9], [42, 16], [62, -6], [18, 0], [27, 15], [28, -18], [-9, -25], [-14, 28], [-13, -9], [38, 14], [6, -10], [22, 8], [24, -2], [8, 18], [-6, -20], [9, -19], [6, -22], [3, -15], [32, -24], [-62, 0], [-22, 30], [-30, 4], [21, 17], [13, -5], [15, 7], [-22, -22], [0, -18], [-26, -12], [-6, -8], [-12, 34], [-4, 6], [36, 4], [12, 0], [-16, -14], [-65, -3], [12, -6], [4, 0], [-17, -15], [6, -12], [68, -2], [-2, 16], [-6, -4], [-52, 0], [-42, 12], [42, -16], [-5, -27], [-30, -20], [-28, 6], [22, 28], [46, -12], [-10, 18], [-14, 0], [-20, -34], [72, -2], [-34, -10], [-34, 10], [-42, 6], [6, 12], [35, 3], [-75, -1], [38, -12], [-17, -27], [36, -4], [-32, 6], [0, 2], [38, -14], [-6, -6], [-54, -4], [33, -5], [0, -12], [-3, 25], [22, -12], [-18, 20], [20, -12], [-60, -8], [-63, 1], [52, 2], [-56, 0], [-24, 24], [23, -17], [15, 5], [-1, 7], [-50, 12], [-30, 28], [-4, -38], [-36, 8], [58, 16], [-15, 7], [-12, 30], [18, -16], [-20, 18], [-6, 32], [-34, -8], [-42, 14], [57, -7], [-26, -4], [6, 0], [35, 31], [46, 0], [-42, 8], [34, 16], [-66, 12], [14, -12], [5, -3], [-29, -3], [-15, 19], [6, -4], [14, -12], [24, 34], [-61, 15], [-42, 24], [17, 1], [-9, 17], [14, 32], [72, 10], [32, -10], [52, -18], [34, -12], [6, -28], [-18, 12], [56, -12], [24, 4], [-9, -5], [-70, 0], [22, 32], [-21, 7], [48, 10], [38, -6], [-14, 40], [-30, 0], [-53, -19], [2, -18], [-48, 16], [18, 14], [15, -5], [0, -34], [-72, -2], [16, -18], [-42, 28], [-30, -12], [-33, -5], [16, -6], [-14, -12], [-30, 8], [70, 0], [-28, 18], [-18, -2], [11, -13], [-15, -33], [18, -42], [-28, 24], [-68, -2], [-33, -17], [39, 15], [-44, -24], [78, 4], [-2, -16], [-48, -6], [18, -12], [1, 55], [42, 4], [-19, 1], [-15, 31], [-34, -22], [-32, -32], [-47, 27], [6, -32], [-4, 10], [18, 32], [12, 44], [-2, 24], [-18, -18], [4, -26], [8, 36], [-6, -48], [17, -7], [54, 18], [-34, 24], [12, -4], [-2, -36], [6, 4], [30, 16], [29, 33], [-8, -32], [-54, 18], [4, 18], [27, -13], [-26, 24], [-60, 12], [-42, -20], [47, 15], [-2, -52], [-60, -10], [-57, -5], [73, 7], [-18, -24], [18, -28], [-6, 8], [-26, 16], [-63, -5], [-6, 6], [46, 24], [6, -32], [-57, -3], [-36, -38], [32, -16], [51, -25]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3825_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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