Oops - please use this line in goeis,  just below,
   echo ' results found',~ ": +/ok
in place of
   echo '3 results found'

Mike

On 06/03/2022 17:05, 'Michael Day' via Programming wrote:
OK - Ian wondered about automating a search in OEIS.
With a little inspection of the "page source" I've come up with this script;  it seems to work!

Although lots of OEIS lists are potentially mentioned if a series is matched,  many are cross-references
rather than the lower number of series that actually match.

My research has hardly been far-reaching,  so there may well turn out to be exceptions to this rule,  but
so far it appears that the pattern
   '<a href="/Axxxxxx/list">'
works for the headwords,  as a dictionary might describe these references.

=============================================================
load   '~addons/web/gethttp/gethttp.ijs'

goeis =: getoeisseries =: {{

 commas =. {{   NB. form a comma-separated list suitable for an OEIS search
 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
}}

NB. commas 10?10

NB. 6,1,9,0,8,2,4,7,3,5,


 OEIS =. 'http://oeis.org/search?q='
NB. read RAW; the result of searching in OEIS for commas y
NB. Using global RAW for later inspection by user
 RAW  =: gethttp OEIS,commas y
NB. find all occurrences of '<a href="/A,d' for digit characters  0-9
 ix   =. 0 -.~ , {{ y&{{  x I.@:E.~ '<a href="/A',y }} "0 '0123456789' }} RAW
NB.  looking for subset matching "/Axxxxxx/list">
 ix =. ix +/ 7 + 10 + i.7
if. +/ ok =. '/list">' -:"1 ix {"1 RAW do.
   echo '3 results found'
   RAW {~ _7 + ok#ix
else.
   echo 'Sorry, but the terms do not match anything in the table.'
   RAW =: ''
end.
}}

NB.    goeis 5 9 15 23 33 45 59
NB. 3 results found
NB. A027688
NB. A118403
NB. A134586

NB.    goeis 5 9 15 23 33 45 59 27
NB. Sorry, but the terms do not match anything in the table.
===============================================================================

IF the series is found,  you can go on to examine - even parse?! - the global "RAW" - though I expect it's just as useful to go to the browser.  I don't use JHS enough to know
how to integrate this approach in that enviornment.

Mike

On 06/03/2022 14:06, 'Michael Day' via Programming wrote:
I don't yet see how to separate the series itself/themselves from cross-refs!
M

On 06/03/2022 12:18, 'Michael Day' via Programming wrote:
Late to the power party!

This is one way to automate the OEIS look-up - I'm not an expert on parsing the result,  but hunting for 'A', a single digit seems
a good starter:

   OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

   getoeisseries =:{{ {{(-.{.) ' ',,/ y&{{~.x{~(i.7)+/~ x I.@:E.~ 'A',y}}"0 '0123456789' }} RAW=:gethttp OEIS,commas y}}

   getoeisseries 5 9 15 23 33 45 59
A027688
A002522
A007954
A176271
A118403
A118401
A118400
A118407
A118402
A134586

where commas is what I always use to format series for OEIS searches:

commas =: 3 : 0   NB. crude - I forget how to format negatives using - with some ": variant!!!
 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
)

Not a primitive adverb,  but it's my starter for 10,

Mike

On 06/03/2022 06:36, Ian Clark wrote:
Let's cheat and look it up in oeis.org …
Skip's sequence is A027688, dropping the first term
A027688 is defined as: (n^2 + n + 3)
but (n*n + n + 3) gives better results with (13 :)

q=: 13 : '(y*y) + y + 3'

q

*~ + 3 + ]

q >:i.10

5 9 15 23 33 45 59 75 93 113


Has anyone tried automating OEIS lookup? It could be the basis for a nifty
new primitive adverb: (...) as in:

5 9 15 23 33 ...

[NB NB NB snipped earlier posts!  MD]



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to