Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Revision History for A002845

(Bold, blue-underlined text is an addition; faded, red-underlined text is a deletion.)

Showing entries 1-10 | older changes
Number of distinct values taken by 2^2^...^2 (with n 2's and parentheses inserted in all possible ways).
(history; published version)
#87 by M. F. Hasler at Sun Apr 28 21:55:39 EDT 2024
STATUS

editing

approved

#86 by M. F. Hasler at Sun Apr 28 21:55:34 EDT 2024
PROG

(PARI) /* Define operators for numbers represented (recursively) as list of positions of bits 1, as illustrated by . Illustration using the next 2 commands, e.g. below: T = 3.bits; T.int */

A2845 = List([[2.bits]]) /* list List of values for each n */

{A002845(n)= while(#A2845<n, my(S=[], n=#A2845); for(k=1, n, foreach(A2845[n-k+1], b, S=setunion(S, Set([POW(a, b)| a<-A2845[k]])))); listput(A2845, S)); #A2845[n]}

STATUS

approved

editing

#85 by M. F. Hasler at Sun Apr 28 21:51:35 EDT 2024
STATUS

editing

approved

#84 by M. F. Hasler at Sun Apr 28 21:51:31 EDT 2024
PROG

{SUB(m, n, a=#n)= if(!a, m; , my(b=a=1, c, i); while(a<=#m && b<=#n, if(0>c=CMP(m[a], n[b]), a++, c, i=[c=n[b]]; b++; while(m[a]!=c=ADD(c, ONE), if(b<=#n && c==n[b], b++, i=concat(i, [c]))); m=concat([m[1..a-1], i, m[a+1..#m]]); a += #i, m=m[^a]; b++)); m)}

STATUS

approved

editing

#83 by M. F. Hasler at Sun Apr 28 21:46:06 EDT 2024
STATUS

editing

approved

#82 by M. F. Hasler at Sun Apr 28 21:41:24 EDT 2024
PROG

{POW(m, n)= if(#m==1, [MUL(m[1], n)], my(p=ONE); until(!#n || !#m=MUL(m, m), #n[1] || p=MUL(p, m); n=RSHIFT(n)); p)} /* \\ binary exponentiation unless only 1 bit set */

{RSHIFT(m, n=ONE)= if(!#m|| !#n|| !(#m[1]|| #m=m[^1]), m, my(go); [SUB(b, n)| b<-m, go||(CMP(b, n)>=0 && go=1)])}

{ADD(m, n, a=#m, b=#n)= if(!a, n, !b, m, a>b && [m, n]=[n, m]; a=b=1; until( a>#m || b>#n, if(m[a]==n[b], until(a>=#m|| m[a]!=m[a+1]|| !#m=m[^a], m[a]=ADD(m[a], ONE)); b++, CMP(m[a], n[b]) < 0, a++, m=concat([m[1..a-1], [n[b]], m[a..#m]]); b++)); b>#n|| m=concat(m, n[b..#n]); m)}

{SUB(m, n, a=#n)= if(!a, m; my(b=a=1, c, insi); while(a<=#m && b<=#n, if(0>c=cmpCMP(m[a], n[b]), a++, c, insi=[c=n[b]]; b++; while(m[a]!=c=ADD(c, ONE), if(c==n[b], b++, insi=concat(ins, i, [c]))); m=concat([m[1..a-1], ins, i, m[a+1 .. #m]]); a += #ins, i, m=m[^a]; b++)); m)}

A2845=List([[2.bits]] ) /* list of values for each n */

{A002845(n)=while(#A2845<n, my(S=[], n=#A2845); for(k=1, n, foreach(A2845[n-k+1], b, S= setunion(S, Set([POW(a, b)| a<-A2845[k]])))); A2845=concatlistput(A2845, [S])); #A2845[n]}

STATUS

approved

editing

Discussion
Sun Apr 28
21:46
M. F. Hasler: minor simplifications
#81 by N. J. A. Sloane at Sun Apr 28 11:29:46 EDT 2024
STATUS

proposed

approved

#80 by M. F. Hasler at Sun Apr 28 11:02:57 EDT 2024
STATUS

editing

proposed

Discussion
Sun Apr 28
11:21
Stefano Spezia: Yes. It is better in a separate file
#79 by M. F. Hasler at Sun Apr 28 11:02:47 EDT 2024
PROG

n.bits = vector(hammingweight(n), v, n -= 1 << v= valuation(n, 2); v.bits)

ONE = 1.bits; m.int = sum(i=1, #m, 1<<m[i].int) /* Convert back. (Not needed.) */

{MUL(m, n)= my(S=[]); #n && foreach(m, b, S=ADD(S, LSHIFT[ADD(n, c, b)| c<-n])); S}

{LSHIFTADD(m, n, a=#m, b=ONE#n)= if(!a, n, !b, m, a>b && [m, n]=[n, m]; a=b=1; until( a>#m || b>#n, if(m[a]==n[b], until(a>=#m|| m[a]!=m[a+1]|| !#m=m[^a], m, [a]=ADD(m[a], ONE)); b, ++, CMP(m[a], n)| [b]) < 0, a++, m=concat([m[1..a-1], [n[b]], m[a..#m]]); b++)); b>#n|| m=concat(m, n[b..#n]); m)}

{CMP(m, n, a=#m, b=#n, c=0)= if(!b, a, !a, -1, while(!(c=CMP(m[a], n[b]))&& a--&& b--, ); if(c, c, 1-b))}

{ADDSUB(m, n, a=#n)= if(!#m, n, !#n, m, #m>#n && [m, n]=[n, a, m]; my(a=1, b=a=1, c, ins); untilwhile( a><=#m || && b><=#n, if(0>c=cmp(m[a]==, n[b], until(), a>++, c, ins=#m|| m[a]!c=mn[a+1b]|| !#m=m[^a], ; b++; while(m[a]!=c=ADD(m[a], c, ONE)); b++, CMP, if(m[a], c==n[b]) < 0, a, b++, ins=concat(ins, [c]))); m=concat([m[1..a-1], [n[b]], ins, m[a+1 .. #m]]); b+a +)); b>= #n|| ins, m=concat(m, n[^a]; b..#n]++)); m)}

{CMP(m, n)= if(!#m, -!!#n, !#n, 1, my(a=#m, b=#n, c); while(!(c = CMP(m[a], n[b])) && a-- && b--, ); if(c, c, 1-b))}

{SUB(m, n)= #n||return m; my(a=1, b=1, c); while( a<=#m && b<=#n, if( !c=cmp(m[a], n[b]), m=m[^a]; b++, c<0, a++, c=n[b]; b++; my(ins=[c]); while(m[a] != c=ADD(c, ONE), if(c==n[b], b++, ins=concat(ins, [c])))/*while*/; m=concat([m[1..a-1], ins, m[a+1 .. #m]]); a += #ins))/*end if !c, while a…*/; m}

STATUS

proposed

editing

#78 by M. F. Hasler at Sun Apr 28 02:09:04 EDT 2024
STATUS

editing

proposed

Discussion
Sun Apr 28
02:14
M. F. Hasler: If that's too long I can put the program in a separate file...