Sets #
This file sets up the theory of sets whose elements have a given type.
Main definitions #
Given a type X
and a predicate p : X → Prop
:
Set X
: the type of sets whose elements have typeX
{a : X | p a} : Set X
: the set of all elements ofX
satisfyingp
{a | p a} : Set X
: a more concise notation for{a : X | p a}
{f x y | (x : X) (y : Y)} : Set Z
: a more concise notation for{z : Z | ∃ x y, f x y = z}
{a ∈ S | p a} : Set X
: givenS : Set X
, the subset ofS
consisting of its elements satisfyingp
.
Implementation issues #
As in Lean 3, Set X := X → Prop
This file is a port of the core Lean 3 file lib/lean/library/init/data/set.lean
.
A set is a collection of elements of some type α
.
Although Set
is defined as α → Prop
, this is an implementation detail which should not be
relied on. Instead, setOf
and membership of a set (∈
) should be used to convert between sets
and predicates.
Instances For
- AddGroupFilterBasis.instMembershipSet
- AddSubgroup.instCanLiftSetCoeAndMemOfNatForallForallForallForallHAddForallForallNeg
- AddSubmonoid.instCanLiftSetCoeAndMemOfNatForallForallForallForallHAdd
- AddSubsemigroup.instCanLiftSetCoeForallForallForallMemForallHAdd
- CompactExhaustion.instFunLikeNatSet
- Filter.instMembership
- Finset.instCoeTCSet
- GroupFilterBasis.instMembershipSet
- Infinite.set
- MeasureTheory.Measure.instFunLike
- MeasureTheory.OuterMeasure.instFunLikeSetENNReal
- ModuleFilterBasis.GroupFilterBasis.hasMem
- NonUnitalStarSubalgebra.instCanLiftSetCoeAndMemOfNatForallForallForallForallHAddForallForallForallForallHMulForallForallForallHSMulForallForallStar
- NonUnitalSubalgebra.instCanLiftSetCoeAndMemOfNatForallForallForallForallHAddForallForallForallForallHMulForallForallForallHSMul
- NonUnitalSubring.instCanLiftSetCoeAndMemOfNatForallForallForallForallHAddForallForallForallForallHMulForallForallNeg
- NonUnitalSubsemiring.instCanLiftSetCoeAndMemOfNatForallForallForallForallHAddForallForallForallForallHMul
- RingFilterBasis.instMembershipSet
- Set.Notation.instCoeHeadElem
- Set.canLift
- Set.fintype
- Set.instAddLeftMono
- Set.instAddRightMono
- Set.instAlternative
- Set.instBooleanAlgebra
- Set.instCanLiftFinsetToSetFinite
- Set.instCoeSortType
- Set.instCommApplicative
- Set.instCompleteAtomicBooleanAlgebra
- Set.instEmptyCollection
- Set.instFinite
- Set.instFunctor
- Set.instHasCompl
- Set.instHasSSubset
- Set.instHasSubset
- Set.instInfSet
- Set.instInhabited
- Set.instInsert
- Set.instInter
- Set.instInvolutiveStar
- Set.instIsAntisymmSubset
- Set.instIsAsymmSSubset
- Set.instIsAtomistic
- Set.instIsCoatomistic
- Set.instIsIrreflSSubset
- Set.instIsNonstrictStrictOrderSubsetSSubset
- Set.instIsReflSubset
- Set.instIsTransSSubset
- Set.instIsTransSubset
- Set.instLE
- Set.instLawfulFunctor
- Set.instLawfulMonad
- Set.instLawfulSingleton
- Set.instMeasurableSingletonClass
- Set.instMeasurableSpace
- Set.instMembership
- Set.instMulLeftMono
- Set.instMulRightMono
- Set.instNoZeroDivisors
- Set.instNoZeroSMulDivisors
- Set.instOrderTop
- Set.instSDiff
- Set.instSProd
- Set.instSingletonSet
- Set.instSupSet
- Set.instTrivialStar
- Set.instUnion
- Set.involutiveInv
- Set.involutiveNeg
- Set.isCentralScalar
- Set.isCentralVAdd
- Set.isScalarTower
- Set.isScalarTower'
- Set.isScalarTower''
- Set.noZeroSMulDivisors_set
- Set.nontrivial_of_nonempty
- Set.smulCommClass
- Set.smulCommClass_set
- Set.smulCommClass_set'
- Set.smulCommClass_set''
- Set.uniqueEmpty
- Set.vaddAssocClass
- Set.vaddAssocClass'
- Set.vaddAssocClass''
- Set.vaddCommClass
- Set.vaddCommClass_set
- Set.vaddCommClass_set'
- Set.vaddCommClass_set''
- Set.vsub
- SetLike.instCoeTCSet
- StarSubalgebra.instCanLiftSetCoeAndForallForallForallMemForallHAddForallForallForallForallHMulForallCoeRingHomAlgebraMapForallForallStar
- Subalgebra.instCanLiftSetCoeAndForallForallForallMemForallHAddForallForallForallForallHMulForallCoeRingHomAlgebraMap
- Subgroup.instCanLiftSetCoeAndMemOfNatForallForallForallForallHMulForallForallInv
- Submodule.instCanLiftSetCoeAndMemOfNatForallForallForallForallHAddForallForallForallHSMul
- Submodule.instCovariantClassSetHSMulLe
- Submonoid.instCanLiftSetCoeAndMemOfNatForallForallForallForallHMul
- Subring.instCanLiftSetCoeAndMemOfNatForallForallForallForallHAddForallForallForallForallHMulForallForallNeg
- Subsemigroup.instCanLiftSetCoeForallForallForallMemForallHMul
- Subsemiring.instCanLiftSetCoeAndMemOfNatForallForallForallForallHAddForallForallForallForallHMul
- TileStructure.Forest.instCoeHeadSet𝔓Real
- TileStructure.Row.instCoeHeadSet𝔓Real
- TopologicalSpace.Closeds.instCanLiftSetCoeIsClosed
- TopologicalSpace.Compacts.instCanLiftSetCoeIsCompact
- TopologicalSpace.IrreducibleCloseds.instCanLiftSetCoeAndIsIrreducibleIsClosed
- TopologicalSpace.OpenNhdsOf.canLiftSet
- TopologicalSpace.Opens.instCanLiftSetCoeIsOpen
- Ultrafilter.instMembershipSet
- instCoeGridSet
- instMembershipSetFilterBasis
- small_set
Equations
- Set.instMembership = { mem := Set.Mem }
We introduce ≤
before ⊆
to help the unifier when applying lattice theorems
to subset hypotheses.
Equations
- Set.instLE = { le := Set.Subset }
Equations
- Set.instHasSubset = { Subset := fun (x1 x2 : Set α) => x1 ≤ x2 }
Equations
- Set.instEmptyCollection = { emptyCollection := fun (x : α) => False }
Set builder syntax. This can be elaborated to either a Set
or a Finset
depending on context.
The elaborators for this syntax are located in:
Data.Set.Defs
for theSet
builder notation elaborator for syntax of the form{x | p x}
,{x : α | p x}
,{binder x | p x}
.Data.Finset.Basic
for theFinset
builder notation elaborator for syntax of the form{x ∈ s | p x}
.Data.Fintype.Basic
for theFinset
builder notation elaborator for syntax of the form{x | p x}
,{x : α | p x}
,{x ∉ s | p x}
,{x ≠ a | p x}
.Order.LocallyFinite.Basic
for theFinset
builder notation elaborator for syntax of the form{x ≤ a | p x}
,{x ≥ a | p x}
,{x < a | p x}
,{x > a | p x}
.
Equations
- One or more equations did not get rendered due to their size.
Elaborate set builder notation for Set
.
{x | p x}
is elaborated asSet.setOf fun x ↦ p x
{x : α | p x}
is elaborated asSet.setOf fun x : α ↦ p x
{binder x | p x}
, wherex
is bound by thebinder
binder, is elaborated as{x | binder x ∧ p x}
. The typical example is{x ∈ s | p x}
, which is elaborated as{x | x ∈ s ∧ p x}
. The possible binders are· ∈ s
,· ∉ s
· ⊆ s
,· ⊂ s
,· ⊇ s
,· ⊃ s
· ≤ a
,· ≥ a
,· < a
,· > a
,· ≠ a
More binders can be declared using the
binder_predicate
command, seeInit.BinderPredicates
for more info.
See also
Data.Finset.Basic
for theFinset
builder notation elaborator partly overriding this one for syntax of the form{x ∈ s | p x}
.Data.Fintype.Basic
for theFinset
builder notation elaborator partly overriding this one for syntax of the form{x | p x}
,{x : α | p x}
,{x ∉ s | p x}
,{x ≠ a | p x}
.Order.LocallyFinite.Basic
for theFinset
builder notation elaborator partly overriding this one for syntax of the form{x ≤ a | p x}
,{x ≥ a | p x}
,{x < a | p x}
,{x > a | p x}
.
Equations
- One or more equations did not get rendered due to their size.
Unexpander for set builder notation.
Equations
- One or more equations did not get rendered due to their size.
{ f x y | (x : X) (y : Y) }
is notation for the set of elements f x y
constructed from the
binders x
and y
, equivalent to {z : Z | ∃ x y, f x y = z}
.
If f x y
is a single identifier, it must be parenthesized to avoid ambiguity with {x | p x}
;
for instance, {(x) | (x : Nat) (y : Nat) (_hxy : x = y^2)}
.
Equations
- One or more equations did not get rendered due to their size.
{ pat : X | p }
is notation for pattern matching in set-builder notation, wherepat
is a pattern that is matched by all objects of typeX
andp
is a proposition that can refer to variables in the pattern. It is the set of all objects of typeX
which, when matched with the patternpat
, makep
come out true.{ pat | p }
is the same, but in the case when the typeX
can be inferred.
For example, { (m, n) : ℕ × ℕ | m * n = 12 }
denotes the set of all ordered pairs of
natural numbers whose product is 12.
Note that if the type ascription is left out and p
can be interpreted as an extended binder,
then the extended binder interpretation will be used. For example, { n + 1 | n < 3 }
will
be interpreted as { x : Nat | ∃ n < 3, n + 1 = x }
rather than using pattern matching.
Equations
- One or more equations did not get rendered due to their size.
{ pat : X | p }
is notation for pattern matching in set-builder notation, wherepat
is a pattern that is matched by all objects of typeX
andp
is a proposition that can refer to variables in the pattern. It is the set of all objects of typeX
which, when matched with the patternpat
, makep
come out true.{ pat | p }
is the same, but in the case when the typeX
can be inferred.
For example, { (m, n) : ℕ × ℕ | m * n = 12 }
denotes the set of all ordered pairs of
natural numbers whose product is 12.
Note that if the type ascription is left out and p
can be interpreted as an extended binder,
then the extended binder interpretation will be used. For example, { n + 1 | n < 3 }
will
be interpreted as { x : Nat | ∃ n < 3, n + 1 = x }
rather than using pattern matching.
Equations
- One or more equations did not get rendered due to their size.
Pretty printing for set-builder notation with pattern matching.
Equations
- One or more equations did not get rendered due to their size.
The universal set on a type α
is the set containing all elements of α
.
This is conceptually the "same as" α
(in set theory, it is actually the same), but type theory
makes the distinction that α
is a type while Set.univ
is a term of type Set α
. Set.univ
can
itself be coerced to a type ↥Set.univ
which is in bijection with (but distinct from) α
.
Equations
- Set.instInsert = { insert := Set.insert }
Equations
- Set.instSingletonSet = { singleton := Set.singleton }
Equations
- Set.instUnion = { union := Set.union }
Equations
- Set.instInter = { inter := Set.inter }
Equations
- Set.instSDiff = { sdiff := Set.diff }
𝒫 s
is the set of all subsets of s
.
Equations
- Set.term𝒫_ = Lean.ParserDescr.node `Set.term𝒫_ 100 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "𝒫") (Lean.ParserDescr.cat `term 100))