ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 26 Nov 2022 13:51:22 +0100How to write a p-adic exponent b^k as a Power series in k ?https://ask.sagemath.org/question/65075/how-to-write-a-p-adic-exponent-bk-as-a-power-series-in-k/Let $b$ be p-adic number, we write $b$ as a Power series in $p$ with a given precison. Is It possible to write $b^k$ as a Power series in $k$, with $k$ an integer ? An example : Let $\gamma_1$ and $\gamma_2$ be the 3-adic unit roots of the quadratic equations $x^2+x+3=0$ and $x^2+2x+3=0$ respectively. Let $k$ be an integer. Let
$$c(k) = \frac{\gamma_1^k}{\gamma_1^2 -3} + \frac{\gamma_2^k}{\gamma_2^2 -3} + 1$$
The problem is to show that
$$v_3(c(k) - 9(-1+4k^2)-27(k^3 + k^4))\geq 4.\qquad (1)$$
I know how to write $\gamma_1$ and $\gamma_2$ as a 3-adic power series with given precision, but have no idea how to work with the exponent. I've tried (1) for k integer between 1 and 100 and the inequality is true only for even numbers. For odd numbers, the left side of (1) is zero.
The inequality (1) is from the article Numerical experiments on families of modular forms by Coleman, Stevens, and Teitelbaum, page 7.ClaudiodsvSat, 26 Nov 2022 13:51:22 +0100https://ask.sagemath.org/question/65075/Koike's Trace Formulahttps://ask.sagemath.org/question/63231/koikes-trace-formula/ Koike's Trace Formula states that
\begin{equation}
\mbox{Tr}((U_p^{\kappa})^n) = - \sum_{0 \leq u < \sqrt{p^n}\\
(u,p)=1}H(u^2-4p^n)\frac{\gamma(u)^\kappa}{\gamma(u)^2 - p^n}-1,
\end{equation}
where $\kappa\in \mathbb{C}_p$, $H(D)$ is the Hurwitz class number of $D$, and $\gamma(u)$ is the unique $p$-adic unit root of the equation
$$x^2-ux+p^n=0.$$
Is there an implementation of this formula in sage ?ClaudiodsvWed, 13 Jul 2022 12:52:36 +0200https://ask.sagemath.org/question/63231/Residue calculation in Sagemathhttps://ask.sagemath.org/question/62355/residue-calculation-in-sagemath/I have done the following calculation in maple, I want to know if we can do it in Sagemath and write a code using the recursive definition.
We construct a family of meromorphic function $W_{g,n}(z_1, z_2, \ldots, z_n)$. We consturct it recursively. The intial data given is the following.
$$y(z) = 2 \frac{sinh^{-1}(z/(2a)^{1/2})}{(z^2 +2a)^{1/2}}$$
where $sinh(z)$ is sine hyperbolic funciton can be defined directly in maple as it is.
$$ K(z):=\frac{1}{z(y(z) - y(-z))} \rightarrow 1/2\,{\frac {a}{{z}^{2}}}+1/6-{\frac {{z}^{2}}{90\,a}}+{\frac {{z}^{4}
}{378\,{a}^{2}}}-{\frac {23\,{z}^{6}}{28350\,{a}^{3}}}+{\frac {263\,{z
}^{8}}{935550\,{a}^{4}}}-{\frac {133787\,{z}^{10}}{1277025750\,{a}^{5}
}}+{\frac {157009\,{z}^{12}}{3831077250\,{a}^{6}}}-{\frac {16215071\,{
z}^{14}}{976924698750\,{a}^{7}}}+{\frac {2689453969\,{z}^{16}}{
389792954801250\,{a}^{8}}}+O \left( {z}^{18} \right)
$$
$K(z)$ we define using $sinh(z)$ and take the Taylor series expansion to study the few terms.
Let $W_{0,2}(z_1, z_2): = 1/(z_1 - z_2)^2$
Having this initial data we can construct a tower of $W_{g,n}(z_1, z_2, \ldots, z_n )$ as follows. Let me give few examples that I have computed by hand in maple.
Let's give some examples of how to generate families of functions
$$W_{1,1} = Res_{z =0}\, K(z)\frac{1}{z-z_1} W_{0,2}(z,-z) = 1/24\,{\frac {{{\it z1}}^{2}+3\,a}{{{\it z1}}^{4}}}
$$
Taking residue at $z =0$ means collecting the $1/z$ ceofficients.
$$W_{0,3}(z_1, z_2 , z_3) = Res_{z =0}\, K(z)\frac{1}{z-z_1} \left(W_{0,2}(z_1,-z)W_{0,2}(z_2,z) + W_{0,2}(z_2,-z)W_{0,2}(z_1,z)\right)= {\frac {a}{{{\it z2}}^{2}{{\it z3}}^{2}{{\it z1}}^{2}}}
$$
$$W_{1,2}(z_1 , z_2) =Res_{z =0}\, K(z)\frac{1}{z-z_1} \left( W_{0,3}(z,-z,z_2) + W_{0,2}(z,z_2)W_{1,1}(-z)+ W_{0,2}(-z,z_2)W_{1,1}(z)\right)= \\ 1/8\,{\frac { \left( 2\,a{{\it z1}}^{2}+5\,{a}^{2} \right) {{\it z2}}^
{4}+ \left( 2\,a{{\it z1}}^{4}+3\,{a}^{2}{{\it z1}}^{2} \right) {{\it
z2}}^{2}+5\,{a}^{2}{{\it z1}}^{4}}{{{\it z1}}^{6}{{\it z2}}^{6}}}
$$
So let's define $W_{g,n}(z_1 , z_2, \ldots, z_n)$ in general by taking the residue of $$W_{g_1,n_1}(z,\ldots)W_{g_2 , n_2}(-z,\ldots) + W_{g-1 , n+1}()\tag{*}$$
along with the product $ K(z)\frac{1}{z-z_1}$.
$W_{g_1,n_1}(z_1 , z_2, \ldots, z_{n_1})$ represent meromorphic functions in $n_1$ variables. And the sum is taken over all such possible combinations. And in case of $W_{g-1 , n+1}(z,-z,z_2 \ldots z_n)$.
In general, if we can write a code where we can give the initial data and then will compute $W_{g,n}(z_1, z_2, \ldots , z_n)$. It should be a recursive definition. I maple I cannot compute more than $(3,1)$ tuples. But with effective Dynamical programming, we definitely can do more.
If someone shows me how to do the initial computation in sagemath, then I will try to write the general programme.AnupamsageSun, 08 May 2022 07:19:30 +0200https://ask.sagemath.org/question/62355/using @interact to enter some information in election systemhttps://ask.sagemath.org/question/54853/using-interact-to-enter-some-information-in-election-system/ The following code gives the candidat who must be eliminated in a *Nanson election *.
def Nanson_one(cand, partisans,code):
Scand=sorted(Set(cand))
ncand=len(cand)
All_pref=Arrangements(Scand,ncand).list()
All_pref_with_index = [(i,All_pref[i]) for i in range(len(All_pref))]
rank=[[(list(All_pref[i]).index(cand[j]))+1 for i in range(len(All_pref))] for j in range(len(cand))]
score = piecewise([([i,i], ncand+1-i) for i in range(ncand+1)])
scores=[[partisans[i]*score(rank[j][i]) for i in range(len(All_pref))] for j in range(len(cand))]
totscore=[add(scores[i]) for i in range(len(cand))]
augmented_scores = [scores[i]+[totscore[i]] for i in range(len(cand))]
ahr=[i for i in range(len(All_pref))]+["$\\text{Total}$"]
minvote = min(totscore)
candidat_éliminé=min(totscore)
indice_candidat_éliminé=totscore.index(min(totscore))
nom_candidat_éliminé=cand[indice_candidat_éliminé]
if code == 1 :
return table(augmented_scores,header_row=ahr,header_column=["$\\stackrel{\\normalsize Préf}{Cand}$","$\\boldsymbol{A}$","$\\boldsymbol{B}$","$\\boldsymbol{C}$","$\\boldsymbol{D}$"])
elif code == 2 :
show(LE(r"\text{Le candidat éliminé est le candidat }"), nom_candidat_éliminé, LE(r"\text{ qui n'a reçu que }"),minvote,LE(r"\text{ votes.}"))
elif code == 3 :
return nom_candidat_éliminé
code = 1 gives the table of scores
code =2 gives the name of the candidat who must be excluded.
In what concerns passing the `cand` parameter, there is no difficulty it must be
cand = ["A","B","C","D"]
For `partisans` parameter it's much involved, since it correspond to the number of electors whose preferences are `ABCD`, `ACBD`, `ACDB`... For teaching purpose, it is necessary to construct a list of number whise entries correspond to the number of voters for `ABCD`...
I have seen that input is possible with `@interact`but the display is elementary and works for small matrix. Here I need
the some information (the `ABCD's`) be above the cell which must be documented (by default it is zero).
I can do it manualy as demonstrated by the following code :
cand = ["A","B","C","D"]
All_pref=Arrangements(Scand,ncand).list()
LE=LatexExpr
All_pref_with_index = [(i,All_pref[i]) for i in range(len(All_pref))]
show(LE(r"\text{Toutes les préférences sont possibles} "))
show(All_pref_with_index)
#Toutes les entrées de partisans sont mises à 0 puis on rajoute celles qu'on veut.
partisans=[0 for i in range(len(All_pref))]
partisans[1]=25
partisans[10]=15
partisans[12]=5
partisans[16]=12
partisans[23]=3
hr=[i for i in range(len(All_pref))]
show(LatexExpr(r"\text{Le nombre des électeurs qui adoptent les préférences sont :}"))
table([partisans], header_row=hr,header_column=[r"$ \text{Indice des préférences }",r"$\text{Nombre d'électeurs}"],frame=true)
but I think it will be better if my student can change thge number of electors in an `@interact` cell.
But if there is no solution it's not a big problem. Now my true problem is the following:
the result of `Nanson_one(cand, partisans,3)` is the name of the eliminated candidate. So I must drop its name from the list `cand`. Here is the code
cand.remove(Nanson_one(cand, partisans,3))
and this works. But if I try to allocate
cand1=cand.remove(Nanson_one(cand, partisans,3))
when I try to display it I obtain nothing.
Hope to have been clear and to have given all needed information.CyrilleTue, 22 Dec 2020 22:30:15 +0100https://ask.sagemath.org/question/54853/