[seqfan] Re: Common terms in An and Am

Olivier Gerard olivier.gerard at gmail.com
Thu Dec 7 14:56:55 CET 2023


Dear Zak,

Here is an equivalent of Robert's maple example in Mathematica
This is not production quality code, just oneliners to get the job done.
Use with caution and discretion.

(* utility code to evaluate before other instructions *)
OEISAnumbase[n_Integer]:=IntegerString[n,10,6]

ReadOEISBfile[n_Integer]:= ReadList["https://oeis.org/
"<>"A"<>OEISAnumbase[n]<>"/b"<>OEISAnumbase[n]<>".txt",{Number,Number}]

findInBfile[oeisb_List,k_Integer]:= Cases[oeisb,{_,k}]


(* Reading a few bfiles *)
b000110= ReadOEISBfile[110];
b000225= ReadOEISBfile[225];

(* display first values *)

Last/@Take[b000110,10]
{1,1,2,5,15,52,203,877,4140,21147}

Last/@Take[b000225,10]
{0,1,3,7,15,31,63,127,255,511}


(* find identical values at identical indices)

Intersection[b000110,b000225]
{{1,1},{4,15}}


(* read other bfiles *)
b002821=ReadOEISBfile[2821];
b002843=ReadOEISBfile[2843];

(* extract list of values *)
v002821 = Last/@b002821;
v002843 = Last/@b002843;

(* find identical values between the two lists *)
Intersection[v002821,v002843]
{1,253}


(* display the indices of a value in a loaded bfile *)
findInBfile[b002821, 253]
{{40,253}}


findInBfile[b002843, 253]
{{10,253}}



Regards,

Olivier


On Thu, Dec 7, 2023 at 4:21 PM zak seidov via SeqFan <seqfan at list.seqfan.eu>
wrote:

>  Maple is great but I use Mathematica or Pari on elementary level, sorry
>     On Thursday, December 7, 2023 at 04:24:55 AM GMT+2, israel at math.ubc.ca
> <israel at math.ubc.ca> wrote:
>
>  Here is Maple code to find the terms common to two sequences.
>
> OEISCommonTerms(num1, num2) finds the list of all pairs [i,t] such that
> Anum1[i] = Anum2[i] = t, where num1 and num2 are integers of up to 6
> digits. The b-files will be used if present, otherwise just the Data. An
> error will occur if these sequences are not in OEIS. Thus
>
> > OEISCommOnTerms(110, 225);
>
>     [[1,1],[4,15]]
>
> because A000110(1) = A000225(1) = 1 and A000110(4) = A000225(4) = 15 are
> the terms that occur at the same index in both A000110 and A000225.
>
>
> OEISIntersect(num1, num2) finds the set of all integers that occur
> at least once in both Anum1 and Anum2.  Thus
>
> > OEISIntersect(2821, 2843);
>
>       {1, 253}
>
> because A002821(1) = A002843(0) = A002843(1) = 1 and A002821(40) =
> A002843(10) = 253.
>
> getbfile:= proc(anumber)
>  local bfile,nstr,S,L,B,t,found;
>  nstr:= sprintf("%6d",10^7+anumber)[-6..-1];
>  bfile := StringTools:-Substitute(sprintf("https://oeis.org/A%s/b%s.txt",
>         nstr$2)," ","0");
>  S:= URL:-Get(bfile);
>  fclose(bfile);
>  if StringTools:-Search("Sorry, the page you requested was not found.",S)
> <> 0 then error "No sequence %1", nstr fi;
>  S:= StringTools:-Split(S,"\n");
>  found:= false;
>  for t in S do
>   L := sscanf(t,"%d %d");
>   if nops(L) = 2 then
>   B[L[1]]:= L[2]; found:= true;
>   fi
>  od;
>  if not found then error "No data" fi;
>  eval(B)
> end proc:
> OEISCommonTerms:= proc(num1,num2)
>   local R, A1, A2, I1, I2, i;
>   A1:= getbfile(num1);
>   A2:= getbfile(num2);
>   I1:= [indices(A1)];
>   I2:= [indices(A2)];
>   R:= NULL;
>   for i from max(min(I1),min(I2)) to min(max(I1),max(I2)) do
>     if A1[i] = A2[i] then R:= R, [i,A1[i]] fi
>   od;
>   [R]
> end proc:
> OEISIntersect:= proc(anum1, anum2)
>   local S1, S2;
>   S1:= convert(getbfile(anum1),set);
>   S2:= convert(getbfile(anum2),set);
>   S1 intersect S2;
> end proc:
>
> Cheers,
> Robert
>
>
>
> On Dec 6 2023, Neil Sloane wrote:
>
> >why not download the two b-files and use Maple or whatever to find their
> >intersection
> >
> >a few lines of Unix shell commands will do it automatically
> >
> >Best regards
> >Neil
> >
> >Neil J. A. Sloane, Chairman, OEIS Foundation.
> >Also Visiting Scientist, Math. Dept., Rutgers University,
> >Email: njasloane at gmail.com
> >
> >
> >
> > On Wed, Dec 6, 2023 at 9:32AM zak seidov via SeqFan
> > <seqfan at list.seqfan.eu> wrote:
> >
> >> Dear all,Is it any possibility to find common terms in any two OEIS
> >> sequences, e.g., from their bfiles?Thanks a lot,Zak
> >>
> >> --
> >> Seqfan Mailing list - http://list.seqfan.eu/
> >>
> >
> >--
> >Seqfan Mailing list - http://list.seqfan.eu/
> >
> >
>
> --
> Seqfan Mailing list - http://list.seqfan.eu/
>
>
> --
> Seqfan Mailing list - http://list.seqfan.eu/
>


More information about the SeqFan mailing list