(** Author: Gilmar Rodriguez Pierluissi  **)

(** This Mathematica notebook was built with the purpose to clarifying the computations behind OEIS sequence A293858.  **)

(** EXAMPLE 1:  **)

n=2707118;

m=n/2

PrimeQ[m]

goldbachpair[n_?EvenQ]/;n>3:=Block[{m=PrimePi[n/2],p},While[!PrimeQ[n-(p=Prime[m])],m--];{p,n-p}]

gpair=goldbachpair[n]

p=gpair[[1]]

(** When we know p = 1351837 beforehand then we can use p to calculate:  **)

L1=PrimePi[m-1]-PrimePi[p+1]

(** But, when you don't know p beforehand then you use the following Mathematica program:  **)

Clear[p]

PreviousPrime[n_]:=NextPrime[n, -1]

L[n_?EvenQ]:=Module[{m=n/2},If[PrimeQ[m],l=0,l=Length[Drop[Most@NestWhileList[PreviousPrime,m,!PrimeQ[n-#]&],1]]];l]

L2=L[n]

(** These are the primes p that we are dealing with:  **)

pvalues=Drop[NestList[PreviousPrime,m,L2],1]

(** These are the n-p values that we are dealing with:  **)

nminusp=n-pvalues

(** Verify that the n-p values are not prime:  **)

PrimeQ[nminusp]

(** Now look at the following value:  **)

p=PreviousPrime[Last[pvalues]]

PrimeQ[p]

q=(n-p)

PrimeQ[q]

p+q==n

{p,q}==gpair

(******************************************************************************************************************************************************************)
(** EXAMPLE 2:  **)
(** Here we use the above L[n_?EvenQ] function to build the values {n,L} for 4 ≤ n ≤ 148 :  **)

nandLvalues=Table[{n,L[n]},{n,16,148,2}]

(** The set of successive maxima values of the above set nandLvalues can be obtained using the following rule:  **)

rule={x___,{a_,b_},{c_,d_},{e_,f_},y___}/;(d-b)/(c-a)<(f-b)/(e-a):>{x,{a,b},{e,f},y};

nandLvalues2=nandLvalues//.rule

(** The set of successive maxima values is abbreviated as follows:  **)

Table[nandLvalues2[[i]][[1]],{i,1,Length[nandLvalues2]}]

(******************************************************************************************************************************************************************)

(** The complete Mathematica code to generate the successive maxima for sequence A293858 is:  **)

PreviousPrime[n_]:=NextPrime[n, -1]

L[n_?EvenQ]:=Module[{m=n/2},If[PrimeQ[m],l=0,l=Length[Drop[Most@NestWhileList[PreviousPrime,m,!PrimeQ[n-#]&],1]]];l]

f[n_]:=For[m=n/2,True,m--,Return[L[n]]];For[n=16;max=-1,True,n+=2,If[f[n]>max,Print[n];max=f[n]]]