Zulip Chat Archive
Stream: lean4
Topic: I can't ascribe to a named subtype
C7X (Dec 19 2025 at 21:18):
In this MWE, I gave the subtype {n : ℕ // n % 2 == 0} the name NatEven. I can create a member of this type inline, by writing (⟨4, by decide⟩ : NatEven), but when I print out its type, Lean displays {n : ℕ // n % 2 == 0} instead of NatEven. Is this only graphical, and the term really does have type NatEven?
import Mathlib.Data.Nat.Basic
def NatEven : Type := {n : ℕ // n % 2 == 0}
-- The following term does not have type NatEven
#check (⟨4, by decide⟩ : NatEven)
Aaron Liu (Dec 19 2025 at 21:20):
no, this is just how it works
Aaron Liu (Dec 19 2025 at 21:21):
a type ascription does not mark the term as having that type
Aaron Liu (Dec 19 2025 at 21:21):
so inferring the type could give you something different (but still defeq)
Jireh Loreaux (Dec 19 2025 at 21:22):
use show NatEven from ... to get it to have type NatEven.
C7X (Dec 19 2025 at 21:24):
Thanks! One more question, is {n : ℕ // n % 2 == 0} definitionally equal to NatEven?
Aaron Liu (Dec 19 2025 at 21:25):
yes, it is
Aaron Liu (Dec 19 2025 at 21:26):
definitions are (usually) defeq to their contents
Aaron Liu (Dec 19 2025 at 21:26):
exceptions for example when you use well-founded recursion
Kevin Buzzard (Dec 20 2025 at 02:26):
Usually we would write n % 2 = 0 here I guess
Last updated: Dec 20 2025 at 21:32 UTC