This PR migrates usages of `Std.Range` to the new polymorphic ranges. This PR unfortunately increases the transitive imports for frequently-used parts of `Init` because the ranges now rely on iterators in order to provide their functionality for types other than `Nat`. However, iteration over ranges in compiled code is as efficient as before in the examples I checked. This is because of a special `IteratorLoop` implementation provided in the PR for this purpose. There were two issues that were uncovered during migration: * In `IndPredBelow.lean`, migrating the last remaining range causes `compilerTest1.lean` to break. I have minimized the issue and came to the conclusion it's a compiler bug. Therefore, I have not replaced said old range usage yet (see #9186). * In `BRecOn.lean`, we are publicly importing the ranges. Making this import private should theoretically work, but there seems to be a problem with the module system, causing the build to panic later in `Init.Data.Grind.Poly` (see #9185). * In `FuzzyMatching.lean`, inlining fails with the new ranges, which would have led to significant slowdown. Therefore, I have not migrated this file either.
37 lines
1.4 KiB
Text
37 lines
1.4 KiB
Text
import Lean
|
||
|
||
/-!
|
||
#2564. `match` reduction currently has some special cases.
|
||
When combined with nonlinear functions like `List.insert` below,
|
||
it is crucial to preserve sharing during reduction. -/
|
||
|
||
section decidability_instances
|
||
|
||
variable {α : Type} {p : α → Prop} [DecidablePred p]
|
||
|
||
instance decidableBex : ∀ (l : List α), Decidable (∃ x, x ∈ l → p x)
|
||
| [] => isFalse sorry
|
||
| x::xs =>
|
||
match ‹DecidablePred p› x with
|
||
| isTrue h₁ => isTrue sorry
|
||
| isFalse h₁ => match decidableBex xs with
|
||
| isTrue h₂ => isTrue sorry
|
||
| isFalse h₂ => isFalse sorry
|
||
|
||
instance decidableBall (l : List α) : Decidable (∀ x, x ∈ l → p x) :=
|
||
match (inferInstance : Decidable <| ∃ x, x ∈ l → ¬ p x) with
|
||
| isFalse h => isTrue $ fun x hx => match ‹DecidablePred p› x with
|
||
| isTrue h' => h'
|
||
| isFalse h' => False.elim $ h sorry
|
||
| isTrue h => isFalse sorry
|
||
|
||
end decidability_instances
|
||
|
||
def parts : List (List Nat) := List.insert ([1, 1, 0, 0]) <| List.insert ([0, 0, 1, 1]) <|
|
||
List.insert ([1, 0, 0, 1]) <| List.insert ([1, 1, 1, 0]) <| List.insert ([1, 0, 0, 0]) <|
|
||
List.insert [1, 2, 3, 4] <| List.insert [5, 6, 7, 8] []
|
||
|
||
#eval show Lean.Elab.Command.CommandElabM _ from
|
||
for _ in *...(10 : Nat) do
|
||
Lean.Elab.Command.elabCommand (←
|
||
`(example : ∀ (x) (_ : x ∈ parts) (y) (_ : y ∈ parts), x ++ y ∉ parts := by decide))
|