primeq=:1=#@q:
primeq 101
1
pcat=:,&.":
2 pcat 3
23
ifp=:{{if. primeq t=.y pcat x do. t else. y end.}}
~.] F:. ifp p: i. 15
23 2311 231131 23113147
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
NB. use built-in prime test
primeq=:1&p:
NB. to use extended integers
pcat=:".@(,&'x')@(,&":)
NB. to make ifp tacit
ifp=:{.`{:@.(primeq@{:)@:(],pcat~)
NB. to get the starting 2 and match oeis
]t=:~.''] F:. ifp p: i. 200x
2 23 2311 231131 23113147 23113147229 23113147229251 23113147229251577 23113147229251577857 23113147229251577857859 23113147229251577857859911 231131472292515778578599111123 2311314722925157785785991111231223
#t
13
NB. get a couple more
#t2=:~.''] F:. ifp p: i. 250x
15
Sorry to Richard - I meant to send to Forum, not to him only!
Message follows...
Cliff's construction returns the sequence with repeats, before
applying ~. as in:
''] F:. ifp p: i. 10x
2 23 23 23 2311 2311 2311 2311 2311 2311
I
hoped to avoid this repetition, and also to avoid lots of long
concatenated primes,
but
with limited success. Cliff's function returns the first 40 to 50
elements in about
half
the time of my approach. But it's still quite nifty, and not too
hungry for space,
so I present it here anyway. Basically, I reproduce A080155 rather than A240563,
ie
the list of added primes rather than their successive
concatenations.
NB. functions could be more one-line-ish, but I was trying to time them with JPM.
nextp =: 4 p: ] NB. next prime!
cat =: ".@(,&'x')@(,&":) NB. cribbed
from Cliff
NB. given a term in the sequence and the current last prime
NB. return the term with the next candidate
prime OR
NB. the term with 1 less than the next required
prime
NB. which is repeated on the next application,
thus closing
NB. the application using the power operator,
^:_
NB. eg
NB. fnsub1 2311 11
NB.2311 13
NB. but
NB. fnsub1 2311 30
NB.2311 30 NB. so no change, so power operator
quits.
fnsub =: >:@{:@: (fnsub1^:_)
NB. eg
NB. fnsub 2311 11
NB. 31
fn =: {{ 2 fn y
:
list =. x NB. eg 2 3 11
rep =. 0 >. y - # list NB. number of required elements
whole =. cat/ list NB. eg 2311
for. i. rep do.
list =. list, newp =. fnsub whole, {: list
whole=. cat/whole, newp
NB. echo list;whole NB. debugging!
end.
list
}}
eg
fn 10 NB. reproduce elements of A080155
2 3 11 31 47 229 251 577 857 859
(, cat/) fn 10
2 3 11 31 47 229 251 577 857 859 23113147229251577857859
2 5 $ (cat/\) fn 10 NB. reproduce elements of A240563.
2 23 2311 231131 23113147
23113147229 23113147229251 23113147229251577 23113147229251577857 23113147229251577857859
NB.
shape not reproduced here!
The number of terms shown in the OEIS page for A080155 is around 44, using up ro
around
5000 primes:
ts'fn 44' NB. slower but leaner than Cliff's
1.0121 15136
ts'_10{.": {:]t=:~.''''] F:. ifp p: i. 5000x'
0.579638 1.4405e6
We
agree on the last new prime:
{:fn 44
48523
_5{.": {:]t=:~.''] F:. ifp p: i. 5000x
48523
Greathouse's Pari GP function, listed in the OEIS page for the concatenated list, A240563,
takes about 13 seconds on my laptop, running the Windows version, for 44 terms, so we're
doing ok compared with a numerical function expert! However, he doesn't offer a function
for
A080155, which only lists the added primes, not their
concatenations. That might be a bit
quicker
in Pari GP. (I don't have Mathematica or Maple.)
Cheers,
Mike
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
On 9 Jun 2025, at 18:26, Richard Donovan <rsdo...@hotmail.com> wrote:
mu =: 3 : 0
max =. y
mu =. 0, max#1
i =. 1
rtmax =. <.%: max
while. rtmax >: i =. 4 p: i do.
j =. i * >: i.max <.@% i
muj =. - i * j{mu
mu =. muj j } mu
j =. i2 * >: i.max <.@% i2 =. *:i
mu =. 0 j } mu
end.
ix =. i.max+1
newmu =. (mu=ix) - (mu = -ix)
newmu =. newmu - (*mu) * 0= newmu
1 (0) }newmu
)
NB - This function sets mu for 0 to be 1 - debatable!
Thanks,
Mike
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.