Subtypes #
This file provides basic API for subtypes, which are defined in core.
A subtype is a type made from restricting another type, say α
, to its elements that satisfy some
predicate, say p : α → Prop
. Specifically, it is the type of pairs ⟨val, property⟩
where
val : α
and property : p val
. It is denoted subtype p
and notation {val : α // p val}
is
available.
A subtype has a natural coercion to the parent type, by coercing ⟨val, property⟩
to val
. As
such, subtypes can be thought of as bundled sets, the difference being that elements of a set are
still of type α
while elements of a subtype aren't.
See Note [custom simps projection]
Equations
- subtype.simps.coe x = ↑x
A version of x.property
or x.2
where p
is syntactically applied to the coercion of x
instead of x.1
. A similar result is subtype.mem
in data.set.basic
.
An alternative version of subtype.forall
. This one is useful if Lean cannot figure out q
when using subtype.forall
from right to left.
An alternative version of subtype.exists
. This one is useful if Lean cannot figure out q
when using subtype.exists
from right to left.
Restrict a (dependent) function to a subtype
Equations
- subtype.restrict p f x = f ↑x
Defining a map into a subtype, this can be seen as an "coinduction principle" of subtype
Equations
- subtype.coind f h = λ (a : α), ⟨f a, _⟩
Restriction of a function to a function on subtypes.
Equations
- subtype.map f h = λ (x : subtype p), ⟨f ↑x, _⟩
Equations
- subtype.setoid p = {r := has_equiv.equiv (subtype.has_equiv p), iseqv := _}
Some facts about sets, which require that α
is a type.