
// Make newform 825.4.c.f in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_825_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_825_c_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_825_4_c_f();".
// 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_825_4_c_f();".
// 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, 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_825_c();"
function MakeCharacter_825_c()
    N := 825;
    order := 2;
    char_gens := [551, 727, 376];
    v := [2, 1, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_825_c_Hecke();"
function MakeCharacter_825_c_Hecke(Kf)
    N := 825;
    order := 2;
    char_gens := [551, 727, 376];
    char_values := [[1, 0], [-1, 0], [1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 4;
    raw_aps := [[0, 1], [0, -3], [0, 0], [0, 26], [11, 0], [0, -32], [0, -74], [60, 0], [0, -182], [90, 0], [-8, 0], [0, 66], [422, 0], [0, 408], [0, 506], [0, 348], [200, 0], [132, 0], [0, 1036], [762, 0], [0, -542], [550, 0], [0, -132], [-570, 0], [0, -14], [1702, 0], [0, -1132], [0, -564], [320, 0], [0, -2142], [0, 1606], [-1908, 0], [0, 2186], [-2740, 0], [1310, 0], [-1198, 0], [0, -2114], [0, 3868], [0, -2004], [0, 678], [1680, 0], [-4358, 0], [-1778, 0], [0, -3962], [0, -374], [-2100, 0], [2232, 0], [0, 2128], [0, -2964], [2550, 0], [0, -3042], [-2700, 0], [-578, 0], [3752, 0], [0, -674], [0, -4352], [-500, 0], [-6538, 0], [0, -124], [3642, 0], [0, 4648], [0, -3102], [0, -1244], [2082, 0], [0, 2378], [0, 496], [-2708, 0], [0, -4034], [0, -11084], [3120, 0], [0, -5622], [8500, 0], [0, -7144], [0, -632], [4220, 0], [0, 8458], [-1740, 0], [0, 5126], [-3098, 0], [-6390, 0], [-9760, 0], [-5138, 0], [-7008, 0], [0, 5578], [10430, 0], [0, -4432], [6290, 0], [0, -3054], [12882, 0], [0, 6148], [0, -5124], [16520, 0], [0, -524], [-15028, 0], [-9020, 0], [0, -14812], [-12660, 0], [-3738, 0], [0, -6352], [-24728, 0], [0, 22756], [0, 9526], [0, 12068], [-15090, 0], [4412, 0], [0, 3906], [0, 12016], [0, -11342], [-20690, 0], [-598, 0], [0, 166], [0, 20108], [0, 2286], [25660, 0], [-11408, 0], [-3378, 0], [0, -11212], [0, 86], [0, -4432], [-4580, 0], [4282, 0], [0, 8438], [0, -34494], [0, -13712], [11372, 0], [-6398, 0], [5830, 0], [-34530, 0], [0, 17316], [0, -27072], [17320, 0], [0, 14588], [26152, 0], [0, 1066], [-37518, 0], [17290, 0], [0, -17172], [0, 9536], [0, 20516], [-22470, 0], [-3368, 0], [-10738, 0], [0, -15912], [0, -22924], [41690, 0], [16450, 0], [0, -30892], [0, 38906], [1020, 0], [0, 15078], [0, -22704], [-19358, 0], [0, -11252], [0, -43684], [0, -45804], [-15318, 0], [-11350, 0], [-33030, 0], [0, 10006], [2622, 0], [0, 39876], [0, 38918], [0, -1114], [-1688, 0], [0, 41826], [0, 978], [47272, 0], [0, -51104]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_825_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_825_4_c_f();".
// 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_825_4_c_f(:prec:=2)
    chi := MakeCharacter_825_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_825_4_c_f();".
// 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_825_4_c_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_825_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![1, 0, 1]>,<7,R![676, 0, 1]>],Snew);
    return Vf;
end function;