;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; http://www.iki.fi/~kartturi/matikka/Schemuli/intfuns1.scm ;; ;; - Often needed integer functions. ;; ;; ;; ;; Coded by Antti Karttunen (my_firstname.my_surname@gmail.com), ;; ;; 2002-2009 ;; ;; ;; ;; This Scheme-code is in Public Domain and runs (at least) ;; ;; in MIT Scheme Release 7.6.0/7.7.?, for which one can find documents ;; ;; and the pre-compiled binaries (for various OS's running in ;; ;; Intel x86 architecture) under the URL: ;; ;; http://www.swiss.ai.mit.edu/projects/scheme/ ;; ;; ;; ;; Last edited Oct 20 2009 by Antti Karttunen. ;; ;; ;; ;; Oct 02 2009: Changed macros MATCHING-POS, NONZERO-POS, ZERO-POS, ;; ;; DISTINCT-POS, DISTINCT-VALS, RECORD-POS, RECORDS-VALS, PARTIALSUMS ;; ;; to use TWO separate starting offsets, the other for the function to ;; ;; be defined, and the other for the function whose values are ;; ;; searched/summed for. ;; ;; ;; ;; Oct 05 2009: Changed macros LEAST-EXCEEDING-I, PSEUDOINVERSE1, ;; ;; PSEUDOINVERSE2 in similar way, to use soff1 and soff2. ;; ;; ;; ;; Refactored implement-cached-function macro out of definec, ;; ;; and used it to implement memoizing functionals ;; ;; MATCHING-POS, NONZERO-POS, ;; ;; DISTINCT-POS, DISTINCT-VALS, RECORD-POS, RECORDS-VALS, ;; ;; NUMBER-OF-CHANGES, LEAST-EXCEEDING-I, PSEUDOINVERSE1 ;; ;; PSEUDOINVERSE2 and COMPLEMENT. ;; ;; These are still first-cut, to be polished. Need better names for some.;; ;; ;; ;; Added Jan 08 2007 a few sieving functions and eigen-convolutions. ;; ;; (Operators: EIGEN-CONVOLUTION, GEN-CONVOLVE, CONVOLVE, INVERT). ;; ;; ;; ;; grep -c "^(define[c]* [(]*A[0-9][0-9][0-9][0-9][0-9][0-9] " --> 226 ;; ;; ;; ;; To do: ;; ;; ;; ;; Implement most of the transformations in ;; ;; http://www.research.att.com/~njas/sequences/transforms.txt ;; ;; ;; ;; Implement all OEIS-sequences (functions) related to the ;; ;; binary fiddling. ;; ;; All http://www.research.att.com/~njas/sequences/Sindx_Bi.html#binary ;; ;; and much more: ;; ;; A000120, A000788, A000069, A001969, A023416, A059015, A007088, A070939 ;; ;; A005536, A003159, A006995, A006364, A054868, A070940, A070941, A001511 ;; ;; A029837, A037800, A014081, A014082 ;; ;; ;; ;; Also all 156 or so "core" sequences, at least those that can be ;; ;; easily computed. (Cf. A000001), the most cross-referenced, ;; ;; etc. (Huh huh!) ;; ;; ;; ;; But first think about the appropriate presentation, with which we ;; ;; can keep more information than with just basic define and definec. ;; ;; ;; ;; E.g. the starting offset, the validity range, if the sequence ;; ;; is finite (cf. A007623), alternative versions and compositions ;; ;; (E.g. we have a _DEFINING_ definition (might be very SLOW), ;; ;; then _IMPLEMENTING_ definition (should be faster) ;; ;; and various alternative compositions and other definitions, ;; ;; that can be used for checking.) ;; ;; Also, what subset of Scheme is allowed, and what kind of operators ;; ;; (PARTIALSUMS, COMPLEMENT, INVERT, etc.) are allowed, ;; ;; so that definitions can be automatically converted to say, Python? ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Compile as: ;; ;; (cf "../Schemuli/definech" "../Schemuli/") ;; ;; (load "../Schemuli/definech") ;; ;Loading "matikka\\schemuli\\definech.com" -- done ;; ;Value: definec ;; ;; (fluid-let ((sf/default-syntax-table user-initial-environment)) ;; (cf "../Schemuli/intfuns1" "../Schemuli/") ;; ) ;; ;; From http://www.swiss.ai.mit.edu/projects/scheme/documentation/user_5.html ;; ;; If you redefine some global name in your code, for example, car, cdr ;; and cons, you should indicate it in the declaration as: ;; (declare (usual-integrations car cdr cons)) ;; (Beware of using an argument name like list in the function definitions?) (declare (usual-integrations)) (load-option 'format) ;; define unary cached functions. Syntax is like ;; (define (func arg) ...) of Scheme. ;; Note that this and other cached functions depend on MIT Scheme ;; peculiarities, like that vectors are initialized to contain #f's ;; and also that #f is actually same thing as (). To be corrected. ;; We could do much more sophisticated things with the cache. ;; E.g. after n > certain size, switch to the dictionary (hash table) based ;; caching. Or give a programmer much more control over the caching ;; parameters, or build an IDE-system where the user can monitor the caching state ;; (e.g. find cache hogs) and toggle the caching parameters on the fly, ;; and ultimately, initialize the cache (e.g. for the sequences like A000001 ;; and A000668) from the central database (OEIS) ;; with variety of methods (RPC, etc.). (Might even send new computed ;; values back there (but how to check/trust them?) For the future thought!) ;; ;; Added this 10. July 2002 to avoid allocation catastrophes ;; caused by the careless use of the cached integer functions: (define *MAX-CACHE-SIZE-FOR-DEFINEC* 131072) ;; 524292) ;; Was: 290512) ;; Was 131072 (define-syntax grow-cache (syntax-rules () ((grow-cache cachename arg) ;; No maxsize specified. (vector-grow cachename (max (1+ arg) (* 2 (vector-length cachename)))) ) ((grow-cache cachename arg 0) ;; Or specified as zero. (vector-grow cachename (max (1+ arg) (* 2 (vector-length cachename)))) ) ((grow-cache cachename arg maxsize) (vector-grow cachename (min maxsize (max (1+ arg) (* 2 (vector-length cachename))))) ) ) ) (define-syntax implement-cached-function (syntax-rules () ((implement-cached-function maxcachesize (funname argname) e0 ...) (letrec ((_cache_ (vector #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f)) (funname (lambda (argname) (cond ((null? argname) _cache_) ;; For debugging. ((vector? argname) argname) ;; As well as this: Caches for caches! ((and (not (= 0 maxcachesize)) (>= argname maxcachesize)) e0 ... ) (else (if (>= argname (vector-length _cache_)) (set! _cache_ (grow-cache _cache_ argname maxcachesize)) ) (or (vector-ref _cache_ argname) ((lambda (res) (vector-set! _cache_ argname res) res ) (begin e0 ...) ) ) ) ) ; cond ) ) ) ; letrec-definitions funname ) ; letrec ) ) ) (define-syntax definec (syntax-rules () ((definec (name arg) e0 ...) (define name (implement-cached-function *MAX-CACHE-SIZE-FOR-DEFINEC* (name arg) e0 ...) ) ;; (define name ...) ) ) ;; syntax-rules ) ;; This is for defining one-based permutations. ;; Stores automatically also the inverse permutation (in _invcache_), ;; which can be accessed with negative arguments. ;; Note that the defined function is subtly state-dependent. The defined permutation must be ;; computed before its inverse! ;; Yes, this is dirty and dangerous. ;; In general this shouldn't be used, only in emergency cases, ;; when I'm in hurry (or just lazy). (define-syntax defineperm1 (syntax-rules () ((defineperm1 (name arg) e0 ...) (define name (letrec ((_cache_ (vector #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f)) (_invcache_ (vector #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f)) ;; For inverses. (name (lambda (arg) (cond ((null? arg) _cache_) ((eq? #t arg) _invcache_) ((< arg 0) ;; (foo -n) means (foo^-1 n) (cond ((>= (- arg) (vector-length _invcache_)) #t) (else (vector-ref _invcache_ (- arg))) ) ) ((>= arg *MAX-CACHE-SIZE-FOR-DEFINEC*) e0 ... ) (else (if (and (>= arg (vector-length _cache_)) (< arg *MAX-CACHE-SIZE-FOR-DEFINEC*) ) (set! _cache_ (grow-cache _cache_ arg *MAX-CACHE-SIZE-FOR-DEFINEC*)) ) (or (vector-ref _cache_ arg) ((lambda (res) (let ((invcachesize (vector-length _invcache_))) (if (< arg *MAX-CACHE-SIZE-FOR-DEFINEC*) (vector-set! _cache_ arg res) ) ;; Handle the inverse cache. First ensure that there's enough space: (cond ((and (< res *MAX-CACHE-SIZE-FOR-DEFINEC*) (or (>= res invcachesize) (>= arg invcachesize)) ) (set! _invcache_ (vector-grow _invcache_ ;; (min *MAX-CACHE-SIZE-FOR-DEFINEC* (max (1+ res) (1+ (vector-length _cache_)) (* 2 (vector-length _invcache_)) ) ;; ) ) ) (format #t "Inverse cache size: ~a -> ~a.\n" invcachesize (vector-length _invcache_) ) ) ;; If this result was already stored in invcache, then check that it was not cached for different arg: ((and (< res *MAX-CACHE-SIZE-FOR-DEFINEC*) (vector-ref _invcache_ res) ) => (lambda (old_n) (if (not (= old_n arg)) (error (format #f "The defined function is not injective, so it cannot be a bijection: f(~a)=f(~a)=~a.\n" old_n arg res) ) ) ) ) ) (if (< res *MAX-CACHE-SIZE-FOR-DEFINEC*) (vector-set! _invcache_ res arg) ) res ) ) ;; (lambda (res) ...) (begin e0 ...) ) ) ) ) ; cond ) ) ) ; letrec-definitions name ) ; letrec ) ;; (define name ...) ) ) ;; syntax-rules ) (define (ROWSUMS0 antidiagfun) (lambda (n) (add antidiagfun (A000217 n) (-1+ (A000217 (1+ n)))))) (define (ROWSUMS1 antidiagfun) (lambda (n) (add antidiagfun (A000124 (-1+ n)) (A000217 n)))) ;; soff1 = starting offset for this function to be defined. ;; soff2 = starting offset for function fun, i.e. its domain: [soff2,infinity] ;; With argument n, the defined function sums the first (n-soff1)+1 values ;; of function 'fun' in domain [soff2,soff2+1,soff2+2,...,soff2+(n-soff1)] (define (PARTIALSUMS soff1 soff2 fun) ;; soff = starting offset. (implement-cached-function 0 (partsumsfun n) (let ((coff (- soff2 soff1))) ;; Correction offset. (cond ((< n soff1) 0) ((= n soff1) (fun soff2)) (else (+ (fun (+ n coff)) (partsumsfun (-1+ n)))) ) ) ) ) ;; Original version: ;; (define (PARTIALSUMS soff fun) ;; soff = starting offset. ;; (implement-cached-function 0 (partsumsfun n) ;; (cond ((< n soff) 0) ;; ((= n soff) (fun n)) ;; (else (+ (fun n) (partsumsfun (-1+ n)))) ;; ) ;; ) ;; ) ;; soff1 = starting offset for this function to be defined. ;; soff2 = starting offset for pred_on_i? function, (define (MATCHING-POS soff1 soff2 pred_on_i?) (implement-cached-function 0 (tvimadur n) (let loop ((i (if (= soff1 n) soff2 (1+ (tvimadur (-1+ n)))))) (cond ((pred_on_i? i) i) (else (loop (1+ i))) ) ) ) ) ;; Original version: ;; (define (MATCHING-POS soff pred_on_i?) ;; soff = starting offset. ;; (implement-cached-function 0 (tvimadur n) ;; (let loop ((i (if (= soff n) soff (1+ (tvimadur (-1+ n)))))) ;; (cond ((pred_on_i? i) i) ;; (else (loop (1+ i))) ;; ) ;; ) ;; ) ;; ) (define (NEXT-MATCHING-POS pred_on_i?) (implement-cached-function 0 (tvimadur n) (let loop ((i (1+ n))) (cond ((pred_on_i? i) i) (else (loop (1+ i))) ) ) ) ) (define (PREV-OR-SAME-MATCHING-POS pred_on_i?) (implement-cached-function 0 (tvimadur n) (let loop ((i n)) (cond ((zero? i) i) ;; Failed? ((pred_on_i? i) i) (else (loop (-1+ i))) ) ) ) ) ;; (define-syntax define-MATCHING-POS ;; (syntax-rules () ;; ((define-MATCHING-POS soff (fun_defined n) pred_on_i?) ;; (define fun_defined ;; (implement-cached-function 0 (fun_defined n) ;; (let loop ((i (if (= soff n) soff (1+ (fun_defined (-1+ n)))))) ;; (cond ((pred_on_i? i) i) ;; (else (loop (1+ i))) ;; ) ;; ) ;; ) ;; ) ;; (define fun_defined ...) ;; ) ;; ) ;; syntax-rules ;; ) ;; ;; (define-MATCHING-POS 0 (A125975 n) (lambda (i) (= i (A125974 (A125974 i))))) ;; (define (fun-succ-matching-is0 pred_on_i?) (MATCHING-POS 0 0 pred_on_i?)) ;; Give an "extended" characteristic function of foo for this, and you get foo: ;; E.g. (define A005117 (NONZERO-POS 1 1 A008683)) ;; soff1 = starting offset for this function to be defined. ;; soff2 = starting offset for charfun (characteristic function) (define (NONZERO-POS soff1 soff2 charfun) (MATCHING-POS soff1 soff2 (lambda (i) (not (zero? (charfun i)))))) (define (ZERO-POS soff1 soff2 fun) (MATCHING-POS soff1 soff2 (lambda (i) (zero? (fun i))))) (define (FIXED-POINTS soff1 soff2 fun) (MATCHING-POS soff1 soff2 (lambda (i) (= i (fun i))))) ;; soff1 = starting offset for this function to be defined. ;; soff2 = starting offset for fun_on_i (i.e. its domain is [soff2,infinity]) (define (DISTINCT-POS soff1 soff2 fun_on_i) (implement-cached-function 0 (belgthor n) (cond ((<= n soff1) soff2) ;; Was: ((<= n soff) n) (else (let outloop ((i (1+ (belgthor (-1+ n)))) (val_here (fun_on_i (1+ (belgthor (-1+ n))))) ) (let inloop ((j (-1+ n))) ;; ((j (-1+ i))) ;; If we didn't find any j < i where fun_on_i(belgthor(j)) would have been belgthor(i), then ... (cond ((< j 0) i) ;; ... we found a new distinct value, return its pos. ((= (fun_on_i (belgthor j)) val_here) ;; This value has occurred before. (outloop (+ i 1) (fun_on_i (+ i 1))) ;; Try the next candidate. ) (else (inloop (- j 1))) ) ) ) ) ) ) ) (define (DISTINCT-VALS soff1 soff2 fun_on_i) (compose-funs fun_on_i (DISTINCT-POS soff1 soff2 fun_on_i))) ;; soff1 = starting offset for this function to be defined. ;; soff2 = starting offset for fun_on_i (i.e. its domain is [soff2,infinity]) (define (RECORD-POS soff1 soff2 fun_on_i) (implement-cached-function 0 (arlaug n) (cond ((<= n soff1) soff2) ;; Was: ((<= n soff) n) (else (let* ((prevrecpos (arlaug (- n 1))) (prev_record (fun_on_i prevrecpos)) ) (let loop ((i (+ 1 prevrecpos))) ;; Starting index. (cond ((> (fun_on_i i) prev_record) i) (else (loop (+ i 1))) ) ) ) ) ) ) ) (define (RECORD-VALS soff1 soff2 fun_on_i) (compose-funs fun_on_i (RECORD-POS soff1 soff2 fun_on_i))) ;; ;; (arlaug n): Find a point i between zeroposfun(n) and zeroposfun(n+1) with ;; a maximum absolute value of fun(i). ;; (define (RECORD-ABSVALS-BETWEEN-ZEROS-POS soff fun zeroposfun) ;; soff = starting offset. (implement-cached-function 0 (arlaug n) (let* ((nextzeropos (zeroposfun (1+ n)))) (let loop ((i (zeroposfun n)) ;; Starting index. (m 0) (mp (zeroposfun n)) ) (cond ((= i nextzeropos) mp) ((> (abs (fun i)) m) (loop (1+ i) (abs (fun i)) i) ) (else (loop (1+ i) m mp)) ) ) ) ) ) ;; This forms a function (cfun n), that gives the number of times the value of function foo ;; has changed from (foo i) to (foo i+1), for i=soff to n-1. ;; For genuinely monotone functions this is always A000027. (define (NUMBER-OF-CHANGES soff foo) ;; soff = starting offset. (implement-cached-function 0 (cfun n) (cond ((< n soff) 0) ;; Maybe we should raise an error instead?! ((= soff n) 1) ;; For the starting offset we return 1, as there is our first value. ((= (foo n) (foo (- n 1))) (cfun (- n 1))) ;; foo stays same, use the previous value. (else (1+ (cfun (- n 1)))) ;; Foo obtains a new value here, return one more than last time ) ) ) ;; (define (GEN_CONVOLVE soff mulfun fun1 fun2) ...) ;; (define (CONVOLVE soff fun1 fun2) ...) ;; (PARSUMS_OF_CHARFUN soff foo): ;; Returns the partial sums of the characteristic function of foo, which should be growing, ;; but not necessarily genuinely so. ;; In other words, how many distinct values function foo has obtained up to and including (foo n). ;; E.g. (define A000720 (PARSUMS_OF_CHARFUN 1 A000040)) ;; A072649 = (compose-funs -1+ (PARSUMS_OF_CHARFUN 0 A000045)) ;; With LEAST-I-WITH-FUN-I-EQ-N we don't assume that fun_on_i is monotone. ;; smallest i, such that (foo i) = n. ;; soff1 = starting offset for this function to be defined. (not used). ;; soff2 = starting offset for fun_on_i (i.e. its domain is [soff2,infinity]) (define (LEAST-I-WITH-FUN-I-EQ-N soff1 soff2 fun_on_i) ;; soff = starting offset. (implement-cached-function 0 (fun_defined n) (let loop ((i soff2)) (cond ((= (fun_on_i i) n) i) (else (loop (+ i 1))) ) ) ) ) ;; Note: With the following it is required that fun_on_i is monotone! ;; smallest i, such that (foo i) > n. ;; soff1 = starting offset for this function to be defined. ;; soff2 = starting offset for fun_on_i (i.e. its domain is [soff2,infinity]) (define (LEAST-EXCEEDING-I soff1 soff2 fun_on_i) ;; soff = starting offset. (implement-cached-function 0 (fun_defined n) (let loop ((i (if (= soff1 n) soff2 (fun_defined (- n 1))))) (cond ((> (fun_on_i i) n) i) (else (loop (+ i 1))) ) ) ) ) ;; smallest i, such that (foo i) >= n. ;; soff1 = starting offset for this function to be defined. ;; soff2 = starting offset for fun_on_i (i.e. its domain is [soff2,infinity]) (define (LEAST-GTE-I soff1 soff2 fun_on_i) ;; soff = starting offset. (implement-cached-function 0 (fun_defined n) (let loop ((i (if (= soff1 n) soff2 (fun_defined (- n 1))))) (cond ((>= (fun_on_i i) n) i) (else (loop (+ i 1))) ) ) ) ) ;; Was: ;; (define (LEAST-EXCEEDING-I soff fun_on_i) ;; soff = starting offset. ;; (implement-cached-function 0 (fun_defined n) ;; (let loop ((i (if (= soff n) n (fun_defined (- n 1))))) ;; (cond ((> (fun_on_i i) n) i) ;; (else (loop (+ i 1))) ;; ) ;; ) ;; ) ;; ) (define (first_pos_with_funs_val_gte fun n) (let loop ((i 0)) (if (>= (fun i) n) i (loop (1+ i)) ) ) ) (define (first-n-where-fun_n-is-i0 fun i) (let loop ((n 0)) (cond ((= i (fun n)) n) (else (loop (+ n 1))) ) ) ) (define (first-n-where-fun_n-is-i1 fun i) (let loop ((n 1)) (cond ((= i (fun n)) n) (else (loop (+ n 1))) ) ) ) ;; When for some i, (foo i) = n, return the smallest such i, ;; otherwise the largest i such that (foo i) < n. ;; soff1 = starting offset for this function to be defined. ;; soff2 = starting offset for fun_on_i (i.e. its domain is [soff2,infinity]) (define (PSEUDOINVERSE1 soff1 soff2 fun_on_i) ;; soff = starting offset. (implement-cached-function 0 (fun_defined n) (let loop ((i (if (= soff1 n) soff2 (fun_defined (- n 1))))) (cond ((= (fun_on_i i) n) i) ((> (fun_on_i i) n) (- i 1)) (else (loop (+ i 1))) ) ) ) ) ;; (define (PSEUDOINVERSE1 soff fun_on_i) ;; soff = starting offset. ;; (implement-cached-function 0 (fun_defined n) ;; (let loop ((i (if (= soff n) n (fun_defined (- n 1))))) ;; (cond ((= (fun_on_i i) n) i) ;; ((> (fun_on_i i) n) (- i 1)) ;; (else (loop (+ i 1))) ;; ) ;; ) ;; ) ;; ) ;; Returns the largest i, such that (foo i) <= n. ;; soff1 = starting offset for this function to be defined. ;; soff2 = starting offset for fun_on_i (i.e. its domain is [soff2,infinity]) (define (PSEUDOINVERSE2 soff1 soff2 fun_on_i) (compose-funs -1+ (LEAST-EXCEEDING-I soff1 soff2 fun_on_i))) ;; Not yet correct: ;; (define (PARSUMS_OF_CHARFUN soff foo) ;; soff = starting offset. ;; (implement-cached-function 0 (cfun n) ;; (cond ((< n soff) 0) ;; ((= soff n) (if (> (foo soff) soff) 0 1)) ;; (else ;; (let ((preval (cfun (- n 1)))) ;; (if (= (foo (+ 1 soff preval)) n) (+ 1 preval) preval) ;; ) ;; ) ;; ) ;; ) ;; ) ;; 0,1,2,3,4,5,6,7 , 8, ;; A000045 begins from zero as: 0,1,1,2,3,5,8,13,21,34,55,89,144,... ;; A001477: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,... ;; Characteristic function: 1,1,1,1,0,1,0,0,1,0 ,0, 0, 0, 1, 0, 0, 0 ;; Its partial sums: 1,2,3,4,4,5,5,5,6,6, 6, 6, 6, 7, 7, 7, 7 ;; "pseudo inverse 1": 0,1,3,4,4,5,5,5,6,6, 6, 6, 6, 7, 7, 7, 7 ;; "pseudo inverse 2": 0,2,3,4,4,5,5,5,6,6, 6, 6, 6, 7, 7, 7, 7 ;; A125975 begins from zero as: 0,1,2,3,5,7,10,11,12,13,15,21,31,38,39,42,43,44,... ;; A001477: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,... ;; Characteristic function: 1,1,1,1,0,1,0,1,0,0, 1, 1, 1, 1, 0, 1, 0, ;; Its partial sums: 1,2,3,4,4,5,5,6,6,6, 7, 8, 9,10,10,11,11, ;; "pseudo inverse": 0,1,2,3,3,4,4,5,5,5, 6, 7, 8, 9, 9,10,10,... ;; A000040 begins from one as: 2,3,5,7,11,13,17,19,23,29,31,,... ;; A000027: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,... ;; "pseudo inverse": (A000720) 0,1,2,2,3,3,4,4,4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, ;; A000523 begins from one as: 0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4 ;; Characteristic function: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,... (all-ones, A000012) ;; Its partial sums = A000027: 1,2,3,4,5,6,7,8,9,10,11,... ;; A000079 begins from zero as: 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,... ;; A001477: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,... ;; Characteristic function: 0,1,1,0,1,0,0,0,1,0, 0, 0, 0, 0, 0, 0, 1, 0,... ;; Its partial sums: 0,1,2,2,3,3,3,3,4,4, 4, 4, 4, 4, 4, 4, 5, 5, ... ;; A000079 begins from one as: 2,4,8,16,32,64,128,256,512,1024,2048,4096,... ;; A001477: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,... ;; Characteristic function: 0,1,0,1,0,0,0,1,0, 0, 0, 0, 0, 0, 0, 1, 0,... ;; Its partial sums: 0,1,1,2,2,2,2,3,3, 3, 3, 3, 3, 3, 3, 4, 4, ... ;; (define (PARSUMS_OF_CHARFUN soff foo) ;; soff = starting offset. ;; (implement-cached-function 0 (cfun n) ;; (cond ((< n soff) 0) ;; ((= soff n) (if (> (foo soff) soff) 0 1)) ;; (else ;; (let ((preval (cfun (- n 1)))) ;; (if (= (foo (+ 1 soff preval)) n) (+ 1 preval) preval) ;; ) ;; ) ;; ) ;; ) ;; ) ;; fun_on_i should be a monotone function, we return the v which do not occur in its range. ;; Is there a way to do this with one cached function less? (define (COMPLEMENT soff fun_on_i) ;; soff = starting offset. (let ((inv (PSEUDOINVERSE2 soff soff fun_on_i))) (MATCHING-POS soff soff (lambda (i) (let ((inv_i (inv i))) (or (< inv_i soff) (not (= i (fun_on_i inv_i)))))) ) ) ) ;; The overriding of the initial values should be implemented in implement-cached-function, ;; so that there would not be any overhead at the runtime. ;; (They would be written directly to the cache, when it is initialized!) (define (EIGEN-CONVOLUTION soffval mulfun) ;; These begin always from zero. (implement-cached-function 0 (fun_defined n) (cond ((and (integer? soffval) (= 0 n)) soffval) ((and (list? soffval) (< n (length soffval))) (list-ref soffval n)) (else (let loop ((s 0) (i 0) (j (- n 1))) (if (>= i j) (+ (* 2 s) (if (= i j) (let ((c (fun_defined i))) (mulfun c c)) 0)) (loop (+ s (mulfun (fun_defined i) (fun_defined j))) (1+ i) (-1+ j)) ) ) ) ) ) ) (define (GEN-CONVOLVE soff mulfun fun1 fun2) (implement-cached-function 0 (fun_defined n) (let loop ((s 0) (i soff) (j n)) (if (< j soff) s (loop (+ s (mulfun (fun1 i) (fun2 j))) (1+ i) (-1+ j)) ) ) ) ) (define (CONVOLVE soff fun1 fun2) (GEN-CONVOLVE soff * fun1 fun2)) ;; Didn't realize that it is this easy. See Joshua Zucker's mail ;; "Re: [SeqFan]: Repeated iterations of INVERT starting from A019590 ?" ;; on SeqFan-mailing list, Jun 7, 2006 6:46 PM (define (INVERT fun) ;; Always one-based! (implement-cached-function 0 (fun_defined n) (+ (fun n) ;; The whole space can be filled by (fun n) objects of size n. (let loop ((s 0) (i 1) (j (- n 1))) ;; In how many ways smaller parts can be filled? (if (< j 1) s (loop (+ s (* (fun_defined i) (fun j))) (1+ i) (-1+ j)) ) ) ) ) ) (definec (add1 n) (1+ n)) ;; Our cached version. (definec (rowfun_n_for_Esieve n) ;; (if (= 1 n) add1 ;; We return +1 function, that gives 2,3,4,5,6,7,8,9,10,11,... (let* ((prevrowfun (rowfun_n_for_Esieve (- n 1))) (prevprime (prevrowfun 1)) ) (compose-funs prevrowfun (NONZERO-POS 1 1 (lambda (i) (modulo (prevrowfun i) prevprime)))) ) ) ) ;; Row 1 = 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,... ;; Row 2 = 3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,... ;; Row 3 = 5,7,11,13,17,19,23,25,29,31,35,37,41,43,47,49,53 ;; Row 4 = 7,11,13,17,19,23,29,31,41,43,47,49,53,... (definec (A000040 n) ((rowfun_n_for_Esieve n) 1)) (define A000720 (PSEUDOINVERSE2 1 1 A000040)) (define A018252 (COMPLEMENT 1 A000040)) ;; 1 and composites. (define A002808 (compose-funs A018252 1+)) ;; Composites. (define Anew_primes_and_composited_convolved (CONVOLVE 1 A000040 A002808)) ;; Noise? (define Anew_primes_and_nonprimes_convolved (CONVOLVE 1 A000040 A018252)) ;; More of the same, noise? ;; In real life we would implement A010051 with some probabilistic or deterministic ;; primeness function, and then have: ;; (define A000040 (NONZERO-POS 1 1 A010051)) ;; and ;; (define A000720 (PARTIALSUMS 1 1 A010051)) ;; ;; (possibly with some clever optimization traversing only 6n+1 and 6n+5, etc. ;; also caching a lots of smaller terms). (define A007504 (PARTIALSUMS 1 1 A000040)) ;; A083375 n appears prime(n) times. (define A083375 (LEAST-GTE-I 1 1 A007504)) (definec (A165569 n) (if (= 1 n) 1 (let* ((i (A165569 (-1+ n))) (champion (abs (- *Phi* (/ (A108539 i) (A000040 i))))) ) (let loop ((i (1+ i))) (cond ((< (abs (- *Phi* (/ (A108539 i) (A000040 i)))) champion) i ;; Found a better specimen than the current champion. ) (else (loop (1+ i))) ) ) ) ) ) ;; Compute these sieve arrays as A-entries, and also similar tables as Yasutoshi's A083140. (define (Esievebi col row) ((rowfun_n_for_Esieve row) col)) (definec (rowfun_n_for_A083221 n) ;; (if (= 1 n) A005843 ;; We return even numbers as the first row. (let ((rowfun_of_esieve (rowfun_n_for_Esieve n)) (prime (A000040 n)) ) (compose-funs rowfun_of_esieve (MATCHING-POS 1 1 (lambda (i) (zero? (modulo (rowfun_of_esieve i) prime)))) ) ) ) ) (define (A083221bi col row) ((rowfun_n_for_A083221 row) col)) (define (A083221 n) (A083221bi (1+ (A025581 (-1+ n))) (1+ (A002262 (-1+ n))))) (define (A083140 n) (A083221bi (1+ (A002262 (-1+ n))) (1+ (A025581 (-1+ n))))) ;; Analogous tables for A000959 and A003309 should be permutations of natural numbers >= 1. ;; See also Y. Motohashi, "An Overview of the Sieve Method and its History" ;; http://arxiv.org/abs/math.NT/0505521 ;; Similarly, implement rowfun_n_for_A014580, provided there is an easily ;; implementable Euclidean algorithm for GCD's of GF(2)[X] polynomials. (definec (A005408shifted n) (- (* 2 n) 1)) ;; Cached variant of odd numbers, one-based. (define A001651c (compose-funs (NONZERO-POS 1 1 (lambda (i) (modulo i 3))) 1+)) ;; Zero-based in OEIS. (define (A001651 n) (if (even? n) (+ 1 (* 3 (/ n 2))) (- (* 3 (/ (+ n 1) 2)) 1))) ;; Lucky numbers: ;; A000959 = 1,3,7,9,13,15,21,25,31,33,37,43,49,51,63,67,69,73,75,79,87,93,99, ;; Delete every 2nd number (of naturals), ;; leaving 1 3 5 7 ...; ;; the 2nd number remaining is 3, so delete every 3rd number, ;; leaving 1 3 7 9 13 15 ...; ;; now delete every 7th number, ;; leaving 1 3 7 9 13 ...; ;; now delete every 9th number; etc. (definec (rowfun_n_for_A000959sieve n) ;; (if (= 1 n) A005408shifted ;; Else, remove every (prevrowfun n):th number from the previous row. (let* ((prevrowfun (rowfun_n_for_A000959sieve (- n 1))) (everynth (prevrowfun n)) ;; to be removed. ) (compose-funs prevrowfun (NONZERO-POS 1 1 (lambda (i) (modulo i everynth)))) ) ) ) (definec (A000959 n) ((rowfun_n_for_A000959sieve n) n)) (define A050505 (COMPLEMENT 1 A000959)) ;; Unlucky numbers. (define A109497 (PSEUDOINVERSE2 1 1 A000959)) ;; Ludic numbers: ;; A003309 = 2,3,5,7,11,13,17,23,25,29,37,41,43,47,53,61,67,71,77,83,89,91,97, ;; Ludic numbers: apply the same sieve as Eratosthenes, but cross off every k-th /remaining/ number. ;; Row 1 = 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,... ;; Row 2 = 3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,... ;; Row 3 = 5,7,11,13,17,19,23,25,29,31,35,37,41,... ;; Row 4 = 7,11,13,17,23,25,29,31,37,41,... (definec (rowfun_n_for_A003309sieve n) ;; (if (= 1 n) add1 ;; We return +1 function, that gives 2,3,4,5,6,7,8,9,10,11,... (let* ((prevrowfun (rowfun_n_for_A003309sieve (- n 1))) (everynth (prevrowfun 1)) ) (compose-funs prevrowfun (NONZERO-POS 1 1 (lambda (i) (modulo (- i 1) everynth)))) ) ) ) (definec (A003309 n) (if (= 1 n) 1 ((rowfun_n_for_A003309sieve (- n 1)) 1))) (define Anew_unludic_numbers (COMPLEMENT 1 A003309)) ;; Unludic numbers. (define Anew_num_of_ludic_numbers (PSEUDOINVERSE2 1 1 A003309)) ;; Number of ludic numbers <= n. (define (Anew_joku1 n) (- (A003309 (+ n 1)) (A000040 n))) ;; Is it always positive?! One-based. Cf. A032600. (define (Anew_joku2 n) (/ (Anew_joku1 n) 2)) (define (A032600 n) (- (A000959 n) (A000040 n))) ;; halved versions not in OEIS. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define *Sqrt5* (sqrt 5)) (define *Phi* (/ (1+ *Sqrt5*) 2)) (define *LogPhi* (log *Phi*)) (define (sgn n) (cond ((zero? n) 0) ((< n 0) -1) (else 1))) (define (A000004 n) (- n n)) (define (A000012 n) (1+ (- n n))) (define (fix:jacobi-symbol p q) (if (not (and (fix:fixnum? p) (fix:fixnum? q) (fix:= 1 (fix:and q 1)))) (error "fix:jacobi-symbol: args must be fixnums, and 2. arg should be odd: " p q ) (let loop ((p p) (q q) (s 0)) ;; 0 in bit-1 stands for +1, 1 in bit-1 for -1. (cond ((fix:zero? p) 0) ((fix:= 1 p) (fix:- 1 (fix:and s 2))) ((fix:= 1 (fix:and p 1)) ;; Odd p ? (loop (fix:remainder q p) p (fix:xor s (fix:and p q))) ) (else ;; It's even, get rid of one 2: (loop (fix:lsh p -1) q (fix:xor s (fix:xor q (fix:lsh q -1)))) ) ) ) ) ) ;; Here's our C-version. The teaching: Never implement mathematician's ;; or logician's elegant formulae directly, without thinking! ;; Working in GF(2) with XOR & AND is much more natural for ;; computers than working in isomorphic multiplicative group of {+1, -1} ;; with MUL. ;; We also convert the recursion in our formula to a simple loop. ;; q should be always odd! ;; ;; int js_ULI(ULI p,ULI q) ;; { ;; int s = 0; /* 0 in bit-1 stands for +1, 1 in bit-1 for -1. */ ;; ULI new_p; ;; loop: ;; if(0 == p) { return(p); } ;; if(1 == p) { return(1-(s&2)); } /* Convert 1 in bit-1 to -1, 0 to +1. */ ;; ;; if(p&1) /* We have an odd p. */ ;; { ;; /* If both p & q are 3 mod 4, then sign changes, otherwise stays same: */ ;; s ^= (p&q); /* Only the bit-1 is significant, others are ignored. */ ;; new_p = q % p; /* Could we have a simple - here as with Euclid? */ ;; q = p; ;; p = new_p; ;; goto loop; ;; } ;; else /* We have an even p. So (2k/q) = (2/q)*(k/q) */ ;; { /* where (2/q) = 1 if q is +-1 mod 8 and -1 if q is +-3 mod 8. */ ;; /* I.e. sign changes only if q's lower bits are (011) or (101), ;; i.e. if the bit-1 and bit-2 xored yield 1. */ ;; s ^= (q^(q>>1)); /* Thus, this does it. */ ;; p >>= 1; ;; goto loop; ;; } ;; } ;; (define fix:legendre-symbol fix:jacobi-symbol) (define jacobi-symbol fix:jacobi-symbol) (define legendre-symbol fix:legendre-symbol) ;; Useful. (define (ratio->float-str x y prec) (if (or (zero? x) (zero? y)) (if (equal? x y) "1" "0") (fluid-let ((flonum-unparser-cutoff (list 'absolute prec))) (string-append (if (< x y) "0" "") (number->string (exact->inexact (/ x y))) ) ) ) ) ;; A007918 Least prime >= n (version 1 of the "next prime" function). ;; (Offset 0) ;; 2,2,2,3,5,5,7,7,11,11,11,11,13,13,17,17,17,17,19,19,23,23,23,23,29,29,29, ;; A151800 Least prime > n (version 2 of the "next prime" function). ;; 2,2,3,5,5,7,7,11,11,11,11,13,13,17,17,17,17,19,19,23,23,23,23,29,29,29,29, ;; (Offset 0) ;; A007917 Version 1 of the "previous prime" function: largest prime <= n. ;; (Offset 2) ;; 2,3,3,5,5,7,7,7,7,11,11,13,13,13,13,17,17,19,19,19,19,23,23,23,23,23,23, ;; A151799 Version 2 of the "previous prime" function: largest prime < n. ;; (Offset 3) ;; 2,3,3,5,5,7,7,7,7,11,11,13,13,13,13,17,17,19,19,19,19,23,23,23,23,23,23, ;; A108539 Prime p such that p/prime(n) is nearest to phi, the golden ratio. ;; Note: A010051 is in module GF2Xfuns.scm/com in this same directory. (define A151800 (NEXT-MATCHING-POS (lambda (i) (= 1 (A010051 i))))) (define A007917 (PREV-OR-SAME-MATCHING-POS (lambda (i) (= 1 (A010051 i))))) (definec (A108539 n) (let* ((p1 (A000040 n)) (n2 (A000201 p1)) (q1 (A151800 n2)) (q2 (A007917 n2)) ) (if (< (abs (- *Phi* (/ q1 p1))) (abs (- *Phi* (/ q2 p1)))) q1 q2 ) ) ) (definec (fibo nakki) ;; I.e., A000045 (if (< nakki 2) nakki (+ (fibo (-1+ nakki)) (fibo (- nakki 2))) ) ) (define A000045 fibo) (define (A001906 n) (A000045 (A005843 n))) (define (A122367 n) (A000045 (A005408 n))) (define (A027941 n) (-1+ (A122367 n))) (define (A000201 n) (floor->exact (* n *Phi*))) (define (A004956 n) (ceiling->exact (* n *Phi*))) (define (A007067 n) (round->exact (* n *Phi*))) (define (A005408 n) (+ (* 2 n) 1)) (define (A004767 n) (+ (* 4 n) 3)) (define (A016813 n) (+ (* 4 n) 1)) (definec (A016813c n) (+ (* 4 n) 1)) ;; Cached version for debugging. (define (A017557 n) (+ (* 12 n) 3)) (define (A017605 n) (+ (* 12 n) 7)) (define (A019590 n) (if (< n 3) 1 0)) (define A000045_shifted_left (INVERT A019590)) ;; Factorial with syntax modified from the post-fix to pre-fix !: (definec (! n) (if (zero? n) 1 (* n (! (-1+ n))))) ;; A000142 (define A000142 !) (define (!cut i j) ;; Compute the product i*(i+1)*(i+2)*...*j (cond ((eq? i j) i) ((> i j) 1) (else (* i (!cut (1+ i) j))) ) ) ;; (C r n) stands for the binomial {r choose n} (define (C r n) (/ (!cut (1+ n) r) (! (- r n)))) (define A000108 (EIGEN-CONVOLUTION 1 *)) (define A000108one_based (INVERT (compose-funs A000108 -1+))) (define (A007318 n) (C (A003056 n) (A002262 n))) (definec (A000984 n) (/ (! (* 2 n)) (expt (! n) 2))) ;; Central binomial coefficients: C(2n,n) = (2n)!/(n!)^2. (definec (binomial_n_2 n) (/ (* (-1+ n) n) 2)) ;; A000217 = LEFT(binomial_n_2) (define A003989bi gcd) (define A003990bi lcm) (define (A003989 n) (A003989bi (1+ (A002262 n)) (1+ (A025581 n)))) (define (A003990 n) (A003990bi (1+ (A002262 n)) (1+ (A025581 n)))) (define (obtain-integer-bitwise-function bit-string-FUN) (lambda (x y) (let ((size (max (binwidth x) (binwidth y)))) (bit-string->unsigned-integer (bit-string-FUN (unsigned-integer->bit-string size x) (unsigned-integer->bit-string size y) ) ) ) ) ) (define A003986bi (obtain-integer-bitwise-function bit-string-or)) (define A003987bi (obtain-integer-bitwise-function bit-string-xor)) (define A004198bi (obtain-integer-bitwise-function bit-string-and)) (definec (nth-row-of-A047999 n) (cond ((zero? n) (unsigned-integer->bit-string 1 1)) (else (next-row-of-A047999 (nth-row-of-A047999 (-1+ n)))) ) ) (define (next-row-of-A047999 gen) (let ((one-zero (make-bit-string 1 #f))) (bit-string-xor (bit-string-append gen one-zero) (bit-string-append one-zero gen) ) ) ) (define (A001317 n) (bit-string->unsigned-integer (nth-row-of-A047999 n))) (definec (nth-gen-of-rule90 n) (cond ((zero? n) (unsigned-integer->bit-string 1 1)) (else (next-rule90-gen (nth-gen-of-rule90 (-1+ n)))) ) ) (define (next-rule90-gen gen) (let ((two-zeros (make-bit-string 2 #f))) (bit-string-xor (bit-string-append gen two-zeros) (bit-string-append two-zeros gen) ) ) ) (define (A038183 n) (bit-string->unsigned-integer (nth-gen-of-rule90 n))) (define (A038183v2 n) (A001317 (* 2 n))) (define (bit-i n i) (modulo (floor->exact (/ n (expt 2 i))) 2)) (define (factbaseR->n rex) ;; Convert the reversed factorial expansion list to an integer. (let loop ((rex rex) (n 0) (i 1)) (cond ((null? rex) n) (else (loop (cdr rex) (+ n (* (! i) (car rex))) (1+ i))) ) ) ) (define (n->factbase n) ;; Convert an integer to a factorial expansion list. (let loop ((n n) (fex (if (zero? n) (list 0) (list))) (i 2)) (cond ((zero? n) fex) (else (loop (floor->exact (/ n i)) (cons (modulo n i) fex) (1+ i))) ) ) ) (define (A099563 n) (car (n->factbase n))) (define (baselist->n base bex) ;; Convert base n expansion list to an integer. (let loop ((bex bex) (n 0)) (cond ((null? bex) n) (else (loop (cdr bex) (+ (* n base) (car bex)))) ) ) ) (define (baselist-as-binary lista) (baselist->n 2 lista)) (define (baselist-as-ternary lista) (baselist->n 3 lista)) (define (baselist-as-decimal lista) (baselist->n 10 lista)) ;; Note: A link from A007623 to A060130 is completely off the wall! ;; This is of the limited usability: (define (A007623 n) (baselist-as-decimal (n->factbase n))) (define (avg lista) (/ (reduce + 0 lista) (length lista))) (define Ajoku1 (MATCHING-POS 0 0 (lambda (i) (integer? (avg (n->factbase i)))))) (define Ajoku2 (MATCHING-POS 0 0 (lambda (i) (let* ((fex (n->factbase i)) (m (avg fex)) ) (and (integer? m) (gs2gs? (list->vector fex) m 0)) ) ) ) ) (define Ajoku3 (MATCHING-POS 0 0 (lambda (i) (integer? (avg (n->factbase (A000290 i))))))) (define Ajoku4 (MATCHING-POS 0 0 (lambda (i) (= 1 (avg (n->factbase (A000290 i))))))) (define Ajoku5 (MATCHING-POS 0 0 (lambda (i) (= 2 (avg (n->factbase (A000290 i))))))) (define Ajoku6 (MATCHING-POS 0 0 (lambda (i) (= 3 (avg (n->factbase (A000290 i))))))) ;; (map Ajoku7 (iota0 6)) --> (0 1 26 195 4666 19888 780568) (definec (Ajoku7 n) (first-n-where-fun_n-is-i0 (lambda (i) (avg (n->factbase (A000290 i)))) n)) ;; A127230 ??? (definec (Ajoku0 n) (first-n-where-fun_n-is-i0 (lambda (i) (avg (n->factbase i))) n)) (define (gs2gs? tv b type) (let ((gs (-1+ (expt 2 b))) ;; The ground state, e.g. 7 for b=3. (p (vector-length tv)) ;; Period of our tentative pattern ) (let loop ((s gs) (i 0) (visited (list))) ;; When finished, return true only if we have returned back to the ground state: (cond ((= i p) (= s gs)) (else (let ((tt (vector-ref tv i))) (cond ((and (= 1 type) (> i 0) (= s gs)) #f) ((and (= 2 type) (memq s visited)) #f) ((and (even? s) (not (zero? tt))) #f) ;; Zero-throw expected! ((not (even? (floor->exact (/ s (expt 2 tt))))) #f ;; Collision! ) (else (loop (floor->exact (/ (+ s (expt 2 tt)) 2)) (1+ i) (if (= 2 type) (cons s visited) visited) ) ) ) ) ) ) ;; cond ) ;; let loop ) ) ;; Shift factorial expansion of n one digit left: (define (A153880 n) (let loop ((n n) (z 0) (i 2) (f 2)) (cond ((zero? n) z) (else (loop (floor->exact (/ n i)) (+ (* f (modulo n i)) z) (1+ i) (* f (+ i 1)) ) ) ) ) ) ;; And the same halved: (define (A153883 n) (/ (A153880 n) 2)) (define (A001563 n) (* n (! (1+ n)))) ;; First differences of A000142. ;; From juggling.scm, all zero-based: (definec (A007489 n) (if (zero? n) 0 (+ (! n) (A007489 (-1+ n))))) (definec (A084555 n) (if (zero? n) 0 (+ (A084556 n) (A084555 (-1+ n))))) ;; PSUM of next (definec (A084556 n) (first_pos_with_funs_val_gte A007489 n)) ;; n occurs n! times. (definec (A084557 n) (first_pos_with_funs_val_gte A084555 n)) ;; n occurs A084556(n) times (definec (A084558 n) (cond ((zero? n) 0) (else (length (n->factbase n))))) ;; After 0, which occurs once, each n occurs A001563(n) times (definec (A084519 n) (cond ((< n 3) 1) ((= n 3) 3) (else (+ (* 3 (A084519 (- n 1))) (* 2 (A084519 (- n 2))) (* 2 (A084519 (- n 3))))) ) ) (definec (A084509 n) (if (< n 4) (! n) (* 4 (A084509 (-1+ n))))) (define A084509v2 (INVERT A084519)) (define (shr n) (if (odd? n) (/ (- n 1) 2) (/ n 2))) (define (>> n i) (if (zero? i) n (>> (floor->exact (/ n 2)) (- i 1)))) (define (<< n i) (if (<= i 0) (>> n (- i)) (<< (+ n n) (- i 1)))) (define (A005843 n) (* 2 n)) (define (A008585 n) (* 3 n)) (define (A008586 n) (* 4 n)) (define (A008587 n) (* 5 n)) (define (A008588 n) (* 6 n)) (define (A008589 n) (* 7 n)) (define (A008590 n) (* 8 n)) (define (A008591 n) (* 9 n)) (define (A008598 n) (* 16 n)) (define (A016777 n) (1+ (* 3 n))) (define (A016789 n) (+ 2 (* 3 n))) (define (A004526 n) (floor->exact (/ n 2))) (define (A002264 n) (floor->exact (/ n 3))) (define (A102283 n) (- (A000035 (A010872 n)) (A004526 (A010872 n)))) ;; Period 3: repeat (0,1,-1). (define (A000035 n) (modulo n 2)) (define (A010872 n) (modulo n 3)) (define (A010873 n) (modulo n 4)) (define halve A004526) (define double A005843) (define lsb A000035) (define (A000079 n) (expt 2 n)) ;; Note for n > 0, (floor-log-2 n) = (- (binwidth n) 1) (define (binwidth n) ;; = A029837(n+1) (let loop ((n n) (i 0)) (if (zero? n) i (loop (floor->exact (/ n 2)) (1+ i)) ) ) ) ;; This doesn't seem to work for numbers > 1023 bits: (define (A000523faster n) (cond ((zero? n) -1) (else (floor->exact (/ (log n) (log 2)))))) ;; Have to do it with a reliable loop! (define (A000523 n) (-1+ (binwidth n))) (define floor-log-2 A000523) ;; An old alias. (define (A052928 n) (+ n (- (modulo n 2)))) (define (A016116 n) (expt 2 (floor->exact (/ n 2)))) ;; 1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,... (define (A081604 n) ;; Except we have a(0)=0, not 1, as in OEIS! (let loop ((n n) (i 0)) (if (zero? n) i (loop (floor->exact (/ n 3)) (1+ i)) ) ) ) ;; 0,0,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3, (define (A062153 n) (- (A081604 n) 1)) ;; Floor [ log_3(n) ]. One-based. (define (A053644 n) (if (zero? n) n (expt 2 (A000523 n)))) ;; (define (A053645 n) (- n (expt 2 (A000523 n)))) (define (A053645 n) (cond ((zero? n) n) (else (- n (expt 2 (A000523 n)))))) ;; One-based. (define (A006257 n) (if (zero? n) 0 (A005408 (A053645 n)))) (define (A004760 n) (if (zero? n) 0 (- (A008585 n) 2 (A006257 (-1+ n))))) (define (A004754 n) (+ n (A053644 n))) (define (A072376 n) (if (< n 2) n (/ (A053644 n) 2))) (define (A003817 n) (if (zero? n) n (-1+ (A005843 (A053644 n))))) (definec (A003817v2 n) (if (zero? n) n (A003986bi (A003817v2 (-1+ n)) n))) (define (A062383 n) (1+ (A003817 n))) ;; A065120 Highest power of 2 dividing A057335(n). ;; 0,1,2,1,3,2,1,1,4,3,2,2,1,1,1,1,5,4,3,3,2,2,2,2,1,1,1,1,1,1,1,1,6,... (define (A065120 n) (if (zero? n) n (1+ (length-of-zero-bit-run-before-msb n)))) ;; Brute and dumb: (define (length-of-zero-bit-run-before-msb n) (let loop ((i 0) (maskbit (A072376 n))) (if (or (zero? maskbit) (not (zero? (modulo (floor->exact (/ n maskbit)) 2))) ) i (loop (1+ i) (floor->exact (/ maskbit 2))) ) ) ) (define (A000120 n) (let loop ((n n) (i 0)) (if (zero? n) i (loop (floor->exact (/ n 2)) (+ i (modulo n 2))) ) ) ) ;; f(z) = 2z if z>0 else 2|z|+1 (define (Z->N n) (if (positive? n) (* n 2) (+ 1 (* 2 (- n))))) ;; g(n) = n/2 if n even, else (1-n)/2. (define (N->Z n) (if (even? n) (/ n 2) (/ (- 1 n) 2))) (define (A001057 n) (N->Z (+ 1 n))) ;; Zero-based version of N->Z (define (A010060 n) (modulo (A000120 n) 2)) (define (A010059 n) (- 1 (A010060 n))) (define (A007895 n) (A000120 (A003714 n))) ;; Number of 1-fibits in Z.E. (define (A095076 n) (A010060 (A003714 n))) ;; Parity of 1-fibits in Z.E. (define (A095111 n) (- 1 (A095076 n))) ;; Its complement. (define (A002450 n) (/ (- (expt 4 n) 1) 3)) (define (A020988 n) (* 2 (A002450 (+ n 1)))) (define (A072197 n) (/ (- (* 10 (expt 4 n)) 1) 3)) ;; I trust Bottomley's formula. (define (A072197v2 n) (+ 3 (* 10 (A002450 n)))) (define (A080675 n) (/ (- (* 5 (expt 4 n)) 8) 6)) ;; Of course many of these (especially those that occur as columns of ;; Wythoff array, A035513) have elegant formulae as well. ;; See the corresponding entries in OEIS. Here I just wanted ;; to be thorough and systematic: (definec (A095096 n) ;; fibevil numbers, complement of A020899. (cond ((= 0 n) 0) ;; 0 is the first fibevil number. (else (let loop ((i (+ 1 (A095096 (- n 1))))) (cond ((= 0 (A095076 i)) i) ;; parity of 1-fibits is even? (else (loop (+ 1 i))) ;; Try the next one then. ) ) ) ) ) (definec (A020899 n) ;; fibodious numbers (cond ((= 0 n) 1) ;; 1 is the first fibodious number. (else (let loop ((i (+ 1 (A020899 (- n 1))))) (cond ((= 1 (A095076 i)) i) ;; parity of 1-fibits is odd? (else (loop (+ 1 i))) ;; Try the next one then. ) ) ) ) ) (definec (A026274 n) ;; fib00 numbers. Check this! (cond ((= 0 n) 3) ;; 3 is the first member. it's z.e. being 100. (else (let loop ((i (+ 1 (A026274 (- n 1))))) (cond ((= 0 (modulo (A003714 i) 4)) i) ;; z.e. ends as ...00 ? (else (loop (+ 1 i))) ;; Try next one then. ) ) ) ) ) (definec (A095097 n) ;; fib000 numbers. (cond ((= 0 n) 5) ;; 5 is the first member, it's z.e. being 1000. (else (let loop ((i (+ 1 (A095097 (- n 1))))) (cond ((= 0 (modulo (A003714 i) 8)) i) ;; z.e. ends as ...000 ? (else (loop (+ 1 i))) ;; Try next one then. ) ) ) ) ) (definec (A095098 n) ;; fib001 numbers. (cond ((= 0 n) 1) ;; 1 is the first member, it's z.e. being 1. (else (let loop ((i (+ 1 (A095098 (- n 1))))) (cond ((= 1 (modulo (A003714 i) 8)) i) ;; z.e. ends as ...001 ? (else (loop (+ 1 i))) ;; Try next one then. ) ) ) ) ) (definec (A035336 n) ;; fib010 numbers, second column of Wythoff array. (cond ((= 0 n) 2) ;; 2 is the first member, it's z.e. being 10. (else (let loop ((i (+ 1 (A035336 (- n 1))))) (cond ((= 2 (modulo (A003714 i) 8)) i) ;; z.e. ends as ...010 ? (else (loop (+ 1 i))) ;; Try next one then. ) ) ) ) ) (definec (A035337 n) ;; fib100 numbers, third column of Wythoff array. (cond ((= 0 n) 3) ;; 3 is the first member. it's z.e. being 100. (else (let loop ((i (+ 1 (A035337 (- n 1))))) (cond ((= 4 (modulo (A003714 i) 8)) i) ;; z.e. ends as ...100 ? (else (loop (+ 1 i))) ;; Try next one then. ) ) ) ) ) (definec (A095099 n) ;; fib101 numbers. (cond ((= 0 n) 4) ;; 4 is the first member. it's z.e. being 101. (else (let loop ((i (+ 1 (A095099 (- n 1))))) (cond ((= 5 (modulo (A003714 i) 8)) i) ;; z.e. ends as ...101 ? (else (loop (+ 1 i))) ;; Try next one then. ) ) ) ) ) (define (A029837 n) (cond ((< n 1) (error "A029837 supplied with argument less than one: " n)) (else (binwidth (-1+ n))) ) ) (definec (A030101 nn) ;; Was: binrev (let loop ((z 0) (n nn)) (if (zero? n) z (loop (+ (* 2 z) (modulo n 2)) (floor->exact (/ n 2)) ;; Doesn't work when n is big enough: (fix:lsh n -1) ;; n >>= 1 ) ) ) ) (definec (A035327 n) (- (-1+ (expt 2 (binwidth n))) n)) ;; Complement the binary exp. (definec (A036044 n) ;; i.e. binrevcompl, differs from EIS-seq as a(0)=0, not 1. (let loop ((z 0) (n n)) (if (zero? n) z (loop (+ (* 2 z) (- 1 (modulo n 2))) (floor->exact (/ n 2)) ;; (fix:lsh n -1) ;; n >>= 1 ) ) ) ) ;; Note that ;; (fetch-from-bits-of-n-given-by-column-x-of-table ;; (store-n-to-bits-given-by-column-x-of-table n col some-NxN->N-map) ;; col some-NxN->N-map) ;; is an identity function on n, with all values of col >= 0. ;; Corresponds to *A057163 (define (A054429 n) ;; -> (0),1,3,2,7,6,5,4,15,14,13,12,11,10,9,8,31,30,... (if (zero? n) n (-1+ (- (* 3 (expt 2 (A000523 n))) n)) ) ) ;; Corresponds to *A069770 ;; A063946 Write n in binary and complement second bit (from the left), with a(0)=0 and a(1)=1. ;; if(n<2, n>0, 3/2*2^floor(log(n)/log(2))-2^floor(log(4/3*n)/log(2))+n) (from R. Stephan) (define (A063946 n) ;; -> (0),1,3,2,6,7,4,5,12,13,14,15,8,9,10,11,24,25,26,... (if (< n 2) n (let ((sm (A072376 n))) (+ n (* sm (- 1 (* 2 (modulo (floor->exact (/ n sm)) 2))))) ) ) ) (definec (A059893 n) (if (<= n 1) n (let* ((k (- (A000523 n) 1)) (r (A059893 (- n (A000079 k))))) (if (= 2 (floor->exact (/ n (A000079 k)))) (* 2 r) (+ 1 r) ) ) ) ) (define A059894 (compose-funs A054429 A059893)) ;; A065190 = A059893 o A063946 o A059893 (define (A065190 n) (if (< n 2) n (+ n (expt -1 n)))) (define (A056539 n) (if (odd? n) (A030101 n) (A036044 n))) ;; There exists similar rotate & deep rotate variants of this same idea. (define (A056539v2 n) (runcount1list->binexp (reverse! (binexp->runcount1list n)))) ;; How to prove that this is an involution? ;; By (strong) induction, or by simpler means? ;; (E.g. if a Life pattern is symmetric, it just cannot ;; but stay symmetric ever after.) (definec (A105726 n) (cond ((< n 2) n) (else (runcount1list->binexp (map A105726 (reverse! (binexp->runcount1list n))))) ) ) (definec (A001477yet_another_variant n) (cond ((< n 2) n) (else (runcount1list->binexp (map A001477yet_another_variant (binexp->runcount1list n)))) ) ) ;; This one by Leroy Quet, Oct 08 2009: ;; a(9)=27, because (binexp->runcount1list 9)=(1 2 1), so replacing ;; run of 1 ones with run of 2 ones, run of 2 0's with run of 1 0's ;; and finally run of 1 ones with run of 2 ones, thus we get 11011 = 27. ;; a(11)=25 because (binexp->runcount1list 11)=(1 1 2) (1011), so ;; replacing run of 1 ones with run of 2 ones, run of 1 0's with run ;; of 2 zeros, and run of 2 ones with run of 1 ones, we get 11001 = 25. (definec (A166166 n) (let* ((runlens (binexp->runcount1list n)) (rlsorted (uniq (sort runlens <))) (lenrls (length rlsorted)) ) (let loop ((rl runlens) (s 0) (b 1)) (cond ((null? rl) s) (else (let* ((nrl (list-ref rlsorted (- lenrls 1 (nthmemq (car rl) rlsorted)) ) ) (p2 (expt 2 nrl)) ) (loop (cdr rl) (+ (* s p2) (* b (-1+ p2))) (- 1 b)) ) ) ) ) ) ) (define (interleave a b) (let loop ((z (list)) (a a) (b b)) (cond ((and (null? a) (null? b)) (reverse! z)) ((null? a) (loop (cons (car b) z) a (cdr b))) ((null? b) (loop (cons (car a) z) (cdr a) b)) (else (loop (cons (car b) (cons (car a) z)) (cdr a) (cdr b))) ) ) ) ;; Cf. A056539 (definec (A166404 n) ;; begins as 0,1,2,3,6,5,4,7,14,13,10,11,12,9,8,15,30,29,26,27,22,21,20,23,28,25,... (let ((runlens (binexp->runcount1list n))) (runcount1list->binexp (interleave (bisect runlens 1) (bisect runlens 0))) ) ) ;; Not an involution like the previous one: (define (Ajoku2 n) ;; begins as 1,2,3,4,5,6,7,8,11,10,9,12,13,14,15,16,23,22,19,20,21 (let ((runlens (binexp->runcount1list n))) (runcount1list->binexp (append (bisect runlens 0) (bisect runlens 1))) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (definec (on-bit-indices n) (let loop ((n n) (i 0) (c (list)) ) (cond ((zero? n) (reverse! c)) ((odd? n) (loop (/ (- n 1) 2) (+ 1 i) (cons i c))) (else (loop (/ n 2) (+ 1 i) c)) ) ) ) (define (halve n) (/ n 2)) (define (shr n) (if (odd? n) (/ (- n 1) 2) (/ n 2))) (definec (left-options n) (map halve (keep-matching-items (on-bit-indices n) even?))) (definec (right-options n) (map halve (map -1+ (keep-matching-items (on-bit-indices n) odd?)))) ;; . = 0 ;; \ = 1 ;; / = 2 ;; \/ = 3 ;; \ ;; / = 8 ;; / ;; \ = 16 ;; \ ;; \ = 4 ;; / ;; / = 32 ;; \ ;; \ \ \ \/ \/ ;; \/ = 9 \/ = 12 \/ = 129 \/ = 524289 = 2^(2*9+1)+1 (definec (A057300 n) (reduce + 0 (map (lambda (i) (expt 2 i)) (map A004442 (on-bit-indices n)))) ) (definec (A126006 n) ;; Swap the positions of quaternary digits q0 <-> q1, q2 <-> q3, q4 <-> q5, ... (let loop ((n n) (s 0) (p 1)) (cond ((zero? n) s) (else (loop (floor->exact (/ n 16)) (+ s (* p (+ (* 4 (modulo n 4)) (modulo (floor->exact (/ n 4)) 4)))) (* p 16) ) ) ) ) ) (define (A126007 n) ;; Swap the positions of quaternary digits q0, q1 <-> q2, q3 <-> q4, ... (+ (modulo n 4) (* 4 (A126006 (floor->exact (/ n 4))))) ) (define A126008 (compose-funs A057300 A126007)) ;; The first 64 terms are same as in A106485. (define A126008v2 (compose-funs A126007 A057300)) ;; Return the number of leading 1-bits in the binary expansion of n: ;; The current version (< 2007) in OEIS has been shifted once left! (define (A090996 n) (A007814 (+ 1 (A030101 n)))) ;; Zero-based, 0,1,1,2,1,1,2,3,1,1,1,1,2,2,3,4,1,... (definec (A106485 n) ;; negate, i.e. take the mirror-image of a CGT-tree. (let loop ((n n) (i 0) (s 0) ) (cond ((zero? n) s) ((odd? n) (loop (/ (- n 1) 2) (+ 1 i) (+ s (if (even? i) (expt 2 (+ 1 (* 2 (A106485 (/ i 2))))) (expt 2 (* 2 (A106485 (/ (- i 1) 2)))) ) ) ) ) (else (loop (/ n 2) (+ 1 i) s)) ) ) ) ;; 85159 --- 85228 ;; Note that: A071156 = A085198 o A014486 (define (A085198 n) (let loop ((n n) (s 0) (h 1) (i 2) (fi 1)) (cond ((zero? n) s) ((odd? n) (loop (/ (-1+ n) 2) s (-1+ h) i fi)) (else (loop (/ n 2) (+ s (* h fi)) (1+ h) (1+ i) (* fi i))) ) ) ) ;; Note that: A126302 = A125989 o A014486 (define (A125989 n) (let loop ((n n) (s 0) (h 0)) (cond ((zero? n) s) ((= 2 (modulo n 4)) (loop (/ (- n 2) 4) (+ s h 1) h)) ((odd? n) (loop (/ (- n 1) 2) s (- h 1))) (else (loop (/ n 2) s (+ 1 h))) ) ) ) ;; binexp->A071158-list o A014486 produces the terms of A071158 in list form: ;; (() (1) (1 1) (2 1) (1 1 1) (1 2 1) ...) (define (binexp->A071158-list n) (let loop ((n n) (lista (list)) (h 1)) (cond ((zero? n) lista) ((odd? n) (loop (/ (- n 1) 2) lista (- h 1))) (else (loop (/ n 2) (cons h lista) (1+ h))) ) ) ) ;; ;; Algorithm for Anewone1: divide the run-lengths of n into ;; two separate lists, those that correspond with runs of ones ;; (starting with the first run from the msb-end of n) ;; and that correspond with runs of zeros in the binary expansion ;; of n. ;; A) Beginning from zero-runs, add 1's to the result (from msb to lsb-end) ;; as long as there are 1's in the zero-runs-list (making it shorter all the time). ;; ;; When there's a first run larger than one in the zero-list, ;; add also one 1 to the result, subtract than run by one, ;; and switch the runlists for zeros and ones, make b=0 (start adding 0's ;; to result), and go back to A. ;; ;; If the run-list of zeros is finished completely ;; (after taking the last 1 from it and adding it to the 2*sum) ;; then switch also in that case to the list of ones. ;; ;; When the run-list of ones is also finished ;; (after taking the last 1 from it and adding zero to the 2*sum) ;; then the result is ready. This is the case for n whose ;; binary expansion is balanced. ;; ;; Note: there are n for which there is only runs of ones (no zeros), ;; e.g. 3, 7, 15. ;; and there are n for which there is one list more of ones than ;; zeros (e.g. 5). ;; ;; ;; (define (Ajoku_not_submitted n) (let ((runlens (binexp->runcount1list n))) (let loop ((chosen (bisect runlens 1)) ;; initially zeros. (others (bisect runlens 0)) ;; initially ones. (s 0) (b 1) ) (format #t "chosen=~a, others=~a, b=~a, s=~a\n" chosen others b s) (cond ((and (null? chosen) (null? others)) s) ((and (pair? chosen) (= 1 (car chosen)) (pair? (cdr chosen))) (loop (cdr chosen) others (+ s s b) b) ) (else ;; next run in result, or chosen will be finished, swap chosen and others. (loop others (if (or (null? chosen) (= 1 (car chosen))) '() (cons (- (car chosen) 1) (cdr chosen)) ) (+ s s b) (- 1 b) ) ) ) ) ) ) ;; Like previous, but start from the lsb-end. ;; Here are the 40 A-numbers you requested: A125974 --- A126013. (define (A125974v2 n) (let ((runlens (binexp->runcount1list n))) (let loop ((chosen (reverse! (bisect runlens 0))) ;; initially ones. (others (reverse! (bisect runlens 1))) ;; initially zeros. (s 0) (b (modulo n 2)) (p 1) ) ;; (format #t "chosen=~a, others=~a, b=~a, s=~a, p=~a\n" chosen others b s p) (cond ((and (null? chosen) (null? others)) s) ((and (pair? chosen) (= 1 (car chosen)) (pair? (cdr chosen))) (loop (cdr chosen) others (+ s (* b p)) b (+ p p)) ) (else ;; next run in result, or chosen will be finished, swap chosen and others. (loop others (if (or (null? chosen) (= 1 (car chosen))) '() (cons (- (car chosen) 1) (cdr chosen)) ) (+ s (* b p)) (- 1 b) (+ p p) ) ) ) ) ) ) ;; Here 1(0/1)* refers to the msb-prefix of the n: ;; ;; 0 Chosen=0 (but others is not 0), swap to others. ;; 1 Chosen=1, last one will follow. ;; (1+)0 Chosen=0, last zero will follow. One of A000918 (2^n - 2) (pow2? n+2) ;; 1(0/1)*11 Chosen=1, and one or more ones will follow. (= 3 (modulo chosen 4)) ;; 1(0/1)*00 Chosen=0, and one or more zeros will follow. (= 0 (modulo chosen 4)) ;; ;; Checked after the above cases: ;; 1(0/1)*(0+)1 Chosen=1, and one or more zeros follow, after which follow more ones. ;; (= 1 (modulo chosen 4)) ;; 1(0/1)*(0+)(1+)0 Chosen=0, and one or more ones follow, after which follow more zeros. ;; (= 2 (modulo chosen 4)) (define (A125974 n) (if (zero? n) n (let loop ((chosen (/ n (A006519 n))) ;; Initially ones, get rid of lsb-0's. (others (floor->exact (/ n (A006519 (+ 1 n))))) ;; Initially zeros, get rid of lsb-1's. (s 0) (b (modulo n 2)) (p 1) ) ;; (format #t "chosen=~a, others=~a, b=~a, s=~a, p=~a\n" chosen others b s p) (cond ((and (zero? chosen) (zero? others)) s) ((or (= 1 chosen) (pow2? (+ chosen 2))) ;; Last one or zero at hand. (loop others 0 (+ s (* b p)) (- 1 b) (+ p p)) ) ((or (= 0 (modulo chosen 4)) (= 3 (modulo chosen 4))) ;; source run continues, dest changes. (loop others (floor->exact (/ chosen 2)) (+ s (* b p)) (- 1 b) (+ p p)) ) ((= 1 (modulo chosen 4)) ;; source run changes, from ones to zeros, skip past zeros. (loop (floor->exact (/ chosen (A006519 (- chosen 1)))) others (+ s (* b p)) b (+ p p) ) ) (else ;; (= 2 (modulo chosen 4)) ;; source run changes, from zeros to ones, skip past ones. (loop (floor->exact (/ chosen (A006519 (+ chosen 2)))) others (+ s (* b p)) b (+ p p) ) ) ) ) ) ) ;; (define A125975 (fun-succ-matching-is0 (lambda (i) (= i (A125974 (A125974 i)))))) (define A125975 (MATCHING-POS 0 0 (lambda (i) (= i (A125974 (A125974 i)))))) ;; A154103 --- A154104. ;; Gives 1, if y should come before x, 0 otherwise: (define (A154103bi x y) (cond ((and (zero? y) (not (zero? x))) 1) ((> (A085207bi (* 2 x) y) (A085207bi (* 2 y) x)) 1) (else 0) ) ) (define (A154103 n) (A154103bi (A002262 n) (A025581 n))) (define (A154104 n) (A154103bi (A025581 n) (A002262 n))) ;; Binary concatenation: (0 understood as an empty string). (define (A085207bi x y) (+ (* (expt 2 (A029837 (1+ y))) x) y)) (define (A085207 n) (A085207bi (A025581 n) (A002262 n))) (define (A085208 n) (A085207bi (A002262 n) (A025581 n))) (define (A085209 n) (A007088 (A085207 n))) (define (A085210 n) (A007088 (A085208 n))) ;; Strange binary concatenation: (define (A085211bi x y) (cond ((zero? x) (A085207bi x y)) (else (* (+ (* (expt 2 (A029837 (1+ y))) (A000265 x)) y) (A006519 x))) ) ) (define (A085211 n) (A085211bi (A025581 n) (A002262 n))) (define (A085212 n) (A085211bi (A002262 n) (A025581 n))) (define (A085213 n) (A007088 (A085211 n))) (define (A085214 n) (A007088 (A085212 n))) ;; Factorial expansion concatenation: (0 understood as an empty string). ;; ! is cached, so it's not so foolish as it looks like: (define (A085215bi x y) (let loop ((x x) (y y) (i 2) (j (1+ (A084558 y)))) (cond ((zero? x) y) (else (loop (floor->exact (/ x i)) (+ (* (! j) (modulo x i)) y) (1+ i) (1+ j))) ) ) ) (define (A085215 n) (A085215bi (A025581 n) (A002262 n))) (define (A085216 n) (A085215bi (A002262 n) (A025581 n))) (define (A085217 n) (A007623 (A085216 n))) (define (A085218 n) (A007623 (A085217 n))) ;; Rised factorial expansion concatenation: (0 understood as an empty string). ;; To the each digit of x we add 'r', the first digit of y. ;; (to get a more or less continuous "staircase"). (define (A085219bi x y) (let loop ((x x) (y y) (i 2) (j (1+ (A084558 y))) (r (car (n->factbase y)))) (cond ((zero? x) y) (else (loop (floor->exact (/ x i)) (+ (* (! j) (+ r (modulo x i))) y) (1+ i) (1+ j) r ) ) ) ) ) (define (A085219 n) (A085219bi (A025581 n) (A002262 n))) (define (A085220 n) (A085219bi (A002262 n) (A025581 n))) (define (A085221 n) (A007623 (A085219 n))) (define (A085222 n) (A007623 (A085220 n))) ;; I bet this is the correct formula: ;; Maple: A002542 := n -> 2^((2^n)-1)*((2^((2^n)-1))-1); (define (A002542 n) (* (expt 2 (-1+ (expt 2 n))) (-1+ (expt 2 (-1+ (expt 2 n)))) ) ) ;; ID Number: A002542 (Formerly M2174 and N0869) ;; Sequence: 0,2,56,16256,1073709056,4611686016279904256, ;; 85070591730234615856620279821087277056 ;; Name: Complete Post functions of n variables. ;; References Wheeler, Roger F.; Complete connectives for the $3$-valued ;; propositional calculus. Proc. London Math. Soc. (3) 16 1966 167-191. ;; See also: Cf. A002543. ;; Keywords: nonn ;; Offset: 1 ;; Author(s): njas (definec (A080303 n) ;; rewrite 1->1, 0->100 in the binary expansion. (cond ((zero? n) 4) ((= n 1) n) ((odd? n) (1+ (* 2 (A080303 (/ (-1+ n) 2))))) (else (+ 4 (* 8 (A080303 (/ n 2))))) ) ) (define (A080310 n) (/ (A080303 (* 2 n)) 2)) (definec (A126308 n) ;; rewrite 10->'' in the binary expansion. Cf. A080303. (cond ((zero? n) 0) ((= 2 (modulo n 4)) (A126308 (/ (- n 2) 4))) (else (+ (modulo n 2) (* 2 (A126308 (floor->exact (/ n 2)))))) ) ) (define (A079946 n) (* 2 (+ (A000079 (1+ (A000523 n))) n))) ;; A079446 := n -> 2*(2^(1+A000523(n))+n); ;; A079446v2 := n -> `if`(0=n,2,2^A000523(4*n)+2*n); (define (A079946v2 n) (if (zero? n) 2 (+ (A000079 (A000523 (* 4 n))) (* 2 n)))) (define (A007088 n) ;; 0,1,10,11,100,101,110,111,1000,... (Show binary form in decimal) (let loop ((z 0) (i 0) (n n)) (if (zero? n) z (loop (+ z (* (expt 10 i) (modulo n 2))) (1+ i) (floor->exact (/ n 2)) ) ) ) ) ;; (Show ternary form in decimal) (define (A007089 n) ;; 0,1,2,10,11,12,20,21,22,100,101,102,... (let loop ((z 0) (i 0) (n n)) (if (zero? n) z (loop (+ z (* (expt 10 i) (modulo n 3))) (1+ i) (floor->exact (/ n 3)) ) ) ) ) ;; Tersum n + n: (definec (A004488 n) ;; 0,2,1,6,8,7,3,5,4,18,20,19,24,26,25,21,23 (let loop ((z 0) (i 0) (n n)) (if (zero? n) z (loop (+ z (* (expt 3 i) (modulo (- (modulo n 3)) 3))) (1+ i) (floor->exact (/ n 3)) ) ) ) ) (define (A007090 n) ;; 0,1,2,3,10,10,11,12,13,20,... (Show quaternary form in decimal) (let loop ((z 0) (i 0) (n n)) (if (zero? n) z (loop (+ z (* (expt 10 i) (modulo n 4))) (1+ i) (floor->exact (/ n 4)) ) ) ) ) ;; E.g. (A000695 n) = (expand-n-x-fold n 2) (define (expand-n-x-fold n x) ;; Expand bits of n, by scale 2^x. (if (zero? n) n (+ (modulo n 2) (* (expt 2 x) (expand-n-x-fold (floor->exact (/ n 2)) x)) ) ) ) (define (A000302 n) (expt 4 n)) (define (A002001 n) (if (zero? n) 1 (* 3 (A000302 (-1+ n))))) ;; A002001 = 1,3,12,48,192,768,3072,12288,49152,196608,786432,3145728, ;; a(n) = 3*4^(n-1), n>0; a(0)=1. (define (A080116 c) ;; Characteristic function of A014486 (let loop ((c c) (lev 0)) (cond ((zero? c) (if (zero? lev) 1 0)) ((< lev 0) 0) (else (loop (floor->exact (/ c 2)) (+ lev (- 1 (* 2 (modulo c 2))))) ) ) ) ) (define (store-n-to-bits-given-by-column-x-of-table n x NxN->N) (let loop ((n n) (i 0) (s 0)) (if (zero? n) s (loop (floor->exact (/ n 2)) (1+ i) (+ s (* (modulo n 2) (expt 2 (NxN->N x i)))) ) ) ) ) ;; The checking of upper-limit is very naive, and to work it requires ;; that all columns of the map NxN->N are monotone (growing). (define (fetch-from-bits-of-n-given-by-column-x-of-table n x NxN->N) (let ((upper-limit (A000523 n))) (let loop ((i 0) (s 0) (bitpos (NxN->N x 0))) (if (> bitpos upper-limit) s (loop (1+ i) (+ s (* (bit-i n bitpos) (expt 2 i))) (NxN->N x (1+ i)) ) ) ) ) ) ;; ;; Moser-de Bruijn sequence: 0,1,4,5,16,17,20,21,64,65,68,69,80,... ;; (definec (A000695 n) ;; Expand bits, 0->00, 1->01, i.e. from base-2 to base-4. ;; (if (zero? n) ;; n ;; (+ (modulo n 2) (fix:lsh (A000695 (fix:lsh n -1)) 2)) ;; ) ;; ) ;; ;; (definec (A059905 n) ;; Take the even-positioned bits and contract them. ;; (if (zero? n) ;; n ;; (+ (modulo n 2) (fix:lsh (A059905 (fix:lsh n -2)) 1)) ;; ) ;; ) ;; ;; Moser-de Bruijn sequence: 0,1,4,5,16,17,20,21,64,65,68,69,80,... (define (A000695 n) ;; Expand bits, 0->00, 1->01, i.e. from base-2 to base-4. (if (zero? n) n (+ (modulo n 2) (* 4 (A000695 (floor->exact (/ n 2))))) ) ) (define (A059905 n) ;; Take the even-positioned bits and contract them. (if (zero? n) n (+ (modulo n 2) (* 2 (A059905 (floor->exact (/ n 4))))) ) ) (definec (A000695c n) (A000695 n)) ;; The cached variant. Be careful with this! (definec (A059905c n) (A055905 n)) ;; The cached variant. Be careful with this! (define (A059906 n) (A059905 (floor->exact (/ n 2)))) ;; Take the odd bits and contract (define (A059906*2 n) (* 2 (A059906 n))) ;; a(0) = 0, a(1) = 1, a(2k) = 3*a(k), a(2k+1) = 2*a(k) + a(k+1). (definec (A006046 n) (cond ((< n 2) n) ((even? n) (* 3 (A006046 (/ n 2)))) (else (+ (* 2 (A006046 (/ (- n 1) 2))) (A006046 (/ (+ n 1) 2)) ) ) ) ) (define (A080978 n) (1+ (* 2 (A006046 n)))) (define (A006519 n) ;; Highest power of 2 dividing n: 1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16 (cond ((zero? n) 0) (else (let loop ((n n) (i 1)) (cond ((odd? n) i) (else (loop (floor->exact (/ n 2)) (* i 2))) ) ) ) ) ) ;; Note that (A007814 33574912) = 12. (define (A007814 n) ;; Exponent of the A006519. (cond ((zero? n) 0) (else (let loop ((n n) (i 0)) (cond ((odd? n) i) ;; (else (loop (fix:lsh n -1) (1+ i))) ;; Dangerous code. (else (loop (floor->exact (/ n 2)) (1+ i))) ) ) ) ) ) (define (A000265 n) (/ n (A006519 n))) ;; Remove 2s from n; or largest odd divisor of n. ;; One-based: (define (A018900 n) (+ (expt 2 (A002024 n)) (expt 2 (A002262 (-1+ n))))) (definec (A036987 n) (if (eq? (1+ n) (A006519 (1+ n))) 1 0)) (define A073268shifted_once_left (CONVOLVE 0 A000108 A036987)) ;; (map A073268shifted_once_left (iota0 25)) ;; --> (1 2 3 8 20 58 179 576 1902 6426 22092 77026 271702 967840 3476555 12578728 45800278 167693698 617037126 2280467586 8461771342 31510700712 117725789124 441141656810 1657559677646 6243810767912) (define (A073265bi n k) (cond ((zero? n) n) ((zero? k) k) ((> k n) 0) ((eq? 1 k) (if (eq? n (A006519 n)) 1 0)) (else (let sumloop ((i (A000523 (-1+ n))) (s 0)) (cond ((negative? i) s) (else (sumloop (-1+ i) (+ s (A073265bi (- n (fix:lsh 1 i)) (-1+ k))) ) ) ) ) ) ) ) ;; (define seqA003319 (list 1 1 3 13 71 461 3447 29093 273343 2829325 31998903 392743957 5201061455 73943424413 1123596277863 18176728317413 311951144828863 5661698774848621 108355864447215063 2181096921557783605 ) ) (define A000142test (INVERT (lambda (n) (list-ref seqA003319 (-1+ n))))) (define A051296shifted_left (INVERT A000142)) (define A051295shifted_left (INVERT (compose-funs A000142 -1+))) ;; (define A061922 (EIGEN-CONVOLUTION 1 A048720bi)) (define A007460 (EIGEN-CONVOLUTION 1 A003986bi)) ;; OR-convolution with itself. (define A007461 (EIGEN-CONVOLUTION 1 A004198bi)) ;; AND-convolution with itself. (define A007462 (EIGEN-CONVOLUTION '(0 1) A003987bi)) ;; XOR-convolution with itself. (define A007463 (EIGEN-CONVOLUTION 1 lcm)) ;; LCM-convolution with itself. (define A007464 (EIGEN-CONVOLUTION 1 gcd)) ;; GCD-convolution with itself. (define A025192 (EIGEN-CONVOLUTION 1 +)) (define A090826 (CONVOLVE 0 A000045 A000108)) (define A090826_shifted_left_check (CONVOLVE 0 (compose-funs A000045 1+) A000108)) ;; A073265 - A073270 reserved for us. (define (A073265 n) (A073265bi (1+ (A025581 n)) (1+ (A002262 n)))) (define (A073266 n) (A073265bi (1+ (A003056 n)) (1+ (A002262 n)))) (define (A073267 n) (A073265bi n 2)) ;; Occurs also as the FIX-counts of form 105. 6o6 ;; (A073265bi n 1) ;; gives the characteristic function of A000079, ;; i.e. A036987 with offset 1 instead of 0, and a(0) = 0. ;; A073265(6,1) = 0 ;; A073265(6,2) = 2 4+2, 2+4 -> 3+(1)+1, 1+(1)+3 ;; A073265(6,3) = 4 2+2+2, 4+1+1, 1+4+1, 1+1+4 -> 1+(1)+1+(1)+1, 3+(1)+0+(1)+0, etc. ;; A073265(6,4) = 6 2+2+1+1, 2+1+2+1, 2+1+1+2, 1+2+1+2, 1+2+2+1, 1+1+2+2 ;; A073265(6,5) = 5 2+1+1+1+1 * 5 --> 1+(1)+0+(1)+0+(1)+0+(1)+0 ;; A073265(6,6) = 1 1+1+1+1+1+1 --> 0+(1)+0+(1)+0+(1)+0+(1)+0+(1)+0 (define (A073268 n) ;; The fix sequence for form 41, SwapBinTree o SwapDownCar (0 o 6) (if (zero? n) 1 (let sumloop ((i (floor->exact (/ (log n) (log 2)))) (s 0)) (cond ((negative? i) s) (else (sumloop (-1+ i) (+ s (A000108 (- n (expt 2 i)))))) ) ) ) ) (define (A073345bi n k) (cond ((zero? n) (if (zero? k) 1 0)) ((zero? k) k) ((> k n) 0) (else (let ((half-n (fix:lsh (-1+ n) -1)) (k-1 (-1+ k)) ) (+ (* 2 (add (lambda (i) (* (A073345bi (- (-1+ n) i) k-1) (add (lambda (j) (A073345bi i j)) 0 k-1 ) ) ) 0 half-n ) ) (* 2 (add (lambda (i) (* (A073345bi (- (-1+ n) i) k-1) (add (lambda (j) (A073345bi i j)) 0 (- k 2) ) ) ) (1+ half-n) (-1+ n) ) ) (if (odd? n) (* -1 (expt (A073345bi half-n k-1) 2)) 0) ) ;; + ) ;; let ) ;; else ) ;; cond ) (define (A073346bi n k) (cond ((zero? k) (A036987 n)) ((zero? n) 0) ((> k n) 0) (else (let ((half-n (fix:lsh (-1+ n) -1)) (k-1 (-1+ k)) ) (+ (* 2 (add (lambda (i) (* (A073346bi (- (-1+ n) i) k-1) (add (lambda (j) (A073346bi i j)) 0 k-1 ) ) ) 0 half-n ) ) (* 2 (add (lambda (i) (* (A073346bi (- (-1+ n) i) k-1) (add (lambda (j) (A073346bi i j)) 0 (- k 2) ) ) ) (1+ half-n) (-1+ n) ) ) (if (odd? n) (* -1 (expt (A073346bi half-n k-1) 2)) 0) (if (= 1 k) (* -1 (A036987 n)) 0) ) ;; + ) ;; let ) ;; else ) ;; cond ) (define (A073345 n) (A073345bi (A025581 n) (A002262 n))) (define (A073346 n) (A073346bi (A025581 n) (A002262 n))) (define (A073429 n) (A073345bi (A003056 n) (A002262 n))) (define (A073430 n) (A073346bi (A003056 n) (A002262 n))) (define (A073431 n) (cond ((zero? n) 1) (else (/ (add (lambda (i) (add (lambda (j) (A073346bi n j)) 0 (A007814 i))) 1 (expt 2 (-1+ n)) ) (expt 2 (-1+ n)) ) ) ) ) ;; For some reason this seems to produce the same answers: ;; (Some peculiar interaction of A007814 & A073346 ?) (define (A073431v2 n) (cond ((zero? n) 1) (else (-1+ (/ (add (lambda (i) (A073346bi n (A007814 i))) 1 (expt 2 (-1+ n)) ) (expt 2 (- n 2)) ) ) ) ) ) (definec (A048678 n) ;; Rewrite to Zeckendorf-expansion: 0->0, 1->01 (cond ((zero? n) n) ((even? n) (* 2 (A048678 (floor->exact (/ n 2))))) (else (1+ (* 4 (A048678 (floor->exact (/ n 2)))))) ) ) (define (A022290 n) ;; I.e. interpret_as_zeckendorf_expansion (let loop ((n n) (s 0) (i 2)) (cond ((zero? n) s) (else (loop (floor->exact (/ n 2)) (+ s (* (modulo n 2) (fibo i))) (1+ i) ) ) ) ) ) (define (A072648 n) ;; An approximate "inverse" of A000045 (of the fibonacci numbers) (cond ((zero? n) n) (else (floor->exact (/ (log (* n *Sqrt5*)) *LogPhi*))) ) ) ;; 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F, ,21 ;; 1,2,3,3,4,4,4,5,5,5,5,5,6,6,6,6,6,6,6,6,7,... (define (A072649 n) ;; n occurs fibo(n) times. (let ((b (A072648 n))) (+ -1 b (floor->exact (/ n (fibo (1+ b))))) ) ) (define (A072650 n) ;; rewrite_0to0_x1to1 (let loop ((n n) (s 0) (i 0)) (cond ((zero? n) s) ((even? n) (loop (floor->exact (/ n 2)) s (1+ i))) (else (loop (floor->exact (/ n 4)) (+ s (expt 2 i)) (1+ i))) ) ) ) (definec (A003714c n) ;; The cached variant. (cond ((< n 3) n) (else (+ (expt 2 (-1+ (A072649 n))) (A003714c (- n (fibo (1+ (A072649 n))))) ) ) ) ) (define (A003714 n) ;; Iterative (tail-recursive) variant, not cached. (let loop ((n n) (s 0)) (cond ((< n 3) (+ s n)) (else (loop (- n (fibo (1+ (A072649 n)))) (+ s (expt 2 (-1+ (A072649 n)))) ) ) ) ) ) (define (A048679 n) (A072650 (A003714 n))) (define (A048680 n) (A022290 (A048678 n))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Some edits of Ctibor O. Zizka's sequences. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here are the 10 A-numbers you requested: A166012 --- A166021. (definec (A133923 n) (cond ((< n 2) n) ((even? (A133923 (-1+ n))) (/ (A133923 (-1+ n)) 2)) (else (A000005 (* n (A133923 (-1+ n))))) ) ) ;; Auxiliary sequence for A138606: (definec (A166012 n) (+ 1 (modulo n 2) (* 2 (- (A000045 n) (modulo n 2))))) ;; Note: A138606(n) = A072649(n) modulo 2. (defineperm1 (A138606 n) (if (zero? n) n (+ (A166012 (-1+ (A072649 n))) (* 2 (- n (A000045 (1+ (A072649 n)))))) ) ) (define (A166013 n) (A138606 (- n))) (defineperm1 (A138607 n) (if (< n 3) n (let ((k (A083375 (- n 2)))) (if (= (- n 2) (A007504 k)) (+ 2 (A138607 (- n 1 (A000040 k)))) (+ 2 (A138607 (-1+ n))) ) ) ) ) (define (A166014 n) (A138607 (- n))) (defineperm1 (A138608 n) (if (< n 4) n (let ((k (A072649 n))) (if (= n (A000045 (1+ k))) (+ 3 (A138608 (- n 1 (A000045 k)))) (+ 3 (A138608 (-1+ n))) ) ) ) ) (define (A166015 n) (A138608 (- n))) (defineperm1 (A074147 n) ;; (2n-1) odd numbers followed by 2n even numbers. (if (zero? n) n (+ (A061925 (-1+ (A002024 n))) (* 2 (A002262 (-1+ n)))) ) ) ;; a(n) = n + {1,2,0,1} according as n == {0,1,2,3} mod 4. (define (A116966 n) (+ n (list-ref '(1 2 0 1) (modulo n 4)))) (defineperm1 (A138609 n) (if (zero? n) n (A116966 (-1+ (A074147 n))))) (define (A166016 n) (A138609 (- n))) ;; Must be computed term-by-term before its inverse A166017 ! (defineperm1 (A138612 n) (if (< n 3) n (let loop ((k (if (zero? (A002262 (-1+ n))) 1 (A138612 (-1+ n)))) (i 1) ) (cond ((not-lte? (A166017 i) (-1+ n)) (if (= 1 k) i (loop (-1+ k) (1+ i))) ) (else (loop k (1+ i))) ) ) ) ) (define (A166017 n) (A138612 (- n))) (define (A166018 n) (A138612 (A000124 (-1+ n)))) ;; Leading edge (define (A166019 n) (A138612 (A000217 n))) ;; Trailing edge. (define A166020 (ROWSUMS1 A138612)) ;; tabl (definec (A166021 n) (if (zero? (A002262 (-1+ n))) (* 2 (A000124 (A003056 (-1+ n)))) (1+ (A166021 (-1+ n)))) ) (define A136272 (COMPLEMENT 1 A166021)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (A000217 n) (/ (* n (+ n 1)) 2)) (define (A000124 n) (1+ (A000217 n))) (define (A000290 n) (* n n)) (define (A061925 n) (1+ (ceiling->exact (/ (A000290 n) 2)))) ; Ceiling[n^2/2]+1 (define (A046092 n) (* 2 n (1+ n))) ;; This gives the central diagonal from zero-indexed arrays/tables. ;; (map A025581 (cons 0 (iota 20))) --> (0 1 0 2 1 0 3 2 1 0 4 3 2 1 0 5 4 3 2 1 0) ;; (definec (A025581 n) ;; The X component (column) of square {0..inf} arrays ;; (- (binomial_n_2 (1+ (floor->exact (+ (/ 1 2) (sqrt (* 2 (1+ n))))))) (1+ n)) ;; ) ;; ;; ;; (map A002262 (cons 0 (iota 20))) --> (0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5) ;; (definec (A002262 n) ;; The Y component (row) of square {0..inf} arrays ;; (- n (binomial_n_2 (floor->exact (+ (/ 1 2) (sqrt (* 2 (1+ n))))))) ;; ) ;; At some point these will produce incorrect values, because of the ;; limited precision of IEEE 64-bit floating point numbers. ;; What is that point, and how to recode these with strictly fixnum-only ;; way? (I need a fixnum-only square root algorithm...) (definec (A025581 n) ;; The X component (column) of square {0..inf} arrays (- (binomial_n_2 (1+ (floor->exact (flo:+ 0.5 (flo:sqrt (exact->inexact (* 2 (1+ n)))))))) (1+ n)) ) ;; (map A002262 (cons 0 (iota 20))) --> (0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5) (definec (A002262 n) ;; The Y component (row) of square {0..inf} arrays (- n (binomial_n_2 (floor->exact (flo:+ 0.5 (flo:sqrt (exact->inexact (* 2 (1+ n)))))))) ) (define (A002024 n) ;; repeat n n times, starting from n = 1. (floor->exact (+ (/ 1 2) (sqrt (* 2 n)))) ) (define (A003056 n) ;; repeat n n+1 times, starting from n = 0. (floor->exact (- (sqrt (* 2 (1+ n))) (/ 1 2))) ) (define (square? n) (= n ((lambda (r) (* r r)) (floor->exact (sqrt n))))) (define (A001477 n) n) (define (A001489 n) (- n)) (define (A023443 n) (- n 1)) (define (A020725 n) (+ n 1)) ;; Actually "Integers >= 2.", with offset=1. (define (packA001477 x y) (/ (+ (expt (+ x y) 2) x (* 3 y)) 2)) (define (packA061579 x y) (/ (+ (expt (+ x y) 2) (* 3 x) y) 2)) (define A001477bi packA001477) ;; I.e. (define (id n) (packA001477 (A025581 n) (A002262 n))) ;; and (define (A061579 n) (packA061579 (A025581 n) (A002262 n))) (define (A038722 n) (if (zero? n) n (1+ (A061579 (-1+ n))))) ;; Gives id (A001477): (+ (A000695 (A059905 n)) (* 2 (A000695 (A059906 n)))) (define (A057300 n) (+ (A000695 (A059906 n)) (* 2 (A000695 (A059905 n))))) (define (A054238 n) (+ (A000695 (A025581 n)) (* 2 (A000695 (A002262 n))))) (define (A054239 n) (packA001477 (A059905 n) (A059906 n))) ;; Here are the 10 A-numbers you requested: A163233 --- A163242. (define (A163233bi x y) (+ (A000695 (A003188 x)) (* 2 (A000695 (A003188 y))))) (define (A163233 n) (A163233bi (A025581 n) (A002262 n))) ;; Inverse: (define (A163234 n) (packA001477 (A006068 (A059905 n)) (A006068 (A059906 n)))) ;; Transpose of A163233: (define (A163235 n) (A163233bi (A002262 n) (A025581 n))) ;; Inverse: (define (A163236 n) (packA001477 (A006068 (A059906 n)) (A006068 (A059905 n)))) (define (A163237 n) (A163241 (A163233 n))) (define (A163238 n) (A163234 (A163241 n))) (define (A163239 n) (A163241 (A163235 n))) (define (A163240 n) (A163236 (A163241 n))) (define (A163241 n) (+ (A000695 (A003987bi (A059905 n) (A059906 n))) (* 2 (A000695 (A059906 n))))) (define A163242 (ROWSUMS0 A163233)) ;; (0 3 18 30 90 153 204 252 492 735 990 1242 1446 1653 1848 2040 3000 3963 4938 5910 6930 7953 8964 9972 10788 11607 12438 13266 14046 14829 15600 16368 20208 24051 27906 31758 35658 39561 43452 47340 51420 55503 59598) ;; lsbs = Least Significant Trigits (define (complement-i-lsbs n i) (if (zero? i) n (+ (- 1 (modulo n 2)) (* 2 (complement-i-lsbs (floor->exact (/ n 2)) (-1+ i))) ) ) ) (define (complement-i-evenpos-lsbs n i) (if (zero? i) n (+ (- 1 (modulo n 2)) (* 2 (complement-i-oddpos-lsbs (floor->exact (/ n 2)) (-1+ i))) ) ) ) (define (complement-i-oddpos-lsbs n i) (+ (* 2 (complement-i-evenpos-lsbs (floor->exact (/ n 2)) i)) (modulo n 2) ) ) ;; Base 3 -> Base 9 conversion: (define (A037314 n) (if (< n 3) n (+ (modulo n 3) (* 9 (A037314 (floor->exact (/ n 3))))) ) ) ;; lsts = Least Significant Trigits (define (complement-i-lsts n i) (if (zero? i) n (+ (- 2 (modulo n 3)) (* 3 (complement-i-lsts (floor->exact (/ n 3)) (-1+ i))) ) ) ) (define (complement-i-evenpos-lsts n i) (if (zero? i) n (+ (- 2 (modulo n 3)) (* 3 (complement-i-oddpos-lsts (floor->exact (/ n 3)) (-1+ i))) ) ) ) (define (complement-i-oddpos-lsts n i) (+ (* 3 (complement-i-evenpos-lsts (floor->exact (/ n 3)) i)) (modulo n 3) ) ) ;; Here are the 20 A-numbers you requested: A163325 --- A163344. ;; Cf. A059905 (define (A163325 n) ;; Take the even-positioned trigits and contract them. (if (zero? n) n (+ (modulo n 3) (* 3 (A163325 (floor->exact (/ n 9))))) ) ) ;; Take the odd trigits and contract. Cf. A059906 (define (A163326 n) (A163325 (floor->exact (/ n 3)))) ;; Gives id (define (id n) (+ (A037314 (A163325 n)) (* 3 (A037314 (A163326 n))))) (define (A163327 n) (+ (A037314 (A163326 n)) (* 3 (A037314 (A163325 n))))) ;; Cf. A057300 (define (A163328 n) (+ (A037314 (A025581 n)) (* 3 (A037314 (A002262 n))))) ;; Cf. A054238 (define (A163329 n) (packA001477 (A163325 n) (A163326 n))) ;; Cf. A054239 ;; Transposes of above: (define (A163330 n) (+ (A037314 (A002262 n)) (* 3 (A037314 (A025581 n))))) (define (A163331 n) (packA001477 (A163326 n) (A163325 n))) (define (A163332 n) (let loop ((z 0) (n n) (i 0) ) (let ((x (modulo n 3)) (y (modulo (floor->exact (/ n 3)) 3)) ) (cond ((zero? n) z) ((and (= 1 x) (= 1 y)) ;; Central square, rotate everything 180 (loop (+ (* 4 (expt 3 i)) (complement-i-lsts z i)) (floor->exact (/ n 9)) (+ i 2) ) ) ((= 1 x) ;; either 01 or 21, complement odd-positioned trigits (loop (+ (* (+ (* y 3) 1) (expt 3 i)) (complement-i-oddpos-lsts z (/ i 2)) ) (floor->exact (/ n 9)) (+ i 2) ) ) ((= 1 y) ;; either 10 or 12, complement even-positioned trigits (loop (+ (* (+ 3 (- 2 x)) (expt 3 i)) ;; also x ! (complement-i-evenpos-lsts z (/ i 2)) ) (floor->exact (/ n 9)) (+ i 2) ) ) (else (loop (+ (* (+ (* y 3) x) (expt 3 i)) z) (floor->exact (/ n 9)) (+ i 2) ) ) ) ) ) ) ;; "Transposed", i.e. A163327-conjugate: (define (A163333 n) (A163327 (A163332 (A163327 n)))) ;; Hilbert II curve in a square array, zero-based (define (A163334 n) (A163332 (A163328 n))) ;; Inverse: (define (A163335 n) (A163329 (A163332 n))) ;; (map (lambda (n) (+ (abs (- (A025581 (A163358 (1+ n))) (A025581 (A163358 n)))) ;; (abs (- (A002262 (A163358 (1+ n))) (A002262 (A163358 n)))))) ;; (iota0 63)) ;; (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) ;; (map (lambda (n) (+ (abs (- (A025581 (A163335 (1+ n))) (A025581 (A163335 n)))) ;; (abs (- (A002262 (A163335 (1+ n))) (A002262 (A163335 n)))))) ;; (same-intfuns? A000012 (lambda (n) (+ (abs (- (A025581 (A163335 (1+ n))) (A025581 (A163335 n)))) ;; (abs (- (A002262 (A163335 (1+ n))) (A002262 (A163335 n)))))) ;; (expt 2 20)) ;; Hilbert II curve in a square array, zero-based, transposed (define (A163336 n) (A163332 (A163330 n))) (define (A163336v2 n) (A163327 (A163333 (A163328 n)))) (define (A163336v3 n) (A163334 (A061579 n))) ;; Inverse: (define (A163337 n) (A163331 (A163332 n))) (define (A163337v2 n) (A061579 (A163335 n))) ;; Hilbert II curve, one-based: (define (A163338 n) (+ 1 (A163334 (-1+ n)))) ;; Inverse: (define (A163339 n) (+ 1 (A163335 (-1+ n)))) ;; Hilbert II curve transposed, one-based: (define (A163340 n) (+ 1 (A163336 (-1+ n)))) ;; Inverse A163341: (define (A163341 n) (+ 1 (A163337 (-1+ n)))) (define A163342 (ROWSUMS0 A163334)) (define (A163343 n) (A163334 (A046092 n))) (define (A163343v2 n) (A163336 (A046092 n))) (define (A163344 n) (/ (A163343 n) 4)) ;; Here are the 11 A-numbers you requested: A163355 --- A163365. (definec (A163355 n) (let* ((i (floor->exact (/ (A000523 n) 2))) (dd (modulo (floor->exact (/ n (expt 4 i))) 4)) (r (if (zero? n) n (modulo n (expt 4 i)))) ) (cond ((zero? n) n) ;; ((= 0 dd) ;; 00xy --> 00xy ;; (format #t "I should not be here! Never executed!\n") ;; (A163355 r) ;; ) ((= (+ 1 (modulo i 2)) dd) ;; 01xy --> 01yx or 10xy --> 01yx (+ (expt 4 i) (A163355 (A057300 r))) ) ((= 3 dd) ;; 11xy --> 10yx (+ (* 2 (expt 4 i)) (A163355 (A057300 r))) ) (else ;; 10xy --> 11c(xy) or 01xy --> 11c(xy) (+ (* 3 (expt 4 i)) (A163355 (- (expt 4 i) 1 r)) ) ) ) ) ) (definec (A163356 n) (if (zero? n) n (let* ((i (floor->exact (/ (A000523 n) 2))) (d (modulo (floor->exact (/ n (expt 4 i))) 4)) (r (modulo n (expt 4 i))) ) (+ (* (-1+ (modulo (expt (+ 2 (modulo i 2)) d) 5)) (expt 4 i)) (cond ;; ((= 0 d) (A163356 r)) ;; Never encountered! ((= 3 d) (- (expt 4 i) 1 (A163356 r))) (else (A057300 (A163356 r))) ) ) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (A163355v2 n) ;; The older version. (let* ((i (A052928 (A000523 n))) (dd (modulo (floor->exact (/ n (expt 2 i))) 4)) (rest (if (zero? n) n (modulo n (expt 2 i)))) ) (cond ((zero? n) n) ((= 0 dd) ;; 00xy --> 00xy (A163355v2 rest) ) ((= 3 dd) ;; 11xy --> 10yx (+ (expt 2 (1+ i)) (A163355v2 (A057300 rest))) ) ((= (+ 1 (floor->exact (/ (modulo i 4) 2))) dd) ;; 01xy --> 01yx or 10xy --> 01yx (+ (expt 2 i) (A163355v2 (A057300 rest))) ) (else ;; 10xy --> 11c(xy) or 01xy --> 11c(xy) (+ (* 3 (expt 2 i)) (A163355v2 (- (expt 2 i) 1 rest)) ) ) ) ) ) ;; Older version: (define (A163356v2 n) (let loop ((z 0) (n n) (i 0) ) (let ((dd (modulo n 4))) (cond ((zero? n) z) ((= 0 dd) ;; 00xy --> 00xy (loop z (floor->exact (/ n 4)) (+ i 2) ) ) ((= 2 dd) ;; 10xy --> 11yx (loop (+ (* 3 (expt 2 i)) (A057300 z)) (floor->exact (/ n 4)) (+ i 2) ) ) ((= 1 dd) ;; 01xy --> 01yx or 01xy --> 10yx (loop (+ (expt 2 (+ i (floor->exact (/ (modulo i 4) 2)))) (A057300 z) ) (floor->exact (/ n 4)) (+ i 2) ) ) (else ;; 11xy --> 10c(xy) or 11xy --> 01c(xy) (loop (+ (expt 2 (+ i (- 1 (floor->exact (/ (modulo i 4) 2))))) (- (expt 2 i) z 1) ) (floor->exact (/ n 4)) (+ i 2) ) ) ) ) ) ) ;; From A000302(n) to A000302(n+1)-1, i.e. [1,3], [4,15], [16,63], [64,255], ;; i.e. A002001 = 1,3,12,48,192,768,3072,12288,49152,196608,786432,3145728, ;; a(n) = 3*4^(n-1), n>0; a(0)=1. (define (range-of-nth-quaternary-forest n) (if (zero? n) (cons n n) (cons (A000302 (-1+ n)) (+ (A000302 (-1+ n)) (-1+ (A002001 n)))) ) ) (define (indices-of-nth-quaternary-forest n) (if (zero? n) (list n) (map (lambda (x) (+ (A000302 (-1+ n)) x)) (iota0 (-1+ (A002001 n)))) ) ) ;; --- ;; ----------------------------------------------------------------- (define (partition-by-intpermAfun size intpermutation indfun) (let ((src_set (indfun size))) (let loop ((cur (car src_set)) (src src_set) (res (list (list)))) (cond ((null? src) (reverse! (map reverse! res))) ((member cur src) (loop (intpermutation cur) (delete! cur src) (cons (cons cur (car res)) (cdr res)) ) ) (else ;; Completed one whole cycle, let's begin the next one with the first ;; parenthesization we have left: (loop (car src) src (cons (list) res)) ) ) ; cond ) ; let loop ) ) (define (number-of-1-cycles cycles) (let ((fes 0)) (for-each (lambda (c) (if (and (pair? c) (not (pair? (cdr c)))) (set! fes (1+ fes))) ) cycles ) fes ) ) (define (num-of-ones cycles) (let ((fes 0)) (for-each (lambda (c) (if (= 1 c) (set! fes (1+ fes)))) cycles ) fes ) ) (define (fc-Afun Afun indfun) (lambda (n) (number-of-1-cycles (partition-by-intpermAfun n Afun indfun))) ) (define (cc-Afun Afun indfun) (lambda (n) (length (partition-by-intpermAfun n Afun indfun))) ) (define (mc-Afun Afun indfun) (lambda (n) (apply max (map length (partition-by-intpermAfun n Afun indfun)))) ) (define (lc-Afun Afun indfun) (lambda (n) (apply lcm (map length (partition-by-intpermAfun n Afun indfun)))) ) (define (compute-and-print-count-seqs Afun indfun outfile upto-n) (call-with-output-file outfile (lambda (outport) (let loop ((n 0) (ccs (list 1)) (fcs (list 1)) (mcs (list 1)) (lcs (list 1)) ) (format #t "n=~A: ccs=~A fcs=~A mcs=~A lcs=~A~%" n ccs fcs mcs lcs ) (format outport "n=~A: ccs=~A fcs=~A mcs=~A lcs=~A~%" n ccs fcs mcs lcs ) (flush-output outport) (cond ((< n upto-n) (let ((partlengths (map length (partition-by-intpermAfun (1+ n) Afun indfun)))) (loop (1+ n) (append ccs (list (length partlengths))) (append fcs (list (num-of-ones partlengths))) (append mcs (list (fold-left max 0 partlengths))) (append lcs (list (fold-left lcm 1 partlengths))) ) ) ) ) ) ) ) ) (define (compute-and-print-cycle-vectors-for-A163355 outfile upto-n) (compute-and-print-cycle-vectors A163355 indices-of-nth-quaternary-forest outfile upto-n ) ) (define (compute-and-print-cycle-vectors Afun indfun outfile upto-n) (call-with-output-file outfile (lambda (outport) (let loop ((n 0) (partlengths (list 1)) ) (let ((ccs (list (length partlengths))) (fcs (list (num-of-ones partlengths))) (mcs (list (fold-left max 0 partlengths))) (lcs (list (fold-left lcm 1 partlengths))) (cpairs (multiset->countpairs partlengths)) ) (format #t "n=~A: ccs=~A fcs=~A mcs=~A lcs=~A, cycles, times*sizes=~A~%" n ccs fcs mcs lcs cpairs ) (format outport "n=~A: ccs=~A fcs=~A mcs=~A lcs=~A, cycles, times*sizes=~A~%" n ccs fcs mcs lcs cpairs ) (flush-output outport) (cond ((< n upto-n) (loop (1+ n) (map length (partition-by-intpermAfun (1+ n) Afun indfun))) ) ) ) ) ) ) ) (define (compute-and-print-one-by-one Afun outfile start upto-n) (call-with-output-file outfile (lambda (outport) (let loop ((n start) (z (Afun start))) (format #t "n=~A: ~A~%" n z) (format outport "~A ~A~%" n z) (flush-output outport) (cond ((< n upto-n) (loop (1+ n) (Afun (1+ n))))) ) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here are the 30 A-numbers you requested: A163890 --- A163919. ;; orbit-size-of-n-under-A163355 (definec (A163890 n) (let loop ((i 1) (nn (A163355 n))) (cond ((= nn n) i) (else (loop (1+ i) (A163355 nn))) ) ) ) ;; Up to n=21 at least. (define A163891 (DISTINCT-POS 0 0 A163890)) ;; Might be a permutation of A003586 (A036561), or at least a subset of it: ;; (Where are for example 27 and 81 and 243?) ;; (define A163892 (DISTINCT-VALS 0 0 A163890)) (define (A163892 n) (A163890 (A163891 n))) ;; Let's use the cache of A163891. ;; (map A163892 (iota0 21)) ;; (1 2 6 3 4 8 12 18 9 16 32 24 108 36 48 54 72 64 96 192 216 324) ;; First differences of A163891, zero-based: (define (A163893 n) (- (A163891 (1+ n)) (A163891 n))) ;; First differing element between A001477 and A163355^n: ;; (0 if they do not differ). (definec (A163894 n) (if (zero? n) 0 (let loop ((i 1) (nth_power (compose-fun-to-nth-power A163355 n))) (cond ((not (= i (nth_power i))) i) (else (loop (1+ i) nth_power)) ) ) ) ) ;; At least up to n=8 or 12: (define A163895 (RECORD-POS 0 0 A163894)) ;; (define A163896 (RECORD-VALS 0 0 A163894)) (define (A163896 n) (A163894 (A163895 n))) ;; Let's use the same cache. (define (A163897 n) (- (A163531 n) (A163547 n))) ;; Table, distance of number n in A163357 from ;; its position in the basic grid A054238: ;; ;; (define (A054238 n) (+ (A000695 (A025581 n)) (* 2 (A000695 (A002262 n))))) ;; (define (A054239 n) (packA001477 (A059905 n) (A059906 n))) ;; Two tables (squares of distances): (define (A163898 n) (A163900 (A054238 n))) (define (A163899 n) (A163900 (A163357 n))) ;; Based on this function: (zeros occur at A163901). ;; Squared distance between n's location in A054238 grid and A163357 grid. (definec (A163900 n) (+ (A000290 (abs (- (A059906 n) (A059252 n)))) (A000290 (abs (- (A059905 n) (A059253 n)))) ) ) (define A163901 (MATCHING-POS 0 0 (lambda (i) (= i (A163355 i))))) (define A163902 (MATCHING-POS 0 0 (lambda (i) (and (not (= i (A163355 i))) (= i (A163355 (A163355 i))) ) ) ) ) (define A163903 (MATCHING-POS 0 0 (lambda (i) (and (not (= i (A163355 i))) (= i (A163355 (A163355 (A163355 i)))) ) ) ) ) ;; Table, cycle size of each n: ;; (1's occur at the same positions as the zeros of A163898 and A163899, i.e. A165403): (define (A163904 n) (A163890 (A054238 n))) (define (A163904v2 n) (A163890 (A163357 n))) ;; (define A165403 (MATCHING-POS 0 0 (lambda (i) (= 0 (A163898 i))))) ;; (define A165403v2 (MATCHING-POS 0 0 (lambda (i) (= 0 (A163899 i))))) (define A165403 (ZERO-POS 0 0 A163898)) (define A165403v2 (ZERO-POS 0 0 A163899)) (define A165403v3 (MATCHING-POS 0 0 (lambda (i) (= 1 (A163904 i))))) (define (A165404 n) (A025581 (A165403 n))) (define (A165406 n) (A007088 (A165404 n))) (define (A165406v2 n) (A007090 (A163901 n))) (define A163910 (cc-Afun A163355 indices-of-nth-quaternary-forest)) (define A163911 (mc-Afun A163355 indices-of-nth-quaternary-forest)) (define A163912 (lc-Afun A163355 indices-of-nth-quaternary-forest)) ;; (map A163913 (iota0 13)) ;; (0 0 6 3 30 27 162 171 885 987 4839 5502 26436 30216) (definec (A163913 n) (let ((rp (range-of-nth-quaternary-forest n))) (let loop ((s 0) (i (car rp))) (cond ((> i (cdr rp)) s) ((and (not (= (A163355 i) i)) (= (A163915 i) i)) (loop (1+ s) (1+ i)) ) (else (loop s (1+ i))) ) ) ) ) ;; (0 0 2 1 10 9 54 57 295 329 1613 1834 8812 10072) (define (A163914 n) (/ (A163913 n) 3)) ;; Also two bisections, up to n=6: (define (A163909 n) (A163914 (* 2 n))) (define (A163919 n) (A163914 (1+ (* 2 n)))) (define (A163905 n) (A163355 (A163355 n))) (define (A163906 n) (A163356 (A163356 n))) (define (A163907 n) (A163905 (A054238 n))) (define (A163908 n) (A054239 (A163906 n))) (define (A163915 n) (A163355 (A163355 (A163355 n)))) (define (A163916 n) (A163356 (A163356 (A163356 n)))) (define (A163917 n) (A163915 (A054238 n))) (define (A163918 n) (A054239 (A163916 n))) ;; Midpoint height of "Jacobi-bridge", computed for each odd integer ;; of the form 4n+3. (definec (A165601 n) (let ((w (A004767 n))) ;; w = 4n+3 (add (lambda (i) (jacobi-symbol i w)) 0 (/ (-1+ w) 2)) ) ) (define A165602 (ZERO-POS 0 0 A165601)) ;; Positions of zeros in A165601. ;; Numbers of the form 4n+3 for which Sum_{i=0..(2n+1)} J(i/4n+3) = 0. (define (A165603 n) (A004767 (A165602 n))) (define (A165604 n) (A165601 (* 3 n))) ;; 12n+3 (define (A165605 n) (A165601 (+ 1 (* 3 n)))) ;; 12n+7 (A017605) (define (A165606 n) (A165601 (+ 2 (* 3 n)))) ;; 12n+11 ;; The height at the 1/3 point at "Jacobi-bridge", ;; computed for each odd integer of the form 12n+7 (definec (A165460 n) (let ((w (A017605 n))) ;; w = 12n+7 (add (lambda (i) (jacobi-symbol i w)) 0 (/ (-1+ w) 3)) ) ) (define A165461 (ZERO-POS 0 0 A165460)) ;; Positions of zeros in A165460. (define (A165462 n) (/ (- (A165463 n) 3) 4)) ;; Subset of A165602 ? ;; Numbers of the form 12n+7 for which Sum_{i=0..(4n+2)} J(i/12n+7) = 0. (define (A165463 n) (A017605 (A165461 n))) ;; Subset of A165603 ? ;; Here are the 10 A-numbers you requested: A165460 --- A165469. ;; Squared distance between n's location in A163334 grid and A163357 grid. ;; (equivalently: between n's location in A163336 grid and A163359 grid.) (definec (A165464 n) (+ (A000290 (abs (- (A163529 n) (A059252 n)))) (A000290 (abs (- (A163528 n) (A059253 n)))) ) ) (define A165465 (ZERO-POS 0 0 A165464)) ;; Positions of zeros in A165464. (definec (A165466 n) (+ (A000290 (abs (- (A163529 n) (A059253 n)))) (A000290 (abs (- (A163528 n) (A059252 n)))) ) ) (define A165467 (ZERO-POS 0 0 A165466)) ;; Positions of zeros in A165466. (define A095274 (MATCHING-POS 1 0 (lambda (n) (let ((w (A004767 n)) ;; w = 4n+3 (hp (A005408 n)) ;; hp = 2n+1 = ((w-1)/2) ) (let loop ((i 1) (s 1)) ;; s = sum of the first i Jacobi-symbols in [1,i] (cond ((< s 0) #f) ((>= i hp) #t) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)))) ) ) ) ) ) ) (define (A095100 n) (A004767 (A095274 n))) (define A095272 (MATCHING-POS 1 0 (lambda (n) (let ((w (A004767 n)) ;; w = 4n+3 (hp (A005408 n)) ;; hp = 2n+1 = ((w-1)/2) ) (and (not (zero? (A010051 w))) (let loop ((i 1) (s 1)) ;; s = sum of the first i Jacobi-symbols in [1,i] (cond ((< s 0) #f) ((>= i hp) #t) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)))) ) ) ) ) ) ) ) (define (A095102 n) (A004767 (A095272 n))) ;; Subset of A095274. (define A165468 (MATCHING-POS 1 0 (lambda (n) (let ((w (A004767 n)) ;; w = 4n+3 (hp (A005408 n)) ;; hp = 2n+1 = ((w-1)/2) ) (let loop ((i 1) (s 1)) ;; s = sum of the first i Jacobi-symbols in [1,i] (cond ((<= s 0) #f) ((>= i hp) #t) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)))) ) ) ) ) ) ) ;; Subset of A095100. (define (A165469 n) (A004767 (A165468 n))) ;; Subset of A095272. (define index_fun_for_A165580 (MATCHING-POS 1 0 (lambda (n) (let ((w (A004767 n)) ;; w = 4n+3 (hp (A005408 n)) ;; hp = 2n+1 = ((w-1)/2) ) (and (not (zero? (A010051 w))) (let loop ((i 1) (s 1)) ;; s = sum of the first i Jacobi-symbols in [1,i] (cond ((<= s 0) #f) ((>= i hp) #t) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)))) ) ) ) ) ) ) ) ;; Subset of A165468 and A095102. (define (A165580 n) (A004767 (index_fun_for_A165580 n))) ;; Difference A095274 \ A165468: ;; (Those n, for which Jacobi-bridge of 4n+3 visits sea level, but doesn't dive) (define A165607 (MATCHING-POS 1 0 (lambda (n) (let ((w (A004767 n)) ;; w = 4n+3 (hp (A005408 n)) ;; hp = 2n+1 = ((w-1)/2) ) ;; s = sum of the first i Jacobi-symbols in [1,i] (let loop ((i 1) (s 1) (zv 0)) ;; zv = # of sea level visits. (cond ((< s 0) #f) ;; Goes negative, fail. ((>= i hp) (not (zero? zv))) ((zero? s) (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) (1+ zv)) ) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) zv)) ) ) ) ) ) ) ;; A095100 \ A165469: (define (A165608 n) (A004767 (A165607 n))) (define index_fun_for_A165977 (MATCHING-POS 1 0 (lambda (n) (let ((w (A004767 n)) ;; w = 4n+3 (hp (A005408 n)) ;; hp = 2n+1 = ((w-1)/2) ) ;; s = sum of the first i Jacobi-symbols in [1,i] (and (not (zero? (A010051 w))) (let loop ((i 1) (s 1) (zv 0)) ;; zv = # of sea level visits. (cond ((< s 0) #f) ;; Goes negative, fail. ((>= i hp) (not (zero? zv))) ((zero? s) (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) (1+ zv)) ) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) zv)) ) ) ) ) ) ) ) ;; A095102 \ A165580: (define (A165977 n) (A004767 (index_fun_for_A165977 n))) ;; Here are the 20 A-numbers you requested: A166040 --- A166059. ;; Fixed points: A165465 (define (A166041 n) (A163357 (A163335 n))) (define (A166041v2 n) (A163359 (A163337 n))) (define (A166042 n) (A163334 (A163358 n))) (define (A166042v2 n) (A163336 (A163360 n))) ;; Fixed points: A165466 (define (A166043 n) (A163357 (A163337 n))) (define (A166043v2 n) (A163359 (A163335 n))) (define (A166044 n) (A163336 (A163358 n))) (define (A166044v2 n) (A163334 (A163360 n))) (define A166045 (RECORD-POS 0 0 A165601)) (define (A166046 n) (A004767 (A166045 n))) (define A166047 (RECORD-VALS 0 0 A165601)) ;; Cf. A112060, A112070 (definec (A166040 n) (let ((w (A005408 n))) ;; s = sum of the first i Jacobi-symbols in [1,i] (let loop ((i 1) (s 1) (zv 0)) ;; zv = # of sea level visits. (cond ((= i w) zv) ((zero? s) (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) (1+ zv)) ) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) zv)) ) ) ) ) (define A166048 (MATCHING-POS 1 0 (lambda (n) (let ((w (A016813 n)) ;; w = 4n+1 (hp (A005843 n)) ;; hp = 2n = ((w-1)/2) ) ;; s = sum of the first i Jacobi-symbols in [1,i] (let loop ((i 1) (s 1)) (cond ((< s 0) #f) ;; Goes negative, fail. ((>= i hp) #t) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)))) ) ) ) ) ) ) (define (A166049 n) (A016813 (A166048 n))) ;; Same without squares: (define index_for_A166051 (MATCHING-POS 1 0 (lambda (n) (let ((w (A016813c n)) ;; w = 4n+1 (hp (A005843 n)) ;; hp = 2n = ((w-1)/2) ) ;; s = sum of the first i Jacobi-symbols in [1,i] (let loop ((i 1) (s 1)) (cond ((< s 0) #f) ;; Goes negative, fail. ((>= i hp) (zero? s)) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)))) ) ) ) ) ) ) ;; A166049 without squares (is this finite? Cf. A080114). ;; At least 7 terms. (define (A166051 n) (A016813 (index_for_A166051 n))) ;; Here are the 20 A-numbers you requested: A166085 --- A166104. ;; Two bisections of A166040: (define (A166085 n) (A166040 (A005843 n))) ;; For searching among 4n+1 (define (A166086 n) (A166040 (A005408 n))) ;; and for amongst 4n+3 (define A046092v2 (MATCHING-POS 1 0 (lambda (i) (= 0 (A166040 i))))) (define (A016754v2 n) (A005408 (A046092v2 n))) ;; Odd squares. (define A165468v2 (MATCHING-POS 1 0 (lambda (i) (= 1 (A166086 i))))) (define (A165469v2 n) (A004767 (A165468v2 n))) ;; Yes. (define A166052 (MATCHING-POS 1 0 (lambda (i) (= 3 (A166086 i))))) (define (A166053 n) (A004767 (A166052 n))) (define A166054 (MATCHING-POS 1 0 (lambda (i) (= 5 (A166086 i))))) (define (A166055 n) (A004767 (A166054 n))) (define A166056 (MATCHING-POS 1 0 (lambda (i) (= 7 (A166086 i))))) (define (A166057 n) (A004767 (A166056 n))) (define A166058 (MATCHING-POS 1 0 (lambda (i) (= 9 (A166086 i))))) (define (A166059 n) (A004767 (A166058 n))) ;; At least 8 terms: (define index_for_A166088 (MATCHING-POS 1 0 (lambda (i) (= 8 (A166040 i))))) (define (A166088 n) (A005408 (index_for_A166088 n))) ;; First occurrence of n in A166040: Zero-based. (define A166087 (LEAST-I-WITH-FUN-I-EQ-N 0 0 A166040)) ;; Corresponding odd numbers: Zero-based. (define (A166089 n) (A005408 (A166087 n))) (define (A166091bi n k) (let ((m (A005408 k))) (let loop ((i 0) (n n)) (cond ((= m (A166086 i)) (if (zero? n) i (loop (1+ i) (-1+ n)) ) ) (else (loop (1+ i) n)) ) ) ) ) (definec (A166091 n) (A166091bi (A025581 n) (A002262 n))) (define (A166092 n) (A004767 (A166091 n))) ;; Corresponding 4k+3 integers. ;; ;; First 5 rows: A165469, A166053, A166055, A166057, A166059 (define A166093 (compose-funs (LEAST-I-WITH-FUN-I-EQ-N 0 0 A166085) A005843)) (define A166094 (compose-funs (LEAST-I-WITH-FUN-I-EQ-N 0 0 A166086) A005408)) ;; First column of A166091. (define (A166090 n) (A016813 (A166093 n))) ;; Two bisections of A166089: (define (A166095 n) (A166089 (A005843 n))) (define (A166096 n) (A166089 (A005408 n))) ;; First column of A166092. ;; NOT!: A166095 = A016813 A166093 (instead, we have A166090.) ;; A166096 = A004767 A166094 (define A166097 (DISTINCT-POS 0 0 A166040)) (defineperm1 (A166098 n) (A166040 (A166097 n))) (define A166098v2 (DISTINCT-VALS 0 0 A166040)) ;; Permutation of A001477? (define (A166099 n) (A166098 (- n))) ;; Offset 0. ;; The height at the 1/6 point at "Jacobi-bridge", ;; computed for each odd integer of the form 12n+7 ;; Compare to A165460. (definec (A166050 n) (let ((w (A017605 n))) ;; w = 12n+7 (add (lambda (i) (jacobi-symbol i w)) 0 (/ (-1+ w) 6)) ) ) (definec (A166100 n) (let ((w (A005408 n))) ;; w = 2n+1 (let loop ((i 1) (s 1)) (cond ((= i w) s) (else (loop (1+ i) (+ s (if (= +1 (jacobi-symbol (1+ i) w)) (1+ i) 0)) ) ) ) ) ) ) ;; Number of even numbers less than the n-th prime. ;; Same as A005097 ((odd primes - 1)/2) with a leading zero. ;; Offset 1, starts as: 0, 1, 2, 3, 5, 6, 8, 9, 11, 14, 15, 18, 20, 21, 23, ... (define (A102781 n) (if (= 1 n) 0 (/ (-1+ (A000040 n)) 2))) ;; Offset 1. (define (A076409 n) (A166100 (A102781 n))) ;; Offset 3. (define (A076410 n) (/ (A076409 n) (A000040 n))) ;; Offset 1. for A166101 - A166104. (define A166101 (MATCHING-POS 1 0 (lambda (n) (not (integer? (/ (A166100 n) (A005408 n)))))) ) ;; Conjecture: a(n) = 3*A166103(n). Checked for terms a(1)-a(92). (define (A166102 n) (A005408 (A166101 n))) (define (A166103 n) (A000290 (A166104 n))) (define (A166103v2 n) (/ (A166102 n) 3)) (define A166104 (MATCHING-POS 1 1 (lambda (n) (for-all? (factor n) (lambda (p) (or (= 1 p) (= 3 p) (= 5 (modulo p 6)))) ) ) ) ) (define (A166104v2 n) (sqrt (A166103 n))) (definec (A166272 n) (numerator (/ (A166100 (A166101 n)) (A166102 n)))) (definec (A166272v2 n) (* 3 (/ (A166100 (A166101 n)) (A166102 n)))) (definec (A166272v3 n) (* 3 (/ (A166100 (A166101 n)) (A005408 (A166101 n))))) (define A045410 ;; Primes congruent to {3, 5} mod 6. 3,5,11,17,23,29,41,47,... (compose-funs A000040 (MATCHING-POS 1 1 (lambda (n) (or (= 2 n) (= 5 (modulo (A000040 n) 6))))) ) ) ;; A125615(n)=a(A102781(n)). (definec (A166405 n) (let ((w (A005408 n))) ;; w = 2n+1 (let loop ((i 1) (s 0)) (cond ((= i w) s) (else (loop (1+ i) (+ s (if (= -1 (jacobi-symbol (1+ i) w)) (1+ i) 0)) ) ) ) ) ) ) (define (A166406 n) (- (A166405 n) (A166100 n))) (define (A166407 n) (* 3 (/ (A166406 n) (A005408 n)))) ;; A165951(n)=A166408(A102781(n)) for n>=2. (define (A166408 n) (floor->exact (/ (A166407 n) 3))) ;; Differs from A077425 for the first time at n=21, where a(n)=99, not 101. ;; I.e. seems to be union of A077425 & A165603: (define A166409 (compose-funs A005408 (ZERO-POS 1 0 A166406))) (define A165603v2 ;; Hmm... Prove it! (compose-funs A005408 (MATCHING-POS 1 0 (lambda (n) (and (zero? (A166406 n)) (odd? n) ) ) ) ) ) ;; Here are the 10 A-numbers you requested: A166268 --- A166277. (define (A166268 n) (A166050 (A005843 n))) (define (A166268v2 n) (A165605 (A005843 n))) ;; ??? (define (A166269 n) (A166050 (A005408 n))) ;; -1 -1 -1 -2 -2 -3 -1 (define (A166270 n) (A165460 (A005843 n))) ;; = 2*A166268(n) ??? (define (A166271 n) (A165460 (A005408 n))) ;; = -2 * A166269(n). = (* 2 (A001489 (A166269 n))) ??? (define (A166273 n) (A165605 (A005408 n))) ;; = -3 * A166269(n). = (* 3 (A001489 (A166269 n))) ??? ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here are the 20 A-numbers you requested: A166404 --- A166423. ;; Here are the 20 A-numbers you requested: A166424 --- A166443. (define (A166436 n) (A102283 (A163536 n))) (define (A166442 n) (A102283 (A163542 n))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here are the 18 A-numbers you requested: A165471 --- A165488. ;; A000668: [3,7,31,127,8191,131071,524287,2147483647,...] ;; A019434: [3,5,17,257,65537] ;; A005478: [2,3,5,13,89,233,1597,28657,514229,...] ;; 5: A080891 ;; 7: ;; 13: A011583 ;; 17: A011584 ;; 31: A011588 ;; 89: A011601 ;; 127: A011608 ;; ;; 199: A011623 ;; 211: A011624 ;; 223: A011625 ;; 227: A011626 ;; 229: A011627 ;; 233: A011628 ;; 239: A011629 ;; 241: A011630 ;; 251: A011631 ;; 257: Not present. ;; 263: ;; 269: ;; 271: ;; 277: ;; 281: ;; 283: ;; 293: ;; 307: (define (A080891 n) (legendre-symbol n 5)) (define (A011583 n) (legendre-symbol n 13)) (define (A011584 n) (legendre-symbol n 17)) (define (A011588 n) (legendre-symbol n 31)) (define (A011601 n) (legendre-symbol n 89)) (define (A011608 n) (legendre-symbol n 127)) (define (A011623 n) (legendre-symbol n 199)) (define (A011624 n) (legendre-symbol n 211)) (define (A011625 n) (legendre-symbol n 223)) (define (A011626 n) (legendre-symbol n 227)) (define (A011627 n) (legendre-symbol n 229)) (define (A011628 n) (legendre-symbol n 233)) (define (A011629 n) (legendre-symbol n 239)) (define (A011630 n) (legendre-symbol n 241)) (define (A011631 n) (legendre-symbol n 251)) (define (A165471 n) (legendre-symbol n 65537)) ;; A019434(4)=65537. (define A165472 (PARTIALSUMS 0 0 A165471)) (define A165473 (ZERO-POS 0 0 A165472)) ;; (A165473 610) = 65536 ;; (A165473 611) = 65537 ;; (A165473 612) = 65543 (define A165474 (RECORD-ABSVALS-BETWEEN-ZEROS-POS 0 A165472 A165473)) (define (A165475 n) (A165472 (A165474 n))) (define (A165476 n) (legendre-symbol n 131071)) ;; A000668(6)=131071. (define A165477 (PARTIALSUMS 0 0 A165476)) (define (A165478 n) (+ (* (floor->exact (/ n 2)) 131071) (* (modulo n 2) 131070))) ;; 0,131070,131071,262141,262142, (define A165478v2 (ZERO-POS 0 0 A165477)) ;; (map A165478 (iota0 4)) = (0 131070 131071 262141 262142) (define (A165479 n) (+ (* (floor->exact (/ n 2)) 131071) (* (+ 1 (* 2 (modulo n 2))) 43690))) (define A165479v2 (RECORD-ABSVALS-BETWEEN-ZEROS-POS 0 A165477 A165478)) ;; Not this: (define (A165480 n) (A165477 (A165479 n))) ;; 570,0,570,0,570,0,570,0,... (define A165480 (ZERO-POS 0 0 A163897)) ;; (A000045 23) = 28657 (define (A165481 n) (legendre-symbol n 28657)) (define A165482 (PARTIALSUMS 0 0 A165481)) (define A165483 (ZERO-POS 0 0 A165482)) ;; (A165483 232) = 28656 ;; (A165483 233) = 28657 ;; (A165483 234) = 28679 (define A165484 (RECORD-ABSVALS-BETWEEN-ZEROS-POS 0 A165482 A165483)) (define (A165485 n) (A165482 (A165484 n))) (define (A165486 n) (* (sgn (A165472 n)) (A000290 (A165472 n)))) (define (A165487 n) (* (sgn (A165477 n)) (A000290 (A165477 n)))) (define (A165488 n) (* (sgn (A165482 n)) (A000290 (A165482 n)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here are the 30 A-numbers you requested: A165569 --- A165598. ;; Here are the 10 A-numbers you requested: A165599 --- A165608. ;; for n=1, a(n)=1, and for n>1, return first such i>a(n-1) that ;; abs(*Phi* - A108539(i)/A000040(i)) ;; < abs(*Phi* - A108539(a(n-1))/A000040(a(n-1))) ;; ;; The indexing sequence for "Successively Better Golden Semiprimes." (definec (A165569 n) (if (= 1 n) 1 (let* ((i (A165569 (-1+ n))) (champion (abs (- *Phi* (/ (A108539 i) (A000040 i))))) ) (let loop ((i (1+ i))) (cond ((< (abs (- *Phi* (/ (A108539 i) (A000040 i)))) champion) i ;; Found a better specimen than the current champion. ) (else (loop (1+ i))) ) ) ) ) ) (define (A165570 n) (* (A165571 n) (A165572 n))) ;; Cf. A108540 (define (A165571 n) (A000040 (A165569 n))) ;; Cf. A108541 (define (A165572 n) (A108539 (A165569 n))) ;; Cf. A108542 (define (A165573 n) (legendre-symbol n 257)) (define (A165574 n) (legendre-symbol n 263)) (define A165575 (PARTIALSUMS 0 0 A165573)) (define A165576 (PARTIALSUMS 0 0 A165574)) (define A165577 (PARTIALSUMS 0 0 A011626)) (define A165578 (PARTIALSUMS 0 0 A011627)) (define A165579 (PARTIALSUMS 0 0 A011628)) (define (A165581 n) (legendre-symbol n 524287)) ;; = A000668(7)=524287. (define A165582 (PARTIALSUMS 0 0 A165581)) (define A165583 (ZERO-POS 0 0 A165582)) (define A165584 (RECORD-ABSVALS-BETWEEN-ZEROS-POS 0 A165582 A165583)) (define (A165585 n) (A165582 (A165584 n))) (define (A165586 n) (legendre-symbol n 514229)) ;; = A005478(9) = A000045(29) (define A165587 (PARTIALSUMS 0 0 A165586)) (define A165588 (ZERO-POS 0 0 A165587)) (define A165589 (RECORD-ABSVALS-BETWEEN-ZEROS-POS 0 A165587 A165588)) (define (A165590 n) (A165587 (A165589 n))) (define (A165591 n) (jacobi-symbol n 59701)) ;; = A005385(11)*A005385(12) = 227*263. (define (A165591v2 n) (* (A011626 n) (A165574 n))) (define A165592 (PARTIALSUMS 0 0 A165591)) (define A165593 (ZERO-POS 0 0 A165592)) (define A165594 (RECORD-ABSVALS-BETWEEN-ZEROS-POS 0 A165592 A165593)) (define (A165595 n) (A165592 (A165594 n))) (define (A165596 n) (jacobi-symbol n 59881)) ;; = A005478(6)*A019434(3) = 233*257 = A117879(11). (define (A165596v2 n) (* (A011628 n) (A165573 n))) (define A165597 (PARTIALSUMS 0 0 A165596)) (define A165598 (ZERO-POS 0 0 A165597)) (define A165599 (RECORD-ABSVALS-BETWEEN-ZEROS-POS 0 A165597 A165598)) (define (A165600 n) (A165597 (A165599 n))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Hilbert curve in a square array, zero-based (define (A163357 n) (A163355 (A054238 n))) ;; Inverse: (define (A163358 n) (A054239 (A163356 n))) ;; Hilbert curve in a square array, transposed, zero-based (define (A163359 n) (A163357 (A061579 n))) ;; Inverse: (define (A163360 n) (A061579 (A163358 n))) ;; Hilbert curve in a square array, one-based (define (A163361 n) (1+ (A163357 (-1+ n)))) ;; Inverse: (define (A163362 n) (1+ (A163358 (-1+ n)))) ;; Hilbert curve in a square array, transposed, one-based (define (A163363 n) (1+ (A163359 (-1+ n)))) ;; Inverse: (define (A163364 n) (1+ (A163360 (-1+ n)))) (define A163365 (ROWSUMS0 A163357)) (define A163365v2 (ROWSUMS0 A163359)) ;; Here are the 10 A-numbers you requested: A163477 --- A163486. (define (A163477 n) (/ (A163365 n) 4)) (define (A163478 n) (/ (A163242 n) 3)) (define (A163479 n) (/ (A163342 n) 6)) (define (A163480 n) (A163334 (A000217 n))) (define (A163481 n) (A163334 (-1+ (A000217 (1+ n))))) (define (A163482 n) (A163357 (A000217 n))) (define (A163483 n) (A163357 (-1+ (A000217 (1+ n))))) ;; Cf. A163355 (defineperm1 (A163485 n) (let* ((i (floor->exact (/ (A000523 n) 2))) (dd (modulo (floor->exact (/ n (expt 4 i))) 4)) (r (if (zero? n) n (modulo n (expt 4 i)))) ) (cond ((zero? n) n) ((= 0 dd) ;; 00xy --> 00xy (A163485 r) ) ((= 1 dd) ;; 01xy --> 11c(y)x (+ (* 3 (expt 4 i)) (- (expt 4 i) 1 (A163485 (complement-i-oddpos-lsbs (A057300 r) i))) ) ) ((= 2 dd) ;; 10xy --> 01c(y)x (+ (expt 4 i) (- (expt 4 i) 1 (A163485 (complement-i-oddpos-lsbs (A057300 r) i))) ) ) (else ;; 11xy --> 10xy (+ (* 2 (expt 4 i)) (A163485 r)) ) ) ) ) ;; Oh I'm so lazy now! Can't bother now to find the formula for the inverse. ;; We can do this with defineperm1 because A163485(0) = 0. (define (A163486 n) (A163485 (- n))) (define (A147995 n) (A163485 (A054238 (A061579 n)))) (define A163484 (ROWSUMS0 A147995)) ;; Inverse of A147995 (define (A163544 n) (A061579 (A163546 n))) ;; Transpose of A147995: (define (A163545 n) (A163485 (A054238 n))) (define (A163546 n) (A054239 (A163486 n))) ;; ----------------------------------------------------------------- ;; Here are the 20 A-numbers you requested: A163528 --- A163547. (define (A163528 n) (A025581 (A163335 n))) (define (A163528v2 n) (A002262 (A163337 n))) (define (A163528v3 n) (A163325 (A163332 n))) (define (A163529 n) (A002262 (A163335 n))) (define (A163529v2 n) (A025581 (A163337 n))) (define (A163529v3 n) (A163326 (A163332 n))) (define (A163530 n) (+ (A163528 n) (A163529 n))) (define (A163531 n) (+ (A000290 (A163528 n)) (A000290 (A163529 n)))) (define (A163532 n) (if (zero? n) n (- (A163528 n) (A163528 (- n 1))))) (define (A163533 n) (if (zero? n) n (- (A163529 n) (A163529 (- n 1))))) ;; a(n) = (A163534 A008591) ;; * 9 n (define (A163534 n) ;; One-based. (modulo (+ 3 (A163532 n) (A163533 n) (abs (A163533 n))) 4) ) (define (A163534origdork n) ;; One-based. (+ (modulo (+ 3 (A163532 n) (A163533 n)) 4) (abs (A163533 n))) ) (define (A163535 n) ;; One-based. (modulo (+ 3 (A163532 n) (A163533 n) (abs (A163532 n))) 4) ) ;; Also one-based sequences: ;; (same-intfuns? (compose-funs A163536 A008591) (compose-funs A163536 A008591 A008591) 59049) --> #t (define (A163536 n) (A163241 (modulo (- (A163534 (1+ n)) (A163534 n)) 4))) (define (A163537 n) (A163241 (modulo (- (A163535 (1+ n)) (A163535 n)) 4))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; This should sort A163344 into ascending order, ;; which seems to be ;; A037314 Numbers n such that (sum of base 3 digits of n)=(sum of base 9 digits of n). ;; ;; Similarly, A163343(n)+1 (submit!) gives the central diagonal of ;; A163338/A163340, and when it is sorted, there are ;; both primes and squares in it. ;; Also A062880(n)+1 contains primes (is this A145812 ?) ;; Yes, comment a(n)=2*A000695(n-1)+1 [From Vladimir Shevelev (shevelev(AT)bgu.ac.il), Nov 07 2008] (define (A128173 n) ;; Numbers in ternary Gray code order. n ;; Not ready. Read Zunic's paper. ) ;; Here are the 20 A-numbers you requested: A166404 --- A166423. ;; Here are the 20 A-numbers you requested: A166424 --- A166443. ;; Do something to the starting offsets, e.g. change A163534 and A163540 ;; to begin with offset 0? (In which case we define (PARTIALSUMS 1 0 ...) ? ;; One-based: (define (A166436 n) (A102283 (A163536 n))) ;; Semantics: gives the number of quarter-turns the Hilbert walk traveler ;; has done with regards to the starting (default) direction, ;; since last "wounding back". (There exists a term for this, ;; something like a "winding number" or such.) ;; Compute up to some good value of A166434: (define A166437 (PARTIALSUMS 2 1 A166436)) ;; Note how this differs from "partial sums modulo 4", which gives the absolute direction: (definec (A163534v2 n) (if (= 1 n) 0 (A010873 (+ (A163534v2 (-1+ n)) (A166436 (-1+ n)))))) ;; A163534(n) = A010873(A166437(n)) (define A166434 (ZERO-POS 1 1 A166437)) ;; Begins as: 1,3,4,39,40,363,364,3279,3280,... ;; (take also bisections). (define A166435 (RECORD-POS 1 1 A166437)) ;;;;;;;;;;;;;;;;;;;;; ;; Sum of the winding numbers: ;; (Is it the same as partial sums of sums of relative directions? Of course. ;; Which one is better. Consider also negatives of the other.) (define (A166439 n) (+ (A166437 n) (A166443 n))) (define A166438 (ZERO-POS 1 1 A166439)) (define (A166442 n) (A102283 (A163542 n))) (define A166443 (PARTIALSUMS 2 1 A166442)) (define A166440 (ZERO-POS 1 1 A166443)) ;; Begins as: 1,2,3,29,51,461,819,7373,13107, (define A166441 (RECORD-POS 1 1 A166443)) ;; Note how this differs from "partial sums modulo 4", which gives the absolute direction: (definec (A163540v2 n) (if (= 1 n) 0 (A010873 (+ (A163540v2 (-1+ n)) (A166442 (-1+ n)))))) ;; A163540(n) = A010873(A166443(n)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; --- ;; These already given by Claude Lenormand: (define (A059253 n) (A025581 (A163358 n))) (define (A059253v2 n) (A002262 (A163360 n))) (define (A059253v3 n) (A059905 (A163356 n))) (define (A059252 n) (A002262 (A163358 n))) (define (A059252v2 n) (A025581 (A163360 n))) (define (A059252v3 n) (A059906 (A163356 n))) (define (A059261 n) (+ (A059252 n) (A059253 n))) (define (A059285 n) (- (A059253 n) (A059252 n))) (define (A163538 n) (if (zero? n) n (- (A059253 n) (A059253 (- n 1))))) (define (A163539 n) (if (zero? n) n (- (A059252 n) (A059252 (- n 1))))) ;; a(n) = (A163534 A008598) ;; * 16 n (define (A163540 n) ;; One-based. (modulo (+ 3 (A163538 n) (A163539 n) (abs (A163539 n))) 4) ) (define (A163540origdork n) ;; One-based. (+ (modulo (+ 3 (A163538 n) (A163539 n)) 4) (abs (A163539 n))) ) (define (A163541 n) ;; One-based. (modulo (+ 3 (A163538 n) (A163539 n) (abs (A163538 n))) 4) ) ;; (same-intfuns? (compose-funs A163542 A008598) (compose-funs A163542 A008598 A008598) (expt 2 16)) --> #t ;; Also one-based sequences: (define (A163542 n) (A163241 (modulo (- (A163540 (1+ n)) (A163540 n)) 4))) (define (A163543 n) (A163241 (modulo (- (A163541 (1+ n)) (A163541 n)) 4))) (define (A163547 n) (+ (A000290 (A059252 n)) (A000290 (A059253 n)))) ;; Here are the 20 A-numbers you requested: A163528 --- A163547. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (A072661 n) (A059905 (A048679 n))) (define (A072662 n) (A059906 (A048679 n))) (define (packA054238 x y) (+ (A000695 x) (* 2 (A000695 y)))) (define (packA054238tr x y) (+ (A000695 y) (* 2 (A000695 x)))) ;; Old version: (define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1))))) ;; This new one returns the exponent k, such that 2^k = n, in case n is ;; the power of 2, otherwise #f. (define (pow2?v2 n) (and (> n 0) (zero? (A004198bi n (- n 1))) (A000523 n))) (define (pow2? n) (let loop ((n n) (i 0)) (cond ((zero? n) #f) ((odd? n) (and (= 1 n) i)) (else (loop (/ n 2) (1+ i))) ) ) ) ;; "Binary asymmetry index", 0 if n is a binary palindrome, i.e. in A006995. (define (A037888 n) (/ (A000120 (A003987bi n (A030101 n))) 2)) (define (A004442 n) (A003987bi n 1)) ;; Natural numbers, pairs reversed: a(n) = n + (-1)^n; n XOR 1. (define (A003188 n) (A003987bi n (floor->exact (/ n 2)))) ;; Gray Code. ;; Prove! (Defined with the help A054429 in analogous manner ;; as A122199 is defined as a "recursed variant" of A122155.) (define (A003188v2 n) (if (< n 1) n (let ((m (A054429 n))) (+ (A053644 m) (A003188v2 (A053645 m)))))) ;; Inverse then follows as: (define (A006068 n) (if (< n 1) n (A054429 (+ (A053644 n) (A006068 (A053645 n)))))) ;; Using the formula given by Benoit Cloitre: ;; a(0)=0, a(3k)=1-a(k); a(3k+1)=a(3k+2)=1. (definec (A014578 n) (cond ((zero? n) n) ((zero? (modulo n 3)) (- 1 (A014578 (/ n 3)))) (else 1) ) ) ;; Fix 0; exchange even and odd numbers. (define (A014681 n) (if (zero? n) 0 (+ n (- (* 2 (modulo n 2)) 1)))) (define (A048735 n) (A004198bi n (>> n 1))) (define (A014081 n) (A000120 (A048735 n))) (define (packA048680oA054238 x y) (A048680 (packA054238 x y))) (define (packA048680oA054238tr x y) (A048680 (packA054238tr x y))) (define (A072793 n) (A048680 (A054238 n))) ;; EIS # reserved for packA048680oA054238 (define (A072794 n) (A054239 (A048679 n))) ;; inverse for above. ;; A072732 - A072741 reserved for us. (define (A072732 n) (packA072732 (A025581 n) (A002262 n))) (define (packA072732 x y) (let ((x-y (- x y))) (cond ((<= x-y 0) ;; i.e. (x <= y) (packA001477 (+ (* 2 x) (modulo x-y 2)) (+ (* 2 x) (floor->exact (/ (1+ (- x-y)) 2))) ) ) ;; ((< x-y 2) ;; either x=y, or x=y+1. ;; (packA001477 (+ (* 2 y) x-y) (* 2 y)) ;; ) (else ;; x > y. (floor->exact (/ -1 2)) has to be -1 !!! (packA001477 (+ (* 2 (1+ y)) (floor->exact (/ (- x-y 2) 2))) (+ (* 2 y) (modulo (1+ x-y) 2)) ) ) ) ) ) (define (A072733 n) (packA072733 (A025581 n) (A002262 n))) (define (packA072733 x y) (cond ((<= x y) ;; i.e. (x <= y) (let ((half-x (floor->exact (/ x 2)))) (packA001477 half-x (+ half-x (* 2 (- y (* 2 half-x) (modulo x 2))) (modulo x 2) ) ) ) ) (else ;; x > y (let ((half-y (floor->exact (/ y 2)))) (packA001477 (+ 1 half-y (* 2 (- (-1+ x) (* 2 half-y) (modulo y 2))) (modulo y 2) ) half-y ) ) ) ) ) (define (A072734 n) (packA072734 (A025581 n) (A002262 n))) ;; And code this as an inverse of A072735 (the next one)... ;; Using this as a NxN->N packing bijection for a global arithmetic ;; unranking function for Catalan structures gives a better result ;; than A072642: ;; (define weird1tr (max-n-fun-with-arithrank-scheme packA072734)) ;; (map binwidth (map weird1tr (iota0 10))) ;; (0 1 2 4 6 8 13 23 43 82 160) ;; And using it's "4th power" gives even better results in a certain range: ;; (0 1 2 8 9 11 15 23 39 71 134) ;; (define (packA072734 x y) (let ((x-y (- x y))) (cond ((negative? x-y) ;; i.e. (y > x) (packA001477 (+ (* 2 x) (modulo (1+ x-y) 2)) (+ (* 2 x) (floor->exact (/ (+ (- x-y) (modulo x-y 2)) 2))) ) ) ((< x-y 3) ;; i.e. (x >= y and x <= y+2) (packA001477 (+ (* 2 y) x-y) (* 2 y)) ) (else ;; x >= y+3 (packA001477 (+ (* 2 y) (floor->exact (/ (1+ x-y) 2)) (modulo (1+ x-y) 2)) (+ (* 2 y) (modulo x-y 2)) ) ) ) ) ) (define (A072735 n) (packA072735 (A025581 n) (A002262 n))) (define (packA072735 x y) (cond ((<= x y) ;; i.e. (x <= y) (let ((half-x (floor->exact (/ x 2)))) (packA001477 half-x (+ half-x (* 2 (- y (* 2 half-x))) (modulo x 2) (if (and (eq? x y) (even? x)) 0 -1) ) ) ) ) (else ;; x > y (let ((half-y (floor->exact (/ y 2)))) (packA001477 (+ half-y (* 2 (- (-1+ x) (* 2 half-y))) (modulo y 2) (if (and (eq? x (1+ y)) (even? y)) 1 0) ) half-y ) ) ) ) ) (define (A072736 n) (A025581 (A072733 n))) ;; X-projection of A072732 (define (A072737 n) (A002262 (A072733 n))) ;; Y-projection of A072732 (define (A072738 n) (A025581 (A072732 n))) ;; X-projection of A072733 (define (A072739 n) (A002262 (A072732 n))) ;; Y-projection of A072733 (define (A072740 n) (A025581 (A072735 n))) ;; X-projection of A072734 (define (A072741 n) (A002262 (A072735 n))) ;; Y-projection of A072734 ;; Also A072781 - A072800 reserved for us. (define (A072781 n) (A025581 (A072734 n))) ;; X-projection of A072735 (define (A072782 n) (A002262 (A072734 n))) ;; Y-projection of A072735 (define (A072783 n) (- (A072740 n) (A072736 n))) (define (A072784 n) (- (A072741 n) (A072737 n))) (define (A072785 n) (- (A072781 n) (A072738 n))) (define (A072786 n) (- (A072782 n) (A072739 n))) (define (A075300bi x y) (-1+ (* (expt 2 x) (1+ (* 2 y))))) (define (A075300 n) (A075300bi (A025581 n) (A002262 n))) (define (A075302bi x y) (-1+ (* (1+ (* 2 x)) (expt 2 y)))) (define (A075302 n) (A075302bi (A025581 n) (A002262 n))) ;; (map binexp->runcount1list (iota0 16)) ;; --> (() (1) (1 1) (2) (1 2) (1 1 1) (2 1) (3) (1 3) ;; (1 2 1) (1 1 1 1) (1 1 2) (2 2) (2 1 1) (3 1) (4) (1 4)) (define (binexp->runcount1list n) ;; (length (binexp->runcount1list n)) gives A005811 (if (zero? n) (list) (let loop ((n n) (rc (list)) (count 0) (prev-bit (modulo n 2))) (if (zero? n) (cons count rc) (if (eq? (modulo n 2) prev-bit) ;; If the lsb has not changed (loop (floor->exact (/ n 2)) rc (1+ count) (modulo n 2) ) (loop (floor->exact (/ n 2)) ;; If it has changed (cons count rc) 1 (modulo n 2) ) ) ) ) ) ) (define (runcount1list->binexp lista) (let loop ((lista lista) (s 0) (state 1)) (cond ((null? lista) s) (else (loop (cdr lista) (+ (* s (expt 2 (car lista))) (* state (- (expt 2 (car lista)) 1)) ) (- 1 state) ) ) ) ) ) ;; ;; Replace in the binary expansion of n each 1-bit ;; with the distance to the next 1-bit: ;; ;; (binexp->siteswap-list 5) --> (2 0 1) ;; (binexp->siteswap-list 6) --> (1 2 0) ;; (binexp->siteswap-list 7) --> (1 1 1) ;; (binexp->siteswap-list 8) --> (4 0 0 0) ;; (binexp->siteswap-list 9) --> (3 0 0 1) ;; (binexp->siteswap-list 10) --> (2 0 2 0) (define (binexp->siteswap-list n) (if (zero? n) (list) (let loop ((n n) (rc (list)) (count 1)) (if (zero? n) rc (if (zero? (modulo n 2)) (loop (/ n 2) (cons 0 rc) (1+ count) ) (loop (floor->exact (/ n 2)) (cons count rc) 1 ) ) ) ) ) ) ;; Pierre Lamothe, Fri, 21 May 2004: (definec (A116623 n) ;; C.f. A001047(n) = A116623(A000225(n)) (cond ((zero? n) 1) ((even? n) (+ (A116623 (/ n 2)) (expt 2 (A000523 n)))) (else (+ (* 3 (A116623 (/ (- n 1) 2))) (expt 2 (+ 1 (A000523 n))))) ) ) (define (A116640 n) (A116623 (A059893 n))) ;; (define seqA116641 (list-head (uniq (sort (map A116623 (iota0 512)) <)) 162)) (define (A116641 n) (list-ref seqA116641 n)) (define (A116642 n) (A007088 (A116641 n))) ;; A055941 a(n) = sum(i[j]-j, j = 0..k-1) where n = sum( 2^i[j], j = 0 .. k-1). ;; As I interpret it: vector i gives the positions of 1-bits in n, ;; and we take (positions 0-based from the least significant end): ;; Sum (position of each 1-bit - how manyth 1-bit it is from the right ;; (first = 0, second = 1, etc.) ;; over all 1-bits of n. ;; ;; This is equivalent of taking ;; Sum (total number of zero-bits to the right of 1-bit) ;; over all 1-bits of n. (define (A055941 n) (let loop ((n n) (ze 0) (s 0)) ;; ze = zeros encountered, s = sum. (cond ((zero? n) s) ((even? n) (loop (/ n 2) (1+ ze) s)) (else (loop (/ (-1+ n) 2) ze (+ s ze))) ) ) ) ;; A161511 Number of 1...0 pairs in binary representation of 2n. ;; a(2n) = a(n) + A000120(n); a(2n+1) = a(n) + 1. ;; Note that A161511(n) = A055941(n)+A000120(n). (define (A161511 n) (let loop ((n n) (ze 0) (s 0)) ;; ze = zeros encountered, s = sum. (cond ((zero? n) s) ((even? n) (loop (/ n 2) (1+ ze) s)) (else (loop (/ (-1+ n) 2) ze (+ s (1+ ze)))) ) ) ) ;; Square array A126441: (Alford Arnold) ;; a(n) occurs in the row A053645(n). ;; Each non-zero m occurs in row A053645(m) and column A161511(m). ;; (both zero-based.) ;; For each row r, the first non-zero term is A004760(r+1). ;; The least possible starting column for the row on which a(n) ;; is, is A000523(n+1). ;; The second value on each row is A004760(n+1) plus A062383(n); ;; subsequent values increase by ever enlarging powers of two. ;; (define (A126441 n) (A126441onebased (1+ n))) (definec (A126441onebased n) (cond ((< n 2) n) (else (let ((prev (A126441onebased (- n (/ (A053644 n) 2))))) (if (or (= (A053644 n) (* 2 (A053644 (A053645 n)))) ;; n in A004755? (zero? prev) ;; Row hasn't started yet? ) (let ((starter (A004760 (1+ (A053645 n))))) (if (> (A161511 starter) (1+ (A000523 n))) 0 starter ) ) (A004754 prev) ) ) ) ) ) (define (A161920 n) (A161511 (A004760 n))) ;; Offset 1. (define A166274 (NONZERO-POS 1 0 A126441)) (define A166275 (ZERO-POS 1 0 A126441)) (defineperm1 (A161924 n) (A126441 (A166274 n))) (define (A166276 n) (A161924 (- n))) ;; upto 87. ;; A000070, off 0, starts as: 1,2,4,7,12,19,30,45,67,97,139,195,272, ;; A026905, off 1, starts as: 1,3,6,11,18,29,44,66,96,138,194,271, (define seqA000070 '(1 2 4 7 12 19 30 45 67 97 139 195 272 373 508 684 915 1212 1597 2087 2714 3506 4508 5763 7338 9296 11732 14742 18460 23025 28629 35471 43820 53963 66273 81156 99133 120770 146785 177970 215308 259891 313065 376326 451501) ) (define seqA026905 '(#f 1 3 6 11 18 29 44 66 96 138 194 271 372 507 683 914 1211 1596 2086 2713 3505 4507 5762 7337 9295 11731 14741 18459 23024 28628 35470 43819 53962 66272 81155 99132 120769 146784 177969 215307) ) (define (A000070 n) (list-ref seqA000070 n)) ;; Lazy now! (define (A026905 n) (list-ref seqA026905 n)) ;; Sequence A161919: sort each subsequence A161924(A000070(k-1)..A026905(k)) ;; into ascending order. ;; (define seqA161924 (cons #f (map A161924 (iota (A026905 19))))) ;; (define seqA161919 (cons #f (append-map! (lambda (n) (sort (sublist seqA161924 (A000070 (-1+ n)) (1+ (A026905 n))) <)) (iota 19)))) (defineperm1 (A161919 n) (list-ref seqA161919 n)) ;; Lazy now! (define (A166277 n) (A161919 (- n))) (definec (A001477hardway n) ;; Compressed version of A126441. (cond ((< n 2) n) ;; n+1 in A004755? ((= (A053644 n) (* 2 (A053644 (A053645 n)))) (A004760 (1+ (A053645 n))) ) (else ;; Otherwise, the previous term of the row + msb of that term. (A004754 (A001477hardway (- n (/ (A053644 n) 2)))) ) ) ) ;; Here are the 6 A-numbers you requested: A116623 --- A116628. ;; From Paul D. Hanna Feb 19 2006: ;; Set a(1)=1; for n>1, a(n) = least positive integer not appearing earlier ;; such that ;; {a(k)|1= (1 2 3 4 7 11 26 42 109 166 373 772 1532) ;; (map A116624 (map A116628 (iota 13))) --> (1 2 4 8 16 32 64 128 256 512 1024 2048 4096) ;; A116624(1) = 1; A116624(n) = the least positive integer i distinct from any of A116624(1..n-1) ;; and A116625(1..n-2), such that ;; also (i XOR A116624(n-1)) is not present in A116625(1..n-2) nor in A116624(1..n-1) ;; (Note that (i XOR A116624(n-1)) cannot be A116624(n-1), because i > 0) ;; Are any of these conditions superfluous? (definec (A116624old n) (cond ((= 1 n) 1) (else (let outloop ((i 1)) ;; Play sure, and start always from the beginning, i is our candidate. (let ((k (A003987bi i (A116624old (- n 1))))) ;; Candidate for A116625(n-1) (let inloop ((j (- n 1))) ;; We compare i and k to all A116624old(n-1 .. 1) and A116625(n-1 .. 1) (cond ((zero? j) i) ;; No clashes found, 'i' is the man we were looking for! ((= i (A116624old j)) (outloop (+ i 1))) ;; A116624 wouldn't be distinct, try next. ((= i (A116625old (- j 1))) (outloop (+ i 1))) ;; A116624 wouldn't be disjoint from A116625 ((= k (A116625old (- j 1))) (outloop (+ i 1))) ;; A116625 wouldn't be distinct, try next. ((= k (A116624old j)) (outloop (+ i 1))) ;; A116625 wouldn't be disjoint from A116624 (else (inloop (- j 1))) ;; So far so good, check also smaller terms of A116624 & -25. ) ) ) ) ) ) ) (define (A116625old n) (if (zero? n) n (A003987bi (A116624old n) (A116624old (+ n 1))))) (definec (A116626old n) (if (odd? n) (A116624old (/ (+ n 1) 2)) (A116625old (/ n 2)))) (definec (A116627old n) (first-n-where-fun_n-is-i1 A116626old n)) (define (A116624 n) (A116626 (- (* 2 n) 1))) (define (A116625 n) (A116626 (* 2 n))) ;; If n is odd, then A116626(n) = A116626(n-1) XOR A116626(n-2). ;; if n is even, then find the first i >= A116648(n-1) ;; such that neither i nor (i XOR A116626(n-1)) is present in A116626(1..n-1), ;; and return (i XOR A116626(n-1)). (What if we return i instead?) (defineperm1 (A116626 n) (cond ((= 1 n) 1) ((odd? n) (A003987bi (A116626 (-1+ n)) (A116626 (- n 2)))) (else (let outloop ((i (A116648 (-1+ n)))) (let ((k (A003987bi i (A116626 (-1+ n))))) (let inloop ((j (- n 1))) ;; We compare i and k to all A116626(n-1 .. 1) (cond ((zero? j) k) ;; No clashes found, 'k' is the man we were looking for! ((= i (A116626 j)) (outloop (+ i 1))) ((= k (A116626 j)) (outloop (+ i 1))) (else (inloop (- j 1))) ;; So far so good check also against smaller terms of A116626. ) ) ) ) ) ) ) (define (A116627 n) (A116626 (- n))) ;; Take values from invcache. Must be computed after A116626. (define A116628 (fun-succ-matching-is0 (lambda (i) (pow2? (A116624 i))))) ;; We consider a > b (i.e. not less than b) also in case a is nil. ;; (Because the stateful caching system used by defineperm1.) (define (not-lte? a b) (cond ((not (number? a)) #t) (else (> a b)))) ;; Here are the 4 A-numbers you requested: A116648 --- A116651. ;; (map A116648 (iota 128)) ;; (2,2,4,4,5,5,5,5,7,7,7,7,7,7,9,9,11,11,11,11,11,11,18,18,19,19,19,19,20,20,20,20,21,21,21,21,21,21,21,21,27,27,27,27,27,27,27,27,29,29,29,29,30,30,30,30,30,30,30,30,30,30,39,39,39,39,42,42,42,42,44,44,44,44,45,45,45,45,46,46,46,46,46,46,47,47,47,47,71,71,71,71,71,71,73,73,73,73,74,74,74,74,75,75,75,75,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76) ;; (map A116649 (iota 32)) ;; (1 3 5 9 15 17 23 25 29 33 41 49 53 63 67 71 75 79 85 89 95 99 103 107 139 143 163 167 175 179 199 219) ;; (map A116650 (iota 32)) ;; (2 4 5 7 9 11 18 19 20 21 27 29 30 39 42 44 45 46 47 71 73 74 75 76 78 83 87 88 90 109 113 116) ;; (map A116651 (iota0 5)) ;; (2 2 4 5 9 20) (definec (A116648 n) (if (< n 2) (+ n 1) ;; A116626 begins as 1,3,2,6,4,12,8,13,5,15,... (let ((prev (A116648 (- n 1)))) (cond ((not (= (A116626 n) prev)) prev) (else (let loop ((i (+ 1 prev))) (cond ((not-lte? (A116627 i) n) i) (else (loop (+ 1 i))) ) ) ) ) ) ) ) (define A116649 (fun-succ-matching-is0 (lambda (i) (not (= (A116648 (- i 1)) (A116648 i)))))) (define (A116650 n) (A116648 (A116649 n))) (define (A116651 n) (A116648 (A000079 n))) ;; The first differences of A005228: ;; (define (A030124 n) (cond ((= n 0) 2) ((= n 1) 4) (else (- (A005228 (+ n 2)) (A005228 (+ n 1)))))) ;; Hofstadter's A005228 = 1,3,7,12,18,26,35,45,56,69,83,98,114,131,150,170,191,213,236,260,... (starting offset = 1). ;; A030124+ 2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,... ;; A000027 1,2,3,4,5,6,7,8,9 ;; pseuinv 0,1,1,2,3,4,4,5,... ;; (define A005228 (COMPLEMENT 1 (compose-funs A030124 -1+))) ;; Needs one-based seq. ;; Hofstadter's A005228 = 1,3,7,12,18,26,35,45,56,69,83,98,114,131,150,170,191,213,236,260,... ;; A030124+ 2,4,5,6,8,9,10,11,13,14,15,16,17,19,20,... ;; A000027 1,2,3,4,5,6,7,8,9 ;; Defined as the partial sums of A030124+ ;; Note that to kick start this recursion, we need to specify the three initial values explicitly: (definec (A005228 n) (cond ((= n 1) 1) ((= n 2) 3) ((= n 3) 7) (else (+ (A005228 (- n 1)) (A030124+ (- n 1)))))) (define A030124+ (COMPLEMENT 1 A005228)) ;; One-based. (define A030124 (compose-funs A030124+ 1+)) ;; Zero-based. ;; Few Murthyisms: ;; %S A096111 1,2,2,3,3,6,6,4,4,8,8,12,12,24,24,5,5,10,10,15,15,30,30,20,20,40,40,60, ;; %T A096111 60,120,120,6,6,12,12,18,18,36,36,24,24,48,48,72,72,144,144,30,30,60,60, ;; %U A096111 90,90 ;; Zero-based. (definec (A096111 n) (cond ;; ((zero? n) 1) ((pow2? (+ n 1)) (+ 2 (A000523 n))) (else (* (+ 1 (A000523 n)) (A096111 (A053645 n)))) ) ) ;; Bisection of above (zero-based): (define (A121663v2 n) (A096111 (* 2 n))) ;; Zero-based. (definec (A121663 n) (cond ((zero? n) 1) ((pow2? n) (+ 2 (A000523 n))) (else (* (+ 2 (A000523 n)) (A121663 (A053645 n)))) ) ) ;; One-based, permutation of natural numbers: ;; v v v v ;; 1 2 3 4 5 6 7 8 9 0 1 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ;;%S A096114 1,2,3,5,4,6,10,11,9,8,7,12,19,20,21,23,22,18,16,17,15,14,13,24,37,38, ;;%T A096114 39,41,40,42,46,47,45,44,43,36,31,32,33,35,34,30,28,29,27,26,25,48 ;; C.f. A073080 (definec (A096114 n) (cond ((< n 3) n) ((and (zero? (modulo n 3)) (pow2? (/ n 3))) n) (else (let ((lastfix (* 3 (expt 2 (A000523 (floor->exact (/ n 3))))))) (+ lastfix (A096114 (- (* 2 lastfix) n))) ) ) ) ) ;; Inverse of the above. One-based. Seems to be formed in a simple way: ;; 1 2 3 5 4 6 11 10 9 7 8 12 23 22 21 19 20 18 13 14 15 17 16 24 ;; 47 46 45 43 44 42 37 38 39 41 40 36 25 26 27 29 28 30 35 34 33 31 32 48 (definec (A121664 n) (first-n-where-fun_n-is-i1 A096114 n)) ;; One-based. Could be zero-based as well. (definec (A096115 n) (cond ((pow2? (+ n 1)) (+ 1 (A000523 n))) ((pow2? n) (+ 1 (A096115 (- n 1)))) (else (* (+ (A000523 n) 1) (A096115 (A035327 (- n 1))))) ) ) ;; One-based. Could be zero-based as well. (definec (A096115v2 n) (cond ((pow2? (+ n 1)) (+ 1 (A000523 n))) ((pow2? n) (+ 1 (A096115v2 (- n 1)))) (else (* (+ (A000523 n) 1) (A096115v2 (- (expt 2 (A000523 (- n 1))) (A053645 (- n 1)) 1)))) ) ) ;; A122154 --- A122156. ;; (map (lambda (n) (count-the-occurrences A096115 n 1 (A000079 n))) (iota 16)) ;; --> (1 2 2 2 2 4 2 4 2 4 2 6 2 4 4 4) ;; halved --> Is it A045778, yes, it is! (define (A025147v2_slow n) (if (< n 2) n (count-the-occurrences A096116 n 1 (+ 1 (A000079 (- n 2)))))) (define (A045778v2_slow n) (count-the-occurrences A121663 n 0 (if (= 1 n) 0 (A000079 (- n 2))))) (define (A122155 n) (cond ((< n 1) n) ((pow2? n) n) (else (- (* 2 (A053644 n)) (A053645 n))) ) ) (definec (A122198 n) (if (< n 1) n (A122155 (+ (A053644 n) (A122198 (A053645 n)))) ) ) (definec (A122199 n) (if (< n 1) n (let ((m (A122155 n))) (+ (A053644 m) (A122199 (A053645 m))) ) ) ) (definec (A096116 n) (cond ((= 1 n) 1) ((pow2? (- n 1)) (+ 2 (A000523 (- n 1)))) (else (+ 2 (A000523 (- n 1)) (A096116 (+ 2 (A035327 (- n 1)))))) ) ) ;; One-based. There's opportunity for further cleaning of this formula: (Use A035327) (definec (A096116v2 n) (cond ((= 1 n) 1) ((pow2? (- n 1)) (+ 2 (A000523 (- n 1)))) (else (+ 2 (A000523 (- n 1)) (A096116v2 (+ 1 (- (expt 2 (A000523 (- n 1))) (A053645 (- n 1))))))) ) ) ;; ---------------------- ;; a(n)=a(n-1)+a(m), where m=2^(p+1)+2-n, and 2^p= 4. (definec (A050049 n) (cond ((= 1 n) 1) (else (+ (A050049 (- n 1)) (A050049 (+ 1 (A035327 (- n 2)))))) ) ) ;; Murthy has supplied A096118 as a duplicate of Kimberling's A050029: (definec (A050029 n) (cond ((< n 3) 1) (else (+ (A050029 (- n 1)) (A050029 (+ 1 (A035327 (- n 2)))))) ) ) ;; Zero-based: Compute up to n=14: (define (A096119 n) (A050029 (+ 1 (expt 2 n)))) ;; Murthy's A096120 is probably an erroneous duplicate of Kimberling's A050030 ! (definec (A050030 n) (cond ((< n 3) 1) (else (+ (A050030 (- n 1)) (A050030 (+ 1 (A053645 (- n 2)))))) ) ) (define (A105996 n) (A050030 (+ 1 (expt 2 n)))) (defineperm1 (A076105 n) (cond ((< n 2) n) ((zero? (A025581 (- n 1))) ;; n is triangular, on the trailing edge (let* ((rowindex (A002024 n)) (rowsumsofar (add A076105 (+ (A000217 (- rowindex 1)) 1) (- (A000217 rowindex) 1) ) ) (prevrowsum (A076103 (- rowindex 1))) ) (let loop ((i (modulo (- rowsumsofar) prevrowsum))) (if (and (not (zero? i)) (not-lte? (A122154 i) (- n 1))) i (loop (+ i prevrowsum)) ) ) ) ) (else (luuA076105 (- n 1))) ) ) (define (A076101 n) (A076105 (+ 1 (A000217 (- n 1))))) (define (A076102 n) (A076105 (A000217 n))) (define (A076103 n) (add A076105 (+ (A000217 (- n 1)) 1) (A000217 n))) (define (A076104 n) (/ (A076103 (+ n 1)) (A076103 n))) (define (A122154 n) (A076105 (- n))) ;; Take values from invcache. Must be computed after A076105 ;; luu stands for "least un-used". We don't want to submit these to OEIS, no inherent value! (definec (luuA076105 n) ;; Least natural number which does not occur in A076105(1..n). (if (< n 2) (+ n 1) ;; A094280 begins as 1,2,3,4,5,6,... (let ((prev (luuA076105 (- n 1)))) (cond ((not (= (A076105 n) prev)) prev) (else (let loop ((i (+ 1 prev))) (cond ((not-lte? (A122154 i) n) i) (else (loop (+ 1 i))) ) ) ) ) ) ) ) ;; 1,2,3,4,5,6,7,8,9,21,10,11,12,13,44,14,15,16,17,18,100,19,20,22,23,24, (defineperm1 (A094280 n) (cond ((< n 2) n) ((zero? (A025581 (- n 1))) ;; n is triangular, on the trailing edge (let* ((rowindex (A002024 n)) (rowsumsofar (add A094280 (+ (A000217 (- rowindex 1)) 1) (- (A000217 rowindex) 1) ) ) (prevrowsum (A094283 (- rowindex 1))) ) ;; (format #t "rowindex=~a, rowsumsofar=~a, prevrowsum=~a\n" ;; rowindex rowsumsofar prevrowsum ;; ) ;; There are more intelligent ways to do this: (... ;-) ;; (let loop ((i (luuA094280 (- n 1)))) ;; (if (and (> (+ rowsumsofar i) prevrowsum) ;; Differs from A076105. ;; (zero? (modulo (+ rowsumsofar i) prevrowsum)) ;; ) ;; i ;; (loop (+ i 1)) ;; ) ;; ) (let loop ((i (modulo (- rowsumsofar) prevrowsum))) (if (and (> (+ i rowsumsofar) prevrowsum) (not-lte? (A122156 i) (- n 1))) i (loop (+ i prevrowsum)) ) ) ) ) (else (luuA094280 (- n 1))) ) ) (define (A094281 n) (A094280 (+ 1 (A000217 (- n 1))))) (define (A094282 n) (A094280 (A000217 n))) (definec (A094283 n) (add A094280 (+ (A000217 (- n 1)) 1) (A000217 n))) (define (A094284 n) (/ (A094283 (+ n 1)) (A094283 n))) (define (A122156 n) (A094280 (- n))) ;; Take values from invcache. Must be computed after A094280 (definec (luuA094280 n) ;; Least natural number which does not occur in A094280(1..n). (if (< n 2) (+ n 1) ;; A094280 begins as 1,2,3,4,5,6,... (let ((prev (luuA094280 (- n 1)))) (cond ((not (= (A094280 n) prev)) prev) (else (let loop ((i (+ 1 prev))) (cond ((not-lte? (A122156 i) n) i) (else (loop (+ 1 i))) ) ) ) ) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; CatTrianglDirect := (r,m) -> `if`((m < 0),0,((r-m+1)*(r+m)!)/(r! * m! * (r+1))); ;; A009766 gives also: ;; a(n,m) = C(n+m,n)*(n-m+1)/(n+1), n >= m >= 0. (define (A009766tr r m) (if (or (> m r) (< m 0)) 0 ;; Maybe we should raise an error instead?! (/ (* (1+ (- r m)) (! (+ r m))) (* (! r) (! m) (1+ r)) ) ) ) (define (A009766 n) (A009766tr (A003056 n) (A002262 n))) ;; ;; (definec (A0similarv2 n) (convolve (lambda (n) (if (zero? n) 1 (A000045 n))) A000108 n)) ;; ;; (definec (A0similarv3 n) ;; (if (zero? n) ;; 1 ;; (convolve (compose-funs A000045 1+) (compose-funs A000108 1+) (- n 1)) ;; ) ;; ) ;; ;; (map a0similarv2 (iota0 20)) ;; (1 2 4 10 26 73 217 677 2192 7302 24860 86086 302162 1072362 3840952 13865259 50389441 184204645 676875116 2498698161 9262054997) ;; (map a0similarv3 (iota0 20)) ;; (1 1 3 9 26 77 235 741 2406 8009 27211 94006 329229 1166135 4169804 15030784 54558258 199233832 731430790 2697927812 9993479022) (define A014137 (PARTIALSUMS 0 0 A000108)) (define A014138 (PARTIALSUMS 1 1 A000108)) ;; (definec (A014137 n) ;; Partial sums of A000108: 1,2,4,9,23,65,197,... ;; (if (zero? n) ;; 1 ;; (+ (A014137 (-1+ n)) (A000108 n)) ;; ) ;; ) ;; ;; This for the old starting offset: ;; (define (A014138 n) (-1+ (A014137 (1+ n)))) ;; (map A072643 (iota0 23)) ;; n occurs (A000108 n) times. ;; --> (0 1 2 2 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5) ;; Was defined with definec, but without reason: (define (A072643 n) (first_pos_with_funs_val_gte A014137 (1+ n))) ;; Was ranks_w/2 (define (A000245 n) (- (A000108 (1+ n)) (A000108 n))) ;; Most of these are "unnecessary", except A081288, A081291 and A081292. (definec (A081288 n) (first_pos_with_funs_val_gte A000108 (1+ n))) (define (A081289 n) (if (zero? n) n (+ (A014137 (-1+ (A081288 n))) (A000108 (-1+ (A081288 n)))))) (define (A081290 n) (first_pos_with_funs_val_gte A081289 (A081289 n))) (define (A081290v2 n) (if (zero? n) n (A000108 (-1+ (A081288 n))))) (define (A081291 n) (if (zero? n) n (+ (A014137 (-1+ (A081288 n))) n))) (define (A081291v2 n) (+ (A081289 n) (- n (A081290 n)))) (define (A130380 n) (floor->exact (/ (+ (A000108 n) 1) 2))) ;; In gatomain.scm: (define (A081292 n) (A014486 (A081291 n))) (define (A081293 n) (+ (A014137 n) (A000108 n))) (define (A081289v2 n) (if (zero? n) n (A081293 (-1+ (A081288 n))))) ;; A081291 = 0 3 6 7 8 14 15 16 17 18 19 20 21 22 37 38 39 40 41 42 43 ;; More. 82852 --- 82861 reserved. (define (A082852 n) (if (zero? n) 0 (A014137 (-1+ (A072643 n))))) (define (A082853 n) (- n (A082852 n))) (define (A082854 n) (1+ (A082853 n))) ;; A082852 = (0 1 2 2 4 4 4 4 4 9 9 9 9 9 9 9 9 9 9 9 9 9 9 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65) ;; A082853 = (0 0 0 1 0 1 2 3 4 0 1 2 3 4 5 6 7 8 9 10 11 12 13 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55) ;; A014137(n) occurs A000245(n) times. (define (A082855 n) (if (< n 2) n (A014137 (-1+ (A081288 (-1+ n)))))) (define (A081291v3 n) (if (zero? n) n (+ (A082855 (1+ n)) n))) ;; (define A001477v3 (compose-funs A082853 A001477 A081291)) ;; (define A072619v2 (compose-funs A082853 A072088 A081291)) ;; (define A038776v2 (compose-funs A082854 A057117 A081291)) ;; ;; (define (A072088v2 n) (+ (A072619 (A082853 n)) (A082852 n))) ;; A081291 A081289 A081288 A081290 ;; 0 0 0 0 0 ;; ;; 1 3 3 0 2 1 ;; ;; 2 6 6 0 3 2 ;; 3 7 6 1 3 2 ;; 4 8 6 2 3 2 ;; ;; 5 14 14 0 4 5 ;; 6 15 14 1 4 5 ;; 7 16 14 2 4 5 ;; 8 17 14 3 4 ;; 9 18 14 4 4 First pos i where (A081289(i) >= A081289(9)) = 5. ;; 10 19 14 5 4 ;; 11 20 14 6 4 ;; 12 21 14 7 4 ;; 13 22 14 8 4 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Note that: A153141(14)=10, A006068(14)=11 (define (A153141 n) (if (< n 2) n (let loop ((maskbit (A072376 n)) (z n)) (cond ((zero? maskbit) z) ((not (zero? (modulo (floor->exact (/ n maskbit)) 2))) (- z maskbit) ;; Found first 1-bit, complement it, and return ) (else (loop (floor->exact (/ maskbit 2)) (+ z maskbit))) ) ) ) ) ;; Note that A153142(10)=14, while A003188(10)=15 (define (A153142 n) (if (< n 2) n (let loop ((maskbit (A072376 n)) (z n)) (cond ((zero? maskbit) z) ((zero? (modulo (floor->exact (/ n maskbit)) 2)) (+ z maskbit) ;; Found first 0-bit, complement it, and return ) (else (loop (floor->exact (/ maskbit 2)) (- z maskbit))) ) ) ) ) (define A153150 (compose-funs A059893 A056539 A059893)) ;; Abridged/rotated binary decrementing! (define (A153151 n) (cond ((< n 2) n) ((pow2? n) (- (* 2 n) 1)) (else (- n 1)))) ;; Abridged/rotated binary incrementing! (define (A153152 n) (cond ((< n 2) n) ((pow2? (1+ n)) (/ (1+ n) 2)) (else (1+ n)))) (define A153153 (compose-funs A059893 A003188 A059893)) (define A153154 (compose-funs A059893 A006068 A059893)) (define (A153151v2 n) (if (< n 2) n (let loop ((uplim (A053644 n)) (maskbit 1) (z n)) (cond ((= uplim maskbit) z) ((not (zero? (modulo (floor->exact (/ n maskbit)) 2))) (- z maskbit) ;; Found first 1-bit, complement it, and return ) (else (loop uplim (* maskbit 2) (+ z maskbit))) ) ) ) ) (define (A153152v2 n) (if (< n 2) n (let loop ((uplim (A053644 n)) (maskbit 1) (z n)) (cond ((= uplim maskbit) z) ((not (zero? (modulo (floor->exact (/ n maskbit)) 2))) (+ z maskbit) ;; Found first 0-bit, complement it, and return ) (else (loop uplim (* maskbit 2) (- z maskbit))) ) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; New ones, Jan 10 2009 onward: ;; From: ;; Bondarenko, Grigorchuk, Kravchenko, Muntyan, Nekrashevych, Savchuk, Sunic, ;; Classification of groups generated by 3-state automata over ;; a 2-letter alphabet, pp. 8--9 & 103. ;; http://arxiv.org/abs/0803.3555 ;; (find-matching-anum (catfun1 (psi Alamplighter1a)) 2055) --> "A122302" ;; (find-matching-anum (catfun1 (psi Alamplighter2a)) 2055) --> "A122301" ;; ;; (compose-funs A059893 Alamplighter1a A059893) ;; ;; (compose-funs A059893 Alamplighter2a A059893) ;; not present. ;; Here are the 50 A-numbers you requested: A154434 --- A154483. ;; ;; First one on page 104, inverse of the third one: ;; Also A054429-conjugate of the fourth one: ;; (compose-funs A054429 Alamplighter1a A054429) = Alamplighter4a ;; (A054429 A003188 A054429) (define (A154436 n) ;; Alamplighter1a (if (< n 2) n (let loop ((maskbit (A072376 n)) (state 1) (z 1)) (if (zero? maskbit) z (let ((dombit (modulo (floor->exact (/ n maskbit)) 2))) (cond ((= state dombit) (loop (floor->exact (/ maskbit 2)) (- 1 state) (+ z z (modulo (- state dombit) 2)) ) ) (else (loop (floor->exact (/ maskbit 2)) state (+ z z (modulo (- state dombit) 2)) ) ) ) ) ) ) ) ) ;; Third one on the page 104, inverse of the above one: ;; A054429-conjugate of the next one ;; (compose-funs A054429 Alamplighter3a A054429) = Alamplighter2a ;; (A054429 A006068 A054429) (define (A154435 n) ;; Alamplighter2a (if (< n 2) n (let loop ((maskbit (A072376 n)) (state 1) (z 1)) (if (zero? maskbit) z (let ((dombit (modulo (floor->exact (/ n maskbit)) 2))) (cond ((= 0 dombit) (loop (floor->exact (/ maskbit 2)) (- 1 state) (+ z z (modulo (- state dombit) 2)) ) ) (else (loop (floor->exact (/ maskbit 2)) state (+ z z (modulo (- state dombit) 2)) ) ) ) ) ) ) ) ) (define A154438 (compose-funs A059893 A154436 A059893)) ;; (A054429 A153153 A054429) (define A154437 (compose-funs A059893 A154435 A059893)) ;; (A054429 A153154 A054429) ;; Second one on the page 104. = A006068 (define (Alamplighter3a n) (if (< n 2) n (let loop ((maskbit (A072376 n)) (state 1) (z 1)) (if (zero? maskbit) z (let ((dombit (modulo (floor->exact (/ n maskbit)) 2))) (cond ((= 1 dombit) (loop (floor->exact (/ maskbit 2)) (- 1 state) (+ z z (modulo (- state dombit) 2)) ) ) (else (loop (floor->exact (/ maskbit 2)) state (+ z z (modulo (- state dombit) 2)) ) ) ) ) ) ) ) ) ;; Fourth one on page 104, inverse of the second one: = A003188 ;; It's clear that this is (n XOR (n>>1)). (define (Alamplighter4a n) (if (< n 2) n (let loop ((maskbit (A072376 n)) (state 1) (z 1)) (if (zero? maskbit) z (let ((dombit (modulo (floor->exact (/ n maskbit)) 2))) (cond ((not (= state dombit)) (loop (floor->exact (/ maskbit 2)) (- 1 state) (+ z z (modulo (- state dombit) 2)) ) ) (else (loop (floor->exact (/ maskbit 2)) state (+ z z (modulo (- state dombit) 2)) ) ) ) ) ) ) ) ) ;; A154439 = (compose-funs A054429 A154443 A054429) (defineperm1 (A154439 n) ;; Abasilica1a (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 0) (z n)) (cond ((zero? maskbit) z) ((zero? (modulo (floor->exact (/ n maskbit)) 2)) (+ z (* p maskbit)) ;; Found first 0-bit, complement it ;; if at even distance from msb, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (- z (* p maskbit)) ) ) ) ) ) ) ;; A154440 = (compose-funs A054429 A154446 A054429) (define (A154440 n) (A154439 (- n))) ;; Abasilica1aINV ;; A154441 = (compose-funs A054429 A154445 A054429) (defineperm1 (A154441 n) ;; Abasilica1b (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 1) (z n)) (cond ((zero? maskbit) z) ((zero? (modulo (floor->exact (/ n maskbit)) 2)) (+ z (* p maskbit)) ;; Found first 0-bit, complement it ;; if at odd distance from msb, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (- z (* p maskbit)) ) ) ) ) ) ) ;; A154442 = (compose-funs A054429 A154446 A054429) (define (A154442 n) (A154441 (- n))) ;; Abasilica1bINV (defineperm1 (A154443 n) ;; Abasilica2a (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 0) (z n)) (cond ((zero? maskbit) z) ((not (zero? (modulo (floor->exact (/ n maskbit)) 2))) (- z (* p maskbit)) ;; Found first 1-bit, complement it ;; if at odd distance, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (+ z (* p maskbit)) ) ) ) ) ) ) (define (A154444 n) (A154443 (- n))) ;; Abasilica2aINV (defineperm1 (A154445 n) ;; Abasilica2b (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 1) (z n)) (cond ((zero? maskbit) z) ((not (zero? (modulo (floor->exact (/ n maskbit)) 2))) (- z (* p maskbit)) ;; Found first 1-bit, complement it ;; if at odd distance, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (+ z (* p maskbit)) ) ) ) ) ) ) (define (A154446 n) (A154445 (- n))) ;; Abasilica2bINV ;; These are inverses of each other: (define (A154448 n) (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 1) (z n)) (cond ((zero? maskbit) z) ((= p (modulo (floor->exact (/ n maskbit)) 2)) (+ z (* (- 1 (* 2 p)) maskbit)) ;; Found first bit ;; equal to p, complement it if at odd distance, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (- z (* (- 1 (* 2 p)) maskbit)) ) ) ) ) ) ) (define (A154447 n) (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 0) (z n)) (cond ((zero? maskbit) z) ((= p (modulo (floor->exact (/ n maskbit)) 2)) (+ z (* (- 1 (* 2 p)) maskbit)) ;; Found first bit ;; equal to p, complement it if at odd distance, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (- z (* (- 1 (* 2 p)) maskbit)) ) ) ) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define Feb2006-list-d (list (list 116623 "a(0)=1, a(2n) = a(n)+A000079(A000523(2n)), a(2n+1) = 3*a(n) + A000079(A000523(2n+1)+1)." '(keywords: "tabf") '(off: 0) '(upto: 129) '(comps: (116640 059893)) '(c: "Viewed as a binary tree, this is (1); 5; 7,19; 11,29,23,65; ..." " Related to the parity vectors of Terras trajectories." ) '(y: "a(A000225(n)) = A001047(n+1), for n>= 1 a(A000079(n)) = A062709(n+1)." " A116641 gives the terms in ascending order and without duplicates." ) '(scheme: "(define (A116623 n) (cond ((zero? n) 1) ((even? n) (+ (A116623 (/ n 2)) (expt 2 (A000523 n)))) (else (+ (* 3 (A116623 (/ (- n 1) 2))) (expt 2 (+ 1 (A000523 n)))))))") ) (list 116640 "a(n) = A116623(A059893(n))." '(keywords: "tabf") '(off: 0) '(upto: 129) '(comps: (116623 059893)) '(c: "Viewed as a binary tree, this is (1); 5; 7,19; 11,23,29,65; ... C.f. A116623." ) '(y: "a(A000225(n)) = A001047(n+1), for n>= 1 a(A000079(n)) = A062709(n+1).") ) (list 116641 "A116623 sorted, without duplicates." '(off: 0) '(upto: 129) '(c: "Related to the parity vectors of Terras and Collatz trajectories.") '(y: "A116642 gives the same sequence in binary.") ) (list 116642 "A116641 in binary." '(off: 0) '(keywords: "base") '(comps: (007088 116641)) '(upto: 129) ) (list 116628 "Positions where A116624 is a power of 2." '(y: "Conjecture: all the powers of 2 occur in A116624, in ascending order, in which case A116624(a(n)) = A000079(n-1). Checked up to n=13." ) '(off: 1) '(upto: 11) ) (list 116624 "a(1)=1; for n>1, a(n) = least positive integer not appearing earlier such that {a(k)|1== 1, and i < 2^k), a(n) = 2^(k+1) - i = 2*A053644(n) - A053645(n).") '(y: "A054429, A122198, A122199") '(scheme: "(define (A122155 n) (cond ((< n 1) n) ((pow2? n) n) (else (- (* 2 (A053644 n)) (A053645 n)))))" ) ) (list 122198 "Permutation of natural numbers: A recursed variant of A122155." '(off: 0) '(indentries: Nperm) '(f: "a(0)=0, otherwise a(n) = A122155(A053644(n)+a(A053645(n))).") '(c: "Maps between A096115 and A096111.") '(inv: 122199) '(scheme: "(define (A122198 n) (if (< n 1) n (A122155 (+ (A053644 n) (A122198 (A053645 n))))))" ) ) (list 122199 "Permutation of natural numbers: A recursed variant of A122155." '(off: 0) '(indentries: Nperm) '(f: "a(0)=0, otherwise a(n) = A053644(A122155(n)) + a(A053645(A122155(n))).") '(c: "Maps between A096111 and A096115.") '(inv: 122198) '(scheme: "(define (A122199 n) (if (< n 1) n (let ((m (A122155 n))) (+ (A053644 m) (A122199 (A053645 m))))))" ) ) (list 096111 "If n=(2^k)-1, a(n)=k+1, otherwise a(n)=(A000523(n)+1)*a(A053645(n))." '(off: 0) '(y: "Bisection: A121663. C.f. A004198.") '(scheme: "(define (A096111 n) (cond ((pow2? (+ n 1)) (+ 2 (A000523 n))) (else (* (+ 1 (A000523 n)) (A096111 (A053645 n))))))") '(scheme: "(define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1)))))") ) (list 121663 "a(0)=1; if n=2^k, a(n)=k+2, otherwise a(n)=(A000523(n)+2)*a(A053645(n))." '(off: 0) '(y: "Bisection of A096111. C.f. A004198.") '(scheme: "(define (A121663 n) (cond ((zero? n) 1) ((pow2? n) (+ 2 (A000523 n))) (else (* (+ 2 (A000523 n)) (A121663 (A053645 n))))))") '(scheme: "(define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1)))))") ) (list 096114 "Insert formula here." '(off: 1) '(indentries: Nperm) '(inv: 121664) '(scheme: "(define (A096114 n) (cond ((< n 3) n) ((and (zero? (modulo n 3)) (pow2? (/ n 3))) n) (else (let ((lastfix (* 3 (expt 2 (A000523 (floor->exact (/ n 3))))))) (+ lastfix (A096114 (- (* 2 lastfix) n)))))))" ) ) (list 121664 "Permutation of natural numbers formed by ..." '(off: 1) '(indentries: Nperm) '(inv: 096114) '(scheme: "") ) (list 096115 "If n=(2^k)-1, a(n)=k, if n=2^k, a(n)=a(n-1)+1 = k+1, otherwise a(n)=(A000523(n)+1)*a(A035327(n-1))." '(off: 1) '(scheme: "(define (A096115 n) (cond ((pow2? (+ n 1)) (+ 1 (A000523 n))) ((pow2? n) (+ 1 (A096115 (- n 1)))) (else (* (+ (A000523 n) 1) (A096115 (A035327 (- n 1)))))))" ) ) (list 096116 "a(1)=1, if n=(2^k)+1, a(n)=k+2, otherwise a(n)=2+A000523(n-1)+a(2+A035327(n-1))." '(off: 1) '(scheme: "(define (A096116 n) (cond ((= 1 n) 1) ((pow2? (- n 1)) (+ 2 (A000523 (- n 1)))) (else (+ 2 (A000523 (- n 1)) (A096116 (+ 2 (A035327 (- n 1))))))))" ) ) (list 096119 "A050029(2^n + 1)." '(off: 0) ;; '(c: "Terms of A050029 which are 1 more than the previous term. (NOT ALL OF THEM!)") '(upto: 14) ) (list 076105 "Permutation of natural numbers formed by ..." '(off: 1) '(upto: 600) '(indentries: Nperm) '(keywords: "tabl") '(inv: 122154) '(y: "Permutation A094280 is defined almost similarly.") '(scheme: "") ) (list 122154 "Inverse permutation to A076105." '(off: 1) '(indentries: Nperm) '(inv: 076105) '(y: "Differs from A122156 for the first time at n=47 where a(n)=28, while A122156(n)=51.") '(scheme: "") ) (list 094280 "Permutation of natural numbers formed by ..." '(off: 1) '(upto: 512) '(indentries: Nperm) '(keywords: "tabl") ;; '(inv: 122156) '(y: "Inverse: A122156. Permutation A076105 is defined almost similarly. C.f. A094281, A094282, A094283, A094284.") '(scheme: "") ) (list 122156 "Inverse permutation to A094280." '(off: 1) '(indentries: Nperm) '(inv: 094280) '(y: "Differs from A122154 for the first time at n=47 where a(n)=51, while A122154(n)=28.") ) (list 094281 "The leftmost column of triangle A094280." '(off: 1) '(f: "a(n) = A094280(1+A000217(n-1)).") '(y: "A094280, A094282, A094283, A094284.") ) (list 094282 "The rightmost column of triangle A094280." '(off: 1) '(f: "a(n) = A094280(A000217(n)).") '(y: "A094280, A094281, A094283, A094284.") ) (list 094283 "Row sums of triangle A094280." '(off: 1) ;; '(upto: 60) '(y: "A094280, A094281, A094282, A094284.") ) (list 094284 "A094283(n+1)/A094283(n)." '(off: 1) ;; '(upto: 59) '(y: "A094280, A094281, A094282, A094283.") ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Lei Zhou's sequences: ;; Needs either GF2Xfuns from this same directory ;; or (load "c:\\slib\\mitscheme.init") ;; and (require 'factor) ;; (for prime? function, and factor) ;; (Offset=4) ;; %S A103151 1,1,2,1,3,2,2,2,3,3,4,2,4,2,4,4,4,4,5,3,4,6,5,3,6,3,3,6,6,5,7, ; Number of decompositions of 2n+1 into ordered sums of one odd prime and two times another odd prime. ;; a(n) = count of all eligible p1 for 2n+1 = 2*p1 + p2; where p1 and p2 are prime numbers. (definec (A103151 n) (let loop ((i 2) (z 0)) (let ((p1 (A000040 i))) (cond ((>= p1 n) z) ((prime? (+ 1 (* 2 (- n p1)))) (loop (+ 1 i) (+ 1 z))) (else (loop (+ 1 i) z)) ) ) ) ) ;; Another variant: (definec (A103151v2 n) (let ((o (+ (* 2 n) 1))) (let loop ((i 2) (z 0)) (let ((p2 (A000040 i))) (cond ((> p2 (- o 6)) z) ((prime? (/ (- o p2) 2)) (loop (+ 1 i) (+ 1 z))) (else (loop (+ 1 i) z)) ) ) ) ) ) ;; %N A103152 Smallest odd number which is the sum of an odd prime and twice another odd prime ;; (can be equal to the first) in exactly n ways. (definec (A103152 n) (+ 1 (* 2 (first-n-where-fun_n-is-i1 A103151 n)))) ;; %N A103507 Index of the smallest prime in decomposition of 2n+1 into sum of twice of this odd ;; prime and another odd prime. (and 0 if no such prime exists). ;; %F A103507 PrimePi[A103153] (definec (A103507 n) (let loop ((i 2)) (let ((p1 (A000040 i))) (cond ((>= p1 n) 0) ((prime? (+ 1 (* 2 (- n p1)))) i) (else (loop (+ 1 i))) ) ) ) ) ; %N A103153 Smallest prime in decomposition of 2n+1 into sum of twice of this prime and another prime. ; (and 0 if there are cases where the conjecture given in A103151 does not hold.) ; (and 0 if no such prime exists) (define (A103153 n) (let ((ind (A103507 n))) (if (zero? ind) 0 (A000040 ind)))) (definec (A103509 n) (let ((o (+ (* 2 n) 1))) (let loop ((i 2)) (let ((p2 (A000040 i))) (cond ((> p2 (- o 6)) 0) ((prime? (/ (- o p2) 2)) i) (else (loop (+ 1 i))) ) ) ) ) ) ;; %N A103509 Index of the smallest prime in decomposition of 2n+1 into sum of this odd prime ;; and twice of another odd prime. (and 0 if no such prime exists). (define (A103506 n) (let ((ind (A103509 n))) (if (zero? ind) 0 (A000040 ind)))) ;; Minimum prime p2, such that |A000040(n)-p2| is of the form 2^k. (definec (A130970 n) (let ((p1 (A000040 n))) (let loop ((i 1)) (cond ((pow2? (abs (- p1 (A000040 i)))) (A000040 i)) (else (loop (+ i 1))) ) ) ) ) ;; Minimum prime p2, such that either |A000040(n)-p2| or A000040(n)+p2 is of the form 2^k. (definec (A130971 n) (let ((p1 (A000040 n))) (let loop ((i 1) (p2 2)) (cond ((pow2? (abs (- p1 p2))) p2) ((pow2? (+ p1 p2)) p2) (else (loop (+ i 1) (A000040 (+ i 1)))) ) ) ) ) (define A130972 (RECORD-POS 1 1 A130971)) (define A103150 (RECORD-VALS 1 1 A130971)) (define (A103149 n) (if (= n 1) 3 (A000040 (A130972 n)) ) ) (define A103149v2 (compose-funs A000040 (RECORD-POS 2 2 A130971) 1+)) (definec (A103508 n) (+ 1 (* 2 (first-n-where-fun_n-is-i1 A103507 (+ 1 n))))) (definec (A103510 n) (+ 1 (* 2 (first-n-where-fun_n-is-i1 A103509 (+ 1 n))))) ;; A103149 & A103150: starting offset changed to o=1. ;; (load "GF2Xfuns") ;; (cd "seqs/batch19jun") ;; (output-entries-to-file120_45 seqs2007Jun19 "2007Jun19.scm" "Jun 19 2007") (define seqs2007Jun19 (list (list 103149 "a(1)=3, a(n) = A000040(A130972(n))." '(off: 1) '(upto: 30) '(y: "A103150.") '(scheme: "(define (A103149 n) (if (= n 1) 3 (A000040 (A130972 n))))") ) (list 103150 "Record values in A130971." '(off: 1) '(upto: 30) '(y: "A103149.") '(comps: (130971 130972)) ) (list 103151 "Number of decompositions of 2n+1 into 2p+q, where p and q are both odd primes (A065091)." '(off: 1) ;; '(upto: 120) '(y: "A103152.") '(c: "Conjecture: all items for n>=4 are greater than or equal to 1. This is a stronger conjecture than the Goldbach conjecture.") ;; By Lei Zhou. (list 'scheme: (string-append "With Aubrey Jaffer's SLIB Scheme library from http://www.swiss.ai.mit.edu/~jaffer/SLIB.html" "\n%o A103151 (define (A103151 n) (let loop ((i 2) (z 0)) (let ((p1 (A000040 i))) (cond ((>= p1 n) z) ((prime? (+ 1 (* 2 (- n p1)))) (loop (+ 1 i) (+ 1 z))) (else (loop (+ 1 i) z))))))" ) ) ) (list 103152 "Smallest odd number which can be written as a sum 2p+q (where p and q are both odd primes, A065091) in exactly n ways, zero if there are no such odd number." '(off: 1) ;; '(upto: 120) '(y: "A103151.") (list 'scheme: (string-append "(define (A103152 n) (+ 1 (* 2 (first-n-where-fun_n-is-i1 A103151 n))))" "\n%o A103152 (define (first-n-where-fun_n-is-i1 fun i) (let loop ((n 1)) (cond ((= i (fun n)) n) (else (loop (+ n 1))))))" ) ) ) (list 103153 "a(n) = Smallest prime p, such that 2n+1 = 2*p + A000040(k) for some k>1, 0 if no such prime exists." '(off: 1) ;; '(comps: (000040 103507)) '(y: "a(n)=0 if A103507(n)=0, otherwise A000040(A103507(n)).") (list 'scheme: (string-append "(define (A103153 n) (let ((ind (A103507 n))) (if (zero? ind) 0 (A000040 ind))))" ) ) ) (list 103506 "a(n) = Smallest prime p, such that 2n+1 = 2*A000040(k) + p for some k>1, 0 if no such prime exists." '(off: 1) ;; '(comps: (000040 103509)) '(y: "a(n)=0 if A103509(n)=0, otherwise A000040(A103509(n)).") (list 'scheme: (string-append "(define (A103506 n) (let ((ind (A103509 n))) (if (zero? ind) 0 (A000040 ind))))" ) ) ) (list 103507 "a(n) = Least i, such that 2n+1 = 2*A000040(i)+A000040(k) for some k>1, 0 if no such i exists." '(off: 1) '(upto: 29) ;; '(c: "That is, least i>1, for which A049084(2*(n-A000040(i)) + 1) > 0") ;; '(comps: (049084 103153)) '(y: "a(n) = A049084(A103153(n)), for n >= ... Used to compute A103153 and A103508. Cf. A103509.") (list 'scheme: (string-append "(define (A103507 n) (let loop ((i 2)) (let ((p1 (A000040 i))) (cond ((>= p1 n) 0) ((prime? (+ 1 (* 2 (- n p1)))) i) (else (loop (+ 1 i)))))))" ) ) ) (list 103508 "a(n) = 1 + 2 * least i such that A103507(i)=n+1, 0 if no such i exists." '(off: 1) '(upto: 20) '(y: "A103510.") (list 'scheme: (string-append "(define (A103508 n) (+ 1 (* 2 (first-n-where-fun_n-is-i1 A103507 (+ 1 n)))))" "\n%o A103508 (define (first-n-where-fun_n-is-i1 fun i) (let loop ((n 1)) (cond ((= i (fun n)) n) (else (loop (+ n 1))))))" ) ) ) (list 103509 "a(n) = Least i, such that 2n+1 = 2*A000040(k)+A000040(i) for some k>1, 0 if no such i exists." '(off: 1) '(upto: 29) ;; '(c: "That is, least i>1, for which A049084(2*(n-A000040(i)) + 1) > 0") ;; '(comps: (049084 103153)) '(y: "a(n) = A049084(A103153(n)), for n >= ... Used to compute A103506 and A103510. Cf. A103507.") (list 'scheme: (string-append "(define (A103509 n) (let ((o (+ (* 2 n) 1))) (let loop ((i 2)) (let ((p2 (A000040 i))) (cond ((> p2 (- o 6)) 0) ((prime? (/ (- o p2) 2)) i) (else (loop (+ 1 i))))))))" ) ) ) (list 103510 "a(n) = 1 + 2 * least i such that A103509(i)=n+1, 0 if no such i exists." '(off: 1) '(upto: 20) '(y: "A103508.") (list 'scheme: (string-append "(define (A103510 n) (+ 1 (* 2 (first-n-where-fun_n-is-i1 A103509 (+ 1 n)))))" "\n%o A103510 (define (first-n-where-fun_n-is-i1 fun i) (let loop ((n 1)) (cond ((= i (fun n)) n) (else (loop (+ n 1))))))" ) ) ) (list 130970 "Smallest prime p, such that |A000040(n)-p| is of the form 2^k." '(off: 1) '(y: "A130971.") (list 'scheme: (string-append "(define (A130970 n) (let ((p1 (A000040 n))) (let loop ((i 1)) (cond ((pow2? (abs (- p1 (A000040 i)))) (A000040 i)) (else (loop (+ i 1)))))))" "(define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1)))))" ) ) ) (list 130971 "Smallest prime p, such that either |A000040(n)-p| or A000040(n)+p is of the form 2^k." '(off: 1) '(y: "A130971, A130972, A103150.") (list 'scheme: (string-append "(define (A130971 n) (let ((p1 (A000040 n))) (let loop ((i 1) (p2 2)) (cond ((pow2? (abs (- p1 p2))) p2) ((pow2? (+ p1 p2)) p2) (else (loop (+ i 1) (A000040 (+ i 1))))))))" "(define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1)))))" ) ) ) (list 130972 "Record positions in A130971." '(off: 1) '(upto: 40) '(y: "A103149, A103150.") ) ) ) ;; Here are the 10 A-numbers you requested: A140259 --- A140268. (definec (A140259 n) (cond ((zero? n) 3) ((= 1 (A140259 (- n 1))) (A002264 (+ n 11))) ((not (zero? (modulo (- n 1) 3))) (- (A140259 (- n 1)) 1)) (else (A140259 (- n 1))) ) ) (define A140260 (MATCHING-POS 0 0 (lambda (i) (= (A140259 i) (A002264 (+ i 11)))))) (define (A140261 n) (A140259 (A140260 n))) (define (A140262 n) (modulo (A140260 n) 9)) (define seqs2008May16 (list ;; %H A140259 Nicolau Werneck, Adaptoide, a library for adaptive finite automata. Source code in C++ available. ;; %H A140259 Nicolau Werneck, The Black Pearl Necklace, description of the problem. ;; %H A140259 Nicolau Werneck, et al. Discussion on the NKS Forum (list 140259 "a(0)=3; a(n)=A002264(n+11) if a(n-1)=1, a(n) = a(n-1)-1 if (n-1) mod 3 <> 0, otherwise a(n-1)." '(off: 0) '(c: "Position of the knot after each iteration in Werneck's Black Pearl Necklace problem.") '(y: "A134342, A140260, A140261.") '(scheme: "(define (A140259 n) (cond ((zero? n) 3) ((= 1 (A140259 (- n 1))) (A002264 (+ n 11))) ((not (zero? (modulo (- n 1) 3))) (- (A140259 (- n 1)) 1)) (else (A140259 (- n 1)))))") ) (list 140260 "Positions n where A140259(n) = A002264(n+11)" '(off: 0) '(upto: 23) '(c: "These are the iterations where the knot comes to the front of the necklace in Werneck's Black Pearl Necklace problem.") '(y: "A134342, A140261, A140262.") ) (list 140261 "The length of Sapro's necklace at successive years in Werneck's Black Pearl Necklace problem." '(off: 0) '(upto: 23) '(comps: (140259 140260)) '(y: "A134342.") ) (list 140262 "A140260 reduced modulo 9." '(off: 0) '(upto: 23) '(y: "A134342.") ) ) ) (define (A117966 n) ;; 0,1,-1,3,4,2,-3,-2,-4,9,10,8,12,... (let loop ((z 0) (i 0) (n n)) (if (zero? n) z (loop (+ z (* (expt 3 i) (if (= 2 (modulo n 3)) -1 (modulo n 3)))) (1+ i) (floor->exact (/ n 3)) ) ) ) ) ;; When applied to natural numbers >= 1, gives: ;; i.e. a bisection of the next sequence. ;; Inverse of A117966: ;; (map A117967 (map A117966 (iota0 729))) = (iota0 729) ;; Gives a non-negative integer, which when converted to ternary ;; and interpreted as _balanced ternary_, is equal to argument z. ;; When restricted to non-negative integers, gives A117967. (define (A117967 z) (cond ((zero? z) 0) ((negative? z) (A004488 (A117967 (- z)))) (else ;; z is positive. (let* ((lp3 (expt 3 (A062153 z))) ;; largest power of three of z. (np3 (* 3 lp3)) ;; Next Power of Three. ) (if (< (* 2 z) np3) ;; z less than np3/2 (+ lp3 (A117967 (- z lp3))) (+ np3 (A117967 (- z np3))) ) ) ) ) ) ;; Based on Frank's: ;; a(0) = 0, a(3n) = 3a(n), a(3n+1) = 3a(n)+1, a(3n-1) = 3a(n)+2. (define (A117967v2 z) (cond ((zero? z) 0) ((negative? z) (A004488 (A117967v2 (- z)))) ((zero? (modulo z 3)) (* 3 (A117967v2 (/ z 3)))) ((= 1 (modulo z 3)) (+ (* 3 (A117967v2 (/ (- z 1) 3))) 1)) (else (+ (* 3 (A117967v2 (/ (+ z 1) 3))) 2)) ;; z = 2 (= -1) modulo 3. ) ) (define (A117968 n) (A117967 (- n))) ;; (define (A117968v2 n) (A004488 (A117967 n))) (define (A140263 n) (A117967 (A001057 n))) ;; Zero-based. (define (A140264 n) (- (A140266 (+ 1 n)) 1)) (define (A140265 n) (+ 1 (A140263 (- n 1)))) ;; One-based. (define (A140266 n) (Z->N (A117966 (- n 1)))) (define (A140267 n) (A007089 (A117967 n))) ;; 1,12,10,11,122,120,121,102,100 ;; 2,21,20,22,211,210,212,201,200,202,221,220,222,2111,2110,2112,2101,2100,... (define (A140268 n) (A007089 (A117968 n))) (define seqs2008May18 (list (list 117966 "Balanced ternary enumeration of integers; write n in ternary, and then replace 2's with (-1)'s." '(off: 0) '(create-b-file: 729) '(scheme: "(define (A117966 n) (let loop ((z 0) (i 0) (n n)) (if (zero? n) z (loop (+ z (* (expt 3 i) (if (= 2 (modulo n 3)) -1 (modulo n 3)))) (1+ i) (floor->exact (/ n 3))))))" ) ) (list 117967 "Positive part of inverse of A117966; write n in balanced ternary, and then replace (-1)'s with 2's." '(off: 0) '(f: "a(0) = 0, a(3n) = 3a(n), a(3n+1) = 3a(n)+1, a(3n-1) = 3a(n)+2. [ AK added this clause, so that the function is now defined on the whole Z: If n<0, then a(n) = A004488(a(-n)) (i.e. A117968(-n))].") '(y: "Bisection of A140263. A140267 gives the same sequence in ternary.") '(comps: (004488 117968)) '(scheme: (string-append "(define (A117967 z) (cond ((zero? z) 0) ((negative? z) (A004488 (A117967 (- z)))) (else (let* ((lp3 (expt 3 (A062153 z))) (np3 (* 3 lp3))) (if (< (* 2 z) np3) (+ lp3 (A117967 (- z lp3))) (+ np3 (A117967 (- z np3))))))))\n" "(define (A117967v2 z) (cond ((zero? z) 0) ((negative? z) (A004488 (A117967v2 (- z)))) ((zero? (modulo z 3)) (* 3 (A117967v2 (/ z 3)))) ((= 1 (modulo z 3)) (+ (* 3 (A117967v2 (/ (- z 1) 3))) 1)) (else (+ (* 3 (A117967v2 (/ (+ z 1) 3))) 2))))" ) ) ) (list 117968 "Negative part of inverse of A117966; write -n in balanced ternary, and then replace (-1)'s with 2's." '(off: 1) '(y: "Bisection of A140263. A140268 gives the same sequence in ternary.") '(comps: (004488 117967)) ) (list 140263 "Permutation of non-negative integers obtained by interleaving A117967 and A117968." '(f: "a(n) = A117967(A001057(n)).") '(off: 0) '(indentries: Nperm) '(create-b-file: 2186) '(inv: 140264) '(comps: (117967 001057)) '(y: "Bisections: A117967 & A117968. a(n) = A140265(n+1)-1.") '(scheme: "(define (A140263 n) (A117967 (A001057 n)))") ) (list 140264 "Inverse permutation of A140263." '(f: "a(n) = A140266(n+1)-1.") '(off: 0) '(indentries: Nperm) '(inv: 140263) '(scheme: "(define (A140264 n) (- (A140266 (+ 1 n)) 1))") ) (list 140265 "Permutation of natural numbers: a(n) = A140263(n-1)+1." '(off: 1) '(indentries: Nperm) '(inv: 140266) '(scheme: "(define (A140265 n) (+ 1 (A140263 (- n 1))))") ) (list 140266 "Inverse permutation of A140265." '(off: 1) '(indentries: Nperm) '(create-b-file: 729) '(inv: 140265) '(f: "a(n) = Z->N(A117966(n-1)), where Z->N(z) = 2z if z>0 else 2|z|+1.") '(y: "a(n) = A140264(n-1)+1.") '(scheme: (string-append "(define (A140266 n) (Z->N (A117966 (- n 1))))\n" "(define (Z->N n) (if (positive? n) (* n 2) (+ 1 (* 2 (- n)))))" ) ) ) (list 140267 "Non-negative integers presented in balanced ternary system." '(c: "Sequence A117967 in ternary.") '(off: 0) '(comps: (007089 117967)) ) (list 140268 "Negative integers presented in balanced ternary system." '(c: "Sequence A117968 in ternary.") '(off: 1) '(comps: (007089 117968)) ) ) ) (define seqs2008Dec19 (list (list 153150 "Self-inverse permutation of natural numbers: A059893-conjugate of A056539." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 153150) '(comps: (59893 56539 59893)) ) (list 153151 "Rotated binary decrementing: For n<2 a(n)=n, if n=2^k, a(n)=(2n)-1, otherwise a(n)=n-1." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 153152) '(comps: (59893 153141 59893) (59894 153142 59894)) '(scheme: "(define (A153151 n) (cond ((< n 2) n) ((pow2? n) (- (* 2 n) 1)) (else (- n 1)))) (define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1)))))" ) ) (list 153152 "Rotated binary incrementing: For n<2 a(n)=n, if n=(2^k)-1, a(n)=(n+1)/2, otherwise a(n)=n+1." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 153151) '(comps: (59893 153142 59893) (59894 153141 59894)) '(scheme: "(define (A153152 n) (cond ((< n 2) n) ((pow2? (1+ n)) (/ (1+ n) 2)) (else (1+ n)))) (define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1)))))" ) ) (list 153153 "Permutation of natural numbers: A059893-conjugate of A003188." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 153154) '(comps: (59893 003188 59893)) ) (list 153154 "Permutation of natural numbers: A059893-conjugate of A006068." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 153153) '(comps: (59893 006068 59893)) ) ) ) ;; Sequences: A154436 - A154447 (define (init-them up) (map A154439 (iota0 up)) (map A154441 (iota0 up)) (map A154443 (iota0 up)) (map A154445 (iota0 up)) "A154439 - A154445 safely initialized!" ) ;; 154435 --> A122301 ;; 154436 --> A122302 (define seqs2009Jan17 (list (list 153141 "Permutation of non-negative integers obtained by complementing ...." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 153142) '(comps: (59893 153151 59893) (59894 153152 59894) (154440 154445) (154442 154443) ) ;; '(y: "Differs from A006068 for the first time at n=14, where a(14)=10 while A006068(14)=11. Cf. also A072376.") '(y: "Corresponds to A069767 in the group of Catalan bijections. Cf. also A154435-A154436, A154439-A154448, A072376.") '(scheme: (define (swap-binary-tree-according-to-infbintree-permutation s inftreeperm) (cond ((not (= 1 (inftreeperm 1))) (error ;; Rotten already at the root "Function inftreeperm should return 1 for 1, and it should be one-to-one and onto!" ) ) (else ;; we can proceed: (let fork ((s s) (nod 1)) (cond ((pair? s) (fork (car s) (* 2 nod)) (fork (cdr s) (+ (* 2 nod) 1)) (let ((node-dest (inftreeperm nod)) (left-dest (inftreeperm (* 2 nod))) (right-dest (inftreeperm (1+ (* 2 nod)))) ) (cond ((or (not (= (floor->exact (/ left-dest 2)) node-dest)) (not (= (floor->exact (/ right-dest 2)) node-dest)) ) (error ;; Runaway child(ren)! (format #t "Function inftreeperm is not an automorphism of an infinite binary tree. Either the left or right child flees from its parent: (inftreeperm ~a)=~a. Left: (inftreeperm ~a)=~a, Right: (inftreeperm ~a)=~a.\n" nod node-dest (* 2 nod) left-dest (1+ (* 2 nod)) right-dest ) ) ) ((= (1+ left-dest) right-dest) ;; images in order, so do nothing, no swap! ) (else ;; I.e. (= left-dest (1+ right-dest)) (*A069770! s) ) ) ) ) ) ) s ) ) ) ) ) (list 153142 "Permutation of non-negative integers obtained by complementing ...." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 153141) '(comps: (59893 153152 59893) (59894 153151 59894) (154444 154441) (154446 154439) ) ;; '(y: "Differs from A003188 for the first time at n=10, where a(10)=14 while A003188(10)=15. Cf. also A072376.") '(y: "Corresponds to A069768 in the group of Catalan bijections. Cf. also A154435-A154436, A154439-A154448, A072376.") '(scheme: (define (A153142 n) (if (< n 2) n (let loop ((maskbit (A072376 n)) (z n)) (cond ((zero? maskbit) z) ((zero? (modulo (floor->exact (/ n maskbit)) 2)) (+ z maskbit) ;; Found first 0-bit, complement it, and return ) (else (loop (floor->exact (/ maskbit 2)) (- z maskbit))) ) ) ) ) ) ) ;; (list 154435 "Permutation of non-negative integers induced by Lamplighter group generating wreath recursion, variant 1: a = s(b,a), b = (a,b), starting from the state a." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154436) '(comps: (59893 154437 59893) (54429 6068 54429)) (list 'c: (string-append "This permutation is induced by the first Lamplighter group generating wreath" " recursion (i.e. binary transducer) a = s(b,a), b = (a,b)" " (where s means swap the digits 0 <-> 1)" " given on page 104 of Bondarenko, Grigorchuk, et al. paper," " starting from the active (swapping) state a," " and rewriting bits from the second most significant bit" " to the least significant end." " This wreath recursion corresponds to the automaton given in figure 1" " at page 211 of Grigorchuk and Zuk paper." ) ) '(y: "Corresponds to A122301 in the group of Catalan bijections. Cf. also A153141-A153142, A154439-A154448, A072376.") '(scheme: (define (A154435 n) ;; Alamplighter2a (if (< n 2) n (let loop ((maskbit (A072376 n)) (state 1) (z 1)) (if (zero? maskbit) z (let ((dombit (modulo (floor->exact (/ n maskbit)) 2))) (cond ((= 0 dombit) (loop (floor->exact (/ maskbit 2)) (- 1 state) (+ z z (modulo (- state dombit) 2)) ) ) (else (loop (floor->exact (/ maskbit 2)) state (+ z z (modulo (- state dombit) 2)) ) ) ) ) ) ) ) ) ) ) (list 154436 "Permutation of non-negative integers induced by Lamplighter group generating wreath recursion, variant 3: a = s(a,b), b = (a,b), starting from the state a." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154435) '(comps: (59893 154438 59893) (54429 3188 54429)) (list 'c: (string-append "This permutation is induced by the third Lamplighter group generating wreath" " recursion (i.e. binary transducer) a = s(a,b), b = (a,b)" " (where s means swap the digits 0 <-> 1)" " given on page 104 of Bondarenko, Grigorchuk, et al. paper," " starting from the active (swapping) state a," " and rewriting bits from the second most significant bit" " to the least significant end." " Note that the fourth wreath recursion on page 104 of Bondarenko, et al." " paper induces similarly the binary reflected Gray code A003188" " (A054429-reflected conjugate of this permutation)" " and the second one induces Gray Code's inverse permutation A006068." ) ) '(y: "Corresponds to A122302 in the group of Catalan bijections. Cf. also A153141-A153142, A154439-A154448, A072376.") '(scheme: (define (A154436 n) ;; Alamplighter1a (if (< n 2) n (let loop ((maskbit (A072376 n)) (state 1) (z 1)) (if (zero? maskbit) z (let ((dombit (modulo (floor->exact (/ n maskbit)) 2))) (cond ((= state dombit) (loop (floor->exact (/ maskbit 2)) (- 1 state) (+ z z (modulo (- state dombit) 2)) ) ) (else (loop (floor->exact (/ maskbit 2)) state (+ z z (modulo (- state dombit) 2)) ) ) ) ) ) ) ) ) ) ) (list 154437 "Permutation of non-negative integers: A059893-conjugate of A154435." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154438) '(comps: (59893 154435 59893) (54429 153154 54429)) (list 'c: (string-append "This permutation is induced by the the same Lamplighter group generating" " wreath recursion (binary transducer) as A154435," " starting from the active (swapping) state a," " but in contrast to it, this one rewrites the bits from the" " least significant end up to the second most significant bit." ) ) ) (list 154438 "Permutation of non-negative integers: A059893-conjugate of A154436." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154437) '(comps: (59893 154436 59893) (54429 153153 54429)) (list 'c: (string-append "This permutation is induced by the the same Lamplighter group generating" " wreath recursion (binary transducer) as A154436," " starting from the active (swapping) state a," " but in contrast to it, this one rewrites the bits from the" " least significant end up to the second most significant bit." ) ) ) (list 154439 "Permutation of non-negative integers induced by Basilica group generating wreath recursion, variant 1: a = (1,b), b = s(1,a), starting from the inactive (fixing) state a." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154440) '(comps: (154445 153142) (54429 154443 54429)) (list 'c: (string-append "This permutation is induced by the Basilica group generating wreath" " recursion (binary transducer) a = (1,b), b = s(1,a)" " (where s means swap the digits 0 <-> 1)" " given on the second page of Bartholdi and Virag paper," " starting from the inactive (fixing) state a," " and rewriting bits from the second most significant bit" " to the least significant end." ) ) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154441-A154448. Corresponds to A154449 in the group of Catalan bijections.") '(scheme: (define (A154439 n) ;; Abasilica1a (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 0) (z n)) (cond ((zero? maskbit) z) ((zero? (modulo (floor->exact (/ n maskbit)) 2)) (+ z (* p maskbit)) ;; Found first 0-bit, complement it ;; if at even distance from msb, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (- z (* p maskbit)) ) ) ) ) ) ) ) ) (list 154440 "Permutation of non-negative integers: inverse of A154439." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154439) '(comps: (153141 154446) (54429 154444 54429)) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154442-A154448. Corresponds to A154450 in the group of Catalan bijections.") ) (list 154441 "Permutation of non-negative integers induced by Basilica group generating wreath recursion, variant 1: a = (1,b), b = s(1,a), starting from the active (swapping) state b." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154442) '(comps: (154443 153142) (54429 154445 54429)) (list 'c: (string-append "This permutation is induced by the Basilica group generating wreath" " recursion (binary transducer) a = (1,b), b = s(1,a)" " (where s means swap the digits 0 <-> 1)" " given on the second page of Bartholdi and Virag paper," " starting from the active (switching) state b," " and rewriting bits from the second most significant bit" " to the least significant end." ) ) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154439-A154448. Corresponds to A154451 in the group of Catalan bijections.") '(scheme: (define (A154441 n) ;; Abasilica1b (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 1) (z n)) (cond ((zero? maskbit) z) ((zero? (modulo (floor->exact (/ n maskbit)) 2)) (+ z (* p maskbit)) ;; Found first 0-bit, complement it ;; if at odd distance from msb, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (- z (* p maskbit)) ) ) ) ) ) ) ) ) (list 154442 "Permutation of non-negative integers: inverse of A154441." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154441) '(comps: (153141 154444) (54429 154446 54429)) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154439-A154448. Corresponds to A154452 in the group of Catalan bijections.") ) (list 154443 "Permutation of non-negative integers induced by Basilica group generating wreath recursion, variant 2: a = (b,1), b = s(a,1), starting from the inactive (fixing) state a." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154444) '(comps: (154441 153141) (54429 154439 54429)) (list 'c: (string-append "This permutation is induced by the Basilica group generating wreath" " recursion (binary transducer) a = (b,1), b = s(a,1)" " (where s means swap the digits 0 <-> 1)," " starting from the inactive (fixing) state a," " and rewriting bits from the second most significant bit" " to the least significant end." ) ) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154439-A154448. Corresponds to A154453 in the group of Catalan bijections.") '(scheme: (define (A154443 n) ;; Abasilica2a (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 0) (z n)) (cond ((zero? maskbit) z) ((not (zero? (modulo (floor->exact (/ n maskbit)) 2))) (- z (* p maskbit)) ;; Found first 1-bit, complement it ;; if at odd distance, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (+ z (* p maskbit)) ) ) ) ) ) ) ) ) (list 154444 "Permutation of non-negative integers: inverse of A154443." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154443) '(comps: (153142 154442) (54429 154440 54429)) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154439-A154448. Corresponds to A154454 in the group of Catalan bijections.") ) (list 154445 "Permutation of non-negative integers induced by Basilica group generating wreath recursion, variant 2: a = (b,1), b = s(a,1), starting from the active (swapping) state b." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154446) '(comps: (154439 153141) (54429 154441 54429)) (list 'c: (string-append "This permutation is induced by the Basilica group generating wreath" " recursion (binary transducer) a = (b,1), b = s(a,1)" " (where s means swap the digits 0 <-> 1)" " given on the second page of Bartholdi and Virag paper," " starting from the active (switching) state b," " and rewriting bits from the second most significant bit" " to the least significant end." ) ) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154439-A154448. Corresponds to A154455 in the group of Catalan bijections.") '(scheme: (define (A154445 n) ;; Abasilica2b (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 1) (z n)) (cond ((zero? maskbit) z) ((not (zero? (modulo (floor->exact (/ n maskbit)) 2))) (- z (* p maskbit)) ;; Found first 1-bit, complement it ;; if at odd distance, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (+ z (* p maskbit)) ) ) ) ) ) ) ) ) (list 154446 "Permutation of non-negative integers: inverse of A154445." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154445) '(comps: (153142 154440) (54429 154442 54429)) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154439-A154448. Corresponds to A154456 in the group of Catalan bijections.") ) (list 154447 "Permutation of non-negative integers induced by wreath recursion a=s(b,c), b=s(c,a), c=(c,c), starting from state b, rewriting bits from the second most significant bit toward the least significant end." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154448) '(comps: (54429 154448 54429)) (list 'c: (string-append "This permutation of natural numbers is induced by" " the second generator of group 2861 mentioned on page 144 of" " \"Classification of groups generated by 3-state automata over a 2-letter alphabet\" paper." " It can be computed by starting scanning n's binary expansion rightward from the" " second most significant bit, complementing every bit down to and including" " A) either the first 0-bit at odd distance from the most significant bit" " or B) the first 1-bit at even distance from the most significant bit." ) ) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154439-A154446. Corresponds to A154457 in the group of Catalan bijections.") '(scheme: (define (A154447 n) (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 0) (z n)) (cond ((zero? maskbit) z) ((= p (modulo (floor->exact (/ n maskbit)) 2)) (+ z (* (- 1 (* 2 p)) maskbit)) ;; Found first bit ;; equal to p, complement it if at odd distance, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (- z (* (- 1 (* 2 p)) maskbit)) ) ) ) ) ) ) ) ) (list 154448 "Permutation of non-negative integers induced by wreath recursion a=s(b,c), b=s(c,a), c=(c,c), starting from state a, rewriting bits from the second most significant bit toward the least significant end." '(off: 0) '(indentries: Nperm) '(keywords: "base") '(create-b-file: 2047) '(inv: 154447) '(comps: (54429 154447 54429)) ;; %H A154448 Bondarenko, Grigorchuk, Kravchenko, Muntyan, Nekrashevych, Savchuk, Sunic, Classification of groups generated by 3-state automata over a 2-letter alphabet, p. 144. (list 'c: (string-append "This permutation of natural numbers is induced by" " the first generator of group 2861 mentioned on page 144 of" " \"Classification of groups generated by 3-state automata over a 2-letter alphabet\" paper." " It can be computed by starting scanning n's binary expansion rightward from the" " second most significant bit, complementing every bit down to and including" " A) either the first 0-bit at even distance from the most significant bit" " or B) the first 1-bit at odd distance from the most significant bit." ) ) '(y: "Cf. A072376, A153141-A153142, A154435-A154436, A154439-A154446. Corresponds to A154458 in the group of Catalan bijections.") '(scheme: (define (A154448 n) (if (< n 2) n (let loop ((maskbit (A072376 n)) (p 1) (z n)) (cond ((zero? maskbit) z) ((= p (modulo (floor->exact (/ n maskbit)) 2)) (+ z (* (- 1 (* 2 p)) maskbit)) ;; Found first bit ;; equal to p, complement it if at odd distance, and return ) (else (loop (floor->exact (/ maskbit 2)) (- 1 p) (- z (* (- 1 (* 2 p)) maskbit)) ) ) ) ) ) ) ) ) ) ) ;; (load "GF2Xfuns") ;; (cd "seqs/batch2009jul29") ;; (output-entries-to-file120_45 seqs2009Jul29 "2009Jul29.scm" "Jul 29 2009") (define seqs2009Jul29 (list (list 163233 "a(i,j) = bits of binary expansion of A003188(i) interleaved with that of A003188(j)." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 2079) '(f: "a(x,y) = A000695(A003188(x) + 2*A000695(A003188(y))") '(inv: 163234) '(comps: (57300 163235)) '(y: "Transpose: A163235. Cf. A054238, A147995.") (list 'scheme: '(define (A163233bi x y) (+ (A000695 (A003188 x)) (* 2 (A000695 (A003188 y))))) '(define (A163233 n) (A163233bi (A025581 n) (A002262 n))) ) ;; 'scheme ) (list 163234 "Inverse permutation of A163233." '(off: 0) '(indentries: Nperm) '(create-b-file: 4095) '(f: "a(n) = A001477bi(A006068(A059905(n)),A006068(A059906(n))), where A001477bi(x,y) = (((x+y)^2)+x+(3y))/2.") '(inv: 163233) '(comps: (163236 057300)) '(y: "Cf. A163236.") (list 'scheme: '(define (A163234 n) (A001477bi (A006068 (A059905 n)) (A006068 (A059906 n)))) '(define (A001477bi x y) (/ (+ (expt (+ x y) 2) x (* 3 y)) 2)) ) ;; 'scheme ) (list 163235 "a(i,j) = bits of binary expansion of A003188(j) interleaved with that of A003188(i)." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 2079) '(inv: 163236) '(comps: (57300 163233)) '(y: "Transpose: A163233. Cf. A054238, A147995.") '(scheme: "(define (A163235 n) (A163233bi (A002262 n) (A025581 n)))" ) ;; 'scheme ) (list 163236 "Inverse permutation of A163235." '(off: 0) '(indentries: Nperm) '(create-b-file: 4095) '(f: "a(n) = A001477bi(A006068(A059906(n)),A006068(A059905(n))), where A001477bi(x,y) = (((x+y)^2)+x+(3y))/2.") '(inv: 163235) '(comps: (163234 57300)) '(y: "Cf. A163234.") (list 'scheme: '(define (A163236 n) (A001477bi (A006068 (A059906 n)) (A006068 (A059905 n)))) '(define (A001477bi x y) (/ (+ (expt (+ x y) 2) x (* 3 y)) 2)) ) ;; 'scheme ) (list 163237 "a(i,j) = bits of binary expansion of A003188(i) interleaved with that of A003188(j), then converted with A163241." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 2079) '(inv: 163238) '(comps: (163241 163233)) '(y: "Transpose: A163239. Cf. A147995.") ) (list 163238 "Inverse permutation of A163237." '(off: 0) '(indentries: Nperm) '(create-b-file: 4095) '(inv: 163237) '(comps: (163234 163241)) '(y: "Cf. A163240.") ) (list 163239 "Transpose of array A163237." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 2079) '(inv: 163240) '(comps: (163241 163235)) '(y: "Transpose: A163237.") ) (list 163240 "Inverse permutation of A163239." '(off: 0) '(indentries: Nperm) '(create-b-file: 4095) '(inv: 163239) '(comps: (163236 163241)) '(y: "Cf. A163238.") ) (list 163241 "Simple self-inverse permutation: Write n in base 4, then replace each digit '2' by '3' and vice versa, then convert back to decimal." '(off: 0) '(indentries: Nperm) '(create-b-file: 1023) '(f: "a(n) = A000695(A003987bi(A059905(n),A059906(n))) + 2*A000695(A059906(n))") '(inv: 163241) '(y: "Cf. A048647, A007090.") (list 'scheme: "(define (A163241 n) (+ (A000695 (A003987bi (A059905 n) (A059906 n))) (* 2 (A000695 (A059906 n)))))" ) ;; 'scheme ) (list 163325 "Pick digits at the even distance from the least significant end of ternary expansion of n, then convert back to decimal." '(off: 0) '(create-b-file: 728) '(f: "a(0) = 0, a(n) = (n mod 3) + 3*A163325(floor(n/9))") '(y: "A059905 is an analogous sequence for binary. Note that A037314(A163325(n)) + 3*A037314(A163326(n)) = n for all n. Cf. A007089, A163327-A163329.") '(scheme (define (A163325 n) ;; Take the even-positioned trigits and contract them. (if (zero? n) n (+ (modulo n 3) (* 3 (A163325 (floor->exact (/ n 9))))) ) ) ) ) (list 163326 "Pick digits at the odd distance from the least significant end of ternary expansion of n, then convert back to decimal." '(off: 0) '(f: "a(n) = A163325(floor(n/3))") '(create-b-file: 728) '(y: "A059906 is an analogous sequence for binary. Note that A037314(A163325(n)) + 3*A037314(A163326(n)) = n for all n. Cf. A007089, A163327-A163329.") '(scheme "(define (A163326 n) (A163325 (floor->exact (/ n 3))))") ) (list 163327 "Self-inverse permutation of integers: swap the odd and even-positioned digits in the ternary expansion of n, then convert back to decimal." '(off: 0) '(indentries: Nperm) '(create-b-file: 728) '(f: "a(n) = A037314(A163326(n)) + 3*A037314(A163325(n))") '(inv: 163327) '(y: "A057300 is an analogous sequence for binary. Cf. A007089, A163328-A163329.") '(scheme: "(define (A163327 n) (+ (A037314 (A163326 n)) (* 3 (A037314 (A163325 n)))))") ) (list 163328 "Square array A, where entry A(y,x) has the ternary digits of x interleaved with the ternary digits of y, converted back to decimal. Listed by antidiagonals: A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 3320) '(f: "a(n) = A037314(A025581(n)) + 3*A037314(A002262(n))") '(inv: 163329) '(comps: (163327 163330)) '(y: "Transpose: A163330. A054238 is an analogous sequence for binary. Cf. A007089, A163327, A163332, A163334.") '(scheme: "(define (A163328 n) (+ (A037314 (A025581 n)) (* 3 (A037314 (A002262 n)))))") ) (list 163329 "Inverse permutation of A163328." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 6560) '(f: "a(n) = A001477bi(A163325(n),A163326(n)), where A001477bi(x,y) = (((x+y)^2)+x+(3y))/2.") '(inv: 163328) '(comps: (163331 163327)) '(y: "A054239 is an analogous sequence for binary. Cf. A007089.") (list 'scheme: (string-append "(define (A163329 n) (A001477bi (A163325 n) (A163326 n)))" "\n(define (A001477bi x y) (/ (+ (expt (+ x y) 2) x (* 3 y)) 2))" ) ) ) (list 163330 "Square array A, where entry A(y,x) has the ternary digits of y interleaved with the ternary digits of x, converted back to decimal. Listed by antidiagonals: A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 3320) '(f: "a(n) = 3*A037314(A025581(n)) + A037314(A002262(n))") '(inv: 163331) '(comps: (163327 163328)) '(y: "Transpose: A163328. Cf. A007089, A163327, A163332, A163334.") '(scheme: "(define (A163330 n) (+ (A037314 (A002262 n)) (* 3 (A037314 (A025581 n)))))") ) (list 163331 "Inverse permutation of A163330." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 6560) '(f: "a(n) = A001477bi(A163326(n),A163325(n)), where A001477bi(x,y) = (((x+y)^2)+x+(3y))/2.") '(inv: 163330) '(comps: (163329 163327)) '(y: "Cf. A007089.") (list 'scheme: (string-append "(define (A163331 n) (A001477bi (A163326 n) (A163325 n)))" "\n(define (A001477bi x y) (/ (+ (expt (+ x y) 2) x (* 3 y)) 2))" ) ) ) (list 163332 "Self-inverse permutation of integers for constructing Hilbert II curve in NxN grid." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 59048) ;; 531440 '(inv: 163332) '(comps: (163327 163333 163327)) '(y: "A163334 & A163336 give two variants of Hilbert II curve in NxN grid. Cf. also A163355.") (list 'scheme: '(define (A163332 n) (let loop ((z 0) (n n) (i 0) ) (let ((x (modulo n 3)) (y (modulo (floor->exact (/ n 3)) 3)) ) (cond ((zero? n) z) ((and (= 1 x) (= 1 y)) ;; Central square, rotate everything 180 (loop (+ (* 4 (expt 3 i)) (complement-i-lsts z i)) (floor->exact (/ n 9)) (+ i 2) ) ) ((= 1 x) ;; either 01 or 21, complement odd-positioned trigits (loop (+ (* (+ (* y 3) 1) (expt 3 i)) (complement-i-oddpos-lsts z (/ i 2)) ) (floor->exact (/ n 9)) (+ i 2) ) ) ((= 1 y) ;; either 10 or 12, complement even-positioned trigits (loop (+ (* (+ 3 (- 2 x)) (expt 3 i)) ;; also x ! (complement-i-evenpos-lsts z (/ i 2)) ) (floor->exact (/ n 9)) (+ i 2) ) ) (else (loop (+ (* (+ (* y 3) x) (expt 3 i)) z) (floor->exact (/ n 9)) (+ i 2) ) ) ) ) ) ) '(define (complement-i-lsts n i) (if (zero? i) n (+ (- 2 (modulo n 3)) (* 3 (complement-i-lsts (floor->exact (/ n 3)) (-1+ i))) ) ) ) '(define (complement-i-evenpos-lsts n i) (if (zero? i) n (+ (- 2 (modulo n 3)) (* 3 (complement-i-oddpos-lsts (floor->exact (/ n 3)) (-1+ i))) ) ) ) '(define (complement-i-oddpos-lsts n i) (+ (* 3 (complement-i-evenpos-lsts (floor->exact (/ n 3)) i)) (modulo n 3) ) ) ) ) (list 163333 "Self-inverse permutation of integers: A163327-conjugate of A163332." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 6560) ;; = 3^8 - 1. '(inv: 163333) '(comps: (163327 163332 163327)) '(y: "A163334 & A163336 give two variants of Hilbert II curve in NxN grid. Cf. also A163355.") ) (list 163334 "Hilbert II curve in NxN grid, starting rightwards from the top-left corner, listed antidiagonally as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 13202) ;; = A000217(162)-1. 266084 = A000217(729)-1 '(inv: 163335) '(comps: (163332 163328)) '(y: "Transpose: A163336. One-based version: A163338. See A163357 & A163359 for Hilbert curves.") ) (list 163335 "Inverse permutation of A163334." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 59048) ;; 3^10 - 1 (list 'c: (string-append "abs(A025581(a(n+1))-A025581(a(n))) + abs(A002262(a(n+1))-A002262(a(n))) = 1 for all n." ) ) '(inv: 163334) '(comps: (163329 163332)) '(y: "One-based version: A163339. See also A163337, A163358.") ) (list 163336 "Hilbert II curve in NxN grid, starting downwards from the top-left corner, listed antidiagonally as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 3320) ;; = A000217(81)-1 '(inv: 163337) '(comps: (163332 163330) (163327 163333 163328) (163334 61579)) '(y: "Transpose: A163334. One-based version: A163340. See A163357 & A163359 for Hilbert curves.") ) (list 163337 "Inverse permutation of A163336." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 6560) ;; = 3^8 - 1 = 9^4 - 1 (list 'c: (string-append "abs(A025581(a(n+1))-A025581(a(n))) + abs(A002262(a(n+1))-A002262(a(n))) = 1 for all n." ) ) '(inv: 163336) '(comps: (163331 163332) (61579 163335)) '(y: "One-based version: A163341. See also A163335, A163358.") ) (list 163338 "Hilbert II curve in NxN grid, one-based, starting rightwards from the top-left corner." '(off: 1) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 3321) ;; = A000217(81) '(f: "a(n) = A163334(n-1)+1") '(inv: 163339) '(y: "Transpose: A163340.") ) (list 163339 "Inverse permutation of A163338." '(off: 1) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 6561) ;; = 3^8 '(inv: 163338) '(f: "a(n) = A163335(n-1)+1") ) (list 163340 "Hilbert II curve in NxN grid, one-based, starting downwards from the top-left corner." '(off: 1) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 3321) ;; = A000217(81) '(f: "a(n) = A163336(n-1)+1") '(inv: 163341) '(y: "Transpose: A163338.") ) (list 163341 "Inverse permutation of A163340." '(off: 1) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 6561) ;; = 3^8 '(inv: 163340) '(f: "a(n) = A163337(n-1)+1") ) (list 163355 "Permutation of integers for constructing Hilbert curve in NxN grid." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 262143) ;; 2^18 - 1 '(inv: 163356) '(y: "A163357 & A163359 give two variants of Hilbert curve in NxN grid. Cf. also A163332.") (list 'scheme: '(define (A163355 n) (let* ((i (A052928 (A000523 n))) (dd (modulo (floor->exact (/ n (expt 2 i))) 4)) (rest (if (zero? n) n (modulo n (expt 2 i)))) ) (cond ((zero? n) n) ((= 0 dd) ;; 00xy --> 00xy (A163355 rest) ) ((= 3 dd) ;; 11xy --> 10yx (+ (expt 2 (1+ i)) (A163355 (A057300 rest))) ) ((= (+ 1 (floor->exact (/ (modulo i 4) 2))) dd) ;; 01xy --> 01yx or 10xy --> 01yx (+ (expt 2 i) (A163355 (A057300 rest))) ) (else ;; 10xy --> 11c(xy) or 01xy --> 11c(xy) (+ (* 3 (expt 2 i)) (A163355 (- (expt 2 i) 1 rest)) ) ) ) ) ) ) ) (list 163356 "Inverse permutation of A163355." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 65535) ;; 2^16 - 1 '(inv: 163355) (list 'scheme: '(define (A163356 n) (let loop ((z 0) (n n) (i 0) ) (let ((dd (modulo n 4))) (cond ((zero? n) z) ((= 0 dd) ;; 00xy --> 00xy (loop z (floor->exact (/ n 4)) (+ i 2) ) ) ((= 2 dd) ;; 10xy --> 11yx (loop (+ (* 3 (expt 2 i)) (A057300 z)) (floor->exact (/ n 4)) (+ i 2) ) ) ((= 1 dd) ;; 01xy --> 01yx or 01xy --> 10yx (loop (+ (expt 2 (+ i (floor->exact (/ (modulo i 4) 2)))) (A057300 z) ) (floor->exact (/ n 4)) (+ i 2) ) ) (else ;; 11xy --> 10c(xy) or 11xy --> 01c(xy) (loop (+ (expt 2 (+ i (- 1 (floor->exact (/ (modulo i 4) 2))))) (- (expt 2 i) z 1) ) (floor->exact (/ n 4)) (+ i 2) ) ) ) ) ) ) ) ) (list 163357 "Hilbert curve in NxN grid, starting rightwards from the top-left corner, listed antidiagonally as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 32895) ;; A000217(256)-1 '(inv: 163358) '(comps: (163355 54238)) '(y: "Transpose: A163359. One-based version: A163361. See also A163334 & A163336.") ) (list 163358 "Inverse permutation of A163357." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 65535) ;; = 2^16 - 1 (list 'c: (string-append "abs(A025581(a(n+1))-A025581(a(n))) + abs(A002262(a(n+1))-A002262(a(n))) = 1 for all n." ) ) '(inv: 163357) '(comps: (54239 163356)) '(y: "One-based version: A163362. See also A163334 and A163336.") ) (list 163359 "Hilbert curve in NxN grid, starting downwards from the top-left corner, listed antidiagonally as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 32895) ;; A000217(256)-1 '(inv: 163360) '(comps: (163357 61579)) '(y: "Transpose: A163359. One-based version: A163363.") ) (list 163360 "Inverse permutation of A163359." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 65535) ;; = 2^16 - 1 (list 'c: (string-append "abs(A025581(a(n+1))-A025581(a(n))) + abs(A002262(a(n+1))-A002262(a(n))) = 1 for all n." ) ) '(inv: 163359) '(comps: (61579 163358)) '(y: "One-based version: A163364.") ) (list 163361 "Hilbert curve in NxN grid, one-based, starting rightwards from the top-left corner." '(off: 1) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 32896) ;; = A000217(256) '(f: "a(n) = A163357(n-1)+1") '(inv: 163362) '(y: "Transpose: A163363.") ) (list 163362 "Inverse permutation of A163361." '(off: 1) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 65535) ;; = 4^8 '(inv: 163361) '(f: "a(n) = A163358(n-1)+1") ) (list 163363 "Hilbert curve in NxN grid, one-based, starting downwards from the top-left corner." '(off: 1) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 32896) ;; = A000217(256) '(f: "a(n) = A163359(n-1)+1") '(inv: 163364) '(y: "Transpose: A163363.") ) (list 163364 "Inverse permutation of A163363." '(off: 1) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 65535) ;; = 4^8 '(inv: 163363) '(f: "a(n) = A163360(n-1)+1") ) ) ) ;; (load "GF2Xfuns") ;; (cd "seqs/batch2009jul29") ;; (output-entries-to-file120_45 seqs2009Jul29b "2009Jul29b.scm" "Jul 29 2009") (define seqs2009Jul29b (list (list 163242 "Row sums of A163233 and A163235." '(off: 0) '(c: "It is easily seen that these terms are always divisible by 3.") '(y: "a(n) = 3*A163478(n).") ) (list 163342 "Row sums of A163334 and A163336." '(off: 0) '(c: "All terms seem to be divisible by 6. Cf. A163479.") ) (list 163343 "Central diagonal of A163334 and A163336." '(off: 0) '(c: "It is easy to see by induction that these terms are always divisible by 4.") '(y: "a(n) = 4*A163344(n).") ) (list 163344 "Central diagonal of A163334 and A163336 divided by 4." '(off: 0) '(y: "a(n) = A163343(n)/4.") ) (list 163365 "Row sums of A163357 and A163359." '(c: "All terms seem to be divisible by 4. Cf. A163477.") '(off: 0) ) (list 163477 "Row sums of A163357 and A163359 divided by 4." '(off: 0) '(y: "a(n) = A163365(n)/4.") ) (list 163478 "Row sums of A163233 and A163235 divided by 3." '(off: 0) '(y: "a(n) = A163242(n)/3.") ) (list 163479 "Row sums of A163334 and A163336 divided by 6." '(off: 0) '(y: "a(n) = A163342(n)/6.") ) (list 163480 "Row 0 of A163334 (column 0 of A163336)." '(off: 0) '(y: "Cf. A163481.") ) (list 163481 "Row 0 of A163336 (column 0 of A163334)." '(off: 0) '(y: "Cf. A163480.") ) (list 163482 "Row 0 of A163357 (column 0 of A163359)." '(off: 0) '(y: "Cf. A163483.") ) (list 163483 "Row 0 of A163359 (column 0 of A163357)." '(off: 0) '(y: "Cf. A163482.") ) ) ) ;; (load "GF2Xfuns") ;; (cd "seqs/batch2009aug01") ;; (output-entries-to-file120_45 seqs2009Aug01 "2009Aug01.scm" "Aug 01 2009") (define seqs2009Aug01 (list (list 163532 "The change in X-coordinate when moving from the n-1:th to the nth term in the type II Hilbert's Hamiltonian walk A163334." '(off: 0) '(create-b-file: 59049) ;; = 9^5 '(f: "a(0)=0, a(n) = A163528(n) - A163528(n-1).") '(y: "A014578(n) = |a(n)|. These are the first differences of A163528. See also: A163533, A163534, A163536.") ) (list 163533 "The change in Y-coordinate when moving from the n-1:th to the nth term in the type II Hilbert's Hamiltonian walk A163334." '(off: 0) '(create-b-file: 59049) ;; = 9^5 '(f: "a(0)=0, a(n) = A163529(n) - A163529(n-1).") '(y: "These are the first differences of A163529. See also: A163532, A163534, A163536.") ) (list 163538 "The change in X-coordinate when moving from the n-1:th to the nth term in the type I Hilbert's Hamiltonian walk A163357." '(off: 0) '(create-b-file: 65536) ;; 2^16 '(f: "a(0)=0, a(n) = A059253(n) - A059253(n-1).") '(y: "These are the first differences of A059253. See also: A163539, A163540, A163542.") ) (list 163539 "The change in Y-coordinate when moving from the n-1:th to the nth term in the type I Hilbert's Hamiltonian walk A163357." '(off: 0) '(create-b-file: 65536) ;; 2^16 '(f: "a(0)=0, a(n) = A059252(n) - A059252(n-1).") '(y: "These are the first differences of A059252. See also: A163538, A163541, A163543.") ) (list 163484 "Antidiagonal sums of A147995 and A163545." '(off: 0) ) (list 163485 "Permutation of integers used for constructing A147995 and A163545." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 65535) ;; 2^16 - 1 '(inv: 163486) '(y: "This permutation can be used to construct array A147995 and its transpose A163545. See A163355 for a bit similarly defined recursive permutation.") (list 'scheme: '(define (A163485 n) (let* ((i (floor->exact (/ (A000523 n) 2))) (dd (modulo (floor->exact (/ n (expt 4 i))) 4)) (r (if (zero? n) n (modulo n (expt 4 i)))) ) (cond ((zero? n) n) ((= 0 dd) ;; 00xy --> 00xy (A163485 r) ) ((= 1 dd) ;; 01xy --> 11c(y)x (+ (* 3 (expt 4 i)) (- (expt 4 i) 1 (A163485 (complement-i-oddpos-lsbs (A057300 r) i))) ) ) ((= 2 dd) ;; 10xy --> 01c(y)x (+ (expt 4 i) (- (expt 4 i) 1 (A163485 (complement-i-oddpos-lsbs (A057300 r) i))) ) ) (else ;; 11xy --> 10xy (+ (* 2 (expt 4 i)) (A163485 r)) ) ) ) ) '(define (complement-i-evenpos-lsbs n i) (if (zero? i) n (+ (- 1 (modulo n 2)) (* 2 (complement-i-oddpos-lsbs (floor->exact (/ n 2)) (-1+ i))) ) ) ) '(define (complement-i-oddpos-lsbs n i) (+ (* 2 (complement-i-evenpos-lsbs (floor->exact (/ n 2)) i)) (modulo n 2) ) ) ) ) (list 163486 "Inverse permutation of A163485." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 65535) ;; 2^16 - 1 '(inv: 163485) ) (list 163528 "The X-coordinate of the nth term in the type II Hilbert's Hamiltonian walk A163334." '(off: 0) '(create-b-file: 59048) ;; = 9^5 - 1 '(comps: (25581 163335) (2262 163337) (163325 163332)) '(y: "See also: A059252, A059253, A163529, A163530, A163531, A163532.") ) (list 163529 "The Y-coordinate of the nth term in the type II Hilbert's Hamiltonian walk A163334." '(off: 0) '(create-b-file: 59048) ;; = 9^5 - 1 '(comps: (2262 163335) (25581 163337) (163326 163332)) '(y: "See also: A059252, A059253, A163528, A163530, A163531, A163533.") ) (list 163530 "a(n) = A163528(n)+A163529(n)." '(off: 0) '(f: "a(n) = A163528(n)+A163529(n)") '(create-b-file: 59048) ;; = 9^5 - 1 '(y: "See also: A059261, A059285, A163528, A163529, A163531.") ) (list 163531 "The square of the distance from the origin to the nth term in the type II Hilbert's Hamiltonian walk A163334." '(off: 0) '(f: "a(n) = A000290(A163528(n))+A000290(A163529(n)).") '(create-b-file: 59048) ;; = 9^5 - 1 '(y: "See also: A163530, A163547.") ) (list 163534 "The absolute direction (0=east, 1=south, 2=west, 3=north) taken by the type II Hilbert's Hamiltonian walk A163334 at the step n." '(off: 1) '(create-b-file: 59049) ;; = 9^5 '(f: "a(n) = A010873(A163532(n)+A163533(n)+abs(A163533(n))+3).") '(c: "Taking every ninth term gives the same sequence: (and similarly for all higher powers of 9 as well).") '(comps: (163534 8591) (4442 163535)) '(y: "See also A163536.") '(scheme: (define (A163534 n) ;; One-based. (modulo (+ 3 (A163532 n) (A163533 n) (abs (A163533 n))) 4) ) ) ) (list 163535 "The absolute direction (0=east, 1=south, 2=west, 3=north) taken by the type II Hilbert's Hamiltonian walk A163336 at the step n." '(off: 1) '(create-b-file: 6561) ;; = 9^4 '(f: "a(n) = A010873(A163532(n)+A163533(n)+abs(A163532(n))+3).") '(c: "Taking every ninth term gives the same sequence: (and similarly for all higher powers of 9 as well).") '(comps: (163535 8591) (4442 163534)) '(y: "See also A163537.") '(scheme: (define (A163535 n) ;; One-based. (modulo (+ 3 (A163532 n) (A163533 n) (abs (A163532 n))) 4) ) ) ) (list 163536 "The relative direction (0=straight ahead, 1=turn right, 2=turn left) taken by the type II Hilbert's Hamiltonian walk A163334 at the step n." '(off: 1) '(create-b-file: 59049) ;; = 9^5 '(f: "a(n) = A163241((A163534(n+1)-A163534(n)) modulo 4).") '(c: "a(9*n) = a(81*n) for all n.") '(comps: (14681 163537)) '(y: "See also A163534.") '(scheme: "(define (A163536 n) (A163241 (modulo (- (A163534 (1+ n)) (A163534 n)) 4)))") ) (list 163537 "The relative direction (0=straight ahead, 1=turn right, 2=turn left) taken by the type II Hilbert's Hamiltonian walk A163336 at the step n." '(off: 1) '(create-b-file: 6561) ;; = 9^4 '(f: "a(n) = A163241((A163535(n+1)-A163535(n)) modulo 4).") '(c: "a(9*n) = a(81*n) for all n.") '(comps: (14681 163536)) '(y: "See also A163535.") '(scheme: "(define (A163537 n) (A163241 (modulo (- (A163535 (1+ n)) (A163535 n)) 4)))") ) (list 59253 "The X-coordinate of the nth term in the type I Hilbert's Hamiltonian walk A163357 (the Y-coordinate of its transpose A163359)." '(off: 0) '(create-b-file: 65535) ;; = 4^8 - 1 '(comps: (25581 163358) (2262 163360) (59905 163356)) '(y: "See also: A163528, A163538, A163540, A163542, A059252, A059253, A059261, A059285, A163547.") ) (list 59252 "The Y-coordinate of the nth term in the type I Hilbert's Hamiltonian walk A163357 (the X-coordinate of its transpose A163359)." '(off: 0) '(create-b-file: 65535) ;; = 4^8 - 1 '(comps: (2262 163358) (25581 163360) (59906 163356)) '(y: "See also: A163529, A163538, A163540, A163542, A059252, A059253, A059261, A059285, A163547.") ) (list 59261 "The sum of blaa blaa blaa ... A163357/A163359." '(off: 0) '(create-b-file: 65535) ;; = 4^8 - 1 '(f: "a(n) = A059252(n)+A059253(n).") '(y: "See also: A163530, A059285, A163547.") ) (list 163540 "The absolute direction (0=east, 1=south, 2=west, 3=north) taken by the type I Hilbert's Hamiltonian walk A163357 at the step n." '(off: 1) '(create-b-file: 65536) ;; 2^16 '(f: "a(n) = A010873(A163538(n)+A163539(n)+abs(A163539(n))+3).") '(c: "Taking every sixteenth term gives the same sequence: (and similarly for all higher powers of 16 as well).") '(comps: (163540 8598) (4442 163541)) '(y: "See also A163542.") '(scheme: (define (A163540 n) ;; One-based. (modulo (+ 3 (A163538 n) (A163539 n) (abs (A163539 n))) 4) ) ) ) (list 163541 "The absolute direction (0=east, 1=south, 2=west, 3=north) taken by the type I Hilbert's Hamiltonian walk A163359 at the step n." '(off: 1) '(create-b-file: 4096) ;; 4^6 '(f: "a(n) = A010873(A163538(n)+A163539(n)+abs(A163538(n))+3).") '(c: "Taking every sixteenth term gives the same sequence: (and similarly for all higher powers of 16 as well).") '(comps: (163541 8598) (4442 163540)) '(y: "See also A163543.") '(scheme: (define (A163541 n) ;; One-based. (modulo (+ 3 (A163538 n) (A163539 n) (abs (A163538 n))) 4) ) ) ) (list 163542 "The relative direction (0=straight ahead, 1=turn right, 2=turn left) taken by the type I Hilbert's Hamiltonian walk A163357 at the step n." '(off: 1) '(create-b-file: 65536) ;; 2^16 '(f: "a(n) = A163241((A163540(n+1)-A163540(n)) modulo 4).") '(c: "a(16*n) = a(256*n) for all n.") '(comps: (14681 163543)) '(y: "See also A163540.") '(scheme: "(define (A163542 n) (A163241 (modulo (- (A163540 (1+ n)) (A163540 n)) 4)))") ) (list 163543 "The relative direction (0=straight ahead, 1=turn right, 2=turn left) taken by the type I Hilbert's Hamiltonian walk A163359 at the step n." '(off: 1) '(create-b-file: 4096) ;; 4^6 '(f: "a(n) = A163241((A163541(n+1)-A163541(n)) modulo 4).") '(c: "a(16*n) = a(256*n) for all n.") '(comps: (14681 163542)) '(y: "See also A163541.") '(scheme: "(define (A163543 n) (A163241 (modulo (- (A163541 (1+ n)) (A163541 n)) 4)))") ) (list 147995 "An array of NxN grid hopping walk." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 8255) ;; 8255 = (A000217 128)-1 '(inv: 163544) '(comps: (163545 61579)) ;; (163485 54238 61579) '(y: "Transpose: A163545. See also A163233, A163235, A163237, A163239, A163357, A163359") ) (list 163544 "Inverse permutation of A147995." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 4095) ;; 4^6 - 1 '(inv: 147995) '(comps: (61579 163546)) ) (list 163545 "Transpose of A147995." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 2079) ;; = (A000217 64)-1 '(inv: 163546) '(comps: (163485 54238)) ) (list 163546 "Inverse permutation of A163545." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 4095) ;; 4^6 - 1 '(inv: 163545) '(comps: (54239 163486) (61579 163544)) ) (list 163547 "The square of the distance from the origin to the nth term in the type I Hilbert's Hamiltonian walk A163357." '(off: 0) '(f: "a(n) = A000290(A059252(n))+A000290(A059253(n)).") '(create-b-file: 65535) ;; 2^16 - 1 '(y: "See also: A059261, A163531.") ) ) ) ;; (load "GF2Xfuns") ;; (cd "seqs/batch2009aug07") ;; (output-entries-to-file120_45 seqs2009Aug07 "2009Aug07.scm" "Aug 07 2009") (define seqs2009Aug07 (list (list 163890 "Orbit size of n under A163355." '(off: 0) '(create-b-file: 262143) ;; 2^18 - 1 '(y: "See A163891, A163892, A163894.") '(scheme: (define (A163890 n) (let loop ((i 1) (nn (A163355 n))) (cond ((= nn n) i) (else (loop (1+ i) (A163355 nn))) ) ) ) ) ) (list 163891 "Positions where A163890 obtains distinct new values." '(off: 0) '(upto: 42) '(y: "See A163892, A163893.") ) (list 163892 "Distinct values in A163890 in the order of appearance." '(off: 0) '(upto: 42) '(comps: (163890 163891)) '(y: "See A163891, A163893, A163894.") ) (list 163893 "First differences of A163891." '(off: 0) '(upto: 41) '(f: "a(n) = A163891(n+1)-A163891(n).") '(y: "See A163892, A163893.") ) (list 163894 "The least i for which A163355^n(i) is not equal to i, 0 if no such i exists, i.e. when A163355^n = A001477." '(off: 0) '(create-b-file: 4095) ;; 2^12 - 1 '(c: "A163355^n means n-fold application of A163355, i.e. A163355^2 = A163905, A163355^3 = A163915. By convention A163355^0 = A001477.") '(y: "See A163890, A163895, A163896.") '(scheme: ;; First differing element between A001477 and A163355^n: ;; (0 if they do not differ). (define (A163894 n) (if (zero? n) 0 (let loop ((i 1) (nth_power (compose-fun-to-nth-power A163355 n))) (cond ((not (= i (nth_power i))) i) (else (loop (1+ i) nth_power)) ) ) ) ) (define (compose-fun-to-nth-power fun n) (cond ((zero? n) (lambda (x) x)) (else (lambda (x) (fun ((compose-fun-to-nth-power fun (- n 1)) x)))) ) ) ) ) (list 163895 "Positions where A163894 obtains record values." '(off: 0) '(upto: 7) '(c: "The ratios a(n+1)/a(n) from n>=1 onward start as 2,3,2,2,3,2,2,3,2,3,2,...") '(y: "See A163896.") ) (list 163896 "Record values of A163894." '(off: 0) '(upto: 7) '(comps: (163894 163895)) '(y: "See A163891, A163893, A163894.") ) (list 163897 "a(n) = A163531(n)-A163547(n)." '(off: 0) '(create-b-file: 65535) ;; = 2^16 - 1 (list 'c: (string-append "This sequence gives the difference of squares of distance" " from the origin to the nth term, in two different types of" " Hilbert's curves on NxN grid (A163357 and A163334)." " Because the former is based on powers of 16 and the latter" " on powers of 9," " the graph of this sequence has dramatic swings, with chaotic behavior." ) ) ) (list 163905 "Permutation A163355 applied twice." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 65535) ;; 2^16 - 1 '(inv: 163906) '(comps: (163355 163355)) '(y: "Array A163907 shows this in NxN grid. See also A163915.") ) (list 163906 "Permutation A163356 applied twice." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 16383) ;; 4^7 - 1 '(inv: 163905) '(comps: (163356 163356)) '(y: "See also A163916.") ) (list 163907 "Permutation A163905 shown in NxN grid." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 32895) ;; A000217(256)-1 '(inv: 163908) '(comps: (163905 54238) (163355 163357)) '(y: "See also A163357, A163917.") ) (list 163908 "Inverse permutation of A163907." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 16383) ;; 4^7 - 1 '(inv: 163907) '(comps: (54239 163906) (163358 163356)) '(y: "See also A163358, A163918.") ) (list 163915 "Permutation A163355 applied thrice." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 65535) ;; 2^16 - 1 '(inv: 163916) '(comps: (163355 163905) (163355 163355 163355)) '(y: "Array A163917 shows this in NxN grid. See also A163915.") ) (list 163916 "Permutation A163356 applied thrice." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 16383) ;; 4^7 - 1 '(inv: 163915) '(comps: (163356 163906) (163356 163356 163356)) '(y: "See also A163916.") ) (list 163917 "Permutation A163915 shown in NxN grid." '(off: 0) '(indentries: Nperm) '(keywords: "tabl") '(create-b-file: 32895) ;; A000217(256)-1 '(inv: 163918) '(comps: (163915 54238) (163355 163907) (163905 163357)) '(y: "See also A163357, A163907.") ) (list 163918 "Inverse permutation of A163917." '(off: 0) '(indentries: Nperm) ;; '(keywords: "tabf") '(create-b-file: 16383) ;; 4^7 - 1 '(inv: 163917) '(comps: (54239 163916) (163908 163356)) '(y: "See also A163358, A163908.") ) ) ) ;; (load "GF2Xfuns") ;; (cd "seqs/batch2009Sep17") ;; (output-entries-to-file120_45 seqs2009Sep17 "2009Sep17.scm" "Sep 18 2009") (define seqs2009Sep17 (list (list 163898 "Array A(i,j) giving the square of distance from (i,j) to the location where A054238(i,j) is situated in array A163357(i,j), listed antidiagonally as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(create-b-file: 32895) ;; A000217(256)-1 '(keywords: "tabl") '(comps: (163900 54238)) '(y: "Positions of zeros: A165403.") '(y: "See A163899, A163904.") ) (list 163899 "Array A(i,j) giving the square of distance from (i,j) to the location where A163357(i,j) is situated in array A054238(i,j), listed antidiagonally as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(create-b-file: 32895) ;; A000217(256)-1 '(keywords: "tabl") '(comps: (163900 163357)) '(y: "Positions of zeros: A165403.") '(y: "See A163898, A163904.") ) (list 163900 "Squared distance between n's location in A054238 array and A163357 array." '(off: 0) '(create-b-file: 65535) ;; 2^16 - 1 ;; '(create-b-file: 262143) ;; 2^18 - 1 '(f: "a(n) = A000290(abs(A059906(n)-A059252(n))) + A000290(abs(A059905(n)-A059253(n))).") '(y: "Positions of zeros: A163901. See also A163898, A163899.") '(scheme: (define (A163900 n) (+ (A000290 (abs (- (A059906 n) (A059252 n)))) (A000290 (abs (- (A059905 n) (A059253 n)))) ) ) ) ) (list 163901 "The positions i where A163355(i) = i, that is, the fixed points of permutation A163355." '(off: 0) '(c: "Alternatively, the positions of zeros in A163900.") '(comps: (000695 165404)) '(y: "Same sequence in base-4: A165406. See also A163902, A163903, A163910.") ) (list 163902 "The positions i where A163355(A163355(i)) = i, but not A163355(i) = i, that is, the 2-cycles of permutation A163355." '(off: 0) '(y: "See also A163901, A163903, A163910.") ) (list 163903 "The positions i where A163355(A163355(A163355(i))) = i, but not A163355(i) = i, that is, the 3-cycles of permutation A163355." '(off: 0) '(y: "See also A163901, A163902, A163910, A163913, A163914.") ) (list 163904 "Array A(i,j): Cycle size of each A054238(i,j) under permutation A163355, listed antidiagonally as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(keywords: "tabl") '(create-b-file: 32895) ;; A000217(256)-1 '(comps: (163890 54238) (163890 163357)) '(y: "Positions of 1's: A165403.") ) (list 165403 "The positions of zeros in A163898 and A163899." '(off: 0) '(c: "Equivalently, the positions of ones in A163904.") '(y: "These positions are all in the top row of the array, that is, for all n, A002262(a(n)) = 0. A025581(a(n)) gives A165404.") ) (list 165404 "The positions of zeros in the top row of A163898 (and A163899)." '(off: 0) '(create-b-file: 609) ;; = A027041(7). Or 232 = A027941(6) '(c: "Equivalently, the positions of ones in the top row of A163904.") '(comps: (025581 165403)) '(y: "Same sequence in binary: A165406. For n>0, A147600(n-1) seems to give the number of terms with binary width n. See also A163901.") ) (list 165406 "Sequence A165404 shown in binary, or equivalently, sequence A163901 in quaternary base." '(off: 0) '(keywords: "base") '(create-b-file: 609) ;; = A027041(7). Or 232 = A027941(6) '(comps: (007088 165404) (007090 163901)) '(y: "For n>0, A147600(n-1) seems to give the number of terms with n binary digits.") ) (list 163910 "Number of cycles in range [A000302(n-1)..A024036(n)] of permutation A163355/A163356." '(off: 0) '(upto: 6) '(y: "See also A163911, A163912, A163914, A163904, A163890.") ) (list 163911 "Maximum cycle size in range [A000302(n-1)..A024036(n)] of permutation A163355/A163356." '(off: 0) '(upto: 6) '(y: "See also A163910, A163912, A163904, A163890.") ) (list 163912 "Least common multiple of all cycle sizes in range [A000302(n-1)..A024036(n)] of permutation A163355/A163356." '(off: 0) '(upto: 6) '(y: "See also A163910, A163911, A163904, A163890.") ) (list 163913 "Number of integers i in range [A000302(n-1)..A024036(n)] of permutation A163355/A163356 with A163915(i)=i, but not A163355(i)=i." '(off: 0) '(upto: 13) '(y: "a(n) = 3*A163914(n). See also A163903.") '(scheme: (define (A163913 n) (let ((rp (range-of-nth-quaternary-forest n))) (let loop ((s 0) (i (car rp))) (cond ((> i (cdr rp)) s) ((and (not (= (A163355 i) i)) (= (A163915 i) i)) (loop (1+ s) (1+ i)) ) (else (loop s (1+ i))) ) ) ) ) (define (range-of-nth-quaternary-forest n) (if (zero? n) (cons n n) (cons (A000302 (-1+ n)) (+ (A000302 (-1+ n)) (-1+ (A002001 n)))) ) ) ) ) (list 163914 "Number of 3-cycles in range [A000302(n-1)..A024036(n)] of permutation A163355/A163356." '(off: 0) '(upto: 13) '(y: "a(n) = A163913(n)/3. Bisections: A163909, A163919. See also A163903, A163911, A163912, A163904, A163890.") ) (list 163909 "a(n) = A163914(2n)." '(off: 0) '(upto: 6) '(y: "See also A163919.") ) (list 163919 "a(n) = A163914(2n+1)." '(off: 0) '(upto: 6) '(y: "See also A163909.") ) ) ) ;; (load "GF2Xfuns") ;; (cd "seqs/batch2009Sep21") ;; (output-entries-to-file120_45 seqs2009Sep21 "2009sep21.scm" "Sep 21 2009") (define seqs2009Sep21 (list (list 165471 "Legendre symbol (n,65537)." '(off: 0) '(create-b-file: 65537) '(keywords: "sign,mult") '(c: "65537 is the 4th Fermat prime, A019434(4).") '(y: "Partial sums: A165472.") ) (list 165472 "Partial sums of A165471." '(off: 0) '(create-b-file: 65537) '(c: "Period 65537.") '(y: "A165486 gives the squared version. Positions of zeros: A165473. See also A165474, A165475. Compare also to A165477, A165482.") ) (list 165473 "Positions of zeros in A165472." '(off: 0) '(create-b-file: 612) '(y: "See also A165474, A165475. Compare also to A165478, A165483.") ) (list 165474 "a(n) = Least i in range [A165473(n),A165473(n+1)] for which abs(A165472(i)) gets the maximum value in that range." '(off: 0) '(create-b-file: 612) '(y: "A165475 gives the corresponding maximum values.") ) (list 165475 "A maximum absolute value of A165472 in range [A165473(n),A165473(n+1)]." '(off: 0) '(create-b-file: 612) '(c: "Period 611.") '(comps: (165472 165474)) ) ;;;; (list 165476 "Legendre symbol (n,131071)." '(off: 0) '(create-b-file: 131071) '(keywords: "sign,mult") '(c: "131071 is the 6th Mersenne prime, A000668(6).") '(y: "Partial sums: A165477.") ) (list 165477 "Partial sums of A165476." '(off: 0) '(create-b-file: 131071) '(c: "Period 131071.") '(y: "A165487 gives the squared version. Positions of zeros: A165478. See also A165479. Compare also to A165472, A165482.") ) (list 165478 "Positions of zeros in A165477." '(off: 0) '(upto: 4) '(y: "See also A165479. Compare also to A165473, A165483.") ) (list 165479 "a(n) = Least i in range [A165478(n),A165478(n+1)] for which abs(A165477(i)) gets the maximum value in that range." '(off: 0) '(upto: 5) ) (list 165480 "Positions of zeros in A163897." '(off: 0) '(upto: 22) ) ;;;; (list 165481 "Legendre symbol (n,28657)." '(off: 0) '(create-b-file: 28657) '(keywords: "sign,mult") '(c: "28657 is the 8th Fibonacci prime, A005478(8) = A000045(23).") '(y: "Partial sums: A165482.") ) (list 165482 "Partial sums of A165481." '(off: 0) '(create-b-file: 28657) '(c: "Period 28657.") '(y: "A165488 gives the squared version. Positions of zeros: A165483. See also A165484, A165485. Compare also to A165472, A165477.") ) (list 165483 "Positions of zeros in A165482." '(off: 0) '(create-b-file: 234) '(y: "See also A165484, A165485. Compare also to A165473, A165478.") ) (list 165484 "a(n) = Least i in range [A165483(n),A165483(n+1)] for which abs(A165482(i)) gets the maximum value in that range." '(off: 0) '(create-b-file: 234) '(y: "A165485 gives the corresponding maximum values.") ) (list 165485 "A maximum absolute value of A165482 in range [A165483(n),A165483(n+1)]." '(off: 0) '(create-b-file: 234) '(c: "Period 233.") '(comps: (165482 165484)) ) ;;;; (list 165486 "Squared version of A165472." '(off: 0) '(create-b-file: 65537) '(c: "Period 65537.") '(y: "Cf. A165487, A165488.") ) (list 165487 "Squared version of A165477." '(off: 0) '(create-b-file: 131071) '(c: "Period 131071.") '(comps: (000290 165477)) '(y: "Cf. A165486, A165488.") ) (list 165488 "Squared version of A165482." '(off: 0) '(create-b-file: 28657) '(c: "Period 28657.") '(y: "Cf. A165486, A165487.") ) ) ) ;; (load "GF2Xfuns") ;; (cd "seqs/batch2009Sep22") ;; (output-entries-to-file120_45 seqs2009Sep22 "2009sep22.scm" "Sep 22 2009") (define seqs2009Sep22 (list (list 165573 "Legendre symbol (n,257)." '(off: 0) '(create-b-file: 257) '(keywords: "mult") '(c: "257 is the 3rd Fermat prime, A019434(3).") '(y: "Partial sums: A165575.") ) (list 165574 "Legendre symbol (n,263)." '(off: 0) '(create-b-file: 263) '(keywords: "mult") '(c: "263 is the 12th Safe prime, A005385(12).") '(y: "Partial sums: A165576.") ) (list 165575 "Partial sums of A165573." '(off: 0) '(create-b-file: 59881) '(c: "Period 257.") ) (list 165576 "Partial sums of A165574." '(off: 0) '(create-b-file: 59701) '(c: "Period 263.") ) (list 165577 "Partial sums of A011626." '(off: 0) '(create-b-file: 59701) '(c: "Period 227.") ) (list 165578 "Partial sums of A011627." '(off: 0) '(create-b-file: 229) '(c: "Period 229.") ) (list 165579 "Partial sums of A011628." '(off: 0) '(create-b-file: 59881) '(c: "Period 233.") ) ;;;; (list 165581 "Legendre symbol (n,524287)." '(off: 0) '(create-b-file: 524287) '(keywords: "mult") '(c: "524287 is the 7th Mersenne prime, A000668(7) = 2^19 - 1.") '(y: "Partial sums: A165582.") ) (list 165582 "Partial sums of A165581." '(off: 0) '(create-b-file: 524287) '(c: "Period 524287. A165582(262143) = 255. Give also the positions where 658 occurs.") '(y: "Positions of zeros: A165583. See also A165584, A165585. Compare also to ALL-OF-THEM.") ) (list 165583 "Positions of zeros in A165582." '(off: 0) '(create-b-file: 1095) '(y: "See also A165584, A165585. Compare also to A165588.") ) (list 165584 "a(n) = Least i in range [A165583(n),A165583(n+1)] for which abs(A165582(i)) gets the maximum value in that range." '(off: 0) '(create-b-file: 1095) '(y: "A165585 gives the corresponding maximum values.") ) (list 165585 "A maximum absolute value of A165582 in range [A165583(n),A165583(n+1)]." '(off: 0) '(create-b-file: 1093) '(c: "Period 1094. Cf. A165590.") '(comps: (165582 165584)) ) ;;;; (list 165586 "Legendre symbol (n,514229)." '(off: 0) '(create-b-file: 514229) '(keywords: "mult") '(c: "514229 is the 9th Fibonacci prime, A005478(9) = A000045(29).") '(y: "Partial sums: A165587.") ) (list 165587 "Partial sums of A165586." '(off: 0) '(create-b-file: 514229) '(c: "Period 514229.") '(y: "Positions of zeros: A165588. See also A165589, A165590. Compare also to ALL-OF-THEM.") ) (list 165588 "Positions of zeros in A165587." '(off: 0) '(create-b-file: 1086) '(y: "See also A165589, A165590. Compare also to A165583.") ) (list 165589 "a(n) = Least i in range [A165588(n),A165588(n+1)] for which abs(A165587(i)) gets the maximum value in that range." '(off: 0) '(create-b-file: 1085) '(y: "A165590 gives the corresponding maximum values.") ) (list 165590 "A maximum absolute value of A165587 in range [A165588(n),A165588(n+1)]." '(off: 0) '(create-b-file: 1084) '(c: "Period 1085. Cf. A165585.") '(comps: (165587 165589)) ) ;;;; (list 165591 "Jacobi symbol (n,59701)." '(off: 0) '(create-b-file: 59701) '(keywords: "mult") '(c: "Semiprime 59701 = 227*263 = A005385(11)*A005385(12).") '(y: "a(n) = A011626(n)*A165574(n). Partial sums: A165592. Cf. A165471.") '(scheme: (define (A165591 n) (jacobi-symbol n 59701)) (Function jacobi-symbol given in entry A165471) ) ) (list 165592 "Partial sums of A165591." '(off: 0) '(create-b-file: 59701) '(c: "Period 59701.") '(y: "Positions of zeros: A165593. See also A165594, A165595. Compare also to ALL-OF-THEM.") ) (list 165593 "Positions of zeros in A165592." '(off: 0) '(create-b-file: 462) '(y: "See also A165594, A165595. Compare also to A165598.") ) (list 165594 "a(n) = Least i in range [A165593(n),A165593(n+1)] for which abs(A165592(i)) gets the maximum value in that range." '(off: 0) '(create-b-file: 461) '(y: "A165595 gives the corresponding maximum values.") ) (list 165595 "A maximum absolute value of A165592 in range [A165593(n),A165593(n+1)]." '(off: 0) '(create-b-file: 460) '(c: "Period 461. Cf. A165600.") '(comps: (165592 165594)) ) ;;;; (list 165596 "Jacobi symbol (n,59881)." '(off: 0) '(create-b-file: 59881) '(keywords: "mult") '(c: "Semiprime 59881 = 233*257 = A005478(6)*A019434(3) = A117879(11).") '(y: "a(n) = A011628(n)*A165573(n). Partial sums: A165597. Cf. A165591.") ) (list 165597 "Partial sums of A165596." '(off: 0) '(create-b-file: 59881) '(c: "Period 59881.") '(y: "Positions of zeros: A165598. See also A165599, A165590. Compare also to ALL-OF-THEM.") ) (list 165598 "Positions of zeros in A165597." '(off: 0) '(create-b-file: 167) '(y: "See also A165599, A165600. Compare also to A165593.") ) (list 165599 "a(n) = Least i in range [A165598(n),A165598(n+1)] for which abs(A165597(i)) gets the maximum value in that range." '(off: 0) '(create-b-file: 166) '(y: "A165600 gives the corresponding maximum values.") ) (list 165600 "A maximum absolute value of A165597 in range [A165598(n),A165598(n+1)]." '(off: 0) '(create-b-file: 166) '(c: "Period 167. Cf. A165595.") '(comps: (165597 165599)) ) ;;;; (list 165569 "The indexing sequence for Successively Better Golden Semiprimes." '(off: 1) '(upto: 15) '(f: "a(1)=1, and for n>1, a(n) = first such i>a(n-1) that abs(phi - A108539(i)/A000040(i)) < abs(phi - A108539(a(n-1))/A000040(a(n-1))), where phi = (1+sqrt(5))/2 (Golden ratio).") '(y: "The corresponding semiprimes is given by A165570(n) = A165571(n)*A165572(n).") '(scheme: (define (A165569 n) (if (= 1 n) 1 (let* ((i (A165569 (-1+ n))) (champion (abs (- *Phi* (/ (A108539 i) (A000040 i))))) ) (let loop ((i (1+ i))) (cond ((< (abs (- *Phi* (/ (A108539 i) (A000040 i)))) champion) i ;; Found a better specimen than the current champion. ) (else (loop (1+ i))) ) ) ) ) ) (define *Phi* (/ (1+ (sqrt 5)) 2)) ) ) (list 165570 "Successively Better Golden Semiprimes." '(off: 1) '(upto: 15) '(keywords: "more") '(f: "a(n) = A165571(n)*A165572(n) = A000040(A165569(n))*A108539(A165569(n)).") (list 'c: (string-append "See A165569 for the definition. Can it be proven that this a subset of A0108540? " "The ratio A165572(n)/A165571(n) converges towards Golden ratio = (1+sqrt(5))/2 = 1.618033988749895... as: " "1.5, 1.6666666666666667, 1.5714285714285714, 1.631578947368421, 1.608695652173913, 1.6206896551724137, 1.6185567010309279, 1.6175637393767706, 1.6181172291296626, 1.618066561014263, 1.618063112078346, 1.618031658637302, 1.6180335296782964, 1.6180341824372995, 1.6180339327699054, ..." ) ) ) (list 165571 "Lesser prime factor of Successively Better Golden Semiprimes." '(off: 1) '(upto: 15) '(keywords: "more") '(comps: (000040 165569)) '(y: "a(n) = A165570(n)/A165572(n).") '(c: "See A165569 for the definition. Probably a subset of A0108541.") ) (list 165572 "Greater prime factor of Successively Better Golden Semiprimes." '(off: 1) '(upto: 15) '(keywords: "more") '(comps: (108539 165569)) '(y: "a(n) = A165570(n)/A165571(n).") '(c: "See A165569 for the definition. Probably a subset of A0108542.") ) ) ) ;; (load "GF2Xfuns") ;; Do the following again, because GF2Xfuns loads slib-library ;; with its old slow version of jacobi-symbol: ;; (define jacobi-symbol fix:jacobi-symbol) ;; (define legendre-symbol jacobi-symbol) ;; (cd "seqs/batch2009oct06") ;; (output-entries-to-file120_45 seqs2009oct06 "2009oct06.scm" "Oct 06 2009") (define seqs2009oct06 (list (list 165601 "Midpoint height of Jacobi-bridge, computed for 4n+3." '(off: 0) '(create-b-file: 65536) '(y: "Trisections: A165604, A165605, A165606. Cf. A165602-A165603, A165460, A166045-A166047.") ) (list 165602 "Positions of zeros in A165601." '(off: 0) '(create-b-file: 5190) '(y: "Cf. A165603, A165462.") ) (list 165603 "Numbers of the form 4n+3 for which Sum_{i=0..(2n+1)} J(i/4n+3) = 0." '(c: "Integers of type 4n+3 whose midpoint height of Jacobi-bridge is zero.") '(off: 0) '(create-b-file: 5190) '(comps: (004767 165602)) '(c: "Conjecture: This is a superset of A165463. - Antti Karttunen, Oct 5 2009.") '(y: "Cf. A165463, A165603, A165608.") ) (list 165604 "Trisection 3n of A165601." '(off: 0) '(comps: (165601 008585)) ) (list 165605 "Trisection 3n+1 of A165601." '(off: 0) '(c: "See the conjecture in A165460.") '(comps: (165601 016777)) ) (list 165606 "Trisection 3n+2 of A165601." '(off: 0) '(comps: (165601 016789)) ) (list 165468 "a(n) = (A165469(n)-3)/4." '(off: 1) '(y: "Subset of A095274. Cf. A165607.") '(scheme: ;; Subset of A095274. (define A165468 (MATCHING-POS 1 0 (lambda (n) (let ((w (A004767 n)) ;; w = 4n+3 (hp (A005408 n)) ;; hp = 2n+1 = ((w-1)/2) ) (let loop ((i 1) (s 1)) ;; s = sum of the first i Jacobi-symbols in [1,i] (cond ((<= s 0) #f) ((>= i hp) #t) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)))) ) ) ) ) ) ) ) ) (list 165469 "Numbers of the form 4n+3 for which Sum_{i=1..u} J(i/4n+3) is never zero for any u in range [1,(2n+1)], where J is Jacobi-symbol." '(off: 1) '(comps: (004767 165468)) '(y: "Setwise difference of A095100 and A165608. A165580 gives the primes in this sequence.") ) (list 165580 "Primes of the form 4n+3 for which Sum_{i=1..u} J(i/4n+3) is never zero for any u in range [1,(2n+1)], where J is Jacobi-symbol." '(off: 1) '(y: "Setwise difference of A095102 and A165977. Also subset of A165469.") ) ;; Difference A095274 \ A165468: ;; (Those n, for which Jacobi-bridge of 4n+3 visits sea level, but doesn't dive) (list 165607 "a(n) = (A165608(n)-3)/4." '(off: 1) '(y: "Set-wise difference of A095274 and A165468.") '(scheme: (define A165607 (MATCHING-POS 1 0 (lambda (n) (let ((w (A004767 n)) ;; w = 4n+3 (hp (A005408 n)) ;; hp = 2n+1 = ((w-1)/2) ) ;; s = sum of the first i Jacobi-symbols in [1,i] (let loop ((i 1) (s 1) (zv 0)) ;; zv = # of sea level visits. (cond ((< s 0) #f) ;; Goes negative, fail. ((>= i hp) (not (zero? zv))) ((zero? s) (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) (1+ zv)) ) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) zv)) ) ) ) ) ) ) ) ) (list 165608 "Numbers of the form 4n+3 for which Sum_{i=1..u} J(i/4n+3) is never negative for any u in range [1,(2n+1)], but obtains at least once value zero, where J is Jacobi-symbol." '(off: 1) '(c: "Setwise difference of A095100 and A165469.") '(comps: (004767 165607)) '(y: "Subset of A095100. A165977 gives the primes only. Cf. A165603.") ) (list 165977 "Primes of the form 4n+3 for which Sum_{i=1..u} J(i/4n+3) is never negative for any u in range [1,(2n+1)], but obtains at least once value zero, where J is Jacobi-symbol." '(off: 1) '(c: "Setwise difference of A095102 and A165580.") '(y: "Subset of A165608.") ) (list 165460 "The height at the 1/3 point at Jacobi-bridge, computed for 12n+7." '(off: 0) '(create-b-file: 21845) '(c: "Conjecture: a(2n) = 2*A165605(2n) and a(2n+1) = (2/3)*A165605(2n+1). - Antti Karttunen, Oct 5 2009. Presupposes the conjecture in A165462.") '(y: "Cf. A165461-A165463, A165605.") ) (list 165461 "Positions of zeros in A165460." '(off: 0) '(create-b-file: 1000) '(y: "Cf. A165462-A165463.") ) (list 165462 "a(n) = (A165463(n)-3)/4." '(off: 0) '(create-b-file: 1000) '(c: "Conjecture: These are all those terms of A165602 which = 1 modulo 3. - Antti Karttunen, Oct 5 2009.") '(y: "Cf. A165461-A165463.") ) (list 165463 "Numbers of the form 12n+7 for which Sum_{i=0..(4n+2)} J(i/12n+7) = 0." '(off: 0) '(create-b-file: 1000) '(comps: (004767 165462)) '(c: "Conjecture: a subset of A165603. See conjectures in A165460 and A165462.") ) (list 165464 "Squared distance between n's location in A163334 array and A163357 array." '(off: 0) '(c: "Equivalently, squared distance between n's location in A163336 array and A163359 array.") '(create-b-file: 65535) ;; 2^16 - 1 '(f: "a(n) = A000290(abs(A163529(n)-A059252(n))) + A000290(abs(A163528(n)-A059253(n))).") '(y: "Positions of zeros: A165465. See also A165466, A163897, A163900.") '(scheme: (define (A165464 n) (+ (A000290 (abs (- (A163529 n) (A059252 n)))) (A000290 (abs (- (A163528 n) (A059253 n)))) ) ) ) ) (list 165465 "Positions of zeros in A165464. Fixed points of A166041/A166042." '(off: 0) '(upto: 9) '(create-b-file: 9) '(y: "Cf. A165467, A165480, A163901.") ) (list 165466 "Squared distance between n's location in A163334 array and A163359 array." '(off: 0) '(c: "Equivalently, squared distance between n's location in A163336 array and A163357 array.") '(create-b-file: 65535) ;; 2^16 - 1 '(f: "a(n) = A000290(abs(A163529(n)-A059253(n))) + A000290(abs(A163528(n)-A059252(n))).") '(y: "Positions of zeros: A165467. See also A165464, A163897, A163900.") '(scheme: (define (A165466 n) (+ (A000290 (abs (- (A163529 n) (A059253 n)))) (A000290 (abs (- (A163528 n) (A059252 n)))) ) ) ) ) (list 165467 "Positions of zeros in A165466. Fixed points of A166043/A166044." '(off: 0) '(upto: 4) '(create-b-file: 4) '(y: "Cf. A165465, A165480, A163901.") ) (list 166041 "Permutation of non-negative integers: a(n) tells which integer is in the same position in the square array A163357 as where n is located in the array A163334." '(off: 0) '(indentries: Nperm) '(create-b-file: 65535) '(inv: 166042) '(comps: (163357 163335) (163359 163337)) '(y: "Fixed points: A165465. Cf. also A166043.") ) (list 166042 "Permutation of non-negative integers: a(n) tells which integer is in the same position in the square array A163334 as where n is located in the array A163357." '(off: 0) '(indentries: Nperm) '(create-b-file: 16383) ;; 4^7 - 1 '(inv: 166041) '(comps: (163334 163358) (163336 163360)) '(y: "Fixed points: A165465. Cf. also A166044.") ) (list 166043 "Permutation of non-negative integers: a(n) tells which integer is in the same position in the square array A163357 as where n is located in the array A163336." '(off: 0) '(indentries: Nperm) '(create-b-file: 65535) '(inv: 166044) '(comps: (163357 163337) (163359 163335)) '(y: "Fixed points: A165467. Cf. also A166041.") ) (list 166044 "Permutation of non-negative integers: a(n) tells which integer is in the same position in the square array A163336 as where n is located in the array A163357." '(off: 0) '(indentries: Nperm) '(create-b-file: 16383) ;; 4^7 - 1 '(inv: 166043) '(comps: (163336 163358) (163334 163360)) '(y: "Fixed points: A165467. Cf. also A166042.") ) (list 166045 "Positions of records in A165601." '(off: 0) ;; '(create-b-file: 4095) ;; '(y: "See A165466 and A166047 for the records themselves.") ) (list 166046 "The 4k+3 integers corresponding to the record positions in A165601." '(off: 0) ;; '(create-b-file: 4095) ;; '(comps: (004767 166045)) '(y: "See A166047 for the records themselves.") ) (list 166047 "Record values in A165601." '(off: 0) ;; '(create-b-file: 4095) ;; '(comps: (165601 166045)) '(y: "See A166046 for the corresponding 4k+3 integers.") ) ) ) ;; (load "GF2Xfuns") ;; (cd "seqs/batch2009oct05") ;; (output-entries-to-file120_45 seqs2009oct05zizka "2009oct05.scm" "Oct 05 2009") (define seqs2009oct05zizka (list (list 136272 "Waterbird take-off sequence. Complement of A166021." '(off: 1) '(keywords: "easy") '(y: "Complement of A166021.") ) (list 133923 "a(1)=1, and for n>1, a(n) = a(n-1)/2, if a(n-1) is divisible by 2, otherwise a(n) = A000005(n*a(n-1))." '(off: 1) '(c: "Edited, corrected and extended by ... The formula could be generalized as ...") '(scheme: (define (A133923 n) (cond ((< n 2) n) ((even? (A133923 (-1+ n))) (/ (A133923 (-1+ n)) 2)) (else (A000005 (* n (A133923 (-1+ n))))) ) ) ) ) (list 138606 "List first F(1) odd numbers, then first F(2) even numbers (starting from 2), then the next F(3) odd numbers, then the next F(4) even numbers, etc, where F(n) = A000045(n), the nth Fibonacci number." '(off: 1) '(upto: 512) '(keywords: "easy") '(f: "a(n) = A166012(A072649(n)-1) + 2*(n-A000045(1+A072649(n))).") '(c: "The original name was \"FibCon sequence\". However, this sequence has only passing resemblance with/to Connell-like sequences (see A001614), which are all monotone, while this sequence is a bijection of natural numbers.") '(indentries: Nperm) '(inv: 166013) '(y: "A000035(a(n)) = A000035(A072649(n)). Cf. A138607-A138609, A138612.") '(scheme: (define (A138606 n) (if (zero? n) n (+ (A166012 (-1+ (A072649 n))) (* 2 (- n (A000045 (1+ (A072649 n)))))) ) ) ) ) (list 138607 "List first A008578(1-1) odd numbers, then first A008578(2-1) even numbers, then the next A008578(3-1) odd numbers, then the next A008578(4-1) even numbers, etc." '(off: 1) '(upto: 1024) '(f: "If n < 3, a(n) = n. If n-2 = A007504(A083375(n-2)), then a(n) = a(n-1-A000040(A083375(n-2)))+2, otherwise a(n) = a(n-1)+2.") '(c: "The original name was \"PrimCon sequence\". However, this sequence has only passing resemblance with/to Connell-like sequences (see A001614), which are all monotone, while this sequence is a bijection of natural numbers.") '(indentries: Nperm) '(inv: 166014) '(y: "Cf. A138606-A138609, A138612.") '(scheme: (define (A138607 n) (if (< n 3) n (let ((k (A083375 (- n 2)))) (if (= (- n 2) (A007504 k)) (+ 2 (A138607 (- n 1 (A000040 k)))) (+ 2 (A138607 (-1+ n))) ) ) ) ) ) ) (list 138608 "List first F(1) numbers from A016777, then first F(2) numbers from A016789, then the first F(3) numbers from A008585 (starting from 3), then the next F(4) numbers from A016777, then the next F(5) numbers from A016789, then the next F(6) numbers from A008585, etc, where F(n) = A000045(n), the nth Fibonacci number." '(off: 1) '(upto: 1024) '(keywords: "easy") '(f: "If n < 4, a(n) = n. If n = A000045(A072649(n)+1), then a(n) = a(n-1-A000045(A072649(n)))+3, otherwise a(n) = a(n-1)+3.") '(c: "The original name was \"Generalized FibCon sequence\". However, this sequence has only passing resemblance with/to Connell-like sequences (see A001614 and the paper by Iannucci & Mills-Taylor), which are all monotone, while this sequence is a bijection of natural numbers.") '(indentries: Nperm) '(inv: 166015) '(y: "CHECK!: A010872(a(n)) = A010872(A072649(n)). Cf. A138607-A138609, A138612.") '(scheme: (define (A138608 n) (if (< n 4) n (let ((k (A072649 n))) (if (= n (A000045 (1+ k))) (+ 3 (A138608 (- n 1 (A000045 k)))) (+ 3 (A138608 (-1+ n))) ) ) ) ) ) ) (list 138609 "List the first term from A042963, then 2 terms from A014601 (starting from 3), 3 terms from A042963, 4 terms from A014601, etc." '(off: 1) '(upto: 1024) '(f: "a(n) = A116966(A074147(n)-1).") '(c: "The original name was \"Generalized Connell sequence\". However, this sequence has only passing resemblance with/to Connell-like sequences (see A001614 and the paper by Iannucci & Mills-Taylor), which are all monotone, while this sequence is a bijection of natural numbers.") '(indentries: Nperm) '(keywords: "tabl,easy") '(inv: 166016) ) ;; Must be computed term-by-term before its inverse A166017 ! (list 138612 "Permutation of natural numbers generated with a sieve algorithm explained in the comment lines." '(off: 1) '(create-b-file: 5050) '(indentries: Nperm) '(keywords: "tabl") '(inv: 166017) '(scheme: (define (A138612 n) (if (< n 3) n (let loop ((k (if (zero? (A002262 (-1+ n))) 1 (A138612 (-1+ n)))) (i 1) ) (cond ((not-lte? (A166017 i) (-1+ n)) (if (= 1 k) i (loop (-1+ k) (1+ i))) ) (else (loop k (1+ i))) ) ) ) ) (define (not-lte? a b) (cond ((not (number? a)) #t) (else (> a b)))) ) ) (list 166012 "a(n) = 2*(A000045(n)-(n mod 2)) + 1 + (n mod 2)." '(off: 0) '(f: "a(2n) = 2*A000045(2n) + 1, a(2n+1) = 2*A000045(2n+1).") '(c: "This is an auxiliary sequence for computing A138606.") '(scheme: (define (A166012 n) (+ 1 (modulo n 2) (* 2 (- (A000045 n) (modulo n 2))))) ) ) (list 166013 "Inverse permutation of A138606." '(off: 1) '(indentries: Nperm) '(inv: 138606) ) (list 166014 "Inverse permutation of A138607." '(off: 1) '(indentries: Nperm) '(inv: 138607) ) (list 166015 "Inverse permutation of A138608." '(off: 1) '(indentries: Nperm) '(inv: 138608) ) (list 166016 "Inverse permutation of A138609." '(off: 1) '(indentries: Nperm) '(inv: 138609) ) (list 166018 "Left edge of triangular table A138612." '(off: 1) '(f: "a(n) = A138612(A000124(n-1)).") ) (list 166019 "Right edge of triangular table A138612." '(off: 1) '(comps: (138612 000217)) ) (list 166020 "Row sums of triangular table A138612." '(off: 1) ) (list 166017 "Inverse permutation of A138612." '(off: 1) '(indentries: Nperm) '(inv: 138612) ) (list 166021 "a(n) = 2*A000124(A003056(n-1)) if A002262(n-1)=0, otherwise a(n-1)+1." '(off: 1) '(upto: 105) '(keywords: "tabl,easy") '(y: "Complement of A136272.") '(scheme: (define (A166021 n) (if (zero? (A002262 (-1+ n))) (* 2 (A000124 (A003056 (-1+ n)))) (1+ (A166021 (-1+ n)))) ) ) ) ) ) ;; (load "GF2Xfuns") ;; Do the following again, because GF2Xfuns loads slib-library ;; with its old slow version of jacobi-symbol: ;; (define jacobi-symbol fix:jacobi-symbol) ;; (define legendre-symbol jacobi-symbol) ;; (cd "seqs/batch2009oct06") ;; (output-entries-to-file120_45 seqs2009oct08 "2009oct08.scm" "Oct 08 2009") (define seqs2009oct08 (list (list 166040 "Number of times Sum_{i=1..u} J(i,2n+1) obtains value zero when u ranges from 1 to (2n+1). Here J(i,k) is the Jacobi symbol." '(off: 0) ;; '(create-b-file: 65536) (list 'c: (string-append "A046092 gives the positions of zeros, as only with odd squares A016754(m) = A005408(A046092(m)) Jacobi symbols J(i,n) never obtain value -1, and thus their" " partial sum never descends back to zero." " Even positions contain only even values, while odd positions contain" " odd values in all other positions, except even values in the positions given" " by A005408(A165602(i)), for i=0..." " Four bold conjectures by Antti Karttunen (Oct 8 2009):" " 1) All odd natural numbers occur." " 2) Each of them occurs infinitely many times." " 3) All even natural numbers occur." " 4) Each even number > 0 occurs only finitely many times." "(The last can be disputed. For example, 6 occurs four times among the first 400001 terms, at the positions 10, 28, 360, 215832.)" ) ) '(y: "Bisections: A166085, A166086. See also A166087, A165601, A166092.") '(scheme: (define (A166040 n) (let ((w (A005408 n))) ;; s = sum of the first i Jacobi-symbols in [1,i] (let loop ((i 1) (s 1) (zv 0)) ;; zv = # of sea level visits. (cond ((= i w) zv) ((zero? s) (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) (1+ zv)) ) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)) zv)) ) ) ) ) ) ) (list 166048 "a(n) = (A166049(n)-1)/4." '(off: 1) '(c: "Indexing sequence for A166049.") '(scheme: (define A166048 (MATCHING-POS 1 0 (lambda (n) (let ((w (A016813 n)) ;; w = 4n+1 (hp (A005843 n)) ;; hp = 2n = ((w-1)/2) ) ;; s = sum of the first i Jacobi-symbols in [1,i] (let loop ((i 1) (s 1)) (cond ((< s 0) #f) ;; Goes negative, fail. ((>= i hp) #t) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)))) ) ) ) ) ) ) ) ) (list 166049 "Integers of the form 4n+1 for which Sum_{i=1..u} J(i,4n+1) is never negative for any u in range [1,(2n)], where J(i,k) is the Jacobi symbol." '(off: 1) '(y: "Union of A016754 and A166051.") '(comps: (016813 166048)) ) (list 166051 "Non-square integers of the form 4n+1 for which Sum_{i=1..u} J(i,4n+1) is never negative for any u in range [1,(2n)], where J(i,k) is the Jacobi symbol." '(off: 1) '(upto: 7) '(c: "Conjecture: There are no more terms after 165. (Checked up to A016813(290511) = 1162045.) If this is true, then also 5, 13 and 37 are only 4k+1 primes in A080114.") '(y: "Setwise difference of A016754 and A166049.") '(scheme: (define (A166051 n) (A016813 (index_for_A166051 n))) (define index_for_A166051 (MATCHING-POS 1 0 (lambda (n) (let ((w (A016813c n)) ;; w = 4n+1 (hp (A005843 n)) ;; hp = 2n = ((w-1)/2) ) ;; s = sum of the first i Jacobi-symbols in [1,i] (let loop ((i 1) (s 1)) (cond ((< s 0) #f) ;; Goes negative, fail. ((>= i hp) (zero? s)) (else (loop (1+ i) (+ s (jacobi-symbol (1+ i) w)))) ) ) ) ) ) ) ) ) (list 166085 "Number of times Sum_{i=1..u} J(i,4n+1) obtains value zero when u ranges from 1 to (4n+1). Here J(i,k) is the Jacobi symbol." '(off: 0) ;; '(create-b-file: 65536) '(comps: (166040 005843)) '(y: "Bisection of A166040.") ) (list 166086 "Number of times Sum_{i=1..u} J(i,4n+3) obtains value zero when u ranges from 1 to (4n+3). Here J(i,k) is the Jacobi symbol." '(off: 0) ;; '(create-b-file: 65536) '(comps: (166040 005408)) (list 'y: (string-append "Bisection of A166040." " A165468 gives the positions of 1's," " and respectively, A166052, A166054, A166056 and A166058" " give the positions of 3's, 5's, 7's and 9's in this sequence." " Note how 3's seem to be more rare than 5's, and 7's more rare than 9's." ) ) ) (list 166052 "Second row of A166091. Positions of 3's in A166086." '(off: 1) '(y: "See A166053.") ) (list 166053 "Integers of the form 4n+3 for which Sum_{i=1..u} J(i,4n+3) obtains value zero exactly 3 times, when u ranges from 1 to (4n+3). Here J(i,k) is the Jacobi symbol." '(c: "Second row of A166092.") '(off: 1) '(comps: (004767 166052)) ) (list 166054 "Third row of A166091. Positions of 5's in A166086." '(off: 1) '(y: "See A166055.") ) (list 166055 "Integers of the form 4n+3 for which Sum_{i=1..u} J(i,4n+3) obtains value zero exactly 5 times, when u ranges from 1 to (4n+3). Here J(i,k) is the Jacobi symbol." '(off: 1) '(c: "Third row of A166092.") '(comps: (004767 166054)) ) (list 166056 "Fourth row of A166091. Positions of 7's in A166086." '(off: 1) '(upto: 50) '(y: "See A166057.") ) (list 166057 "Integers of the form 4n+3 for which Sum_{i=1..u} J(i,4n+3) obtains value zero exactly 7 times, when u ranges from 1 to (4n+3). Here J(i,k) is the Jacobi symbol." '(off: 1) '(upto: 50) '(c: "Fourth row of A166092.") '(comps: (004767 166056)) ) (list 166058 "Fifth row of A166091. Positions of 9's in A166086." '(off: 1) '(upto: 70) '(y: "See A166059.") ) (list 166059 "Integers of the form 4n+3 for which Sum_{i=1..u} J(i,4n+3) obtains value zero exactly 9 times, when u ranges from 1 to (4n+3). Here J(i,k) is the Jacobi symbol." '(off: 1) '(upto: 70) '(c: "Fifth row of A166092.") '(comps: (004767 166058)) ) (list 166088 "Odd integers (that is, of the form 2n+1) for which Sum_{i=1..u} J(i,2n+1) obtains value zero exactly 8 times, when u ranges from 1 to (2n+1). Here J(i,k) is the Jacobi symbol." '(off: 1) '(upto: 8) ;; (14 18 20 32 36 48 88 96) -> (29 37 41 65 73 97 177 193) '(c: "Of these eight, all are of the form 4k+1, and all others are primes except 65 (= 5*13) and 177 (= 3*59). Conjecture: There are no more terms after the eight one, 193. (Checked up to the 400000th term of A166040, i.e. up to A005408(400000)=800001.)") '(scheme: (define index_for_A166088 (MATCHING-POS 1 0 (lambda (i) (= 8 (A166040 i))))) (define (A166088 n) (A005408 (index_for_A166088 n))) ) ) (list 166087 "a(n) = Position of the first occurrence of n in A166040. -1 if it does not occur there." '(off: 0) '(y: "A166089 gives the corresponding odd numbers. See also A166097, A166098.") ) (list 166089 "a(n) = First odd number 2k+1, for which Sum_{i=1..u} J(i,2k+1) obtains value zero exactly n times when u ranges from 1 to (2k+1). Here J(i,k) is the Jacobi symbol." '(off: 0) '(comps: (005408 166087)) '(y: "See also A166095-A166096, A166097-A166098.") ) (list 166091 "Square array A(row>=0, col>=0) = (A166092(row,col)-3)/4, listed antidiagonally as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." '(off: 0) '(keywords: "tabl") '(c: "Note: This is not a permutation of non-negative integers. Although even if each odd integer occurred infinitely many times in A166040 (as it seems), for some odd n A166040 gets even value, the first example being A166040(49)=32, thus 24 (= (49-1)/2) is missing from here, and correspondingly, 99 (= 2*49 + 1) is missing from A166092. Sequence A165602 gives the natural numbers missing from this table.") '(y: "See also A112060. The leftmost column: A166094. The first five rows: A165468, A166052, A166054, A166056, A166058.") '(scheme: (define (A166091 n) (A166091bi (A025581 n) (A002262 n))) (define (A166091bi n k) (let ((m (A005408 k))) (let loop ((i 0) (n n)) (cond ((= m (A166086 i)) (if (zero? n) i (loop (1+ i) (-1+ n)) ) ) (else (loop (1+ i) n)) ) ) ) ) ) ) (list 166092 "Integers (all of the form 4k+3) organized into an array based on the number of times Sum_{i=1..u} J(i,4k+3) obtains value zero when u ranges from 1 to (4k+3), where J(i,k) is the Jacobi symbol." (list 'c: (string-append "Note: these are all of the form 4k+3, but still this is not permutation of A004767 (for the reason explained in A166091). Sequence A165603 gives the 4k+3 integers missing from this table." "This square array A(row>=0, col>=0) is listed antidiagonally" " as A(0,0), A(0,1), A(1,0), A(0,2), A(1,1), A(2,0), ..." ) ) '(off: 0) '(keywords: "tabl") '(comps: (004767 166091)) '(y: "See also A112070. The leftmost column: A166096. The first five rows: A165469, A166053, A166055, A166057, A166059.") ) (list 166093 "a(n) gives the least i, for which A166085(i) = 2n." '(off: 0) '(y: "a(n) = (A166090(n)-1)/4. See also A166094, A166095.") ) (list 166094 "Leftmost column of A166091." '(off: 0) '(y: "See also A166093, A166096.") '(c: "a(n) gives the least i, for which A166086(i) = 2n+1.") ) (list 166090 "a(n) = A016813(A166093(n))." '(off: 0) '(c: "a(n) = the least integer of the form 4i+1, with A166040(i/2) = 2n.") '(comps: (16813 166093)) '(y: "Differs from A166095. See also A166096.") ) (list 166095 "Bisection of A166089." '(off: 0) '(c: "a(n) = the least odd integer 2i+1, with A166040(i) = 2n.") '(comps: (166089 005843) (005408 166087 005843)) '(y: "Differs from A166090. See also A166096.") ) (list 166096 "Bisection of A166089. Leftmost column of A166092." '(off: 0) '(c: "a(n) = the least integer i of the form 4k+3, with A166040(i) = 2n+1.") '(comps: (004767 166094) (166089 005408) (005408 166087 005408)) '(y: "See also A166096.") ) (list 166097 "Positions where A166040 obtains distinct new values." '(off: 0) '(y: "A166098 gives the values themselves. See also A166087.") ) (list 166098 "Distinct values of A166040 in the order of appearance." '(off: 0) '(indentries: Nperm) '(create-b-file: 1000) '(c: "This is a permutation of non-negative integers if all integers >= 0 occur in A166040 at least once. In that case A166099 gives the inverse permutation.") '(comps: (166040 166097)) '(y: "See also A166087.") ) (list 166099 "a(n) = Position of the first occurrence of n in A166098. -1 if it does not occur there." '(off: 0) '(indentries: Nperm) '(inv: 166098) '(y: "See also A166087.") ) ) ) ;; (load "GF2Xfuns") ;; Do the following again, because GF2Xfuns loads slib-library ;; with its old slow version of jacobi-symbol: ;; (define jacobi-symbol fix:jacobi-symbol) ;; (define legendre-symbol jacobi-symbol) ;; (cd "seqs/batch2009oct12") ;; (output-entries-to-file120_45 seqs2009oct12 "2009oct12.scm" "Oct 12 2009") (define seqs2009oct12 (list (list 126441 "Tabular arrangement of the natural numbers by Alford Arnold, etc." '(off: 0) '(create-b-file: 65534) '(scheme: (define (A126441 n) (A126441onebased (1+ n))) (definec (A126441onebased n) (cond ((< n 2) n) (else (let ((prev (A126441onebased (- n (/ (A053644 n) 2))))) (if (or (= (A053644 n) (* 2 (A053644 (A053645 n)))) ;; n in A004755? (zero? prev) ;; Row hasn't started yet? ) (let ((starter (A004760 (1+ (A053645 n))))) (if (> (A161511 starter) (1+ (A000523 n))) 0 starter ) ) (A004754 prev) ) ) ) ) ) ) ) (list 161919 "Permutation of natural numbers: concatenation of subsequences A161924(A000070(k-1)..A026905(k)), k>=1, each sorted into ascending order." '(off: 1) '(upto: 80) '(create-b-file: 1596) '(indentries: Nperm) '(inv: 166277) ) (list 161920 "a(n) = A161511(A004760(n))." '(off: 1) '(c: "a(n) gives the starting position of row n-1 in A126441.") '(comps: (161511 004760)) ) (list 161924 "Permutation of natural numbers: sequence A126411 without zeros." '(off: 1) '(upto: 80) '(create-b-file: 1596) '(indentries: Nperm) '(comps: (126441 166274)) '(inv: 166276) ) (list 166274 "Positions of nonzeros in A126441." '(off: 1) '(c: "Here we assume that the starting offset of A126441 is 0, i.e. A126441(0)=1, A126441(1)=2, etc.") '(y: "Complement: A166275. See A161924.") ) (list 166275 "Positions of zeros in A126441." '(off: 1) '(c: "Here we assume that the starting offset of A126441 is 0, i.e. A126441(0)=1, A126441(1)=2, etc.") '(y: "Complement: A166274.") ) (list 166276 "Inverse permutation of A161924." '(off: 1) '(upto: 80) '(indentries: Nperm) '(inv: 161924) '(y: "Cf. A166277.") ) (list 166277 "Inverse permutation of A161919." '(off: 1) '(upto: 80) '(indentries: Nperm) '(inv: 161919) '(y: "Cf. A166276.") ) (list 166050 "The height at the 1/6 point at Jacobi-bridge, computed for each odd integer of the form 12n+7" '(off: 0) '(create-b-file: 131071) '(c: "Conjecture: a(...) = A165460.") '(y: "Bisections: A166268, A166269. Cf. ...") '(scheme: (define (A166050 n) (let ((w (A017605 n))) ;; w = 12n+7 (add (lambda (i) (jacobi-symbol i w)) 0 (/ (-1+ w) 6)) ) ) ) ) (list 166100 "Sum of the quadratic residues of 2n+1 in range [1,2n+1]." '(off: 0) ;; '(create-b-file: 1) '(y: "A076409(n)=a(A102781(n)). Cf. A166101-A166104.") '(e: "Explain it for some n !") '(scheme: (define (A166100 n) (let ((w (A005408 n))) ;; w = 2n+1 (let loop ((i 1) (s 1)) (cond ((= i w) s) (else (loop (1+ i) (+ s (if (= +1 (jacobi-symbol (1+ i) w)) (1+ i) 0)) ) ) ) ) ) ) ) ) (list 166101 "Integers i such A166100(i)/A005408(i) is not integer." '(off: 1) '(upto: 10) '(y: "A166102 gives the corresponding odd numbers. Cf. A166272.") '(scheme: (define A166101 (MATCHING-POS 1 0 (lambda (i) (not (integer? (/ (A166100 i) (A005408 i)))))) ) ) ) (list 166102 "Odd numbers i such A166100((i-1)/2)/i is not integer." '(off: 1) '(upto: 10) '(c: "Conjecture: a(n)=3*A166103(n). (Checked for terms a(1)-a(92).)") '(comps: (005408 166101)) '(y: "Cf. A166272.") ) (list 166103 "Squares of A166104." '(off: 1) '(c: "Conjecture: a(n)=A166102(n)/3. (Checked for terms a(1)-a(92).)") '(comps: (000290 166104)) ) (list 166104 "Natural numbers whose all prime factors are congruent to 3 or 5 mod 6. (i.e. in the sequence A045410)." '(off: 1) '(c: "1 is included here as the first term, as it has no prime factors at all, thus \"all of them\" satisfy the criterion of being a member of A045410.") '(y: "See the conjecture at A166103. Cf. A045410.") '(scheme: (define A166104 (MATCHING-POS 1 1 (lambda (n) (for-all? (factor n) (lambda (p) (or (= 1 p) (= 3 p) (= 5 (modulo p 6)))) ) ) ) ) ) ) (list 166272 "Numerator of A166100(A166101(n))/A166102(n)." '(off: 1) '(upto: 10) '(c: "Conjecture: equal to 3*A166100(A166101(n))/A166102(n), i.e. the denominator of the quotient A166100(A166101(n))/A166102(n) in its reduced form is always 3.") '(y: "Cf. A166272.") ) (list 166268 "Bisection 2n of A166050." '(off: 0) '(create-b-file: 16383) '(c: "Conjecture: a(n) = A166270(n)/2, and also A165605(A005843(n)).") '(comps: (166050 005843) (165605 005843) (004526 166270)) ) (list 166269 "Bisection 2n+1 of A166050." '(off: 0) '(create-b-file: 16383) '(c: "Conjecture: a(n) = -(1/2) * A166271(n).") '(comps: (166050 005408) (001489 004526 166271)) ) (list 166270 "Bisection 2n of A165460." '(off: 0) '(create-b-file: 16383) '(c: "Conjecture: a(n) = 2*A166268(n).") '(comps: (165460 005843) (005843 166268)) ) (list 166271 "Bisection 2n+1 of A165460." '(off: 0) '(create-b-file: 16383) '(c: "Conjecture: a(n) = -2 * A166269(n).") '(comps: (165460 005408) (001489 005843 166269)) ) (list 166273 "Bisection 2n+1 of A165605." '(off: 0) '(create-b-file: 16383) '(c: "Conjecture: a(n) = -3 * A166269(n).") '(comps: (165605 005408) (001489 008585 166269)) ) ) ) ;; (load "GF2Xfuns") ;; (cd "seqs/next2batch") ;; (output-entries-to-file120_45 seqs2009oct20a "2009oct20a.scm" "Oct 20 2009") (define seqs2009oct20a (list (list 166166 "Write n in binary with each run (of either digit b) of the kth-longest distinct run-length replaced with a run of digit b of a length equal to that of the k-th shortest distinct run-length. Convert back to decimal for a(n). (See comment.) Leroy Quet, Oct 08 2009" '(off: 0) '(create-b-file: 65535) '(indentries: Nperm) '(inv: 166166) '(y: "Cf. A056539, A166404.") '(scheme: (define (A166166 n) (let* ((runlens (binexp->runcount1list n)) (rlsorted (uniq (sort runlens <))) (lenrls (length rlsorted)) ) (let loop ((rl runlens) (s 0) (b 1)) (cond ((null? rl) s) (else (let* ((nrl (list-ref rlsorted (- lenrls 1 (nthmemq (car rl) rlsorted)) ) ) (p2 (expt 2 nrl)) ) (loop (cdr rl) (+ (* s p2) (* b (-1+ p2))) (- 1 b)) ) ) ) ) ) ) (define (binexp->runcount1list n) ;; (length (binexp->runcount1list n)) gives A005811 (if (zero? n) (list) (let loop ((n n) (rc (list)) (count 0) (prev-bit (modulo n 2))) (if (zero? n) (cons count rc) (if (eq? (modulo n 2) prev-bit) ;; If the lsb has not changed (loop (floor->exact (/ n 2)) rc (1+ count) (modulo n 2) ) (loop (floor->exact (/ n 2)) ;; If it has changed (cons count rc) 1 (modulo n 2) ) ) ) ) ) ) (define (uniq lista) ;; Assumed to be sorted already with (sort lista <) (let loop ((lista lista) (z (list))) (cond ((null? lista) (reverse! z)) ((and (pair? z) (equal? (car z) (car lista))) (loop (cdr lista) z) ) (else (loop (cdr lista) (cons (car lista) z))) ) ) ) (define (nthmemq elem lista) (let loop ((lista lista) (i 0)) (cond ((null? lista) #f) ((eq? (car lista) elem) i) (else (loop (cdr lista) (1+ i))) ) ) ) ) ) (list 166404 "Self-inverse permutation of natural numbers obtained by exchanging the run lengths of adjacent runs of ones and zeros, starting from the most significant run of 1's. (See comment lines)." '(off: 0) '(create-b-file: 65535) '(indentries: Nperm) '(inv: 166404) '(y: "Cf. A056539, A166166.") '(scheme: ;; Cf. A056539 (define (A166404 n) ;; begins as 0,1,2,3,6,5,4,7,14,13,10,11,12,9,8,15,30,29,26,27,22,21,20,23,28,25,... (let ((runlens (binexp->runcount1list n))) (runcount1list->binexp (interleave (bisect runlens 1) (bisect runlens 0))) ) ) (define (binexp->runcount1list n) ;; (length (binexp->runcount1list n)) gives A005811 (if (zero? n) (list) (let loop ((n n) (rc (list)) (count 0) (prev-bit (modulo n 2))) (if (zero? n) (cons count rc) (if (eq? (modulo n 2) prev-bit) ;; If the lsb has not changed (loop (floor->exact (/ n 2)) rc (1+ count) (modulo n 2) ) (loop (floor->exact (/ n 2)) ;; If it has changed (cons count rc) 1 (modulo n 2) ) ) ) ) ) ) (define (runcount1list->binexp lista) (let loop ((lista lista) (s 0) (state 1)) (cond ((null? lista) s) (else (loop (cdr lista) (+ (* s (expt 2 (car lista))) (* state (- (expt 2 (car lista)) 1)) ) (- 1 state) ) ) ) ) ) (define (bisect lista parity) ;; Parity is 0 or 1. (let loop ((lista lista) (i 0) (z (list))) (cond ((null? lista) (reverse! z)) ((eq? i parity) (loop (cdr lista) (modulo (1+ i) 2) (cons (car lista) z)) ) (else (loop (cdr lista) (modulo (1+ i) 2) z)) ) ) ) (define (interleave a b) (let loop ((z (list)) (a a) (b b)) (cond ((and (null? a) (null? b)) (reverse! z)) ((null? a) (loop (cons (car b) z) a (cdr b))) ((null? b) (loop (cons (car a) z) (cdr a) b)) (else (loop (cons (car b) (cons (car a) z)) (cdr a) (cdr b))) ) ) ) ) ) ) ) ;; (load "GF2Xfuns") ;; Do the following again, because GF2Xfuns loads slib-library ;; with its old slow version of jacobi-symbol: ;; (define jacobi-symbol fix:jacobi-symbol) ;; (define legendre-symbol jacobi-symbol) ;; (cd "seqs/next3batch") ;; (output-entries-to-file120_45 seqs2009oct21 "2009oct21.scm" "Oct 21 2009") (define seqs2009oct21a (list (list 166405 "Sum of those positive i <= 2n+1, for which J(i,2n+1)=-1. Here J(i,k) is the Jacobi symbol." '(off: 0) '(create-b-file: 131071) '(y: "A125615(n)=a(A102781(n)). Cf. A166100, A166406-A166408. The cases where a(i)/A005408(i) is not integer seem also to be given by A166101. This is NOT a bisection of A165898. Scheme-code for jacobi-symbol is given at A165601.") '(e: "For n=5, we get odd number 11 (2*5+1), and J(i,11) = 1,-1,1,1,1,-1,-1,-1,1,-1,0 when i ranges from 1 to 11, J(i,11) getting value -1 when i=2, 6, 7, 8 and 10, thus a(5)=33.") '(scheme: (define (A166405 n) (let ((w (A005408 n))) ;; w = 2n+1 (let loop ((i 1) (s 0)) (cond ((= i w) s) (else (loop (1+ i) (+ s (if (= -1 (jacobi-symbol (1+ i) w)) (1+ i) 0)) ) ) ) ) ) ) ) ) (list 166406 "a(n) = A166405(n)-A166100(n)." '(off: 0) '(create-b-file: 65535) '(y: "A125615(n)=a(A102781(n)). Cf. A166100, A166407-A166409. The cases where a(i)/A005408(i) is not integer seem also to be given by A166101.") ) (list 166407 "a(n) = floor(3*(A166406(n)/A005408(n)))." '(off: 0) '(create-b-file: 65535) '(c: "Conjecture: the quotient A166406(i)/A005408(i) has denominator 3 when i is one of the terms of A166101, and integral otherwise. If true, then floor in the formula is unnecessary.") '(y: "Cf. A166408.") ) (list 166408 "a(n) = floor(A166407(n)/3)." '(off: 0) '(c: "See the conjecture in A166407. If true, then a(i) = A166406(i)/A005408(i), whenever i is not in A166101.") '(y: "A165951(n)=a(A102781(n)) for n>=2.") ) (list 166409 "Positions of zeros in A166406." '(off: 1) '(c: "Probably a union of A077425 & A165603.") ) ) )