testing.slim_check.sampleableMathlib.Testing.SlimCheck.Sampleable

This file has been ported!

Changes since the initial port

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.

Changes in mathlib3

(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)

Changes in mathlib3port

mathlib3
mathlib3port
Diff
@@ -5,9 +5,9 @@ Authors: Simon Hudon
 -/
 import Data.LazyList.Basic
 import Data.Tree
-import Data.Pnat.Basic
+import Data.PNat.Basic
 import Control.Bifunctor
-import Control.Ulift
+import Control.ULift
 import Testing.SlimCheck.Gen
 import Mathbin.Tactic.Linarith.Default
 
@@ -194,7 +194,7 @@ section Prio
 
 open SampleableExt
 
-/- ./././Mathport/Syntax/Translate/Basic.lean:339:40: warning: unsupported option default_priority -/
+/- ./././Mathport/Syntax/Translate/Basic.lean:340:40: warning: unsupported option default_priority -/
 set_option default_priority 50
 
 instance SampleableExt.ofSampleable {α} [Sampleable α] [Repr α] : SampleableExt α
@@ -218,7 +218,7 @@ instance Sampleable.bifunctor {α β} {F} [Bifunctor F] [SampleableBifunctor F]
   shrink := SampleableBifunctor.shrink α β Sampleable.shrink Sampleable.shrink
 #align slim_check.sampleable.bifunctor SlimCheck.Sampleable.bifunctor
 
-/- ./././Mathport/Syntax/Translate/Basic.lean:339:40: warning: unsupported option default_priority -/
+/- ./././Mathport/Syntax/Translate/Basic.lean:340:40: warning: unsupported option default_priority -/
 set_option default_priority 100
 
 instance SampleableExt.functor {α} {F} [Functor F] [SampleableFunctor F] [SampleableExt α] :
@@ -430,7 +430,7 @@ instance Rat.sampleable : Sampleable ℚ :=
     intro i
     rcases i with ⟨x, ⟨y, hy⟩⟩ <;> unfold_wf <;> dsimp [Rat.mkPnat]
     mono*
-    · rw [← Int.ofNat_le, Int.coe_natAbs, Int.coe_natAbs]
+    · rw [← Int.ofNat_le, Int.natCast_natAbs, Int.natCast_natAbs]
       apply Int.abs_ediv_le_abs
     · change _ - 1 ≤ y - 1
       apply tsub_le_tsub_right
@@ -866,7 +866,7 @@ instance IntGe.sampleable {x : ℤ} : SlimCheck.Sampleable { y : ℤ // x ≤ y
 
 instance IntLt.sampleable {y} : SlimCheck.Sampleable { x : ℤ // x < y } :=
   Sampleable.lift ℕ
-    (fun n => ⟨y - (n + 1), Int.sub_left_lt_of_lt_add <| by linarith [Int.coe_nat_nonneg n]⟩)
+    (fun n => ⟨y - (n + 1), Int.sub_left_lt_of_lt_add <| by linarith [Int.natCast_nonneg n]⟩)
     (fun ⟨i, h⟩ => (y - i - 1).natAbs) fun n => by
     unfold_wf <;> simp [int_lt.sampleable._match_1] <;> ring
 #align slim_check.int_lt.sampleable SlimCheck.IntLt.sampleable
Diff
@@ -533,9 +533,9 @@ def List.shrinkRemoves (k : ℕ) (hk : 0 < k) :
         match (motive := ∀ ys, ys = List.splitAt k xs → _) List.splitAt k xs, rfl with
         | ⟨xs₁, xs₂⟩, h =>
           have h₄ : xs₁ = xs.take k := by
-            simp only [List.splitAt_eq_take_drop, Prod.mk.inj_iff] at h  <;> tauto
+            simp only [List.splitAt_eq_take_drop, Prod.mk.inj_iff] at h <;> tauto
           have h₃ : xs₂ = xs.drop k := by
-            simp only [List.splitAt_eq_take_drop, Prod.mk.inj_iff] at h  <;> tauto
+            simp only [List.splitAt_eq_take_drop, Prod.mk.inj_iff] at h <;> tauto
           have : SizeOf.sizeOf xs₂ < SizeOf.sizeOf xs := by
             rw [h₃] <;> solve_by_elim [list.sizeof_drop_lt_sizeof_of_lt_length]
           have h₁ : n - k = xs₂.length := by simp only [h₃, ← hn, List.length_drop]
Diff
@@ -119,7 +119,7 @@ def ShrinkFn (α : Type _) [SizeOf α] :=
   ∀ x : α, LazyList { y : α // SizeofLt y x }
 #align slim_check.shrink_fn SlimCheck.ShrinkFn
 
-/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:400:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable α` provides ways of creating examples of type `α`,
 and given such an example `x : α`, gives us a way to shrink it
 and find simpler examples.  -/
@@ -134,7 +134,7 @@ attribute [instance 100] hasWellFoundedOfHasSizeof defaultHasSizeof
 
 attribute [instance 200] sampleable.wf
 
-/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:400:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_functor F` makes it possible to create samples of and
 shrink `F α` given a sampling function and a shrinking function for
 arbitrary `α` -/
@@ -145,7 +145,7 @@ class SampleableFunctor (F : Type u → Type v) [Functor F] where
   pRepr : ∀ α, Repr α → Repr (F α)
 #align slim_check.sampleable_functor SlimCheck.SampleableFunctor
 
-/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:400:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_bifunctor F` makes it possible to create samples of
 and shrink `F α β` given a sampling function and a shrinking function
 for arbitrary `α` and `β` -/
@@ -165,8 +165,8 @@ unsafe def sampleable.mk_trivial_interp : tactic Unit :=
 #align slim_check.sampleable.mk_trivial_interp slim_check.sampleable.mk_trivial_interp
 
 #print SlimCheck.SampleableExt /-
-/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
-/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:400:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:400:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_ext` generalizes the behavior of `sampleable`
 and makes it possible to express instances for types that
 do not lend themselves to introspection, such as `ℕ → ℕ`.
Diff
@@ -119,7 +119,7 @@ def ShrinkFn (α : Type _) [SizeOf α] :=
   ∀ x : α, LazyList { y : α // SizeofLt y x }
 #align slim_check.shrink_fn SlimCheck.ShrinkFn
 
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable α` provides ways of creating examples of type `α`,
 and given such an example `x : α`, gives us a way to shrink it
 and find simpler examples.  -/
@@ -134,7 +134,7 @@ attribute [instance 100] hasWellFoundedOfHasSizeof defaultHasSizeof
 
 attribute [instance 200] sampleable.wf
 
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_functor F` makes it possible to create samples of and
 shrink `F α` given a sampling function and a shrinking function for
 arbitrary `α` -/
@@ -145,7 +145,7 @@ class SampleableFunctor (F : Type u → Type v) [Functor F] where
   pRepr : ∀ α, Repr α → Repr (F α)
 #align slim_check.sampleable_functor SlimCheck.SampleableFunctor
 
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_bifunctor F` makes it possible to create samples of
 and shrink `F α β` given a sampling function and a shrinking function
 for arbitrary `α` and `β` -/
@@ -165,8 +165,8 @@ unsafe def sampleable.mk_trivial_interp : tactic Unit :=
 #align slim_check.sampleable.mk_trivial_interp slim_check.sampleable.mk_trivial_interp
 
 #print SlimCheck.SampleableExt /-
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:404:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_ext` generalizes the behavior of `sampleable`
 and makes it possible to express instances for types that
 do not lend themselves to introspection, such as `ℕ → ℕ`.
Diff
@@ -3,12 +3,12 @@ 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.Data.LazyList.Basic
-import Mathbin.Data.Tree
-import Mathbin.Data.Pnat.Basic
-import Mathbin.Control.Bifunctor
-import Mathbin.Control.Ulift
-import Mathbin.Testing.SlimCheck.Gen
+import Data.LazyList.Basic
+import Data.Tree
+import Data.Pnat.Basic
+import Control.Bifunctor
+import Control.Ulift
+import Testing.SlimCheck.Gen
 import Mathbin.Tactic.Linarith.Default
 
 #align_import testing.slim_check.sampleable from "leanprover-community/mathlib"@"9240e8be927a0955b9a82c6c85ef499ee3a626b8"
@@ -119,7 +119,7 @@ def ShrinkFn (α : Type _) [SizeOf α] :=
   ∀ x : α, LazyList { y : α // SizeofLt y x }
 #align slim_check.shrink_fn SlimCheck.ShrinkFn
 
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable α` provides ways of creating examples of type `α`,
 and given such an example `x : α`, gives us a way to shrink it
 and find simpler examples.  -/
@@ -134,7 +134,7 @@ attribute [instance 100] hasWellFoundedOfHasSizeof defaultHasSizeof
 
 attribute [instance 200] sampleable.wf
 
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_functor F` makes it possible to create samples of and
 shrink `F α` given a sampling function and a shrinking function for
 arbitrary `α` -/
@@ -145,7 +145,7 @@ class SampleableFunctor (F : Type u → Type v) [Functor F] where
   pRepr : ∀ α, Repr α → Repr (F α)
 #align slim_check.sampleable_functor SlimCheck.SampleableFunctor
 
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_bifunctor F` makes it possible to create samples of
 and shrink `F α β` given a sampling function and a shrinking function
 for arbitrary `α` and `β` -/
@@ -165,8 +165,8 @@ unsafe def sampleable.mk_trivial_interp : tactic Unit :=
 #align slim_check.sampleable.mk_trivial_interp slim_check.sampleable.mk_trivial_interp
 
 #print SlimCheck.SampleableExt /-
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_ext` generalizes the behavior of `sampleable`
 and makes it possible to express instances for types that
 do not lend themselves to introspection, such as `ℕ → ℕ`.
@@ -194,7 +194,7 @@ section Prio
 
 open SampleableExt
 
-/- ./././Mathport/Syntax/Translate/Basic.lean:334:40: warning: unsupported option default_priority -/
+/- ./././Mathport/Syntax/Translate/Basic.lean:339:40: warning: unsupported option default_priority -/
 set_option default_priority 50
 
 instance SampleableExt.ofSampleable {α} [Sampleable α] [Repr α] : SampleableExt α
@@ -218,7 +218,7 @@ instance Sampleable.bifunctor {α β} {F} [Bifunctor F] [SampleableBifunctor F]
   shrink := SampleableBifunctor.shrink α β Sampleable.shrink Sampleable.shrink
 #align slim_check.sampleable.bifunctor SlimCheck.Sampleable.bifunctor
 
-/- ./././Mathport/Syntax/Translate/Basic.lean:334:40: warning: unsupported option default_priority -/
+/- ./././Mathport/Syntax/Translate/Basic.lean:339:40: warning: unsupported option default_priority -/
 set_option default_priority 100
 
 instance SampleableExt.functor {α} {F} [Functor F] [SampleableFunctor F] [SampleableExt α] :
Diff
@@ -2,11 +2,6 @@
 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.sampleable
-! 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.Data.LazyList.Basic
 import Mathbin.Data.Tree
@@ -16,6 +11,8 @@ import Mathbin.Control.Ulift
 import Mathbin.Testing.SlimCheck.Gen
 import Mathbin.Tactic.Linarith.Default
 
+#align_import testing.slim_check.sampleable from "leanprover-community/mathlib"@"9240e8be927a0955b9a82c6c85ef499ee3a626b8"
+
 /-!
 # `sampleable` Class
 
Diff
@@ -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.sampleable
-! leanprover-community/mathlib commit e1bccd6e40ae78370f01659715d3c948716e3b7e
+! leanprover-community/mathlib commit 9240e8be927a0955b9a82c6c85ef499ee3a626b8
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -19,6 +19,9 @@ import Mathbin.Tactic.Linarith.Default
 /-!
 # `sampleable` Class
 
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
 This class permits the creation samples of a given type
 controlling the size of those values using the `gen` monad`. It also
 helps minimize examples by creating smaller versions of given values.
Diff
@@ -391,8 +391,8 @@ instance Prod.sampleable : SampleableBifunctor.{u, v} Prod
     where
   wf := _
   sample α β sama samb := do
-    let ⟨x⟩ ← (Uliftable.up <| sama : Gen (ULift.{max u v} α))
-    let ⟨y⟩ ← (Uliftable.up <| samb : Gen (ULift.{max u v} β))
+    let ⟨x⟩ ← (ULiftable.up <| sama : Gen (ULift.{max u v} α))
+    let ⟨y⟩ ← (ULiftable.up <| samb : Gen (ULift.{max u v} β))
     pure (x, y)
   shrink := @Prod.shrink
   pRepr := @Prod.hasRepr
@@ -417,8 +417,8 @@ instance Sum.sampleable : SampleableBifunctor.{u, v} Sum
     where
   wf := _
   sample (α : Type u) (β : Type v) sam_α sam_β :=
-    @Uliftable.upMap Gen.{u} Gen.{max u v} _ _ _ _ (@Sum.inl α β) sam_α <|>
-      @Uliftable.upMap Gen.{v} Gen.{max v u} _ _ _ _ (@Sum.inr α β) sam_β
+    @ULiftable.upMap Gen.{u} Gen.{max u v} _ _ _ _ (@Sum.inl α β) sam_α <|>
+      @ULiftable.upMap Gen.{v} Gen.{max v u} _ _ _ _ (@Sum.inr α β) sam_β
   shrink α β Iα Iβ shr_α shr_β := @Sum.shrink _ _ Iα Iβ shr_α shr_β
   pRepr := @Sum.hasRepr
 #align slim_check.sum.sampleable SlimCheck.Sum.sampleable
@@ -772,7 +772,7 @@ instance Large.sampleableFunctor : SampleableFunctor Large
 instance Ulift.sampleableFunctor : SampleableFunctor ULift.{u, v}
     where
   wf α h := ⟨fun ⟨x⟩ => @SizeOf.sizeOf α h x⟩
-  sample α samp := Uliftable.upMap ULift.up <| samp
+  sample α samp := ULiftable.upMap ULift.up <| samp
   shrink := fun α _ shr ⟨x⟩ => (shr x).map (Subtype.map ULift.up fun a h => h)
   pRepr α h := ⟨@repr α h ∘ ULift.down⟩
 #align slim_check.ulift.sampleable_functor SlimCheck.Ulift.sampleableFunctor
@@ -900,7 +900,7 @@ open Tactic
 def printSamples {t : Type u} [Repr t] (g : Gen t) : Io Unit := do
   let xs ←
     Io.runRand <|
-        Uliftable.down do
+        ULiftable.down do
           let xs ← (List.range 10).mapM <| g.run ∘ ULift.up
           pure ⟨xs repr⟩
   xs Io.putStrLn
Diff
@@ -105,7 +105,6 @@ namespace SlimCheck
 
 variable (α : Type u)
 
--- mathport name: «expr ≺ »
 local infixl:50 " ≺ " => WellFoundedRelation.R
 
 /-- `sizeof_lt x y` compares the sizes of `x` and `y`. -/
@@ -120,7 +119,7 @@ def ShrinkFn (α : Type _) [SizeOf α] :=
   ∀ x : α, LazyList { y : α // SizeofLt y x }
 #align slim_check.shrink_fn SlimCheck.ShrinkFn
 
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable α` provides ways of creating examples of type `α`,
 and given such an example `x : α`, gives us a way to shrink it
 and find simpler examples.  -/
@@ -135,7 +134,7 @@ attribute [instance 100] hasWellFoundedOfHasSizeof defaultHasSizeof
 
 attribute [instance 200] sampleable.wf
 
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_functor F` makes it possible to create samples of and
 shrink `F α` given a sampling function and a shrinking function for
 arbitrary `α` -/
@@ -146,7 +145,7 @@ class SampleableFunctor (F : Type u → Type v) [Functor F] where
   pRepr : ∀ α, Repr α → Repr (F α)
 #align slim_check.sampleable_functor SlimCheck.SampleableFunctor
 
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_bifunctor F` makes it possible to create samples of
 and shrink `F α β` given a sampling function and a shrinking function
 for arbitrary `α` and `β` -/
@@ -165,8 +164,9 @@ unsafe def sampleable.mk_trivial_interp : tactic Unit :=
   tactic.refine ``(id)
 #align slim_check.sampleable.mk_trivial_interp slim_check.sampleable.mk_trivial_interp
 
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
-/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+#print SlimCheck.SampleableExt /-
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_ext` generalizes the behavior of `sampleable`
 and makes it possible to express instances for types that
 do not lend themselves to introspection, such as `ℕ → ℕ`.
@@ -184,6 +184,7 @@ class SampleableExt (α : Sort u) where
   sample : Gen proxy_repr
   shrink : ShrinkFn proxy_repr
 #align slim_check.sampleable_ext SlimCheck.SampleableExt
+-/
 
 attribute [instance 100] sampleable_ext.p_repr sampleable_ext.wf
 
@@ -267,6 +268,7 @@ def Nat.shrink' (k : ℕ) :
 
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
+#print SlimCheck.Nat.shrink /-
 /-- `nat.shrink n` creates a list of smaller natural numbers by
 successively dividing by 2 and subtracting the difference from
 `n`. For example, `nat.shrink 100 = [50, 75, 88, 94, 97, 99]`. -/
@@ -279,6 +281,7 @@ def Nat.shrink (n : ℕ) : List { m : ℕ // WellFoundedRelation.R m n } :=
     ⟨n / 11, this _ (by norm_num)⟩::⟨n / 3, this _ (by norm_num)⟩::Nat.shrink' n n le_rfl []
   else []
 #align slim_check.nat.shrink SlimCheck.Nat.shrink
+-/
 
 open Gen
 
@@ -454,9 +457,11 @@ def sampleableChar (length : Nat) (characters : String) : Sampleable Char
   shrink _ := LazyList.nil
 #align slim_check.sampleable_char SlimCheck.sampleableChar
 
+#print SlimCheck.Char.sampleable /-
 instance Char.sampleable : Sampleable Char :=
   sampleableChar 3 " 0123abcABC:,;`\\/"
 #align slim_check.char.sampleable SlimCheck.Char.sampleable
+-/
 
 variable {α}
 
@@ -889,6 +894,7 @@ instance Perm'.slimCheck {xs : List α} : SlimCheck.Sampleable { ys : List α //
 /- ./././Mathport/Syntax/Translate/Tactic/Mathlib/Core.lean:38:34: unsupported: setup_tactic_parser -/
 open Tactic
 
+#print SlimCheck.printSamples /-
 /-- Print (at most) 10 samples of a given type to stdout for debugging.
 -/
 def printSamples {t : Type u} [Repr t] (g : Gen t) : Io Unit := do
@@ -899,6 +905,7 @@ def printSamples {t : Type u} [Repr t] (g : Gen t) : Io Unit := do
           pure ⟨xs repr⟩
   xs Io.putStrLn
 #align slim_check.print_samples SlimCheck.printSamples
+-/
 
 /-- Create a `gen α` expression from the argument of `#sample` -/
 unsafe def mk_generator (e : expr) : tactic (expr × expr) := do
Diff
@@ -120,7 +120,7 @@ def ShrinkFn (α : Type _) [SizeOf α] :=
   ∀ x : α, LazyList { y : α // SizeofLt y x }
 #align slim_check.shrink_fn SlimCheck.ShrinkFn
 
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable α` provides ways of creating examples of type `α`,
 and given such an example `x : α`, gives us a way to shrink it
 and find simpler examples.  -/
@@ -135,7 +135,7 @@ attribute [instance 100] hasWellFoundedOfHasSizeof defaultHasSizeof
 
 attribute [instance 200] sampleable.wf
 
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_functor F` makes it possible to create samples of and
 shrink `F α` given a sampling function and a shrinking function for
 arbitrary `α` -/
@@ -146,7 +146,7 @@ class SampleableFunctor (F : Type u → Type v) [Functor F] where
   pRepr : ∀ α, Repr α → Repr (F α)
 #align slim_check.sampleable_functor SlimCheck.SampleableFunctor
 
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_bifunctor F` makes it possible to create samples of
 and shrink `F α β` given a sampling function and a shrinking function
 for arbitrary `α` and `β` -/
@@ -165,8 +165,8 @@ unsafe def sampleable.mk_trivial_interp : tactic Unit :=
   tactic.refine ``(id)
 #align slim_check.sampleable.mk_trivial_interp slim_check.sampleable.mk_trivial_interp
 
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
-/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:394:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_ext` generalizes the behavior of `sampleable`
 and makes it possible to express instances for types that
 do not lend themselves to introspection, such as `ℕ → ℕ`.
Diff
@@ -395,7 +395,7 @@ instance Prod.sampleable : SampleableBifunctor.{u, v} Prod
   pRepr := @Prod.hasRepr
 #align slim_check.prod.sampleable SlimCheck.Prod.sampleable
 
-instance Sigma.sampleable {α β} [Sampleable α] [Sampleable β] : Sampleable (Σ_ : α, β) :=
+instance Sigma.sampleable {α β} [Sampleable α] [Sampleable β] : Sampleable (Σ _ : α, β) :=
   Sampleable.lift (α × β) (fun ⟨x, y⟩ => ⟨x, y⟩) (fun ⟨x, y⟩ => ⟨x, y⟩) fun ⟨x, y⟩ => le_rfl
 #align slim_check.sigma.sampleable SlimCheck.Sigma.sampleable
 
@@ -528,9 +528,9 @@ def List.shrinkRemoves (k : ℕ) (hk : 0 < k) :
         match (motive := ∀ ys, ys = List.splitAt k xs → _) List.splitAt k xs, rfl with
         | ⟨xs₁, xs₂⟩, h =>
           have h₄ : xs₁ = xs.take k := by
-            simp only [List.splitAt_eq_take_drop, Prod.mk.inj_iff] at h <;> tauto
+            simp only [List.splitAt_eq_take_drop, Prod.mk.inj_iff] at h  <;> tauto
           have h₃ : xs₂ = xs.drop k := by
-            simp only [List.splitAt_eq_take_drop, Prod.mk.inj_iff] at h <;> tauto
+            simp only [List.splitAt_eq_take_drop, Prod.mk.inj_iff] at h  <;> tauto
           have : SizeOf.sizeOf xs₂ < SizeOf.sizeOf xs := by
             rw [h₃] <;> solve_by_elim [list.sizeof_drop_lt_sizeof_of_lt_length]
           have h₁ : n - k = xs₂.length := by simp only [h₃, ← hn, List.length_drop]
@@ -678,7 +678,7 @@ theorem recShrinkWith_eq [SizeOf α]
           shrink_a x fun t' => recShrink _ (fun x h' => recShrinkWith shrink_a x) _) :=
   by
   conv_lhs => rw [rec_shrink_with, WellFounded.fix_eq]
-  congr ; ext ⟨y, h⟩; rfl
+  congr; ext ⟨y, h⟩; rfl
 #align slim_check.rec_shrink_with_eq SlimCheck.recShrinkWith_eq
 
 /-- `tree.shrink_with shrink_f t` shrinks `xs` by using the empty tree,
@@ -837,7 +837,7 @@ instance Ge.sampleable {x : α} [Sampleable α] [LinearOrderedAddCommGroup α] :
     where
   sample := do
     let y ← sample α
-    pure ⟨x + |y|, by norm_num [abs_nonneg] ⟩
+    pure ⟨x + |y|, by norm_num [abs_nonneg]⟩
   shrink _ := LazyList.nil
 #align slim_check.ge.sampleable SlimCheck.Ge.sampleable
 
Diff
@@ -421,11 +421,11 @@ instance Sum.sampleable : SampleableBifunctor.{u, v} Sum
 #align slim_check.sum.sampleable SlimCheck.Sum.sampleable
 
 instance Rat.sampleable : Sampleable ℚ :=
-  (Sampleable.lift (ℤ × ℕ+) (fun x => Prod.casesOn x [anonymous]) fun r =>
+  (Sampleable.lift (ℤ × ℕ+) (fun x => Prod.casesOn x Rat.mkPnat) fun r =>
       (r.Num, ⟨r.den, r.Pos⟩)) <|
     by
     intro i
-    rcases i with ⟨x, ⟨y, hy⟩⟩ <;> unfold_wf <;> dsimp [[anonymous]]
+    rcases i with ⟨x, ⟨y, hy⟩⟩ <;> unfold_wf <;> dsimp [Rat.mkPnat]
     mono*
     · rw [← Int.ofNat_le, Int.coe_natAbs, Int.coe_natAbs]
       apply Int.abs_ediv_le_abs
Diff
@@ -165,12 +165,6 @@ unsafe def sampleable.mk_trivial_interp : tactic Unit :=
   tactic.refine ``(id)
 #align slim_check.sampleable.mk_trivial_interp slim_check.sampleable.mk_trivial_interp
 
-/- warning: slim_check.sampleable_ext -> SlimCheck.SampleableExt is a dubious translation:
-lean 3 declaration is
-  Sort.{u1} -> Sort.{max (imax (succ u2) u1) (succ (succ u2))}
-but is expected to have type
-  Sort.{u1} -> Sort.{max u1 (succ (succ u2))}
-Case conversion may be inaccurate. Consider using '#align slim_check.sampleable_ext SlimCheck.SampleableExtₓ'. -/
 /- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
 /- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_ext` generalizes the behavior of `sampleable`
@@ -271,12 +265,6 @@ def Nat.shrink' (k : ℕ) :
       nat.shrink' m h₀ (⟨k - m, h₁⟩::ls)
 #align slim_check.nat.shrink' SlimCheck.Nat.shrink'
 
-/- warning: slim_check.nat.shrink -> SlimCheck.Nat.shrink is a dubious translation:
-lean 3 declaration is
-  forall (n : Nat), List.{0} (Subtype.{1} Nat (fun (m : Nat) => WellFoundedRelation.R.{1} Nat (hasWellFoundedOfHasSizeof.{1} Nat Nat.hasSizeof) m n))
-but is expected to have type
-  Nat -> (List.{0} Nat)
-Case conversion may be inaccurate. Consider using '#align slim_check.nat.shrink SlimCheck.Nat.shrinkₓ'. -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /-- `nat.shrink n` creates a list of smaller natural numbers by
@@ -466,12 +454,6 @@ def sampleableChar (length : Nat) (characters : String) : Sampleable Char
   shrink _ := LazyList.nil
 #align slim_check.sampleable_char SlimCheck.sampleableChar
 
-/- warning: slim_check.char.sampleable -> SlimCheck.Char.sampleable is a dubious translation:
-lean 3 declaration is
-  SlimCheck.Sampleable.{0} Char
-but is expected to have type
-  Nat -> (forall (chars : List.{0} Char), (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (List.length.{0} Char chars)) -> (SlimCheck.SampleableExt.{1, 0} Char))
-Case conversion may be inaccurate. Consider using '#align slim_check.char.sampleable SlimCheck.Char.sampleableₓ'. -/
 instance Char.sampleable : Sampleable Char :=
   sampleableChar 3 " 0123abcABC:,;`\\/"
 #align slim_check.char.sampleable SlimCheck.Char.sampleable
@@ -907,12 +889,6 @@ instance Perm'.slimCheck {xs : List α} : SlimCheck.Sampleable { ys : List α //
 /- ./././Mathport/Syntax/Translate/Tactic/Mathlib/Core.lean:38:34: unsupported: setup_tactic_parser -/
 open Tactic
 
-/- warning: slim_check.print_samples -> SlimCheck.printSamples is a dubious translation:
-lean 3 declaration is
-  forall {t : Type.{u}} [_inst_1 : Repr.{u} t], (SlimCheck.Gen.{u} t) -> (Io Unit)
-but is expected to have type
-  forall {t : Type} [_inst_1 : Repr.{0} t], (SlimCheck.Gen.{0} t) -> (IO PUnit.{1})
-Case conversion may be inaccurate. Consider using '#align slim_check.print_samples SlimCheck.printSamplesₓ'. -/
 /-- Print (at most) 10 samples of a given type to stdout for debugging.
 -/
 def printSamples {t : Type u} [Repr t] (g : Gen t) : Io Unit := do
Diff
@@ -536,15 +536,10 @@ def List.shrinkRemoves (k : ℕ) (hk : 0 < k) :
     else
       if hkn' : k = n then
         have : 1 < xs.sizeOf := by
-          subst_vars
-          cases xs
-          · contradiction
-          unfold_wf
-          apply lt_of_lt_of_le
-          show 1 < 1 + SizeOf.sizeOf xs_hd + 1
-          · linarith
-          · mono
-            apply list.one_le_sizeof
+          subst_vars; cases xs; · contradiction
+          unfold_wf; apply lt_of_lt_of_le
+          show 1 < 1 + SizeOf.sizeOf xs_hd + 1; · linarith
+          · mono; apply list.one_le_sizeof
         LazyList.singleton ⟨[], this⟩
       else
         have h₂ : k < xs.length := hn ▸ lt_of_le_of_ne (le_of_not_gt hkn) hkn'
Diff
@@ -271,9 +271,14 @@ def Nat.shrink' (k : ℕ) :
       nat.shrink' m h₀ (⟨k - m, h₁⟩::ls)
 #align slim_check.nat.shrink' SlimCheck.Nat.shrink'
 
+/- warning: slim_check.nat.shrink -> SlimCheck.Nat.shrink is a dubious translation:
+lean 3 declaration is
+  forall (n : Nat), List.{0} (Subtype.{1} Nat (fun (m : Nat) => WellFoundedRelation.R.{1} Nat (hasWellFoundedOfHasSizeof.{1} Nat Nat.hasSizeof) m n))
+but is expected to have type
+  Nat -> (List.{0} Nat)
+Case conversion may be inaccurate. Consider using '#align slim_check.nat.shrink SlimCheck.Nat.shrinkₓ'. -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
 /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
-#print SlimCheck.Nat.shrink /-
 /-- `nat.shrink n` creates a list of smaller natural numbers by
 successively dividing by 2 and subtracting the difference from
 `n`. For example, `nat.shrink 100 = [50, 75, 88, 94, 97, 99]`. -/
@@ -286,7 +291,6 @@ def Nat.shrink (n : ℕ) : List { m : ℕ // WellFoundedRelation.R m n } :=
     ⟨n / 11, this _ (by norm_num)⟩::⟨n / 3, this _ (by norm_num)⟩::Nat.shrink' n n le_rfl []
   else []
 #align slim_check.nat.shrink SlimCheck.Nat.shrink
--/
 
 open Gen
 
Diff
@@ -908,6 +908,12 @@ instance Perm'.slimCheck {xs : List α} : SlimCheck.Sampleable { ys : List α //
 /- ./././Mathport/Syntax/Translate/Tactic/Mathlib/Core.lean:38:34: unsupported: setup_tactic_parser -/
 open Tactic
 
+/- warning: slim_check.print_samples -> SlimCheck.printSamples is a dubious translation:
+lean 3 declaration is
+  forall {t : Type.{u}} [_inst_1 : Repr.{u} t], (SlimCheck.Gen.{u} t) -> (Io Unit)
+but is expected to have type
+  forall {t : Type} [_inst_1 : Repr.{0} t], (SlimCheck.Gen.{0} t) -> (IO PUnit.{1})
+Case conversion may be inaccurate. Consider using '#align slim_check.print_samples SlimCheck.printSamplesₓ'. -/
 /-- Print (at most) 10 samples of a given type to stdout for debugging.
 -/
 def printSamples {t : Type u} [Repr t] (g : Gen t) : Io Unit := do
Diff
@@ -120,7 +120,7 @@ def ShrinkFn (α : Type _) [SizeOf α] :=
   ∀ x : α, LazyList { y : α // SizeofLt y x }
 #align slim_check.shrink_fn SlimCheck.ShrinkFn
 
-/- ./././Mathport/Syntax/Translate/Command.lean:388:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable α` provides ways of creating examples of type `α`,
 and given such an example `x : α`, gives us a way to shrink it
 and find simpler examples.  -/
@@ -131,11 +131,11 @@ class Sampleable where
     LazyList.nil
 #align slim_check.sampleable SlimCheck.Sampleable
 
-attribute [instance] hasWellFoundedOfHasSizeof defaultHasSizeof
+attribute [instance 100] hasWellFoundedOfHasSizeof defaultHasSizeof
 
-attribute [instance] sampleable.wf
+attribute [instance 200] sampleable.wf
 
-/- ./././Mathport/Syntax/Translate/Command.lean:388:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_functor F` makes it possible to create samples of and
 shrink `F α` given a sampling function and a shrinking function for
 arbitrary `α` -/
@@ -146,7 +146,7 @@ class SampleableFunctor (F : Type u → Type v) [Functor F] where
   pRepr : ∀ α, Repr α → Repr (F α)
 #align slim_check.sampleable_functor SlimCheck.SampleableFunctor
 
-/- ./././Mathport/Syntax/Translate/Command.lean:388:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_bifunctor F` makes it possible to create samples of
 and shrink `F α β` given a sampling function and a shrinking function
 for arbitrary `α` and `β` -/
@@ -171,8 +171,8 @@ lean 3 declaration is
 but is expected to have type
   Sort.{u1} -> Sort.{max u1 (succ (succ u2))}
 Case conversion may be inaccurate. Consider using '#align slim_check.sampleable_ext SlimCheck.SampleableExtₓ'. -/
-/- ./././Mathport/Syntax/Translate/Command.lean:388:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
-/- ./././Mathport/Syntax/Translate/Command.lean:388:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`interp] [] -/
+/- ./././Mathport/Syntax/Translate/Command.lean:393:30: infer kinds are unsupported in Lean 4: #[`sample] [] -/
 /-- `sampleable_ext` generalizes the behavior of `sampleable`
 and makes it possible to express instances for types that
 do not lend themselves to introspection, such as `ℕ → ℕ`.
@@ -191,7 +191,7 @@ class SampleableExt (α : Sort u) where
   shrink : ShrinkFn proxy_repr
 #align slim_check.sampleable_ext SlimCheck.SampleableExt
 
-attribute [instance] sampleable_ext.p_repr sampleable_ext.wf
+attribute [instance 100] sampleable_ext.p_repr sampleable_ext.wf
 
 open Nat LazyList
 
@@ -347,7 +347,7 @@ def Int.hasSizeof : SizeOf ℤ :=
   ⟨Int.natAbs⟩
 #align slim_check.int.has_sizeof SlimCheck.Int.hasSizeof
 
-attribute [local instance] int.has_sizeof
+attribute [local instance 2000] int.has_sizeof
 
 instance Int.sampleable : Sampleable ℤ where
   wf := _

Changes in mathlib4

mathlib3
mathlib4
chore: Split Data.{Nat,Int}{.Order}.Basic in group vs ring instances (#11924)

Scatter the content of Data.Nat.Basic across:

  • Data.Nat.Defs for the lemmas having no dependencies
  • Algebra.Group.Nat for the monoid instances and the few miscellaneous lemmas needing them.
  • Algebra.Ring.Nat for the semiring instance and the few miscellaneous lemmas following it.

Similarly, scatter

  • Data.Int.Basic across Data.Int.Defs, Algebra.Group.Int, Algebra.Ring.Int
  • Data.Nat.Order.Basic across Data.Nat.Defs, Algebra.Order.Group.Nat, Algebra.Order.Ring.Nat
  • Data.Int.Order.Basic across Data.Int.Defs, Algebra.Order.Group.Int, Algebra.Order.Ring.Int

Also move a few lemmas from Data.Nat.Order.Lemmas to Data.Nat.Defs.

Before pre_11924

After post_11924

Diff
@@ -3,7 +3,7 @@ Copyright (c) 2022 Henrik Böving. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Henrik Böving, Simon Hudon
 -/
-import Mathlib.Data.Int.Order.Basic
+import Mathlib.Algebra.Order.Ring.Int
 import Mathlib.Init.Data.List.Instances
 import Mathlib.Testing.SlimCheck.Gen
 
chore: replace λ 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

  • In lines I was modifying anyway, I also converted => to .
  • Also contains some mild in-passing indentation fixes in Mathlib/Order/SupClosed.
  • Some doc comments still contained Lean 3 syntax λ x, , which I also replaced.
Diff
@@ -95,7 +95,7 @@ open Random Gen
 /-- Given an example `x : α`, `Shrinkable α` gives us a way to shrink it
 and suggest simpler examples. -/
 class Shrinkable (α : Type u) where
-  shrink : (x : α) → List α := λ _ => []
+  shrink : (x : α) → List α := fun _ ↦ []
 
 /-- `SampleableExt` can be used in two ways. The first (and most common)
 is to simply generate values of a type directly using the `Gen` monad,
@@ -159,7 +159,7 @@ instance Fin.shrinkable {n : Nat} : Shrinkable (Fin n.succ) where
 
 /-- `Int.shrinkable` operates like `Nat.shrinkable` but also includes the negative variants. -/
 instance Int.shrinkable : Shrinkable Int where
-  shrink n := Nat.shrink n.natAbs |>.map (λ x => ([x, -x] : List ℤ)) |>.join
+  shrink n := Nat.shrink n.natAbs |>.map (fun x ↦ ([x, -x] : List ℤ)) |>.join
 
 instance Rat.shrinkable : Shrinkable Rat where
   shrink r :=
@@ -170,14 +170,14 @@ instance Char.shrinkable : Shrinkable Char := {}
 
 instance Prod.shrinkable [shrA : Shrinkable α] [shrB : Shrinkable β] :
     Shrinkable (Prod α β) where
-  shrink := λ (fst,snd) =>
+  shrink := fun (fst,snd) ↦
     let shrink1 := shrA.shrink fst |>.map fun x ↦ (x, snd)
     let shrink2 := shrB.shrink snd |>.map fun x ↦ (fst, x)
     shrink1 ++ shrink2
 
 instance Sigma.shrinkable [shrA : Shrinkable α] [shrB : Shrinkable β] :
     Shrinkable ((_ : α) × β) where
-  shrink := λ ⟨fst,snd⟩ =>
+  shrink := fun ⟨fst,snd⟩ ↦
     let shrink1 := shrA.shrink fst |>.map fun x ↦ ⟨x, snd⟩
     let shrink2 := shrB.shrink snd |>.map fun x ↦ ⟨fst, x⟩
     shrink1 ++ shrink2
@@ -269,7 +269,7 @@ instance inhabited [inst : Inhabited α] : Inhabited (NoShrink α) := inst
 instance repr [inst : Repr α] : Repr (NoShrink α) := inst
 
 instance shrinkable : Shrinkable (NoShrink α) where
-  shrink := λ _ => []
+  shrink := fun _ ↦ []
 
 instance sampleableExt [SampleableExt α] [Repr α] : SampleableExt (NoShrink α) :=
   SampleableExt.mkSelfContained <| (NoShrink.mk ∘ SampleableExt.interp) <$> SampleableExt.sample
chore: move to v4.6.0-rc1, merging adaptations from bump/v4.6.0 (#10176)

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Joachim Breitner <mail@joachim-breitner.de>

Diff
@@ -201,7 +201,7 @@ instance Nat.sampleableExt : SampleableExt Nat :=
 
 instance Fin.sampleableExt {n : Nat} : SampleableExt (Fin (n.succ)) :=
   mkSelfContained (do choose (Fin n.succ) (Fin.ofNat 0) (Fin.ofNat (← getSize)) (by
-    simp only [LE.le, Fin.ofNat, Nat.zero_mod, Fin.zero_eta, Fin.val_zero]
+    simp only [Fin.ofNat, Fin.val_zero]
     exact Nat.zero_le _))
 
 instance Int.sampleableExt : SampleableExt Int :=
refactor: Split off basic Nat file (#9551)

Data.Nat.Basic is currently made of two things:

  • Basic lemmas that continue the theory in Std (and could belong there, really)
  • Basic algebraic order instances

I need the first ones earlier in the algebraic order hierarchy, hence the split.

Part of #9411. Similar to #9443

Diff
@@ -3,8 +3,9 @@ Copyright (c) 2022 Henrik Böving. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Henrik Böving, Simon Hudon
 -/
+import Mathlib.Data.Int.Order.Basic
+import Mathlib.Init.Data.List.Instances
 import Mathlib.Testing.SlimCheck.Gen
-import Qq
 
 #align_import testing.slim_check.sampleable from "leanprover-community/mathlib"@"fdc286cc6967a012f41b87f76dcd2797b53152af"
 
chore: cleanup simp calls (#9539)

Remove some unnecessary arguments in simp calls, which will become problematic when the simp algorithm changes in leanprover/lean4#3124.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -200,7 +200,7 @@ instance Nat.sampleableExt : SampleableExt Nat :=
 
 instance Fin.sampleableExt {n : Nat} : SampleableExt (Fin (n.succ)) :=
   mkSelfContained (do choose (Fin n.succ) (Fin.ofNat 0) (Fin.ofNat (← getSize)) (by
-    simp only [LE.le, Fin.ofNat, Nat.zero_mod, Fin.zero_eta, Fin.val_zero, Nat.le_eq]
+    simp only [LE.le, Fin.ofNat, Nat.zero_mod, Fin.zero_eta, Fin.val_zero]
     exact Nat.zero_le _))
 
 instance Int.sampleableExt : SampleableExt Int :=
chore(*): replace $ with <| (#9319)

See Zulip thread for the discussion.

Diff
@@ -216,7 +216,7 @@ instance Rat.sampleableExt : SampleableExt Rat :=
     return Rat.divInt d n)
 
 instance Bool.sampleableExt : SampleableExt Bool :=
-  mkSelfContained $ chooseAny Bool
+  mkSelfContained <| chooseAny Bool
 
 /-- This can be specialized into customized `SampleableExt Char` instances.
 The resulting instance has `1 / length` chances of making an unrestricted choice of characters
@@ -227,7 +227,7 @@ def Char.sampleable (length : Nat) (chars : List Char) (pos : 0 < chars.length)
     let x ← choose Nat 0 length (Nat.zero_le _)
     if x.val == 0 then
       let n ← interpSample Nat
-      pure $ Char.ofNat n
+      pure <| Char.ofNat n
     else
       elements chars pos
 
@@ -271,7 +271,7 @@ instance shrinkable : Shrinkable (NoShrink α) where
   shrink := λ _ => []
 
 instance sampleableExt [SampleableExt α] [Repr α] : SampleableExt (NoShrink α) :=
-  SampleableExt.mkSelfContained $ (NoShrink.mk ∘ SampleableExt.interp) <$> SampleableExt.sample
+  SampleableExt.mkSelfContained <| (NoShrink.mk ∘ SampleableExt.interp) <$> SampleableExt.sample
 
 end NoShrink
 
refactor(Testing/SlimCheck/Sampleable): Qq-ify (#8857)

This makes things a little less fragile to refactors, as the types are checked up front. It also means we get better error messages.

Diff
@@ -288,18 +288,20 @@ def printSamples {t : Type} [Repr t] (g : Gen t) : IO PUnit := do
 open Lean Meta Qq
 
 /-- Create a `Gen α` expression from the argument of `#sample` -/
-def mkGenerator (e : Expr) : MetaM (Expr × Expr) := do
-  let t ← inferType e
-  match t.getAppFnArgs with
-  | (`Gen, #[t]) => do
-    let repr_inst ← synthInstance (← mkAppM ``Repr #[t])
-    pure (repr_inst, e)
-  | _ => do
-    let sampleableExt_inst ← synthInstance (mkApp (← mkConstWithFreshMVarLevels ``SampleableExt) e)
-    let repr_inst ← mkAppOptM ``SampleableExt.proxyRepr #[e, sampleableExt_inst]
-    let gen ← mkAppOptM ``SampleableExt.sample #[none, sampleableExt_inst]
-    pure (repr_inst, gen)
-
+def mkGenerator (e : Expr) : MetaM (Σ (u : Level) (α : Q(Type $u)), Q(Repr $α) × Q(Gen $α)) := do
+  match ← inferTypeQ e with
+  | ⟨.succ u, ~q(Gen $α), gen⟩ =>
+    let repr_inst ← synthInstanceQ (q(Repr $α) : Q(Type $u))
+    pure ⟨u, α, repr_inst, gen⟩
+  | ⟨.succ u, ~q(Sort u), α⟩ => do
+    let v ← mkFreshLevelMVar
+    let _sampleableExt_inst ← synthInstanceQ (q(SampleableExt.{u,v} $α) : Q(Sort (max u (v + 2))))
+    let v ← instantiateLevelMVars v
+    let repr_inst := q(SampleableExt.proxyRepr (α := $α))
+    let gen := q(SampleableExt.sample (α := $α))
+    pure ⟨v, q(SampleableExt.proxy $α), repr_inst, gen⟩
+  | ⟨_u, t, _e⟩ =>
+    throwError "Must be a Sort u` or a `Gen α`, got value of type{indentExpr t}"
 open Elab
 
 /--
@@ -339,8 +341,10 @@ values of type `type` using an increasing size parameter.
 elab "#sample " e:term : command =>
   Command.runTermElabM fun _ => do
     let e ← Elab.Term.elabTermAndSynthesize e none
-    let (repr_inst, gen) ← mkGenerator e
-    let printSamples ← mkAppOptM ``printSamples #[none, repr_inst, gen]
+    let g ← mkGenerator e
+    -- `printSamples` only works in `Type 0` (see the porting note)
+    let ⟨0, α, _, gen⟩ := g | throwError "Cannot sample from {g.1} due to its universe"
+    let printSamples := q(printSamples (t := $α) $gen)
     let code ← unsafe evalExpr (IO PUnit) q(IO PUnit) printSamples
     _ ← code
 
chore: space after (#8178)

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -196,23 +196,23 @@ section Samplers
 open SampleableExt
 
 instance Nat.sampleableExt : SampleableExt Nat :=
-  mkSelfContained (do choose Nat 0 (←getSize) (Nat.zero_le _))
+  mkSelfContained (do choose Nat 0 (← getSize) (Nat.zero_le _))
 
 instance Fin.sampleableExt {n : Nat} : SampleableExt (Fin (n.succ)) :=
-  mkSelfContained (do choose (Fin n.succ) (Fin.ofNat 0) (Fin.ofNat (←getSize)) (by
+  mkSelfContained (do choose (Fin n.succ) (Fin.ofNat 0) (Fin.ofNat (← getSize)) (by
     simp only [LE.le, Fin.ofNat, Nat.zero_mod, Fin.zero_eta, Fin.val_zero, Nat.le_eq]
     exact Nat.zero_le _))
 
 instance Int.sampleableExt : SampleableExt Int :=
   mkSelfContained (do
-    choose Int (-(←getSize)) (←getSize)
+    choose Int (-(← getSize)) (← getSize)
       (le_trans (Int.neg_nonpos_of_nonneg (Int.ofNat_zero_le _)) (Int.ofNat_zero_le _)))
 
 instance Rat.sampleableExt : SampleableExt Rat :=
   mkSelfContained (do
-    let d ← choose Int (-(←getSize)) (←getSize)
+    let d ← choose Int (-(← getSize)) (← getSize)
       (le_trans (Int.neg_nonpos_of_nonneg (Int.ofNat_zero_le _)) (Int.ofNat_zero_le _))
-    let n ← choose Nat 0 (←getSize) (Nat.zero_le _)
+    let n ← choose Nat 0 (← getSize) (Nat.zero_le _)
     return Rat.divInt d n)
 
 instance Bool.sampleableExt : SampleableExt Bool :=
feat: add slim_check generators for Rat (#8759)

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -160,6 +160,10 @@ instance Fin.shrinkable {n : Nat} : Shrinkable (Fin n.succ) where
 instance Int.shrinkable : Shrinkable Int where
   shrink n := Nat.shrink n.natAbs |>.map (λ x => ([x, -x] : List ℤ)) |>.join
 
+instance Rat.shrinkable : Shrinkable Rat where
+  shrink r :=
+    (Shrinkable.shrink r.num).bind fun d => Nat.shrink r.den |>.map fun n => Rat.divInt d n
+
 instance Bool.shrinkable : Shrinkable Bool := {}
 instance Char.shrinkable : Shrinkable Char := {}
 
@@ -204,6 +208,13 @@ instance Int.sampleableExt : SampleableExt Int :=
     choose Int (-(←getSize)) (←getSize)
       (le_trans (Int.neg_nonpos_of_nonneg (Int.ofNat_zero_le _)) (Int.ofNat_zero_le _)))
 
+instance Rat.sampleableExt : SampleableExt Rat :=
+  mkSelfContained (do
+    let d ← choose Int (-(←getSize)) (←getSize)
+      (le_trans (Int.neg_nonpos_of_nonneg (Int.ofNat_zero_le _)) (Int.ofNat_zero_le _))
+    let n ← choose Nat 0 (←getSize) (Nat.zero_le _)
+    return Rat.divInt d n)
+
 instance Bool.sampleableExt : SampleableExt Bool :=
   mkSelfContained $ chooseAny Bool
 
chore: remove nonterminal simp (#7580)

Removes nonterminal simps on lines looking like simp [...]

Diff
@@ -196,9 +196,8 @@ instance Nat.sampleableExt : SampleableExt Nat :=
 
 instance Fin.sampleableExt {n : Nat} : SampleableExt (Fin (n.succ)) :=
   mkSelfContained (do choose (Fin n.succ) (Fin.ofNat 0) (Fin.ofNat (←getSize)) (by
-    simp [Fin.ofNat, LE.le]
-    exact Nat.zero_le _
-  ))
+    simp only [LE.le, Fin.ofNat, Nat.zero_mod, Fin.zero_eta, Fin.val_zero, Nat.le_eq]
+    exact Nat.zero_le _))
 
 instance Int.sampleableExt : SampleableExt Int :=
   mkSelfContained (do
fix: disable autoImplicit globally (#6528)

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:

  • Assuming variables are in scope, but pasting the lemma in the wrong section
  • Pasting in a lemma from a scratch file without checking to see if the variable names are consistent with the rest of the file
  • Making a copy-paste error between lemmas and forgetting to add an explicit arguments.

Having set_option autoImplicit false as the default prevents these types of mistake being made in the 90% of files where autoImplicits 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.

Diff
@@ -85,6 +85,8 @@ random testing
 
 -/
 
+set_option autoImplicit true
+
 namespace SlimCheck
 
 open Random Gen
chore: script to replace headers with #align_import statements (#5979)

Open in Gitpod

Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -2,15 +2,12 @@
 Copyright (c) 2022 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.sampleable
-! 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.Testing.SlimCheck.Gen
 import Qq
 
+#align_import testing.slim_check.sampleable from "leanprover-community/mathlib"@"fdc286cc6967a012f41b87f76dcd2797b53152af"
+
 /-!
 # `SampleableExt` Class
 
feat: port Testing.SlimCheck.Functions (#5768)

This diverges fairly considerably from mathlib3 since we changed the SampleableExt API when porting the previous file.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Matthew Ballard <matt@mrb.email>

Diff
@@ -171,6 +171,13 @@ instance Prod.shrinkable [shrA : Shrinkable α] [shrB : Shrinkable β] :
     let shrink2 := shrB.shrink snd |>.map fun x ↦ (fst, x)
     shrink1 ++ shrink2
 
+instance Sigma.shrinkable [shrA : Shrinkable α] [shrB : Shrinkable β] :
+    Shrinkable ((_ : α) × β) where
+  shrink := λ ⟨fst,snd⟩ =>
+    let shrink1 := shrA.shrink fst |>.map fun x ↦ ⟨x, snd⟩
+    let shrink2 := shrB.shrink snd |>.map fun x ↦ ⟨fst, x⟩
+    shrink1 ++ shrink2
+
 open Shrinkable
 
 /-- Shrink a list of a shrinkable type, either by discarding an element or shrinking an element. -/
fix: correct universe polymorphism in SlimCheck (#5796)

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.

Diff
@@ -218,7 +218,7 @@ def Char.sampleable (length : Nat) (chars : List Char) (pos : 0 < chars.length)
 instance Char.sampleableDefault : SampleableExt Char :=
   Char.sampleable 3 " 0123abcABC:,;`\\/".toList (by decide)
 
-instance Prod.sampleableExt {α β : Type u} [SampleableExt α] [SampleableExt β] :
+instance Prod.sampleableExt {α : Type u} {β : Type v} [SampleableExt α] [SampleableExt β] :
     SampleableExt (α × β) where
   proxy := Prod (proxy α) (proxy β)
   proxyRepr := inferInstance
chore: fix slim_check porting headers (#5522)

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -3,7 +3,7 @@ Copyright (c) 2022 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.sampleable
 ! leanprover-community/mathlib commit fdc286cc6967a012f41b87f76dcd2797b53152af
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.

Dependencies 8 + 184

185 files ported (95.9%)
78074 lines ported (97.0%)
Show graph

The unported dependencies are