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.
Map a total_function to one whose default value is zero so that it represents a finsupp.
Equations
- (Plausible.TotalFunction.withDefault A a).zeroDefault = Plausible.TotalFunction.withDefault A 0
Instances For
The support of a zero default TotalFunction
.
Equations
- (Plausible.TotalFunction.withDefault A a).zeroDefaultSupp = (List.map Sigma.fst (List.filter (fun (ab : (_ : α) × β) => decide (ab.snd ≠ 0)) A.dedupKeys)).toFinset
Instances For
Create a finitely supported function from a total function by taking the default value to zero.
Equations
- tf.applyFinsupp = { support := tf.zeroDefaultSupp, toFun := tf.zeroDefault.apply, mem_support_toFun := ⋯ }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
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).Nodup → Plausible.InjectiveFunction α
Instances For
Equations
- Plausible.instInhabitedInjectiveFunction = { default := Plausible.InjectiveFunction.mapToSelf [] ⋯ ⋯ }
Apply a total function to an argument.
Equations
- (Plausible.InjectiveFunction.mapToSelf m a a_1).apply x✝ = (List.dlookup x✝ m).getD x✝
Instances For
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.
Equations
- (Plausible.InjectiveFunction.mapToSelf m a a_1).repr = toString "[" ++ toString (Plausible.TotalFunction.reprAux m) ++ toString "x ↦ x]"
Instances For
Equations
- Plausible.InjectiveFunction.instRepr α = { reprPrec := fun (f : Plausible.InjectiveFunction α) (_p : ℕ) => Std.Format.text f.repr }
Interpret a list of pairs as a total function, defaulting to the identity function when no entries are found for a given function
Equations
- Plausible.InjectiveFunction.List.applyId xs x = (List.dlookup x (List.map Prod.toSigma xs)).getD x
Instances For
Remove a slice of length m
at index n
in a list and a permutation, maintaining the property
that it is a permutation.
Equations
- Plausible.InjectiveFunction.Perm.slice n m ⟨xs, ⟨ys, ⋯⟩⟩ = ⟨List.dropSlice n m xs, ⟨ys.inter (List.dropSlice n m xs), ⋯⟩⟩
Instances For
A list, in decreasing order, of sizes that should be
sliced off a list of length n
Equations
- Plausible.InjectiveFunction.sliceSizes x✝ = if h : 0 < x✝ then let_fun this := ⋯; MLList.cons ⟨x✝, h⟩ (Plausible.InjectiveFunction.sliceSizes (x✝ / 2)) else MLList.nil
Instances For
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create an injective function from one list and a permutation of that list.
Equations
- Plausible.InjectiveFunction.mk xs ys h h' = Plausible.InjectiveFunction.mapToSelf (Plausible.TotalFunction.List.toFinmap' (xs.zip ys)) ⋯ ⋯
Instances For
Equations
- One or more equations did not get rendered due to their size.