User:DroneBetter/miscellaneous curiosities
this page is largely to be considered superseded by my OEISwiki writings, except for the parts i haven't found interesting enough to write about there. in general those pages are more explanatory while things here are either workings or rough unannotated result tabulations. there are various things i was unaware of while writing this like the combinatorial version of Faà di Bruno's formula which would have benefited it significantly, so it isn't useful as a reference work for the things it does study (rather an exhibition of times i hit my head against the ceiling of my then-knowledge) plus, pages over there can use LaTeX which significantly furthers the whimsy:decipherableness Pareto hull <math>.\ .\atop\smile</math> |
I created this page to explain programs that aren't large or relevant enough to Life to warrant pages of their own in the wiki, typically for problems that partially arose in tasks in my programming but give rise to phenomena (beyond the main programs' scopes) that made them pursuits unto themselves, that may be of interest to others. However, since creating it my interests grew broader, after the first section it is mainly comprised of things I intend to put on the OEIS eventually (as notes or sequences of their own). In this sense, it is intended more to be a buffer than any kind of reference material, but I hope others will gleam enjoyment from it.
The three programs with which it begins are arranged in increasing order of complexity, but the rest is grouped very loosely by category, not chronologically, though I usually add it at about the time of discovery (the part that gets to be the outer part of a section rather than a subsection is a somewhat arbitrary decision). Of the discoveries, the simpler ones have probably been found before, the more complicated ones have probably not.
This page seems off-topic for the wiki (even for a userspace), but the most interesting things in it are those primarily concerning emergent patterns and structures in recursive systems, often similar in nature to cellular automata. My mathematical interests are mainly in such things that arise from programming, or those to which it can be applied (like combinatorics and generating functions), though this page is increasingly varied, and its subjects often lead to other areas.
I rearrange parts frequently, and comment out those I no longer deem interesting enough to be worthwhile, with the intention of eventually perhaps returning to them.
often I will find that a problem is intractable to my current knowledge, but find other things I did not intend to (serendipity accounts for many of the most interesting parts)
my areas of interest are somewhat focused upon combinatorics, mainly since that is the one to which my proclivity for programming has found most use
- your mathematics has goblin energy, it's a hoard of random shiny baubles of dubious worth
- -Magma (from the ConwayLife lounge)
Conventions
Some words and phrases like "almost all" are used in the mathematical sense, and O is used to refer to functions asymptotically bounding above, see the Big-Θ notation page.
Exponentiation is right-associative (ie. abc=a(bc), not (ab)c). Booleans are interpreted as integers (ie. every bracket is the Iverson bracket ), and dyadic boolean operators generalise to integers in the Python shortcutting way ((a and b)=(b if a else a) and (a or b)=(a if a else b), where integers are considered true iff they're nonzero). Generally, = is used to denote truth, and == the function that returns booleans.
The conversion of a function over the nonnegative integers to its generating function (and exponential, Dirichlet or binomial thereof) is denoted with the functions gf, egf, dgf and bgf (even though the former may only be formal power series, and the latter are not necessarily unique).[co 1] However, here functions are often denoted as equal (ie. in chains of equalities in workings) if they output the same values over their domain, even if they're computed by different methods or uncomputable. Occasionally, their inverse functions (ie. gf-1(f)) are used, when the most elegant means of expressing a function is through its g.f.
Let pn denote the nth term of an analytic function p's series expansion (ie. diffn(p)(0)n!). It is not to be confused with the Pochhammer falling factorial (which isn't used here).
Also with currying where calculus arises, I use
- diff=λ f: λ x: ∑∞n=1(fn*n*xn-1)
. . =λ f: λ x: limh->0(f(x+h)-f(x)h) - ∫=λ f: λ x: ∑∞n=0(fn*xn+1n+1)
.=λ f: λ x: limn->∞(∑nk=0(f(k*xn))*xn) - ∫ab=λ f: ∫(f)(b)-∫(f)(a)
Similarly to log, let vald(n) be the exponent of the greatest power of d dividing n, the d-adic valuation of n (A286563), so ρ(n)=val2(n).
In general, this mainly uses Python syntax (especially lambda functions :-), but for the purposes of conciseness and readability, the word lambda is substituted for λ, and l.index(i) is abbreviated to l.ι(i), as in APL. It is the language I fell in love with but also hate; I ought to move onto Haskell eventually but also have a nice library through which I entrench myself here.
Operator precedence is as in Python and C. Everywhere they are used, ^ refers exclusively to bitwise XOR and exponentiation is exclusively denoted by superscript, and except where specified otherwise, | refers to bitwise OR, not divisibility.
The symbols ⌊⌋ refer to floor, and ⌈⌉ to ceiling.
∑ is upper-inclusive, and for a<b, ∑an=b(f(n)) = -∑b-1n=a+1(f(n)). sum behaves the same as the Python function, but sum(map(f,range(b,a))) = -sum(map(f,range(a,b)))
When the upper argument of ∑ is omitted, the lower one is a condition (sometimes membership within a set), where the summand iterates over all values that satisfy it.
ℕ is considered to be 0-indexed, and ℕ+ to be 1-. ℙ is used as the set of prime numbers.
In general, multivariate generating functions of arrays (of n and k) follow the OEIS convention of λ x,y: ∑∞n=0(∑∞k=0(a(n,k)*xn*yk)), despite the fact that they're generally written in tables with n on the y axis and k on the x.
Some things are given in terms of conventionally formatted math, others in inline Python, depending on whether they're intended to convey or demonstrate things. All Python excerpts work, though they may require things from dronery to be imported first.
for Stirling numbers of the first kind, I use Knuth's convention [nk] = A132393(n,k) so that [nk]={-k-n} holds (by polynomial extension of the diagonals) and ∑nk=0([nk]*xk)n! equals (x+n-1n) rather than (xn)
for Eulerian numbers, I use <nk> = A123125(n,k) so that gf(λ k: kn)=λ x: ∑nk=0(<nk>*xk)(1-x)n+1
for Bernoulli numbers, I use B-n, with B-2=-12 (since unlike Peter Luschny I am upperexclusivebrained), and for Gregory coefficients, G0=1,G1=12, etc. (ie. Gn = A002206(n-1)A002207(n-1), so the same as Wikipedia but different from the OEIS)
notes
bijective structure-emulators
hexagon bijector
Say we have a range-r hexagonal neighbourhood, and would like to assign a coordinate system to its cells. Of the three directions perpendicular to the edges, we choose two as our x and y (such that interpreting them as perpendicular would make it look like a square, with the bottom-left and top-right quadrants each missing their outer diagonal halves). We would like to iterate over them in row-major order (that we read in).
Shown here are the hexagons (with cells' coordinates in our convention, ranks in the iterating order and positions in the square coordinate reinterpretation) for r=1 and r=2.
(0,0) (1,0) 0 1 oo
(0,1) (1,1) (2,1) 2 3 4 ooo
(1,2) (2,2) 5 6 oo
(0,0) (1,0) (2,0) 0 1 2 ooo
(0,1) (1,1) (2,1) (3,1) 3 4 5 6 oooo
(0,2) (1,2) (2,2) (3,2) (4,2) 7 8 9 a b ooooo
(1,3) (2,3) (3,3) (4,3) c d e f oooo
(2,4) (3,4) (4,4) g h i ooo
Making this program uses the fact that where
- l = ∑n-1k=0(k) = ∑n-1k=0(k1) = (n2) = n*(n-1)2 = (2*n-1)2-18
it is invertible,
- n = ⌊√8*l+1+12⌋
(where l is the index within the flattened list representation)
We could generate a list of coordinate tuples and index within that, but instead (out of scientific curiosity) we will make a program that behaves equivalently (ie. in case a hexagonal board is very large and couldn't be stored).
class hexer:
def __init__(h,r):
h.r=r
h.cells=3*h.r*(h.r+1)+1
__len__=λ h: h.cells
This length equation can be derived geometrically, by the fact that there's an (r+1)*(r+1) square in the top-left, and r L-shaped strips, each of total length 2*r+1.
We can iterate over each of these coordinates in order trivially with a nested list comprehension.
__iter__=λ h: ((x,y) for y in range(2*r+1) for x in (range(r+1+y) if y<=r else range(y-r,2*r+1)))
The expression for the widths of each row is (r+1+y if y<=r else 3*r+1-y for y in range(2*r+1)).
So we can sum this first part up to (and excluding) a given value of y (so we know the index at which our counting begins),
- s = (λ y: ∑y-1y=0(r+1+y) = (λ y: y*(y+2*r+1)2)
and substitute in y=r+1 to know the index at which the second segment (in which the width decreases) begins,
- s(r+1) = (r+1)*(3*r+2)2
And add this to the summation of the second segment,
- s = (λ y: (r+1)*(3*r+2)2 + ∑y-1y=r+1(3*r+1-y)) = (λ y: (r+1)*(3*r+2) + (y-r-1)*(5*r+2-y)2) = (λ y: y*(3-y)2 + r*(3*y-1-r))
Now we must only add x for the first segment, and x-(y-r) for the second (which begins with the part "cut out") and simplify, and we have created a function (that unpacks and indexes coordinates).
__index__=λ h,c: (λ x,y: (y*(y+2*r+1)//2 if y<=r else y*(3-y)//2+r*(3*y+~r))+x)(*c)
Now we can use len(hexer(3)) and hexer(3).index((1,2)), but would like a __getitem__ so we can use hexer(3)[10] also.
For both variants, we can find the inverse of this existing function, to calculate the y value from the index (i), and find the x by the difference between this and the first i that produces the y.
- i = y*(y+2*r+1)2,
- y2 + (2*r+1)*y - 2*i = 0,
- y = -1 - 2*r ± √(2*r+1)2 + 8*i2
- i = (r+1)*(3*r+2) + (y-r-1)*(5*r+2-y)2,
- -y2 + (3+6*r)*y - 2*r - 2*r2 - 2*i = 0,
- y = 3 + 6*r ± √(3+6*r)2 - 8*(r+r2+i)2
- . = 3 + 6*r ± √9 - 8*i + 28*r*(r+1)2
The quadratic formula returns two roots, the first one will use the positive branch of the sqrt (because it grows at a slowing rate as i increases), and the second the negative branch (because it grows at an accelerating rate).
These will each return integers only if i equals a value outputted by s, when the x position is at the beginning of the row (where x=0 in the first part, and the x=y-r term in the second). However, because they're strictly increasing functions over their intended range (within the hexagon), taking their floor will return the desired y.
Python (and other languages) implement an isqrt function, equivalent to the floor of the square-root but computed more efficiently (without converting to an intermediate float) and exactly (working on Python's arbitrarily long (self-extending) ints), we can substitute the positive sqrt for it and the second one for a ceiling-sqrt function (adding 1 if the isqrt is smaller).
A trivial implementation is ceilsqrt=λ x: (s:=isqrt(x))+(s**2<x), but because the graph is the same as isqrt's but shifted rightwards and upwards by 1, it can equivalently be implemented branchlessly, as ceilsqrt=λ n: n and isqrt(n-1)+1.[h 2]
We enact the summation function on this (the floor of its inverse) to obtain the value of i that the index would take if the x position were minimal, and subtract it from the actual value for the x position (i's difference from that).
__getitem__=λ h,i: (λ y: (i-y*(y+2*r+1)//2,y))((isqrt(8*i+(1+2*r)**2)-1)//2-r) if i<(r+1)*(3*r+2)//2 else (λ y: (i+1-y*(3-y)//2-r*(3*y+~r),y))(3*r+(3-ceilsqrt(9-8*i+28*r*(1+r)))//2)
(Note that for very large lists, this method is actually slower than storing it all, because it takes O(n*log(n)) time (with respect to the length of the integer number of cells) to compute an integer square-root, whereas list bisection would take O(n).)
notes
lexbin
At the bottom of the bit-twiddling hacks is Compute the lexicographically next bit permutation (ie. a function such that f(0b1)=0b10, f(0b101)=0b110). Beginning with (1<<m)-1[l 1] you can reach any positive integer that also has m 1s in its binary representation, by recursively applying f. Nontrivially, f may be defined exactly as
- lexinc=λ n: n and (u:=(n|n-1)+1)|((u&-u)//(n&-n)>>1)-1
However, the bit hacks haven't been updated since 2011, and if you input tuple(map(lexinc,range(1,16))) to the OEIS, you will find that there is a sequence,
A057168, and a function from Michael S. Branicky in 2022-07-10, using the same single floordiv and bitshift, but only four arithmetic operations instead of five, and two bitwise ones instead of three, equivalent to
- lexinc=λ n: n and ((n^n+(u:=n&-n))//u>>2)+n+u
However, the + may be instead an |.[l 2]
- lexinc=λ n: n and (n^n+(u:=n&-n))//u>>2|n+u
After learning about this I wondered, if you define an infinite sequence where a[0]=(1<<m)-1 and a[n+1]=lexinc(a[n]), whether there is a way to index an element or get it from its index more efficiently than generating all of its predecessors on-the-fly or caching them. This is a simple problem but interesting if you aren't aware.
We will define (for our convenience) a function for iterating over an integer's bits in little-endian order.
- decompose=λ n: map(λ i: n>>i&1,range(n.bit_length())
This involves combinatorics, so from math we will import factorial as fact,comb as choose.[l 3]
A 1-bit at the nth place (0-indexed), with k 1-bits after it, will have (nk) possible permutations of those bits, so we only need to sum this for all i from k to (and excluding) n, to get the index of an integer with the 1 bit in the nth place, and all k after it being packed to the right. ∑n-1i=k(ik)=(nk+1)-(kk+1)=(nk+1). We will iterate over the bits upwards from the lowest place value, adding this choose function's output for each nonzero one and counting up the number of occurrences thus far in the same loop in a reduce function. In the s,m,i,b function,
- s is the running sum of chooses constructing the index thus far,
- m is the count of 1-bits,
- i is the current bit's index, and b its value.
(By counting 0s instead of 1s, our output is the same (because (nk)=(nn-k)), but we can avoid having to add 1 to m on the left side of the if, where it appears in both the choose function call and the assigning of its new value.)
bindex=λ i: reduce(λ r,i: (λ s,m,i,b: (s+choose(i,m),m) if b else (s,m+1))(*r,*i),enumerate(decompose(i)),(0,-1))[0]
And this does indeed return A079071(i).
However, we can use the fact that (n+1k)=(nk)*(n+1)n+1-k, and (n+1k+1)=(nk)*(n+1)k+1, to avoid having to recompute the entire choose function each iteration by instead mutating its output in-place (as a new variable, c).
bindex=λ i: reduce(λ m,i: (λ s,m,c,i,b: ((s+c,m,c*i//(i-m+1)) if b else (s,m+1,c*i//m)) if m else (s,1-b,c))(*m,*i),enumerate(decompose(i),1),(0,0,1))[0]
We will define a class, instances of which (given the m parameter) emulate sorted infinite sets of integers with a bit_count of m. The optional n parameter specifies their contained integers' maximum length, allowing them to be finite.
class lexbin:
def __init__(self,m,n=0):
self.m=m;self.n=self.m
self.length=choose(n,m)
__len__=λ self: self.length
index=λ self,i: bindex(i)
Now we will implement getting an element of the lexbin, given its index. In constructing the integer, for the decision at the nth bit, if it's set to 0, the maximum index that any configuration of its preceding bits can reach (packed to the left) is 1 less than the minimum if it's set to 1 (with them packed to the right). This means that when the preceding bits are known but the succeeding bits' states are undetermined, the state of the nth bisects the range containing the index, so we can iterate over the bits in reverse order (an idea which will recur in this article).
getter=λ self,i: construce(λ o,m,i,n: (o<<1,m,i) if i<choose(n,m) else (o<<1|1,m-1,i-choose(n,m)),revange(self.n),(0,self.m,i))[0]
However, for infinite lexbins (with the n parameter not specified), this requires us to guarantee that the chosen upper bound of n is greater than or equal to the length of the element we're getting. To minimise the number of bits we iterate over, we need it to be the first value such that (nk) (the number of integers with bit_count k up to bit_length n) is greater than or equal to the index i.
def firstchoose(k,i):
n=k;c=1
while c<=i:
n+=1;c=c*n//(n-k)
return(n)
getter=λ self,i: construce(λ o,m,i,n: (o<<1,m,i) if i<choose(n,m) else (o<<1|1,m-1,i-choose(n,m)),revange(firstchoose(self.m,i)),(0,self.m,i))[0]
And so now our __getitem__ (supporting slices) and __iter__ functions can be defined in terms of it.
__getitem__=λ self,i: expumulate(lexinc,i.stop-i.start-1)(self.getter(i.start)) if type(i)==slice else self.getter(i) __iter__=λ self: expumulate(lexinc,choose(self.n,self.m)-1)((1<<self.m)-1)
If each bit of a length-n integer's binary expansion is interpreted as the coordinate in a corresponding axis of a vertex on an n-dimensional hypercube, lexbin(m,n) is the set of (nm) vertices a total of m edges from the origin. They may also be interpreted as the group of reflections through orthogonal hyperplane lines of symmetry, composed by bitwise XOR. A k-dimensional facet of an n-dimensional hypercube may be given in canonicalised form by two such length-n integers varying in bit_count by k (one of which contains a superset of the other's 1-bits). For each such integer i of bit_count b<=n-k, generating lexbin(n-b,k) and inserting them in i's 0s provides the set of facets with a "smallest vertex" i.
I was playing with this, and decided to generate every combination of a vertice o, that is k edges from the origin in an n-dimensional hypercube, and a vertice i, that is k edges from o, and find every vertice that is an intermediate point on a path from o to i, sorting each set of intermediates into a tuple unpacked into a set over all o,i pairs, and returning the length of this set. It seems to be that for a given value of n and k, this is equivalent to the sum of the trinomial choose function, A141905(n,k)=∑n-kj=0(n!k!*j!*(n-k-j)!).
from functools import reduce
from itertools import accumulate,product
expumulate=λ f,l: λ i: accumulate(range(l),λ x,i: f(x),initial=i)
dims=5
lexinc=λ n: n^n+(u:=n&-n))//u>>2|n+u
perms=λ n,m: expumulate(lexinc,choose(n,m)-1)((1<<m)-1)
f=λ n,k: {tuple(sorted(reduce(λ o,r: (o[0]^(c>>o[1]&1)<<r,o[1]+1) if i>>r&1 else o,range(n),(o,0))[0] for c in range(1<<k))) for o,i in product(perms(n,k),repeat=2)}
print(tuple(len(f(n,k) ) for n in range(dims+1) for k in range(d+1)))
A141905=λ n,k: sum(choose(n,k,j) for j in range(k+1))
print(tuple(A141905(n,k) for n in range(dims+1) for k in range(d+1)))
notes
- ↑ (equivalently, ~(~0<<m) :-)
- ↑ It was first published in MIT's HAKMEM memo, item 175 (transcription), but it seems Michael S. Branicky didn't know that and copied it from Charles R. Greathouse IV, who had changed the | to a + to save space, because he'd otherwise have to write bitor in PARI/GP.
- ↑ Typically, in my programming, I define
- fact=lambda n: factorial(n) if type(n) in {int,bool} else gamma(n+1)
- choose=lambda n,*k: comb(n,k[0]) if len(k)==1 else (lambda n,*k: int(all(map((0).__le__,k)) and fact(n)//reduce(int.__mul__,map(fact,k))))(n,*k,n-sum(k))
twofold reducer
This is a program like the eightfold reducer, but for 1-dimensional tapes. Due to its relative simplicity, it doesn't require any separate lookup tables (its 'layers' being comprised only of up to 2 cells), and much can be inlined manually.
Similarly its eightfold sibling, we will define a class, twofold, so that setting t=twofold(5) will allow t to be treated as a list-like structure, to have elements indexed and retrieved and slices iterated over efficiently, using constant space with respect to the size of the structure instead of linear (as storing it directly would require).[r 1] This may be useful, for instance, to anyone wanting to run an exhaustive oscillator search program on bounded tapes in an isotropic Wolfram rule more quickly, by iterating over nonequivalent initial states without duplicates.
The implementation shown here will work only on integers' binary representations, and will be inner-little-/outer-big-endian (considering the outermost bits to be of the highest precedence (changed last) instead of the centre like the first one), so that it can guarantee that its canonical representations will be lexicographically minimal states, and thus minimal integer values.[r 2]
We will begin with some definitions that will be useful later.
revange=λ a,b=None,c=1: range(b-c,a-c,-c) if b else range(a-c,-c,-c)
redumulate=λ f,l,i=None: accumulate(l,f,initial=i)
funcxp=λ f,l: λ i: reduce(λ x,i: f(x),range(l),i)
construce=λ f,l,i=None: reduce(λ a,b: f(*a,b),l,i)
def iindex(s,i,d=None):
try:
n=0
j=next(s)
while j!=i:
n+=1
j=next(s)
return(n)
except StopIteration: return(n if d==None else d)
def shortduce(f,l,i=None,o=None,b=None):
if i==None: i=next(l)
i=(i,True)
for j in l:
if i[1]: i=f(i[0],j)
else: return(i[0] if b==None else b(i[0]))
return((λ f,i: i if f==None else f(i))(o if i[1] else b,i[0]))
- revange returns reversed ranges (so that we don't have to offset all three parameters ourselves),
- redumulate is accumulate with reduce syntax,
- funcxp is for functional exponentiation (ie. funcxp(f,2)(x)=f(f(x))),[r 3]
- construce is like starmap but for reduce instead, unpacking the accumulated value into the lambda function (for multiple-element recursive systems),
- iindex is equivalent to index but for iterators (ie. generator expressions and map, filter and accumulate) that don't implement the method because they generate their elements on-the-fly as they're queried,
- shortduce is equivalent to reduce but is short-circuiting, and requires the function to return a tuple containing both its regular output (to be inputted in the next iteration) and a boolean (whether to continue, otherwise stopping early).
(See also bitwise SWAR Life's prerequisites.)
Note that the expression for 1D tapes under symmetry in the Pólya enumeration theorem article (A005418(n+1)=A361870(n)), because there are n cycles in the identity action, and ⌈n/2⌉ in the reflection one (because the central one is not halved in odd cases), is
- 2n+2⌈n/2⌉2
is implementable as self.length=(2**n+2**((n+1)//2))//2[r 4] The (n+1)//2 is using the fact that over the integers, ⌈pq⌉=⌊p+q-1q⌋=⌊p-1q⌋+1.[r 5] Our class will begin
class twofold:
def __init__(self,n):
self.n=n
self.length=(1<<(n+1>>1)|1<<n)>>1
__len__=λ self: self.length
strate=λ self,s: ''.join(map(λ i: 'o' if s>>i&1 else ' ',range(self.n)))
In the __init__ function, we will also add the reversalParameters function from the manifold implementation in bitwise SWAR Life, for generating functions for reversing n-bit numbers' binary representations.[r 6] However, I couldn't find a way to execute a definition within the __init__ function, to define a function local to the class instance, so reversalParameters's final line will be replaced with a slightly suspicious lambda function version.
return(eval("lambda x: "+"".join("(lambda x: "+'|'.join(conditionalSwap('x',(n[2] and n[1]),"&"+indent(marge[0],str(hex(n[0]))),((">>" if n[1]>0 else "<<")+indent(marge[1],str(abs(n[1]))) if n[1] else ' '*(2+marge[1])),(n[1] and n[2])) for n in m)+')(' for m in masks[::-1])+'x'+')'*len(masks)))
then we can use self.reversed=reversalParameters(n) (and self.halfverse=reversalParameters(n>>1) for later).
Now, we will define layers here as pairs of cells with the same displacement from the centre (except for the central cell for odd n, which is considered separately), with the outermost pair having index 0, and make a function for getting a layer (by putting its bits in a 2-bit integer, preserving their order).
Unlike the eightfold reducer, the central layer has the highest index, but still the lowest precedence. It counts in modified base-4, with the outermost bits having the highest precedence. This has the consequence that in comparing two values, their second half (including the central cell if odd) only needs to be halved if their first halves (excluding it) don't differ.
layer=λ self,s,i: s>>i&1|s>>self.n-i-2&2
In n dimensions, for oblique cells, there are A000165(n)=n!*2n actions, so layers (equivalence classes of cells under action the group) have up to A000165(n) cells, maximised when they're 'oblique' (not lying on lines of symmetry), meaning 2A000165(n) states must be accounted for. For n=1 this provides 4 different layer values (00,01,10,11) instead of 256, and only two symmetry classes instead of eight. This means it is feasible to unravel the layer-incrementing function for each symmetry.
It will intake parameters s,b,i,
- s is the state (an integer),
- b is the index of its first asymmetrical layer (from the outside (lowest index, highest precedence) inwards). If an incremented layer's index is less than this, the layer won't increment to 0b10, because all states in which it is 0b10 could be reflected to states in which it's 0b01 (making the integer's leading half smaller).
- i is the current index being incremented.
It is made to be put within shortduce, and will return a nested tuple, ((s,b),c) (the i being provided by te shortduce).
- s is the state with layer i incremented.
- b is amended from its input,
- c is a boolean of whether it has incremented from 3 (0b11, the maximum value a layer may take), and must produce a carry. (shortduce will terminate, returning the final s, when it becomes false.)
layinc=λ self,s,b,i: (λ l: ((s&~(1<<i|1<<self.n+~i),b),True) #11 -> 00 and carry
if l==3 else #both on
( (s|1<<i,i if i==b+1 else b) #10 -> 11, increment b if symmetry has been extended
if l==2 else #left (greater) on
( (s&~(1<<i)|1<<self.n+~i,b) #01 -> 10 (allowed because asymmetrical)
if l else #right (smaller) on
(s|1<<i,b)) #00 -> 01
if i>b else #beyond threshold, into the asymmetrical layers
( (s|1<<self.n+~i,b) #01 -> 11 (no 10)
if l else #right (smaller) on
(s|1<<i,i)), #00 -> 01 (b becomes i, all greater (lower-precedence) layers may now be asymmetrical)
False))(self.layer(s,i))
The branch function will find the index b at which symmetry begins within a state. It only has to search through the layers for a 01, which is the only layer value that can violate symmetry (because states with 10's doing so are equivalent but lexicographically greater, and won't be reached) but instead finds disparities both ways by searching the XORs of bits in a layer for a 1. If the carry process reaches the central cell for an odd width, it adds 1 so it isn't disturbed by its increment.
branch=λ self,s: (λ i: i+(i==self.n//2 and self.n&1))(iindex(map(λ i: s>>i&1^s>>self.n+~i&1,range(self.n//2)),1))
Note that the layer at the index branch returns is the first asymmetrical one, not the last symmetrical one. This is intentional, because for the purpose of its incrementing, it's still under action of its predecessors' symmetry, so is the last one that can't itself become 0b10 while preserving its predecessors.
Now a symmetry function for "canonicalising" input states (much smaller than the one in the eightfold version[r 7]),
symmetry=λ self,s: self.reverse(s) if (λ b: b<=self.n//2 and self.layer(s,b)==2)(self.branch(s)) else s
Now we put it together in the shortduce, for function that, given a state and its branch value, increments the state (recursively applying layinc outwards as far as the layers overflow) and returns both. Our function would be
nexter=λ self,s,b: shortduce(λ s,i: self.layinc(*s,i),revange(self.n//2),(s,b))
However, for odd widths n, we can make the innermost cell count in base-2, and carry to the other base-4 cells.
(Note that this means that for integer n, A361870(1,2*n+1)=2*A361870(1,2*n), and in our ordering convention, the central cell's state is the index's parity modulo 2 (whereas in the eightfold one it is whether it's in the second half of the index range))
nexter=λ self,s,b: (s|1<<self.n//2,b) if self.n&1 and not s&1<<self.n//2 else shortduce(λ s,i: self.layinc(*s,i),revange(self.n//2),(s&~(1<<self.n//2) if self.n&1 else s,b))
So we can define our __next__ (the in-place mutation function, for the purposes of Python internals and indexing, generating the value at the next index) to only compute branch, compute nexter once with that and discard the resultant branch value, and __iter__ in terms of it,
__next__=λ self,s: self.nexter(s,self.branch(s))[0] __iter__=λ self: redumulate(λ s,i: t.__next__(s),range(len(self)-1),0)
However, this way __next__ recomputes branch, instead __iter__ can store the branch value between iterations of nexter and remove it from its output with an enclosing map.
__iter__=λ self: map(λ i: i[0],redumulate(λ s,i: t.nexter(*s),range(len(self)-1),(0,self.n)))
It must be slightly less elegant to support slice notation,
__iter__=λ self,l=None,u=None: map(λ i: i[0],redumulate(λ s,i: t.nexter(*s),range((len(self) if u==None else u if l==None else u-l)-1),(0,self.n) if l==None else (λ s: (s,self.branch(s)))(self[l])))
Now for the interesting part, a function for determining the index of a state (in a similar manner to lexbin). We will first need one for computing partial sums on the length function (intaking a layer's value, its index and whether it's beyond the branch point, and returning the number of states in each of the layer's possible preceding values, to be added to the state's index in the structure, so that calling it and summing its results across all layers will return the index of the state itself).
Similarly to in the eightfold version, given a set of "known" layers and its corresponding symmetry group (which for 1D is only whether they're all binary palindromes), we can determine the number of nonequivalent states in the "unknown" layers outside it using the Pólya enumeration theorem. For each layer (iterating from the outside in, downwards in precedence instead of upwards like the carries), for each of the values preceding the one in the inputted state (excluding 10 if it's one of the outer symmetrical layers, so would have been the first layer violating symmetry), the number of states of the layers inside it may be counted. We sum this over the preceding values, and the results of these over the layers.
We will find the closed-form expression for each layer's "inner state count" (states of the tape, varying in the values of layers further inwards than the current one), for each of the current layer's states (00,01,10,11), both before and after the branch point (of symmetry ending).
In odd widths, we shift the index right by 1, and pretend it is an even width tape, then use the index's last bit for the central cell.
If the current layer in the sum is beyond the branch point, symmetry doesn't need to be considered, so the addition is the number of preceding values of the layer, times 2(n&~1)-2*(i+1). If it's under symmetry it becomes more complicated (because whether the states further in are under symmetry also depends on each of its states), but is ultimately only, for the layer's value
- if 0=0b00: 0
- if 1=0b01: 2n-2*i if b (symmetry has been broken before this layer), else the Pólya equation (that we derived for determining the twofold structure's length), with n substituted for n-i, because the only preceding value of this layer is 0, which conserves symmetry
- if 2=0b10: 2*2n-2*i (note that we don't need a case if b is False, because 0b10 violates symmetry in the wrong direction so only appears in layers where it's True)
- if 3=0b11: 3*2n-2*i if b. Else, the case for 01 (counting where it equalled 0), plus 2 times the non-symmetry-reduced case (counting when it equalled 1 and 2).
(Note that this is only for the even case, we here also treat odd widths as their even predecessors here and handle the innermost cell with parity)
So our explicit equation is
polya=λ self,l,i,b: ( 3<<(self.n&~1)-2*(i+1)
if b else
(1<<((self.n>>1)-1-i))+(2<<(self.n&~1)-2*(i+1))>>1)
if l==3 else
2<<(self.n&~1)-2*(i+1)
if l==2 else
( 1<<(self.n&~1)-2*(i+1)
if b else
(1<<((self.n>>1)-1-i))+(1<<(self.n&~1)-2*(i+1))>>1)
if l else 0)
We can reduce this arithmetically to
polya=λ self,l,i,b: l<<(self.n&~1)+(~i<<1) if b else l and (l<<(self.n&~1)+(~i<<1))+(1<<(self.n>>1)+~i)>>1
Now we would like to do this summing across layers, to implement our index method. First it will enact symmetry on s, and override the initial value by passing it as a parameter to the lambda function inside, which will calculate the branch value and pass it to the one inside it.
index=λ self,s,sym=True: indexMethod(self.branch(self.symmetry(s) if sym else s) indexMethod=λ b: sum(map(λ i: self.polya(self.layer(s,i),i,i>b),range(self.n>>1)))<<(self.n&1)|self.n&s>>(self.n>>1)&1
(the polya function itself uses n as the exponent of a power of 2, so we shift left by the width's last bit (its parity), then OR its last bit with n's last bit AND s's middle bit, using the fact that in odd widths, the middle bit's value is the index's parity).
The __getitem__ function, like the one in the eightfold reducer, only iterates over layers from the highest precedence downwards (inwards from the outside), for each one bisecting the range by incrementing it until the polya function returns a value greater than its initial value.
__getitem__=λ self,j: self.__iter__(j.start,j.stop) if type(j)==slice else (λ f: f(j>>1)|(j&1)<<(self.n>>1) if self.n&1 else f(j))(λ j: construce(λ s,j,b,i: (λ k,m: (s|(k&1)<<i|(k&2)<<(self.n+~i-1),j-m,b|k&1^k>>1))(*next(filter(λ r: r[0][1]<=j<r[1][1],pairwise(map(λ r: (r,len(self) if r==4 else self.polya(r,i,b)),(0,1,)+(2,)*b+(3,4)))))[0]),range(self.n//2),(0,j%len(self),0))[0]) if self.sym else j&(1<<self.n)-1
The type(j)==slice is for handling when it's called with two indexes, as lower and upper-exclusive limits delimited by a colon (slice notation), using the optional parameters we added to __iter__ (which, itself calls self[l], the __getitem__ method on an integer index), and otherwise defines a function f for even cases and, if n is odd, instead calls it with the index floor-halved (>>1 being equivalent to //2), then sets the middle bit based on the parity. Here is the function for even cases, on its own.
λ j: construce(λ s,j,b,i: (λ k,m: (s|(k&1)<<i|(k&2)<<(self.n+~i-1),j-m,b|k&1^k>>1))(*next(filter(λ r: r[0][1]<=j<r[1][1],pairwise(map(λ r: (r,len(self) if r==4 else self.polya(r,i,b)),(0,1,)+(2,)*b+(3,4)))))[0]),range(self.n//2),(0,j%len(self),0))[0]
The construce's tuple contains the state it's constructing, the index change remaining to enact and whether symmetry has been violated yet (in this constructed state). Each iteration, up to the floor-half of the state's length, it generates a list of values from 0 to 4 inclusive, generates the number of states preceding each of them (4's value being 1 greater than the index change remaining) and iterates pairwise (so that 4 only appears as the second element), then for each of these pairs it determines the first that the remaining index change falls within, and assigns it to the layer, subtracts its value from the index change (for the next iteration) and ORs the asymmetricality with the XOR of the new layer value's bits.
Now we can test it (the __name__ checking determining that it's the file being called by the user directly and not only ran by another importing it), checking each of the __iter__, __len__, __getitem__, reverse, symmetry and index methods.
if __name__=='__main__':
t=twofold(5)
print('|'.join(map(t.strate,t)))
print(len(t))
print('|'.join(map(λ i: t.strate(t[i]),range(len(t)))))
print('|'.join(map(λ i: t.strate(t.reverse(t[i])),range(len(t)))))
print('|'.join(map(λ i: t.strate(t.symmetry(t.reverse(t[i]))),range(len(t)))))
#print('|'.join(map(t.strate,t[:4])))
print(tuple(map(t.index,t))==tuple(range(len(t))))
And we will see
| o | o | oo | o o | ooo |o |o o |oo |ooo |o o |o oo |oo o |oooo |o o|o o o|oo o|ooo o|oo oo|ooooo
20
| o | o | oo | o o | ooo |o |o o |oo |ooo |o o |o oo |oo o |oooo |o o|o o o|oo o|ooo o|oo oo|ooooo
ooo
| o | o | oo | o o | ooo | o| o o| oo| ooo| o o| oo o| o oo| oooo|o o|o o o|o oo|o ooo|oo oo|ooooo
| o | o | oo | o o | ooo |o |o o |oo |ooo |o o |o oo |oo o |oooo |o o|o o o|oo o|ooo o|oo oo|ooooo
True
delightful
notes
- ↑ For a twofold instance with O(n)-bit elements and O(len:=2n) length, just as in the eightfold reducer, __index__ and __getitem__ iterate over all bits so run in O(n)=O(log(len)) time (equivalently to bisection). nexter's time in each iteration is proportional to the number of bits flipped, and the probability of a given increment flipping n bits is O(1/2n), so it will take on average Θ(∑nk=0(k/2k)) time. Note that this converges as n->∞ (because where x=1/2, it is the generating function for the natural numbers, ∑∞k=0(k*xk)=x(1-x)2=2), so is an O(1) factor. Note also that using __next__ and calling branch would require iterating over O(1) cells, because the likelihood of any layer violating symmetry and terminating it at any index, given that those up to the prior one are symmetrical, is constant with respect to width).
- ↑ For this set of algorithms, this property doesn't generalise to higher-dimensional versions like the eightfold one, because the radial layers' order of precedence differs from the (row-major) reading order, and like the higher-dimensional ones, the emulated structure is not sorted lexicographically (but has a defined comparison method by which it's sorted), but the first element is all 0s and the last one all 1s.
- ↑ One would like to denote it (f**2)(x) but this is unfortunately not allowed by Python, only non-builtin classes may have methods assigned.
- ↑ (also λ n: (1<<(n+1>>1)|1<<n)>>1 and λ n: n+1 if n<2 else 1<<n-1|1<<(n-1>>1))
- ↑ This subtraction of 1 from the input and addition of 1 to the output for obtaining the ceil version from the floor version of a slow-growing continuous function occurs also in the ceilsqrt. In Python, it may even be 0--n//k, using the spaceship operator (very suspicious)
- ↑ It is slightly smaller (with slightly fewer operations) than shifting up to the next power-of-2 length, using the trivial method and shifting back down (by carrying common shifts through masks and across iterations).
- ↑ See also the one for chess positions
Duval's algorithm
If you wanted to enumerate oscillators in a Wolfram rule on a length-n circular tape instead (referred to formally as a necklace), you would also be able to reduce the number of states by by cyclic bitshifts (corresponding with rotation of the necklace) as well as bitwise reversals (reflections). (For now, we will consider rotation without reflection, assuming the rule isn't isotropic.)
Without any idea of how to proceed (because states can't be split into layers (equivalence classes under the group) that can be used to bisect like with reflections), you may decide to try, for each binary integer in range(1<<n), finding, of all amounts by which to cyclically shift it, the one that causes it to become the minimal possible value, and add it to the list of states (or increment a counter) only if this shift is by 0 (so that only a single instance of each equivalence class is included). (This is the same idea as in the first algorithm shown for enumerating binary hypercubes under symmetry.)
You could also try using the Pólya enumeration theorem yourself. For a length-n necklace, there are n actions, and all cells behave with the same period under cyclic shifts, the cycle length of a shift by k cells will be lcm(n,k) divided by k.[n 1]
>>> from math import lcm >>> tap(λ n: tap(λ k: lcm(n,k)//k if k else 1,range(n)),range(8)) #periods ((), (1,), (1, 2), (1, 3, 3), (1, 4, 2, 4), (1, 5, 5, 5, 5), (1, 6, 3, 2, 3, 6), (1, 7, 7, 7, 7, 7, 7))
This sequence (if we flatten it with a chain(*)) is in fact
A277227 (or
A054531 if 1-indexed and upper-inclusive, or
A341314 if 0-indexed and upper-inclusive).
So for a rule with c cell states (or necklace of beads of c colours), for each of these actions' cycle lengths l, n//l=gcd(n,k) is the number of cycles, so cgcd(n,k) is the number of invariant states under the action. Note that where n is prime, all nonzero shifts have only a single cycle (because gcd(n,k) will be 1), leading to Fermat's little theorem, that cn+c*(n-1)n is integer, so (cn+c*(n-1))%n=0, so (cn-c)%n=0, so cn≡c (mod n). However, where n isn't necessarily prime, we can instead say that
- λ c,n: ∑n-1k=0(cgcd(n,k))/n
would always return an integer if the // were replaced with a /, and equivalently that replacing it with a % would return 0.
This function returns the length we would like, however it takes O(n) iterations (over each of which it takes O(log(n)*log(log(n))2) time (according to gcd's time complexity (based on multiplication's) on Wikipedia)), so we would like a faster way (for scientific curiosity, though it will be a negligible proportion of the total time, in practical use). Note that all values returned in the map are factors of n, so we could instead iterate over n's divisors, and for each one d, count its number of occurrences by some other means and multiply by cn/d before dividing by n. In fact, if an integer l occurs in the output of the periods function for a given n (of which it's a factor), it will have the same number of occurrences as for all other n in which it appears, because in the noninteger real numbers between 0 and 1, a cycle length l occurs at l distinct locations, excluding those already covered by its factors, and these correspond with cells if n is a multiple of l. For some value of l, the number of points not covered by subperiods is l minus sum(1 for each of its divisors), or equivalently 0 plus sum(1 for each of its nonzero coprime predecessors), which is what Euler's totient function (
A000010, hereafter phi) computes. After defining some functions within our class,
primate=λ self,n: () if n==1 else (λ p: p if p else ((n,1),))(tuple(filter(λ p: p[1],map(λ p: (p,shortduce(λ i: (i[0],False) if i[1]%p else ((i[0]+1,i[1]//p),True),i=(0,n))),reduce(λ t,i: t+(i,)*all(map(λ p: i%p,t)),range(2,n),()))))) phi=λ self,n: 1 if n==1 else reduce(int.__mul__,starmap(λ p,e: p**(e-1)*(p-1),self.primate(n)),1)
(computing phi using the definition from Wikipedia in integer aritmetic, that after obtaining n's prime factorisation as a product of exponents of unique primes, each prime p has its exponent decremented by 1 then is multiplied by (p-1)), then we can find the length with a function into which we pass phi as o,
lengther=λ self,n,o: sum(map(λ f: o(f)<<n//f,self.factorise(n)))//n if n else 1
The reason to pass phi in is that we can then replace it with the Möbius function,
mu=λ self,n: (λ p: int(all(map(λ f: f[1]<2,p)) and (-1)**len(p)))(self.primate(n))
(compute the prime factorisation, return 0 if any primes are exponentiated to a power greater than 1 (equivalently, if it has any square factor), otherwise -1 to the power of the number of prime factors (ie. -1 if odd number else 1)) self.lengther(n,mu) will instead return the number of "primitive" necklaces of length n, such that none consist of a repeating sequence (with a length of a factor of the necklace's).
If you did either of these, and inputted the numbers of states with respect to necklace width to the OEIS, you would find that it has a sequence,
A000031 (and, if you played with both some more, ie. that
A001037 is the aforementioned primitive necklaces,
A000029 is allowing reflection and
A000016 is the number with an odd number of 1s (or equivalently an odd number of 0s)).
For a given length and numerical base, Lyndon words are integers with length n (including trailing and leading 0s), such that no cyclic bitwise shift of them returns a smaller or equivalent integer, so each corresponds with a primitive necklace (and can be used as its canonical representation for our purposes). Duval made two algorithms, one for partitioning integers' representations into sorted lists of (little-endian) Lyndon words of the same base but not necessarily the same length (to enact a different bijective correspondence between integers and multisets of Lyndon words), and another[n 2] for generating all Lyndon words of a base and length (which is the one we're interested in). The idea is the same as binary counting; beginning with the last bit, recursively XOR it with 1 and move to the preceding bit, until one is reached that this changes from 0 to 1. However, after the largest one this process touches has been changed, instead of resetting all bits after it to 0, take the subsequence of bits preceding and including the last one checked, and 'tile' these bits after it with copies of this subsequence. David Eppstein made an implementation (of which I initially found a Github gist reupload) using lists already, from which I learned about it.
def LengthLimitedLyndonWords(s,n):
w=[-1]
while w:
w[-1]+=1
yield(copy(w))
m=len(w)
while len(w)<n:
w.append(w[-m])
while w and w[-1]==s-1:
w.pop()
def LyndonWordsWithLength(s,n):
if n==0:
yield([])
for w in LengthLimitedLyndonWords(s,n):
if len(w)==n:
yield(w)
LengthLimitedLyndonWords begins with w=[-1], because it increments the last bit before the yield, and this way will yield 0 in the first iteration. It increments the last bit, and the while len(w)<n: w.append(w[-m]) part is only appending the mth-last bit to itself (that is, initially the first, then the second after the length is incremented by the first), fulfilling the tiling, then all bits that are the last symbol of the alphabet are removed (so that they can be refilled in after the next increment). Nontrivially, this process of truncation causes it to generate not only a sorted list of canonical (lexicographically minimal) representatives of all length-n states, but also all those of preceding ones.
My version is a transliteration to bitwise operators, making it binary-only but four times as fast (in my testing), and using the fact that integer right-shift truncates efficiently.
Note that in many iterations, the list contains leading 0s (and in some it is comprised entirely of 0s), that serve only to contribute to its length (to differentiate states from each other that have the same binary representations but different lengths), so we will require a variable, l, to remember its length. We will be slightly suspicious here, because instead of putting the loop (that runs until the length is reached) into our __next__ function, we will use a nexter that takes l as an argument instead of recomputing it itself, and will pass l into and out of it with our redumulate function in (so l will replace the b parameter from earlier, and will mean either length or branch point, depending on whether it has scroll enabled).
def nexter(self,w,l):
if self.scroll:
while True:
t=(w&~w-1).bit_length()
if t<self.n:
l=self.n-t
w=reduce(λ w,i: w|w>>(l<<i),range(l and (self.n//l).bit_length()),(w>>t^1)<<t)
if (not self.n%l if self.subperiods else self.n==l) and (not self.sym or self.canonical(w)):
return(w,l)
else:
raise(StopIteration)
else:
return((w|1<<self.n//2,l) if self.n&1 and not w&1<<self.n//2 else shortduce(λ w,i: self.layinc(*w,i),revange(self.n//2),(w&~(1<<self.n//2) if self.n&1 else w,l)))
Note that, again nontrivially, this while True (that corresponds with running LengthLimitedLyndonWords until LyndonWordsWithLength's condition is met) takes converging (and thus constant) time complexity with respect to n.[n 3] We determine t as the number of trailing 1s,[n 4] the initialisation of the reduce covers the original program's popping of trailing s-1's (by shifting them all out by underflow), the increment of the last element (by XORing the last zero bit), and the tiling (by recursively ORing with itself shifted right by its length times 2 to the power of the iteration, to achieve it in logarithmically many operations (handling overlaps by underflow)). The condition involves the self.subperiods parameter (also set in the __init__), because if the integer's length (as was measured excluding trailing 1s (before their removal and replacement)) is a factor of n, it will not be a Lyndon word but a canonical necklace nonetheless.
The __iter__ function can be modified trivially to accommodate this amended function, as is shown below, however indexing methods are more complicated.[n 5]
notes
- ↑ Note that for two integers, if they are to be represented as infinite lists of exponents for each prime in their factorisation, gcd corresponds with taking the minimum in each, and lcm with the maximum, so gcd(n,k)*lcm(n,k)=n*k, so lcm(n,k)k=ngcd(n,k).
- ↑ J.-P. Duval, Theor. Comput. Sci. 1988, doi:10.1016/0304-3975(88)90113-2
- ↑ explained in this paper
- ↑ With Chai Wah Wu's function in
A007814 (that took 13 years and 4 days since the release of Python 3.1 (and int.bit_length()) to be added (preceded by one using int(math.log())))
- ↑ Explained in this paper, I will understand it enough to implement here one day, I hope
redstoneboi's algorithm
On May 17, 2022, during a discussion of this matter, my friend redstoneboi (from the forums) sent me this program
to_bits=λ x,n: [bool(x>>i&1) for i in range(n)]
def enumerate_n(n):
for i in range(1<<n):
yield to_bits(i,n)
rights=[]
for left in enumerate_n(3):
rights.append(list(reversed(left)))
for right in rights:
print(''.join(str(int(b)) for b in left+right))
For even n, it generates and returns the set of 2-colourings of length-n tapes under symmetry. (For odd n, we need only iterate over the off and on state of the central cell for each state in the even preceding n.) As far as I know, it doesn't permit such indexing methods, but it works in a novel way, slightly similarly to Duval's algorithm in that lower-precedence parts' values are set based on the higher-precedence ones. (Though the right half iterates over all values that the left side has taken, it may equivalently be implemented as iterating over all values for the right side up to the all-1's value, then incrementing the left side and reinitialising the right side to that.)
One must take care that one of the halves in this situation is incremented in reverse bit order for it to work. The idea may also be modified slightly, to instead iterate through the left half in standard order order, and at each increment of the left half add its previous value to the set of states that the right half may not take thereafter, and iterate over the values not in this list, each reemaining possible state of the right half, after each such increment of the left half. This has the consequence that all states are iterated over, in sorted order, with neither reflected duplicates nor iteration over illegal states (ie. in constant time between iterations, though the existence of the internal list causes it to take space linearly proportional to the output size).
This is itself slightly curious and worthy of mention here, however moreso is something I found in the prcess of implementing it, that is not mentioned in the OEIS.
Firstly, for context, there is the OEIS sequence A264596, with two nontrivially equivalent main definitions.
- a(n) is the index in which n is inserted in constructing the sorted list of integers <=n, where the sorting key function compares each bit in ascending order of precedence instead of descending until it finds a disparity.
- A264596=λ n: sorted(range(n+1),key=λ n: bin(n)[:1:-1]).index(n)
- Equivalently, instead of using lexicographic string operations, it may use any bitwise reverse function working in a b-bit register, where b>=n.bit_length().
- a(0)=0, a(2*n)=a(n), a(2*n+1)=a(n)+n+1
-
- Equivalently, a(n) is the sum, for each 1-bit in n's binary expansion representing 2i, of ⌈n/2i+1⌉
- A264596=λ n: sum(map(λ i: n>>i&1 and (n>>i+1)+1,range(n.bit_length())))
Here is a faster implementation of redstoneboi's idea (using the bisect library's insort and our own halfverse from earlier), that is lexicographically sorted (but is "top-heavy," returning the larger of the two representations of each asymmetrical state).
def redstone(self):
rights=[]
for left in range(1<<(self.n>>1)):
insort(rights,self.halfverse(left))
#print(rights.index(self.halfverse(left)))
for right in range(1<<(self.n>>1)):
if right not in rights:
yield(left<<(self.n>>1)|right)
This commented-out print statement will return the first 2n/2 elements of A264596, as expected from the first definition above, and may be replaced with it. However, what about generating a sorted list containing the minimal representations of each asymmetrical state, instead of the maximal ones? We may implement it as
def redstone(self):
rights=list(range(1<<(self.n>>1)))
for left in range(1<<(self.n>>1)):
for right in rights:
yield(left<<(self.n>>1)|right)
#print(rights.index(self.halfverse(left)))
del(rights[rights.index(self.halfverse(left))])
I would be very interested if there were to be an efficient indexing method for each of these, like the Pólya-based one at the beginning.
This one's print statement (not inserting but removing elements by the bitwise-reversed key) returns the first 2n/2 elements of A233931, in reverse order. It has the similar recursive definitions
- a(0)=0, a(2*n)=a(n)+n, a(2*n+1)=a(n) (in this way it is something of a 'dual' to A264596)
-
- As noted by Ralf Stephan on its creation, a(n) is the sum, for each 0-bit in n's binary expansion representing 2i, of ⌊n/2i+1⌋.
- A233931=λ n: sum(map(λ i: ~n>>i&1 and n>>i+1,range(n.bit_length())))
Neither sequence mentions the other, despite the duality of summing ⌊n/2i+1⌋ over 0-bits' indexes and ⌈n/2i+1⌉ over 1-bits. (Note that summing floors over 1-bits returns A233905, but interestingly, ceilings over 0-bits has no sequence.)
If we give ourselves some functions with which to reason more efficiently, one for reversing n's binary representation in a d-bit register,
def niceA030101(d,n):
b=d-1
l=b.bit_length()
o=c=(1<<(1<<l))-1
for i in range(l):
s=1<<l+~i #s=1<<i
o^=o<<s[red 1]
n=(n&o)<<s|n>>s&o
return(n>>1+(~d^~0<<d.bit_length()) if d&d-1 else n)
two for closed-form in-place mutation of lists,[red 2]
def inn(l,n):[red 3] l.insort(n) return(l) def out(l,n): del(l[l.index(n)]) return(l)
one for the first power of 2 greater than n (for the purposes of generation and reversal),
- nextpow=λ n: 1<<n.bit_length()[red 4]
and rewrite A264596's first definition.
- A264596=λ n: (λ k: bisect(reduce(λ r,i: inn(r,k(i)),range(n),[]),k(n)))(λ i: niceA030101(n.bit_length(),i))
Demonstrating their duality in the other regard,
- A233931=λ n: (λ k,u: bisect(reduce(λ r,i: out(r,k(i)),range(u),list(range(nextpow(n)))),k(u)))(λ i: niceA030101(n.bit_length(),i),nextpow(n)+~n)
notes
- ↑ Note that o does not have to be set in the beginning, but can be instead o=c//~(~0<<(s<<1))*~(~0<<s)
- ↑ "mutate-and-return," in the manner of Python's walrus operator and all assignment in C.
- ↑ in is used by a builtin keyword, and this way inn lines up with out (and is also more whimsical :-)
- ↑ Given also by A062383
bitwise fractals
(also things that are only tenuously bitwise, and that are only tenuously fractal)
I will try to find more in my exploration
- If for each positive integer x, you plot all y which have a subset of its 1-bits set (ie. y&~x=0), it comprises a Sierpinski triangle (which makes
A080099 a Sierpinski triangle stretched to a parabola (pretty nifty, I believe)) - The values for which (x^x>>1)&(y^y>>1) evaluates to 0 (the Gray codings of x and y have no intersection) are instead the lower-left corner of an infinite fractal, the T-square . Though it has even parity at each boundary between two segments, another fractal (with odd parity, but the same limiting shape) is produced at generations 2n-1 in the evolution of a single cell in b1c3e4e5-a678s012345678. (MaxTheFox from the ConwayLife lounge informed me of the rule when I showed it to her, but it was in fact considered long prior, and is better known in the (less neat) H-trees rule.)
- Scatter-plotting f(x,y)=x^y (bitwise XOR) for 0<=x,y<2n for sufficiently large n (or, in the limiting case, XORing each bits of the binary expansions of the real numbers 0<=x,y<1) produces a Sierpinski pyramid. Because its edges are all diagonals of the cube in which it is inscribed, it is regular.
- The sequence A120385 is defined recursively by a(1)=1 and thereafter a(n)=a(n-1)>>1 or, if that's 0, the maximum value it previously outputted plus 1.
- Beginning at each first occurrence of a power of 2 (2k), there are 2k integers with length-k+1 chains, so there are (k+1)*2k elements, the partial sums of which are (k-1)*2k+1 (albeit +1 again due to the 1-indexing), so a(n) first equals 2k when n=(k-1)*2k+2, and the current k-section is k=W0((n-2)*log(2)2)log(2) + 1, where W is the Lambert W function , then a(n)=2k+⌊n-(k-1)*2k-2k+1⌋2(n-(k-1)*2k-2)%(k+1), providing the elegant form
- A120385=λ n: int(n==1) or (λ m,d: (1<<k|d)>>m)(*moddiv(n-((k:=⌊W0((n-2)*log(2)2)log(2)⌋+1)-1<<k)-2,k+1))
- we also have
- A030530=λ n: n if n<2 else 1<<(k:=⌊W0((n-2)*log(2)2)log(2)⌋+1)|⌊n-(k-1<<k)-2k+1⌋
- Consider the generalised towers of Hanoi, where there are infinity (or equivalently n) rungs on the first peg and n moves, after which there are a(n) possible states.
- >>> l=17;print(tap(λ n: len(set(Y(λ f: λ n,s: tuple(chain.from_iterable(map(λ m: f(n-1,tarmap(λ i,t: t[:-1] if i==m%3 else t+(s[m%3][-1],) if i==m//3+(m//3>=m%3) else t,enumerate(s))),tilter(λ m: s[m%3][-1]>s[m//3+(m//3>=m%3)][-1],range(6))))) if n else (s,))(n,(tuple(range(n)),(0,),(0,))))),range(l)))
- the sequence begins 1,2,5,9,11,15,19,27,29,33,37,45,49,57,65,81,83. Changing the 2 to a 3 returns the number of endpoints in this graph reachable within n moves, instead of after exactly n, and it is equivalently given by A006046(n+1) (partial sums of λ n: 2n.bit_count()). This is because it is the coordination sequence for the Hanoi graph, whose adjacency matrix is a Sierpinski triangle, in which there are 2n.bit_count() 1s in the nth row.
- interesting one-liner: ruler function of Sierpinskis!
- >>> from dronery import*;import matplotlib.pyplot as plot;tap(λ c: (λ t: plot.scatter(range(len(t)),t))(tap(λ n: Y(λ f: λ i,n: n and n+f(i+n,n&~i))(c,n)-2*n,range(1<<8))),range(1<<6));plot.show()
- A224694 is the sorted set of integers n for which n2 & n = 0
- we have that all integers of the form k<<k.bit_length() are members; there are thus >=2n members up to 4n, providing that a(n) <= 4⌈log2(n)⌉ <= 4*(n-1)2 for n != 1
- if n is in the sequence, so is n-2n.bit_length()-1, providing that for two integers m < n and 2p > m,n, a.ι(2p+n)-a.ι(2p+m) <= a.ι(n)-a.ι(m)
- exact forms for solutions to recurrence relations involving bitwise operators!
- let f(l) be the sequence satisfying a(n) = 0 for 0 <= n < l, and a(n) = (a(n-1)^a(n-2)^...^a(n-l))+1 thereafter
- f=λ l: Y(λ f: λ t: λ n: f(t[1:]+(reduce(int.__xor__,t[-l:],0)+1,))(n-1) if n else t[0])(l*(0,))
- consider the sequence characterised by a(0) = a(1) = 0, a(n) = (a(n-1)^a(n-2))+1
- A114375=f(2)
. . . .=λ n: ((n:=⌊n3⌋+1)&-n)*4+~((n&1)<<1) if n≡2 (mod 3) else (⌊n3⌋+1&~1 if n≡1 (mod 3) else ⌊n3⌋)<<1 - f(3)=λ n: ((∑(n>>2)+1k=0(k&-k)<<1)-n<<1|n&1)<<1|1 if n≡3 (mod 4) else (∑n>>3k=0(k&-k)<<1)+(n>>2&1 and (n:=n>>3)+1&~n)<<3 if n≡2 (mod 4) else (⌊n4⌋+1&~1 if n≡1 (mod 4) else ⌊n4⌋)<<1
- f(4)=λ n: (∑⌊n5⌋+1k=0(k&-k)+~⌊n10⌋^(∑⌊n10⌋k=0(k&-k)<<1)+(⌊n5⌋&1 and ⌊n10⌋+1&~⌊n10⌋))<<3^(((⌊n5⌋+1&~⌊n5⌋)<<(⌊n5⌋&1))-1)<<1|1 if n≡4 (mod 5) else ∑⌊n5⌋+1k=0(k&-k)+~⌊n10⌋<<3 if n≡3 (mod 5) else (∑⌊n10⌋k=0(k&-k)<<1)+(⌊n5⌋&1 and ⌊n10⌋+1&~⌊n10⌋)<<3 if n≡2 (mod 5) else (⌊n5⌋+1&~1 if n≡1 (mod 5) else ⌊n5⌋)<<1
- A114375=f(2)
- Note that these bear a few similarities to the generalisations of A338888 discussed later on (which are the same idea but with bitwise OR instead of XOR), such as that a given sequence in this series, in which each term depends upon the k preceding terms, appears to have cases dependent on the value of n%(k+1).
OEIS things
I became overzealous in my editing in other people's OEIS sequence draft slots and was temporarily banned, my OEIS wiki account was banned from making changes to my userpage also, so I put here the things I intend to add there (as a buffer for my own eventual draft edits).
fun with isqrt
Python 3.8 added both int.bit_count(n) = ⌊log2(n)⌋+1 and math.isqrt(n) = ⌊√n⌋ for integer inputs, computed efficiently and without floating-point precision loss). As shown above in the hexagon bijector, arrays with linearly-growing rows can be indexed using it, findable by the quadratic formula, and floors of expressions involving arbitrarily high-precision intermediate square-roots can usually be reworded in terms of it.
One characterisation of choose is the recursive form (nk) = 1 if n==0==k else ∑ni=0((ik-1)) (because successive columns of Pascal's triangle are upper-exclusive running sums of preceding ones). Finding a sequence b for a given a such that ∑∞n=0(an*xn) = ∑∞n=0(bn*(xn)) is solving a set of linear equations in each of the exponents of x, so is computable by matrix inversion. Given a polynomial a, to find the coefficients of each exponent of x in the expansion of λ x: ∑x-1y=0(∑∞n=0(an*yn)) (a polynomial function in x, of degree deg(a)+1), you may either: convert to chooses, increment all of the second parameters and convert back; compute the first few terms of the sum and find the interpolating polynomial (with either matrix inversion or Lagrange's formula ). Like ∑x-1i=0(i1)=∑n-1i=0(i1)=(n2)=n*(n-1)2, there is also the sporadic case in which a sum of powers is always also a power, ∑n-1i=0(i3)=(n*(n-1)2)2.
Arbitrary quadratics can be represented as compositions of a linear function, a squaring and a linear function, for only a single call of n (the basis of the quadratic formula), (n2)=n*(n-1)2=(2*n-1)2-18, so the sum of the first n cubes is ((2*n-1)2-18)2.
When representing triangular arrays as 1-dimensional sequences by reading them by rows, the y positions in the reading order follows A002024, where n appears n times. Due to its 1-indexing, n first appears as a(n*(n-1)2+1), so the function for the index in terms of the value can be inverted to sqrt(8*n-7)+12. This is a continuous and function with first differences in the range [0,1], and equality to A002024 at the values following increments, so its floor (⌊sqrt(8*n-7)+12⌋) exactly equals A002024. As n increases, it increments each time the sqrt's output increments to an odd number, so the sqrt can have its floor taken also, becoming an isqrt instead.
Note that the sequence of a(n)=n2%8 is 0,1,4,1 for n ≡ 0,1,2,3 (mod 4), and this function's input to the sqrt function will be congruent to 1 modulo 8. Incrementing the isqrt's output from an even to an odd value is not allowed, but an odd to an even one is ineffectual, and the gaps between successive odd squares are multiples of 8, so it may be simplified to ⌈⌊√8*n⌋2⌉, ie.
- A002024=λ n: isqrt(n<<3)+1>>1
In the sequence in which n occurs n2 times, A074279, n first appears as a(n*(n-1)*(2*n-1)6+1). Inverting this (to produce a(n) from n) is equivalent to the cubic formula, because expressing it (in terms of standard arithmetic functions) with only a single call of n is impossible. However, you can use the fact that a(n)=Θ(3√n), and that 0 <= a(n)-⌊3√n3⌋ <= 1, to produce the (still somewhat unsatisfying) form
- A074279=λ n: (c:=icbrt(3*n))+(n>c*(c+1)*(2*c+1)//6)[fun 1]
In the "n occurs n3 times" sequence (A108582), however, n first appears as a(((2*n-1)2-18)2+1), which inverts to a(n)=⌊sqrt(8*sqrt(n-1)+1)+12⌋, which (by the same reasoning as before) can be reduced to the integer arithmetic form
- A108582=λ n: n and isqrt(isqrt(n-1)<<3|1)+1>>1
notes
- ↑ with from sympy import integer_nthroot
icbrt=λ n: integer_nthroot(n,3)[0]
a few closed forms
Michael Somos's page, Indexing Functions for Triangular or Rectangular Arrays contains a few sequences that are used to biject between 1- and 2-dimensional structures, similarly to the hexagon bijector functions explained above, but where both are infinite. Provided here are some integer-arithmetic-only Python implementations of __getitem__ methods (which can be in terms of isqrts due to the quadratic formula), and (where not yet present in the OEIS) generating functions in terms of Jacobi theta functions.
The Ramanujan theta function is defined
- f=λ a,b: ∑∞n=-∞(an*(n+1)2*bn*(n-1)2)
.=λ a,b: 1+∑∞n=1((a*b)n*(n-1)2*(an+bn))
.=λ a,b: ∏∞n=0((1+a*(a*b)n)*(1+b*(a*b)n)*(1-(a*b)n+1)) #Jacobi triple product
so one may express functions of the form of sums of p(n)th powers of x for all quadratic sequences p=λ n: a*n2+b*n+c,
- ∑∞n=-b2*a(xa*n2+b*n+c)=xc*f(xa+b,xa-b)+x-b24*a2
(where -b2*a is an integer, allowing it to be deduplicated by this), leading to a few g.f.'s being theoretically expressible in terms of Ramanujan but not Jacobi theta functions. However, the first and second pentagonal numbers (which arise surprisingly often, as partial sums of sequences 3*n+1 and 3*n+2, respectively) don't have integer minima, so unfortunately I don't know how to find closed forms for each of them separately (only together, somewhat interestingly).
Also, I provide some multivariate generating functions (only where missing from the OEIS, but where the sequences are described as such), in the form ∑∞n=0(∑∞k=0(a(n,k)*xn*yk)). The convention is used that they are 0- or 1-indexed in both axes depending on the original sequence's indexing method.
in general, ∑∞n=-∞(x(n+c)2) = xc2*f(x1-2*c,x1+2*c)
note we use the univariate versions of Jacobi theta functions herein (ie. ϑn(x) would be ϑn(0,x)), so we have
Ramanujan's psi,
- ψ(x) = ∑∞n=1(x(n2)) = f(x,x3) = f(1,x)2 = x*f(x-1,x2)2
Jacobi's,
- ϑ2(x) = ∑∞n=-∞(x(n+1/2)2) = 4√x*f(1,x2) = 2*4√x*f(x2,x6) = 2*4√x*ψ(x2) #unpleasant and therefore not used here
- ϑ3(x) = φ(x) = ∑∞n=-∞(xn2) = ∏∞n=0((1+x2*n+1)2*(1-x2*(n+1))) = f(x,x) = x*f(x-1,x3) #Ramanujan used phi for this
- ϑ4(x) = ϑ3(-x)
the Euler function,
- Φ(x) = ∏∞n=1(1-xn) = ∑∞n=-∞((-1)n*xn*(3*n-1)2) = f(-x,-x2) #Ramanujan used f(-x)
and Ramanujan's chi,
- χ(x) = ∏∞k=0(1+x2*k+1) = ϑ3(x)Φ(-x) = f(x,x)f(x,-x2)
onto the formulas!
- pure isqrts of floordivs
- A000196=λ n: ⌊√n⌋
- gf(A000196)=λ x: ϑ3(x)-12*(1-x)
- A172471=λ n: ⌊√2*n⌋
- gf(A172471)=λ x: x*ψ(x4) + ϑ3(x)-121-x
. . . . . .=λ x: ϑ3(√x)+ϑ3(-√x)+√x*(ϑ3(√x)-ϑ3(-√x))-24*(1-x)
- gf(A172471)=λ x: x*ψ(x4) + ϑ3(x)-121-x
- A202304=λ n: ⌊√3*n⌋
- gf(A202304)=λ x: x*f(x,x5) + ϑ3(x3)-121-x
- λ n: A060018(n+2)=λ n: ⌊√4*n⌋
- gf(λ n: ⌊√4*n⌋)=λ x: x*(ψ(x2)+ψ(x8))+x4*ϑ3(x4)-121-x
. . . . . . . .=λ x: ϑ3(x)-1+x*ϑ2(x)2*(1-x)
- gf(λ n: ⌊√4*n⌋)=λ x: x*(ψ(x2)+ψ(x8))+x4*ϑ3(x4)-121-x
- A000196=λ n: ⌊√n⌋
x*f(x,x**9)+x*f(x**3,x**7)+(ϑ_3(x**5)-1)/2
- note that for a fixed c, chain.from_iterable(map(λ n: (⌊√c*n⌋-⌊√c*(n-1)⌋)*(n,),range(1,∞))) (the indexes n at which a sequence of this kind increments, with multiplicity) is (by floor-inverse) equal to ∑∞k=0((⌈(k+1)2c⌉)*xk) = ∑c-1k=0(x⌊√k⌋) + 2*xc(1-x)(1-x)*(1-xc)
- A025581=λ n: ((⌊√n<<3|1⌋+1|1)2>>3)+~n
- A002262=λ n: n-((⌊√n<<3|1⌋-1|1)2>>3)
- gf(A002262)=λ x,y: x*y(1-x)*(1-x*y)2
- A004736=λ n: ((⌊√n<<3⌋+1|1)2>>3)+1-n
- gf(A004736)=λ x,y: x*y(1-x)2*(1-x*y)
- A002260=λ n: n-((⌊√n<<3⌋-1|1)2>>3)
- A002024=λ n: ⌊⌊√8*n-7⌋+14⌋+⌊⌊√8*n-7⌋-14⌋+1=λ n: ⌊⌊√8*n⌋+12⌋
- gf(A002024)=λ x: x*ψ(x)1-x
- (and when considered to be not a triangle but an array read by antidiagonals, as the commenters say)
- A073188=λ n: ⌊⌊√24*(n+1)⌋+16⌋+⌊⌊√24*(n+1)⌋-16⌋ + ⌊⌊√24*n+9⌋+312⌋+⌊⌊√24*n+9⌋-312⌋=λ n: ⌊√24*(n+1)⌋-3>>1
- A073189=λ n: n-⌊(⌊√24*(n+1)⌋-1|1)224⌋
- gf(A073189)=λ x,y: x3*y(1-x)*(1-x3*y)2
- A003059=λ n: n and ⌊√n-1⌋+1
- gf(A003059)=λ x: x*(1+ϑ3(x))2*(1-x)
- A071797=λ n: n-⌊√n-1⌋2
- gf(A071797)=λ x,y: x*y*(1+2*x*y+x*y2)(1-x)*(1-x*y2)2
- A000267=λ n: ⌊√n<<2|1⌋
- A001670=λ n: ⌊√n<<2⌋+1&~1
- A206224=λ n: (⌊√n<<2|1⌋-1)2>>2
- A130821=λ n: ⌊√n<<2⌋-1|1
- gf(A130821)=λ x: 2*x*ψ(x2)-11-x
- A130829=λ n: ⌊√n<<2⌋+1|1
- A180447=λ n: ⌊⌊√24*n+1⌋+16⌋
- A130819=λ n: n and ⌊√n-1⌋+1<<1
- gf(A130819)=λ x: x*(ϑ3(x)+1)1-x
- A131506=λ n: n and ⌊√n-1⌋+1<<1|1
- gf(A131506)=λ x: x*(ϑ3(x)+2)1-x
- A131507=λ n: ⌊√n<<3|1⌋-1|1
- A001650=λ n: n and ⌊√n-1⌋<<1|1
- A111651=λ n: n and ⌊√(8*n-5)//3⌋+1>>1
- A216607=λ n: n and ((⌊√4*n-1⌋+1)2>>2)-n
- A094727=λ n: n and n+(1-(⌊√8*n-7⌋-3|1)2>>3)
- gf(A094727)=λ x,y: 1+x*y-2*x2*y(1-x)2*(1-x*y)2
- A235963=λ n: ⌊⌊√24*n+1⌋+16⌋+⌊⌊√24*n+1⌋-16⌋=λ n: ⌊⌊√24*n+1⌋-1&~13⌋
- which is defined by
- n appears n+11+n%2 times.
- (for all nonnegative n), using the version of the Ramanujan theta function from Euler's pentagonal number theorem,
- gf(A235963)=λ x: ∑∞n=1(xn*(3*n-1)2+xn*(3*n+1)2)1-x
. . . . . .=λ x: ∑∞n=-∞(xn*(3*n-1)2)-11-x
. . . . . .=λ x: f(x,x2)-11-x
- gf(A235963)=λ x: ∑∞n=1(xn*(3*n-1)2+xn*(3*n+1)2)1-x
- A108582=λ n: n and isqrt(⌊√n-1⌋<<3|1)+1>>1
- A097807=λ n: (-1)n^⌊√n<<3|1⌋-1>>2
- A070909=λ n: (n^(⌊√n+1<<3⌋-1|1)2>>3^(n+1!=(⌊√8*n+9⌋-1&~2|1)2>>3))&1
- A079643=λ n: ⌊n⌊√n⌋⌋
. . . .=λ n: ⌊√4*(n+1)⌋ - ⌊√n⌋
. . . .=λ n: ⌊[⌊√m:=n+1⌋2=m]+⌊√4*m⌋+12⌋- gf(A079643)=λ x: ϑ3(x)-12*x + ψ(x2)1-x - 2
- gf(A127773)=λ x: x*(ddx)(ψ(x))
- A080343=λ n: ⌊√8*n⌋-2*⌊√2*n⌋
- gf(A080343)=λ x: ∑∞n=1(x1+n+2*n2*(1-xn)*(1+x2*n+1))1-x
. . . . . .=λ x: x*(ψ(x)-ψ(x4)) + 3-ϑ3(x2)21-x
- gf(A080343)=λ x: ∑∞n=1(x1+n+2*n2*(1-xn)*(1+x2*n+1))1-x
- A080352=λ n: ∑nk=0(A080343(k))
. . . .=λ n: ⌊(a-1)24⌋+n-(a+12) if (a:=⌊⌊√8*n-7⌋-12⌋)==⌊√2*n-1⌋+1&~1 or a==⌊√⌊n/2⌋⌋*2+1 else ⌊a24⌋
- A134986=λ n: (0,2,3)[n] if n<3 else n-⌊⌊√4*n⌋-12⌋
- gf(A134986)=λ x: 1(1-x)2 - 1 + x + x2 - x*ψ(x2)1-x
Its definition is a(n) = smallest integer m not equal to n such that n = ⌊n2m⌋ + m2.
We will consider only n ≥ 3, for which the form pertains (it would for 1 and 2, were it not for "not equal to n")
Let s = n-m = ⌊⌊√4*n⌋-12⌋, then we rewrite
- ⌊n2m⌋+m2 = ⌊n2+m2m⌋2 = ⌊n2+(n-s)2n-s⌋2 = ⌊2*n*(n-s)+s2n-s⌋2 = n + ⌊s2n-s⌋2 = n
since ⌊s2n-s⌋ = 0. Proof: 0 ≤ s2n-s < 1, since (using the familiar bounds over the integers, p+1q - 1 ≤ ⌊pq⌋ ≤ pq and √n+1-1=√n-2*√(n+1)+2 ≤ ⌊√n⌋ ≤ √n) we have that √n+1/4 - 32 ≤ s ≤ √n - 12, then
- 0 ≤ n - 3*√n+1/4 + 52n - √n+1/4 + 32 = 1 - 2*√4*n+1-12*n-√4*n+1+3
. ≤ s2n-s
. ≤ n - √n + 14n - √n + 12 = 1 - 14*(n-√n)+2
. < 1
We have that m is the smallest of the integers c for which ⌊n2c⌋ = ⌊n2m⌋, since ⌊n2⌊n2m⌋⌋ = ⌊n22*n - m⌋ = ⌊n2n+s⌋ = ⌊n*(n+s) - n*sn + s⌋ = n - ⌈n*⌊⌊√4*n⌋-12⌋n+⌊⌊√4*n⌋-12⌋⌉ = n - ⌊⌊√4*n⌋-12⌋ = n - s = m, since (over the positive integers) we have the general implication (⌊s2n-s⌋=0) => (⌈n*sn+s⌉=s) (similarly to with floor division, pq ≤ ⌈pq⌉ ≤ p-1q + 1, so the former implies that s2+1+s-n ≤ 0 ≤ s2 (from which we get s ≤ √4*n-3-12) and the latter that n*s ≤ (n+s)*s ≤ n*s-1 + n + s (from which we get s ≤ √4*n-3+12))
since pq + 1q-1 - 1 ≤ ⌊pq-1⌋ - ⌊pq⌋ ≤ pq-1 - 1q + 1, for m (and, since λ m: n2m + m2 is a function with a strictly decreasing absolute derivative, all values lower than it) there is at least ⌊n2m-1⌋-⌊n2m⌋ ≥ n2m + 1m-1 - 1 ≥ 2*n-m+1m-1 = 2*nm-1 - 1 = 2*nn-⌊⌊√4*n⌋-12⌋-1 - 1 ≥ 4*n2*n+1-√4*n+1 - 1 = 1 + √4*n+1+1n ≥ 1; for m in particular, from the above paragraph, since (⌊n2m-1⌋-⌊n2m⌋=1) <=> (⌊n2m⌋ + m2 - ⌊n2m-1⌋ + m-12 = 0), so we have that ⌊n2m-1⌋-⌊n2m⌋ ≥ 2, and by induction, equality can never be achieved for any lower integer
In general, for n>=3, the characteristic function of the n-gonal numbers is given by
- a=λ n,k: int(k-1==⌊(⌊⌊√n2+8*(n-2)*(k-1)⌋-2n-2⌋-1|1)*(n-2)+2)2-n2n-2⌋>>3)
(A010054(k)=a(3,k), A010052(k)=a(4,k), A255849(k)=a(5,k), A132918(k)=a(6,k))
A027568 is the complete set of 3-gonal numbers of the form (n3), however {0,1,28,3003} is the complete set of 6-gonal numbers that are of the form (n6) (together with 210 if you allow negative n). It seems that 6 is the last such number for which these nontrivial examples exist at all.
- ⌊√s*(n+1)⌋-⌊√s*n⌋ = ⌊√s⌋+(~⌊√s*n2<<2⌋&⌊√s*(n+1)2<<2⌋&1)
- A003849=λ n: (n^⌊√5*(n+2)2⌋)&(n^⌊√5*(n+1)2⌋)&1
. . . .=λ n: int(((n+⌊√5*(n+2)2⌋&~1)+~n)2<5*(n+1)2)
combinatorial number systems
Let Cnk be the function returning the kth element of the nth combinatorial number system (representing the j in the (jk) summand), and f-1 be the "floor-inverse" of an increasing function (ie. the g such that g(n)=min({k ∈ ℤ: f(k)==n}) or max({k ∈ ℤ: f(k)<n}) if there is no such number, such that the operation of floor-inversion is an involution). Then
- Cnk(x) = { ((λ x: (xk))-1)(x). .k = nCkk(x-(Ck+1n(x)k+1)). . . k < n
We have
- C44=A194882=λ n: isqrt(⌊√24*n+1⌋*4+5)+3>>1
- C34=A194883=λ n: ⌊3*(c:=icbrt(6*(n-⌊((isqrt(⌊√24*n+1⌋*4+5)-1|1)2-5>>2)2-2524⌋)))2+13*c⌋+1
- C24=A194884=λ n: isqrt(8*((n:=n-⌊((isqrt(⌊√24*n+1⌋*4+5)-1|1)2-5>>2)2-2524⌋) - (c:=⌊3*(c:=⌊3√6*n⌋)2+13*c⌋)*(c-1)*(c+1)6)-7)+1>>1
- C14=A127324=λ n: (n:=(n:=n-⌊((isqrt(⌊√24*n+1⌋*4+5)-1|1)2-5>>2)2-2524⌋) - (c:=⌊3*(c:=⌊3√6*n⌋)2+13*c⌋)*(c-1)*(c+1)6)+~((⌊√n-1<<3|1⌋-1|1)2>>3)
Due to the identity for even-k binomials in #binomial decomposition, we also have
- C66=λ n: ⌊sqrt(2*((2*(c:=cbrt(√25*(243*n+2)2-343+1215*n+10))-5)23+1)c+25)+52⌋
Similarly in nature, Benoit Cloitre's formula from September 30, 2006 on A052852(n) = [xnn!](x1-x*ex1-x), that A052852(n) = n!e*∑.kn≥kn-1≥...≥k1≥0(1(kn)!), can be reexpressed. The multiplicity of a given value of kn in the sum is #({t=(kn-1,...,k1) ∈ ℕn: t nonincreasing}) = (n+k-1k), so one can rewrite A052852(n) = n!e*∑∞k=0((n+k-1k)k!) = n!e*1F1(n1;1)
notes
Wolfram e.g.f.'s
All of Colin Barker's conjectured generating functions are true by inspection of each rule's evolution. If, after sufficiently many initial exception terms, one becomes comprised of fixedly many noninteracting perturbations in linearly-growing agars that are periodic in time and space (see for instance rule 57), generating functions may have different cases over each parity modulo the time period (since, for instance, two can be interlaced by substituting their x calls for x2 and multiplying one by x).
Say you have a Wolfram rule's sequence with period pt in time, for which you've decomposed it into pt sequences for each parity of the generation modulo pt, which you will interlace. The kth such one will be a function of n, in the basis sequence representing generation pt*n+k. Considering such a k-sequence, for one of its agar components to be periodic over space, say with period ps, for a given value of n, it may be expressed (where c<2ps, and c's binary representation is the periodically-tiled image) as
- c*∑n-1k=0(2ps*k)=c*1-2ps*n1-2ps
This is a linear-recurrent function, because
- gf(λ n: c*1-2ps*n1-2ps)=λ x: c*x(1-x)*(1-2ps*x)
And shifting its right edge to begin at a different bit from 1 doesn't change this, since the elementwise product of two linear-recurrent sequences is itself linear-recurrent also.
I think I have all nontrivial ones of reasonable size here (that haven't yet been added to the OEIS), but 110 becomes periodic after many thousands of initial exception terms, I'm not sure which others are exceptions, and I think it is generally equivalent to the halting problem to decide whether a given rule's sequence is eventually linear-recurrent, since Turing machines may be explicitly implemented as Wolfram rules. Note that excluding rule 110, with the width-3 neighbourhood, 7 exception terms are the maximum, so if entering its periodic form is considered to be termination, the equivalent to the busy beaver sequence with respect to width (1-indexed) begins with 0,1,7. (Rules 0, 1, 7 and 15, implementable as 0, 17, 119 and 255, are the unique width-2 rules for which the initial term is the exception.)
Where possible, they are also provided in factorised form. For two sequences a and b, gf-1(gf(a)*gf(b))=λ n: ∑nk=0(a(k)*b(n-k)).[e 1] However, for e.g.f.'s, the equivalent is egf-1(egf(a)*egf(b))=λ n: ∑nk=0((nk)*a(k)*b(n-k)). This decomposition may not be so useful on sequences of a binary nature, but it may be of interest, I have left them where the polynomial over ex has rational factors.
- egf(. rule1)=λ x: cosh(2*x)-(1+7*cosh(x))*sinh(x)+2*sinh(4*x) #also rule 33
- egf(. rule3:=A266069)=λ x: cosh(√2*x) - sinh(x) + 2*sinh(4*x) - 3*sinh(√2*x)√2 #also rule 35
- egf(. rule5:=A266176)=λ x: cosh(2*x)-(1+5*cosh(x))*sinh(x)+2*sinh(4*x)
- egf(. rule6:=A266180)=λ x: 5*e4*x-e-4*x4
. . . . . . . . . . .=λ x: cosh(4*x) + 3*sinh(4*x)2 #also 38, 134 and 166 - egf(. rule7:=A266218)=λ x: 1-x-sinh(x)+2*sinh(4*x)
. . . . . . . . . . .=λ x: 1-x-(1-ex)*(1+ex)*(e-4*x+e-2*x - e-x2 + 1 + e2*x)
. . . . . . . . . . .=λ x: 1-x+2*cosh(x2)*sinh(x2)*(4*(cosh(x)+cosh(3*x))-1) - egf(. rule9:=A266245)=λ x: -28+88*x-24*x2+32*x3/3+29*cosh(x)-96*sinh(x)+2*sinh(4*x)
- egf( rule11:=A266176)=λ x: -2 + 3*cosh(x) - 4*sinh(x) + 2*sinh(4*x) #also rule 43
- egf( rule13:=A266284)=λ x: -cosh(x)+4*cosh(2*x)-2*sinh(x)-8*sinh(2*x)+6*sinh(4*x)3
- egf( rule14:=A266284)=λ x: 1 + 3*e4*x2 #also 46, 142 and 174
- egf( rule17:=A266090)=λ x: cosh(2*√2*x)-sinh(x)+2*sinh(4*x) - 3*sinh(2*√2*x)√2 #also 49
- egf( rule23:=A266436)=λ x: 1-sinh(x)+2*sinh(4*x) #also rules 31, 55, 63, 87, 95, 119, 127
- egf( rule25:=A266443)=λ x: -28+88*x-22*x2 + 32*x33+29*cosh(√2*x)-sinh(x)+2*sinh(4*x)-47*√2*sinh(√2*x)
- egf( rule27:=A266461)=λ x: cosh(√2*x)-sinh(x)+2*sinh(4*x)-√2*sinh(√2*x)
- egf( rule28:=λ n: A001045(n+2))=λ x: 4*e2*x-e-x3 #also rule 156
- egf(A001045)=λ x: (1-e-x)*(1+ex+e2*x)3
. . . . . . =λ x: (1-∑∞n=0((-x)nn!))*(1+∑∞n=0((1+2n)*xnn!))3
- egf(A001045)=λ x: (1-e-x)*(1+ex+e2*x)3
- providing
- A001045=λ n: ∑nk=0(n!(n-k)!*k!*((n==k)-(-1)n-k)*((k==0)+1+2k))3
- egf( rule37:=A266590)=λ x: -5+21*x+7*cosh(2*x)2-sinh(x) - 31*sinh(2*x)4+2*sinh(4*x)
- egf( rule39:=A266607)=λ x: cosh(√2*x)-sinh(x)+2*sinh(4*x) - sinh(√2*x)√2
- egf( rule41:=A266610)=λ x: 3*cosh(x)-2*cos(x)+18*sinh(x)-2*sinh(4*x)-10*sin(x)
- egf( rule50:=λ n: A002450(n+1))=λ x: 4*e4*x-ex3 #also 58, 114, 122, 178, 179, 186, 242, 250
. . . . . . . . . . . . . . . .=λ x: ex*(2*ex-3√2)*(4*e2*x+2*3√2*ex+3√4)6 - egf(A002450)=λ x: e4*x-ex3
. . . . . . =λ x: ex*(ex-1)*(e2*x+ex+1)3 - egf( rule51:=A266668)=λ x: cosh(2*x)-sinh(x)-sinh(2*x)+2*sinh(4*x)
- egf( rule53:=A266671)=λ x: cosh(2*√2*x)-√2*sinh(2*√2*x)-sinh(x)+2*sinh(4*x)
- egf( rule54:=A118108)=λ x: -6*e-4*x+3*e-x-4*ex+22*e4*x15
- egf( rule57:=A266674)=λ x: 24*cosh(2*√2*x)-36*√2*sinh(2*√2*x)+7*(cosh(2*x)+sinh(2*x)+6*sinh(4*x))-e-x*(cos(√3*x)+√3*sin(√3*x))21-sinh(x) - 3*cosh(√2*x)-√2*sinh(√2*x)7
- egf( rule59:=A266718)=λ x: 3*cosh(√2*x)-sinh(x)+2*sinh(4*x)-√2*sinh(√2*x)
- egf( rule61:=A266788)=λ x: -2932 + 7*x4 - 13*x28 + x3 - x412 + 61*cosh(2*√2*x)32 - sinh(x) + 2*sinh(4*x) - 23*sinh(2*√2*x)8*√2
- egf( rule62:=A266810)=λ x: -7*e-x9 - 4*ex7 - 4*e2*x45 + 12*e4*x7 + 28*cos(x)65 + 36*sin(x)65 + 40*e-x*2*cos(√3*x) - sin(√3*x)√3273
- Rule 65 has no OEIS sequence currently, however it has
- rule65=λ n: (1,0,20,3)[n] if n<4 else -64+89*(-4)n+64*(-1)n+95*4n128
- gf(rule65)=λ x: 1+3*x2+3*x3+44*x4-4*x5-48*x6+16*x7(1-x)*(1+x)*(1-4*x)*(1+4*x)
- egf(rule65)=λ x: -84+156*x-288*x2+32*x3+276*cosh(4*x)+9*sinh(4*x)192-sinh(x)
- egf( rule67:=A266839)=λ x: -7+13*x+23*cosh(2*√2*x) - 61*sinh(2*√2*x)2*√216 - 3*x24 + x312-sinh(x)+2*sinh(4*x)
- egf( rule69:=A266842)=λ x: -sinh(x) + -cosh(2*x) + sinh(2*x)2+4*cosh(4*x)+2*sinh(4*x)3
- egf( rule70:=A266846)=λ x: -e-4*x-2*e2*x+9*e4*x6 #also rule 198
- egf( rule71:=A266850)=λ x: cosh(2*x)-(1+cosh(x))*sinh(x)+2*sinh(4*x)
- egf( rule77:=A266873)=λ x: 2*e-4*x+e-x-3*ex+6*e4*x6
- egf( rule78:=A266976)=λ x: e-4*x-4*e2*x+21*e4*x12 - 12
- egf( rule79:=A266980)=λ x: -cosh(x)+4*cosh(2*x)-2*(sinh(x)+sinh(2*x)-3*sinh(4*x))3
- egf( rule81:=A266984)=λ x: -2*sinh(x)+3*cosh(4*x)+sinh(4*x)2 #also 113
- egf( rule83:=A267003)=λ x: cosh(2*√2*x)-sinh(x)+2*sinh(4*x) - sinh(2*√2*x)√2
- egf( rule85:=A267036)=λ x: e4*x-sinh(x)
- egf( rule91:=A267042)=λ x: -274 + 5*x - 21*x22 + 31*cosh(2*x)4 - (1+7*cosh(x))*sinh(x) + 2*sinh(4*x)
- egf( rule92:=A267052)=λ x: 2*e-x+3*ex+4*e2*x3-2
- egf( rule93:=A267055)=λ x: 2*e-4*x-3*e-2*x+3*e-x-3*ex+e2*x6+e4*x
. . . . . . . . . . =λ x: -cosh(2*x)+4*cosh(4*x)+2*(sinh(2*x)+sinh(4*x))3-sinh(x) - egf( rule94:=A118101)=λ x: -1 - 2*x - e-4*x12 - 2*e-x3+ex + 7*e4*x4
- egf( rule97:=A267058)=λ x: 36*cosh(4*x)-4*cos(4*x)-32*sinh(x)-sin(4*x)+9*sinh(4*x)32
- egf( rule99:=A267128)=λ x: -28*e2*x-6*cosh(√2*x)+72*cosh(2*√2*x)+3*√2*(3*sinh(√2*x)-8*sinh(2*√2*x))+4*e-x*(cos(√3*x)+√3*sin(√3x))42 - sinh(x) + 2*sinh(4*x)
- egf(rule103:=A267139)=λ x: -46+28*x-44*x2+8*x3 - 16*x43+47*cosh(√2*x)-sinh(x)+2*sinh(4*x) - 29*sinh(√2*x)√2
- egf(rule107:=A267154)=λ x: -1798+1282*x-3464*x2+40*x3-70*x4 + 152*x515 - 404*x645-2570*cos(x)+4369*cosh(x)-514*sin(x)-772*sinh(x)+2*sinh(4*x)
- egf(rule109:=A267207)=λ x: -82 + 6825*e-4*x+13845*e4*x+12740*e-x-780*ex+672*(11*sin(x)+23*cos(x))-546*(cos(4*x)-2*sin(4*x))+320*e-x*(5*cos(√3*x)-3*√3*sin(√3*x))10920
- egf(rule111:=A267255)=λ x: -94+28*x-44*x2+4*x3 - 8*x43+95*cosh(x)-30*sinh(x)+2*sinh(4*x)
- egf(rule115:=A267271)=λ x: -1+3*cosh(2*√2*x)-√2*sinh(2*√2*x)2-sinh(x)+2*sinh(4*x)
- egf(rule117:=A267274)=λ x: -1+3*cosh(4*x)+sinh(4*x)2+2*x-sinh(x)
- egf(rule118:=A267276)=λ x: 49725*e4*x-11375*e-4*x-14040*ex+2912*e2*x-126*(17*cos(4*x)+6*sin(4*x))+1280*e-x*(√3*sin(√3*x)+6*cos(√3*x))32760
- egf(rule121:=A267294)=λ x: -775-1004*x-566*x21024-5*x3/8+35*x4/32-11*x5/120+17*x6/144-sinh(x) + 257*cos(4*x)+14135*cosh(4*x)-1028*sin(4*x)+7132*sinh(4*x)8192
- egf(rule123:=A267351)=λ x: 7*cosh(2*x)-52-sinh(x)-sinh(2*x)+4*sinh(4*x)
- egf(rule125:=A267360)=λ x: -183+336*x-312*x2-32*x4+108*sinh(4*x)+375*cosh(4*x)192+2*x3-sinh(x)
- egf(rule131:=A267450)=λ x: -1 + 4*7*cos(x)+9*sin(x)65 + 7*e-x9 - 3*ex7 + e2*x45 + 8*e4*x7+5*e-x*5*√3*sin(√3*x)+9*cos(√3*x)819
- Rule 139 has no OEIS sequence, but
- rule139=λ n: 1 if n==0 else 5*4n-1-1
- gf(rule139)=λ x: 1-x+3*x2(1-x)*(1-4*x)
- egf(rule139)=λ x: 3+5*e4*x4-ex
- egf(rule141:=A267527)=λ x: 3/2 + 2*x - ex + e-4*x+2*e2*x+3*e4*x12
- egf(rule143:=A267536)=λ x: {{3+4*x+13*e4*x|8}}-ex
- egf(rule145:=A262860)=λ x: 11375*e-4*x-126*(6*sin(4*x)+17*cos(4*x))-4680*ex-11648*e2*x+15795*e4*x+2560*e-x*(3*cos(√3*x)+7*√3*sin(√3*x))32760
- egf(rule147:=A262862)=λ x: -3*e-4*x+6*e-x-7*ex+19*e4*x15
- egf(rule151:=A083420)=λ x: ex*(2*e3*x-1) #also rules 159,183,191,215,222,223,247,254,255
- egf(rule155:=A263245)=λ x: 11*e4*x-e-4*x8-ex
- egf(rule157:=A263806)=λ x: 1 - ex + -e-4*x+4*e2*x+3*e4*x6
- egf(rule158:=A118171)=λ x: e-4*x-10*e-x-16*ex+55*e4*x30
- egf(rule163:=A266753)=λ x: ex*7*e3*x-46
- Rule 171 has no OEIS sequence, but
- rule171=λ n: 1 if n==0 else 5*4n-1-1
- gf(rule171)=λ x: 1-x+3*x2(1-x)*(1-4*x)
- egf(rule171)=λ x: 3+5*e4*x4-ex
- egf(rule173:=A267596)=λ x: 1-x-ex+e4*x
- Rule 175 has no OEIS sequence, but
- rule173=λ n: 1 if n==0 else 7*4n-1-1
- gf(rule173)=λ x: 1+x+x2(1-x)*(1-4*x)
- egf(rule173)=λ x: 1+7*e4*x4-ex
- Rule 177 has no OEIS sequence, but
- rule173=λ n: 1 if n==0 else 2*4n-53
- gf(rule173)=λ x: 1-4*x+8*x2(1-x)*(1-4*x)
- egf(rule173)=λ x: 2 + 2*e4*x-5*ex3
- egf(rule185:=A267614)=λ x: 5+3*e4*x4-x-ex
- Rule 187 has no OEIS sequence, but
- rule187=λ n: 1 if n==0 else 3*4n/2-1
- gf(rule187)=λ x: 1+2*x2(1-x)*(1-4*x)
- egf(rule187)=λ x: 1+3*e4*x2-ex
- egf(rule190:=λ n: A037576(n+1))=λ x: -3*e-x-10*ex+28*e4*x15
- egf(A037576)=λ x: 3*e-x-10*ex+7*e4*x15
- egf(rule197:=A267678)=λ x: 3+2*x + 2*e-x-8*e2*x3-2*ex+2*e4*x
- egf(rule199:=A267689)=λ x: 1 - e-x+2*e2*x3 - ex + 2*e4*x
- egf(rule201:=A267681)=λ x: 1+e-2*x/2-ex-3*e2*x+2*e4*x
- egf(rule203:=A267685)=λ x: 1-x-ex-e2*x+2*e4*x
- Rule 205 has no OEIS sequence, but
- rule205=λ n: 1 if n==0 else 2*4n-5*2n-1-1
- gf(rule205)=λ x: 1-5*x+21*x2-20*x3(1-x)*(1-2*x)*(1-4*x)
- egf(rule205)=λ x: 2*e4*x-ex+5*1-e2*x2
- egf(rule207:=A267774)=λ x: 1-e2*x2-ex+2*e4*x
- Rule 209 (which is the same as 241) has no OEIS sequence, but
- rule209=λ n: 1 if n==0 else 2*4n-7
- gf(rule209)=λ x: 1-4*x+24*x2(1-x)*(1-4*x)
- egf(rule209)=λ x: 6-7*ex+2*e3*x
- egf(rule211:=A267780)=λ x: 6-2*e-x-5*ex+2*e4*x
- egf(rule213:=A267802)=λ x: 12+8*x-13*ex+2*e4*x
- egf(rule214:=A267805)=λ x: -e-4*x-8*e-x+ex+23*e4*x15
- egf(rule217:=A267812)=λ x: 1-4*x-ex-e2*x+2*e4*x
. . . . . . . . . . .=λ x: 1-4*x+ex*(ex-1)*(1+2*ex+2*e2*x) - Rule 219 has no sequence, though it is more natural than 217 (inverts the initial configuration then remains unchanged, without any temporary debris)
- rule219=λ n: 1 if n==0 else (2n-1)*(2n+1+1)
- gf(rule219)=λ x: 1-2*x+6*x2-3*x3(1-x)*(1-2*x)*(1-4*x)
- egf(rule219)=λ x: 1-ex+e2*x+2*e4*x
. . . . . . =λ x: 1+ex*(ex-1)*(1+2*ex+2*e2*x)
- egf(rule221:=A267816)=λ x: 2-ex-2*e2*x+2*e4*x
- egf(rule227:=A267847)=λ x: 5+2*x-6*ex+2*e4*x
- egf(rule229:=A267851)=λ x: 1-4*x-2*ex+2*e4*x
- egf(rule230:=A267855)=λ x: 3*cos(2*x)-6*sin(2*x)-10*cosh(2*x)+22*cosh(4*x)+28*sinh(4*x)15
. . . . . . . . . . .=λ x: (3+6*i)*e2*i*x+(3-6*i)*e-2*i*x-15*e2*x-5*e-2*x+50*e4*x-6*e-4*x30 - Rule 231 has no OEIS sequence, but
- rule231=λ n: 1 if n==0 else 2*(4n-1)
- gf(rule231)=λ x: 1+x+4*x2(1-x)*(1-4*x)
- egf(rule231)=λ x: 1-2*ex+2*e4*x
- egf(rule233:=A267877)=λ x: -7*x-5*x2-4*x3/3-ex+2*e4*x
- egf(rule235:=A267886)=λ x: -3*x-2*x2-ex+2*e4*x
- egf(rule237:=A267888)=λ x: -5*x-ex+2*e4*x
- egf(rule239:=A267890)=λ x: -x-ex+2*e4*x
- egf(rule243:=A267921)=λ x: 2-3*ex+2*e4*x
- egf(rule245:=A267924)=λ x: 4-5*ex+2*e4*x
- egf(rule246:=A267926)=λ x: -7*ex+25*e4*x-3*e-4*x15
- egf(rule249:=A267935)=λ x: -6*x-2*x2-ex+2*e4*x
- egf(rule251:=A267938)=λ x: -2*x-ex+2*e4*x
rule 225
The results from the experimentation in this section (and some more) are formatted more nicely and proven in Rule 120- do not listen to that italicised indented note, i am from the future. i rewrote it into on nearsighted binary counters which is much more pleasant and readable, go read that instead
Rule 225[e 2] is more interesting, it is not definable in any such form arithmetically but bitwisely.
- A078176=λ n: n and reduce(λ s,i: s<<2&s<<1^s,range(n-1),7)
For n>0, A078176 is defined recursively, beginning with three consecutive 1-bits. Though a(0)=0 retains the property that lets states in rule 225 be XORed back from it, it is also the iteration before the infinite number of cells on either side flip in rule 225. Beginning with a(0)=3 makes the recurrence relation apply over all n>=1.
While successive rows of the Sierpinski triangle can be computed with bitwise operators by recursively computing "flip state if the neighbour to your right is on," this one instead requires the two bits to the right both to be on. The bits left of the rightmost two (which are always on) appear at first to count in binary, 0,1,2,3,4,5,6, but upon their last bit becoming 1 for 7, the next bit becomes 1 also. Each time a subsection of the integer deviates from the standard process of binary counting by incrementing a new bit, all lower bits will turn off in the next generation, providing another carry.
Stephen Wolfram stated in A New Kind of Science that the length of the binary representation in generation n "grows like √n,"[e 3] but I will investigate here more precisely.
Bits are dependent only on their own state and the lower ones, so trivially, when considering only the last n bits (elements modulo 2n), the sequence is periodic, and for each bit, depending on whether the two bits to its right are both 1 an even or odd number of times in their period, its period is either 1 or 2 times theirs respectively, so by induction, all bits' periods are powers of 2. Whereas in standard binary counting, the bit at index n has period 2n, however, in this the sequence of periods begins 1,1,2,4,8,8,16,32,32,32,32,32,64. Taking log2 of each of these, 0,0,1,2,3,3,4,5,5,5,5,5,6,7,7,7. Excluding the first two 0s, even numbers occur once, and odd numbers 2*n+1 occur A083329(n) times. Multiplying this by x1-x will take its upper-exclusive partial sum (returning the function such that a(n) returns the sum of the run lengths up to period 2n). The explicit analytic form for this is
- λ n: (0,2)[n] if n<2 else 2*(1-(-1)n)+3*2(n-1)/2*(1-(-1)n)+3*2n/2*(1+(-1)n)4
Equivalently (over the integers),
- λ n: (0,2)[n] if n<2 else n%2+3*2⌊n/2⌋/2
Or
- λ n: (2 if n==1 else 3*2(n-1)/2/2+1) if n≡1 (mod 2) else (0 if n==0 else 3*2n/2/2)
We know that (after the initial two) the odd case applies only to single elements at a time. This computes the number of bits preceding the first with period 2n, so inverting the function (and taking the floor) returns the log2 of the period as a function of the bit index. Ignoring everything and inverting both cases blindly yields
- a=λ n: 2*log2(√2*(n-1)3) if a(n)≡1 (mod 2) else 2*log2(2*n/3)
This is not very useful, but the even-output case is true in precisely one case, at which its output is integer, which can be checked by seeing whether taking its floor and then its inverse (an integer-to-integer function) returns n, and otherwise adding 1.[e 4]
- λ n: (o:=⌊2*log2(2*n3)⌋)+(n>3*2o/22)
Being that o is assumed to be even for the equality, the ⌊2*log2⌋ can be changed to 2*⌊log2⌋, and ⌊log2(n)⌋=n.bit_length()-1.
- λ n: (p:=2*(⌊2*n3⌋).bit_length()-1)+(n>3*2p/22)
We may trivially reduce it, and also account for the first two 0s again.
- λ n: 0 if n<2 else 2*(p:=(⌊n3⌋).bit_length())+(n>⌊3*2p2⌋)
So, for a given integer p>=1, the unique bit with period 22*p lies at index 3*2p/2. Equivalently, bits with indexes of the form n=3*2p have period (2*n3)2.
Knowing this, we will move onto the question, what is the first iteration at which the nth bit turns on? It begins 0,0,1,2,4,7,8,16,25,26,28,31,32,64,97,98. Taking the first differences and splitting it at each successive power of 2 reached,
- from itertools import starmap,pairwise,accumulate
redumulate=λ f,l,i=None: accumulate(l,f,initial=i)
space=λ l: λ s: ' '*(l-len(str(s)))+str(s)
print('\n'.join(map(space(max(map(len,t:=tuple(map(str,(λ f: f(f))(λ f: λ r,i,t: f(f)(*((t[-1][i],1,t[:-1]+(t[-1][:i],t[-1][i:])) if t[-1][i]>=2*r else (r,i+1,t))) if i<len(t[-1]) else t)(0,0,((0,)+tuple(starmap(int.__rsub__,pairwise(t:=tuple(map(λ i: next(filter(λ n: t[n]>>i&1,range(len(t)))),range((t:=tuple(redumulate(λ s,i: s<<2&s<<1^s,range(1<<16),3)))[-1].bit_length())))))),))))))),t)))
It can be seen that this, too, abides by a recursive definition.
(0,0,1)
(1)
(2,3,1)
(8,9,1,2,3,1)
(32,33,1,2,3,1,8,9,1,2,3,1)
(128,129,1,2,3,1,8,9,1,2,3,1,32,33,1,2,3,1,8,9,1,2,3,1)
(512,513,1,2,3,1,8,9,1,2,3,1,32,33,1,2,3,1,8,9,1,2,3,1,128,129,1,2,3,1,8,9,1,2,3,1,32,33,1,2,3,1,8,9,1,2,3,1)
After the first three terms, it is generated recursively,
- (0,0,1)+reduce(λ r,i: r+(2**(2*i+1),2**(2*i+1)+1)+r,range(5),(1,))
This provides a recurrence-relation-based form,
- The sequence begins a(0)=0,a(1)=0,a(2)=1,
- a(n)=2*(n-13)2 .=2k+1 . if n is of the form 3*2k+1 (ie. n=3*2⌊log2(⌊n-13⌋)⌋+1),
- a(n)=2*(n-23)2+1=2k+1+1 if n is of the form 3*2k+2 (ie. n=3*2⌊log2(⌊n-23⌋)⌋+2),
- a(n)=a(n-3*2⌊log2(⌊n3⌋-1)⌋) otherwise.
This may be implemented
- a=λ n: (0,0,1)[n] if n<3 else 2*(n//3)**2+n+~k if 1<=n-(k:=3<<(n//3).bit_length()>>1)<3 else a(n-(3<<(n//3-1).bit_length()>>1))
Being that this provides only the first differences, taking its partial sums seems a very hard task, however from the recursive definition we obtain that since the function f=λ k: ∑3*2kn=0(a(n)) abides by f(0)=2 and f(k)=22*k+2*f(k-1), meaning f(k)=22*k+1.
Extending this to explicit forms for the two non-recurrent cases, it too has a recurrence-relation-based form.
- The sequence begins a(0)=0,a(1)=0,a(2)=1,
- a(n)=(2*n-13)2=2*22*k+1 . . if n is of the form 3*2k+1.
- a(n)=2*(n-2)23+1=3*22*k+1+1 if n is of the form 3*2k+2.
- a(n)=3*22*k+1+1+a(n-3*2k) otherwise, where k=⌊log2(⌊n3⌋-1)⌋.[e 5]
Which may be implemented
- a=λ n: (0,0,1,2)[n] if n<4 else (k**2//3<<1|1 if n+~k else (k//3<<1)**2) if 1<=n-(k:=3<<(n//3).bit_length()>>1)<3 else (3<<2*(k:=(n//3-1).bit_length())-1)+a(n-(3<<k-1))
This sequence turns out to have an OEIS entry of its own, A338888.
It is defined by
- a(1)=a(2)=0
- a(n)=(a(n-1)|a(n-2))+1
However, this definition (a linear recurrence relation) takes linearly many operations, whereas mine (an exponential one, of sorts) takes logarithmically. It is also not mentioned there that a(n) is the number of generations for the nth bit in rule 225's counting system to first become 1.
However, on July 29, 2023, after telling my close friend Magma (from the ConwayLife lounge) about this, he said
(A000695 is defined by reinterpreting its input's binary representation as its output's base-4 representation, ie. λ n: int(bin(n)[2:],4))
I experimented for a few minutes, and sure enough, it is computable as
- A338888=λ n: int(n>=2 and (3*(A000695(2*n//3-1)+A000695((2*n-1)//3))>>2)+1)
(note that when it bitshifts right by 2, it utilises the bitshifts' truncation to round down, however A000695(n) is periodic modulo any power of 4, so the nth term will have (2,3,3)[n%3] subtracted from it)
A338888 analysis
g.f.
Note that A000695's generating function is expressible as a summation (that converges at a rate equivalent to finding O(2n) terms in n iterations),
- gf(A000695)=λ x: ∑∞k=0(4k*x2k1+x2k)1-x
which works since the bit representing 4k flips each 2k iterations, beginning on the 2kth, and each time it turns on and off, the first differences change by ±4k with alternating sign (of which partial sums are taken by the division by (1-x)). (The nth term accounts for the nth set of bits.)
This means that A338888's generating function is expressible in terms of such a form as well, with some tricks.
Workings
We begin with the identity
- gf(λ n: f(n+1))=λ x: gf(f)(x)-f(0)x
It is a well-known fact that given a linear-recurrent sequence, one can sum its terms with indexes congruent to 0 modulo a number n, by evaluating its generating function on the nth roots of unity and taking their average, since the average of the roots' kth powers is 1 if k≡0 (mod n) and 0 otherwise. In general, given a function f, a summation may be constructed in which each of f's terms are multiplied by those of an arbitrary sequence with a given period n as an expression in terms of gf(f), by taking a linear combination of calls of it on each of the nth roots of unity times n√x, with coefficients findable by matrix inversion.
Understanding this in detail is not necessary here, however, since this derivation will concern the simplest case, computing it modulo 2. The second roots of unity are 1 and -1, so no knowledge of complex numbers is necessary (and the final form is over the reals).
We have the identities
- gf(λ n: f(2*n ))=λ x: gf(f)(√x)+gf(f)(-√x)2
- gf(λ n: f(2*n+1))=λ x: gf(f)(√x)-gf(f)(-√x)2*√x
Since i=λ n: 2*n//3+1 has three cases for each parity of n, to find the expression using it for indexing in a generating function, one must only find
- for n≡0 (mod 3), i(n)=2*n3+1
- for n≡1 (mod 3), i(n)=2*n+13
- for n≡2 (mod 3), i(n)=2*n3+2
Therefore,
- gf(λ n: f(. 2*n//3+1))=λ x: (1+x)*gf(λ n: f(2*n+1))(x3). . + x2*gf(λ n: f(2*n+2))(x3)
. . . . . . . . . . . =λ x: (1+x)*gf(λ n: f(2*n+1))(x3). . + x2*(λ x: gf(λ n: f(2*n))(x)-f(0)x)(x3)
. . . . . . . . . . . =λ x: (1+x)*gf(λ n: f(2*n+1))(x3). . + gf(λ n: f(2*n))(x3)-f(0)x
. . . . . . . . . . . =λ x: (1+x)*gf(f)(x3/2)-gf(f)(-x3/2)2*x3/2 + gf(f)(x3/2)+gf(f)(-x3/2)2-f(0)x
. . . . . . . . . . . =λ x: (1+√x+x)*gf(f)(x3/2)-(1-√x+x)*gf(f)(-x3/2)2-√x*f(0)x3/2
And similarly, for i=λ n: (2*n+1)//3,
- gf(λ n: f((2*n+1)//3))=λ x: gf(λ n: f(2*n))(x3) . . .+ x*(1+x)*gf(λ n: f(2*n+1))(x3)
. . . . . . . . . . . =λ x: gf(f)(x3/2)+gf(f)(-x3/2)2 + x*(1+x)*gf(f)(x3/2)-gf(f)(-x3/2)2*x3/2
. . . . . . . . . . . =λ x: gf(f)(x3/2)+gf(f)(-x3/2) + x*(1+x)*gf(f)(x3/2)-gf(f)(-x3/2)x3/22
. . . . . . . . . . . =λ x: gf(f)(x3/2)+gf(f)(-x3/2) + . (1+x)*gf(f)(x3/2)-gf(f)(-x3/2)√x2
. . . . . . . . . . . =λ x: (1+√x+x)*gf(f)(x3/2)-(1-√x+x)*gf(f)(-x3/2)2*√x
Let both=λ f: λ n: f((2*n+1)//3)+f(2*n//3+1), for brevity, then this allows for them to be combined,
- gf(both(f))=λ x: (1+x)*(1+√x+x)*gf(f)(x3/2)-(1-√x+x)*gf(f)(-x3/2)2*x3/2
Because A338888=λ n: int(n>=2 and 3*both(A000695)(n-2)-(2,3,3)[n%3]4+1), we have
- gf(A338888)=λ x: 3*x2*gf(both(A000695)) - 3*x2+2*x3+3*x41-x34 + x21-x
Inlining this,
- . . . . . .=λ x: 3*x2*(1+x)*∑∞k=0(4k*(x3/21+x3/2)2k1-√x-(-x3/2)2k1+(-x3/2)2k1+√x)2*x3/2-3*x2+2*x3+3*x41-x34+x21-x
Note that the (-x3/2)2k term is equivalently (-1)2k*x3*2k/2, and that over the integers, (-1)2k is -1 only if k=0 (because as a square-root of unity, (-1).__pow__ is nature's (2).__rmod__ :-), so we may change it to its positive form and move the difference from the k=0 case into its own term.
- . . . . . .=λ x: 3*x2*(1+x)*∑∞k=0(4k*(x3*2k1+x3*2k1-√x-x3*2k1+x3*2k1+√x))2*x3/2+3*x2*1+x1+√x-x3-x7/2-3*x2+2*x3+3*x41-x34+x21-x
Allowing the summand to be greatly reduced
- . . . . . .=λ x: 3*x*(1+x)*∑∞k=0(4k*x3*2k1+x3*2k)1-x+3*x2*1+x1+√x-x3-x7/2-3*x2+2*x3+3*x41-x34+x21-x
Thereafter it is only standard algebraic manipulation
- . . . . . .=λ x: 3*x*(1+x)*∑∞k=0(4k*x3*2k1+x3*2k)+4*x21-x+3*x2*1+x1+√x-x3-x7/2-3*x2+2*x3+3*x41-x34
- . . . . . .=λ x: 3*x*(1+x)*∑∞k=0(4k*x3*2k1+x3*2k)+4*x21-x+3*x2*1+x1+√x-3*x2-2*x3-3*x41-x34
- . . . . . .=λ x: 3*x*(1+x)*∑∞k=0(4k*x3*2k1+x3*2k)+4*x2+3*x2*1+x1+√x-3*x2-2*x3-3*x41+x+x24*(1-x)
- . . . . . .=λ x: x*(1+x)*3*∑∞k=0(4k*x3*2k1+x3*2k)+x*4+√x+x+x3/2(1+√x)*(1+x+x2)4*(1-x)
- . . . . . .=λ x: x*(1+x)*3*∑∞k=0(4k*x3*2k1+x3*2k)+x*31+√x+1+x1+x+x24*(1-x)
- gf(A338888)=λ x: x*(1+x)*3*∑∞k=0(4k*x3*2k1+x3*2k)+x+x21+x+x21-x
Since we have the bounds 2*(n-1)29 <= A338888(n) <= 2*(n-3)23+1, gf(A338888)(x) converges for |x|<1.
notes
- ↑ Partial fraction expansions have the corollary that the factorisation of a generating function's denominator means the sequence it represents may be expressed as a sum of sequences with recurrence relations given by each of the factors, so a sequence given by such a convolution of two sequences is also expressible as a sum of two other sequences with functions of similar forms but different coefficients.
- ↑ It is a member of the equivalence class also including rules 169 (its left/right reflection), 120 (its black/white reversal) and 106 (both), but is used as the representative because a single on-cell in it produces this pattern and it's right-aligned.
- ↑ A New Kind of Science, page 58: 'More cellular automata'
- ↑ This is a common method for many sequences that aren't otherwise computable in terms of integer arithmetic, like those that require cubic equations to be inverted, and have closed forms involving taking the floor of the sum of two infinite-precision radicals.
- ↑ In the implementation, k has 1 subtracted from it due to how bit_length works, it looks as though the calls may be reduced by merging in the subtraction to its definition, but this can in fact cause negative shifts in the first case.
generalisations
- See also Big-Θ notation
These bounds mean lim infn->∞(A338888(n)n2)=29 and lim supn->∞(A338888(n)n2)=23.
Consider the generalisation of rule 225's counting system to a width-n+1 rule. Each rule is defined as a function that XORs its input integer with the reduced bitwise AND of copies of itself shifted each of 1,2,...,n bits left. The rule integer for the Wolfram rule that emulates it on the right edge, after inverting from the single-cell state, is (surprisingly elegantly) ∑2n+1-1k=2n+1(2k)+1=(22n-1)2. (Hereafter, however, we consider the counting system, ie. the bitwise NOT of this.)
The counting system in the nth such rule (in a width-n+1 neighbourhood) grows with Θ(n√t). The last n bits are always on (so first turn on at generation 0, firston(n,k)=0 for 0<=k<n), the kth bit first becomes on at iteration firston(n,k)=reduce(λ r,i: r|A(n,k+~i),range(n),0)+1. This provides an infinite array, with some interesting properties. Here it is shown (with 0s hidden)
(1,1,1,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ,1,2,3,4,5,6, 7, 8, 9,10, 11, 12, 13, 14, 15, , ,1,2,4,7,8,16,25,26,28, 31, 32, 64, 97, 98, , , ,1,2,4,8,15,16,32,64,113,114,116,120,127, , , , ,1,2,4, 8,16,31,32, 64,128,256,481,482, , , , , ,1,2, 4, 8,16,32, 63, 64,128,256,512, , , , , , ,1, 2, 4, 8,16, 32, 64,127,128,256, , , , , , , , 1, 2, 4, 8, 16, 32, 64,128,255, , , , , , , , , 1, 2, 4, 8, 16, 32, 64,128, , , , , , , , , , 1, 2, 4, 8, 16, 32, 64, , , , , , , , , , , 1, 2, 4, 8, 16, 32, , , , , , , , , , , , 1, 2, 4, 8, 16, , , , , , , , , , , , , 1, 2, 4, 8, , , , , , , , , , , , , , 1, 2, 4, , , , , , , , , , , , , , , 1, 2, , , , , , , , , , , , , , , , 1)
- update: this array is now A385674
- Since the condition that each cell flips if the reduced bitwise AND of the succeedng n bits is 1 (where the first n are always on) is equivalent to all succeeding bits for a cell with an index less than or equal to 2*n (and since the reduced bitwise OR of the preceding terms for k<=2*n is a Mersenne number), for n<=k<=2*n, firston(n,k)=2k-n.
- Being the inversion of the counting system's slow-growing bit-length function, with respect to k, firston(n,k)=Θ(kn).
- More precisely, lim infk->∞(firston(n,k)kn)=2(n+1)n and lim supk->∞(firston(n,k)kn)=(2n-1)*2(n+1)n
Consider the function bn, that reinterprets its input's binary expansion as its output's base-2n expansion.
- |∑=λ l: reduce(int.|,l,0) #ORsum
- bn=λ k: |∑(map(λ i: (n>>i&1)<<(i*b),range(n.bit_length())))
We have that lim supk->∞(bn(k)kn)=1 (with equality at powers of 2), and lim infk->∞(bn(k)kn)=12n-1 (achieved in the limit as k is preceding powers of 2, since adjacent bits are stretched 2n indexes apart, and the representation of 1bn-1 in base b is ∑∞k=1(b-n*k).)
As mentioned previously, λ k: firston(2,k) may be expressed as a closed form in terms of 2 copies of λ k: b2(⌊2*(k+o)-13⌋) evaluated on different offsets o. Note that λ k: firston(n,k) and bn both grow with the same asymptotic rate and shape (with the same ratio between their lim infs and lim sups). In fact, for all n, for almost all k, firston(n,k) ~ bn(⌊kn+1⌋)*(2n-1)*2.
Using the ρ function (A007814) from the conventions, this function firston (that generates the array) has the explicit form
- firston=λ n,k: 2*(2n-1)*bn(⌊kn+1⌋)+(k%(n+1)==n or 2*(1+2k%(n+1)-2n)*2ρ(⌊kn+1⌋)*n)[gen 1]
And row n's generating function is
- .λ x: 2*(2n-1)*∑∞k=0(2n*k*x(n+1)*2k1+x(n+1)*2k)1-x + xn1-xn+1 + 2*((1-2n)*(1-xn)1-x + 1-(2*x)n1-2*x)*∑∞k=0(2n*k*x(n+1)*2k1-x(n+1)*2k+1)
=λ x: ((1-2n)*(1+xn)1-x + 1-(2*x)n1-2*x)*∑∞k=0(2n*k*x(n+1)*2k1+x(n+1)*2k) + xn1-xn+1 + ((1-2n)*(1-xn)1-x + 1-(2*x)n1-2*x)*∑∞k=0(2n*k*x(n+1)*2k1-x(n+1)*2k)
Now consider the function p(n,k), which returns the period of the kth bit in the nth counting system. As mentioned above for the n=2, by induction, each cell's period is that of the set of n cells to its right, multiplied by 2 if they all become on simultaneously an odd number of times in this period, so each term is a power of 2, and it cannot increase any faster than doubling with each cell (which is what it converges to for large n, since the limit as n->∞ is a standard binary counter). Consider the log2 of this sequence, then for each period k plot the number of cells for which it remains on. Using the slightly suspicious dronery program,
rule=λ w: λ n: n^reduce(λ r,i: r&n<<i,range(1,w+1),~0)
iterate=λ w,n: tuple(expumulate(rule(w),n)(~(~0<<w)))
print(stratrix((('n\k',)+tuple(range(16)),)+tap(λ n: (n,)+tap(rgetitem(1),rle(Y(λ f: λ k,t: t[:-1] if t and t[-1]==16 else f(k+1,t+(period(tap(λ i: i>>k&1,iterate(n,1<<widthRLE(n,k).bit_length()+1))).bit_length()-1,)))(0,()))),range(1,16)),2))we have
(n\k, 0,1,2,3,4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 1,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384, 2, 2,1,1,2,1, 5, 1,11, 1, 23, 1, 47, 1, 95, 1, 191, 3, 3,1,1,1,2, 1, 1, 6, 1, 1, 14, 1, 1, 30, 1, 1, 4, 4,1,1,1,1, 2, 1, 1, 1, 7, 1, 1, 1, 17, 1, 1, 5, 5,1,1,1,1, 1, 2, 1, 1, 1, 1, 8, 1, 1, 1, 1, 6, 6,1,1,1,1, 1, 1, 2, 1, 1, 1, 1, 1, 9, 1, 1, 7, 7,1,1,1,1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 10, 8, 8,1,1,1,1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 9, 9,1,1,1,1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 10,10,1,1,1,1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 11,11,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 12,12,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 13,13,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 14,14,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 15,15,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
Note that the non-1 elements in each row (with indexes congruent to 1 modulo n) have the interesting recurrence relation a(n,n+1)=2 and thereafter a(n,k)=2*a(n,k-n)+n-1.
The number of cells with period 2p in rule n is given by the form
- λ n,p: (n+1)*2⌊pn⌋+~(n==1))-n+1 if p>n and (p-1)%n==0 else 1 if p else n
given somewhat more elegantly as its g.f.,
- λ x,y: ∑∞n=1(xn*(n + y*(1-yn+(n-1)*y2*n)(1-yn)*(1-2*yn) + y2*(1-yn-1)(1-y)*(1-yn)))
To take the partial sum, multiplying by y1-y, partial-fraction-decomposing and solving, one obtains the form for the first index of period 2p
- λ n,p: p and (n if p==1 else (n+1)*(2⌊p+n-2n⌋-1)+3*(n-1)2 + p - ⌊p+n-2n⌋*n)
using the identity ⌊xy⌋*y + x%y = x, we get
- λ n,p: p and (n if p==1 else (n+1)*2⌊p-2n⌋ + (p-2)%n)
and being a strictly increasing function, this has a floor-inverse (in the manner of isqrt), which is given by λ n,k: ⌊log2(firston(n,k))⌋+1, or equivalently the function
- log2per=λ n,k: k==n or k>n and ⌊log2(⌊kn+1⌋)⌋*n+1+min(n,k+1-(n+1)*2⌊log2(⌊kn+1⌋)⌋)
Consider the function that returns the number of times the kth bit flips within its oscillatory period (for k>n). For n=1 (the Sierpinski triangle case), this is 2A086784(k)+1 (where A086784=λ k: k.bit_length()-k.bit_count()-(~k&k-1).bit_length(), the number of non-trailing 0-bits), but for n>1, it may be obtained by a morphism from this.
Given the sequence A086784 (albeit with a(0)=-2), each element b (with an a preceding it and c succeeding it) is transformed to the tuple
- (0,)*(1 if a else n) if not b and c else (b,) if b<=c else tuple(range(b,c,-1))
before all elements' tuples are concatenated together to obtain the sequence a such that the number of flippings per period by the kth cell in the nth rule is given by ⌊2a(k)+1⌋. (All integers are multiplied by n, all descents are padded to decrease by 1 each time, and each 0 bordered by 0s is repeated n times.) While there is no last element, the initial 0 term is skipped by the iteration process (since it has no a), so n -2s and n-1 0s are prepended.
The length-k runs of 0s are changed to length n*(k-2)+2, and all length-2k-1 runs of nonzero integers are changed to length (n+1)*2k-22 (ie. k to (k+1)*n+k-12). Asymptotically, a length-k subsequence will approach length n+12 * k as k->∞. Using this (and experimenting and golfing somewhat), the morphism's __getitem__ has the explicit form,
- log2flips=λ n,k: -2 if k<n else (a:=A086784(i:=⌊k+1n+1⌋*2-1)) and n*a-k+⌊(n+1)*i+n2⌋
(ie. ⌊2log2flips(n,k)+1⌋ is the number of flippings by the kth cell in the nth rule.)
Within its period, after the first firston(n,k) iterations, the kth cell becomes on for fixed durations 2ρ(firston(n,k)), with ρ(firston(n,k)) given by
- log2ondur=λ n,k: int(k>n) and (a:=ρ(i:=⌊kn+1⌋+⌊k+1n+1⌋)) and n*(a-1)+1+k-⌊(n+1)*i2⌋
With these functions, one may define the state of the kth cell at the tth generation in the nth rule as
- bit=λ n,k,t: k<n or t&~(~0<<log2period(n,k))>=firston(n,k) and t>>log2ondur(n,k)&1 and (k%(n+1)<n and not ⌊kn+1⌋&⌊kn+1⌋-1 or bit(n,k-(n+1<<(⌊kn+1⌋).bit_length()>>1),t))
Unravelling this allows an explicit form to be given for A264442, as a function of two variables n,k (n in place of t),
- A000695=λ n: int(bin(n)[2:],4)
A264442=λ n,k: int(not n or (o:=6*A000695(⌊k3⌋)+(k%3==2 or (⌊k3⌋&-⌊k3⌋)2*(2k%3-3)<<1))>n&~(~0<<o.bit_length()) or k>1 and ~n>>(~o&o-1).bit_length()&1 or (not k%3<2 or ⌊k3⌋&⌊k3⌋-1) and A264442(n,k-(3<<(⌊k3⌋).bit_length()>>1)))
(and of course A267841(n,k)=A264442(n,2*n-k))
notes
- ↑
The full set of equivalent forms from this is
- A338888=λ n: (0,0,1,2)[n] if n<4 else (⌊k23⌋<<1|1 if n+~k else (⌊k3⌋<<1)2) if 1<=n-(k:=3<<(⌊n3⌋).bit_length()>>1)<3 else (3<<2*(k:=(⌊n3⌋-1).bit_length())-1)+A338888(n-(3<<k-1))
- A338888=λ n: int(n>1) and (3*(b2(⌊2*n3⌋-1)+b2(⌊2*n-13⌋))>>2)+1
- A338888=λ n: int(n>1) and 6*b2(⌊n3⌋)+(n%3==2 or 2*(2n%3-3)*4ρ(⌊n3⌋))
other OEIS things
other bitwise g.f.'s
See #redstoneboi's algorithm for the interesting context in which the first four arose.
Similarly to A000695, we may find a generating function for the function that reverses n's binary representation in a length-l register (which was referred to as niceA030101 when used earlier). (It is a finite polynomial because it is undefined outside 0<=n<2l.)
- λ l: λ x: ∑l-1n=0(2l+~n*x2n*∑2n-1k=0(xk)*∑2l+~n-1k=0(x2n+1*k))
which may be simplified
- λ l: λ x: ∑l-1n=0(2l+~n*x2n*1-x2n1-x*1-x2l1-x2n+1)
- λ l: λ x: (1-x2l)*∑l-1n=0(2l+~n*x2n*1-x2n1-x2n+1)1-x
- λ l: λ x: (1-x2l)*∑l-1n=0(2l+~n*x2n1+x2n)1-x
A030101(n) is defined by reversing n's binary representation in a register with the same bit length as n (such that the first bit is always moved to 20). To do this, we may sum only over the second half of the x's for a given l's sequence, to get its subsection. The last nested summation must have the starting index set to half the ending one, except for the last one, where l+~n=0 so it is over a length-20=1 iteration, which cannot be halved, so it must be unravelled into its own term.[bitwise 1]
- λ x: ∑∞l=1(∑l-2n=0(2l+~n*x2n*∑2n-1k=0(xk)*∑2l+~n-1k=2l-1+~n(x2n+1*k))+x2l-1*∑2l-1-1k=0(xk))
which may be simplified
- λ x: ∑∞l=1(x2l-1*∑l-2n=0(2l+~n*x2n*(1-x2n)*1-x2l-11-x2n+1)+(1-x2l-1)1-x)
- λ x: ∑∞l=1(x2l-1*(1-x2l-1)*(∑l-2n=0(2l+~n*x2n1+x2n)+1))1-x
It seems as though the indexing would like to be changed
- λ x: ∑∞l=0(x2l*(1-x2l)*(∑l-1n=0(2l-n*x2n1+x2n)+1))1-x
However, note that because this applies the right half of the previous finite-register form for each l, it sums over the first 2l terms. However, the previous generating function shown for A000695 works with one iteration of its sum per bit of all outputs (over all exponents of x). Individual bits are not periodic here so it is not so easy, however we may use the fact that the powers of 2 are their own shifted first difference. Instead of beginning and ending a new finite polynomial over powers of x with a specific bit with each summand, it corrects the existing infinite polynomials, and outside the n-summation, it corrects for the fact that the new bit for this l-iteration is not being doubled but created. (The l and prevents this in the l=0 case, which is handled by the x on the outside.)
- λ x: ∑∞l=0(x2l*(∑l-1n=0(2l+~n*x2n1+x2n)+(l and x2l-11+x2l-1)))+x1-x
However, if we detach from the notion that iterations should correspond with specific sections of the output entirely, with a small amount of special care the leading-bit-correction term can be handled by the preceding iteration. This provides the form
- gf(A030101)=λ x: ∑∞l=0(x2l*(∑l-1n=0(2l+~n*x2n1+x2n) + x2l+11+x2l))+x1-x
Note that it converges rapidly (in logarithmic time compared to explicit iteration), but the divisions by (1+x2n) cause it to have singularities at all 2nth roots of unity, so evaluating it on any point within the unit circle's edge for sufficiently many iterations will cause it to become arbitrarily large. I am interested to know whether such a function may be continued outside the unit circle, this form doesn't converge but grows arbitrarily.
Note that Project Euler's recurrence-based form for it, a(1)=1, a(3)=3, a(2*n)=a(n), a(4*n+1)=2*a(2*n+1)-a(n), a(4*n+3)=3*a(2*n+1)-2*a(n), or
- A030101=λ n: (0,1,1,3)[n] if n<4 else (1,2,1,3)[n&3]*A030101(n>>1|n&1)-(0,1,0,2)[n&3]*A030101(n>>2)
becomes the identity that gf(A030101) follows (and uniquely defines it, together with the initial terms),
- f(x)=f(x2) + (2x + 3*x)*f(x2)-f(-x2)2 - x*(1+2*x2)*f(x4)
Let n be the bit's precedence, k be the current run of 1-bits, and l be the index within it.
- .λ x: ∑∞n=0(x2n*∑∞k=0(k*x2n+1*k*∑2n-1l=0(xl)))
- =λ x: ∑∞n=0(x2n*x2n+1(1-x2n+1)2*1-x2n1-x)
- =λ x: ∑∞n=0(x3*2n(1-x2n+1)2*1-x2n1-x)
- =λ x: ∑∞n=0(x3*2n(1-x2n+1)*(1+x2n)*(1-x))
- =λ x: ∑∞n=0(x3*2n(1-x2n)*(1+x2n)2*(1-x))
- f(0)=0, f(x) = (1+x)*f(x2) + x3(1-x2)2
Like A233905 but we do not impart the initial shift, so it is
- .λ x: ∑∞n=0(x2*2n(1-x2n)*(1+x2n)2*(1-x))
- f(0)=0, f(x) = (1+x)*f(x2) + x2(1-x2)2
- .λ x: ∑∞n=0(x2n*∑∞k=0((k+1)*x2n+1*k)*∑2n-1l=0(xk))
- =λ x: ∑∞n=0(x2n(1-x2n+1)2*1-x2n1-x)
- =λ x: ∑∞n=0(x2n(1-x2n)*(1+x2n)2*(1-x))
- f(0)=0, f(x) = (1+x)*f(x2) + x(1-x2)2
conjectured form
Velin Yanev conjectured on 2017-09-12 that a(n) = n*(n+3)2 - A007814(A293290(n)), ie.
- A264596=λ n: n*(n+3)2 - ρ(∏nk=1(∏kj=1(k2+j2)))
. . . .=λ n: n*(n+3)2 - ∑nk=1(∑kj=1(ρ(k2+j2)))
which is true
note that for x,y != 0, in general ρ(x+y) = (m:=min(ρ(x),ρ(y)))+Y(λ f: λ x,y: x&y&1 and (n:=ρ(~x^y>>1))+(n and f(x>>n,y>>n) or 1))(x>>m,y>>m)
however, for squares, there is the special case that ρ(x2+y2) = 2*min(ρ(x),ρ(y))+(ρ(x)==ρ(y)), since squares' last nonzero digit in base-4 must be 1, so there may be at most one carry operation.
- . . . .=λ n: n*(n+3)2 - ∑nk=1(∑kj=1(2*min(ρ(k),ρ(j))+(ρ(k)==ρ(j))))
note that ∑kj=1(min(ρ(k),ρ(j))) = A331739(k) = k-(k>>ρ(k)) and ∑kj=1(ρ(k)==ρ(j)) = A003602(k) = (k>>ρ(k)+1)+1
- . . . .=λ n: n*(n+3)2 - ∑nk=1(2*(k-(k>>ρ(k)))+(k>>ρ(k)+1)+1)
. . . .=λ n: n*(n+1)2 - ∑nk=1(2*(k-(k>>ρ(k)))+(k>>ρ(k)+1))
=λ n: ∑nk=1(2*(k>>ρ(k))-(k>>ρ(k)+1)) - n*(n+1)2
=λ n: ∑nk=1(1+(3*k>>ρ(k)+1)) - n*(n+1)2
=λ n: ∑nk=1(3*k>>ρ(k)+1) - n*(n-1)2
=λ n: ∑nk=1(1+(3*k>>ρ(k)+1)) - n*(n+1)2
=λ n: ∑nk=1((3*k>>ρ(k))-1)-n*(n-1)2
=λ n: 3*∑nk=1(k>>ρ(k))-n22[bitwise 2]
so it has a(n)-a(n-1) = 3*(n>>ρ(n))+12 - n, and incidentally (due to Alejandro Erickson's form for A135013) a(n) = 3*∑n.bit_length()k=1((n+2k-1>>k)2)-n22
and in terms of generating functions, this means
- ∑∞n=0(x2n(1-x2n)*(1+x2n)2*(1-x)) = 6*∑∞n=0(x2n(1-x2n)2*(1+x2n)2) - 3*x(1-x) - x*(1+x)(1-x)22*(1-x)
∑∞n=0(x2n(1-x2n)*(1+x2n)2*(1-x)) = 6*∑∞n=0(x2n(1-x2n)2*(1+x2n)2) + 2*x*(x-2)(1-x)22*(1-x)
∑∞n=0(x2n(1-x2n)*(1+x2n)2) = 3*∑∞n=0(x2n(1-x2n)2*(1+x2n)2) + x*(x-2)(1-x)2
∑∞n=0(x2n*(2+x2n)(1-x2n)2*(1+x2n)2) = x*(2-x)(1-x)2
unconverting from generating functions, for positive n (since they both have an n = 0 term of 0),
- ∑ρ(n)k=0(3*n2k - (2 + n2k)*(-1)n2k + 2)4 = n + 1
by definition, all but the last iteration of the sum will have (-1) to an even power, so it may be unravelled to the trivial
- ∑ρ(n)-1k=0(n2k)2 + n2ρ(n) + 1 = n + 1
- a(0) = 0, a(1) = 1, a(n) = a(n-1)&a(n-2)^n
let b(n,k) = a(n)>>k&1
- b(n,k) = b(n-1,k)&b(n-2,k)^n>>k&1
from some cursory analysis,
- >>> print(tap(λ k: Y(λ f: λ t: len(t)-i if len(t)>3+(1<<k+1) and (i:=next(filter(λ i: t[i-3:i]==t[-3:],range((len(t)-3&~(~0<<k))+3,len(t),1<<k)),-1))>-1 else f(t+(len(t)>>k&1^(len(t) and t[-1])&(len(t)>1 and t[-2]),)))(()),range(12)))
the kth bit has period 2*4⌈k2⌉, and g.f. x2k*(1+x-(-1)k*x2k)-x2*(4⌈k2⌉+1)-(k&1 and x3*2k+x2k+2)(1-x3)*(1-x2*4⌈k2⌉) (that is to say, x2k*1+x+x2k*(1-x2k*(1+x2k*(1+x2)))1-x4*2k if k&1 else 1+x-x2k*(1+x2)1-x2*2k1-x3)
as such, we have
- gf(A182560)=λ x: ∑∞k=0((x4k*1+x-x4k*(1+x2)1-x2*4k + 2*x2*4k*1+x+x2*4k*(1-x2*4k*(1+x2*4k*(1+x2)))1-x8*4k)*4k)1-x3
the 0th bit's numerator is the only one whose count of nonzero coefficients in its numerator is 2 (thereafter it alternates between 4 and 6), so moving it out allows for the normalisation of the denominator by moving each other even-index bit to the preceding summand
- . . . . . .=λ x: x1-x2 + 2*∑∞k=0(x2*4k*(1+x+x2*4k*(1-x2*4k*(1+x2*4k*(1+x2)))) + 2*x4*4k*(1+x-x4*4k*(1+x2))1-x8*4k*4k)1-x3
. . . . . .=λ x: x1-x2 + 2*∑∞k=0(x2*4k*(1+x+x2*4k*(3+2*x-x2*4k*(1+3*x2*4k*(1+x2))))1-x8*4k*4k)1-x3
and so from the former one, we have
- A182560=λ n: ∑n.bit_length()-1k=0(2k*(λ m: m>=2k and bool(m>=2*2k or (m-1)%3 if k&1 and m<3*2k else m%3)(n%(2*4⌈k2⌉)))
and from the latter,
- A182560=λ n: n%2 + 2*∑⌊n.bit_length()2⌋-1k=0((λ m: m>=2*4k and (bool((m-1)%3) if m<4*4k else 1+2*bool(m%3) if m<6*4k else 3*bool(m%3)))(n%(8*4k))*4k)
notes
- ↑ It could also have k initialised at ⌊2l+~n/2⌋, but a floor to handle a single case seems like overkill.
- ↑ this last form is somewhat interesting
there is a slightly suspicious heuristic argument for the asymptotics of ∑nk=1(k>>ρ(k)) = A135013(n):- choose a random k from a sufficiently large range; in 12 of all cases, it is odd so will be multiplied by 1; in 14 of cases, it is congruent to 2 modulo 4 so will be multiplied by 12, etc.
- for all i >= 0, in 12i+1 of cases, it is congruent to 2i modulo 2i+1, and thus is divided by 2i
- so the average amount by which the kth summand will be multiplied is ∑∞i=0(12i+1*12i) = ∑∞i=0(122*i+1) = 11 - 142 = 23
- so substituting ∑nk=1(k>>ρ(k)) for ∑nk=1(k*23) returns n*(n+1)3
however, since its first differences grow linearly, though this is the average of the two bounds, n23 < a(n) ≤ n*(n+2)3
since A264596's last form from here is in terms of the difference between 3 times these partial sums and n2, it is the O(n) error term in this argument!
hypercube colouring sequences
faster A361870
My favourite sequence, of those I added to the OEIS.
- Array read by downward antidiagonals: A(n,k) is the number of nonequivalent 2-colorings of the cells of an n-dimensional hypercube with edges k cells long under action of symmetry.
I had implemented a few algorithms of varying degrees of efficiency, explained in dimensional INT enumerator (though I didn't know so much about MediaWiki formatting at that time, so it is not so nice as here).
However, I didn't then know how to represent conjugacy classes of actions or find their multiplicities, to compute Pólya enumeration terms' exponents for single representatives of them, so they were all much slower than is necessary. Maybe one day I will go back through that article, which was (at least ostensibly) intended to be didactic, but this one mainly only contains results, so I will put them here.
An action in the n-dimensional hypercube's group is a permutation of its axes and an orthogonal reflection of (reversal of order in) a subset of them, so there are n!*2n of them. Without the orthogonal reflections, the conjugacy classes of actions, in the group of permutations, are defined by the multiset of lengths in their cycle decompositions, given by the partitions of n, A000041(n). (I use Jerome Kelleher's accel_asc for this, though here it is denoted partitions. Herein, though they are multisets, for indexing purposes partitions are considered to be sorted by length.)
Within these dimension permutations, cycles of the same length are isomorphic if their numbers of axis reflections have the same parity modulo 2 (since they cancel each other out).
Let rle here return the tuple of run-lengths (not length-value pairs) of its input.
If, over each partition of n into cycles, you take the product of each of the run-lengths r plus 1 (the number of subsets each of them can have reflections in, from 0 to r inclusive), you obtain the number of conjugacy classes in the hypercube group, A000712(n). That is,
- A000712=gf-1(λ x: ∏∞m=1(1(1-xm)2))=λ n: ∑.p ∈ partitions(n)(∏.r ∈ rle(p)(r+1))
Let ∘. denote the Cartesian product itertools.product (APL-style).
For each conjugacy class representative, given by a combination of a cycle-partition p and a member r of this Cartesian product of reflecting subsets of each run-length, one can count the other members. Account for:
- the number of ways in which the dimensions can be allocated to the cycles, (n*p) (where *p unpacks p into the multinomial function),
- the product of the ways in which each length-k part in the partition, given its k elements, may form a cycle, (k-1)! (since each of the p! permutations may be cyclically permuted in p ways to form the same cycle), ∏.k ∈ p((k-1)!)
- the product of the ways in which the reflection-counts in r may be permuted amongst each of the multisets of cycles of corresponding length, ∏len(rle(p))i=0(rle(p)iri),
- the product of the number of ways within each cycle to allocate a number of orthogonal reflections of its parity, ∏.k ∈ p(∑⌊k2⌋i=0(k2*i)) = ∏.k ∈ p(2k-1) = 2n-len(p)
Also, divide by the ways in which cycles of equivalent length may be swapped, ∏.l ∈ rle(p)(l!)
This all simplifies to the final formula for the complete action count in terms of representative multiplicities
- n!*2n = ∑.p ∈ partitions(n)(∑.l ∈ ∘.(*map(λ l: range(l+1),r:=rle(p)))((n*p)*∏.k ∈ p((k-1)!)∏len(r)-1i=0(li!*(ri-li)!)*2n-len(p)))
(Note that interestingly, removing the 2n-len(p) causes it to evaluate (n+1)!, I would be interested in a proof or explanation for this.)
Recall the explanation by apg, of how to compute odd-k terms of A361870 in an exact form in terms of choose functions at facets of the Disdyakis polytope. From personal communication with Magma, given apg's encoding scheme, let a=λ n: (n+1)! and b=λ n: n!*2n. Given an n-bit encoding of a vertice type in the n-dimensional Disdyakis polytope in apg's scheme, its multiplicity is given by b(n) divided by the product, over each run-length of k 0s in the code, of b(k) if it's leading, and a(k) otherwise. That is,
- mul=λ n,c: b(n)∏.i,r ∈ enumerate(rle(map(λ i: c>>i&1,range(n))))(1 if r[0] else (a if i else b)(r[1]))
From which we have the formula A080253=λ n: ∑2n-1c=0(mul(n,c)). apg's explanation provides that (2*k+1)n=∑2n-1c=0(mul(n,c)*(kc.bit_count())), and we have that (2*k)n=∑2n-1c=0(c&1 and mul(n,c)*(kc.bit_count())).
Using this, I made a dimensional conjugator program (asymptotically many times faster than my first dimensional INT enumerator, due to iterating only over single instances of conjugacy class representatives), which may be expressed very simply (using the dronery library).
It can compute many more equations for rows of A361870, I have reached n=6 with it but only that for n=5 (in reduced branchless form) is given.
- penteract=λ k: (2k5+20*2k4*(1+k)2+5*2⌈k2⌉*k4+60*2k3*(1+k2)2+70*2⌈k22⌉*k3+130*2⌈k32⌉*k2+25*2⌈k42⌉*k+2⌈k52⌉+80*2k3*(2+k2)3+240*2k2*(k+1)*(2-k+k2)4+240*2⌈k2*(1+k2)4⌉*k+20*2⌈k24⌉*k3+180*2⌈⌈k22⌉*k2⌉*k2+180*2⌈⌈1+k22⌉*k22⌉*k+20*2⌈⌈k22⌉*k32⌉+60*2(⌈k44⌉)*k+60*2⌈⌈k42⌉*k2⌉+384*2k*(4+k4)5+160*2k2*(1+k)*(2+k2)6+160*2⌈k2⌉*k2*(2+k2)3+80*2⌈k22⌉*k*(2+k2)3+80*2⌈2*k+k36⌉*k2+320*2⌈k2*(2+k2)6⌉*k+80*2⌈k3*(2+k2)6⌉+240*2⌈k48⌉*k+240*2⌈⌈k44⌉*k2⌉+384*2⌈k*(4+k4)10⌉+160*2⌈k24⌉*k*(2+k2)3+160*2⌈2+k32⌉+⌈⌈k22⌉*k22⌉*k3)/3840
It seems also that A059344(n,l)=n!l!*(n-2*l)! also describes the coefficient of the term 2kn-1-l*(1+kl+1)2 in the edge-length-k formula.
under group products
I have some other A361870-like sequences to create, which (by the same method as my proof there) have the corollary of providing additional descriptions and asymptotic forms for various other sequences (to which they converge from above, the error ratio decreasing monotonically towards 1).
Consider the function of two nonnegative integers, A(n,k), that returns the number of c-colourings of an n-dimensional hypercube with edges k cells long, where two colourings are considered equivalent if they may be transformed into each other by a combination of permutation of axes and of n-1-hyperplanes within axes.
When c=2, it also equivalently enumerates functions; each cell is a boolean output, and each axis a k-valued input, hyperplane permutation corresponds with mapping of monadic functions to each input, and A(n,k) ~ 2knn!*k!n.
- . . . . . . A000616
. . . .(2,2,. . . 2, . . 2,. 2, . 2,2,2,
. . . . 1,2,. . . 3, . . 4,. 5, . 6,7,
A007139 1,2,. . . 6,. . 26,192,3014
. . . . 1,2, . . 22,111618,
. . . . 1,2,. . 402,
. . . . 1,2,
. . . . 1,)
- In A(1,k), all permutations are equivalent, so it is k+1, the number of bit_counts that a k-bit number may have.
- The generalisation of this to c colours is (k+c-1c-1).
- A(2,n)=A007139(n) ~ 2n22*n!2
- It is defined there as
- Number of unlabeled bicolored bipartite graphs on 2*n nodes having n nodes of each color with no edges between nodes of the same color and allowing the color classes to be interchanged.
- (where "colour classes" refer to those of the nodes, not the edges, the interchanging corresponds with axis transposition, and graphs are considered transitive to node reordering, which provides the hyperplane (row/column) permutation)
When c=k, meanwhile, it describes functions from range(k)n to range(k), and A(n,k) ~ kknn!*k!n.
- . . . . . . A000616, . A001327,
. . . .(0,1,. . . 2, . . . . 3,. . . 4, . . . . . . 5,. 6, . 7,8,
A088218 1,1,. . . 3,. . . . 10, . . 35, . . . . . 126,462,1716,
A001328 1,1,. . . 6, . . . 438,3962646,10417184196975,
. . . . 1,1, . . 22,5893028544,
. . . . 1,1,. . 402,
. . . . 1,1,
. . . . 1,)
- A(0,k) is the number of k-colourings of a 0-dimensional hypercube, which has k0 cells, we say A(0,0)=0 because 000=01=0,[c 1] thereafter it abides by the arithmetic progression for the different reason that kk0=k1=k.
- A(n,3)=A001327(n) ~ 33nn!*6n
- It is defined there as
- Number of equivalence classes of 3-valued Post functions of n variables under action of semi-direct product of symmetric groups Sn and S(n,3).
- Equivalently, "Number of 3-colourings of an n-dimensional hypercube with edge length 3 under action of permutation of axes and exchanging of hyperplanes along axes"
- Note that this also provides the extension backwards to A001327(0)=3.
- A(1,n)=A088218(n)
- Its definition
- Total number of leaves in all rooted ordered trees with n edges.
- is equivalently "Number of n-colourings of an n-cell list, where elements may be permuted." This may be seen most clearly from the equivalent definition provided by César Eliud Lozada,
- Number of terms in the expansion of (x1+x2+...+xn)n.
- Note that similarly to the previous sequence's A(1,n), in this one states may be considered unordered multisets; an equivalence class of states is given by a sorted set of partitions of range(n) into n (potentially empty) sections, so it is exactly (2*n-1n), which is why it describes such an unrelated-seeming thing.
- The statement that A088218(n) ~ nnn! is false, since it doesn't converge (because there are conjugacy classes of actions with multiplicities outgrowing their division of the number of cycles from the identity action).
- A(2,n)=A001328(n) ~ nn22*n!2
- Its definition
I found these with my dronery library, and the Python one-liner
- permutatenumerator=λ n,k,colour=False: (2**k if not colour and k<1 else sum(starmap(λ i,j: (λ f: (λ p: (λ d: (k if colour else 2)**(sum(map(λ c: 1 if p==1 else max(filter(λ f: all(map(λ i: d[(p//f+i)%p][c]==d[i%p][c],range(p))),(1,)+factorise(p))),range(k**n)))//p))(tuple(expumulate(f,p-1)(tuple(range(k**n))))))((λ g: g(g))(λ g: λ i,t: i if i and t==tuple(range(k**n)) else g(g)(i+1,f(t)))(0,tuple(range(k**n)))))(λ t: tap(λ c: t[sum(starmap(λ o,p: permutation(j[o])[c//k**o%k]*k**p,enumerate(extend(permutation(i),n))))],range(k**n))),product(range(fact(n)),product(range(fact(k)),repeat=n))))//(fact(n)*fact(k)**n)) if n else k if colour else 2
As far as I can see, there are at present no sequences considering equivalence classes of functions under sets of even permutations (alternating groups) of either axes or hyperplanes.
notes
- ↑ In combinatorics, the convention that 00=1 is used because (though it is a singularity and converges to a different value depending on the direction from which it is approached) this way the general rule n0=1 is conserved (which breaks the fewest things :-)
permutation inequalities
- this since became an OEISwiki article
I had the idea for a new and highly whimsical sequence.
- Write n in binary, and replace 0 with > and 1 with <,
- put these symbols in between the places of a length-(k:=n.bit_length()+1) list, then
- a(n) is the number of permutations of range(k) such that these are satisfied.
Again using my dronery library, this may be implemented trivially with
- inequalities=λ n: sum(map(λ p: all(tarmap(λ i,p: __gt__(*p)==n>>i&1,enumerate(pairwise(permutation(p)[:n.bit_length()+1])))),range(fact(n.bit_length()+1))))
Trivially, it abides by the identities a(2n-1)=1, a(2n-2)=n and a(2n)=n+1.
As well as this form, it may be computed more efficiently with a recurrence relation. Instead of counting the total number of permutations satisfying it, count the permutations ending in each integer. For each number i in which the length-n.bit_length() permutations may end, add 1 to each number >=i in the length-n.bit_length()-1 case. If n is odd, the number ending in i is the sum up to i in the preceding iteration, otherwise the sum of terms after it. This may be implemented (with a few annoying offsets) as
- inequalities=λ n: sum(reduce(λ r,k: tap(λ i: sum(r[:i] if n>>k&1 else r[i:]),range(k+2)),range(n.bit_length()),(1,0)))
Plotting shows what at first appears to be chaotic behaviour, with minima and maxima at about the same proportions of the widths across each segment.
Consider the sequence "b(n) is the number of ways to partition a set of n.bit_length() elements into subsets, of lengths equal to those of the runs in n's binary expansion," given by the multinomial (in dronery)
- λ n: (n.bit_length()*map(λ i: i[1],rle(decompose(n))))
b(n) provides the upper bound a(n) ≤ b(n) (with equality iff n is of the form 2i-2j (with i>=j), a member of A023758, since one must select a single element for the change of inequality direction, and due to the sets on either side being completely ordered, only the selection between them matters, a(2i-2j)=(ij)).
Note that lim infn->∞(a(n)b(n)) = 0, but lim infn->∞(log(a(n))log(b(n))) = 1, since each new record minimum of a(n)b(n) occurs at n = ⌊2k+13⌋ = A000975(k), where b(n) = k! but a(n) = A000111(k+1) (the Euler up-down numbers).
However, the convergence of the lim infs to the lim sups is very slow. By using the form A000111(n) ~ 2n+2*n!πn+1 and Stirling's approximation for the factorial, and removing all constant offsets, one obtains that infm≥⌊2k+13⌋(log(a(m))log(b(m))) ~ 1 - 2*log(2π)*k2*k*(log(k)-1)+log(2*π*k) ~ 1 - log(π2)log(k), so infm≥n(log(a(m))log(b(m))) ~ 1 - log(π2)log(log2(n)) is a better approximation.[perm 1]
Plotting a(n) with respect to b(n) (in a log-log plot) and zooming out will, in the limiting case, cause it to appear as an infinitesimally thin line, however if you do it with respect to ∏.l ∈ map(λ i: i[1],rle(decompose(n)))(l!) (ie. the denominator of the fraction form of b(n)'s choose) instead, each bit-length's section's "image" is reflected left-to-right. The sections' minima eventually overlap with their preceders' maxima, beginning at 218<=n<219.
- for n in range(18): r=range(1<<n,1<<n+1);plot.scatter(tap(λ n: log(reduce(lambda r,i: r*fact(i[1]),rle(decompose(n)),1)),r),tap(λ n: log(inequalities(n)),r))
the inspiration for this was the 1995 British Maths Olympiad Round 1, question 5
- The seven dwarfs walk to work each morning in single file. As they go, they sing their famous song, “High-low-high-low, it’s off to work we go...”. Each day they line up so that no three successive dwarfs are either increasing or decreasing in height. Thus, the line-up must go up-down-up-down-... or down-up-down-up-... . If they all have different heights, for how many days they go to work like this if they insist on using a different order each day?
- What if Snow White always came along too?
The n-dwarf case is given by 2*a(⌊2n+13⌋). (In fact, this method of computation is the intended means by which the problem would be solved by hand, I think.)
notes
- ↑ Given a function f(n), we call a function, h(n), a "better" approximation than another, g(n), if limn->∞(f(n)-h(n)f(n)-g(n))=0.
integral form
If you have a list of (l:=n.bit_length()+1) distinct elements with n's inequalities upon it, there is a a(n)l! chance that it will be satisfied. Since choosing l independent uniform random real numbers between 0 and 1 has probability 0 of any two being equal, this can be equivalently defined in terms of them.
For the ith number, one can define a function fi, as the probability of the function's satisfaction given its value, then we have the recursive form
- f0=λ x: 1,
- fi+1=λ x: (∫x1 if n>>i&1 else ∫0x)(fi),
- a(n) = (l+1)! * ∫01(fl).
By unravelling each of these steps and permuting it a bit, we get the much cooler algorithm,
- begin with the function λ x: 1,
- for each bit in n (little-endian),
- integrate the function,
- if the current bit is 0,
- subtract this integral from itself evaluated at x=1 to get the function's new value
- else,
- set the function to its integral
- integrate, evaluate at x=1, and multiply the result by (n.bit_length()+1)!
ie.
- inequalities=λ n: (n.bit_length()+1)!*reduce(λ r,k: ∫(r) if n>>k&1 else sum(i:=∫(r))-i,range(n.bit_length()),λ x: 1)(1)
implementable in dronery as
- inequalities=λ n: int(fact(n.bit_length()+1)*sum(reduce(λ r,k: r.inte() if n>>k&1 else sum(i:=r.inte())-i,range(n.bit_length()),polynomial(1)).inte()))
g.f. analyses
Both subsections of this are together due to their similar nature, they both concern series of linear-recurrent sequences (the former in factorisations of fixed integers into increasingly long multisets, the latter in partitions of fixed integers into parts of increasingly many colours), whose g.f.'s both seem to have interesting patterns.
ordered factorisations and Dirichlet inverses
For this section only,
- | means "divides," not bitwise OR. (ie. (d|n) = (n%d==0))
- Using the conventions of the Wikipedia article , let f*g be λ n: ∑.d|n(f(d)*g(nd)), the Dirichlet convolution of f and g,
- and fn likewise be dgf-1(λ x: dgf(f)(x)n).
Note that dgf(λ n: 1)=ζ, so (λ n: 1)k is dgf-1(λ x: ζ(x)k). These are also denoted τk(n), the number of ordered k-factorisations of n.
Let Ω(n) denote A001222(n), the number of prime divisors of n with multiplicity,[dgf 1] and ω(n) denote A001221(n), the number without
Fix an integer n >= 1, then define the function fn=λ k: τk(n). It is a polynomial function over k, with degree Ω(n). For a fixed k, the function is multiplicative over n, and is defined as being (k+e-1e) for each prime power n = pe, so fn is given equivalently by λ k: ∏.d ∈ ℙ(k+vald(n)-1vald(n)).
fn(k)=fm(k) for each n,m with the same multiset of multiplicities in their prime factorisations.
For a fixed x, consider gf(fn) as a fraction of polynomials. Its denominator has degree Ω(n)+1 and its numerator has degree ω(n) and sum A008480(n).[dgf 2] Its numerator's coefficient
- of x0 is 1 if n==1 else 0 (since 1 is the only number expressible as an empty product),
- of x1 is 0 if n==1 else 1 (since numbers' 1-factorisations are only themselves),
- of x2 is A281116(n),[dgf 3]
- of x3 is nonzero for members of A350353(n),[dgf 4] yet is not in the OEIS.[dgf 5]
- of xp (for p>=1) first becomes 1 for n=(1,2,6,30,180,900,5400,27000,162000,810000...)[p]. From a search under the constraint of each term being a multiple of the preceding (since it cares only for prime signature, so is a strict subset of A025487), this appears to be given by the generating function (1-4*x)*(1+6*x)1-30*x2.
Also, evaluating its numerator polynomial on x=2 returns absolute values of A114005, whose signs are given by the denominator, leading to the equivalent definition,
- A114005(n) is -1 times the unique analytic continuation of ∑∞k=0(τk(n)*2k) given by its generating function.[dgf 6]
In general, evaluating the generating function for a fixed n on a given value of x gives the nth term of the Dirichlet inverse of the sequence 1-x,-x,-x,-x,..., providing that A114005 is that of 1,2,2,2,....
Fix an x, and consider Fn = gf(fn), and Gn = λ x: (λ n: gf(fn)(x))-1(n) (the Dirichlet inverse of the sequence of generating functions, which we are stating equals -x if n==1 else 1-x)
There is a recursive formula for the Dirichlet inverse of an arbitrary function f, as
- f-1(n) = -∑.d|n
d<n(f(nd)*f-1(d))f(1)[pr 1]
So, fix an integer n and number x, then for our f,
- Fn(x) = -∑.d|n
d<n(Fd(x)*Gnd(x))G1(x)
since we iterate over proper divisors d, nd > 1, so under our assumption, Gnd(x) = -x. Substituting in the conjectured values for the inverse, we have
- Fn(x) = -∑.d|n
d<n(Fd(x)*-x)1-x
. . . . . = x*∑.d|n
d<n(Fd(x))1-x
To prove this, since it is a rational function of x (with only a singularity of multiplicity Ω(n) at x=1), we need only prove that the generating function identity it forms is satisfied for the coefficient of xk, for all k.
Where here (Fn)k refers to the kth term of the series representation,
- (Fn)k = (λ x: -∑.d|n
d<n(Fd(x)*-x)1-x)k
which becomes
- fn(k) = ∑.d|n
d<n(∑k-1i=0(fd(i)))
Written back in terms of the standard function,
- τk(n) = ∑.d|n
d<n(∑k-1i=0(τi(d)))
. . . = ∑k-1i=0(∑.d|n
d<n(τi(d)))
. . . = τ1(n) + ∑k-1i=1(∑.d|n
d<n(τi(d)))
then we have the inductive case
- τk(n) = τj(n)+∑k-1i=j(∑.d|n
d<n(τi(d)))
. . . = ∑.d|n(τj(d))+∑k-1i=j+1(∑.d|n
d<n(τi(d)))
. . . = τj+1(d)+∑k-1i=j+1(∑.d|n
d<n(τi(d)))
so the characterisation of the generating function is due to the right side of this simplifying to τk(n)
notes
- ↑ where 𝕄 is the set of all finite multisets, this unravels to
- factorisations=λ n: {m ∈ 𝕄: ∧k ∈ m(k ∈ ℤ and k>1) and ∏.k ∈ m(k) = n}
- f-1(n) = -∑.m ∈ factorisations(n)(∏.k ∈ m(f(k)f(1)))f(1)
From coefficient-extraction after convolution, we have the explicit form for each of the series of g.f.'s
- gf(λ k: τk(n))=λ x: ∑ω(n)k=0(∑ki=0((-1)k-i*τi(n)*(Ω(n)+1k-i))*xk)(1-x)Ω(n)+1
leading to
- A114005=λ n: (-1)Ω(n)*∑ω(n)k=0(∑ki=0((-1)k-i*τi(n)*(Ω(n)+1k-i))*2k)
and as a corollary, for A050328, the number of ordered factorisations of n into squarefree numbers > 1 (in terms of which A114005 is defined, but also working the other way around), we have that for n > 1,
- A050328=λ n: ∑ω(n)k=0(∑ki=0((-1)k-i*τi(n)*(Ω(n)+1k-i))*2k)2
providing the first primitive-recursive form (the other existing ones being defined in terms of recursive self-calls).
notes
- ↑ (compare with the not-necessarily-prime version, A169594, ∑nd=1(vald(n)))
- ↑ Number of ordered prime factorisations of n
- ↑ Number of factorisations of n into coprime parts, except a(1)=0
- ↑ Numbers whose multiset of prime factors has a permutation that is not weakly alternating
- ↑ The first few nonzero terms are ((30,1),(36,1),(42,1),(60,4),(66,1),(70,1),(72,3),(78,1),(84,4),(90,4),(100,1),(102,1),(105,1),(108,3),(110,1),(114,1),(120,9),(126,4),(130,1),(132,4),(138,1),(140,4),(144,6),(150,4),(154,1),(156,4),(165,1),(168,9),(170,1),(174,1),(180,15),(182,1),(186,1),(190,1),(195,1),(196,1),(198,4),(200,3),(204,4),(210,11),(216,9),(220,4),(222,1),(225,1),(228,4),(230,1),(231,1),(234,4),(238,1),(240,16),(246,1),(252,15),(255,1)).
- ↑ It is defined there currently as the first column of A114004, which is the matrix inverse of the triangle A114002 (for which the kth column is the expansion of xk*(1+xk+1)1-xk+1). Per Ilya Gutkovskiy's comment, it is equivalently defined a(1) = 1; a(n) = -2*∑.d ∈ divisors(n)[:-1](a(d)).
partition colourings
The function a(n,k), that returns the number of ways to colour each of the integer partitionings of its input with k colours (up to permutation of parts), has the form gf-1(λ x: ∏∞i=1(11-xi)k)(n). It has OEIS sequence A144064, and is similarly a degree-n polynomial in k for each n (since the degree is maximised by the partitioning into n parts, which has ). These polynomials are highly factorisable into linear parts, and asymptotically knn!, here are their factorised forms (over the integers)
1 k k*(3+k)/2 k*(1+k)*( 8+k)/6 k*(1+k)*( 3+k)*( 14+k)/24 k*(3+k)*( 6+k)*( 8+21*k+k²)/120 k*(1+k)*(10+k)*(144+181*k+34*k²+k³)/720 k*(2+k)*( 8+k)*( 3+k)*( 120+529*k+50*k²+k³)/5040 k*(1+k)*( 3+k)*( 6+k)*(4200+9994*k+1571*k²+74*k³+k⁴)/40320 k*(1+k)*( 4+k)*( 3+k)*( 14+k)*(26+k)*(120+491*k+60*k²+k³)/362880
Note that when the entire polynomial is made a fraction, the denominator is n! but the coefficient of k1 is A038048(n)=(n-1)!*σ(n). Taking their generating functions yields
1/(1-x)
x/(1-x)²
x*(2-x)/(1-x)³
x*(3-2*x)/(1-x)⁴
x*(5-5*x+x²)/(1-x)⁵
x*(7-6*x-3*x²+4*x³-x⁴)/(1-x)⁶
x*(11-12*x-3*x²+7*x³-2*x⁴)/(1-x)⁷
x*(15-10*x-31*x²+48*x³-28*x⁴+8*x⁵-x⁶)/(1-x)⁸
x*(22-13*x-63*x²+102*x³-63*x⁴+18*x⁵-2*x⁶)/(1-x)⁹
x*(30-171*x²+290*x³-220*x⁴+90*x⁵-20*x⁶+2*x⁷)/(1-x)¹⁰Note that the first coefficient of each of these generating function numerators (within the large factor) is the first nonzero element of each of the sequences, the number of partitions of n (A000041(n)). The next terms and lengths/degrees don't have any such equivalent descriptions in OEIS sequences, but note thaat the numerators always have sum 1 (since in the nth g.f., each numerator term with exponent p represents a function of the form λ k: (k+n-pn), which is similarly Θ(knn!)) As a triangle of expansions, this has sequence A078521 (albeit, since that one considers it for positive instead of negative powers of (1-xi), chequerboard-signed there),
(1, 0, 1, 0, 3, 1, 0, 8, 9, 1, 0, 42, 59, 18, 1, 0, 144, 450, 215, 30, 1, 0, 1440, 3394, 2475, 565, 45, 1, 0, 5760, 30912, 28294, 9345, 1225, 63, 1, 0, 75600, 293292, 340116, 147889, 27720, 2338, 84, 1, 0,524160,3032208,4335596,2341332,579369,69552,4074,108,1)
The polynomials seem chaotic (given that the number of terms in their factorisations begins (1,1,2,3,4,4,4,5,5,7,3,6,4,6,...)), however if they are observed by diagonals instead of columns, patterns emerge. Let p(n) be the nth polynomial times n!, then p(n)n=1 and p(n)n-1=A045943(n+1). More generally, the n diagonal (with the ith term given by a(i,)) is linear-recurrent and its coefficients are of degree 2*n. Their denominators begin (1,2,24,16,5760,3840,2903040,...), which coincide with A055535 for the first five terms, and have large gcds thereafter (which may not be a coincidence, being that it has an (unfortunately now broken) JSTOR link to the paper An Asymptotic Formula for (1+1/x)x Based on the Partition Function).
1 (-3*x+3*x²)/2 (-98*x+201*x²-130*x³+27*x⁴)/24 (-480*x+1174*x²-1073*x³+473*x⁴-103*x⁵+9*x⁶)/16 (-2165712*x+5836820*x²-6236100*x³+3525215*x⁴-1166088*x⁵+230030*x⁶-25380*x⁷+1215*x⁸)/5760 (-25459200*x+73664400*x²-87234612*x³+56894120*x⁴-22983255*x⁵+6068987*x⁶-1063038*x⁷+120410*x⁸-8055*x⁹+243*x¹⁰)/3840 (-434248346880*x+1330115736096*x²-1703488654504*x³+1230453441252*x⁴-566580266574*x⁵+177226717689*x⁶-38936756154*x⁷+6077721321*x⁸-666687266*x⁹+49263795*x¹⁰-2214702*x¹¹+45927*x¹²)/2903040
which curiously also factorise,
1x*(1-x)/2 x*(1-x)*(2-x)*(49-27*x)/24 x*(1-x)*(2-x)*(-240+227*x-76*x²+9*x³)/16 x*(1-x)*(2-x)*(4-x)*(-270714+255853*x-94895*x²+16875*x³-1215*x⁴)/5760 x*(1-x)*(2-x)*(4-x)*(5-x)*(-636480+600474*x-230253*x²+46835*x³-5139*x⁴+243*x⁵)/3840
x*(1-x)*(2-x)*(4-x)*(5-x)*(-10856208672+12083286492*x-5725952080*x²+1536840921*x³-256984406*x⁴+27050436*x⁵-1663578*x⁶+45927*x⁷)/2903040
Does the number of linear factors increase monotonically with respect to n, and do factors present in one polynomial appear in all thereafter?
Multiplying the nth diagonal's polynomial by n!3 seems to make each coefficient integer. Does this always hold, and is there a smaller monotonically-increasing sequence whose nth term is always divisible by the nth denominator?
small trivia
(I have too little to say about each of these to make their own sections, or they were found by straightforward methods, without much creativity, but might warrant OEIS inclusion, I am putting here lest I forget)
- A122155=λ n: n^(n&n-1 and (1<<n.bit_length()-1)-2*(n&-n))
- Due to Hardy and Ramanujan's approximation for the partition numbers, A198194(n) ~ 6*(W-1(-πsqrt(√1728*n))π)2
- Due to the form in the Wikipedia page , A094941=λ n: (1+√π+(1-√π)*(-1)n)*(n-12)!*2n-1√π
characterisations of sequences by matrix inversions
To describe these more elegantly, let mat=λ f,d=n+1: tap(λ y: tap(λ x: f(x,y),range(d)),range(d)) (square, since we are concerned with inversion) and vec=λ f,d=n+1: tap(f,range(d)), and let * and m-1 refer to matrix multiplication and inversion. (Vectors behave as though each element is nested for the purposes of matrix multiplication, but are not for the purposes of indexing methods.) The reason for d defaulting to n+1 is to the fact that a degree-n polynomial is defined by n+1 points.
- A131689=λ n: mat(λ x,y: (xy),n+1)-1*vec(λ y: yn,n+1)
- A173018=λ n: mat(λ x,y: (x+yn),n+1)-1*vec(λ y: yn,n+1)
- A048994=λ n: n!*mat(λ x,y: xy,n+1)-1*vec(λ y: (yn),n+1)
. . . .=λ n: mat(λ x,y: xyn!,n+1)-1*vec(λ y: (yn),n+1) - The triangular sequence with rows given by
- mat(λ x,y: (x-y)n,n+1)-1*vec(λ y: (yn),n+1)
- seems to have a(2*n+1,2*n+1)=0 for all integers n, and it appears n!3*a(n,k) is always integer, but not with n!2.
- see also the page that grew out of this, a nicer hypergeometric formulation
- For all n,m ∈ ℕ,
- gf(λ k: (kn)*(km))=λ x: ∑n+mk=0((nk-m)*(mk-n)*xk)(1-x)n+m+1
- since gf-1(λ x: xo(1-x)p+1)=λ n: (n-o+pp), we then have the identity
- (kn)*(km) = ∑n+mo=0((no-m)*(mo-n)*(k-o+n+mn+m))
- by reversing the iteration order (substituting o := n+m-o and using (nn-o)=(no)) we have
- (kn)*(km) = ∑n+mo=0((no)*(mo)*(k+on+m))
- and a cool identity from obtaining the numerator by convolving the series with the denominator
- ∑∞i=0((-1)k-i*(in)*(im)*(n+m+1k-i)) = (nk-m)*(mk-n)
- Setting n = m, this provides that the nth row of A008459 (Pascal's triangle with entries squared) is the expansion of the numerator of gf(λ k: (kn)2) (over the nonzero terms, for each n its k represents the xn+k coefficient), where the denominator is (1-x)2*n+1, providing the form
- With offsets to each term, for all n,m,o,p ∈ ℕ,
- gf(λ k: (k+on)*(k+pm))=λ x: ∑n+m-max(o,p)k=max(m-p,n-o)((n+p-ok+p-m)*(m+o-pk+o-n)*xk)(1-x)n+m+1
- in hypergeometrics,
- (on)*(pm)*3F2(1,1+o,1+p1+o-n,1+p-m;x)=(n+p-op-m)*(m+o-po-n)*3F2(1,o-n-m,p-m-n1+o-n,1+p-m;x)(1-x)n+m+1
- which can be rewritten (with 2G2(a,bc,d;x)=∑∞n=0((a+1)n*(b+1)n(c+1)n*(d+1)n*xn)) as
- 2G2(o,pn,m;x)=(o-m)n*(p-n)mon*pm*2G2(n+m+~o,n+m+~pn,m;x)(1-x)o-n+p-m+1
- and where m=1, it becomes Euler's third hypergeometric transformation
- gf(λ k: (k+nn)3)=λ x: ∑2*nk=0(A181544(n,k)*xk)(1-x)3*n+1. From the same method, we have that
- A181544=λ n,k: ∑ki=0((-1)i*(3*n+1i)*(k-i+nn)3)
- In general, we have a hypergeometric expression for the numerator,
- gf(λ k: (k+nn)p)=λ x: ∑(p-1)*nk=0(p+1Fp(*p*(-k,),-1-p*n*p*(-k-n,);1)*xk)(1-x)p*n+1
assorted g.f.'s
(the sequences here either came up in things discussed above, in simple experimentation or in OEIS reading/perusal)
- In general, d+e*x1-2*b*x+c = d+e*x(1-(r0:=b+√b2-c)*x)*(1-(r1:=b-√b2-c)*x) = d*r0-e1-r0*x + e-d*r11-r1*xr0-r1:=2*√b2-c
- since r0*r1=c, [xn] is √cn*((d*r0-e)*(r0/√c)n + (e-d*r1)*(√c/r0)n)r0-r1 = √cn*(d*cosh(log(√cr0)*n)+e-d*b√b2-c*sinh(log(√cr0)*n)) = √cn*(d*cosh(acosh(b√c)*n)+e-d*b√b2-c*sinh(acosh(b√c)*n))
- The denominator of the generating function of a degree-n polynomial is (1-x)n+1. As noted by Wolfdieter Lang, the nth row of triangle of Eulerian numbers A123125 is equivalently the numerator of the generating function for the sequence of nth powers (ie. given by λ m: mn).
- due to the Eulerian triangle being symmetrical, its even rows have equal sums at odd and even indexes, so are divisible by 1+x (since dividing by it takes the alternating sum).
- A171692=λ n,k: (-1)k*∑ki=0((-1)i*∑ij=0((-1)j*(i-j)2*n*(2*n+1j)))
. . . .=λ n,k: (-1)k*∑kj=0((-1)j*j2*n*∑k-ji=0(2*n+1i))
- and for n ≥ 1,
- gf(λ k: k2*n)=λ x: (1+x)*∑2*n-1k=0(A171692(n,k)*xk)(1-x)2*n+1
- gf(A057145:=λ n,k: n>=2 and k>=1 and (n-2)*k2 - (n-4)*k2)=λ x,y: x2*y*(1-x-y+2*x*y)(1-x)2*(1-y)3
- egf(A057145)=λ x,y: y*ey*(x*y*(1+ex)2 - x - (1-y)*(1-ex))
- The upper bound for the number of Kobon triangles (A006066) has
- dgf(A038608)=λ x: (42x - 1)*ζ(x-1)
- Its Ramanujan sum is 0
- dgf(A347438)=λ x: ∏∞n=2(11-n-2*x)
- dgf(A349906)=λ x: ∏∞n=2(11-(2*n)-x)
- For the first sequence I ever submitted to the OEIS, regarding king placements
- dgf(A357723)=λ x: 4*(1-2-x)*ζ(x)+12*2-x*ζ(x-1)-(5+8*2-x)*ζ(x-2)+ζ(x-4)8
- Its Ramanujan sum is 38920160 (what could this mean)
- egf(A061084)=λ x: (1-√5)*e(-1-√5)*x2+(1+√5)*e(-1+√5)*x22
. . . . . . =λ x: (cosh(√5*x2)+√5*sinh(√5*x2))*e-x2
. . . . . . =λ x: 2*sinh(√5*x2 + log(1+√52))*e-x2 - Where g.f.'s of two-valued functions satisfy f(x,y)=∑∞n=0(∑nk=0(a(n,k)*xn*yk)),
- f=gf(A001263)(x,y) satisfies f=(f+1)*x*(f+y)
- f=gf(A103371)(x,y) satisfies f*(f+1)*((x*(y-1))2-2*x*(y+1)+1) = x*y
- egf(A103371)=λ x,y: ∑∞k=0((x*y)k*1F1(2+k1;x)k!)
. . . . . . =λ x,y: ∑∞d=0(xd*(1+d)*1F2(d+21,2;x*y)d!)
- egf(A103371)=λ x,y: ∑∞k=0((x*y)k*1F1(2+k1;x)k!)
- egf(A001318)=λ x: x*(e-x+3*ex*(2+x))+sinh(x)8
- A145919=λ n: (n-1)*(n-2) if n%3 else n*(3-n)6
. . . .=λ n: (λ n: 3*n*(1-n)2,λ n: n*(3*n-1)2,λ n: n*(3*n+1)2)[n%3](⌊n3⌋)
. . . .=λ n: (1-3*n+n2)*(1-4*cos(2*π*n3))+318
- egf(A145919)=λ x: ex*(2 - x + x22) + e-x/2*2*(x2*cos(√3*x2 + π3) - 2*x*sin(√3*x2 + π6) - cos(√3*x2))9
- A003417=λ n: 2 if n==0 else 2*4+n+(1-2*n)*sin(π*4*n+16)9
- A145920=λ n: (6*n+(-1)n+344)
- egf(A145920)=λ x: cosh(x)*x*(5+69*x+90*x2+27*x3) + sinh(x)*(3*x-1)*(5+20*x+45*x2+9*x3)128
- (n4) = (6*int((1-3*n+n2)*(1-4*cos(2*π*n3))18) - 1)2-124 #pentagonal number of first or second kind
. . = ((2*n-3)2-54)2-124 #composition of quadratics - A006446(n) = 6*n*(n+7)+52+(2-6*n)*cos(2*π*n3)-2*√3*(n-3)*sin(2*π*n3)54
- Gary Detlefs' comment on A051403 on June 23, 2010 says A051403(n) = (n2 + 1)*A003422(n+1); with Djurdje Cvijovic and Aleksandar Petojevic's egf(A003422)=λ x: (Ei(1)-Ei(1-x))*ex-1, one has egf(A051403)=λ x: 1 - x22(1-x)2+(1+x/2)*(Ei(1)-Ei(1-x))*ex-1, which means we also have A051403(n) = A003422(n) + n*A003422(n-1) + n!*(3+n) -[n=0]2
Roger L. Bagula's things
- For n>=1, the nth row of A142158 is the numerator of the g.f. of λ k: (k+n)n. (I found this when making a generating-function-finding program, and seeming to have miscalibrated it somewhat.) To abide by the convention of 00=1, it would be more consistent if it were triangular and began (1,),(1,0),....
- A142158=λ n,k: ∑ki=0((-1)i*(n+1i)*(k-i+n)n)
- A178658=λ n,k: (λ x: gf(λ k: (n+3*k3*k)*(n+3*k3*k+1)n+3*k)(x)*(1-x)2*n+1)k
. . . .=λ n,k: (λ x: 6F5(n3,n+13,n+13,n+23,n+23,n+3313,23,23,1,43;x)*(1-x)2*n-1)k
. . . .=λ n,k: ∑ki=0((-1)k-i*(2*n+1k-i)*(n+3*i3*i)*(n+3*i3*i+1)n+3*i)
. . . .=λ n,k: (-1)k*(2*n-1k)*7F6(-k,n3,n+13,n+13,n+23,n+23,n+332*n-k,13,23,23,1,43;1) - A165883=λ n,k: ∑kj=0((-1)k-j*(2*n+3k-j)*∑ji=0((2*i+1)n*(j-i)n+1))
- A004306=λ n: (1,1,2,6)[n] if n<4 else 2*(1+F(n+1)+2*F(n)+3*F(n-1)) where F = A000073, the Tribonacci numbers
- gf(λ k: A059259(n,k))=λ y: (1+y)n+1-(-y)n+11+2*y
- gf(λ k: A220074(n,k))=λ y: (1-y)n+1-yn+11-2*y
- see my StackExchange answer for the context in which these arose
planar tiling coordination sequences
of the 11 uniform planar tilings,
- A008576=λ n: 2*4*n + sin(2*π*n/3)√33 if n else 1
- egf(A008576)=λ x: 1 + 2*4*x*ex + e-x/2*sin(√3*x2)√33
- A250122=λ n: (1,4)[n] if n<2 else 9*n+(n-8)*cos(π*n/2)+3*sin(π*n/2)4 if n else 1
- A219529=λ n: 2*8*n - sin(2*π*n/3)√33 if n else 1
- egf(A219529)=λ x: 1 + 16*x*ex - 2*e-x/2*sin(√3*x/2)√33
- A250120=λ n: 2*12*n+sqrt(1 + 2√5)*sin(4*π*n5)-sqrt(1 - 2√5)*sin(2*π*n5)5 if n else 1
note also there is a list of those up to 6-uniform
coordination sequence of the truncated order-7 triangular tiling (as used in HyperRogue!)
- beginning at a heptagon:
- A290398=λ n: 7√78*(sqrt(√13+1)*(3+√13)*sinh(acosh(1+√134)*(n-2)+acosh(√13+34))
. . . . . . . . . +sqrt(√13-1)*(3-√13)*sin (acos (1+√134)*(n-2)+acos (√13-34))) if n else 1
- A290398=λ n: 7√78*(sqrt(√13+1)*(3+√13)*sinh(acosh(1+√134)*(n-2)+acosh(√13+34))
- beginning at a hexagon:
- λ n: √6√13*(sqrt(√13+1)*(4+√13)*sinh(acosh(1+√134)*(n-2)+acosh(√13+34))
. . . . . +sqrt(√13-1)*(4-√13)*sin (acos (1+√134)*(n-2)+acos (√13-34))) if n else 1
- λ n: √6√13*(sqrt(√13+1)*(4+√13)*sinh(acosh(1+√134)*(n-2)+acosh(√13+34))
see also the wiki page there, with the partial sums also
- gf(A356836)=λ x: (1+x)³(1-x)*(1-8*x+x²)
- A356836=λ n: 2*5*cosh(n*acosh(4))-23 if n else 1
- similarly,
- A082398=λ n: 0 if n==2 else 1 + 2*(n-1)*sinh((n-2)*acosh(32))√5
periodic characteristic functions
- egf(A166486)=λ x: cosh(x)-cos(x)2 + sinh(x) and Leonid Bedratyuk's definition, A166486=λ n: 3-cos(π*n)4 - cos(π*n2)2, factorises to sin(π*n4)2*(2+cos(π*n2)).
- A168181=λ n: (8+9*cos(π*n4)+4*cos(π*n2)+cos(3*π*n4))*sin(π*n8)22
- egf(A168181=λ x: sinh(x) + 3*cosh(x)-cos(x)4 - cosh(x√2)*cos(x√2)2
- Due to 1-x5=(1-x)*(1+x+x2+x3+x4)=(1-x)*(1 + 1-√5-i*sqrt(10+2*√5)4*x)*(1 + 1-√5+i*sqrt(10+2*√5)4*x)*(1 + 1+√5-i*sqrt(10-2*√5)4*x)*(1 + 1+√5+i*sqrt(10-2*√5)4*x) (which is not only solvable with the quartic formula, but also (because 5 is a Fermat prime, making it constructible) one in terms of sqrts), there is
- Similarly,
- egf(A253513)=λ x: cos(x)+cosh(x)2 + cos(x√2)*cosh(x√2)2
- which provides the reduction from
- a(n) = sin(sin(π*n+12)2*π*n+24)2 + sin(π*n+12)24 + sin(π*n+12)4
- to
- .cos(π*n8)2*(cos(π*n4)+cos(π*3*n4))2
=cos(π*n8)2*cos(π*n4)*cos(π*n2)
- .cos(π*n8)2*(cos(π*n4)+cos(π*3*n4))2
- which provides the reduction from
- egf(A253513)=λ x: cos(x)+cosh(x)2 + cos(x√2)*cosh(x√2)2
- A014041=λ n: ∑7k=0(cos(π*n*(2*k+1)16))8
. . . .=λ n: 8*cos(π*n16)*∏2k=0(cos(π*(n2k - 1)4)*cos(π*(n2k + 1)4))
. . . .=λ n: cos(π*n16)*cos(π*n8)*cos(π*n4)*cos(π*n2) - egf(characteristic(12))=λ x: cosh(x)+cos(x)+2*cosh(x2)*cos(√3*x2)+2*cosh(√3*x2)*cos(x2)6
- egf(A168185)=λ x: ex-egf(characteristic(12))(x)
- egf(characteristic(10))=λ x: cosh(x)+2*cosh((1+√5)*x4)*cos(sqrt(5-√52)*x2)+2*cosh((1-√5)*x4)*cos(sqrt(5+√52)*x2)5
- egf(A168184)=λ x: ex-egf(characteristic(10))(x)
- egf(A034326)=λ x: 7*cosh(x) + 6*sinh(x) + cos(x) - sin(x) + 2*cosh(x2)*cos(√3*x2) + cosh(√3*x2)*(2*cos(x2) - 4*sin(x2)) - 2*√3*sin(x2)*sinh(√3*x2) - 2*sin(√3*x2)*(sinh(x2) + 2*cosh(x2))√3, providing
- A034326=λ n: 4*sin(π*n3)*(cos(π*n)*cos(π*(2*n+1)6) - 2*sin(π*n3)*sin(π*n2) - sin(π*(2*n+1)6)√3 - 2*sin(π*(n+1)3)*cos(π*n2)) + 3*√2*sin(π*(2*n+1)4) + 3*cos(π*n)2 + 152
maximal-density still lifes
In Conway's Game of Life: Mathematics and Construction, section 2.5, a formula for the maximum population of an n×n still life, or A055397(n), is provided (from G. Chu and P. J. Stuckey, A complete solution to the Maximum Density Still Life Problem, Artificial Intelligence, 184:1-16 (2012)), equivalent to
- A055397=λ n: (0,0,4,6,8,16,18,28,36,43,54,64,76,90,104,119,136,152,171,190,210,232,253,276,302,326,353,379,407,437,467,497,531,563,598,633,668,706,744,782,824,864,907,949,993,1039,1085,1132,1181,1229,1280,1331,
1382,1436,1490,1545,1602,1658,1717,1776,1835)[n] if n<61 else ⌊(27*n2+34*n-1-(n%54 in {0,1,3,8,9,11,16,17,19,25,27,31,33,39,41,47,49}))/54⌋
This is a finite number of exception terms followed by a function in terms of polynomial and periodic functions of n, the polynomial is of degree 2 and the oscillations are of constant magnitude. One can naively state that since it is describable as a different quadratic for each congruence modulo 54, a generating function for it could interlace 54 different noninteracting quadratic registers, with the quadratic recurrence relation 'stretched' to 1-3*x54+3*x108-x162 ((1-x54)3), and find the degree-162 numerator for 162 terms in the closed form (beginning at n=61), by the same method of matrix inversion shown above, then multiply the initial exception terms by the denominator and add them.
However, as the cube of a cyclotomic polynomial , (1-x54)3 factorises to (1-x)3*(1+x)3*(1-x+x2)3*(1+x+x2)3*(1-x3+x6)3*(1+x3+x6)3*(1-x9+x18)3*(1+x9+x18)3. Each of these factors has a different set of roots of unity as its polynomial roots, and because they're cubed, these have multiplicities of 3. Because, for a multiplicity of m, these roots' nth powers' coefficients (in the analytic closed form for a(n) that it provides) are m-1th-degree polynomials in n, and their purpose is to construct the modular expression (that has a constant coefficient), they can all be reduced to an exponent of 1. After inverting the matrix,
- .4*x2+6*x3+8*x4+16*x5+18*x6+28*x7+36*x8+43*x9+54*x10+64*x11+76*x12+90*x13+104*x14+119*x15+136*x16+152*x17+171*x18+190*x19+210*x20+232*x21+253*x22+276*x23+302*x24+326*x25+353*x26+379*x27+407*x28+437*x29+467*x30
+497*x31+531*x32+563*x33+598*x34+633*x35+668*x36+706*x37+744*x38+782*x39+824*x40+864*x41+907*x42+949*x43+993*x44+1039*x45+1085*x46+1132*x47+1181*x48+1229*x49+1280*x50+1331*x51+1382*x52+1436*x53+1490*x54
+1545*x55+1602*x56+1658*x57+1717*x58+1776*x59+1835*x60
+x61*
(1898-1835*x+x3+x4+x5+x6+x7+x8+2*x9+x11+x12+x13+x14+x15+x16+2*x17+x19+x20+x21+x22+x23+x24+2*x25+x27+x28+x29+x30+x31+2*x32+x34+x35+x36+x37+x38+x39+2*x40+x42+x43+x44+x45+x46+x47+2*x48+x50+x51+x52+x53-1897*x54+1837*x55)
/((1-x)3*(1+x)*(1-x+x2)*(1+x+x2)*(1-x3+x6)*(1+x3+x6)*(1-x9+x18)*(1+x9+x18))
Or the canonical form,
- x2*(4-2*x+6*x3-6*x4+8*x5-2*x6-x7+4*x8-x9+2*x10+2*x11+x13+2*x14-x15+3*x16+x18+2*x19-x20+2*x21+3*x22-2*x23+3*x24-x25+2*x26+2*x27+4*x30-2*x31+3*x32+3*x35+4*x38-2*x39+3*x40-x41+2*x42+2*x43+x45+2*x46-x47+3*x48+3*x51+x53-2*x54+x55+3*x56-6*x57+6*x58-4*x59+2*x60+x61-3*x62+2*x63-x64-x65+x66+x69-2*x70+x71-x73+2*x74-x75-x76+2*x77-2*x78+2*x79-x80-x81+x82+x83-2*x84+2*x85-2*x86+x87+x88-2*x89+x90+2*x91-4*x92+3*x93-2*x94+2*x95-x96-x97+x98+x99-2*x100+2*x101-2*x102+x103+x104-2*x105+x106+x107-2*x108+2*x109-2*x110+x111+x112-3*x113+2*x114)
/((1-x)3*(1+x)*(1-x+x2)*(1+x+x2)*(1-x3+x6)*(1+x3+x6)*(1-x9+x18)*(1+x9+x18))
Probably it is too large to be useful to add to the OEIS, but it is nice to have, I suppose.
multifactorials
A006882=λ n: reduce(int.*,range(2-(n&1),n+1,2),1), ie. A006882(n) is the product of all integers between 1 and n sharing n's parity. a(0)=1, and it abides by a(n)=n*a(n-2). It occurred to me that λ n: (n2)! has a(n)=n2*a(n-2), so multiplying it by 2n/2 returns a sequence equivalent to A006882 for even n, and because (12)! = √π2, multiplying it by √2/π makes it work for odd n, so
- A006882=n!!
. . . .=λ n: (n2)!*2n/2*(n&1?√2/π:1)
. . . .=λ n: (n2)!*2n2*√2/πn&1
. . . .=λ n: (n2)!*2n2*√2/π(1-(-1)n)/2
. . . .=λ n: (n2)!*sqrt(2n*√2/π1-(-1)n)
However, this is an equivalent reexpression of Peter Luschny's on the OEIS,
- λ n: (n2)!*2n2*(2π)sin(π*n2)22
For the k-factorial, n!(k) (defined by the product of all positive integers i in the range 0<i≤n with the same parity modulo k),
- n!(k) = prod(range((n-1)%k+1,n+1,k)) = ∏⌈nk⌉-1i=0(n-i*k)
this formula generalises to
- n!(k) = (nk)!(nk%1)!*k⌊nk⌋*(n%k or 1)
(where (n%k or 1)=(1 if n%k==0 else n%k)), which generalises Peter Luschny's form's property for the k=2 case,
- This analytical extension supports the view that a(-1) = 1 is a meaningful numerical extension.
(being a product of an empty set similarly to 0!) to the property that a(n,k)=1 for all integer k in the range 0≥n>-k. (See A114423 and its transpose A129116, which map it over n,k ∈ ℕ+×ℕ+)
This also allows analytic continuations, using the general form from the series representation transform (the inverse of the generating function transform gf) of each discontinuous function, in terms of kth roots of unity (and thereby trigonometric functions),
- continuation(λ n: n%k)=(gf-1)(λ x: ∑k-1n=0(n*xn)1-xk)
- continuation(λ n: n%k or 1)=(gf-1)(λ x: 1+∑k-1n=1(n*xn)1-xk)
- continuation(λ n: ⌊n/k⌋)=(gf-1)(λ x: xk(1-x)*(1-xk))
For k=3, this is exactly
- continuation(λ n: n%3)=λ n: 1+2*cos(π*4*n+56)√3
- continuation(λ n: n%3 or 1)=λ n: 4+2*cos(2*π*n+13)3
- continuation(λ n: ⌊n3⌋)=λ n: n-1+2*cos(π*4*n-16)√33
Providing the analytic continuation,
- n!!! = A007661(n) = (n3)!(13 + 2*cos(π*4*n+56)3*√3)!*3n-1+2*cos(π*4*n-16)√33*4+2*cos(2*π*n+13)3
Which has interesting outputs for rational inputs, such as (12)!!! = 2*(16)!35/6 and (-12)!!! = 10*(-16)!√3.
Note that because the analytic functions each abide by their discrete functions' necessary identities over the nonintegers (that f(n+3)=f(n) for the first two, and f(n+3)=f(n)+1 for the third), the generalisation abides by the identity n!!! = n*(n-3)!!!.
It is a known fact that, though one may multiply the gamma function's output by that of any function that returns 1 for integer n and has period 1, to get another function that generalises the factorial (equalling it over the integers and abiding by n! = n*(n-1)!), the gamma function definition is the unique one under the constraint that the graph of log(n!), for n≥1, is concave (ie. has a strictly increasing derivative), or equivalently λ n: d(n!)dn/n! is a strictly increasing function.
The integer k-multifactorial begins with an arithmetic progression, over 1<=n<=k+1 (for which it is equivalent to the identity function), during which log-convexity is impossible, because either its derivative is equal to the first differences (1) or must exceed it at some point between two intervals, meaning it must subsede it between them also. (When the function it is fitting is straight, convexity must be accompanied by concavity, which precludes log-convexity, as does straightness.) Due to this, such a condition would generalise to log-convexity for all n≥k. My function is not log-convex over any interval to positive infinity (though it is strictly increasing for n ≥ 22), but there does not exist one that is, due to the logarithmic first differences not being strictly increasing.
log-factorial integration
Note that we can use this (multifactorial in terms of factorials) with the formula for the factorial of a multiple of k in terms of k-multifactorials,
- . (k*n)!
= ∏k-1i=0((k*n-i)!(k))
= ∏k-1i=0((n - ik)!(1 - ik)!*kn-sgn(i)*(k-i if i else 1))
= ∏k-1i=0((n - ik)!(1 - ik)!)*kk*(n-1)+1*(k-1)!
= ∏k-1i=0((n - ik)!(1 - ik)!)*kk*(n-1)*k!
By using Stirling's approximation and limn->∞(n!/(n-x)!nx)=1, ∏ki=1((ik)!) = k!*kk*(n-1)*∏k-1i=0((n - ik)!)(k*n)! = limn->∞(k!*n!k*∏k-1i=0((n - ik)!/n!)√2*π*k*n*(ne)k*n*kk) = limn->∞(k!*n!k/∏k-1i=0(ni/k)√2*π*k*n*(ne)k*n*kk) = limn->∞(k!*√2*π*nk√2*π*k*n*kk*n(k-1)/2) = k!*√2*πk-1kk+1/2, meaning the above form can be reduced to (k*n)! = ∏k-1i=0((n - ik)!)*kk*n+1/2√2*πk-1 (which is already known, as Gauss's duplication/multiplication formula )
there is the more elegant variant ∏k-1i=0((-ik)!) = ∏ki=1((ik)!ik) = ∏ki=1((ik)!)/k!kk = √(2*π)k-1/k
since (for a smooth function) ∫ab(f(x) dx) = limk->∞(∑k-1i=0(f(b-(b-a)*ik)k)), we obtain
- ∫n-1n(log(x!) dx) = limk->∞(∑k-1i=0(log((n - ik)!)k)) = limk->∞(log(∏k-1i=0((n - ik)!))k) = limk->∞(log((k*n)!*√2*πk-1kk*n+1/2)k) = limk->∞(log(√2*πk*(ne)k*n*√n)k) = log(√2*π) + n*(log(n)-1) (with the special case ∫-10(log(x!) dx) = log(√2*π)); this is known as Raabe's formula (and is mentioned in Joseph Ludwig Raabe 's Wikipedia page)
as such, ∫-1n(log(x!) dx) = log(√2*π) + ∑nk=1(log(√2*π)+k*(log(k)-1)) = (n+1)*log(√2*π) + log(∏nk=1(kk)) - (n+12), so
- . ∏nk=1(kk)
= exp(∫-1n(log(x!) dx) + (n+12))√2*πn+1
= exp(∫1n(x*(log(x)-1) + log(√2*π*x) + 112*x + ∑∞i=2(B2*i2*i*(2*i-1)*x2*i-1) dx) + (n+12))e*√2*πn-1
= n(n+12)+1/12*√2*πn-1*e∑∞i=2(B2*i*(1-n2-2*i)4*(i-1)*i*(2*i-1))-(3*n+5)*(n-1)/4*e(n+12)e*√2*πn-1
= n(n+12)+1/12*e(1-n2)/4+∑∞i=2(B2*i*(1-n2-2*i)4*(i-1)*i*(2*i-1))
~ e1/4+∑∞i=2(B2*i4*(i-1)*i*(2*i-1))*n(n+12)+1/12en2/4
However, this is not a formula for Glaisher's constant A=e112-ζ'(-1) (the n-independent coefficient that arises), since Bernoulli numbers grow hyperexponentially (shortest explanation: g.f. is xex-1, whose closest singularities are ±2*π*i, giving Bn ~ -2*cos(π*n2)*n!(2*π)n), causing it to diverge (for any fixed input, eventually additional correction terms begin to diverge). Using the Wikipedia page's convergent extension ,
- . ∏n-1k=0(kk)
= exp(∫-1n-1(log(x!) dx) + (n2))√2*πn
= exp(∫0n(x*(log(x)-1) + log(2*π/x)2 + ∑∞m=1(x!*∑mk=1(k*[mk](k+1)*(k+2))(x+m)!*2*m) dx) + (n2))√2*πn #change bounds since extension is for the gamma function
= (nn-1*2*πe3*n/2-1)n/2*exp(∫0n(∑∞m=1(x!*∑mk=1(k*[mk](k+1)*(k+2))(x+m)!*2*m) dx) + (n2))√2*πn
= (nn-1e3*n/2-1)n/2*exp(∑∞m=1(∑mk=1((-1)k-1*log(1 + nk)(k-1)!*(m-k)!)*∑mk=1(k*[mk](k+1)*(k+2))2*m) + (n2)) #x!(x+m)! = ∑mk=1((-1)k-1(k-1)!*(m-k)!*(x+k))
= n(n2)en2/4*∏∞m=1(∏mk=1((1 + nk)(-1)k-1(k-1)!*(m-k)!)∑mi=1(i*[mi](i+1)*(i+2))2*m)
We can define the other kind of meta-factorial, the superfactorial , in terms of the hyperfactorial,
- sf(n)=∏n-1k=0(k!)=(n-1)!n∏n-1k=0(kk)
(I am being contrarian and using it upper-exclusively because it gives a nicer asymptotic, sf(n) ~ √2*πn*(√ne3/4)n2*eζ'(-1)12√n, and for reasons explained later)
this paper gives a formula for the (n2)-dimensional volume of SO(n), as 2n-12*∏n-1d=1(V(Sd)) = 2n-12*∏n-1d=1(2*√πd+1(d-12)!) = 232*(n-1)*π(n-1)*(n+2)4∏⌊n2⌋-1d=0(d!)*∏⌈n2⌉-1d=0((d+12)!) = 232*(n-1)*π(n-1)*(n+2)4*sf(-12)sf(⌊n2⌋)*sf(⌈n2⌉-12)
The integral also gives a fun interpretation of Stirling's approximation as the statement n! ~ √n*e∫n-1n(log(x!) dx), the geometric expected value of the factorial of a random number in (n-1,n] with the integral's centre's offset corrected by √n
in fact, one has limn->∞(log(√2*π*(n+1/2e)n+1/2/n!)log(√2*π*n*(ne)n/n!)) = -1/2
One can prove this by using log(x)≈x-1 in the neghbourhood of x=1 and the Laurent series extension of Stirling's approximation, n! ~ √2*π*n*(ne)n*∑∞i=0(A001163(i)A001164(i)*ni) = √2*π*n*nen*e∑∞i=1(B2*i2*i*(2*i-1)*n2*i-1) truncated to n! ~ √2*π*n*(ne)n*(1+112*n+...) and (n+12)n+1/2nn*√e*n ~ 1+18*n-..., then
- limn->∞(log(√2*π*(n+1/2e)n+1/2/n!)log(√2*π*n*(ne)n/n!)) = limn->∞(1+18*n1+112*n-1-112*n) = limn->∞(-12+16*n) = -1/2
so since the centred integral approximation has asymptotically half the logarithmic error of Stirling's approximation in the opposite direction, n! = √2*π*3√n*(n+1/2)2n+1/2en+1/3*(1 + 172*n2 + O(1n3)) has asymptotically 0 times the logarithmic error of either.
however, a nicer proof is given in Jonathan M. Borwein & Robert M. Corless (2018). Gamma and Factorial in the Monthly, p. 415; their formulation shows "Burnside's (which was in fact Stirling's original approximation) is twice as accurate as Stirling's" to be equivalent to "the midpoint rule is twice as accurate as the trapezoidal rule"
Since limn->∞(e∫n+c-1n+c(log(x!) dx)*n1/2-cn! - 1)*n) = limn->∞((√2*π*n*(n+ce)n+cnc.n! - 1)*n) = 1-6*c212, we get n! = √2*π*n*(n+1√6e)n+1√6√6√n*(1 + 165/2*n2 + O(1n3)), which is √3/2 times better.
It also seems to be exceedingly good experimentally! approximating 1! with each:
- Stirling's gives √2*πe = 0.9221370...,
- the centred integral gives 3*√2*π2*e3/2 = 1.0275077...,
- the average gives 3*√π/2e4/3 = 0.9911100...
- Stirling's with the 112*n term gives 13*√π/26*e = 0.9989817...
log(x!) = ∑∞k=1(ψk-1(1)*xkk!) = ∑∞k=1(ζ(k)*(-x)kk); together with ∫n-1n(log(x!) dx) = log(√2*π) + n*(log(n)-1), means ∑∞k=1(ζ(k)*(-1)k*(nk+1-(n-1)k+1)k*(k+1)) = log(√2*π) + n*(log(n)-1).
In the n=0 case, this becomes ∑∞k=1(ζ(k)k*(k+1)) = log(√2*π).
By rewriting ζ(k)=∑∞n=1(1nk) and transposing, we would have ∑∞n=1(1+(n-1)*log(1 - 1n)) = log(√2*π), ie. ∏∞n=1(e*(1 - 1n)n-1) = √2*π
however, since (for the log-factorial series's purposes) ζ(1) = γ, we handle that term separately; eγ2*∏∞n=1(e1 - 12*n*(1 - 1n)n-1) = √2*π
writing this as a limit,
- . √2*π/eγ = limn->∞(
. ∏nk=1(e1 - 12*k*(k-1k)k-1)
= ∏n-1k=0(e1 - 12*(k+1)*kk)/∏nk=1(kk-1)
= √e*∏n-1k=1(e1 - 12*(k+1)*k)/nn-1
= ∏nk=1(e1 - 12*k)*(n-1)!nn-1
= en - Hn2*n!nn
= en - γ2*n!nn+12)
hence, we recover Stirling's approximation; the second-last form (before application of Hn ~ log(n)+γ) makes it converge half as fast with the opposite error sign.
OEIS errata
- The empirical generating functions given for sequences A249098 and A249099 (that imply the former is the partial sum of a period-6 sequence, and the latter of a period-5 one) by Colin Barker are wrong, taking the 6th root shows A249097 to be an interlacing of two linear sequences, which differ by a factor of 6√3. The generating functions predict that A249098(257)=471 and A249099(214)=470, however in actuality they are the other way around (since 25763*2146=288136807515649288140227555008<1), which couldn't have been predicted by automatic methods because they have only 63 and 61 terms in their b-files, respectively. The reason for this is that 6√3's continued fraction representation begins 1+14+11+141+11+..., and the large number 41 causes the continued fraction convergent series to begin 1,54,65,251209, a difference of 11045.
- Zerinvary Lajos's comment on A118963, written on November 3, 2006, assumes it is 0-indexed when it is in fact 1-. It should state
- a(n,k)=(n-1k)*(n+1n-k)
- N. J. A. Sloane's comment on A057889 (from its creation) lists A003010 when it means A030101
- The cross-reference in A145920 to A141919 should be to A145919.
- On A001952, the comment "A080764(a(n)) = 0" by Reinhard Zumkeller on July 3rd, 2015, is wrong, it should be "A080764(n) = 0 iff n+1 is in this sequence."
- The comment on A050328 (added by N. J. A. Sloane at some time prior to its moving in 1999),
- Dirichlet g.f.: 11-B(s) where B(s) is D.g.f. of characteristic function of squarefree numbers > 1.
- is wrong, that would be λ s: 1ζ(s)ζ(2*s) - 1 (entailing a division by 0 at s = 0) but its Dirichlet g.f. is λ s: 12 - ζ(s)ζ(2*s)
- Eryk Kopczynski's comment on A247308 is the recurrence relation of its coordination sequences, that comment should be put on its first differences (A356835) and on there it should be
- a(n) = 4*a(n-1) - a(n-2) + 5*a(n-3) - 6*a(n-4) - 6*a(n-5) + 8*a(n-6) - 5*a(n-7) - 16*a(n-8) + 36*a(n-9) - 16*a(n-10) - 5*a(n-11) + 8*a(n-12) - 6*a(n-13) - 6*a(n-14) + 5*a(n-15) - a(n-16) + 4*a(n-17) - a(n-18)
- due to the n leading 0s, Darse Billings' statement upon A166315 of
- Terms grow like Θ(22n).
- is false, it is Θ(22n-n)
- the leading sections (aligned by the length-n run of 0s) of the nth term of a sequence of binary de Bruijn words (lexicographically minimal cyclic superstrings) contain small groups of 1s (counting over odd numbers) spaced with their ends n bits apart, and since the number of such terms is strictly increasing, we have A166315(n) ~ ∑∞i=0((1+2*i)*22n2(i+1)*n+1) = (1+2n)*22n-1(1-2n)2
- the number of leading bits for which this is accurate grows in a strange and gnarly manner, however
- Vladeta Jovovic's formula egf(A126671)=λ x,y: x*log(1-(1+x)*y)(x*y-1)*(1+x) (that is, e.g.f. in n, g.f. in k) has a(n,k)*yn*xk, whereas usually it is the other way around
- also, it is for the interpretation of the sequence with offset 0, and would require integration with respect to (the variable that is currently y) to match the sequence's offset 1, leading to use of the logarithmic integral (horrible); it arose for me (in #mononomials, monochooses and g.f. numerators) with offset 0, maybe that is the more natural one
- D. S. McNeil's comment on A000587 from February 2, 2011, says a(723) is almost certainly prime, however Edwin Hall gave a primality proof certificate on factordb on December 7 that year
- Vladimir Reshetnikov's comment on A000522 from October 27, 2015 is the correct asymptotic (mentioned above), with the factorial substituted for Stirling's approximation, without the Laurent series of the error, and (most importantly) erroneously divided by n
- not quite an erratum but Vaclav Kotesovec's comment on A187646 from May 30, 2011, can be simplified a little bit, from
- [2*nn] ~ (2*ne*z*(1-z))n*√(1-z2*π*n*(2*z-1)) ~ n!*(2z*(1-z))n*√(1-z2*z-1)2*π*n, where z = 0.715331862959... is a root of the equation z = 2*(z-1)*log(1-z)
- to
- G. C. Greubel's hypergeometric for A317365 is wrong! the final parameter should be 1, not -1, which produces A052852 instead.
binomial analyticity
- binomial reflections
- (herein, n ∈ ℕ+, k ∈ ℤ)
- (nk) = (nn-k) = (-1)k*(k+~nk) = (-1)k-n*(~k~n)
- everyone knows the first, however the other two enable Pascal's triangle to be extended to negative n also
(the derivation requires one to believe either that columns and diagonals can be extended backwards by interpreting them as polynomials or (more suspiciously, in this case) that 00 = 1)
- (-nk) = ∏-ni=1(i)∏ki=1(i)*∏-n-ki=1(i) = ∏-ni=1(i)/∏-n-ki=1(i)∏ki=1(i) = ∏-ni=1-n-k(i)∏ki=1(i) = (-1)k*∏n+k-1i=n(i)∏ki=1(i) = (-1)k*(n+k-1)!(n-1)!k! = (-1)k*(k-1+nk)
- (-n-k) = ∏-ni=1(i)∏-ki=1(i)*∏k-ni=1(i) = ∏-ni=1(i)/∏-ki=1(i)∏k-ni=1(i) = ∏-ni=1-k(i)∏k-ni=1(i) = (-1)k-n*∏k-1i=n(i)∏k-ni=1(i) = (-1)k-n*(k-1)!(n-1)!(k-n)! = (-1)k-n*(k-1n-1)
- this extends the binomial theorem also, to (1+x)-n = ∑∞k=0((-nk)*xk) if |x|<1 else ∑-nk=-∞((-nk)*xk)
- note that ddx((1+x)-n) = -n*(1+x)-n-1 so (ddx)k(λ x: (1+x)-n)(0) = (-1)k*(n+k-1)!(n-1)! so (λ x: (1+x)-n)k = (-1)k*(n+k-1)!(n-1)!*k! = (-1)k*(k-1+nk) = (-nk)
- so (1+x)-n = ∑∞k=0((-nk)*xk) (converging for |x| < 1, since it has a singularity at x = -1)
- let y = 1x, then (1+x)-n = (1+1y)-n = yn*(1+y)-n, and (using the previous proof)
- (1+1y)-n = yn*(1+y)-n = yn*∑∞k=0((-1)k*(k-1+nk)*yk) = ∑∞k=n((-1)k-n*(k-1k-n)*yk) = ∑∞k=n((-1)k-n*(k-1n-1)*yk) = ∑∞k=n((-n-k)*yk) = ∑-nk=-∞((-nk)*xk) (converging for |y| < 1 and thus |x| > 1)
- note that ddx((1+x)-n) = -n*(1+x)-n-1 so (ddx)k(λ x: (1+x)-n)(0) = (-1)k*(n+k-1)!(n-1)! so (λ x: (1+x)-n)k = (-1)k*(n+k-1)!(n-1)!*k! = (-1)k*(k-1+nk) = (-nk)
- which is writable in g.f. terms as (nk) = [xk]((1+x)n) = [xk]((1-x)k+~n) = [x~n]((1-x)~k), the latter two being combinatorially equivalent
- note that (-1)k*(-nk)=(k-1+nk) (often written ((nk))) has a combinatorial interpretation as being the number of ways to create a multiset of k elements from a set of n with repetition (via a stars and bars argument or Richard P. Stanley's theorem later on)
- it also is the basis for the negative binomial distribution ; the value ((nk))*pn*(1-p)k is the probability that, tossing a coin (with chance p of heads) until n heads, there are k tails
- (12)!
- usually, (12)! = Γ(32) = √π2 is computed by taking (-12)! = Γ(12) = √π first (by using Euler's reflection formula to get Γ(12)2 = πsin(π2) or doing the easy integration by substitution into the Gaussian integral), however it can be done directly (though I'm not sure why one would want to)
- . (12)!
= ∫0∞(e-x*√x dx)
= ∫0∞(e-y2*y*(dxdy:=2*y) d(y:=√x))
- . (12)!
- we use the same cool Cartesian product trick as the Gaussian integral
- = √(∫0∞(e-x2*2*x2 dx)*∫0∞(e-y2*2*y2 dy))
= √(∫0∞(∫0∞(e-x2*e-y2*4*x2*y2 dy) dx))
= √(∫-∞∞(∫-∞∞(e-x2*e-y2*x2*y2 dy) dx))
= √(∫0∞(∫02*π(e-r2*r2*cos(θ)2*r2*sin(θ)2*r dθ) dr))
= √(∫0∞(∫02*π(cos(θ)2*sin(θ)2 dθ)*e-r2*r5 dr))
= √(∫02*π(1-cos(4*θ)8 dθ)*∫0∞(e-r2*r5 dr))
= √(π4*∫0∞(e-r2*r5 dr))
= √(π4*∫0∞(e-x*x5/2*(drdx:=12*√x) d(x:=r2)))
= √(π8*∫0∞(e-x*x2 dx))
- = √(∫0∞(e-x2*2*x2 dx)*∫0∞(e-y2*2*y2 dy))
- note that since ∫0∞((e-x)*(xn) dx) + ∫0∞((-e-x)*(n*xn-1) dx) = [(-e-x)*(xn)]0∞ = 0, ∫0∞((e-x)*(xn) dx) = n*∫0∞((e-x)*(xn-1) dx) and ∫0∞(e-x dx) = [-e-x]0∞ = 1, so ∫0∞((e-x)*(xn) dx) = n! (which is why the gamma function behaves as the factorial), so
- = √(π8*2!)
= √π2
- = √(π8*2!)
- series expansion of the sqrt of a linear function!
- recall that (2*n)! = (2*n-1)!!*(2*n)!!, so by rearranging the form from #multifactorials, we have (for n ∈ ℕ) (n2)! = n!!2⌊n2⌋*(π2)n%2
- ( n - 12)! = (2*n-12)! = √π*(2*n-1)!!2n = √π*∏ni=1(2*i-1)2n = √π*(2*n-1)!!2n = √π*(2*n)!n!*4n
- (-n - 12)! = √π*(-1-2*n)!!2n+1 = √π*2n∏0i=-n(2*i-1) = √π*(-2)n∏ni=1(2*i-1) = √π*(-2)n(2*n-1)!! = √π*n!*(-4)n(2*n)!
- so
- (1/2n) = √π2n!*(1/2-n)! = (2*n-3)!!2n*n!*(-1)n-1 = (2*n-3)!!(2*n)!!*(-1)n-1 = (2*n-1)!!(2*n-1)*(2*n)!!*(-1)n-1 = (2*n)!(2*n)!!(2*n-1)*(2*n)!!*(-1)n-1 = (2*n)!*(-1)n-1n!2*(2*n-1)*4n = (2*nn)(1-2*n)*(-4)n
- (-1/2n) = √πn!*(-1/2-n)! = (2*n-1)!!*(-1)nn!*2n = (2*n)!*(-1)nn!2*4n = (2*nn)(-4)n
- which are special cases of the following table
- vertical bifurcation is where (to keep the choose inputs nonnegative) cells' contents depend upon sgn(n-k) (n≥k atop and n≤k abelow); zerotude and infinitude represented by red and cyan
- recall that (2*n)! = (2*n-1)!!*(2*n)!!, so by rearranging the form from #multifactorials, we have (for n ∈ ℕ) (n2)! = n!!2⌊n2⌋*(π2)n%2
(xy) n-1 -n-1 n-1/2 -n-1/2 k nn-k*(nk) (-1)k*(n+kk) (2*n2*k)*(2*kk)(nk)*4k (2*kk)*(2*(n+k)2*k)(n+kk)*(-4)k (-1)k-n*0n*(kn) (2*kk)*(kn)*(-1)k+n(2*k2*n)*4k -k (n+k)*(-1)k*0n*k*(n+kk) 0k*(nk) (2*nn)*(-4)k*0k*(2*(n+k)n+k)*(n+kk) (nk)*4k*0k*(2*n2*k)*(2*kk) (-1)k-1-n*kk-n*(kn) (2*k2*n)*4k*(-1)k-n*0k*(kn)*(2*kk) k-1/2 (2*n2*k)*4nπ*n*(2*nn)*(nk) (2*nn)*(2*(n+k)2*k)π*(n+kk)*(-1)k*4n*0 (2*nn)*(nk)*4k(2*kk)*4n (n+kk)*4n+k*(-1)k*0(n+k)*(2*nn)*(2*kk) (kn)*(-1)k-n*4nπ*n*(2*k2*n)*(2*nn) (2*nn)*(-4)k-n*0(k-n)*(2*kk)*(kn) -k-1/2 (2*kk)*4n*(-1)kπ*n*(2*(n+k)n+k)*(n+kk) (2*nn)*(nk)π*(2*n2*k)*4n*0 (2*nn)*(2*kk)(n+kk)*4n+k*(-1)k (2*kk)*4n-k*0(n-k)*(2*nn)*(nk) (2*k2*n)*(2*nn)π*(kn)*(-1)k+n*4n*0 (2*kk)*(kn)*(-4)n(2*nn)*(-4)k
- workings
- all indented an additional layer have k>n
- (n-1k) = (n-1)!k!*∏-(k-n)-1i=1(i) = (n-1)!*∏0i=-(k-n)(i)k! = (n-1)!*(-1)k-n*(k-n)!*0k! = (-1)k-n*0n*(kn)
- (-n-1-k) = ∏-n-1i=-k+1(i)(k-n-1)! = 1∏-ki=-n(i)*(k-n-1)! = 1(-1)n-k-1*∏ni=k(i)*(k-n-1)! = (k-1)!(-1)n-k-1*n!*(k-n-1)! = k!*∏0i=k-n(i)(-1)n-k-1*n!*k = k!*(-1)n-k-1*(n-k)!*0(-1)n-k-1*(nk)*k = 0(nk)*k
- (-n-1-k) = (k-1)!(-1)n-k*n!*(k-n-1)! = (-1)n-k*(k-1n)
- (n-1/2k) = (2*n)!*(n-k)!(2*(n-k))!*n!*k!*4k = (2*nn)*(nk)(2*(n-k)n-k)*4k = (2*n2*k)*(2*kk)(nk)*4k
- (n-1/2k) = (2*n)!*(2*(k-n))!*(-1)k-nk!*4k*(k-n)!*n! = (2*nn)*(2*(k-n)k-n)*(-1)k-n(kn)*4k = (2*kk)*(kn)*(-1)k-n(2*k2*n)*4k
- (n-1/2-k) = (2*n)!*(n+k)!*4kn!*∏-ki=1(i)*(2*(n+k))! = (2*n)!*(n+k)!*∏0i=1-k(i)*4kn!*(2*(n+k))! = (2*n)!*(n+k)!*(k-1)!*(-4)k*0n!*(2*(n+k))! = (n+kk)*(-4)k*0k*(2*(n+k)2*n)*(2*kk) = (2*nn)*(-4)k*0k*(n+kk)*(2*(n+k)n+k)
- (-n-1/2k) = (2*(n+k))!*n!*2n(n+k)!*2n+k*(2*n)!*k!*(-2)k = (2*(n+k)n+k)*(n+kk)(2*nn)*(-4)k = (2*kk)*(2*(n+k)2*k)(n+kk)*(-4)k
- (-n-1/2-k) = (2*(n-k))!*n!*(-4)k(2*n)!*∏-ki=1(i)*(n-k)! = (2*(n-k))!*n!*k!*4k*0k*(2*n)!*(n-k)! = (2*(n-k)n-k)*4k*0k*(2*nn)*(nk) = (nk)*4k*0k*(2*n2*k)*(2*kk)
- (-n-1/2-k) = n!*(k-n)!*4k-n*(-4)n(2*n)!*(2*(k-n))!*∏-ki=1(i) = n!*(k-n)!*(k-1)!*4k*(-1)k-n*0(2*n)!*(2*(k-n))! = (kn)*4k*(-1)k-n*0k*(2*nn)*(2*(k-n)k-n) = (2*k2*n)*4k*(-1)k-n*0k*(kn)*(2*kk)
- (n-1k-1/2) = (n-1)!*4n*k!*(n-k)!π*(2*k)!*(2*(n-k))! = (nk)*4nπ*n*(2*kk)*(2*(n-k)n-k) = (2*n2*k)*4nn*π*(2*nn)*(nk)
- (n-1k-1/2) = (n-1)!*k!*(2*(k-n))!*(-1)k-n*4nπ*(2*k)!*(k-n)! = (2*(k-n)k-n)*(-1)k-n*4nn*π*(2*kk)*(kn) = (kn)*(-1)k-n*4nn*π*(2*k2*n)*(2*nn)
- (n-1-k-1/2) = (n-1)!*(2*k)!*(n+k)!*4n+kπ*k!*(2*(n+k))!*(-4)k = (n+kk)*4nn*π*(2*(n+k)2*k)*(2*nn)*(-1)k = (2*kk)*4nπ*n*(2*(n+k)n+k)*(n+kk)*(-1)k
- (-n-1k-1/2) = ∏-1-ni=1(i)*k!*(2*(n+k))!π*(2*k)!*(n+k)!*(-1)n+k*4n = k!*(2*(n+k))!π*(2*k)!*(n+k)!*∏0i=-n(i)*(-1)n+k*4n = k!*(2*(n+k))!π*(2*k)!*(n+k)!*n!*(-1)k*4n*0 = (2*(n+k)n+k)*(n+kk)π*(2*kk)*(-1)k*4n*0 = (2*nn)*(2*(n+k)2*k)π*(n+kk)*(-1)k*4n*0
- (-n-1-k-1/2) = (2*k)!*(2*(n-k))!π*k!*(n-k)!*n!*4n*0 = (2*kk)*(2*(n-k)n-k)π*(nk)*4n*0 = (2*nn)*(nk)π*(2*n2*k)*4n*0
- (-n-1-k-1/2) = ∏-1-ni=1(i)*(2*k)!*(k-n)!*4k-nπ*k!*(2*(k-n))!*(-4)k = (2*k)!*(k-n)!π*n!*k!*(2*(k-n))!*(-1)k+n*4n*0 = (2*kk)*(kn)π*(2*(k-n)k-n)*(-1)k+n*4n*0 = (2*k2*n)*(2*nn)π*(kn)*(-1)k+n*4n*0
- (n-1/2k-1/2) = (2*n)!*k!*4k(2*k)!*n!*4n*(n-k)! = (2*n2*k)*(2*(n-k)n-k)*4k(nk)*4n = (2*nn)*(nk)*4k(2*kk)*4n
- (n-1/2k-1/2) = (2*n)!*k!*(k-n)!*(-4)k-n*0(k-n)*n!*(2*k)! = (kn)*(-4)k-n*0(k-n)*(2*k2*n)*(2*(k-n)k-n) = (2*nn)*(-4)k-n*0(k-n)*(2*kk)*(kn)
- (n-1/2-k-1/2) = (2*n)!*(2*k)!n!*k!*(n+k)!*4n*(-4)k = (2*(n+k)n+k)*(n+kk)(2*(n+k)2*n)*4n+k*(-1)k = (2*nn)*(2*kk)(n+kk)*4n+k*(-1)k
- (-n-1/2k-1/2) = n!*k!*(-4)n*4k(2*n)!*(2*k)!*∏-n-ki=1(i) = n!*k!*(-4)n*4k*(-1)n+k*(n+k)!*0(n+k)*(2*n)!*(2*k)! = (2*(n+k)2*k)*4n+k*(-1)k*0(n+k)*(n+kk)*(2*(n+k)n+k) = (n+kk)*4n+k*(-1)k*0(n+k)*(2*nn)*(2*kk)
- (-n-1/2-k-1/2) = n!*(2*k)!*(-4)n-k*(-1)n-k*(n-k)!*0(n-k)*(2*n)!*k! = (nk)*4n-k*0(n-k)*(2*n2*k)*(2*(n-k)n-k) = (2*kk)*4n-k*0(n-k)*(2*nn)*(nk)
- (-n-1/2-k-1/2) = n!*(2*k)!*(-4)n(2*n)!*k!*(k-n)!*(-4)k = (2*k2*n)*(2*(k-n)k-n)*(-4)n(kn)*(-4)k = (2*kk)*(kn)*(-4)n(2*nn)*(-4)k
- all indented an additional layer have k>n
- as such, gf(λ n: (2*nn)1-2*n)=λ x: √1-4*x and gf(λ n: (2*nn))=λ x: 1√1-4*x
- from which we have such inanity as ∑nk=0((2*kk)1-2*k * (2*(n-k)n-k)1-2*n+2*k) = (1,-4)[n] if n<2 else 0 and ∑nk=0((2*kk)1-2*k * (2*(n-k)n-k)) = 0 if n else 1
- let fp = gf-1(λ x: gf(f)(x)p)
- since ∑nk=0(f-1(k)*f(n-k))=0 if n else 1, we have f-1=λ n: -∑n-1k=0(f-1(k)*f(n-k)) if n else 1f(0)
- likewise, ∑nk=0(√f(k)*√f(n-k))=f(n), and √f=λ n: f(n)-∑n-1k=1(√f(k)*√f(n-k))2*√f(0) if n else √f(0)
- so (2*nn) = ∑nk=1((2*kk)*(2*(n-k)n-k)2*k-1), and as a recursive form (unravelling out the last iteration) (2*nn) = 2*n-12*(n-1)*∑n-1k=1((2*kk)*(2*(n-k)n-k)2*k-1) = 2*n-1n-1*∑n-2k=1(C(k)*(2*(n-1-k)n-1-k))
- and π4 = ∫01((√1-x2:=∑∞n=0((2*nn)1-2*n*(x2)2*n)) dx) = (λ x: ∑∞n=0((2*nn)1-4*n2*2*(x2)1+2*n))10 = ∑∞n=0((2*nn)1-4*n2*2*(12)1+2*n) = ∑∞n=0((2*nn)(1-4*n2)*4n)
binomial g.f.'s
- note that most of this section has been very much superseded by my more recent and readable page, an introduction to Stirling numbers
I cannot find any existing occurrences of this idea (mainly because I don't know how I would search for it without any keywords that are inundated with other results, and it is not in Wikipedia's examples of forms for generating functions ). amendment: it seems these are usually known as Newtonian series
Let bgf=λ f: ∑∞n=0(f(n)*(xn)). A few properties:
- convolution: since (xn)*(xm) = ∑n+mi=max(n,m)((ni-m)*(in)*(xi)), we have that
- bgf-1(bgf(a)*bgf(b))=λ i: ∑in=0(∑im=i-n((ni-m)*(in)*a(n)*b(m)))
- where (ni-m)*(in) is the commutative function i!(i-n)!*(i-m)!*(n+m-i)!
- noninteger-order terms: per theorem 1 of this paper (on noninteger-order Stirling numbers), we have
- (xa)=∑∞k=0((xk)*sin(π*(a-k))π*(a-k))
- for Re(x) > -1 and a ∈ ℂ
We have that (where [nk] = A132393(n,k) and {nk} = A048993(n,k), per Knuth's notation for Stirling numbers) for finite sequences f,
- bgf(f) = gf(λ k: ∑∞n=k((λ x: (xn))k*f(n))) = egf(λ k: ∑∞n=k((ddx)k(λ x: (xn))(0)*f(n))) = gf(λ k: ∑∞n=k((-1)n-k*[nk]n!*f(n)))
and (where Δ=λ f: λ x: f(x+1)-f(x), and Δn(f) = Δ(Δ(...Δ(Δ(f))...)))
- gf(f) = bgf(λ k: ∑∞n=k(Δk(λ x: xn)(0)*f(n))) = bgf(λ k: k!*∑∞n=k({nk}*f(n)))
it also has elegant closed forms for linear-recurrent sequences
- bgf(λ n: cn*nk)=λ x: (c+1)x-k*xk
the 0-indexed sequence 1,0,0,0,... is the convolutional identity, like with g.f.'s and e.g.f.'s.
- bgf(λ n: (cn))=λ x: (x+cc)
However, since this allows one to "delay" the change to an earlier term of the polynomial series expansion to the later terms of the sequence arbitrarily, the binomial series expansion of a function is not a bijective correspondence. Consider
- bgf(λ n: (-1)n*nk)=λ x: 0
(the set of alternating-sign polynomial sequences vanishes under the taking of the b.g.f., unusefully)
so one should not try to identify b.g.f. series by their conversion to an ordinary g.f. or complex function unless they are finite; hereafter, we will use the bgf function only on finite polynomials (where this holds), but it could be used as syntax for 'formal b.g.f.s,' which use its properties (like multiplication as a weird combinatorial convolution operation) without necessarily converging.
- note that Carlson's theorem provides a more general method of determining b.g.f.s' existence and uniqueness
In general (where | denotes divisibility), (λ n: c*(c|n))=(λ n: ∑c-1k=0(ei*2*π*k/c)) so bgf(λ n: c*(c|n))=(λ x: ∑c-1k=0((ei*2*π*k/c+1)x))=egf(λ n: ∑c-1k=0(log(ei*2*π*k/c+1)k))
one may also take the b.g.f. series expansion of the reciprocal of a function f, by using the fact that the matrix m such that the jth element of the ith column is the coefficient of (xj) that f(x)*(xi) contributes is necessarily lower-diagonal, so must only have nonzero elements on its main diagonal to be invertible
a special case: recall that gf-1(λ x: gf(f)(x)1+x)=λ n: ∑ni=0((-1)i*f(n-i)). However, we have that bgf-1(λ x: bgf(f)(x)(1+x):=((x0)+(x1)))=λ n: (mat(λ x,y: x if 0 ≤ y-x ≤ 1 else 0,n+1)-1)[n]*vec(f,n+1)=λ n: ∑ni=0((-1)i*f(n-i)n+1) (where [n] takes the matrix's nth row)
b.g.f. equivalents to Pascal's triangle
since the previous convolution method provides (1+x)*bgf(f)=bgf(λ k: k*f(k-1)+(k+1)*f(k)), we may write rows of Pascal's triangle as sequences, then take the b.g.f. expansions of their g.f.'s, f=λ n,k: bgf-1((1+x)n)(k), with the recurrence relation
- f(n,k) = k*f(n-1,k-1)+(k+1)*f(n-1,k), with f(0,0) = 1 and all others defined inductively.
Thus, where F=gf(f), since gf(λ n: n*f(n))=λ x: x*(ddx)(gf(f))(x), the recurrence relation becomes F(x,y) = 1 + x*(1+y)*gf(λ n,k: (k+1)*f(n,k)) = 1 + x*(1+y)*(F(x,y)+y*(ddy)(F)(x,y)). It also corresponds with a recurrence relation satisfied by the kth column's generating function, denoted Fk, that Fk(x) = x*k*Fk-1(x) + x*(k+1)*Fk(x), or Fk(x) = k*x1-(k+1)*x*Fk-1(x), together with F0=λ x: 11-x, so Fk=λ x: k!*xk∏ki=0(1-(i+1)*x), from which we obtain
- . F(x,y)
= ∑∞k=0(Fk(x)*yk)
= ∑∞k=0(k!*xk*yk∏ki=0(1-(i+1)*x))
= ∑∞k=0(k!*xk*yk∏k+1i=2(1-i*x))1-x
= ∑∞k=0(k!*xk∏k+1i=2(i*x-1)*(-y)k)1-x
= ∑∞k=0(k!2∏k+1i=2(i - 1x)*(-y)kk!)1-x
= ∑∞k=0(k!/0!*k!/0!(k+1 - 1x)!/(1 - 1x)!*(-y)kk!)1-x
= 2F1(1,12 - 1x;-y)1-x
partial-fraction-decomposing each column's g.f. (here each one represented as a row of decomposed parts) reveals a pattern
>>> print(stratrix(tap(lambda n: tap(str,polyfrac(fact(n)*x**n,prod(map(lambda k: 1-(k+1)*x,range(n+1)))).decompose()),range(8)),dims=2)) ( 1/(1-x), -1/(1-x), 1/(1-2*x), 1/(1-x),-2/(1-2*x), 1/(1-3*x), -1/(1-x), 3/(1-2*x), -3/(1-3*x), 1/(1-4*x), 1/(1-x),-4/(1-2*x), 6/(1-3*x), -4/(1-4*x), 1/(1-5*x), -1/(1-x), 5/(1-2*x),-10/(1-3*x), 10/(1-4*x), -5/(1-5*x), 1/(1-6*x), 1/(1-x),-6/(1-2*x), 15/(1-3*x),-20/(1-4*x), 15/(1-5*x),-6/(1-6*x), 1/(1-7*x), -1/(1-x), 7/(1-2*x),-21/(1-3*x), 35/(1-4*x),-35/(1-5*x),21/(1-6*x),-7/(1-7*x),1/(1-8*x))
leading us to the conjecture Fk(x) = ∑ki=0((-1)k-i*(ki)1-(i+1)*x), or equivalently f(n,k) = ∑ki=0((-1)k-i*(ki)*(i+1)n). We indeed have f(n,0)=1, and the recurrence relation becomes ∑ki=0((-1)k-i*(ki)*(i+1)n) = ∑k-1i=0((-1)k-i*((k+1)*(ki)-k*(k-1i))*(i+1)n-1) + (i+1)n-1, which is shown by (k+1)*(ki)-k*(k-1i) = (k+1)*k!i!*(k-i)! - k!i!*(k-1-i)! = (k+1)*k!i!*(k-i)!-(k-i)*k!i!*(k-i)! = (i+1)*(ki). As such, f(n,k) = A028246(n+1,k+1) = k!*{n+1k+1}
g.f. (ordinary in both variables) for Stirling numbers of the second kind
herein, I will be slightly idiosyncratic; as well as using the upper and lower incomplete gamma function Γ(n,x) = ∫x∞(tn-1*e-t dt) and γ(n,x) = ∫0x(tn-1*e-t dt), I will also use the "incomplete factorials" (n,x)! = ∫x∞(tn*e-t dt) and (n,x)¡ = ∫0x(tn*e-t dt) (ie. (n,x)!=Γ(n+1,x) and (n,x)¡=γ(n+1,x)); this makes the last steps slightly more elegant
- . gf(λ n,k: {nk})
= 1 + x*y*gf(λ n,k: f(n,k)k!)
= 1 + x*y*∑∞k=0(Fk(x)k!*yk)
= 1 + x*y*∑∞k=0(∑ki=0((-1)k-i*(ki)1-(i+1)*x)*ykk!)
= 1 + y*∑∞k=0(∑ki=0(xi!*(1-(i+1)*x)*(-1)k-i(k-i)!)*yk)
= 1 + y*∑∞k=0(x*ykk!*(1-(k+1)*x))*∑∞k=0((-1)k*ykk!)
= 1 + y*∑∞k=0(ykk!*(1/x-1-k))*∑∞k=0((-1)k*ykk!)
= 1 - ∑∞k=0(-x√-1*yk+1-1/xk!*(k+1-1/x))*∑∞k=0(x√-1*(-1)k*yk+1/xk!)
= 1 - ∫0y(∑∞k=0(-x√-1*tk-1/xk!) dt)*∑∞k=0((-1)k+1/x*yk+1/xk!)
= 1 - ∫0y(etx√-t dt)*∑∞k=0((-y)k+1/xk!)
= 1 - ∫0y(etx√-t dt)*x√-yey
= 1 + -∫0y((-t)-1/x*et dt)*x√-yey
= 1 + ∫0-y(t-1/x*e-t dt)*x√-yey
= 1 + (-1/x,-y)¡*x√-yey
= 1 + γ(1-1/x,-y)*x√-yey
which gives a proof (by replacing x with 11-x and y with -y) of 1F1(1x;y) = 1 + γ(x,y)*y1-x*ey; together with the standard γ(x,y)=yx1F1(x1+x;-y)x, we get 1F1(1x;y) = 1 + y*ey*1F1(x1+x;-y)x; nicer is to use (1F1(1x;y)-1)/yx = 1F1(11+x;y) to get 1F1(11+x;y) = ey*1F1(x1+x;-y), which a search of the relevant DLMF section reveals is just a rederivation of 13.2.39 :-(
however, as implied by the fact that it returns an imaginary value for all positive y, the series does not converge (since {2*n-1n} = A129506(n) ~ 23/2*(4*n)n-3/2*(2+W(-2*e-2))1-n√π*(1+W(-2*e-2))*(e*-W(-2*e-2))n, as given by Vaclav Kotesovec, so for any x,y, the nn grows faster than all other terms shrink, including x2*n-1*yn for all choices of x,y with y>0, and all but these central coefficients can be neglected); however I have little to no idea of how to prove convergence for negative y, they will be treated as formal power series
some other identities
From the conversion formulae and gf(λ k: (nk))=bgf(λ k: f(n,k):=k!*{n+1k+1})=λ x: (1+x)n we get some identities
- {n+1k+1} = ∑ni=k({ik}*(ni))[bgf 1]
- (nk) = ∑ni=k((-1)i-k*[ik]*{n+1i+1})
going the other way, bgf(λ k: (nk))=gf(λ k: [n+1k+1]n!)=(x+nn) (or maybe more usefully gf(λ k: [nk]n!) = bgf(λ k: (n-1k-1)) = (x+n-1n), the counterpart of xn = fgf(λ k. {nk})), so
- [n+1k+1] = ∑ni=k((-1)i-k*[ik]*n!i!*(ni))[bgf 2]
- n!k!*(nk) = ∑ni=k({ik}*[n+1i+1])
these generalise to
- gf(λ k: (n-ck-c)) = bgf(λ k: k!*∑ci=0((-1)i*(ci)*{n+1-ik+1})) = xc*(1+x)n-c
- ∑ci=0((-1)i*(ci)*{n+1-ik+1}) = ∑ni=k({ik}*(n-ci-c))[bgf 3]
- (n-ck-c) = ∑ni=k((-1)i-k*[ik]*∑cj=0((-1)j*(cj)*{n+1-ji+1}))
- bgf(λ k: (n-ck-c)) = gf(λ k: ∑ci=0((-1)c-i*[ci]*[n+1-ck+1-i])n!) = (xc)*2F1(c-n,c-x1+c;1) = (x+n-cn) #Gauss's hypergeometric identity
- ∑ci=0((-1)c-i*[ci]*[n+1-ck+1-i]) = ∑ni=k((-1)i-k*[ik]*n!i!*(n-ci-c))[bgf 4]
- n!k!*(n-ck-c) = ∑ni=k({ik}*∑cj=0((-1)c-j*[cj]*[n+1-ci+1-j]))
for these next few, use fgf to denote the 'falling generating function'; fgf=λ f: bgf(λ n: n!*f(n))=λ f: ∑∞n=0(f(n)*xn)
- fgf(λ k: (nk)) = bgf(λ k: nk) = gf(λ k: ∑ni=k((-1)i-k*(ni)*[ik])) = 2F0(-n,-x;1)
- gf(λ k: nk) = fgf(λ k: ∑ni=k(ni*{ik})) = 2F0(1,-n;-x) = xn*e1/x*Γ(n+1,1x)
(no extraction formulas for these two, since they're tautological)
- fgf(λ k: [nk]) = gf(λ k: ∑ni=k([ni]*[ik]*(-1)i-k)) = [xnn!]((1+log(11-x))y)
- gf(λ k: {nk}) = fgf(λ k: ∑ni=k({ni}*{ik})) = [xnn!](e(ex-1)*y)
- fgf(λ k. {nk}) = gf(λ k: [k=n]) = xn
- gf(λ k: [nk]) = fgf(λ k: n!k!*(n-1k-1)) = xn
some bivariate g.f.s of mixed kind for f=λ n,k: (nk)
- (fgf,bgf) = 2F0(-x,1+y;-1)
- (bgf,bgf) = 2F1(-x,1+y1;-1)
- (ogf,bgf) = 1F0(1+y;x) = 1(1-x)1+y
- (egf,bgf) = 1F1(1+y1;x)
- (fgf,ogf) = 2F0(1,-x;-1-y) = (1+y)x*e1/(1+y)*Γ(x+1,11+y)
- (bgf,ogf) = 1F0(-x;-1-y) = (2+y)x
- (ogf,ogf) = 1F0(1;x*(1+y)) = 11-x*(1+y)
- (egf,ogf) = 0F0( ;x*(1+y)) = ex*(1+y)
- (ogf,fgf) = 2F0(1,-y;-x1-x)1-x = xy(1-x)y+1*e1/x-1*Γ(y+1,1-xx)
while trying to find (ogf,fgf), I accidentally found (gf,bgf)(λ n,k: n!*k!(n-k)!) = (gf,fgf)(λ n,k: nk) = (gf,gf)(A099599) = 3F0(1,1,-y;-x1-x)1-x, so the nth row is 3F0(1,-n,-x;1) (for which RISC's fastZeil WolframScript library provides R(n+1,x) = (n+1)*(n*R(n-1,x)+(x-n)*R(n,x)) + 1), and A099599=λ n,k: ∑ni=k(ni*(-1)i-k*[ik]) (for which the Stirling library provides the same recurrence relation, extracted into coefficients)
as another generalisation, bgf(λ k: (nk)*yk)(x) = ogf(λ k: (nk)*(xk))(y) = 2F1(-n,-x1;y)
where a,b are triangular matrices (such that m[n][k] is nonzero iff n≥k), matmul(a,b)[n][k] = ∑ni=k(a[n][i]*b[i][k])
for lower-triangular matrices upon a row vector of coefficients, we can change basis from g.f. to b.g.f., shift each term rightwards by 1 (take the partial sums), and change back, giving us a matrix
- m = matmul(tap(λ n: polychoose(xn),range(∞)),tap(λ n: polynomial((xn)),range(1,∞)))
. = matmul(mat(λ n,k: k!*{nk}),mat(λ n,k: (-1)n+1-k*[n+1k](n+1)!))
. = mat(λ n,k: ∑ni=k-1(i!*{ni}*(-1)i+1-k*[i+1k](i+1)!))
. = mat(λ n,k: ∑n+1i=k({ni-1}*(-1)i-k*[ik]i))
so due to Faulhaber's formula , the Bernoulli numbers can be expressed B-n = n+1(n+kk)*∑n+k+1i=k((-1)i-k*[ik]*{n+ki-1}i) for all k>0, and the other way around, the Gregory coefficients as Gn = k!(n+k)!*∑n+k+1i=k((-1)n+k+1-i*{ik}*[n+ki-1]i)
by setting k=0, one gets the well-known conventional formulas B-n=∑nk=0((-1)k*k!*{nk}k+1) and n!*Gn=∑nk=0((-1)n-k*[nk]k+1) (note there is also a sequence n!*A051780(n)A051781(n)=[xnn!](e1-ex-11-ex)=∑nk=0((-1)k*{nk}k+1))
weird poset/partition thing
A094216(n,k) is the coefficient of (xk) in the binomial series expansion of fn=λ x: [n+xx] (ie. Δk(fn)(0)), however there is no such sequence for a(n,k) = Δk(gn)(0) with gn=λ x: {n+xx} (note that gf(f) and gf(g)'s numerators are each other, with coefficients read in opposite order)
listing this out as a number triangle,
>>> l=8;print(stratrix(tap(lambda n: polychoose(fit(*tap(lambda k: subset(n+k,k),range(2*n+2)))),range(l)))) (1, ,1, 1, ,1, 5, 7, 3, ,1, 13, 48, 76, 55, 15, ,1, 29, 211, 679, 1151, 1075, 525, 105, ,1, 61, 780, 4280, 12710, 22506, 24556, 16240, 5985, 945, ,1,125,2647, 22763,105190, 296246, 540730, 655802, 526393, 269325, 79695, 10395, ,1,253,8568,109956,741405,3048381,8267448,15431088,20212011,18596935,11796400,4920300,1216215,135135)
and transposing it for a(n,k) = Δn(gk)(0),
>>> l=8;print(stratrix(tuple(transpose(tap(lambda n: fixlen(list(polychoose(fit(*tap(lambda k: subset(n+k,k),range(2*n+1))))),2*l-1),range(l)))),dims=2)) (1, , , , , , , , ,1,1, 1, 1, 1, 1, 1, ,1,5,13, 29, 61, 125, 253, , ,7,48, 211, 780, 2647, 8568, , ,3,76, 679, 4280, 22763, 109956, , , ,55,1151,12710,105190, 741405, , , ,15,1075,22506,296246, 3048381, , , , , 525,24556,540730, 8267448, , , , , 105,16240,655802,15431088, , , , , , 5985,526393,20212011, , , , , , 945,269325,18596935, , , , , , , 79695,11796400, , , , , , , 10395, 4920300, , , , , , , , 1216215, , , , , , , , 135135)
one notices that the columns (now rows) are linear-recurrent functions of their index! multiplying by the characteristic polynomial (∏ni=0(1-i*x), the nth row of the Stirling triangle of the first kind in reverse order), gives us a(n,k) = ∑ki=0((-1)i*[n+1n+1-i]*Δn(gk-i)(0)) = ∑ki=0((-1)i*[n+1n+1-i]*∑nj=0((-1)n-j*(nj)*{k-i+jj}))
>>> l=12;print(stratrix(tarmap(lambda n,p: (prod(map(lambda i: 1-i*x,range(1,n+1)))*p)[:~n],enumerate(tuple(transpose(tap(lambda n: fixlen(list(polychoose(fit(*tap(lambda k: subset(n+k,k),range(2*n+1))))),2*l-1),range(l)))))),dims=2)) (1, ,1, ,1,2, , ,7, 6, , ,3,46, 24, , , ,55,326, 120, , , ,15,760, 2556, 720, , , , ,525, 9856, 22212, 5040, , , , ,105,12460,128492, 212976, 40320, , , , , , 5985,257068,1731276, 2239344, 362880, , , , , , 945,217350,5031460, 24403176, 25659360, 3628800, , , , , , , 79695,6536530, 97266620, 361732536, 318540960, , , , , , , 10395,4109490,179386900,1896760536, 5649316992, , , , , , , ,1216215,169699530,4710611620, 37753410552, , , , , , , , 135135, 84504420,6219413200,121528014608, , , , , , , , , 20945925,4588043460,213050437600, , , , , , , , , 2027025,1886484600,216507050760, , , , , , , , , , 402026625,130300530360, , , , , , , , , , 34459425, 45555359850, , , , , , , , , , , 8511477975, , , , , , , , , , , 654729075)
row sums are A000262(n), column sums are A058349(k+1), a(n,n) = n! and a(n,n-1) = A067318(n) = n!*(n-Hn), a(2*n,n) = (2*n-1)!!
so we have
- A000262(n) = ∑nk=⌈n2⌉(∑ki=0((-1)i*[n+1n+1-i]*∑nj=0((-1)n-j*(nj)*{k-i+jj})))
compare with the much nicer existing forms
- A000262(n) = ∑nk=0(n!k!*(n-1k-1)) = ∑nk=0([nk]*∑ki=0({ki}))
and
- A058349(k+1) = ∑2*kn=k(∑ki=0((-1)i*[n+1n+1-i]*∑nj=0((-1)n-j*(nj)*{k-i+jj})))
compare with Vladimir Kruchinin's decidedly less nice form, from February 19, 2012
- A058349(n+1) = n!*∑nk=1((n+kn)*∑kj=1((kj)*∑j-1l=0((jl)*(1+(-1)n-l+j)*∑j-lr=1((j-lr)*2j-l-r-1*(-1)r-j*∑ri=0((r-2*i)n-l+j*(ri)))(n-l+j)!)))
the sequence states that its e.g.f. is the inverse of x+2*(1-cosh(x)), and equivalently by the logarithm of egf(A048172) = inverse(λ x: log(1+x) - x21+x), corresponding with A048172(n) = n!*∑nk=0(∑.
.l0+l1+...+lk-1=n
1≤li≤1+n-k(∏k-1i=0(A058349(li))))
for my attempts to prove this, see my OEIS wiki userspace page about it
| unlabelled | labelled | ||||||
|---|---|---|---|---|---|---|---|
| all | connected | all | connected | ||||
| all | parallel | all | parallel | all | parallel | all | parallel |
| A000112 | A003430 | A000608 | A007453 | A001035 | A048172 | A001927 | A058349 |
| exp(A001927) | (λ x: log(1+x)-x21+x)-1 | (λ x: x+2*(1-cosh(x)))-1 | |||||
Andrew Howroyd's comment upon A003430 is technically wrong due to the indexing, it should say gf(A003430) = 1+gf(A007454)1-gf(A007454), from which (with gf(A003430)=gf(A007453)+gf(A007454)+1-x) one has gf(A007453) = gf(A003430)+1gf(A003430)+x-2 and gf(A003430) = gf(A007453)-x+2 + √(gf(A007453)-x)*(gf(A007453)-x+4)2
- ↑ exists as recurrence relation 26.8.25 in the DLMF, which has a few other interesting ones as well
by adding a factor of (-1)i-k to the summand like the third form, one obtains A105794(n,k) = ∑ni=k((-1)i-k*{ik}*(ni)), and forgetting the binomial yields A105794(n+1,k+1) = ∑ni=k((-1)i-k*{ik})
A137596(n,k) = ∑ni=k({ik}) = (-1)k*(∑ki=2((-1)i*(k-1i-1)*in-ik-1i-1)+k-1-n)(k-1)! = (-1)k*(∑ki=2((-1)i*(ki)*in+1-iki-1)+(k-1-n)*k)k! - ↑ looks similar to recurrence relation 26.8.20 in the DLMF; one would imagine that one is missing the (ni) coefficient in the summand and therefore generating sequence A190782(n,k) instead of [n+1k+1]
however, their conventions use signed Stirling numbers of the first kind - ↑ equal to A269952(n,k) (= A143494(n+1,k+1)) for c=1
- ↑ equal to A094645(n,k) for c=1, A094646(n,k) for c=2
binomial decomposition
in general, for a fixed k, due to (n2*k) being an even function in n-k-1/2 and (n2*k+1)n-k in n-k, they are expressible in terms of functional compositions of a quadratic and a degree-k polynomial in n,
- (xn) = ∏k-1i=0(n-i)k! = ∏⌊n2⌋-1i=0(i*(n-1-i)+x*(1-n+x))n!*(x - n-12)n&1
since (-1)n-k*[nk]n! is the coefficient of xk in (xn), we can remove the signs and denominator by evaluating (-1)n*n!*(-xn)(x + n-12)n&1 = ∏⌊n2⌋-1i=0(i*(n-1-i)+x*(n-1+x)), whose expansion's xk coefficient is given by a function f(n,k) such that [nk] = f(n,k-1) + n-12*f(n,k) if n&1 else f(n,k), with
- f=λ n,k: ∑.
3⌊n2⌋-1t=0
digsum3(t)=k(∏⌊n2⌋-1i=0((i*(n-1-i),n-1,1)[⌊t3i⌋%3])) - equivalently, since the 1 digits behave the same irrespective of index, we can count them with c
- f=λ n,k: ∑.
kc=k&1
c≡k (mod 2)((n-1)c*((k+c)/2c)*∑.
.
2⌊n2⌋-1t=0
digsum2(t)=k+c2(∏⌊n2⌋-1i=0((i*(n-1-i),1)[t>>i&1])))
- f=λ n,k: ∑.
- remove the parity
- f=λ n,k: ∑⌊k2⌋c=0((n-1)2*c+k%2*(⌈k2⌉+c2*c+k%2)*∑.
.
2⌊n2⌋-1t=0
digsum2(t)=⌈k2⌉+c(∏⌊n2⌋-1i=0((i*(n-1-i),1)[t>>i&1])))
- f=λ n,k: ∑⌊k2⌋c=0((n-1)2*c+k%2*(⌈k2⌉+c2*c+k%2)*∑.
- setting c := ⌈k2⌉+c, 2*c+k%2 becomes 2*(c-⌈k2⌉)+k%2 = 2*(c - k+k%22)+k%2 = 2*c-k
- we can also avoid iterating over the zero multiplicand
- f=λ n,k: ∑min(k,⌊n2⌋-1)c=⌈k2⌉((n-1)2*c-k*(c2*c-k)*∑.
2⌊n2⌋-1-1t=0
digsum2(t)=c(∏⌊n2⌋-2i=0(((i+1)*(n-2-i),1)[t>>i&1])))
- f=λ n,k: ∑min(k,⌊n2⌋-1)c=⌈k2⌉((n-1)2*c-k*(c2*c-k)*∑.
- there are (nk) numbers with bit_length = n and bit_count = k (see #lexbin :-) so ∑min(k,⌊n2⌋-1)c=⌈k2⌉((⌊n2⌋-1c))*(⌊n2⌋-1) ∈ O((n/2k)*2k*n) multiplicands (with respect to n for worst-case k (at k=⌊⌊n2⌋+13⌋*2), ~ 2⌊n2⌋*n4)
- compare with the one obtained from the ordinary product (nk) = ∏k-1i=0(n-i)k!, equivalent to the DLMF's definition 26.8.3
- [nk] = ∑.
2n-1t=0
digsum2(t)=k(∏n-1i=0((i,1)[⌊t2i⌋%2]))
- [nk] = ∑.
- with (nk)*n multiplicands (worst-case k (either rounding of n2) yields (from Stirling's formula) n*A001405(n) ~ 2n*√2*n/π)
- since for odd n, [nk] = f(n,k-1) + n-12*f(n,k), n!*(x+n-1n) = gf(λ k: [nk]) = (n-12+x)*gf(λ k: f(n,k))
- note that there is a triangle which has f's odd rows as its even rows, A188286(2*n,k) = f(2*n+1,k)
mononomials, monochooses and g.f. numerators
let Δ<(f)(x)=f(x+1)-f(x) and ∑<(f)(x)=∑x-1i=0(f(i)) (iterates explained in my answer)
the point of the g.f. numerator row is for its series expansion to be a sum of offset binomials of maximal degree
| id | diff | inte | Δ< | ∑< | |
|---|---|---|---|---|---|
| monomial | xn ∑nk=0(⟨nk⟩*xk)(1-x)n+1 |
n*xn-1 | xn+1n+1 | ∑n-1k=0((nk)*xk) | ∑n+1k=1((n+1k)*B-n+1-k*xk)n+1 |
| monochoose | (xn) xn(1-x)n+1 |
∑n-1k=0((-1)n+~kn-k*(xk)) | ∑n+1k=1(Gn+1-k*(xk)) | (xn-1) | (xn+1) |
| g.f. num | (x+nn) 1(1-x)n+1 |
∑n-1k=0((-1)n+~k*∑n-1i=0((n+~ik-i)*n!n-i)*(x+n-1-kn-1)) (-1)n*∑n-1i=0((-x)i*(1-x)n+~i*n!n-i)(1-x)n[transTables 1] |
∑n+1k=1(∑ki=1(Gn+1-i*(-1)k-i*(n+1-ik-i))*(x+n+1-kn+1)) ∑n+1i=1(Gn+1-i*xi*(1-x)n+1-i)(1-x)n+2 |
(x+nn-1) | (x+nn+1) |
the denominator lcm for the choose integral in a g.f. seems to be A091137(n) = ∏.p ∈ ℙ(p⌊np-1⌋), the Hirzebruch numbers (agreeing beyond the point of divergence from n!*A002790(n))
that is to say, A091137(n)=lcm(map(λ k: denom(∑ki=1(Gn+1-i*(-1)k-i*(n+1-ik-i))),range(n+1)))=lcm(map(λ k: denom(Gk),range(n+1)))
as such, it appears the above Gregory coefficient formula's implied denom(Gn) | (n+1)!*lcm(1,2,...,n+1) can be improved to denom(Gn) | A091137(n) and (where A027760(n) = A091137(n)A091137(n-1)) also A027760(n) | denom(Gn)
since n! = ∏.p ∈ ℙ(p∑⌊logp(n)⌋i=1(⌊npi⌋))
from the bounds upon floordiv and floorlog, one gets
p⌊np-1⌋-⌊logp(n)⌋ ≤ p∑⌊logp(n)⌋i=1(⌊npi⌋) ≤ p⌊n-1p-1⌋, each of which holds for values n=pl-1 and n=pl
since ∏.p ∈ ℙ(p⌊logp(n)⌋) = lcm(range(1,n+1)) = A003418(n), where | denotes divisorhood,
(n+1)! | A091137(n) | n!*lcm(1,2,...,n+1)
this means that asymptotically, from Stirling's approximation and A003418(n) ~log en (where the ratio of the logarithms converges to 1), one has the surprisingly neat A091137(n) ~< √2*π*n*e*nn
A027760(n) = A091137(n)A091137(n-1), so we have (n+1)*nA003418(n) | A003418(n+1)A003418(n) | A027760(n) | A003418(n+1)
the second member of the chain, A003418(n+1)A003418(n) = A014963(n+1), has upper divisibility trivially and lower divisibility provided by n+1 and n being coprime
import matplotlib.pyplot as plot;r=λ: range(1,1<<8);tap(λ f: plot.scatter(r(),tap(λ n: log(f(n)),r())),(λ n: fact(n+1),λ n: prod(map(λ p: p**(n//(p-1)),primerange(n+2))),λ n: prod(map(λ p: p**ilog(n+1,p),primerange(n+2)))*fact(n)));plot.show()
~ ∑⌈√n⌉p=2((p ∈ ℙ)*log(p)*⌊⌊n+1p⌊logp(n+1)⌋⌋+(p-1)*⌊logp(n+1)⌋2-1p-1⌋) + ∑⌊n2⌋+1p=⌈√n⌉+1((p ∈ ℙ)*log(p)*(#({k ∈ ℤ: 1≤k≤n+1 ∧ ⌊n+1k⌋=p-1}) - (p-1|n+1)))
~ ∑⌈√n⌉p=2((p ∈ ℙ)*log(p)*⌊(p-1)*(⌊logp(n+1)⌋+1)2-1p-1⌋) + ∑n+1k=1((⌊n+1k⌋+1 ∈ ℙ)*log(⌊n+1k⌋+1)) - ∑⌊n2⌋+1p=⌈√n⌉+1((p ∈ ℙ)*log(p)*(p-1|n+1))
~ ∑⌈√n⌉p=2((p ∈ ℙ)*log(p)*logp(n+1)+12) + ∑n+1k=1(1log(⌊n+1k⌋+1)*log(⌊n+1k⌋+1)) - ∑⌊n2⌋+1p=⌈√n⌉+1(1log(p)*log(p)*n+1p-1) #this step onwards extremely heuristic
~ ∑⌈√n⌉p=2((p ∈ ℙ)*log(n+1)+log(p)2) + n - ∑⌊n2⌋p=⌈√n⌉(n+1p)
= π(⌈√n⌉)*log(n+1)2 + ϑ(⌈√n⌉)2 + n - (n+1)*(H⌊n2⌋+1-H⌈√n⌉)
~ 32*√n + n - (n+1)*(log(n)/2)
-->
note the Bernoulli number denominators have the analogous fact that den(Bn)=A002445|A027760(n)=∏ p ∈ ℙ,p-1|n(p) from the von Staudt–Clausen theorem
miscellaneous facts
- Where the block divisions in the x and y axes occur at the same indexes (ie. it is the same shape as its transpose, and all cells on the diagonal are members of square blocks with opposite corners on the diagonal), a diagonal block-matrix's determinant is the product of the determinants of the blocks along the diagonal
- Where m is a lower-triangular matrix (mx,y is nonzero only if x <= y) and m(x0:x1),(y0:y1), is the (x1-x0)×(y1-y0) matrix containing the corresponding subsection of m (like 2D slice notation but upper-inclusive),
- m-1x,y = (-1)x+y*det(m(x:y-1),(x+1:y))∏yi=x(mi,i)
- (see my StackExchange answer)
- Let (k|v) = (v ≡ 0 (mod k))
- For all prime k, τk(n) (mod k) is congruent to 1 if n is a kth power and 0 otherwise, since under action of ℤ/kℤ, each cyclic ordering has k distinct representatives except for the one into k√nk, which has 1.
- Recall that τk(n) = ∏.d ∈ ℙ(k+vald(n)-1vald(n)), so this provides (from prime power n) that (k+v-1v) ≡ (k|v) (mod k).
- For v=k, this provides a weaker version of Wolstenholme's theorem
- generatingfunctionological interpretations/variations of integral transforms:
-
- ℒ(f)=λ x: ∫0∞(f(t)*e-x*t dt)
- denote
- ℒ(f)(x) = ℒ(f)(1x)x = ∫0∞(λ t: f(t)*e-t/x)x = ∫0∞(λ t: f(x*t)*e-t)
- then we also have
- ℒ(f) = gf(egf-1(f))
- this is the inverse of the Borel transform
- Mellin transforms
- since x! = ∫0∞(tx*e-t dt), we can modify the Mellin transform
- ℳ(f)=λ x: ∫0∞(f(t)*tx-1 dt)
- to
- ℳ(f)=λ x: ∫0∞(f(t)*tx-1*e-t dt)(x-1)!
- then we have the curious fact
- ℳ(ogf(a))=rgf(a)
- that is,
- ℳ(λ t: ∑∞n=0(a(n)*tn))=λ x: ∑∞n=0(a(n)*xn)
- example: since [xn]H-x = -[n>0]n*n!, and ogf(λ n: [n>0]n*n!)(x) = Ei(x)-log(x)-γ, we have (from evaluating the latter two terms) ∫0∞(Ei(t)*tx-1*e-t dt)(x-1)! = ψ(x)+γ - (H-x:=Hx-1+π*cot(π*x)) = -π*cot(π*x), so ∫0∞(Ei(t)*tx*e-t dt)=-x!*π*cot(π*x)
- Cauchy's integral formula : list a complex function F's singularities' absolute values (without multiplicity) in order, s0,s1,..., then for an anticlockwise loop around the origin C such that si < |c| < si+1 for all c ∈ C, all points x also between those two roots may have F(x) computed by the Laurent series
- F(x) = ∑∞n=-∞(f(n)*xn)
- where
- f(n) = ∮C(F(x)xn+1 dx)2*π*i
- in general, (choosing the innermost radius of convergence) this is useful for ordinary Taylor series coefficient extraction
- also, Cauchy's inequality; for all r<s0
- |f(n)|≤max|x|=r(|F(x)|)rn
- (where the f(n) are nonnegative reals, this maximum will occur where sgn(x)=1)
- saddle point method (from page 115 onwards of Asymptotic enumeration methods in the external links):
- say one has a function whose maximum in any radius indeed occurs where sgn(x)=1, and that this maximum is also unique. find the (nonnegative real) input xn at which f(x)xn is minimised (a saddle point, since the absolute-value plot curves down with respect to angle and up with respect to radius).
- equivalently, define g(x) = x*f'(x)f(x) = x*(log ∘ f)'(x), then xn is the point (on the inside of the singularity) where g(xn)=n
- (if there are multiple such minima, this doesn't work, but nonnegative coefficients guarantee uniqueness)
- then [xn]f(x) ~ f(xn)√2*π*g'(xn)*xnn+1/2
- generatingfunctionology attributes this variation as Hayman's method, beginning at page 181
- also, gfology mentions this only as a means of showing that it's useful for singularityless functions, but Asymptotic enumeration methods mentions a broader range of applications.
- gfology gives Hayman's criteria for admissibility under this method on page 183, and helpfully gives a few; the set of admissible functions is closed under
- multiplication with each other,
- exp-taking,
- multiplication with polynomials whose output is positive over the positive reals,
- putting inside (or adding with) eventually-always-positive polynomials,
- and that an exp of a real-valued polynomial is admissible if its series expansion eventually becomes always-positive
- meanwhile, Asymptotic enumeration methods gives more general criteria; there must be a singularity X along the positive real line (or at ∞!) so that f grows at least as quickly as elog(X−x)2 as x approaches X from below, or elog(x)2 if X=∞
- say one has a function whose maximum in any radius indeed occurs where sgn(x)=1, and that this maximum is also unique. find the (nonnegative real) input xn at which f(x)xn is minimised (a saddle point, since the absolute-value plot curves down with respect to angle and up with respect to radius).
- there are many ways to represent degree-d polynomials as d+1 parameters (its expansion, forward differences sequence (inverse binomial transform), generating function numerator), but one surprisingly nice one is as its values in an arithmetic progression!
- P(n)=∑deg(P)i=0((ni)*(deg(P)-ni-n)*P(i))
- (this is especially useful when there is an arithmetic progression in which it contains many zero terms whose corresponding summands can be skipped, as in the Stirling numbers; answer there (with short derivation) is motivated by {nk}=[-k-n], which works according to the diagonals being polynomials (as well as many other formulations))
- the twentysevenfold way (similarly to the twelvefold way); let ordertitionsG,K,P(n,k) be the number of partitions of a set of n elements into k parts, where the set of parts is (unordered,cyclically ordered,totally ordered)[K] (considering parts of equal cardinality equivalent), and each part is (unordered,cyclically ordered,totally ordered)[P], where G determines whether elements are given global identifiers in the initial set (G=2), identifiers with final partitionings reduced to equivalence classes for cyclic shift of the identifiers (G=1), or local ones within their part (G=0)
- partmute=λ K,P,p: (choose(len(p),*map(rgetitem(1),rle(p))) if K==2 else len(sap(λ p: tuple(min(map(λ i: p[i:]+p[:i],range(k)))),multiset_permutations(p))) if K else 1)*(prod(map(fact,p)) if P==2 else prod(map(lambda i: fact(i-1),p)) if P else 1)
ordertitions=λ G,K,P: λ n,k: (sum(map(λ p: partmute(K,P,map(len,p)),multiset_partitions(range(n),k))) if G else sum(map(λ p: partmute(K,P,p),filter(λ p: len(p)==k,accel_asc(n))))) if k else int(not n)
- partmute=λ K,P,p: (choose(len(p),*map(rgetitem(1),rle(p))) if K==2 else len(sap(λ p: tuple(min(map(λ i: p[i:]+p[:i],range(k)))),multiset_permutations(p))) if K else 1)*(prod(map(fact,p)) if P==2 else prod(map(lambda i: fact(i-1),p)) if P else 1)
- then from running
- >>> print(stratrix(tap(λ n: tap(λ k: ordertitions(G,K,P)(n,k),range(n+1)),range(8)),keepzero=1))
- one obtains number triangles, some of which have OEIS entries
globally K\P unordered cyclic total unordered unordered A072233(n,k) A144351(n,k) A134134(n,k) cyclic A037306(n,k) total (n-1k-1) A084938(n,k) A090238(n,k) cyclic unordered A152175(n,k) cyclic total total unordered {nk} [nk] n!k!*(n-1k-1) cyclic (k-1)!*{nk} (k-1)!*[nk] (n-1)!*(nk) total k!*{nk} k!*[nk] n!*(n-1k-1)
- the reason for ordertitions(0,2,0)=λ n,k: (n-1k-1) is that one can write the set of n identical elements as a list with n-1 intervals between pairs and place k-1 separators into those (since where G=0, equal-length subsets are identified as equal)
- note that the modification a(n,0)=1 makes A037306 symmetrical (as proven by David Wasserman here)
- ordertitions(1,0,2)(n+1,n)=⌈n2⌉*2
- ordertitions(1,2,0)(n+1,n)=A185252(n)=∑⌈n2⌉k=0(k*(nk))
- ordertitions(2,2,0)(n,2)=A285917(n)=2n-2-(~n&1 and (nn/2)2), ordertitions(2,2,0)(n+1,n)=n*(n+1)*2n-2
- gf(A285917)=λ x: 11-2*x - 21-x + 3 - 1√1-4*x22
- ordertitions(2,2,2)(n+1,n)=n*(n+1)*2n-1
- and row sums (where formulas (ie. 2n-1) are not integer for n=0 or sequences (ie. A008965) are 1-indexed, note there is always 1 way to partition a set of 1 element)
globally K\P unordered cyclic total unordered
o.g.f.unordered A000041(n)
∏∞n=1(11-xn)A107107(n)
∏∞n=1(11-(n-1)!*xn)A077365(n)
∏∞n=1(11-n!*xn)cyclic A008965(n)
∑∞k=1(φ(k)k*log(11-∑∞n=1(xk*n)))total n==0 or 2n-1
11-∑∞n=1(xn)=1-x1-2*xA051295(n)
11-∑∞n=1((n-1)!*xn)A051296(n)
11-∑∞n=1(n!*xn)cyclic unordered A084423(n) cyclic total total
e.g.f.unordered A000110(n)
eex-1[misc 1]n!
elog(11-x)A000262(n)
ex1-xcyclic ((1,)+A000629)(n-1)
1+log(11-(ex-1))A000154(n)
1+log(11-log(11-x))n==0 or (n-1)!*(2n-1)
(1+A029767)(n)
1+log(11 - x1-x)=1+log(1-x1-2*x)total A000670(n)
11-(ex-1)A007840(n)
11-log(11-x)n==0 or n!*2n-1
A002866(n)
11 - x1-x=1-x1-2*x
- note that ∑nk=0([nk]*(A000110,A000629,A000670)[K](k)) = (A000262,A029767,A002866)[K](n), and likewise ∑nk=0((-1)n-k*{nk}*(A000262,A029767,A002866)[K](k)) = (A000110,A000629,A000670)[K](n), as a variant of the Stirling transform with signs swapped around
- the ∑nk=1(ordertitions(0,1,0)(n,k)) = A008965(n) g.f. can be rewritten
- . ∑∞k=1(φ(k)k*log(11-∑∞n=1(xk*n)))
= ∑∞k=1(φ(k)k*∑∞n=1((xk1-xk)nn))
= ∑∞k=1(φ(k)k*∑∞n=1(∑∞i=n((i-1n-1)*xk*i)n))
= ∑∞k=1(φ(k)k*∑∞i=1(∑in=1((i-1n-1)n)*xk*i))
= ∑∞k=1(φ(k)k*∑∞i=1(2i-1i*xk*i))
- . ∑∞k=1(φ(k)k*log(11-∑∞n=1(xk*n)))
- so A008965(n) = ∑.d|n(φ(d)*(2n/d-1))n (as mentioned in A346558)
- by blind pattern-following, assume
- gf(λ n: ∑nk=1(ordertitions(0,1,2)(n,k)))=λ x: ∑∞k=1(φ(k)k*log(11-∑∞n=1(n!*xk*n)))
- then
- = ∑∞k=1(φ(k)k*∑∞i=1(∑∞n=1(n!*xk*n)ii))
- Fourier series
- let f=ℱl(a) be a singularityless function on the range [0,l], then f(x)=∑∞n=0(a(n)*cos(π*n*xl)) and a(n)=1+sgn(n)l*∫0l(f(x)*cos(π*n*xl) dx)
- application to monomials:
- . ℱl-1(λ x: xp)(0)=1p
- all for n>0
- . ℱl-1(λ x: xp)
- = λ n: 2l*∫0l(∑∞k=0((-1)k*(π*nl)2*k*xp+2*k(2*k)!) dx)
- = λ n: 2l*∑∞k=0((-1)k*(π*nl)2*k*∫0l(xp+2*k dx)(2*k)!)
- = λ n: 2*lp*∑∞k=0((-1)k*(π*n)2*k(2*k)!*(2*k+p+1))
- = λ n: lp*∑∞k=0((-1)k*(π*n)2*k(2*k)!*(k+p+12))
- = λ n: 2*lp*∑∞k=0((-1/2)!*(p+12)!*(k+p-12)!(k-1/2)!*(k+p+12)!*(p-12)!*(-(π*n)24)kk!)p+1 #see #multifactorials
- = λ n: 2*lp*1F2(p+1212,p+32;-(π*n)24)p+1
- . ℱl-1(λ x: xp)
- small p evaluations that solve the Basel problem:
- ℱ1-1(λ x: 1)=λ n: (n==0)
- ℱ1-1(λ x: x)=λ n: -2*(1-(-1)n)(π*n)2 if n else 12
- from the evaluation of λ x: 1-x at x=1 (it must be nonzero at x=0 to have a series), 12=2π2*∑∞n=1(1-(-1)nn2), so π28=∑∞n=0(1(2*n+1)2)
- ℱ1-1(λ x: x2)=λ n: 4*(-1)n(π*n)2 if n else 13
- π212 = ∑∞n=1((-1)nn2)
- in page 16 of Two notes on notation, Knuth mentions a theorem from Richard P. Stanley's PhD thesis,
- given a poset P, let the number of order-preserving homomorphisms (that permit two comparable nodes to be mapped to the same element) from P to the totally-ordered list [0..n-1] be ΩP(n), and the number of strictly order-preserving homomorphisms (that don't permit this) be ωP(n), then they are both degree-|P| polynomials in k and in particular related by ωP(n)=(-1)|P|*ΩP(-n)!
- in there, Knuth gives a few examples,
- Pk a disjoint set of k nodes: ωPk(n)=ΩPk(n)=nk (since in general, the union of two posets has the product of the polynomials)
- Pk a totally-ordered set of n nodes: ωPk(n)=(nk), and ΩPk(n)=(k-1+nk) by straightforward combinatorics; as such, the fact that (-1)k*(-nk)=(k-1+nk) is a special case of Stanley's theorem!
- Pk a totally-ordered set of n nodes (called xi), each with its own foot leading downwards to a yi (when oriented with edges' arrows pointing upwards towards greater nodes) to form a centipede; the y set's only constraint is that yi<xi: ωPk(n)=[nn-k], and ΩPk(n)={n+kn}; {nk}=[-k-n] is also a special case!
- and now some (probably known) results from experimentation of my own!
- (note we use sf(n) from #log-factorial integration)
- tie the centipede's shoelaces together, to form a poset which (when plotted out as a directed graph) is a sequence of connected squares (or a diagonally-oriented 2×k array of vertices), then ωPk(n)=n!*(n-1)!(n-k)!*(n-k-1)!*k!*(k+1)!=A001263(n,k+1), and ΩPk(n)=(n+k)!*(n+k-1)!n!*(n-1)!*k!*(k+1)!=A001263(n+k,k+1)
- Pj,k a j×k diagonally-oriented array, with a partial order based on coordinates, that (x0,y0)≤(x1,y1) iff x0≤x1 and y0≤y1, then ωPj,k(n)=∏j-1i=0(i!*(n-i)!(n-i-k)!*(k+i)!)=∏ji=1((n-i+1)kik), ΩPj,k(n)=∏j-1i=0(i!*(n+k-1+i)!(n-1+i)!*(k+i)!)=∏ji=1((n+i-1)kik)
- note that by the hook length formula , the number of bijective homomorphisms is a divisor of the total number of permutations, (j*k)!∏ji=1(∏kl=1(i+l-1)) = (j*k)!∏ji=1(ik)
- the shared denominator for each of these is the 'superbinomial' sb(j+kj,k) = sf(j+k)sf(j)*sf(k), so we get
- unstrict: sf(n-1)*sf(n+j+k-1)sf(n+j-1)*sf(n+k-1)sb(j+kj,k) = sb(n-1+j+kj+k)sb(n-1+jj)*sb(n-1+kk)
- strict: sf(n+1)*sf(n-j-k+1)sf(n-j+1)*sf(n-k+1)sb(j+kj,k) = sb(n+1j+k)sb(n+1-jk)*sb(n+1-kj)
- injective: n!(n-j*k)!*sb(j+kj,k)
- in general, sb(nk)=A090441(n-1,k)
- the third page of this paper gives the result that if you define ωP,v(n,k),ΩP,v(n,k) to be the numbers of homomorphisms σ: P->[n] such that σ(v)=k, then for any fixed P,v,n the sequence with respect to k is log-concave.
- Pólya enumeration theorem number theory
- cp+(p-1)*cp ways to colour a length-p necklace in c colours
- each cycle period d has φ(d) shifts with full-period-d cycles; hence, for non-prime n, ∑nx=0(cngcd(n,x))n = ∑d|n(φ(nd)*cd)n
- p!+(p-1)2*pp2 ways to configure p nonattacking rooks on a p×p torus
- note that for a shift (x,y), one must have (d:=gcd(x,n))=gcd(y,n), since otherwise (if the x-shift's period is lower) the process of placing rooks to make them closed under the shift would run into two being attacking vertically. So for each satisfying pair, one can begin with a permutation of d elements in a d×d subsquare, shift each one up by its own multiple of d and then copy into all other width-d panes, to get ∑n-1x=1(∑n-1y=1([(d:=gcd(x,n))=gcd(y,n)]*(nd)d*d!))n2 = ∑d|n(φ(nd)2*(nd)d*d!)n2 = ∑d|n(φ(nd)2*(nd)d-1*(d-1)!)n = A002619(n)
- as mentioned in Richard L. Ollerton's 2021-05-09 comment there, multiplying the summands by a cd enumerates colourings of the d cycles of rooks in each configuration with c colours
- cp+(p-1)*cp ways to colour a length-p necklace in c colours
- two-body problems! (in 2D, where cross product's output is scalar)
- without loss of generality, assume a massless observer around a unit-mass object at the origin. denote by r its displacement vector, and by r its distance.
- ddt(r×ṙ) = ddt(x*ẏ-ẋ*y) = (ẋ*ẏ+x*ÿ) - (ẍ*y+ẋ*ẏ) = x*ÿ-ẍ*y = r×r̈
- where acceleration acts radially (as here), this cross product equals zero so r×ṙ is constant (conservation of angular momentum); denote it by h=|h|, where h=ṙ-ṙ*sgn(r). likewise,
- ddt(r⋅ṙ) = r⋅r̈ + ṙ⋅ṙ = r⋅r̈ + |ṙ|2 = r⋅r̈ + |ṙ|2 = r*r̈ - h2r2 + ṙ2 + (θ̇*r)2 = r*r̈ - h2r2 + ṙ2 + (hr)2 = r*r̈ + ṙ2
- now some standard results:
- ṙ = drdr2*(dr2dx*ẋ+dr2dy*ẏ) = dr2dx*ẋ+dr2dy*ẏ2*r = 2*x*ẋ+2*y*ẏ2*r = x*ẋ+y*ẏr = r⋅ṙr
- θ̇ = ddtatan(yx) = 11+(yx)2*dyxdt = x*ẏ-ẋ*yx2+y2 = r×ṙr2 = hr2
- r̈ = (r×ṙ)2r3 + r⋅r̈r = h2r3 + r⋅r̈r
- θ̈ = r×r̈r2 - 2*(r×ṙ)*(r⋅ṙ)r4 = 0 - 2*h*(r⋅ṙ)r4
- let u = 1r, then ṙ = d1udθ*θ̇ = -dudθ*r2*θ̇ = -dudθ*h and r̈ = dṙdθ = θ̇*(ddθ)2(ṙ) = -h*θ̇*(ddθ)2(u) = - h2r2*(ddθ)2(u)
- Hooke's law:
- r̈ = -r
- when split into axial components, they are independent; (xy)=(c0*cos(t-c1)c2*cos(t-c3)), with h = c0*c2*sin(c3-c1). we also have
- r = sqrt((c02*cos(2*c1) + c22*cos(2*c3))*cos(2*t) + (c02*sin(2*c1) + c22*sin(2*c3))*sin(2*t) + c02 + c222)
- inverse-square law:
- r̈ = - sgn(r)r2 = - rr3
- r̈ = h2r3 - 1r2
- -h2*u2*(ddθ)2(u) = h2*u3 - u2
- -(ddθ)2(u) = u - 1h2
- solving diffeq,
- u = 1h2 + c0*cos(θ-c1)
- and solving boundaries,
- u(t) = 1h2 + (1r(0) - 1h2)*cos(θ(t)-θ(0)) + ṙ(0)h*sin(θ(t)-θ(0))
- neglecting c1, since r'(θ) = c*sin(θ)(1h2+c*cos(θ))2, the total length is
- ∫02*π √r(θ)2+r'(θ)2 dθ = ∫02*π sqrt(1 + c2*sin(θ)2(1h2+c*cos(θ))2)1h2+c*cos(θ) dθ = ∫02*π √1+2*c*h2*cos(θ)+c2*h4(1h+h*c*cos(θ))2 dθ
- the periapsis is 11h2+c and the apoapsis 11h2-c; their arithmetic mean (semi-major) is h21-c2*h4 and their geometric mean (semi-minor) is h2√1-c2*h4, so the eccentricity is √1-minor/major=c*h2, so the total circumference is the second complete elliptic integral 4*h21-c2*h4*E(c*h2) = 2*π*h21-c2*h4*2F1(12,-121;c2*h4) (which equals 2*π*h2*2F1(12,321;c2*h4) by Euler's hypergeometric transformation)
- without loss of generality, assume a massless observer around a unit-mass object at the origin. denote by r its displacement vector, and by r its distance.
notes
external links
- the twofold reducer on Github (also featuring a bitwise Wolfram rule implementation (with minimal logic gate assemblages), sorry for it being in the tablebase program's repository)
open-access things I've seen that either I enjoyed/got use from/intend to read or may appeal to those who find any of this page interesting
(you may notice glaring omissions; these are due to the strictness of the open-access criterion)
- Herbert S. Wilf, generatingfunctionology (my belovedmost of books)
- A. M. Odlyzko, Asymptotic enumeration methods (as recommended by Vaclav Kotesovec !!!! expounds upon saddle pointery ('Hayman's method') considerably)
- Wilf again, Doron Zeilberger, Marko Petkovšek, A=B (1996, largely on hypergeometrics)
- Richard P. Stanley, Differentiably Finite Power Series (June 1980) European Journal of Combinatorics Vol. 1, Iss. 2, pp. 175-188
- (the paper uses P-recursive to refer to sequences and D-finite to refer to their generating functions (ordinary or exponential, it doesn't matter); in the OEIS this is usually abbreviated to D-finite and used for both sequences and series)
- Jet Wimp, Doron Zeilberger, Resurrecting the Asymptotics of Linear Recurrences (1985)
- confusingly, it uses the term 'linear recurrence' to refer to D-finitude
- Rida Ait El Manssour, Anna-Laura Sattelberger, Bertrand Teguia Tabuguia, D-Algebraic Functions (2023)
- functions defined by their boundary conditions and their vanishing under a mixture of exponentiation and differentiation (with polynomial coefficients), to form a set that contains algebraics and D-finites, satisfy various closure properties as well!
- Emil Artin, The Gamma function (1931)
- Donald Knuth,
- Two notes on notation (1992)
- Mircea Dan Rus, Yet another note on notation (2025), on the notation k{n}=k!*{nk} for enumerating partitions into labelled sets (or as the kth term of the inverse binomial transform of λ x: xn directly; extremely soulful in general)
- The Art of Computer Programming, Pre-Fascicle 1A, Draft of Section 7.1.3 (2008, very very good pre-fascicle, concerning bitwise operators :-)
- Two notes on notation (1992)
- Stanford, bit-twiddling hacks
- Mark Dickinson (Python core maintainer
and the discoverer of the spaceship operator)'s efficient 64-bit square-root for integers known to be squares
- Mark Dickinson (Python core maintainer
- Philippe Flajolet, Robert Sedgewick, Analytic Combinatorics (2009)
- Frank Ruskey, Combinatorial Generation (exceedingly delightful)
- UNCG Summer School - 2013 (contains some information on polynomial factorisation algorithms)
- Pavel Atnashev, Multiplication, exponentiation and factorization of big numbers (as recommended by Darren Li, who is acknowledged therein :-)
- John D. Lipson, Newton's Method: A Great Algebraic Algorithm (on how to do things like polynomial division in the same complexity as an FFT for multiplication)
- Hao Ze, Fast Power Series Inversion: Newton’s Iteration and the Middle Product Optimization (shaves off constant factor)
- Kaare Brandt Petersen and Michael Syskind Pedersen, The Matrix Cookbook (explains all manner of things with calculus upon matrices)
- NIST's Digital Library of Mathematical Functions (is quite useful, if you can get past its somewhat idiosyncratic syntax that seemingly always takes after the first convention ever adopted for everything; s(n,k) for (-1)n-k*[nk], Kummer's and Tricomi's conventions for confluent hypergeometrics, (x)n for Pochhammers)
- complex function domain colourer (that enables one to plot over the split-complex plane also, in which many things are different (ie. trigonometric functions are periodic in both axes))
- Michael Somos, Introduction to Ramanujan theta functions (txt version of introduction section)
- things concerning computing things modulo prime powers for Chinese remaindering together
- Jean-Guillaume Dumas, On Newton-Raphson iteration for multiplicative inverses modulo prime powers
- Andrew Granville, Binomial coefficients modulo prime powers (see also Arithmetic properties of Binomial Coefficients)
- Jianing Song, Formula for A349593
- A349593(n,k) is the period of the nth column of Pascal's triangle modulo k (which is multiplicative in k :-)
- note that since one has A349593(n,k) | A349593(n+1,k), any polynomial p with integer outputs (given by integer combination of choose functions) has period A349593(deg(p),k) mod k
- more generally, an order-n linear-recurrent sequence modulo k has maximal period A059380(n,k) (though see A059379 (the other orientation) for formulas)
- Edsgar W. Dijkstra, note 831 (extolling the merits of zero-indexed upper-exclusive ranges)
- Henry W. Gould's page (contains an eight-volume free version of his book with combinatorial identities)
- Jonathan Sondow's page (contains quite a few cool identities)
- Marko Riedel's page (similar but also has links to the context (usually math.se) where the identities arose)
- analytic number theory
- Bernhard Riemann, On the Number of Prime Numbers less than a Given Quantity (1859-11, see also Wikipedia page; this translation by David R. Wilkins, 1998-12)
things Magma has shown me (that are also included here by merit of availability for free but that I have not read yet)
- Allen Hatcher, Algebraic Topology