Skip to content

SmoothNumbers ​

The kk-smooth numbers -- positive integers with every prime factor ≤k\le k -- as a lazy indexed family, one collection per kk.

SmoothNumbers(k)the positive integers whose prime factors are all ≤k\le k, an infinite indexed collection.
Typed signatures
TypePackageApplies
(integer<0..>) -> indexed_collection<integer>combinatoricsalways

Domain: Collections

Details
  • A lazy indexed collection for each kk: Count(SmoothNumbers(k))=+∞Count(SmoothNumbers(k)) = +\infty, and At(SmoothNumbers(k),i)At(SmoothNumbers(k), i) unranks the ii-th kk-smooth number -- At(SmoothNumbers(7),1)=1At(SmoothNumbers(7), 1) = 1 (vacuously smooth).
  • 7-smooth numbers are OEIS A002473.
  • Membership goes through Element: Element(12,SmoothNumbers(7))Element(12, SmoothNumbers(7)) is true (its factors 2,3≤72, 3 \le 7), Element(22,SmoothNumbers(7))Element(22, SmoothNumbers(7)) is false (22=2×1122 = 2 \times 11).

Definition

Epsil, as the implementation runs it.

count(_k)

1 if _k < 2 else PositiveInfinity

unrank(_k, _r)

Apply(
       (sn_f: integer) => sn_f if sn_f > 0 else `NaN`,
       Fold(Function(
                      sn_s if sn_s > 0 else (sn_k if sn_s + _r == 0 else sn_s -
                                                                         1) if (sn_k ==
                                                                               1 if _k < 2 else Fold(
                                                                                                     Function(sm_w if sm_w[1] == 1 ||
                                                                                                                      sm_w[2] > _k else [sm_w[1] / sm_w[2], sm_w[2]] if sm_w[1] % sm_w[2] ==
                                                                                                                                                            0 else [sm_w[1], sm_w[2] + 1], sm_w, sm_i),
                                                                                                     [sn_k, 2],
                                                                                                     Range(1, _k +
                                                                                                              Floor(Log(sn_k, 2)) +
                                                                                                              1, 1),
                                                                                                   )[1] ==
                                                                                               1) else sn_s,
                      sn_s,
                      sn_k,
                    ), 0, Range(1, 1 if _k < 2 else 2 ^ (_r + 1 - 1), 1)),
     )

rank(_k, _x)

Fold(
      Function(sn_c + 1 if (sn_k == 1 if _k < 2 else Fold(
                                                           Function(
                                                                     sm_w if sm_w[1] ==
                                                                             1 ||
                                                                             sm_w[2] >
                                                                             _k else [
                                                                                     sm_w[1] / sm_w[2],
                                                                                     sm_w[2],
                                                                                   ] if sm_w[1] % sm_w[2] ==
                                                                                       0 else [sm_w[1], sm_w[2] + 1],
                                                                     sm_w,
                                                                     sm_i,
                                                                   ),
                                                           [sn_k, 2],
                                                           Range(
                                                                  1,
                                                                  _k +
                                                                  Floor(Log(
                                                                             sn_k,
                                                                             2,
                                                                           )) + 1,
                                                                  1,
                                                                ),
                                                         )[1] == 1) else sn_c, sn_c, sn_k),
      0,
      Range(1, _x - 1, 1),
    ) if ((_x == 1 if _k < 2 else Fold(
                                       Function(
                                                 sm_w if sm_w[1] == 1 || sm_w[2] >
                                                                         _k else [
                                                                                 sm_w[1] / sm_w[2],
                                                                                 sm_w[2],
                                                                               ] if sm_w[1] % sm_w[2] ==
                                                                                   0 else [sm_w[1], sm_w[2] + 1],
                                                 sm_w,
                                                 sm_i,
                                               ),
                                       [_x, 2],
                                       Range(1, _k + Floor(Log(_x, 2)) + 1, 1),
                                     )[1] == 1) if _x >= 1 else False) else -1

valid(_k, _x)

(_x == 1 if _k < 2 else Fold(Function(
                                       sm_w if sm_w[1] == 1 || sm_w[2] > _k else [
                                                                                   sm_w[1] / sm_w[2],
                                                                                   sm_w[2],
                                                                                 ] if sm_w[1] % sm_w[2] ==
                                                                                     0 else [sm_w[1], sm_w[2] + 1],
                                       sm_w,
                                       sm_i,
                                     ), [_x, 2], Range(1, _k +
                                                         Floor(Log(_x, 2)) + 1, 1))[1] == 1) if _x >=
                                                                           1 else False

Enumeration

Examples

Scope #

The first ten 7-smooth numbers

live ↗
InTake(SmoothNumbers(7),10)\mathrm{Take}(\mathrm{SmoothNumbers}(7), 10)Out[1,2,3,4,5,6,7,8,9,10]\bigl\lbrack1, 2, 3, 4, 5, 6, 7, 8, 9, 10\bigr\rbrack
About
Examples1

See also: Count, At, Element, PrimeNumbers