Skip to content

PowersOfTwo ​

The powers of two 1,2,4,8,…1, 2, 4, 8, … — subsets of an nn-set; row-sums of Pascal's triangle.

PowersOfTwo2n−12^{n-1} for n=1,2,3,…n = 1, 2, 3, ….

Domain: Collections

Details
  • A lazy indexed collection: Count(PowersOfTwo)=+∞Count(PowersOfTwo) = +\infty, and At(PowersOfTwo,k)=2k−1At(PowersOfTwo, k) = 2^{k-1} unranks in closed form, exact for every kk -- At(PowersOfTwo,60)At(PowersOfTwo, 60) is exact past 2532^{53}, not a rounded double.
  • OEIS A000079.
  • Membership goes through Element by the bit trick x&(x−1)=0x \mathbin{\&} (x-1) = 0 -- Element(64,PowersOfTwo)Element(64, PowersOfTwo) is true, Element(48,PowersOfTwo)Element(48, PowersOfTwo) is false.
  • Count(Subsets(n))=At(PowersOfTwo,n+1)Count(Subsets(n)) = At(PowersOfTwo, n+1); see Subsets.

Definition

Epsil, as the implementation runs it.

count()

PositiveInfinity

unrank(_r)

2 ^ _r

rank(_x)

Apply(
       (sq_at: integer) => sq_at if 2 ^ sq_at == _x else -1,
       Fold(Function(
                      sq_at + 2 ^ sq_b if 2 ^ (sq_at + 2 ^ sq_b) <= _x else sq_at,
                      sq_at,
                      sq_b,
                    ), 0, Range(Floor(Log(Floor(Log(_x, 2)) + 2, 2)) + 1, 0, -1)),
     ) if True else -1

valid(_x)

Apply(
       (sq_at: integer) => 2 ^ sq_at == _x,
       Fold(Function(
                      sq_at + 2 ^ sq_b if 2 ^ (sq_at + 2 ^ sq_b) <= _x else sq_at,
                      sq_at,
                      sq_b,
                    ), 0, Range(Floor(Log(Floor(Log(_x, 2)) + 2, 2)) + 1, 0, -1)),
     ) if True && _x >= 1 else False

Enumeration

Examples

1 more kept as data, checked against the oracles
Properties #
live ↗
In64∈PowersOfTwo64∈\mathrm{PowersOfTwo}OutTrue\mathrm{True}
live ↗
In48∈PowersOfTwo48∈\mathrm{PowersOfTwo}OutFalse\mathrm{False}
About
Examples3
CrosswalkOEIS

See also: Subsets, FactorialNumbers, Count, At, Element