The areas / V33. Data structures and computation
Mathlib.Testing.Plausible.Functions
36 declarations. Mathlib docs · Source
Plausible: generators for functions
This file defines Sampleable instances for ℤ → ℤ injective functions.
Injective functions are generated by creating a list of numbers and a permutation of that list. The permutation ensures that every input is mapped to a unique output. When an input is not found in the list the input itself is used as an output.
Injective functions f : α → α could be generated easily instead of
ℤ → ℤ by generating a List α, removing duplicates and creating a
permutation. One has to be careful when generating the domain to make
it vast enough that, when generating arguments to apply f to,
they argument should be likely to lie in the domain of f. This is
the reason that injective functions f : ℤ → ℤ are generated by
fixing the domain to the range [-2*size .. 2*size], with size
the size parameter of the gen monad.
Much of the machinery provided in this file is applicable to generate
injective functions of type α → α and new instances should be easy
to define.
Other classes of functions such as monotone functions can generated using similar techniques. For monotone functions, generating two lists, sorting them and matching them should suffice, with appropriate default values. Some care must be taken for shrinking such functions to make sure their defining property is invariant through shrinking. Injective functions are an example of how complicated it can get.
def Plausible.InjectiveFunction.ctorIdx E1 #
{α : Type u} → Plausible.InjectiveFunction α → ℕ
theorem Plausible.TotalFunction.zeroDefault.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} {β : Type u_2} (motive : Plausible.TotalFunction α β → Sort u_3) (x : Plausible.TotalFunction α β)
(h_1 : (A : List ((_ : α) × β)) → (a : β) → motive (Plausible.TotalFunction.withDefault A a)) (A : List ((_ : α) × β))
(a : β),
x = Plausible.TotalFunction.withDefault A a →
(match x with
| Plausible.TotalFunction.withDefault A a => h_1 A a) ≍
h_1 A a
theorem Plausible.InjectiveFunction.mapToSelf.inj E1 #
∀ {α : Type u} {xs : List ((_ : α) × α)} {a : (List.map Sigma.fst xs).Perm (List.map Sigma.snd xs)}
{a_1 : (List.map Sigma.snd xs).Nodup} {xs_1 : List ((_ : α) × α)}
{a_2 : (List.map Sigma.fst xs_1).Perm (List.map Sigma.snd xs_1)} {a_3 : (List.map Sigma.snd xs_1).Nodup},
Plausible.InjectiveFunction.mapToSelf xs a a_1 = Plausible.InjectiveFunction.mapToSelf xs_1 a_2 a_3 → xs = xs_1
theorem List.dlookup.match_1.congr_eq_1 E1 #
∀ {α : Type u_2} {β : α → Type u_1} (motive : List (Sigma β) → Sort u_3) (x : List (Sigma β)) (h_1 : Unit → motive [])
(h_2 : (a' : α) → (b : β a') → (l : List (Sigma β)) → motive (⟨a', b⟩ :: l)),
x = [] →
(match x with
| [] => h_1 ()
| ⟨a', b⟩ :: l => h_2 a' b l) ≍
h_1 ()
theorem Plausible.TotalFunction.List.toFinmap'.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} {β : Type u_2} (motive : α × β → Sort u_3) (x : α × β) (h_1 : (a : α) → (b : β) → motive (a, b))
(a : α) (b : β),
x = (a, b) →
(match x with
| (a, b) => h_1 a b) ≍
h_1 a b
theorem Plausible.InjectiveFunction.mapToSelf.injEq E0 #
∀ {α : Type u} (xs : List ((_ : α) × α)) (a : (List.map Sigma.fst xs).Perm (List.map Sigma.snd xs))
(a_1 : (List.map Sigma.snd xs).Nodup) (xs_1 : List ((_ : α) × α))
(a_2 : (List.map Sigma.fst xs_1).Perm (List.map Sigma.snd xs_1)) (a_3 : (List.map Sigma.snd xs_1).Nodup),
(Plausible.InjectiveFunction.mapToSelf xs a a_1 = Plausible.InjectiveFunction.mapToSelf xs_1 a_2 a_3) = (xs = xs_1)
theorem Plausible.TotalFunction.apply.congr_simp E1 #
∀ {α : Type u} {β : Type v} {inst : DecidableEq α} [inst_1 : DecidableEq α] (a a_1 : Plausible.TotalFunction α β),
a = a_1 → ∀ (a_2 a_3 : α), a_2 = a_3 → a.apply a_2 = a_1.apply a_3
theorem List.dlookup.match_1.congr_eq_2 E1 #
∀ {α : Type u_2} {β : α → Type u_1} (motive : List (Sigma β) → Sort u_3) (x : List (Sigma β)) (h_1 : Unit → motive [])
(h_2 : (a' : α) → (b : β a') → (l : List (Sigma β)) → motive (⟨a', b⟩ :: l)) (a' : α) (b : β a') (l : List (Sigma β)),
x = ⟨a', b⟩ :: l →
(match x with
| [] => h_1 ()
| ⟨a', b⟩ :: l => h_2 a' b l) ≍
h_2 a' b l
def Plausible.TotalFunction.zeroDefault E1 #
{α : Type u} → {β : Type v} → [Zero β] → Plausible.TotalFunction α β → Plausible.TotalFunction α β
Map a TotalFunction to one whose default value is zero so that it represents a Finsupp.
def Plausible.TotalFunction.zeroDefaultSupp E1 #
{α : Type u} → {β : Type v} → [DecidableEq α] → [Zero β] → [DecidableEq β] → Plausible.TotalFunction α β → Finset α
The support of a zero default TotalFunction.
def Plausible.TotalFunction.applyFinsupp E1 #
{α : Type u} → {β : Type v} → [DecidableEq α] → [inst : Zero β] → [DecidableEq β] → Plausible.TotalFunction α β → α →₀ β
Create a finitely supported function from a total function by taking the default value to zero.
instance Plausible.TotalFunction.Finsupp.sampleableExt E0 #
{α : Type u} →
{β : Type v} →
[DecidableEq α] →
[inst : Zero β] →
[DecidableEq β] →
[Plausible.SampleableExt α] → [Plausible.SampleableExt β] → [Repr α] → Plausible.SampleableExt (α →₀ β)
instance Plausible.TotalFunction.DFinsupp.sampleableExt E0 #
{α : Type u} →
{β : Type v} →
[DecidableEq α] →
[inst : Zero β] →
[DecidableEq β] →
[Plausible.SampleableExt α] → [Plausible.SampleableExt β] → [Repr α] → Plausible.SampleableExt (Π₀ (x : α), β)
inductive Plausible.InjectiveFunction E1 #
Type u → Type u
Data structure specifying a total function using a list of pairs and a default value returned when the input is not in the domain of the partial function.
mapToSelf f encodes x ↦ f x when x ∈ f and x ↦ x,
i.e. x to itself, otherwise.
We use Σ to encode mappings instead of × because we
rely on the association list API defined in Mathlib/Data/List/Sigma.lean.
ctor Plausible.InjectiveFunction.mapToSelf E0 #
{α : Type u} →
(xs : List ((_ : α) × α)) →
(List.map Sigma.fst xs).Perm (List.map Sigma.snd xs) → (List.map Sigma.snd xs).Nodup → Plausible.InjectiveFunction α
instance Plausible.instInhabitedInjectiveFunction E0 #
{α : Type u} → Inhabited (Plausible.InjectiveFunction α)
def Plausible.InjectiveFunction.apply E1 #
{α : Type u} → [DecidableEq α] → Plausible.InjectiveFunction α → α → α
Apply a total function to an argument.
def Plausible.InjectiveFunction.repr E1 #
{α : Type u} → [Repr α] → Plausible.InjectiveFunction α → String
Produce a string for a given InjectiveFunction.
The output is of the form [x₀ ↦ f x₀, .. xₙ ↦ f xₙ, x ↦ x].
Unlike for TotalFunction, the default value is not a constant
but the identity function.
instance Plausible.InjectiveFunction.instRepr E0 #
(α : Type u) → [Repr α] → Repr (Plausible.InjectiveFunction α)
def Plausible.InjectiveFunction.List.applyId E1 #
{α : Type u} → [DecidableEq α] → List (α × α) → α → α
Interpret a list of pairs as a total function, defaulting to the identity function when no entries are found for a given function
theorem Plausible.InjectiveFunction.List.applyId_cons E0 #
∀ {α : Type u} [inst : DecidableEq α] (xs : List (α × α)) (x y z : α),
Plausible.InjectiveFunction.List.applyId ((y, z) :: xs) x =
if y = x then z else Plausible.InjectiveFunction.List.applyId xs x
theorem Plausible.InjectiveFunction.List.applyId_zip_eq E0 #
∀ {α : Type u} [inst : DecidableEq α] {xs ys : List α},
xs.Nodup →
xs.length = ys.length →
∀ (x y : α) (i : ℕ),
xs[i]? = some x → (Plausible.InjectiveFunction.List.applyId (xs.zip ys) x = y ↔ ys[i]? = some y)
theorem Plausible.InjectiveFunction.applyId_mem_iff E0 #
∀ {α : Type u} [inst : DecidableEq α] {xs ys : List α},
xs.Nodup → xs.Perm ys → ∀ (x : α), Plausible.InjectiveFunction.List.applyId (xs.zip ys) x ∈ ys ↔ x ∈ xs
theorem Plausible.InjectiveFunction.List.applyId_eq_self E1 #
∀ {α : Type u} [inst : DecidableEq α] {xs ys : List α},
∀ x ∉ xs, Plausible.InjectiveFunction.List.applyId (xs.zip ys) x = x
theorem Plausible.InjectiveFunction.applyId_injective E1 #
∀ {α : Type u} [inst : DecidableEq α] {xs ys : List α},
xs.Nodup → xs.Perm ys → Function.Injective (Plausible.InjectiveFunction.List.applyId (xs.zip ys))
def Plausible.InjectiveFunction.Perm.slice E1 #
{α : Type u} →
[DecidableEq α] →
ℕ →
ℕ →
(xs : List α) ×' (ys : List α) ×' xs.Perm ys ∧ ys.Nodup →
(xs : List α) ×' (ys : List α) ×' xs.Perm ys ∧ ys.Nodup
Remove a slice of length m at index n in a list and a permutation, maintaining the property
that it is a permutation.
def Plausible.InjectiveFunction.sliceSizes E1 #
ℕ → MLList Id ℕ+
A list, in decreasing order, of sizes that should be
sliced off a list of length n
def Plausible.InjectiveFunction.shrinkPerm E1 #
{α : Type} →
[DecidableEq α] →
(xs : List α) ×' (ys : List α) ×' xs.Perm ys ∧ ys.Nodup →
List ((xs : List α) ×' (ys : List α) ×' xs.Perm ys ∧ ys.Nodup)
Shrink a permutation of a list, slicing a segment in the middle.
The sizes of the slice being removed start at n (with n the length
of the list) and then n / 2, then n / 4, etc. down to 1. The slices
will be taken at index 0, n / k, 2n / k, 3n / k, etc.
def Plausible.InjectiveFunction.shrink E1 #
{α : Type} → [DecidableEq α] → Plausible.InjectiveFunction α → List (Plausible.InjectiveFunction α)
Shrink an injective function slicing a segment in the middle of the domain and removing the corresponding elements in the codomain, hence maintaining the property that one is a permutation of the other.
def Plausible.InjectiveFunction.mk E1 #
{α : Type u} → (xs ys : List α) → xs.Perm ys → ys.Nodup → Plausible.InjectiveFunction α
Create an injective function from one list and a permutation of that list.
theorem Plausible.InjectiveFunction.injective E1 #
∀ {α : Type u} [inst : DecidableEq α] (f : Plausible.InjectiveFunction α), Function.Injective f.apply
instance Plausible.InjectiveFunction.instArbitraryInt E0 #
Plausible.Arbitrary (Plausible.InjectiveFunction ℤ)
instance Plausible.InjectiveFunction.PiInjective.sampleableExt E0 #
Plausible.SampleableExt { f // Function.Injective f }
instance Plausible.Injective.testable E0 #
{α : Type u} →
{β : Type v} →
(f : α → β) →
[I :
Plausible.Testable
(Plausible.NamedBinder "x"
(∀ (x : α), Plausible.NamedBinder "y" (∀ (y : α), Plausible.NamedBinder "H" (f x = f y → x = y))))] →
Plausible.Testable (Function.Injective f)
instance Plausible.Monotone.testable E0 #
{α : Type u} →
{β : Type v} →
[inst : Preorder α] →
[inst_1 : Preorder β] →
(f : α → β) →
[I :
Plausible.Testable
(Plausible.NamedBinder "x"
(∀ (x : α), Plausible.NamedBinder "y" (∀ (y : α), Plausible.NamedBinder "H" (x ≤ y → f x ≤ f y))))] →
Plausible.Testable (Monotone f)
instance Plausible.Antitone.testable E0 #
{α : Type u} →
{β : Type v} →
[inst : Preorder α] →
[inst_1 : Preorder β] →
(f : α → β) →
[I :
Plausible.Testable
(Plausible.NamedBinder "x"
(∀ (x : α), Plausible.NamedBinder "y" (∀ (y : α), Plausible.NamedBinder "H" (x ≤ y → f y ≤ f x))))] →
Plausible.Testable (Antitone f)