Skip to content

FactorialNumbers ​

The factorials 1,2,6,24,…1, 2, 6, 24, … — n!n! — the number of permutations of nn items.

WikipediaFactorialMathWorldFactorialWikidataQ120976Encyclopedia of MathematicsFactorialnLabfactorialBritannicatopic/factorialOEISA000142mathlib4Nat.factorialMATLABfactorial
FactorialNumbersn!n! for n=1,2,3,…n = 1, 2, 3, ….

Domain: Collections

Details
  • A lazy indexed collection: Count(FactorialNumbers)=+∞Count(FactorialNumbers) = +\infty, and At(FactorialNumbers,k)=k!At(FactorialNumbers, k) = k! -- exact for every kk, since every term is computed over arbitrary-precision integers rather than floats -- At(FactorialNumbers,20)=2432902008176640000At(FactorialNumbers, 20) = 2432902008176640000, already past 2532^{53}.
  • OEIS A000142, whose offset differs from ours: A000142 opens a(0)=a(1)=1a(0) = a(1) = 1 (the duplicate 0!=1!=10! = 1! = 1); this collection starts at n=1n=1, so At(FactorialNumbers,1)=1At(FactorialNumbers, 1) = 1 without repeating.
  • Membership goes through Element by growing the factorial sequence forward until it reaches or passes the candidate -- Element(720,FactorialNumbers)Element(720, FactorialNumbers) is true, Element(700,FactorialNumbers)Element(700, FactorialNumbers) is false. See Factorial for the scalar function.

Definition

Epsil, as the implementation runs it.

count()

PositiveInfinity

unrank(_r)

Fold(Function([wk_w[1] * (wk_n + 2)], wk_w, wk_n), [1], Range(0, _r - 1, 1))[1]

rank(_x)

Fold(
      Function(
                wk_w if wk_n >= 0 && wk_w[1] > _x else [
                                                         wk_w[1] * (wk_n + 2),
                                                         wk_n if wk_w[2] < 0 &&
                                                                 wk_w[1] == _x else wk_w[2],
                                                       ],
                wk_w,
                wk_n,
              ),
      [1, -1],
      Range(
             0,
             1 * (Apply(
                         (fl_r: list<integer>) => fl_r[2],
                         Fold(Function(
                                        [
                                          (fl_s[1] - fl_s[1] % 2 ^ fl_k) / 2 ^
                                                                           fl_k,
                                          fl_s[2] + fl_k,
                                        ] if fl_s[1] >= 2 ^ fl_k else fl_s,
                                        fl_s,
                                        fl_k,
                                      ), [_x + 2, 0], [
                                                       8_192,
                                                       4_096,
                                                       2_048,
                                                       1_024,
                                                       512,
                                                       256,
                                                       128,
                                                       64,
                                                       32,
                                                       16,
                                                       8,
                                                       4,
                                                       2,
                                                       1,
                                                     ]),
                       ) + 1) + 12,
             1,
           ),
    )[2] if _x >= 0 else -1

valid(_x)

Fold(
      Function(
                wk_w if wk_n >= 0 && wk_w[1] > _x else [
                                                         wk_w[1] * (wk_n + 2),
                                                         wk_n if wk_w[2] < 0 &&
                                                                 wk_w[1] == _x else wk_w[2],
                                                       ],
                wk_w,
                wk_n,
              ),
      [1, -1],
      Range(
             0,
             1 * (Apply(
                         (fl_r: list<integer>) => fl_r[2],
                         Fold(Function(
                                        [
                                          (fl_s[1] - fl_s[1] % 2 ^ fl_k) / 2 ^
                                                                           fl_k,
                                          fl_s[2] + fl_k,
                                        ] if fl_s[1] >= 2 ^ fl_k else fl_s,
                                        fl_s,
                                        fl_k,
                                      ), [_x + 2, 0], [
                                                       8_192,
                                                       4_096,
                                                       2_048,
                                                       1_024,
                                                       512,
                                                       256,
                                                       128,
                                                       64,
                                                       32,
                                                       16,
                                                       8,
                                                       4,
                                                       2,
                                                       1,
                                                     ]),
                       ) + 1) + 12,
             1,
           ),
    )[2] >= 0 if _x >= 0 else False

Enumeration

Examples

1 more kept as data, checked against the oracles
About
Examples1
CrosswalkWikipediaMathWorldWikidataEncyclopedia of MathematicsnLabBritannicaOEISmathlib4MATLAB

See also: Factorial, DoubleFactorialNumbers, SymmetricGroup, Count, At, Element