testing.slim_check.gen
⟷
Mathlib.Testing.SlimCheck.Gen
The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(last sync)
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -4,8 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Control.Random
-import Control.Uliftable
-import Data.List.BigOperators.Lemmas
+import Control.ULiftable
+import Algebra.BigOperators.List.Lemmas
import Data.List.Perm
#align_import testing.slim_check.gen from "leanprover-community/mathlib"@"9240e8be927a0955b9a82c6c85ef499ee3a626b8"
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -195,7 +195,7 @@ def freq (xs : List (ℕ+ × Gen α)) (pos : 0 < xs.length) : Gen α :=
List.length_le_sum_of_one_le _ fun i => by simp; intros; assumption
have : 0 ≤ s - 1 := le_tsub_of_add_le_right ha
ULiftable.adaptUp Gen.{0} Gen.{u} (chooseNat 0 (s - 1) this) fun i =>
- freqAux xs i.1 (by rcases i with ⟨i, h₀, h₁⟩ <;> rwa [le_tsub_iff_right] at h₁ <;> exact ha)
+ freqAux xs i.1 (by rcases i with ⟨i, h₀, h₁⟩ <;> rwa [le_tsub_iff_right] at h₁ <;> exact ha)
#align slim_check.gen.freq SlimCheck.Gen.freq
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce64cd319bb6b3e82f31c2d38e79080d377be451
@@ -3,10 +3,10 @@ Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
-import Mathbin.Control.Random
-import Mathbin.Control.Uliftable
-import Mathbin.Data.List.BigOperators.Lemmas
-import Mathbin.Data.List.Perm
+import Control.Random
+import Control.Uliftable
+import Data.List.BigOperators.Lemmas
+import Data.List.Perm
#align_import testing.slim_check.gen from "leanprover-community/mathlib"@"9240e8be927a0955b9a82c6c85ef499ee3a626b8"
mathlib commit https://github.com/leanprover-community/mathlib/commit/8ea5598db6caeddde6cb734aa179cc2408dbd345
@@ -2,17 +2,14 @@
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-
-! This file was ported from Lean 3 source module testing.slim_check.gen
-! leanprover-community/mathlib commit 9240e8be927a0955b9a82c6c85ef499ee3a626b8
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathbin.Control.Random
import Mathbin.Control.Uliftable
import Mathbin.Data.List.BigOperators.Lemmas
import Mathbin.Data.List.Perm
+#align_import testing.slim_check.gen from "leanprover-community/mathlib"@"9240e8be927a0955b9a82c6c85ef499ee3a626b8"
+
/-!
# `gen` Monad
mathlib commit https://github.com/leanprover-community/mathlib/commit/9240e8be927a0955b9a82c6c85ef499ee3a626b8
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
! This file was ported from Lean 3 source module testing.slim_check.gen
-! leanprover-community/mathlib commit 23f67f2fd1b092739d7fbfcdfaab65ea2783a39d
+! leanprover-community/mathlib commit 9240e8be927a0955b9a82c6c85ef499ee3a626b8
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
@@ -16,6 +16,9 @@ import Mathbin.Data.List.Perm
/-!
# `gen` Monad
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
This monad is used to formulate randomized computations with a parameter
to specify the desired size of the result.
mathlib commit https://github.com/leanprover-community/mathlib/commit/f2ad3645af9effcdb587637dc28a6074edc813f9
@@ -103,12 +103,12 @@ def chooseNat' (x y : ℕ) (p : x < y) : Gen (Set.Ico x y) :=
open Nat
-instance : Uliftable Gen.{u} Gen.{v} :=
+instance : ULiftable Gen.{u} Gen.{v} :=
ReaderT.uliftable' (Equiv.ulift.trans Equiv.ulift.symm)
instance : HasOrelse Gen.{u} :=
⟨fun α x y => do
- let b ← Uliftable.up <| chooseAny Bool
+ let b ← ULiftable.up <| chooseAny Bool
if b then x else y⟩
variable {α}
@@ -139,7 +139,7 @@ by the size parameter of `gen`. -/
def listOf (cmd : Gen α) : Gen (List α) :=
sized fun sz => do
do
- let ⟨n⟩ ← Uliftable.up <| choose_nat 0 (sz + 1) (by decide)
+ let ⟨n⟩ ← ULiftable.up <| choose_nat 0 (sz + 1) (by decide)
let v ← vector_of n cmd
return v
#align slim_check.gen.list_of SlimCheck.Gen.listOf
@@ -150,7 +150,7 @@ open ULift
#print SlimCheck.Gen.oneOf /-
/-- Given a list of example generators, choose one to create an example. -/
def oneOf (xs : List (Gen α)) (pos : 0 < xs.length) : Gen α := do
- let ⟨⟨n, h, h'⟩⟩ ← Uliftable.up <| chooseNat' 0 xs.length Pos
+ let ⟨⟨n, h, h'⟩⟩ ← ULiftable.up <| chooseNat' 0 xs.length Pos
List.nthLe xs n h'
#align slim_check.gen.one_of SlimCheck.Gen.oneOf
-/
@@ -158,7 +158,7 @@ def oneOf (xs : List (Gen α)) (pos : 0 < xs.length) : Gen α := do
#print SlimCheck.Gen.elements /-
/-- Given a list of example generators, choose one to create an example. -/
def elements (xs : List α) (pos : 0 < xs.length) : Gen α := do
- let ⟨⟨n, h₀, h₁⟩⟩ ← Uliftable.up <| chooseNat' 0 xs.length Pos
+ let ⟨⟨n, h₀, h₁⟩⟩ ← ULiftable.up <| chooseNat' 0 xs.length Pos
pure <| List.nthLe xs n h₁
#align slim_check.gen.elements SlimCheck.Gen.elements
-/
@@ -194,7 +194,7 @@ def freq (xs : List (ℕ+ × Gen α)) (pos : 0 < xs.length) : Gen α :=
List.length_map (Subtype.val ∘ Prod.fst) xs ▸
List.length_le_sum_of_one_le _ fun i => by simp; intros; assumption
have : 0 ≤ s - 1 := le_tsub_of_add_le_right ha
- Uliftable.adaptUp Gen.{0} Gen.{u} (chooseNat 0 (s - 1) this) fun i =>
+ ULiftable.adaptUp Gen.{0} Gen.{u} (chooseNat 0 (s - 1) this) fun i =>
freqAux xs i.1 (by rcases i with ⟨i, h₀, h₁⟩ <;> rwa [le_tsub_iff_right] at h₁ <;> exact ha)
#align slim_check.gen.freq SlimCheck.Gen.freq
@@ -205,7 +205,7 @@ def permutationOf {α : Type u} : ∀ xs : List α, Gen (Subtype <| List.Perm xs
| [] => pure ⟨[], List.Perm.nil⟩
| x::xs => do
let ⟨xs', h⟩ ← permutation_of xs
- let ⟨⟨n, _, h'⟩⟩ ← Uliftable.up <| chooseNat 0 xs'.length (by decide)
+ let ⟨⟨n, _, h'⟩⟩ ← ULiftable.up <| chooseNat 0 xs'.length (by decide)
pure
⟨List.insertNth n x xs',
List.Perm.trans (List.Perm.cons _ h) (List.perm_insertNth _ _ h').symm⟩
mathlib commit https://github.com/leanprover-community/mathlib/commit/9fb8964792b4237dac6200193a0d533f1b3f7423
@@ -56,7 +56,6 @@ deriving Monad, LawfulMonad
variable (α : Type u)
--- mathport name: «expr .. »
local infixl:41 " .. " => Set.Icc
/-- Execute a `gen` inside the `io` monad using `i` as the example
@@ -134,6 +133,7 @@ def vectorOf : ∀ (n : ℕ) (cmd : Gen α), Gen (Vector α n)
| succ n, cmd => Vector.cons <$> cmd <*> vector_of n cmd
#align slim_check.gen.vector_of SlimCheck.Gen.vectorOf
+#print SlimCheck.Gen.listOf /-
/-- Create a list of examples using `cmd`. The size is controlled
by the size parameter of `gen`. -/
def listOf (cmd : Gen α) : Gen (List α) :=
@@ -143,20 +143,25 @@ def listOf (cmd : Gen α) : Gen (List α) :=
let v ← vector_of n cmd
return v
#align slim_check.gen.list_of SlimCheck.Gen.listOf
+-/
open ULift
+#print SlimCheck.Gen.oneOf /-
/-- Given a list of example generators, choose one to create an example. -/
def oneOf (xs : List (Gen α)) (pos : 0 < xs.length) : Gen α := do
let ⟨⟨n, h, h'⟩⟩ ← Uliftable.up <| chooseNat' 0 xs.length Pos
List.nthLe xs n h'
#align slim_check.gen.one_of SlimCheck.Gen.oneOf
+-/
+#print SlimCheck.Gen.elements /-
/-- Given a list of example generators, choose one to create an example. -/
def elements (xs : List α) (pos : 0 < xs.length) : Gen α := do
let ⟨⟨n, h₀, h₁⟩⟩ ← Uliftable.up <| chooseNat' 0 xs.length Pos
pure <| List.nthLe xs n h₁
#align slim_check.gen.elements SlimCheck.Gen.elements
+-/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/-- `freq_aux xs i _` takes a weighted list of generator and a number meant to select one of the
@@ -194,6 +199,7 @@ def freq (xs : List (ℕ+ × Gen α)) (pos : 0 < xs.length) : Gen α :=
#align slim_check.gen.freq SlimCheck.Gen.freq
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
+#print SlimCheck.Gen.permutationOf /-
/-- Generate a random permutation of a given list. -/
def permutationOf {α : Type u} : ∀ xs : List α, Gen (Subtype <| List.Perm xs)
| [] => pure ⟨[], List.Perm.nil⟩
@@ -204,6 +210,7 @@ def permutationOf {α : Type u} : ∀ xs : List α, Gen (Subtype <| List.Perm xs
⟨List.insertNth n x xs',
List.Perm.trans (List.Perm.cons _ h) (List.perm_insertNth _ _ h').symm⟩
#align slim_check.gen.permutation_of SlimCheck.Gen.permutationOf
+-/
end Gen
mathlib commit https://github.com/leanprover-community/mathlib/commit/cca40788df1b8755d5baf17ab2f27dacc2e17acb
@@ -49,7 +49,8 @@ It has a `nat` parameter so that the caller can decide on the
size of the examples. -/
@[reducible]
def Gen (α : Type u) :=
- ReaderT (ULift ℕ) Rand α deriving Monad, LawfulMonad
+ ReaderT (ULift ℕ) Rand α
+deriving Monad, LawfulMonad
#align slim_check.gen SlimCheck.Gen
-/
@@ -186,10 +187,10 @@ def freq (xs : List (ℕ+ × Gen α)) (pos : 0 < xs.length) : Gen α :=
have ha : 1 ≤ s :=
le_trans Pos <|
List.length_map (Subtype.val ∘ Prod.fst) xs ▸
- List.length_le_sum_of_one_le _ fun i => by simp; intros ; assumption
+ List.length_le_sum_of_one_le _ fun i => by simp; intros; assumption
have : 0 ≤ s - 1 := le_tsub_of_add_le_right ha
Uliftable.adaptUp Gen.{0} Gen.{u} (chooseNat 0 (s - 1) this) fun i =>
- freqAux xs i.1 (by rcases i with ⟨i, h₀, h₁⟩ <;> rwa [le_tsub_iff_right] at h₁ <;> exact ha)
+ freqAux xs i.1 (by rcases i with ⟨i, h₀, h₁⟩ <;> rwa [le_tsub_iff_right] at h₁ <;> exact ha)
#align slim_check.gen.freq SlimCheck.Gen.freq
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -77,10 +77,12 @@ def chooseAny [Random α] : Gen α :=
variable {α} [Preorder α]
+#print SlimCheck.Gen.choose /-
/-- Lift `random.random_r` to the `gen` monad. -/
def choose [BoundedRandom α] (x y : α) (p : x ≤ y) : Gen (x .. y) :=
⟨fun _ => Rand.randomR x y p⟩
#align slim_check.gen.choose SlimCheck.Gen.choose
+-/
end Rand
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -77,12 +77,6 @@ def chooseAny [Random α] : Gen α :=
variable {α} [Preorder α]
-/- warning: slim_check.gen.choose -> SlimCheck.Gen.choose is a dubious translation:
-lean 3 declaration is
- forall {α : Type.{u1}} [_inst_1 : Preorder.{u1} α] [_inst_2 : BoundedRandom.{u1} α _inst_1] (x : α) (y : α), (LE.le.{u1} α (Preorder.toHasLe.{u1} α _inst_1) x y) -> (SlimCheck.Gen.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} α) Type.{u1} (Set.hasCoeToSort.{u1} α) (Set.Icc.{u1} α _inst_1 x y)))
-but is expected to have type
- forall (α : Type.{u1}) [_inst_1 : Preorder.{u1} α] [_inst_2 : BoundedRandom.{u1} α _inst_1] (x : α) (y : α), (LE.le.{u1} α (Preorder.toLE.{u1} α _inst_1) x y) -> (SlimCheck.Gen.{u1} (Subtype.{succ u1} α (fun (a : α) => And (LE.le.{u1} α (Preorder.toLE.{u1} α _inst_1) x a) (LE.le.{u1} α (Preorder.toLE.{u1} α _inst_1) a y))))
-Case conversion may be inaccurate. Consider using '#align slim_check.gen.choose SlimCheck.Gen.chooseₓ'. -/
/-- Lift `random.random_r` to the `gen` monad. -/
def choose [BoundedRandom α] (x y : α) (p : x ≤ y) : Gen (x .. y) :=
⟨fun _ => Rand.randomR x y p⟩
@@ -137,12 +131,6 @@ def vectorOf : ∀ (n : ℕ) (cmd : Gen α), Gen (Vector α n)
| succ n, cmd => Vector.cons <$> cmd <*> vector_of n cmd
#align slim_check.gen.vector_of SlimCheck.Gen.vectorOf
-/- warning: slim_check.gen.list_of -> SlimCheck.Gen.listOf is a dubious translation:
-lean 3 declaration is
- forall {α : Type.{u}}, (SlimCheck.Gen.{u} α) -> (SlimCheck.Gen.{u} (List.{u} α))
-but is expected to have type
- forall {α : Type}, (SlimCheck.Gen.{0} α) -> (SlimCheck.Gen.{0} (List.{0} α))
-Case conversion may be inaccurate. Consider using '#align slim_check.gen.list_of SlimCheck.Gen.listOfₓ'. -/
/-- Create a list of examples using `cmd`. The size is controlled
by the size parameter of `gen`. -/
def listOf (cmd : Gen α) : Gen (List α) :=
@@ -155,24 +143,12 @@ def listOf (cmd : Gen α) : Gen (List α) :=
open ULift
-/- warning: slim_check.gen.one_of -> SlimCheck.Gen.oneOf is a dubious translation:
-lean 3 declaration is
- forall {α : Type.{u}} (xs : List.{u} (SlimCheck.Gen.{u} α)), (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (List.length.{u} (SlimCheck.Gen.{u} α) xs)) -> (SlimCheck.Gen.{u} α)
-but is expected to have type
- forall {α : Type} (xs : Array.{0} (SlimCheck.Gen.{0} α)), (autoParam.{0} (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Array.size.{0} (SlimCheck.Gen.{0} α) xs)) _auto._@.Mathlib.Testing.SlimCheck.Gen._hyg.572) -> (SlimCheck.Gen.{0} α)
-Case conversion may be inaccurate. Consider using '#align slim_check.gen.one_of SlimCheck.Gen.oneOfₓ'. -/
/-- Given a list of example generators, choose one to create an example. -/
def oneOf (xs : List (Gen α)) (pos : 0 < xs.length) : Gen α := do
let ⟨⟨n, h, h'⟩⟩ ← Uliftable.up <| chooseNat' 0 xs.length Pos
List.nthLe xs n h'
#align slim_check.gen.one_of SlimCheck.Gen.oneOf
-/- warning: slim_check.gen.elements -> SlimCheck.Gen.elements is a dubious translation:
-lean 3 declaration is
- forall {α : Type.{u}} (xs : List.{u} α), (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (List.length.{u} α xs)) -> (SlimCheck.Gen.{u} α)
-but is expected to have type
- forall {α : Type} (xs : List.{0} α), (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (List.length.{0} α xs)) -> (SlimCheck.Gen.{0} α)
-Case conversion may be inaccurate. Consider using '#align slim_check.gen.elements SlimCheck.Gen.elementsₓ'. -/
/-- Given a list of example generators, choose one to create an example. -/
def elements (xs : List α) (pos : 0 < xs.length) : Gen α := do
let ⟨⟨n, h₀, h₁⟩⟩ ← Uliftable.up <| chooseNat' 0 xs.length Pos
@@ -214,12 +190,6 @@ def freq (xs : List (ℕ+ × Gen α)) (pos : 0 < xs.length) : Gen α :=
freqAux xs i.1 (by rcases i with ⟨i, h₀, h₁⟩ <;> rwa [le_tsub_iff_right] at h₁ <;> exact ha)
#align slim_check.gen.freq SlimCheck.Gen.freq
-/- warning: slim_check.gen.permutation_of -> SlimCheck.Gen.permutationOf is a dubious translation:
-lean 3 declaration is
- forall {α : Type.{u}} (xs : List.{u} α), SlimCheck.Gen.{u} (Subtype.{succ u} (List.{u} α) (List.Perm.{u} α xs))
-but is expected to have type
- forall {α : Type} (xs : List.{0} α), SlimCheck.Gen.{0} (Subtype.{1} (List.{0} α) (fun (ys : List.{0} α) => List.Perm.{0} α ys xs))
-Case conversion may be inaccurate. Consider using '#align slim_check.gen.permutation_of SlimCheck.Gen.permutationOfₓ'. -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/-- Generate a random permutation of a given list. -/
def permutationOf {α : Type u} : ∀ xs : List α, Gen (Subtype <| List.Perm xs)
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -208,10 +208,7 @@ def freq (xs : List (ℕ+ × Gen α)) (pos : 0 < xs.length) : Gen α :=
have ha : 1 ≤ s :=
le_trans Pos <|
List.length_map (Subtype.val ∘ Prod.fst) xs ▸
- List.length_le_sum_of_one_le _ fun i => by
- simp
- intros
- assumption
+ List.length_le_sum_of_one_le _ fun i => by simp; intros ; assumption
have : 0 ≤ s - 1 := le_tsub_of_add_le_right ha
Uliftable.adaptUp Gen.{0} Gen.{u} (chooseNat 0 (s - 1) this) fun i =>
freqAux xs i.1 (by rcases i with ⟨i, h₀, h₁⟩ <;> rwa [le_tsub_iff_right] at h₁ <;> exact ha)
mathlib commit https://github.com/leanprover-community/mathlib/commit/0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8
@@ -77,12 +77,16 @@ def chooseAny [Random α] : Gen α :=
variable {α} [Preorder α]
-#print SlimCheck.Gen.choose /-
+/- warning: slim_check.gen.choose -> SlimCheck.Gen.choose is a dubious translation:
+lean 3 declaration is
+ forall {α : Type.{u1}} [_inst_1 : Preorder.{u1} α] [_inst_2 : BoundedRandom.{u1} α _inst_1] (x : α) (y : α), (LE.le.{u1} α (Preorder.toHasLe.{u1} α _inst_1) x y) -> (SlimCheck.Gen.{u1} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} α) Type.{u1} (Set.hasCoeToSort.{u1} α) (Set.Icc.{u1} α _inst_1 x y)))
+but is expected to have type
+ forall (α : Type.{u1}) [_inst_1 : Preorder.{u1} α] [_inst_2 : BoundedRandom.{u1} α _inst_1] (x : α) (y : α), (LE.le.{u1} α (Preorder.toLE.{u1} α _inst_1) x y) -> (SlimCheck.Gen.{u1} (Subtype.{succ u1} α (fun (a : α) => And (LE.le.{u1} α (Preorder.toLE.{u1} α _inst_1) x a) (LE.le.{u1} α (Preorder.toLE.{u1} α _inst_1) a y))))
+Case conversion may be inaccurate. Consider using '#align slim_check.gen.choose SlimCheck.Gen.chooseₓ'. -/
/-- Lift `random.random_r` to the `gen` monad. -/
def choose [BoundedRandom α] (x y : α) (p : x ≤ y) : Gen (x .. y) :=
⟨fun _ => Rand.randomR x y p⟩
#align slim_check.gen.choose SlimCheck.Gen.choose
--/
end Rand
mathlib commit https://github.com/leanprover-community/mathlib/commit/bd9851ca476957ea4549eb19b40e7b5ade9428cc
@@ -53,9 +53,9 @@ lemma chooseNatLt_aux {lo hi : Nat} (a : Nat) (h : Nat.succ lo ≤ a ∧ a ≤ h
lo ≤ Nat.pred a ∧ Nat.pred a < hi :=
And.intro (Nat.le_sub_one_of_lt (Nat.lt_of_succ_le h.left)) <|
show a.pred.succ ≤ hi by
- rw [Nat.succ_pred_eq_of_pos]
- exact h.right
- exact lt_of_le_of_lt (Nat.zero_le lo) h.left
+ rw [Nat.succ_pred_eq_of_pos]
+ · exact h.right
+ · exact lt_of_le_of_lt (Nat.zero_le lo) h.left
/-- Generate a `Nat` example between `x` and `y` (exclusively). -/
def chooseNatLt (lo hi : Nat) (h : lo < hi) : Gen {a // lo ≤ a ∧ a < hi} :=
λ
by fun
(#11301)
Per the style guidelines, λ
is disallowed in mathlib.
This is close to exhaustive; I left some tactic code alone when it seemed to me that tactic could be upstreamed soon.
Notes
=>
to ↦
.Mathlib/Order/SupClosed
.λ x,
, which I also replaced.@@ -42,12 +42,12 @@ namespace Gen
/-- Lift `Random.random` to the `Gen` monad. -/
def chooseAny (α : Type u) [Random Id α] : Gen α :=
- λ _ => rand α
+ fun _ ↦ rand α
/-- Lift `BoundedRandom.randomR` to the `Gen` monad. -/
def choose (α : Type u) [Preorder α] [BoundedRandom Id α] (lo hi : α) (h : lo ≤ hi) :
Gen {a // lo ≤ a ∧ a ≤ hi} :=
- λ _ => randBound α lo hi h
+ fun _ ↦ randBound α lo hi h
lemma chooseNatLt_aux {lo hi : Nat} (a : Nat) (h : Nat.succ lo ≤ a ∧ a ≤ hi) :
lo ≤ Nat.pred a ∧ Nat.pred a < hi :=
Nat
file (#9551)
Data.Nat.Basic
is currently made of two things:
I need the first ones earlier in the algebraic order hierarchy, hence the split.
@@ -4,10 +4,6 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving, Simon Hudon
-/
import Mathlib.Control.Random
-import Mathlib.Control.ULiftable
-import Mathlib.Data.List.Perm
-import Mathlib.Data.Subtype
-import Mathlib.Data.Nat.Basic
#align_import testing.slim_check.gen from "leanprover-community/mathlib"@"fdc286cc6967a012f41b87f76dcd2797b53152af"
$
with <|
(#9319)
See Zulip thread for the discussion.
@@ -97,7 +97,7 @@ def oneOf (xs : Array (Gen α)) (pos : 0 < xs.size := by decide) : Gen α := do
/-- Given a list of examples, choose one to create an example. -/
def elements (xs : List α) (pos : 0 < xs.length) : Gen α := do
let ⟨x, _, h2⟩ ← ULiftable.up <| chooseNatLt 0 xs.length pos
- pure $ xs.get ⟨x, h2⟩
+ pure <| xs.get ⟨x, h2⟩
open List in
/-- Generate a random permutation of a given list. -/
This follows the pattern that is already present in the haskell version
@@ -45,11 +45,11 @@ abbrev Gen (α : Type u) := ReaderT (ULift Nat) Rand α
namespace Gen
/-- Lift `Random.random` to the `Gen` monad. -/
-def chooseAny (α : Type u) [Random α] : Gen α :=
+def chooseAny (α : Type u) [Random Id α] : Gen α :=
λ _ => rand α
/-- Lift `BoundedRandom.randomR` to the `Gen` monad. -/
-def choose (α : Type u) [Preorder α] [BoundedRandom α] (lo hi : α) (h : lo ≤ hi) :
+def choose (α : Type u) [Preorder α] [BoundedRandom Id α] (lo hi : α) (h : lo ≤ hi) :
Gen {a // lo ≤ a ∧ a ≤ hi} :=
λ _ => randBound α lo hi h
@@ -118,7 +118,7 @@ end Gen
/-- Execute a `Gen` inside the `IO` monad using `size` as the example size-/
def Gen.run (x : Gen α) (size : Nat) : BaseIO α :=
- IO.runRand $ ReaderT.run x ⟨size⟩
-
+ letI : MonadLift Id BaseIO := ⟨fun f => pure <| Id.run f⟩
+ IO.runRand (ReaderT.run x ⟨size⟩:)
end SlimCheck
outParam
and adjust universe orders (#8849)
The most useful universe argument to up
and down
(the one in the ULift
type) is now first.
Combined with the outParam
, this makes using ULiftable.up
more ergonomic downstream, removing a handful of type annotations.
@@ -78,7 +78,7 @@ variable {α : Type u}
/-- Create an `Array` of examples using `x`. The size is controlled
by the size parameter of `Gen`. -/
def arrayOf (x : Gen α) : Gen (Array α) := do
- let ⟨sz⟩ ← (ULiftable.up <| do choose Nat 0 (← getSize) (Nat.zero_le _) : Gen (ULift ℕ))
+ let (⟨sz⟩ : ULift ℕ) ← ULiftable.up do choose Nat 0 (← getSize) (Nat.zero_le _)
let mut res := #[]
for _ in [0:sz] do
res := res.push (← x)
@@ -110,8 +110,8 @@ def permutationOf : (xs : List α) → Gen { ys // xs ~ ys }
/-- Given two generators produces a tuple consisting out of the result of both -/
def prodOf {α : Type u} {β : Type v} (x : Gen α) (y : Gen β) : Gen (α × β) := do
- let ⟨a⟩ ← (ULiftable.up x : Gen (ULift.{max u v} α))
- let ⟨b⟩ ← (ULiftable.up y : Gen (ULift.{max u v} β))
+ let ⟨a⟩ ← ULiftable.up.{max u v} x
+ let ⟨b⟩ ← ULiftable.up.{max u v} y
pure (a, b)
end Gen
@@ -78,7 +78,7 @@ variable {α : Type u}
/-- Create an `Array` of examples using `x`. The size is controlled
by the size parameter of `Gen`. -/
def arrayOf (x : Gen α) : Gen (Array α) := do
- let ⟨sz⟩ ← (ULiftable.up <| do choose Nat 0 (←getSize) (Nat.zero_le _) : Gen (ULift ℕ))
+ let ⟨sz⟩ ← (ULiftable.up <| do choose Nat 0 (← getSize) (Nat.zero_le _) : Gen (ULift ℕ))
let mut res := #[]
for _ in [0:sz] do
res := res.push (← x)
@@ -55,7 +55,7 @@ def choose (α : Type u) [Preorder α] [BoundedRandom α] (lo hi : α) (h : lo
lemma chooseNatLt_aux {lo hi : Nat} (a : Nat) (h : Nat.succ lo ≤ a ∧ a ≤ hi) :
lo ≤ Nat.pred a ∧ Nat.pred a < hi :=
- And.intro (Nat.le_pred_of_lt (Nat.lt_of_succ_le h.left)) <|
+ And.intro (Nat.le_sub_one_of_lt (Nat.lt_of_succ_le h.left)) <|
show a.pred.succ ≤ hi by
rw [Nat.succ_pred_eq_of_pos]
exact h.right
Autoimplicits are highly controversial and also defeat the performance-improving work in #6474.
The intent of this PR is to make autoImplicit
opt-in on a per-file basis, by disabling it in the lakefile and enabling it again with set_option autoImplicit true
in the few files that rely on it.
That also keeps this PR small, as opposed to attempting to "fix" files to not need it any more.
I claim that many of the uses of autoImplicit
in these files are accidental; situations such as:
variables
are in scope, but pasting the lemma in the wrong sectionHaving set_option autoImplicit false
as the default prevents these types of mistake being made in the 90% of files where autoImplicit
s are not used at all, and causes them to be caught by CI during review.
I think there were various points during the port where we encouraged porters to delete the universes u v
lines; I think having autoparams for universe variables only would cover a lot of the cases we actually use them, while avoiding any real shortcomings.
A Zulip poll (after combining overlapping votes accordingly) was in favor of this change with 5:5:18
as the no:dontcare:yes
vote ratio.
While this PR was being reviewed, a handful of files gained some more likely-accidental autoImplicits. In these places, set_option autoImplicit true
has been placed locally within a section, rather than at the top of the file.
@@ -31,6 +31,8 @@ random testing
* https://hackage.haskell.org/package/QuickCheck
-/
+set_option autoImplicit true
+
namespace SlimCheck
open Random
@@ -2,11 +2,6 @@
Copyright (c) 2021 Henrik Böving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving, Simon Hudon
-
-! This file was ported from Lean 3 source module testing.slim_check.gen
-! leanprover-community/mathlib commit fdc286cc6967a012f41b87f76dcd2797b53152af
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathlib.Control.Random
import Mathlib.Control.ULiftable
@@ -14,6 +9,8 @@ import Mathlib.Data.List.Perm
import Mathlib.Data.Subtype
import Mathlib.Data.Nat.Basic
+#align_import testing.slim_check.gen from "leanprover-community/mathlib"@"fdc286cc6967a012f41b87f76dcd2797b53152af"
+
/-!
# `Gen` Monad
The use of auto-implicits was introducing a universe metavariable where we wanted a free variable.
The new ULiftable
instances handle the common case of a universe polymorphic monad with a universe-lifted state from Type
.
@@ -9,6 +9,7 @@ Authors: Henrik Böving, Simon Hudon
! if you have ported upstream changes.
-/
import Mathlib.Control.Random
+import Mathlib.Control.ULiftable
import Mathlib.Data.List.Perm
import Mathlib.Data.Subtype
import Mathlib.Data.Nat.Basic
@@ -73,10 +74,12 @@ def getSize : Gen Nat :=
def resize (f : Nat → Nat) (x : Gen α) : Gen α :=
withReader (ULift.up ∘ f ∘ ULift.down) x
+variable {α : Type u}
+
/-- Create an `Array` of examples using `x`. The size is controlled
by the size parameter of `Gen`. -/
def arrayOf (x : Gen α) : Gen (Array α) := do
- let sz ← choose Nat 0 (←getSize) (Nat.zero_le _)
+ let ⟨sz⟩ ← (ULiftable.up <| do choose Nat 0 (←getSize) (Nat.zero_le _) : Gen (ULift ℕ))
let mut res := #[]
for _ in [0:sz] do
res := res.push (← x)
@@ -89,26 +92,28 @@ def listOf (x : Gen α) : Gen (List α) :=
/-- Given a list of example generators, choose one to create an example. -/
def oneOf (xs : Array (Gen α)) (pos : 0 < xs.size := by decide) : Gen α := do
- let ⟨x, _, h2⟩ ← chooseNatLt 0 xs.size pos
+ let ⟨x, _, h2⟩ ← ULiftable.up <| chooseNatLt 0 xs.size pos
xs.get ⟨x, h2⟩
/-- Given a list of examples, choose one to create an example. -/
def elements (xs : List α) (pos : 0 < xs.length) : Gen α := do
- let ⟨x, _, h2⟩ ← chooseNatLt 0 xs.length pos
+ let ⟨x, _, h2⟩ ← ULiftable.up <| chooseNatLt 0 xs.length pos
pure $ xs.get ⟨x, h2⟩
open List in
/-- Generate a random permutation of a given list. -/
-def permutationOf : (xs : List α) → Gen { ys // ys ~ xs }
+def permutationOf : (xs : List α) → Gen { ys // xs ~ ys }
| [] => pure ⟨[], Perm.nil⟩
| x::xs => do
let ⟨ys, h1⟩ ← permutationOf xs
- let ⟨n, _, h3⟩ ← choose Nat 0 ys.length (Nat.zero_le _)
- pure ⟨insertNth n x ys, Perm.trans (perm_insertNth _ _ h3) (Perm.cons _ h1)⟩
+ let ⟨n, _, h3⟩ ← ULiftable.up <| choose Nat 0 ys.length (Nat.zero_le _)
+ pure ⟨insertNth n x ys, Perm.trans (Perm.cons _ h1) (perm_insertNth _ _ h3).symm⟩
/-- Given two generators produces a tuple consisting out of the result of both -/
-def prodOf {α β : Type u} (x : Gen α) (y : Gen β) : Gen (α × β) := do
- pure (←x, ←y)
+def prodOf {α : Type u} {β : Type v} (x : Gen α) (y : Gen β) : Gen (α × β) := do
+ let ⟨a⟩ ← (ULiftable.up x : Gen (ULift.{max u v} α))
+ let ⟨b⟩ ← (ULiftable.up y : Gen (ULift.{max u v} β))
+ pure (a, b)
end Gen
@@ -3,7 +3,7 @@ Copyright (c) 2021 Henrik Böving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving, Simon Hudon
-! This file was ported from Lean 3 source module testing.slim_check.testable
+! This file was ported from Lean 3 source module testing.slim_check.gen
! leanprover-community/mathlib commit fdc286cc6967a012f41b87f76dcd2797b53152af
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
The unported dependencies are