Skip to content

KAlmostPrimes ​

The kk-almost primes -- integers with exactly kk prime factors, counted with multiplicity (Ω(n)=k\Omega(n)=k) -- as a lazy indexed family, one collection per kk.

KAlmostPrimes(k)the nn with Ω(n)=k\Omega(n) = k, an infinite indexed collection for every k≥1k \geq 1.
Typed signatures
TypePackageApplies
(integer<0..>) -> indexed_collection<integer>combinatoricsalways

Domain: Collections

Details
  • A lazy indexed collection for each kk: Count(KAlmostPrimes(k))=+∞Count(KAlmostPrimes(k)) = +\infty -- 2k−1p2^{k-1}p has Ω=k\Omega = k for every prime pp. KAlmostPrimes(1)KAlmostPrimes(1) is PrimeNumbers verbatim; KAlmostPrimes(2)KAlmostPrimes(2) is SemiprimeNumbers verbatim.
  • At(KAlmostPrimes(k),i)At(KAlmostPrimes(k), i) unranks the ii-th match by scanning forward, factoring each candidate -- At(KAlmostPrimes(3),1)=8At(KAlmostPrimes(3), 1) = 8 (232^3).
  • Membership goes through Element: Element(30,KAlmostPrimes(3))Element(30, KAlmostPrimes(3)) is true (2×3×52\times3\times5), Element(30,KAlmostPrimes(2))Element(30, KAlmostPrimes(2)) is false.

Definition

Epsil, as the implementation runs it.

count(_k)

0 if _k < 0 else 1 if _k == 0 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 Apply(
                                                                                     (fw_e: list<integer>) => fw_e[3] +
                                                                                                              (1 if fw_e[1] > 1 else 0) ==
                                                                                                              _k,
                                                                                     Fold(
                                                                                           Function(fw_w if fw_w[2] * fw_w[2] >
                                                                                                            fw_w[1] else [
                                                                                                                    fw_w[1] / fw_w[2],
                                                                                                                    fw_w[2],
                                                                                                                    fw_w[3] + 1,
                                                                                                                    fw_w[4] +
                                                                                                                    (1 - fw_w[5]),
                                                                                                                    1,
                                                                                                                  ] if fw_w[1] % fw_w[2] ==
                                                                                                                      0 else [fw_w[1], fw_w[2] + 1, fw_w[3], fw_w[4], 0], fw_w, fw_i),
                                                                                           [sn_k, 2, 0, 0, 0],
                                                                                           Range(1, Floor(Sqrt(sn_k)) +
                                                                                                    Floor(Log(sn_k, 2)) +
                                                                                                    2, 1),
                                                                                         ),
                                                                                   ) else sn_s, sn_s, sn_k),
             0,
             Range(
                    1,
                    1 if _k < 1 else 2 ^ (_k - 1) * Apply(
                                                           (pb_n: integer) => 11 if pb_n < 6 else Floor(pb_n *
                                                                                                        (Ln(pb_n) + Ln(Ln(pb_n)))) +
                                                                                                  1,
                                                           _r + 1,
                                                         ),
                    1,
                  ),
           ),
     )

rank(_k, _x)

Fold(Function(sn_c + 1 if Apply(
                                 (fw_e: list<integer>) => fw_e[3] +
                                                          (1 if fw_e[1] > 1 else 0) == _k,
                                 Fold(
                                       Function(fw_w if fw_w[2] * fw_w[2] >
                                                        fw_w[1] else [
                                                                fw_w[1] /
                                                                fw_w[2],
                                                                fw_w[2],
                                                                fw_w[3] + 1,
                                                                fw_w[4] + (1 -
                                                                           fw_w[5]),
                                                                1,
                                                              ] if fw_w[1] %
                                                                  fw_w[2] == 0 else [
                                                                               fw_w[1],
                                                                               fw_w[2] +
                                                                               1,
                                                                               fw_w[3],
                                                                               fw_w[4],
                                                                               0,
                                                                             ], fw_w, fw_i),
                                       [sn_k, 2, 0, 0, 0],
                                       Range(1, Floor(Sqrt(sn_k)) +
                                                Floor(Log(sn_k, 2)) + 2, 1),
                                     ),
                               ) else sn_c, sn_c, sn_k), 0, Range(1, _x - 1, 1)) if (Apply(
                                                                                           (fw_e: list<integer>) => fw_e[3] +
                                                                                                                    (1 if fw_e[1] > 1 else 0) ==
                                                                                                                    _k,
                                                                                           Fold(
                                                                                                 Function(fw_w if fw_w[2] * fw_w[2] >
                                                                                                                  fw_w[1] else [
                                                                                                                          fw_w[1] / fw_w[2],
                                                                                                                          fw_w[2],
                                                                                                                          fw_w[3] + 1,
                                                                                                                          fw_w[4] +
                                                                                                                          (1 - fw_w[5]),
                                                                                                                          1,
                                                                                                                        ] if fw_w[1] % fw_w[2] ==
                                                                                                                            0 else [fw_w[1], fw_w[2] + 1, fw_w[3], fw_w[4], 0], fw_w, fw_i),
                                                                                                 [_x, 2, 0, 0, 0],
                                                                                                 Range(1, Floor(Sqrt(_x)) +
                                                                                                          Floor(Log(_x, 2)) +
                                                                                                          2, 1),
                                                                                               ),
                                                                                         ) if _x >= 1 else False) else -1

valid(_k, _x)

Apply(
       (fw_e: list<integer>) => fw_e[3] + (1 if fw_e[1] > 1 else 0) == _k,
       Fold(
             Function(
                       fw_w if fw_w[2] * fw_w[2] > fw_w[1] else [
                                                                  fw_w[1] /
                                                                  fw_w[2],
                                                                  fw_w[2],
                                                                  fw_w[3] + 1,
                                                                  fw_w[4] + (1 -
                                                                             fw_w[5]),
                                                                  1,
                                                                ] if fw_w[1] %
                                                                    fw_w[2] == 0 else [
                                                                                 fw_w[1],
                                                                                 fw_w[2] + 1,
                                                                                 fw_w[3],
                                                                                 fw_w[4],
                                                                                 0,
                                                                               ],
                       fw_w,
                       fw_i,
                     ),
             [_x, 2, 0, 0, 0],
             Range(1, Floor(Sqrt(_x)) + Floor(Log(_x, 2)) + 2, 1),
           ),
     ) if _x >= 1 else False

Enumeration

Examples

1 more kept as data, checked against the oracles
About
Examples1
CrosswalkOEIS

See also: Count, At, Element, PrimeNumbers, SemiprimeNumbers, RoughNumbers