Binary recursion on Nat
#
This file defines binary recursion on Nat
.
Main results #
Nat.binaryRec
: A recursion principle forbit
representations of natural numbers.Nat.binaryRec'
: The same asbinaryRec
, but the induction step can assume that ifn=0
, the bit being appended istrue
.Nat.binaryRecFromOne
: The same asbinaryRec
, but special casing both 0 and 1 as base cases.
@[inline]
def
Nat.bitCasesOn
{motive : Nat → Sort u}
(n : Nat)
(h : (b : Bool) → (n : Nat) → motive (Nat.bit b n))
:
motive n
For a predicate motive : Nat → Sort u
, if instances can be
constructed for natural numbers of the form bit b n
,
they can be constructed for any given natural number.
Equations
- Nat.bitCasesOn n h = ⋯ ▸ h (1 &&& n != 0) (n >>> 1)
Instances For
@[irreducible, specialize #[]]
def
Nat.binaryRec
{motive : Nat → Sort u}
(z : motive 0)
(f : (b : Bool) → (n : Nat) → motive n → motive (Nat.bit b n))
(n : Nat)
:
motive n
A recursion principle for bit
representations of natural numbers.
For a predicate motive : Nat → Sort u
, if instances can be
constructed for natural numbers of the form bit b n
,
they can be constructed for all natural numbers.
Equations
- Nat.binaryRec z f n = if n0 : n = 0 then ⋯ ▸ z else let x := f (1 &&& n != 0) (n >>> 1) (Nat.binaryRec z f (n >>> 1)); ⋯ ▸ x
Instances For
@[specialize #[]]
def
Nat.binaryRec'
{motive : Nat → Sort u}
(z : motive 0)
(f : (b : Bool) → (n : Nat) → (n = 0 → b = true) → motive n → motive (Nat.bit b n))
(n : Nat)
:
motive n
The same as binaryRec
, but the induction step can assume that if n=0
,
the bit being appended is true
Equations
- Nat.binaryRec' z f n = Nat.binaryRec z (fun (b : Bool) (n : Nat) (ih : motive n) => if h : n = 0 → b = true then f b n h ih else let_fun this := ⋯; ⋯ ▸ z) n
Instances For
@[specialize #[]]
def
Nat.binaryRecFromOne
{motive : Nat → Sort u}
(z₀ : motive 0)
(z₁ : motive 1)
(f : (b : Bool) → (n : Nat) → n ≠ 0 → motive n → motive (Nat.bit b n))
(n : Nat)
:
motive n
The same as binaryRec
, but special casing both 0 and 1 as base cases
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]
theorem
Nat.binaryRec_zero
{motive : Nat → Sort u}
(z : motive 0)
(f : (b : Bool) → (n : Nat) → motive n → motive (Nat.bit b n))
:
Nat.binaryRec z f 0 = z
@[simp]
theorem
Nat.binaryRec_one
{motive : Nat → Sort u}
(z : motive 0)
(f : (b : Bool) → (n : Nat) → motive n → motive (Nat.bit b n))
:
Nat.binaryRec z f 1 = f true 0 z
@[deprecated Nat.binaryRec_eq]
theorem
Nat.binaryRec_eq'
{motive : Nat → Sort u}
{z : motive 0}
{f : (b : Bool) → (n : Nat) → motive n → motive (Nat.bit b n)}
(b : Bool)
(n : Nat)
(h : f false 0 z = z ∨ (n = 0 → b = true))
:
Nat.binaryRec z f (Nat.bit b n) = f b n (Nat.binaryRec z f n)
Alias of Nat.binaryRec_eq
.