File: .lake/packages/lean4/src/lean/Init/SizeOf.lean

full_name: SizeOf.sizeOf
code: /--
`SizeOf` is a typeclass automatically derived for every inductive type,
which equips the type with a "size" function to `Nat`.
The default instance defines each constructor to be `1` plus the sum of the
sizes of all the constructor fields.

This is used for proofs by well-founded induction, since every field of the
constructor has a smaller size than the constructor itself,
and in many cases this will suffice to do the proof that a recursive function
is only called on smaller values.
If the default proof strategy fails, it is recommended to supply a custom
size measure using the `termination_by` argument on the function definition.
-/
class SizeOf (α : Sort u) where
  /-- The "size" of an element, a natural number which decreases on fields of
  each inductive type. -/
  sizeOf : α → Nat
goal: α → Nat

full_name: SizeOf
code: /--
`SizeOf` is a typeclass automatically derived for every inductive type,
which equips the type with a "size" function to `Nat`.
The default instance defines each constructor to be `1` plus the sum of the
sizes of all the constructor fields.

This is used for proofs by well-founded induction, since every field of the
constructor has a smaller size than the constructor itself,
and in many cases this will suffice to do the proof that a recursive function
is only called on smaller values.
If the default proof strategy fails, it is recommended to supply a custom
size measure using the `termination_by` argument on the function definition.
-/
class SizeOf (α : Sort u) where
  /-- The "size" of an element, a natural number which decreases on fields of
  each inductive type. -/
  sizeOf : α → Nat
goal: Sort (max 1 u)

full_name: default.sizeOf
code: /--
Every type `α` has a default `SizeOf` instance that just returns `0`
for every element of `α`.
-/
protected def default.sizeOf (α : Sort u) : α → Nat
  
goal: α → Nat

full_name: instSizeOf
code: instance (priority := low) (α : Sort u) : SizeOf α 
goal: SizeOf α

full_name: sizeOf_default
code: @[simp] theorem sizeOf_default (n : α) : sizeOf n = 0 
goal: sizeOf n = 0

full_name: instSizeOfNat
code: instance : SizeOf Nat 
goal: SizeOf Nat

full_name: sizeOf_nat
code: @[simp] theorem sizeOf_nat (n : Nat) : sizeOf n = n 
goal: sizeOf n = n

full_name: instSizeOfForallUnit
code: instance [SizeOf α] : SizeOf (Unit → α) 
goal: SizeOf (Unit → α)

full_name: sizeOf_thunk
code: @[simp] theorem sizeOf_thunk [SizeOf α] (f : Unit → α) : sizeOf f = sizeOf (f ()) 
goal: sizeOf f = sizeOf (f Unit.unit)

full_name: Unit.sizeOf
code: @[simp] theorem Unit.sizeOf (u : Unit) : sizeOf u = 1 
goal: sizeOf u = 1

full_name: Bool.sizeOf_eq_one
code: @[simp] theorem Bool.sizeOf_eq_one (b : Bool) : sizeOf b = 1 
goal: sizeOf b = 1

full_name: Lean.Name.sizeOf
code: /--
We manually define the `Lean.Name` instance because we use
an opaque function for computing the hashcode field.
-/
protected noncomputable def Name.sizeOf : Name → Nat
  
goal: Lean.Name → Nat

full_name: Lean.instSizeOfName
code: noncomputable instance : SizeOf Name 
goal: SizeOf Lean.Name

full_name: Lean.Name.anonymous.sizeOf_spec
code: @[simp] theorem Name.anonymous.sizeOf_spec : sizeOf anonymous = 1 
goal: sizeOf Lean.Name.anonymous = 1

full_name: Lean.Name.str.sizeOf_spec
code: @[simp] theorem Name.str.sizeOf_spec (p : Name) (s : String) : sizeOf (str p s) = 1 + sizeOf p + sizeOf s 
goal: sizeOf (p.str s) = 1 + sizeOf p + sizeOf s

full_name: Lean.Name.num.sizeOf_spec
code: @[simp] theorem Name.num.sizeOf_spec (p : Name) (n : Nat) : sizeOf (num p n) = 1 + sizeOf p + sizeOf n 
goal: sizeOf (p.num n) = 1 + sizeOf p + sizeOf n