Documentation

Mathlib.Testing.Plausible.Functions

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 insures 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.TotalFunction.zeroDefault {α : Type u} {β : Type v} [Zero β] :
TotalFunction α βTotalFunction α β

Map a TotalFunction to one whose default value is zero so that it represents a Finsupp.

Instances For
    def Plausible.TotalFunction.zeroDefaultSupp {α : Type u} {β : Type v} [DecidableEq α] [Zero β] [DecidableEq β] :
    TotalFunction α βFinset α

    The support of a zero default TotalFunction.

    Instances For
      def Plausible.TotalFunction.applyFinsupp {α : Type u} {β : Type v} [DecidableEq α] [Zero β] [DecidableEq β] (tf : TotalFunction α β) :
      α →₀ β

      Create a finitely supported function from a total function by taking the default value to zero.

      Instances For
        @[implicit_reducible]
        instance Plausible.TotalFunction.Finsupp.sampleableExt {α : Type u} {β : Type v} [DecidableEq α] [Zero β] [DecidableEq β] [SampleableExt α] [SampleableExt β] [Repr α] :
        SampleableExt (α →₀ β)
        @[implicit_reducible]
        instance Plausible.TotalFunction.DFinsupp.sampleableExt {α : Type u} {β : Type v} [DecidableEq α] [Zero β] [DecidableEq β] [SampleableExt α] [SampleableExt β] [Repr α] :
        SampleableExt (Π₀ (x : α), β)
        inductive Plausible.InjectiveFunction (α : 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.

        • mapToSelf {α : Type u} (xs : List ((_ : α) × α)) : (List.map Sigma.fst xs).Perm (List.map Sigma.snd xs)(List.map Sigma.snd xs).NodupInjectiveFunction α
        Instances For
          @[implicit_reducible]
          def Plausible.InjectiveFunction.apply {α : Type u} [DecidableEq α] :
          InjectiveFunction ααα

          Apply a total function to an argument.

          Instances For
            def Plausible.InjectiveFunction.repr {α : Type u} [Repr α] :
            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.

            Instances For
              @[implicit_reducible]
              instance Plausible.InjectiveFunction.instRepr (α : Type u) [Repr α] :
              def Plausible.InjectiveFunction.List.applyId {α : Type u} [DecidableEq α] (xs : List (α × α)) (x : α) :
              α

              Interpret a list of pairs as a total function, defaulting to the identity function when no entries are found for a given function

              Instances For
                @[simp]
                theorem Plausible.InjectiveFunction.List.applyId_cons {α : Type u} [DecidableEq α] (xs : List (α × α)) (x y z : α) :
                applyId ((y, z) :: xs) x = if y = x then z else applyId xs x
                theorem Plausible.InjectiveFunction.List.applyId_zip_eq {α : Type u} [DecidableEq α] {xs ys : List α} (h₀ : xs.Nodup) (h₁ : xs.length = ys.length) (x y : α) (i : ) (h₂ : xs[i]? = some x) :
                applyId (xs.zip ys) x = y ys[i]? = some y
                theorem Plausible.InjectiveFunction.applyId_mem_iff {α : Type u} [DecidableEq α] {xs ys : List α} (h₀ : xs.Nodup) (h₁ : xs.Perm ys) (x : α) :
                List.applyId (xs.zip ys) x ys x xs
                theorem Plausible.InjectiveFunction.List.applyId_eq_self {α : Type u} [DecidableEq α] {xs ys : List α} (x : α) :
                xxsapplyId (xs.zip ys) x = x
                theorem Plausible.InjectiveFunction.applyId_injective {α : Type u} [DecidableEq α] {xs ys : List α} (h₀ : xs.Nodup) (h₁ : xs.Perm ys) :
                Function.Injective (List.applyId (xs.zip ys))
                def Plausible.InjectiveFunction.Perm.slice {α : Type u} [DecidableEq α] (n m : ) :
                (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.

                Instances For
                  @[irreducible]

                  A list, in decreasing order, of sizes that should be sliced off a list of length n

                  Instances For
                    def Plausible.InjectiveFunction.shrinkPerm {α : Type} [DecidableEq α] :
                    (xs : List α) ×' (ys : List α) ×' xs.Perm ys ys.NodupList ((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.

                    Instances For
                      def Plausible.InjectiveFunction.shrink {α : Type} [DecidableEq α] :

                      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.

                      Instances For
                        def Plausible.InjectiveFunction.mk {α : Type u} (xs ys : List α) (h : xs.Perm ys) (h' : ys.Nodup) :

                        Create an injective function from one list and a permutation of that list.

                        Instances For
                          theorem Plausible.InjectiveFunction.injective {α : Type u} [DecidableEq α] (f : InjectiveFunction α) :
                          Function.Injective f.apply
                          @[implicit_reducible]
                          instance Plausible.InjectiveFunction.PiInjective.sampleableExt :
                          SampleableExt { f : // Function.Injective f }
                          @[implicit_reducible]
                          instance Plausible.Injective.testable {α : Type u} {β : Type v} (f : αβ) [I : Testable (NamedBinder "x" (∀ (x : α), NamedBinder "y" (∀ (y : α), NamedBinder "H" (f x = f yx = y))))] :
                          Testable (Function.Injective f)
                          @[implicit_reducible]
                          instance Plausible.Monotone.testable {α : Type u} {β : Type v} [Preorder α] [Preorder β] (f : αβ) [I : Testable (NamedBinder "x" (∀ (x : α), NamedBinder "y" (∀ (y : α), NamedBinder "H" (x yf x f y))))] :
                          Testable (Monotone f)
                          @[implicit_reducible]
                          instance Plausible.Antitone.testable {α : Type u} {β : Type v} [Preorder α] [Preorder β] (f : αβ) [I : Testable (NamedBinder "x" (∀ (x : α), NamedBinder "y" (∀ (y : α), NamedBinder "H" (x yf y f x))))] :
                          Testable (Antitone f)