% a338699.tex, Kevin Ryde, May 2021
%
% LaTeX with PGF/Tikz for drawing.

\documentclass[a4paper]{article}
\pagestyle{empty}         % no page numbers

% \title and \author go into PDF by hyperref pdfusetitle,
% but not displayed as such.
\title{A338699 by Piecewise-Linear Above Cumulative Primes}
\author{Kevin Ryde}
\date{May 2021}

\usepackage[pdfusetitle,
            pdfsubject={OEIS A338699},
            pdfkeywords={OEIS, A338699, cumulative primes, piecewise linear},
            pdflang={en}, % RFC3066 ISO639 code
            pdfborderstyle={/W 0},  % no border on hyperlinks
           ]{hyperref}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}         % for ($(...)$) coordinate calculations
\usetikzlibrary{arrows.meta}  % for scaled arrows
\tikzset{>=latex,         % arrowhead type
         font=\small}     % same as text, not the display \normalfont

% % Uncomment this to see a box around page text width and height.
% \usepackage{fancybox}
% \fancypage{\setlength{\fboxsep}{0pt}\fbox}{}


%------------------------------------------------------------------------------
\begin{document}
\noindent
\hfil {\large A338699 by Piecewise-Linear Above Cumulative Primes}
\hfil

\smallskip

\noindent
\hfil Kevin Ryde, May 2021
\hfil

\bigskip

Sequence \href{http://oeis.org/A338699}{A338699}
 \hskip.06em plus .06em minus .06em
can be thought of as fitting a piece-wise linear curve above the
cumulative primes (\href{http://oeis.org/A007504}{A007504}).  The
slope of each piece is a power $2^k$ and the next steeper piece begins
where necessary to stay at or above the cumulative primes.  Sequence
values are the distance up from the cumulative primes to this curve.

\vspace{.5ex}

\begin{center}
\begin{tikzpicture}[xscale=.4,yscale=.127,
                    my dot/.style={fill,circle,inner sep=.08em,node contents=},
                   ]
  % Y coordinates are given scaled by 1/10 so as not to overflow a TeX
  % dimension on input.  For example cumulative primes final point
  % A007504(24) = 963 is coordinates (24, 96.3).

  \draw[black!50,densely dotted] (15, 28) --(15, 42);
  \draw[|->|] (13.5, 32.8) -- (13.5, 37.0)
    node[midway,left=.5em] {$a(15) = 42$};

  % BEGIN GENERATED
  % cumulative primes:
  \draw (1,.2)--(2,.5)--(3,1.0)--(4,1.7)--(5,2.8)--(6,4.1)--(7,5.8)--(8,7.7)
    --(9,10.0)--(10,12.9)--(11,16.0)--(12,19.7)--(13,23.8)--(14,28.1)
    --(15,32.8)--(16,38.1)--(17,44.0)--(18,50.1)--(19,56.8)--(20,63.9)
    --(21,71.2)--(22,79.1)--(23,87.4)--(24,96.3);
  % piecewise above:
  \draw (1,.2)--(3,1.0)--(4,1.8)--(8,8.2)--(13,24.2)--(23,88.2)--(24,101.0);
  \path foreach \p in {(2,.5),(5,2.8),(6,4.1),(7,5.8),(9,10.0),(10,12.9),
    (11,16.0),(12,19.7),(14,28.1),(15,32.8),(16,38.1),(17,44.0),(18,50.1),
    (19,56.8),(20,63.9),(21,71.2),(22,79.1),(24,96.3),(15,37.0)}
    { \p node[my dot] };
  \newcommand\MyNmax{24}
  \newcommand\MyYmax{101.0}
  \newcommand\MyYmaxTens{100} % multiple of 10
  % END GENERATED

  % axes
  \draw[<->] (0,\MyYmax+3) -- (0,0) -- (\MyNmax+1, 0)
    node[at end,right] {$n$};
  \coordinate (n-tick) at (0, -5ex);
  \coordinate (y-tick) at (-1.5ex, 0);
  \foreach \n in {1,...,\MyNmax} {
    \draw (\n,0)-- ++(n-tick);
  }
  \foreach \n in {1,5,10,15,20,24} {
    \path (\n,0) ++(n-tick) node[below] {$\n$};
  }
  \foreach \y in {10,20,...,\MyYmaxTens} {
    \draw (0,\y)-- ++(y-tick) node[at end,left] {$\y 0$};
  }

  % closest approaches n=8,13,23, local minima in A338699
  \begin{scope}[>/.tip={Latex[scale width=.7]}]
    \draw[->,dotted] (9.5, 4.2) .. controls +(180:.5) and +(-75:2)
      .. ($(8, 7.7) + (-60:.6)$)
      node[at start,right] {$n {=} 8$};

    \draw[->,dotted] (14.6, 20) .. controls +(180:.5) and +(-70:1.5)
      .. ($(13, 23.8) + (-70:.9)$)
      node[at start,right] {$n {=} 13$};

    \draw[->,dotted] (20.8, 88.8) ..controls +(0:.5) and +(150:1)
      .. ($(23, 88.2) + (170:.5)$)
      node[at start,left] {$n {=} 23$};
  \end{scope}

  \node at (18, 60) [above left,align=center]
    {piece-wise linear \\[.1ex]
     slopes $2^k$ \\[.4ex]
     above};

  \node at (19, 50) [below right,align=center]
    {cumulative \\
     primes \\[.4ex]
     below};

\end{tikzpicture}
\end{center}

Dots are shown at each $n$ in the cumulative primes, except the
closest approaches.  The primes grow fairly steadily which makes it
otherwise hard to see the cumulative primes are in segments rather
than something smooth.

At the example
 $\thickmuskip=\medmuskip % around "=" operator
  a(15) = 42$,
the cumulative primes are
 $\text{\href{http://oeis.org/A007504}{A007504}}(15)       \linebreak[0]
  =                                                        \linebreak[0]
  328$
and the piece-wise curve is at
 $\thickmuskip=\thinmuskip % around "=" operator
  y = 370$,
for sequence
 $a(15) =                                                  \linebreak[0]
          370 - 328                                        \linebreak[0]
        =                                                  \linebreak[0]
          42$.
% 370-328==42

\vspace{.1ex}

Points
 $\thickmuskip=\medmuskip % around "=" operator
  n = 8, 13, 23$
are some of the places the piece-wise curve becomes steeper so as not
to be overtaken by the cumulative primes.  The primes are increasing
so they eventually exceed any straight line.

%------------------------------------------------------------------------------
\end{document}
