Returns the least power of two that's greater than or equal to n
.
Examples:
Nat.nextPowerOfTwo 0 = 1
Nat.nextPowerOfTwo 1 = 1
Nat.nextPowerOfTwo 2 = 2
Nat.nextPowerOfTwo 3 = 4
Nat.nextPowerOfTwo 5 = 8
Equations
@[irreducible]
Equations
- Nat.nextPowerOfTwo.go n power h = if power < n then Nat.nextPowerOfTwo.go n (power * 2) ⋯ else power
@[reducible, inline, deprecated Nat.isPowerOfTwo_one (since := "2025-03-18")]
Equations
@[irreducible]
theorem
Nat.isPowerOfTwo_nextPowerOfTwo.isPowerOfTwo_go
(n power : Nat)
(h₁ : power > 0)
(h₂ : power.isPowerOfTwo)
:
(nextPowerOfTwo.go n power h₁).isPowerOfTwo