Computable inverses for injective/surjective functions on finite types #
Main results #
Function.Injective.invOfMemRange
,Embedding.invOfMemRange
,Fintype.bijInv
: computable versions ofFunction.invFun
.Fintype.choose
: computably obtain a witness forExistsUnique
.
The inverse of an hf : injective
function f : α → β
, of the type ↥(Set.range f) → α
.
This is the computable version of Function.invFun
that requires Fintype α
and DecidableEq β
,
or the function version of applying (Equiv.ofInjective f hf).symm
.
This function should not usually be used for actual computation because for most cases,
an explicit inverse can be stated that has better computational properties.
This function computes by checking all terms a : α
to find the f a = b
, so it is O(N) where
N = Fintype.card α
.
Equations
- hf.invOfMemRange b = Finset.choose (fun (a : α) => f a = ↑b) Finset.univ ⋯
Instances For
The inverse of an embedding f : α ↪ β
, of the type ↥(Set.range f) → α
.
This is the computable version of Function.invFun
that requires Fintype α
and DecidableEq β
,
or the function version of applying (Equiv.ofInjective f f.injective).symm
.
This function should not usually be used for actual computation because for most cases,
an explicit inverse can be stated that has better computational properties.
This function computes by checking all terms a : α
to find the f a = b
, so it is O(N) where
N = Fintype.card α
.
Equations
- f.invOfMemRange b = ⋯.invOfMemRange b
Instances For
Given a fintype α
and a predicate p
, associate to a proof that there is a unique element of
α
satisfying p
this unique element, as an element of the corresponding subtype.
Equations
- Fintype.chooseX p hp = ⟨Finset.choose p Finset.univ ⋯, ⋯⟩
Instances For
Given a fintype α
and a predicate p
, associate to a proof that there is a unique element of
α
satisfying p
this unique element, as an element of α
.
Equations
- Fintype.choose p hp = ↑(Fintype.chooseX p hp)
Instances For
bijInv f
is the unique inverse to a bijection f
. This acts
as a computable alternative to Function.invFun
.
Equations
- Fintype.bijInv f_bij b = Fintype.choose (fun (a : α) => f a = b) ⋯