Source/Packages

Std.Natural

packages/foundation/standard/src/Std/Natural.alpha

376 lines51 declarations16.0 KiBSHA-256 7e7128c5e781

def · lines 297–305

naturalBelowTwoPower

Full file
"value < 2^bits" WITHOUT building 2^bits: halve bits times and ask whether anything is left. The general form of naturalBelowBytePower (a byte is eight halvings); it is what a limit such as "fits int64" (bits = 63) or "at most 16 MiB of input" (bits = 24) must use at runtime, since 2^24 alone costs 2.75 GB to materialise and 2^63 cannot be materialised at all.
297def naturalBelowTwoPower =
298  (lambda unrestricted bits : Nat . unrestricted value : Nat .
299    naturalIsZero
300      (nat-eliminate
301        (lambda unrestricted current : Nat . Nat)
302        value
303        (lambda unrestricted predecessor : Nat . unrestricted quotient : Nat .
304          naturalDivideUnchecked quotient 2)
305        bits))

The compiler supplied declaration spans and resolved links from this source snapshot. This page does not assert that this file belongs to a checked closure.