nl_statement
stringlengths
6
6k
nl_proof
stringlengths
55
8.29k
⌀
lean_statement
stringlengths
3
29.8k
lean_proof
stringlengths
2
189k
labels
listlengths
1
3
source
stringclasses
245 values
For every signed 32-bit integer $x$, its integer value equals the signed integer value of its associated 32-bit vector.
null
@[grind hom] theorem Lean.Grind.Int32.toInt_eq_toBitVec_toInt (x : Int32) : x.toInt = x.toBitVec.toInt
:= rfl
[ "theorem", "core library" ]
lean4
For every signed 16-bit integer $x$, its integer value equals the signed integer value of its associated 16-bit vector.
null
@[grind hom] theorem Lean.Grind.Int16.toInt_eq_toBitVec_toInt (x : Int16) : x.toInt = x.toBitVec.toInt
:= rfl
[ "theorem", "core library" ]
lean4
For every natural number $a$, the bit vector associated with the unsigned 32-bit numeral $a$ equals the 32-bit vector numeral $a$.
null
@[grind hom] theorem Lean.Grind.UInt32.toBitVec_OfNat_ofNat (a : Nat) : (OfNat.ofNat a : UInt32).toBitVec = OfNat.ofNat a
:= (UInt32.toBitVec_ofNat a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every natural number $a$, converting $a$ to an unsigned 32-bit integer using `ofNat` and then to a bit vector gives the 32-bit vector numeral $a$.
null
@[grind hom] theorem Lean.Grind.UInt32.toBitVec_ofNat (a : Nat) : (UInt32.ofNat a).toBitVec = OfNat.ofNat a
:= (UInt32.toBitVec_ofNat' a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every unsigned 32-bit integer $x$, its natural-number value equals the natural-number value of its associated bit vector.
null
@[grind hom] theorem Lean.Grind.UInt32.toNat_eq_toBitVec_toNat (x : UInt32) : x.toNat = x.toBitVec.toNat
:= rfl
[ "theorem", "core library" ]
lean4
For every natural number $a$, the bit vector associated with the unsigned 64-bit numeral $a$ equals the 64-bit vector numeral $a$.
null
@[grind hom] theorem Lean.Grind.UInt64.toBitVec_OfNat_ofNat (a : Nat) : (OfNat.ofNat a : UInt64).toBitVec = OfNat.ofNat a
:= (UInt64.toBitVec_ofNat a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every natural number $a$, converting $a$ to an unsigned 64-bit integer using `ofNat` and then to a bit vector gives the 64-bit vector numeral $a$.
null
@[grind hom] theorem Lean.Grind.UInt64.toBitVec_ofNat (a : Nat) : (UInt64.ofNat a).toBitVec = OfNat.ofNat a
:= (UInt64.toBitVec_ofNat' a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every unsigned 64-bit integer $x$, its natural-number value equals the natural-number value of its associated bit vector.
null
@[grind hom] theorem Lean.Grind.UInt64.toNat_eq_toBitVec_toNat (x : UInt64) : x.toNat = x.toBitVec.toNat
:= rfl
[ "theorem", "core library" ]
lean4
For every signed machine-sized integer $x$ of type `ISize`, its integer value equals the signed integer value of its associated bit vector.
null
@[grind hom] theorem Lean.Grind.ISize.toInt_eq_toBitVec_toInt (x : ISize) : x.toInt = x.toBitVec.toInt
:= rfl
[ "theorem", "core library" ]
lean4
For every natural number $a$, the bit vector associated with the unsigned 16-bit numeral $a$ equals the 16-bit vector numeral $a$.
null
@[grind hom] theorem Lean.Grind.UInt16.toBitVec_OfNat_ofNat (a : Nat) : (OfNat.ofNat a : UInt16).toBitVec = OfNat.ofNat a
:= (UInt16.toBitVec_ofNat a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every natural number $a$, converting $a$ to an unsigned 16-bit integer using `ofNat` and then to a bit vector gives the 16-bit vector numeral $a$.
null
@[grind hom] theorem Lean.Grind.UInt16.toBitVec_ofNat (a : Nat) : (UInt16.ofNat a).toBitVec = OfNat.ofNat a
:= (UInt16.toBitVec_ofNat' a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every unsigned 16-bit integer $x$, its natural-number value equals the natural-number value of its associated bit vector.
null
@[grind hom] theorem Lean.Grind.UInt16.toNat_eq_toBitVec_toNat (x : UInt16) : x.toNat = x.toBitVec.toNat
:= rfl
[ "theorem", "core library" ]
lean4
For every signed 64-bit integer $x$, its integer value equals the signed integer value of its associated 64-bit vector.
null
@[grind hom] theorem Lean.Grind.Int64.toInt_eq_toBitVec_toInt (x : Int64) : x.toInt = x.toBitVec.toInt
:= rfl
[ "theorem", "core library" ]
lean4
For all integers $m,n,k$, $((m\bmod n)k)\bmod n=(mk)\bmod n$, where $\bmod$ is the Euclidean remainder, with $a\bmod 0=a$.
null
@[grind hom] theorem Lean.Grind.Int.emod_mul_emod (m n k : Int) : m % n * k % n = m * k % n
:= by rw [Int.mul_emod, Int.emod_emod, ← Int.mul_emod]
[ "theorem", "core library" ]
lean4
For all integers $m,n,k$, $(m(n\bmod k))\bmod k=(mn)\bmod k$, where $\bmod$ is the Euclidean remainder, with $a\bmod 0=a$.
null
@[grind hom] theorem Lean.Grind.Int.mul_emod_emod (m n k : Int) : m * (n % k) % k = m * n % k
:= by rw [Int.mul_emod, Int.emod_emod, ← Int.mul_emod]
[ "theorem", "core library" ]
lean4
For all natural numbers $x,c,m,n$ satisfying $c=2^n-1$ and $m=2^n$, the bitwise AND satisfies $x\mathbin{\&}c=x\bmod m$.
null
theorem Lean.Grind.Nat.and_eq_mod (x c m n : Nat) (h₁ : c = 2^n - 1) (h₂ : m = 2^n) : x &&& c = x % m
:= by subst h₁ h₂; exact Nat.and_two_pow_sub_one_eq_mod x n
[ "theorem", "core library" ]
lean4
For all natural numbers $x,c,m,n$ satisfying $c=2^n-1$ and $m=2^n$, the bitwise AND satisfies $c\mathbin{\&}x=x\bmod m$.
null
theorem Lean.Grind.Nat.ones_and_eq_mod (x c m n : Nat) (h₁ : c = 2^n - 1) (h₂ : m = 2^n) : c &&& x = x % m
:= by rw [Nat.and_comm]; exact and_eq_mod x c m n h₁ h₂
[ "theorem", "core library" ]
lean4
For all natural numbers $x,c,p,q,k,n$ satisfying $c=(2^n-1)2^k$, $p=2^k$, and $q=2^n$, the bitwise AND satisfies $x\mathbin{\&}c=(\lfloor x/p\rfloor\bmod q)p$.
null
theorem Lean.Grind.Nat.and_eq_div_mod_mul (x c p q k n : Nat) (h₁ : c = (2^n - 1) * 2^k) (h₂ : p = 2^k) (h₃ : q = 2^n) : x &&& c = x / p % q * p
:= by subst h₁ h₂ h₃ apply Nat.eq_of_testBit_eq intro i simp only [Nat.testBit_and, Nat.testBit_mul_two_pow, Nat.testBit_two_pow_sub_one, Nat.testBit_mod_two_pow, Nat.testBit_div_two_pow] cases Nat.lt_or_ge i k with | inl h => simp [Nat.not_le_of_lt h] | inr h => simp [h, Nat.sub_add_cancel h, Bool.an...
[ "theorem", "core library" ]
lean4
For all natural numbers $x,c,p,q,k,n$ satisfying $c=(2^n-1)2^k$, $p=2^k$, and $q=2^n$, the bitwise AND satisfies $c\mathbin{\&}x=(\lfloor x/p\rfloor\bmod q)p$.
null
theorem Lean.Grind.Nat.ones_zeros_and_eq_div_mod_mul (x c p q k n : Nat) (h₁ : c = (2^n - 1) * 2^k) (h₂ : p = 2^k) (h₃ : q = 2^n) : c &&& x = x / p % q * p
:= by rw [Nat.and_comm]; exact and_eq_div_mod_mul x c p q k n h₁ h₂ h₃
[ "theorem", "core library" ]
lean4
For all natural numbers $x,c,c',m$ satisfying $c+c'=m$, $(cx)\bmod m=(m-((c'x)\bmod m))\bmod m$, where subtraction is truncated at zero and $a\bmod 0=a$.
null
theorem Lean.Grind.Nat.mul_mod_eq_sub_mul_mod (x c c' m : Nat) (h : c + c' = m) : c * x % m = (m - c' * x % m) % m
:= by subst h have h₁ : (c * x + c' * x) % (c + c') = 0 := by rw [← Nat.add_mul, Nat.mul_mod_right] rw [Nat.add_mod] at h₁ cases Nat.eq_zero_or_pos (c + c') with | inl h₀ => have ⟨hc, hc'⟩ := Nat.add_eq_zero_iff.mp h₀ subst hc hc'; simp | inr hpos => have ha := Nat.mod_lt (c * x) hpos have h...
[ "theorem", "core library" ]
lean4
For all natural numbers $x,c,c',m$ satisfying $c+c'=m$, $(xc)\bmod m=(m-((c'x)\bmod m))\bmod m$, where subtraction is truncated at zero and $a\bmod 0=a$.
null
theorem Lean.Grind.Nat.mul_mod_eq_sub_mul_mod' (x c c' m : Nat) (h : c + c' = m) : x * c % m = (m - c' * x % m) % m
:= by rw [Nat.mul_comm]; exact mul_mod_eq_sub_mul_mod x c c' m h
[ "theorem", "core library" ]
lean4
For every natural number $a$, the bit vector associated with the unsigned machine-sized numeral $a$ of type `USize` equals the bit-vector numeral $a$ of the machine word width.
null
@[grind hom] theorem Lean.Grind.USize.toBitVec_OfNat_ofNat (a : Nat) : (OfNat.ofNat a : USize).toBitVec = OfNat.ofNat a
:= (USize.toBitVec_ofNat a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every natural number $a$, converting $a$ to `USize` using `ofNat` and then to a bit vector gives the bit-vector numeral $a$ of the machine word width.
null
@[grind hom] theorem Lean.Grind.USize.toBitVec_ofNat (a : Nat) : (USize.ofNat a).toBitVec = OfNat.ofNat a
:= (USize.toBitVec_ofNat' a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every unsigned machine-sized integer $x$ of type `USize`, its natural-number value equals the natural-number value of its associated bit vector.
null
@[grind hom] theorem Lean.Grind.USize.toNat_eq_toBitVec_toNat (x : USize) : x.toNat = x.toBitVec.toNat
:= rfl
[ "theorem", "core library" ]
lean4
For every natural number $n$ and all $a,b\in\operatorname{Fin}(n)$, where $\operatorname{Fin}(n)$ consists of natural numbers less than $n$, $a=b$ if and only if their underlying natural-number values are equal.
null
@[grind hom] theorem Lean.Grind.Fin.eq_iff_val_eq {n : Nat} (a b : Fin n) : a = b ↔ a.val = b.val
:= ⟨Fin.val_eq_of_eq, Fin.eq_of_val_eq⟩
[ "theorem", "core library" ]
lean4
For every natural number $n$, decidable proposition $c$, and $x,y\in\operatorname{Fin}(n)$, the underlying natural-number value of $\text{if }c\text{ then }x\text{ else }y$ equals $\text{if }c\text{ then }\operatorname{val}(x)\text{ else }\operatorname{val}(y)$.
null
@[grind hom] theorem Lean.Grind.Fin.val_ite {n : Nat} (c : Prop) [Decidable c] (x y : Fin n) : (if c then x else y).val = if c then x.val else y.val
:= by split <;> rfl
[ "theorem", "core library" ]
lean4
For every nonzero natural number $n$ and natural number $a$, the underlying natural-number value of the numeral $a$ in $\operatorname{Fin}(n)$ is $a\bmod n$.
null
@[grind hom] theorem Lean.Grind.Fin.val_OfNat_ofNat (n : Nat) [NeZero n] (a : Nat) : (OfNat.ofNat a : Fin n).val = a % n
:= by dsimp [OfNat.ofNat]
[ "theorem", "core library" ]
lean4
For every natural number $n$ and $a\in\operatorname{Fin}(n)$, $\operatorname{val}(\operatorname{log2}(a))=\operatorname{log2}(\operatorname{val}(a))$, using the natural-number `log2` on the right.
null
@[grind hom] theorem Lean.Grind.Fin.val_log2 {n : Nat} (a : Fin n) : a.log2.val = a.val.log2
:= by simp [Fin.log2]
[ "theorem", "core library" ]
lean4
For every nonzero natural number $n$ and natural number $a$, the underlying value of the natural-number cast of $a$ into $\operatorname{Fin}(n)$ is $a\bmod n$.
null
@[grind hom] theorem Lean.Grind.Fin.val_natCast (n : Nat) [NeZero n] (a : Nat) : (NatCast.natCast a : Fin n).val = a % n
:= rfl
[ "theorem", "core library" ]
lean4
For every nonzero natural number $n$ and integer $i$, the underlying natural-number value of the integer cast of $i$ into $\operatorname{Fin}(n)$ is $\operatorname{toNat}(i\bmod n)$, where the remainder is Euclidean and $\operatorname{toNat}(z)=\max(z,0)$ viewed as a natural number.
null
@[grind hom] theorem Lean.Grind.Fin.val_intCast (n : Nat) [NeZero n] (i : Int) : (IntCast.intCast i : Fin n).val = (i % n).toNat
:= by have hn : n ≠ 0 := NeZero.ne n change (Fin.intCast i : Fin n).val = _ unfold Fin.intCast split next h => rw [Fin.val_ofNat, Int.emod_natAbs_of_nonneg h] next h => have h : i < 0 := by omega change (n - i.natAbs % n) % n = _ rw [Int.emod_natAbs_of_neg h hn] have h₁ := Int.emod_nonneg i ...
[ "theorem", "core library" ]
lean4
For every natural number $a$, the bit vector associated with the unsigned 8-bit numeral $a$ equals the 8-bit vector numeral $a$.
null
@[grind hom] theorem Lean.Grind.UInt8.toBitVec_OfNat_ofNat (a : Nat) : (OfNat.ofNat a : UInt8).toBitVec = OfNat.ofNat a
:= (UInt8.toBitVec_ofNat a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every natural number $a$, converting $a$ to an unsigned 8-bit integer using `ofNat` and then to a bit vector gives the 8-bit vector numeral $a$.
null
@[grind hom] theorem Lean.Grind.UInt8.toBitVec_ofNat (a : Nat) : (UInt8.ofNat a).toBitVec = OfNat.ofNat a
:= (UInt8.toBitVec_ofNat' a).trans BitVec.ofNat_eq_ofNat.symm
[ "theorem", "core library" ]
lean4
For every unsigned 8-bit integer $x$, its natural-number value equals the natural-number value of its associated bit vector.
null
@[grind hom] theorem Lean.Grind.UInt8.toNat_eq_toBitVec_toNat (x : UInt8) : x.toNat = x.toBitVec.toNat
:= rfl
[ "theorem", "core library" ]
lean4
For every signed 8-bit integer $x$, its integer value equals the signed integer value of its associated 8-bit vector.
null
@[grind hom] theorem Lean.Grind.Int8.toInt_eq_toBitVec_toInt (x : Int8) : x.toInt = x.toBitVec.toInt
:= rfl
[ "theorem", "core library" ]
lean4
The opaque function $\mathrm{getMajor}:\mathrm{Unit}\to\mathbb N$ supplies the major version number; $\mathrm{major}=\mathrm{getMajor}(())$.
null
@[extern "lean_version_get_major"] private opaque version.getMajor (u : Unit) : Nat def version.major : Nat
:= version.getMajor ()
[ "definition", "core library" ]
lean4
The natural number $\mathrm{major}$ is $\mathrm{getMajor}(())$, the major version number.
null
def version.major : Nat
:= version.getMajor ()
[ "definition", "core library" ]
lean4
The opaque function $\mathrm{getMinor}:\mathrm{Unit}\to\mathbb N$ supplies the minor version number; $\mathrm{minor}=\mathrm{getMinor}(())$.
null
@[extern "lean_version_get_minor"] private opaque version.getMinor (u : Unit) : Nat def version.minor : Nat
:= version.getMinor ()
[ "definition", "core library" ]
lean4
The natural number $\mathrm{minor}$ is $\mathrm{getMinor}(())$, the minor version number.
null
def version.minor : Nat
:= version.getMinor ()
[ "definition", "core library" ]
lean4
The opaque function $\mathrm{getPatch}:\mathrm{Unit}\to\mathbb N$ supplies the patch version number; $\mathrm{patch}=\mathrm{getPatch}(())$.
null
@[extern "lean_version_get_patch"] private opaque version.getPatch (u : Unit) : Nat def version.patch : Nat
:= version.getPatch ()
[ "definition", "core library" ]
lean4
The natural number $\mathrm{patch}$ is $\mathrm{getPatch}(())$, the patch version number.
null
def version.patch : Nat
:= version.getPatch ()
[ "definition", "core library" ]
lean4
The opaque function $\mathrm{getGithash}:\mathrm{Unit}\to\mathrm{String}$ supplies a Git hash string; $\mathrm{githash}=\mathrm{getGithash}(())$.
null
@[extern "lean_get_githash"] opaque getGithash (u : Unit) : String def githash : String
:= getGithash ()
[ "definition", "core library" ]
lean4
The string $\mathrm{githash}$ is $\mathrm{getGithash}(())$.
null
def githash : String
:= getGithash ()
[ "definition", "core library" ]
lean4
The opaque function $\mathrm{getIsRelease}:\mathrm{Unit}\to\mathrm{Bool}$ supplies a release flag; $\mathrm{isRelease}=\mathrm{getIsRelease}(())$.
null
@[extern "lean_version_get_is_release"] opaque version.getIsRelease (u : Unit) : Bool def version.isRelease : Bool
:= version.getIsRelease ()
[ "definition", "core library" ]
lean4
The Boolean $\mathrm{isRelease}$ is $\mathrm{getIsRelease}(())$.
null
def version.isRelease : Bool
:= version.getIsRelease ()
[ "definition", "core library" ]
lean4
Additional version description like "nightly-2018-03-11"
null
@[extern "lean_version_get_special_desc"] opaque version.getSpecialDesc (u : Unit) : String def version.specialDesc : String
:= version.getSpecialDesc ()
[ "definition", "core library" ]
lean4
The string $\mathrm{specialDesc}$ is $\mathrm{getSpecialDesc}(())$, the special version description.
null
def version.specialDesc : String
:= version.getSpecialDesc ()
[ "definition", "core library" ]
lean4
The string $\mathrm{versionStringCore}$ concatenates the decimal representations of $\mathrm{major}$, $\mathrm{minor}$, and $\mathrm{patch}$, separated by periods.
null
def versionStringCore
:= String.Internal.append (String.Internal.append (String.Internal.append (String.Internal.append (toString version.major) ".") (toString version.minor)) ".") (toString version.patch)
[ "definition", "core library" ]
lean4
The string $\mathrm{versionString}$ is $\mathrm{versionStringCore}$ followed by a hyphen and $\mathrm{specialDesc}$ when that description is nonempty; otherwise it is $\mathrm{versionStringCore}$ for a release, and $\mathrm{versionStringCore}$ followed by “, commit ” and $\mathrm{githash}$ otherwise.
null
def versionString
:= if version.specialDesc ≠ "" then String.Internal.append (String.Internal.append versionStringCore "-") version.specialDesc else if version.isRelease then versionStringCore else (String.Internal.append (String.Internal.append versionStringCore ", commit ") githash)
[ "definition", "core library" ]
lean4
The string $\mathrm{origin}$ is “leanprover/lean4”.
null
def origin
:= "leanprover/lean4"
[ "definition", "core library" ]
lean4
The string $\mathrm{toolchain}$ is $\mathrm{origin}$ followed by “:v”, $\mathrm{versionStringCore}$, a hyphen, and $\mathrm{specialDesc}$ when the description is nonempty and the release flag is true; with a nonempty description and false release flag it is $\mathrm{origin}$ followed by a colon and the description. Wit...
null
def toolchain
:= if version.specialDesc ≠ "" then if version.isRelease then String.Internal.append (String.Internal.append (String.Internal.append (String.Internal.append origin ":v") versionStringCore) "-") version.specialDesc else String.Internal.ap...
[ "definition", "core library" ]
lean4
For a character $c$, the Boolean $\mathrm{isGreek}(c)$ is true exactly when its Unicode value lies in the inclusive hexadecimal interval $[391,3DD]$.
null
@[inline] def isGreek (c : Char) : Bool
:= 0x391 ≤ c.val && c.val ≤ 0x3dd
[ "definition", "core library" ]
lean4
For a character $c$ with Unicode value $v$, $\mathrm{isLetterLike}(c)$ is true exactly when $v$ lies in one of the following inclusive hexadecimal ranges: $[3B1,3C9]\setminus\{3BB\}$, $[391,3A9]\setminus\{3A0,3A3\}$, $[3CA,3FB]$, $[1F00,1FFE]$, $[2100,214F]$, $[1D49C,1D59F]$, $[C0,FF]\setminus\{D7,F7\}$, or $[100,17F]$...
null
def isLetterLike (c : Char) : Bool
:= (0x3b1 ≤ c.val && c.val ≤ 0x3c9 && c.val ≠ 0x3bb) || (0x391 ≤ c.val && c.val ≤ 0x3A9 && c.val ≠ 0x3A0 && c.val ≠ 0x3A3) || (0x3ca ≤ c.val && c.val ≤ 0x3fb) || (0x1f00 ≤ c.val && c.val ≤ 0x1ffe) || (0x2100 ≤ c.val && c.val ≤ 0x214f) || (0x1d49c ≤ c.val && c.val ≤ 0x1d59f) || (0x00c0 ≤ c.val && c.val ...
[ "definition", "core library" ]
lean4
For a character $c$, $\mathrm{isNumericSubscript}(c)$ is true exactly when its Unicode value lies in the inclusive hexadecimal interval $[2080,2089]$.
null
@[inline] def isNumericSubscript (c : Char) : Bool
:= 0x2080 ≤ c.val && c.val ≤ 0x2089
[ "definition", "core library" ]
lean4
For a character $c$, $\mathrm{isSubScriptAlnum}(c)$ is true exactly when its Unicode value lies in one of the inclusive hexadecimal intervals $[2080,2089]$, $[2090,209C]$, or $[1D62,1D6A]$, or equals $2C7C$.
null
def isSubScriptAlnum (c : Char) : Bool
:= isNumericSubscript c || (0x2090 ≤ c.val && c.val ≤ 0x209c) || (0x1d62 ≤ c.val && c.val ≤ 0x1d6a) || c.val == 0x2c7c
[ "definition", "core library" ]
lean4
For a character $c$, $\mathrm{isIdFirst}(c)$ is true exactly when $c$ is alphabetic according to `isAlpha`, is an underscore, or satisfies `isLetterLike`.
null
@[inline] def isIdFirst (c : Char) : Bool
:= c.isAlpha || c = '_' || isLetterLike c
[ "definition", "core library" ]
lean4
For an unsigned byte $c$, $\mathrm{isAlphaAscii}(c)$ is true exactly when $c$ is the ASCII encoding of a letter from a through z or A through Z.
null
@[inline] private def isAlphaAscii (c : UInt8) : Bool
:= 'a'.toUInt8 ≤ c && c ≤ 'z'.toUInt8 || 'A'.toUInt8 ≤ c && c ≤ 'Z'.toUInt8
[ "definition", "core library" ]
lean4
For an unsigned byte $c$, $\mathrm{isIdFirstAscii}(c)$ is true exactly when $c$ encodes an ASCII letter or an underscore.
null
@[inline] def isIdFirstAscii (c : UInt8) : Bool
:= isAlphaAscii c || c = '_'.toUInt8
[ "definition", "core library" ]
lean4
For an unsigned byte $c$, $\mathrm{isAlphanumAscii}(c)$ is true exactly when $c$ encodes an ASCII letter or a digit from 0 through 9.
null
@[inline] private def isAlphanumAscii (c : UInt8) : Bool
:= isAlphaAscii c || '0'.toUInt8 ≤ c && c ≤ '9'.toUInt8
[ "definition", "core library" ]
lean4
For a character $c$, $\mathrm{isIdRest}(c)$ is true exactly when $c$ satisfies `isAlphanum`, is one of underscore, apostrophe, exclamation mark, or question mark, or satisfies `isLetterLike` or `isSubScriptAlnum`.
null
@[inline] def isIdRest (c : Char) : Bool
:= c.isAlphanum || c = '_' || c = '\'' || c == '!' || c == '?' || isLetterLike c || isSubScriptAlnum c
[ "definition", "core library" ]
lean4
For an unsigned byte $c$, $\mathrm{isIdRestAscii}(c)$ is true exactly when $c$ encodes an ASCII letter, digit, underscore, apostrophe, exclamation mark, or question mark.
null
@[inline] def isIdRestAscii (c : UInt8) : Bool
:= isAlphanumAscii c || c = '_'.toUInt8 || c = '\''.toUInt8 || c == '!'.toUInt8 || c == '?'.toUInt8
[ "definition", "core library" ]
lean4
The character $\mathrm{idBeginEscape}$ is «.
null
def idBeginEscape
:= '«'
[ "definition", "core library" ]
lean4
The character $\mathrm{idEndEscape}$ is ».
null
def idEndEscape
:= '»'
[ "definition", "core library" ]
lean4
For a character $c$, $\mathrm{isIdBeginEscape}(c)$ is true exactly when $c$ is «.
null
@[inline] def isIdBeginEscape (c : Char) : Bool
:= c = idBeginEscape
[ "definition", "core library" ]
lean4
For a character $c$, $\mathrm{isIdEndEscape}(c)$ is true exactly when $c$ is ».
null
@[inline] def isIdEndEscape (c : Char) : Bool
:= c = idEndEscape
[ "definition", "core library" ]
lean4
The function $\mathrm{getRoot}:\mathrm{Name}\to\mathrm{Name}$ sends the anonymous name to itself and every nonanonymous name to its first component, retaining whether that component is a string or a natural number.
null
def getRoot : Name → Name
| anonymous => anonymous | n@(str anonymous _) => n | n@(num anonymous _) => n | str n _ => getRoot n | num n _ => getRoot n
[ "definition", "core library" ]
lean4
The Boolean function $\mathrm{isInaccessibleUserName}$ on names returns true when the last string component contains ✝ or equals “_inaccessible”; it skips trailing numeric components and returns false for the anonymous name.
null
def isInaccessibleUserName : Name → Bool
| Name.str _ s => (String.Internal.contains s '✝') || s == "_inaccessible" | Name.num p _ => isInaccessibleUserName p | _ => false
[ "definition", "core library" ]
lean4
For a string $s$ and natural number $i$, $\mathrm{needsNoEscapeAsciiRest}(s,i)$ is true exactly when every UTF-8 byte of $s$ at an index at least $i$ satisfies `isIdRestAscii`; it is true when $i$ is at least the byte length.
null
private partial def needsNoEscapeAsciiRest (s : String) (i : Nat) : Bool
:= if h : i < s.utf8ByteSize then let c := String.Internal.getUTF8Byte s i h isIdRestAscii c && needsNoEscapeAsciiRest s (i + 1) else true
[ "definition", "core library" ]
lean4
For a string $s$ with positive UTF-8 byte length, $\mathrm{needsNoEscapeAscii}(s)$ is true exactly when its first byte satisfies `isIdFirstAscii` and all remaining bytes satisfy `isIdRestAscii`.
null
@[inline] private def needsNoEscapeAscii (s : String) (h : s.utf8ByteSize > 0) : Bool
:= let c := String.Internal.getUTF8Byte s 0 h isIdFirstAscii c && needsNoEscapeAsciiRest s 1
[ "definition", "core library" ]
lean4
For a string $s$ with positive UTF-8 byte length, $\mathrm{needsNoEscape}(s)$ is true when `needsNoEscapeAscii` holds, or when its first character satisfies `isIdFirst` and every remaining character satisfies `isIdRest`.
null
@[inline] private def needsNoEscape (s : String) (h : s.utf8ByteSize > 0) : Bool
:= needsNoEscapeAscii s h || isIdFirst (String.Internal.get s 0) && Substring.Raw.Internal.all (Substring.Raw.Internal.drop s.toRawSubstring 1) isIdRest
[ "definition", "core library" ]
lean4
For a string $s$, $\mathrm{escape}(s)$ is the concatenation of «, $s$, and ».
null
@[inline] private def escape (s : String) : String
:= String.Internal.append (String.Internal.append idBeginEscape.toString s) idEndEscape.toString
[ "definition", "core library" ]
lean4
For a string $s$ and Boolean $\mathrm{force}$, defaulting to false, $\mathrm{escapePart}(s,\mathrm{force})$ returns $\mathrm{some}(s)$ if $s$ is nonempty, forcing is disabled, and `needsNoEscape` holds. Otherwise it returns none if the nonempty string contains », and returns $\mathrm{some}(\text{«}s\text{»})$ in all ot...
null
@[inline] private def Internal.Meta.escapePart (s : String) (force : Bool := false) : Option String
:= if h : s.utf8ByteSize > 0 then if !force && needsNoEscape s h then some s else if String.Internal.any s isIdEndEscape then none else some <| escape s else some <| escape s
[ "definition", "core library" ]
lean4
For a name $n$, separator string $\mathrm{sep}$, escape flag, and token test $\mathrm{isToken}$ defaulting to constantly false, `toStringWithSep` renders the anonymous name as “[anonymous]”, a root string component using `maybeEscape` with its token-test result, and a root numeric component in decimal. A further string...
null
private def Internal.Meta.toStringWithSep (n : Name) (isToken : String → Bool := fun _ => false) : String
:= match n with | anonymous => "[anonymous]" | str anonymous s => maybeEscape s (isToken s) | num anonymous v => toString v | str n s => let r := toStringWithSep n isToken let r' := String.Internal.append (String.Internal.append r sep) (maybeEscape s false) if escape && isToken r' th...
[ "definition", "core library" ]
lean4
For a name $n$, Boolean escape flag defaulting to true, and token test $\mathrm{isToken}:\mathrm{String}\to\mathrm{Bool}$, `toStringWithToken` applies `toStringWithSep` with period separators and the given token test, enabling escaping exactly when the flag is true, $n$ is neither an inaccessible user name nor a name w...
null
private def Internal.Meta.toStringWithToken (n : Name) (escape := true) (isToken : String → Bool) : String
:= toStringWithSep "." (escape && !n.isInaccessibleUserName && !n.hasMacroScopes && !maybePseudoSyntax) n isToken
[ "definition", "core library" ]
lean4
For a name $n$ and Boolean escape flag defaulting to true, $\mathrm{toString}(n)$ is `toStringWithToken` applied with that flag and a token test that is always false.
null
private def Internal.Meta.toString (n : Name) (escape := true) : String
:= toStringWithToken n escape (fun _ => false)
[ "definition", "core library" ]
lean4
Returns true if the name has any numeric components.
null
def hasNum : Name → Bool
| anonymous => false | num .. => true | str p .. => hasNum p
[ "definition", "core library" ]
lean4
For a name $n$ and natural-number precedence $p$, $\mathrm{reprPrec}(n,p)$ produces a formatted representation: the anonymous name uses its constructor label; a numeric component uses an application of `mkNum` to the recursively represented prefix and the represented number; a string component whose prefix contains a n...
null
protected def reprPrec (n : Name) (prec : Nat) : Std.Format
:= match n with | anonymous => Std.Format.text "Lean.Name.anonymous" | num p i => Repr.addAppParen ("Lean.Name.mkNum " ++ Name.reprPrec p max_prec ++ " " ++ repr i) prec | str p s => if p.hasNum then Repr.addAppParen ("Lean.Name.mkStr " ++ Name.reprPrec p max_prec ++ " " ++ repr s) prec else ...
[ "definition", "core library" ]
lean4
The function $\mathrm{capitalize}:\mathrm{Name}\to\mathrm{Name}$ applies string capitalization to the final component of a name when that component is a string, preserving its prefix; anonymous names and names ending in a numeric component remain unchanged.
null
def capitalize : Name → Name
| .str p s => .str p (String.Internal.capitalize s) | n => n
[ "definition", "core library" ]
lean4
For names $n,q,r$, $\mathrm{replacePrefix}(n,q,r)$ replaces a prefix equal to $q$ by $r$: it returns $r$ if $n=q$, otherwise recursively processes the parent of each string or numeric component and reattaches that component. At the anonymous name it returns $r$ if $q$ is anonymous, and the anonymous name otherwise.
null
def replacePrefix : Name → Name → Name → Name
| anonymous, anonymous, newP => newP | anonymous, _, _ => anonymous | n@(str p s), queryP, newP => if n == queryP then newP else Name.mkStr (p.replacePrefix queryP newP) s | n@(num p s), queryP, newP => if n == queryP then newP else Name.mkNum (p.replacePrefix queryP newP) s
[ "definition", "core library" ]
lean4
`eraseSuffix? n s` return `n'` if `n` is of the form `n == n' ++ s`.
null
def eraseSuffix? : Name → Name → Option Name
| n, anonymous => some n | str p s, str p' s' => if s == s' then eraseSuffix? p p' else none | num p s, num p' s' => if s == s' then eraseSuffix? p p' else none | _, _ => none
[ "definition", "core library" ]
lean4
Remove macros scopes, apply `f`, and put them back
null
@[inline] def modifyBase (n : Name) (f : Name → Name) : Name
:= if n.hasMacroScopes then let view := extractMacroScopes n { view with name := f view.name }.review else f n
[ "definition", "core library" ]
lean4
For a name $n$ and string $s$, $\mathrm{appendAfter}(n,s)$ applies `modifyBase` to $n$, concatenating $s$ to a string base component and otherwise adding $s$ as a new string component after the base name.
null
@[export lean_name_append_after] def appendAfter (n : Name) (suffix : String) : Name
:= n.modifyBase fun | str p s => Name.mkStr p (String.Internal.append s suffix) | n => Name.mkStr n suffix
[ "definition", "core library" ]
lean4
For a name $n$ and natural number $i$, $\mathrm{appendIndexAfter}(n,i)$ applies `modifyBase` to $n$, appending an underscore and the decimal representation of $i$ to a string base component, or adding that combined string as a new component otherwise.
null
@[export lean_name_append_index_after] def appendIndexAfter (n : Name) (idx : Nat) : Name
:= n.modifyBase fun | str p s => Name.mkStr p (String.Internal.append (String.Internal.append s "_") (toString idx)) | n => Name.mkStr n (String.Internal.append "_" (toString idx))
[ "definition", "core library" ]
lean4
For a name $n$ and string $s$, $\mathrm{appendBefore}(n,s)$ applies `modifyBase` with the following transformation: an anonymous base becomes a root string component $s$; a string component has $s$ prepended; a numeric component retains its number and gains a string component $s$ immediately before it.
null
def appendBefore (n : Name) (pre : String) : Name
:= n.modifyBase fun | anonymous => Name.mkStr anonymous pre | str p s => Name.mkStr p (String.Internal.append pre s) | num p n => Name.mkNum (Name.mkStr p pre) n
[ "definition", "core library" ]
lean4
For all $m,n$ of type `Name`, the Boolean equality test $m==n$ is true if and only if $m=n$.
null
protected theorem beq_iff_eq {m n : Name} : m == n ↔ m = n
:= by change m.beq n ↔ _ induction m generalizing n <;> cases n <;> simp_all [Name.beq, And.comm]
[ "theorem", "core library" ]
lean4
For a name generator $g$, $\mathrm{curr}(g)$ is the name obtained by appending the numeric component $g.\mathrm{idx}$ to $g.\mathrm{namePrefix}$.
null
@[inline] def curr (g : NameGenerator) : Name
:= Name.mkNum g.namePrefix g.idx
[ "definition", "core library" ]
lean4
For a name generator $g$, $\mathrm{next}(g)$ preserves its other fields and replaces its index by $g.\mathrm{idx}+1$.
null
@[inline] def next (g : NameGenerator) : NameGenerator
:= { g with idx := g.idx + 1 }
[ "definition", "core library" ]
lean4
For a name generator $g$, $\mathrm{mkChild}(g)$ returns a pair of generators: the first has prefix $\mathrm{curr}(g)$ and index $1$, and the second is $\mathrm{next}(g)$.
null
@[inline] def mkChild (g : NameGenerator) : NameGenerator × NameGenerator
:= ({ namePrefix := Name.mkNum g.namePrefix g.idx, idx := 1 }, { g with idx := g.idx + 1 })
[ "definition", "core library" ]
lean4
For a type constructor $m:\mathrm{Type}\to\mathrm{Type}$, the class `MonadNameGenerator` provides operations $\mathrm{getNGen}:m\,\mathrm{NameGenerator}$ and $\mathrm{setNGen}:\mathrm{NameGenerator}\to m\,\mathrm{Unit}$, with no additional laws specified.
null
class MonadNameGenerator (m : Type → Type)
where getNGen : m NameGenerator setNGen : NameGenerator → m Unit
[ "definition", "core library" ]
lean4
Creates a globally unique `Name`, without any semantic interpretation. The names are not intended to be user-visible. With the default name generator, names use `_uniq` as a base and have a numeric suffix. This is used for example by `Lean.mkFreshFVarId`, `Lean.mkFreshMVarId`, and `Lean.mkFreshLMVarId`. To create fres...
null
def mkFreshId {m : Type → Type} [Monad m] [MonadNameGenerator m] : m Name
:= do let ngen ← getNGen let r := ngen.curr setNGen ngen.next pure r
[ "definition", "core library" ]
lean4
For type constructors $m,n:\mathrm{Type}\to\mathrm{Type}$, a lift from $m$ to $n$ and a `MonadNameGenerator` structure on $m$ induce one on $n$ by lifting both the generator-reading action and each generator-setting action.
null
instance monadNameGeneratorLift (m n : Type → Type) [MonadLift m n] [MonadNameGenerator m] : MonadNameGenerator n
:= { getNGen := liftM (getNGen : m _), setNGen := fun ngen => liftM (setNGen ngen : m _)
[ "definition", "core library" ]
lean4
Syntax that represents a Lean term.
null
abbrev Term
:= TSyntax `term
[ "definition", "core library" ]
lean4
Syntax that represents a command.
null
abbrev Command
:= TSyntax `command
[ "definition", "core library" ]
lean4
Syntax that represents a universe level.
null
protected abbrev Level
:= TSyntax `level
[ "definition", "core library" ]
lean4
Syntax that represents a tactic.
null
protected abbrev Tactic
:= TSyntax `tactic
[ "definition", "core library" ]
lean4
Syntax that represents an element of a `do` sequence.
null
abbrev DoElem
:= TSyntax `doElem
[ "definition", "core library" ]
lean4
Syntax that represents a sequence of `do` elements.
null
abbrev DoSeq
:= TSyntax `Lean.Parser.Term.doSeq
[ "definition", "core library" ]
lean4
Syntax that represents a precedence (e.g. for an operator).
null
abbrev Prec
:= TSyntax `prec
[ "definition", "core library" ]
lean4
Syntax that represents a priority (e.g. for an instance declaration).
null
abbrev Prio
:= TSyntax `prio
[ "definition", "core library" ]
lean4
Syntax that represents an identifier.
null
abbrev Ident
:= TSyntax identKind
[ "definition", "core library" ]
lean4
Syntax that represents a string literal.
null
abbrev StrLit
:= TSyntax strLitKind
[ "definition", "core library" ]
lean4