\documentclass{beamer}

\mode<presentation> {
  \usetheme{Montpellier}
  \setbeamercovered{transparent}
}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{times,url,tikz, tikz-cd}
\usepackage[T1]{fontenc}
\newcommand{\Cl}{\mathcal{C}\ell}
\newcommand{\N}{\mathcal{N}}
\renewcommand{\P}{\mathcal{P}}
\renewcommand{\O}{\mathcal{O}}
\newcommand{\p}{\mathfrak{p}}
\newcommand{\f}{\mathfrak{f}}
\renewcommand{\L}{\mathcal{L}}
\renewcommand{\S}{\mathfrak{S}}
\newcommand{\CC}{\mathbb{C}}
\newcommand{\PP}{\mathbb{P}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\FF}{\mathbb{F}}
\renewcommand{\d}{\mathrm{d}}
\newcommand{\Gal}{\mathrm{Gal}}
\newcommand{\frob}[2]{\left(\frac{#1}{#2}\right)}
\newcommand{\val}{v}
%\renewcommand{\theorem}{}
\newtheorem{defi}{Définition}
\newtheorem{theorema}{Théorème}
\newtheorem{lemmaa}[theorem]{Lemme}
\newtheorem{remark}[theorem]{Remarque}
\newtheorem{princip}[theorem]{Principe}
\newtheorem{algorithm}[theorem]{Algorithme}
\renewcommand{\theorem}{\theorema}
\renewcommand{\lemma}{\lemmaa}
\newcommand{\kbd}[1]{\texttt{#1}}

\title{Some new GP features}
\subtitle{A tutorial}

\author{B.~Allombert}
\institute
{
  IMB \\
  CNRS/Université de Bordeaux
}

\date{20/01/2020}

%\subject{Exposé}
%\logo{\pgfimage[height=1cm]{um2.png}}
%\logo{\pgfuseimage{um2}}
%\logo{\includegraphics[height=1.5cm]{um2.png}}
%\AtBeginSubsection[] {
%  \begin{frame}<beamer>{Lignes directrices}
%    \tableofcontents[currentsection,currentsubsection]
%  \end{frame}
%}

%\beamerdefaultoverlayspecification{<+->}

\begin{document}
\begin{frame}
  \titlepage
\input ../opendreamkit.tex
\end{frame}

%\begin{frame}
%  \tableofcontents
%  % Vous pouvez, si vous le souhaiter ajouter l'option [pausesections]
%\end{frame}

\begin{frame}[fragile]{References}
It is now possible to pass vectors and matrices by references with \verb!~!.
\begin{verbatim}
? V = [1,2,3];
? f(V,x) = V[x]++;
? f(V,1)
%3 = 2
? V
%4 = [1,2,3]
? f(~V,x) = V[x]++;
? f(~V,1)
%6 = 2
? V
%7 = [2,2,3];
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{References}
It also works with lists and map. For better legibility it is encouraged to
use \verb!~! with \kbd{listput} and \kbd{mapput}.
\begin{verbatim}
? L = List([1,2,3]);
? f(~L,x) = listput(~L,x^2);
? f(~L,5)
%10 = 25
? L
%11 = List([1,2,3,25])
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{References}
User-defined member functions now always use references:
\begin{verbatim}
? a.inc=a[1]++;
? V.inc
%13 = 2
? V
%14 = [3,2,3]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{References}
Using references avoid copies when passing large objects:
\begin{verbatim}
? W=vector(1000,i,i!);
? f(x)=x[1];
? g(~x)=x[1];
? x.b = x[1];
? default(timer,1);
? for(i=1,10^5,W[1])
time = 5 ms.
? for(i=1,10^5,f(W))
time = 3,718 ms.
? for(i=1,10^5,g(~W))
time = 12 ms.
? for(i=1,10^5,W.b)
time = 12 ms.
? default(timer,0);
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{polrootspadic}
\kbd{polrootspadic} now support unramified extensions:
\begin{verbatim}
? T = y^2+y+1; p = 2;
? lift(polrootspadic(x^3-x^2+64*y, [T,p], 5))
%26 = [(2^3+O(2^5))*y+(2^3+O(2^5)),
%     (2^3+2^4+O(2^5))*y+(2^3+2^4+O(2^5)),
%     1+O(2^5)]~
\end{verbatim}
This also works with \kbd{hyperellpadicfrobenius}.
\end{frame}

\begin{frame}[fragile]{qfbsolve}
\kbd{qfbsolve} now accepts a flag to select output:
\begin{itemize}
\item bit $0$: return one / all the solutions modulo units of positive norms.
\item bit $1$: return primitive / non-primitive solutions
\end{itemize}
Primitive means that $x$ and $y$ are coprime.
\begin{verbatim}
? qfbsolve(Qfb(1,0,1),65,0)
%27 = [8,-1]
? qfbsolve(Qfb(1,0,1),65,1)
%28 = [[8,-1],[7,4],[7,-4],[-8,-1]]
? qfbsolve(Qfb(1,0,1),65,2)
%29 = [8,-1]
? qfbsolve(Qfb(1,0,1),65,3)
%30 = [[8,-1],[7,4],[7,-4],[-8,-1]]
\end{verbatim}
\end{frame}
\begin{frame}[fragile]{qfbsolve}
\begin{verbatim}
? qfbsolve(Qfb(1,0,1),20,0)
%31 = []
? qfbsolve(Qfb(1,0,1),20,1)
%32 = []
? qfbsolve(Qfb(1,0,1),20,2)
%33 = [-4,-2]
? qfbsolve(Qfb(1,0,1),20,3)
%34 = [[-4,-2],[4,-2]]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{matreduce}
\kbd{matreduce} reduce factorization matrices with redundant factors.
\begin{verbatim}
? M = matconcat([factor(12),factor(20)]~)
%35 = [2,2;3,1;2,2;5,1]
? F=matreduce(M)
%36 = [2,4;3,1;5,1]
? factorback(F)
%37 = 240
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{fft, fftinv}
Compute fast Fourier transform of order $2^n$,
given the vector of roots of unity.
\begin{verbatim}
? P = x^3+2*x^2+3*x+4; w = rootsof1(4)
%38 = [1,I,-1,-I]~
? f = fft(w, P)
%39 = [10,2+2*I,2,2-2*I]
? apply(z->subst(P,x,z),w)
%40 = [10,2+2*I,2,2-2*I]~
? fi = fftinv(w, f)
%41 = [16,12,8,4]
? Polrev(fi/#fi)
%42 = x^3+2*x^2+3*x+4
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{fft, fftinv}
Over a finite field:
\begin{verbatim}
? w = powers(znprimroot(5),3)
%43 = [Mod(1,5),Mod(2,5),Mod(4,5),Mod(3,5)]
? f = fft(w, P)
%44 = [Mod(0,5),Mod(1,5),Mod(2,5),Mod(3,5)]
? apply(z->subst(P,x,z),w)
%45 = [Mod(0,5),Mod(1,5),Mod(2,5),Mod(3,5)]
? fi = fftinv(w, f)
%46 = [Mod(1,5),Mod(2,5),Mod(3,5),Mod(4,5)]
? lift(Polrev(fi/#fi))
%47 = x^3+2*x^2+3*x+4
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Euler numbers and polynomials}
Analogous to Bernoulli polynomials $B_n(x)$ and numbers $B_n$
(\kbd{bernpol}, \kbd{bernfrac}) satisfying
$$ \frac{t e^{xt}}{e^t - 1} = \sum_{n\ge 0} B_n(x) \frac{t^n}{n!},\quad
B_n = B_n(0),$$
we now have Euler polynomials $E_n(x)$ (\kbd{eulerpol}) and numbers $E_n$
(\kbd{eulerfrac})
%$$ \frac{1}{\cosh t} = \sum_{n\ge 0} E_n \frac{t^n}{n!}$$
$$ \frac{2}{e^{xt} + 1} = \sum_{n\ge 0} E_n(x) \frac{t^n}{n!},\quad
E_n = 2^n\*E_n(1/2)$$
\begin{verbatim}
? serlaplace(1/cosh(t+O(t^10)))
%48 = 1-t^2+5*t^4-61*t^6+1385*t^8+O(t^10)
? vector(10,i,eulerfrac(i))
%49 = [0,-1,0,5,0,-61,0,1385,0,-50521]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{eulerfrac, eulerpol, eulervec, eulerianpol}
Similarly, in addition to $\kbd{bernvec(n)} = [B_0,B_2,\dots,B_{2n}]$ we now
have $\kbd{eulervec(n)} = [E_0,E_2,\dots,E_{2n}]$. We also have Eulerian
polynomials $A_n(x)$(\kbd{eulerianpol})
$$ \frac{x}{1 + x - e^{tx}} = \sum_{n\ge 0} A_n(x+1) \frac{t^n}{n!},\quad
\text{s.t.}
\sum_{j\ge 0} x^j j^n = \frac{x A_n(x)}{(1-x)^{n+1}}.
$$
\begin{verbatim}
? eulervec(5)
%50 = [1,-1,5,-61,1385,-50521]
? eulerpol(5)
%51 = x^5-5/2*x^4+5/2*x^2-1/2
? vector(4,i,eulerianpol(i))
%52 = [1,x+1,x^2+4*x+1,x^3+11*x^2+11*x+1]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Asymptotic expansion}
The function \kbd{asympnum} computes numerically as many terms of an
asymptotic expansion $f(n) \approx a_0 + a_1 / n + \dots + a_k / n^k$
as it can. But it fails when the expansion is not rational. The variant
\kbd{asympnumraw} takes $k$ as extra argument (mandatory!) and approximates
$(a_0,\dots,a_k)$ without assumptions. This allows for instance to take
periods into account before rationalizing.
\begin{verbatim}
? f(n) = n! / (n^n * exp(-n) * sqrt(n));
? asympnum(f)
%54 = []  \\ fail
? v = asympnumraw(f, 3)
%55 = [2.506..., 0.208..., 0.008..., -0.006..]
? bestappr(v / v[1])
%56 = [1, 1/12, 1/288, -139/51840]  \\ Stirling expansion
\end{verbatim}
In the above, we don't need to know that $\kbd{v[1]} \approx \sqrt{2\pi}$.
\end{frame}

\begin{frame}[fragile]{ffmaprel}
Extend partial maps between finite fields.
\begin{verbatim}
? a = ffgen([3,5],'a);
? b = ffgen([3,10],'b);
? m = ffembed(a, b);
? mi= ffinvmap(m);
\end{verbatim}
$m$ is the inclusion from $\FF_{3^5}$ to $\FF_{3^{10}}$.
$mi$ is the reverse partial map from the image of $m$ to $\FF_{3^5}$.
\kbd{ffmaprel} extends $mi$ to a map from $\FF_{3^{10}}$ to an algebraic
extension of $\FF_{3^5}$.
\end{frame}
\begin{frame}[fragile]{ffmaprel}
\begin{verbatim}
? R = ffmaprel(mi,b)
%61 = Mod(b,b^2+(a+1)*b+(a^2+2*a+2))
\end{verbatim}
This can be used to compute relative minimal polynomials:
\begin{verbatim}
? minpoly(R)
%62 = x^2+(a+1)*x+(a^2+2*a+2)
? trace(R)
%63 = 2*a+2
? norm(R)
%64 = a^2+2*a+2
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{nfsubfields}
\kbd{nfsubfieldsmax} return the maximal subfields,
\kbd{nfsubfieldscm} return the maximal CM subfields,
see Aurel talk.
\begin{verbatim}
? P = x^8+3*x^4+5;
? nfsubfields(P)
%66 = [[x,0],[x^2-3*x+5,-x^4],[x^4+3*x^2+5,-x^2],[x^8+3*x^4+5,x]]
? nfsubfieldsmax(P)
%67 = [[x^4+3*x^2+5,x^2]]
? nfsubfieldscm(P)
%68 = [x^2+11,2*x^4+3]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{nfdiscfactors}
\kbd{nfdiscfactors} returns the discriminant and its factorization.
\begin{verbatim}
? nfdiscfactors(x^3+3*x+7)
%69 = [-1431,[3,3;53,1]]
\end{verbatim}
\kbd{nfbasis} now can return the discriminant in an optional argument:
\begin{verbatim}
? nfbasis(x^3+3*x+7,&dK)
%70 = [1,x,x^2]
? dK
%71 = -1431
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{idealismaximal, idealdown}
\kbd{idealismaximal} checks whether an ideal is maximal and returns
the corresponding \kbd{prid}:
\begin{verbatim}
? a = 'a;
? nf = nfinit(a^3-2);
? idealismaximal(nf,7)
%74 = [7,[7,0,0]~,1,3,1]
? idealismaximal(nf,5)
%75 = 0
\end{verbatim}
\kbd{idealdown} returns a generator of the intersection of the ideal with
$\ZZ$.
\begin{verbatim}
? id2 = idealprimedec(nf,2)[1];
? id3 = idealprimedec(nf,3)[1];
? idealdown(nf, idealmul(nf, id2, id3))
%78 = 6
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{bnrclassfield}
\kbd{bnrclassfield} computes ray class fields without the limitation
of \kbd{rnfkummer}. See Aurel tutorial.
\begin{verbatim}
? bnf=bnfinit(a^2+41); bnf.cyc
%79 = [8]
? P=bnrclassfield(bnf,,1)
%80 = x^8-2*a*x^7-66*x^6+26*a*x^5+189*x^4-8*a*x^3+32*x^2+8*a*x+4
? rnfdisc(bnf,P)
%81 = [1,-1]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{bnfunits}
\kbd{bnfunits} allows to access the compact representation of units,
see Karim talk.
\begin{verbatim}
? bnf = bnfinit(x^2-nextprime(2^38), 1);
? sizebyte(bnf.fu)
%83 = 193216
? sizebyte(bnfunits(bnf))
%84 = 5672
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Faltings height}
\kbd{ellheight} can now be used to obtain the Faltings height of an
elliptic curve.
\begin{verbatim}
? ellheight(ellinit([1,3]))
%85 = -0.62991512865301812208879099375776471315
? ellheight(ellinit([1,a],nfinit(a^2+1)))
%86 = -0.82141261022274297551562408240979575893
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{lfun}
\kbd{lfun} now returns rational special values of quadratic character exactly:
\begin{verbatim}
? lfun(1,-7)
%87 = 1/240
? lfun(-4,-8)
%88 = 1385/2
? lfun(5,-9)
%89 = -825502/25
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{lfunshift}
If $f$ is a $L$-function, allow to create $s\mapsto f(s-d)$ and $s\mapsto
f(s)\*f(s-d)$.
\begin{verbatim}
? L = lfunshift(1,1); \\ zeta(s-1)
? lfun(L,1)
%91 = -0.50000000000000000000000000000000000000
? M = lfunshift(1,1,1); \\ zeta(s)*zeta(s-1)
? lfun(M,2)
%93 = 1.6449340668482264364724151666*x^-1+O(x^0)
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{lfuncreate}
\kbd{lfuncreate} can now handle data that depend on the precision.
\begin{verbatim}
? G=znstar(7,1); chi=[2]; \\ cubic char of cond 7
? V=[rootsof1(3)~,3];
? r=sqrtn((-13-sqrt(-27))/14,6); \\ root number
? an(V)=n->vector(n,i,chareval(G,chi,i,V));
? L=lfuncreate([an(V),1,[0],1,7,r]);
? lfuncheckfeq(L)
%99 = -126
? localbitprec(256); lfuncheckfeq(L)
%100 = -128
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{lfuncreate}
We create a closure that return the ldata structure with the current prrecision.
\begin{verbatim}
? F() =
{ 
  my(V=[rootsof1(3)~,3]);
  my(r=sqrtn((-13-sqrt(-27))/14,6));
  [an(V),1,[0],1,7,r];
}
? L = lfuncreate(F);
? lfuncheckfeq(L)
%103 = -126
? localbitprec(256); lfuncheckfeq(L)
%104 = -254
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Multiple characters in lfun}
\kbd{lfun} now allow to pass multiple characters if they have $L$-functions
with the same functional equation (different root numbers are allowed).
\begin{verbatim}
? G=znstar(17,1); C=[[1],[3],[5],[7]];
? lfun([G,C],1)
%106 = [1.60101836-0.392774395*I,0.990332401+0.0107451138*I,
%       0.336453687+0.304143387*I,1.02655704+0.711485755*I]
? lfunrootres([G,C])
%107 = [0,0,[0.825809120-0.563949729*I,0.988439629+0.151614974*I,
%       -0.974084005-0.226186541*I,-0.139252958+0.990256842*I]]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Multiple characters in lfun}
\begin{verbatim}
? default(timer,1);
? localprec(1000); lfun([G,C],1);
time = 4,188 ms.
? localprec(1000); [lfun([G,c],1)|c<-C];
time = 14,372 ms.
? default(timer,0);
\end{verbatim}
Multiple Hecke characters are also supported.
\begin{verbatim}
? bnf = bnfinit(x^2+47); bnr = bnrinit(bnf,1);
? lfun([bnr,[[1],[2]]],1)
%113 = [0.64666083128645259893546663,
%       0.450660220947390529728481755]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{mfisetaquo}
\kbd{mfisetaquo} try to write modular forms as eta quotients.
\begin{verbatim}
? find(a,b)=
  {
    forell(e,a,b,
      my(E=ellinit(e[1]));
      my(F=mffromell(E)[2]);
      my(Q=mfisetaquo(F));
      if(Q,print(e[1],":",Q)),1);
  }
? find(1,100)
% 11a1:[1,2;11,2]
% 14a1:[1,1;2,1;7,1;14,1]
% 15a1:[1,1;3,1;5,1;15,1]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Miscellaneous}
\begin{verbatim}
? print(strtime(12345678))
%3h, 25min, 45,678 ms
? derivn((x*(1-x))^4,4)
%117 = 1680*x^4-3360*x^3+2160*x^2-480*x+24
? arity((x,y)->x^2+y^2)
%118 = 2
? arity(sin)
%119 = 1
? L=List([1,2,3]);L[1..2]
%120 = List([1,2])
? L=List([1,2,3]);L[^1]
%121 = List([2,3])
? svg=parplothexport("svg",x=1,10,1/gamma(x));
\end{verbatim}
\end{frame}

\end{document}
