
// Make newform 11.4.a.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_11_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_11_4_a_a();".
// 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_11_4_a_a();".
// 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_11_a();"
function MakeCharacter_11_a()
    N := 11;
    order := 1;
    char_gens := [2];
    v := [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_11_a_Hecke(Kf)
    return MakeCharacter_11_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 := 4;
    raw_aps := [[1, 1], [-1, -4], [1, 8], [10, -4], [-11, 0], [40, -20], [-62, 12], [36, 60], [-49, -36], [72, -56], [-17, 28], [27, -8], [268, -4], [-30, -16], [-136, -120], [-246, -56], [317, -132], [420, 184], [377, -20], [-339, 76], [-200, -468], [158, 656], [234, 120], [-921, -328], [1097, 144], [566, -420], [-880, 488], [174, 380], [490, 320], [-855, 664], [-604, -412], [-222, -796], [905, 408], [-1466, 828], [530, -1708], [-1870, -408], [1409, 616], [-2060, -384], [1608, 652], [2058, 144], [-2871, 900], [1303, -1216], [2321, -348], [-572, 1104], [-4322, 464], [408, 240], [1500, -928], [-1973, -1132], [1422, -1844], [3495, -912], [2304, 1208], [114, -2424], [1456, 1416], [409, 396], [-1226, 1160], [3194, 1724], [3010, -1168], [3032, 892], [166, 232], [198, 2952], [-4964, 136], [-3276, 3236], [-1588, -52], [-1956, 3192], [3263, 2264], [109, -72], [3607, -2844], [5726, -3444], [-632, -3020], [5106, -932], [-2589, -4808], [-7808, -2132], [8215, -836], [-2726, -1492], [-1829, 572], [-4585, 1012], [-2847, 3440], [9262, 2856], [-2950, -1912], [2514, -3872], [-12100, 1624], [-170, 7688], [2658, 1300], [-6755, -2880], [-2000, -5672], [10885, -452], [8315, -5000], [-13380, 1624], [6660, -1112], [-2243, 3276], [-5019, 5852], [10784, 452], [-5641, -7324], [-10472, 1648], [-3580, 9520], [8974, 688], [2487, 2288], [-5859, -7776], [9356, -1788], [-2348, -6732], [-7984, 1752], [-7910, 2372], [-9332, -328], [-2472, 4504], [-7180, -5648], [-17607, 1224], [484, 6120], [3740, 352], [11632, 896], [-6994, -6796], [9650, 7056], [4592, -4688], [-3246, -11248], [-4393, -9844], [8791, 7356], [6375, 7952], [8189, 11940], [-6031, 2564], [13183, 3952], [2338, -7424], [2797, 288], [11006, -7040], [5538, 4436], [-21688, 4536], [8993, -10860], [5126, 14332], [15215, -2256], [-15393, -9948], [-4029, 2036], [10308, -968], [-22750, 2536], [-9020, 11664], [3937, 7388], [5666, -17360], [21432, -7484], [10616, 12828], [-24126, -6608], [5656, 5816], [-9571, 10080], [14772, -5124], [23842, -5568], [-8618, -6480], [1887, -17372], [-1864, 20724], [1897, 1752], [-37781, -236], [10238, 18896], [13064, -17520], [19425, -5836], [2352, -6928], [-11760, 18180], [11645, 4520], [48940, 88], [25394, -9296], [29652, 4640], [18348, 8488], [4066, -15712], [-8310, -8584], [-29524, -2916], [28626, 7624], [-2955, 17428], [10102, 17804], [-27176, -10968], [-12865, 4452], [12117, -1400], [1815, 17956], [-4304, 19504], [-29374, -1484]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_11_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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