-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into lake/check-prelude
- Loading branch information
Showing
85 changed files
with
23,408 additions
and
19,521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#! /bin/env bash | ||
# Open a Mathlib4 PR for benchmarking a given Lean 4 PR | ||
|
||
set -euo pipefail | ||
|
||
[ $# -eq 1 ] || (echo "usage: $0 <lean4 PR #>"; exit 1) | ||
|
||
LEAN_PR=$1 | ||
PR_RESPONSE=$(gh api repos/leanprover-community/mathlib4/pulls -X POST -f head=lean-pr-testing-$LEAN_PR -f base=nightly-testing -f title="leanprover/lean4#$LEAN_PR benchmarking" -f draft=true -f body="ignore me") | ||
PR_NUMBER=$(echo "$PR_RESPONSE" | jq '.number') | ||
echo "opened https://github.com/leanprover-community/mathlib4/pull/$PR_NUMBER" | ||
gh api repos/leanprover-community/mathlib4/issues/$PR_NUMBER/comments -X POST -f body="!bench" > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/- | ||
Copyright (c) 2024 Lean FRO. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Kim Morrison | ||
-/ | ||
prelude | ||
import Init.Data.List.Nat.Perm | ||
import Init.Data.Array.Lemmas | ||
|
||
namespace Array | ||
|
||
open List | ||
|
||
/-- | ||
`Perm as bs` asserts that `as` and `bs` are permutations of each other. | ||
This is a wrapper around `List.Perm`, and for now has much less API. | ||
For more complicated verification, use `perm_iff_toList_perm` and the `List` API. | ||
-/ | ||
def Perm (as bs : Array α) : Prop := | ||
as.toList ~ bs.toList | ||
|
||
@[inherit_doc] scoped infixl:50 " ~ " => Perm | ||
|
||
theorem perm_iff_toList_perm {as bs : Array α} : as ~ bs ↔ as.toList ~ bs.toList := Iff.rfl | ||
|
||
@[simp] theorem perm_toArray (as bs : List α) : as.toArray ~ bs.toArray ↔ as ~ bs := by | ||
simp [perm_iff_toList_perm] | ||
|
||
@[simp, refl] protected theorem Perm.refl (l : Array α) : l ~ l := by | ||
cases l | ||
simp | ||
|
||
protected theorem Perm.rfl {l : List α} : l ~ l := .refl _ | ||
|
||
theorem Perm.of_eq {l₁ l₂ : Array α} (h : l₁ = l₂) : l₁ ~ l₂ := h ▸ .rfl | ||
|
||
protected theorem Perm.symm {l₁ l₂ : Array α} (h : l₁ ~ l₂) : l₂ ~ l₁ := by | ||
cases l₁; cases l₂ | ||
simp only [perm_toArray] at h | ||
simpa using h.symm | ||
|
||
protected theorem Perm.trans {l₁ l₂ l₃ : Array α} (h₁ : l₁ ~ l₂) (h₂ : l₂ ~ l₃) : l₁ ~ l₃ := by | ||
cases l₁; cases l₂; cases l₃ | ||
simp only [perm_toArray] at h₁ h₂ | ||
simpa using h₁.trans h₂ | ||
|
||
instance : Trans (Perm (α := α)) (Perm (α := α)) (Perm (α := α)) where | ||
trans h₁ h₂ := Perm.trans h₁ h₂ | ||
|
||
theorem perm_comm {l₁ l₂ : Array α} : l₁ ~ l₂ ↔ l₂ ~ l₁ := ⟨Perm.symm, Perm.symm⟩ | ||
|
||
theorem Perm.push (x y : α) {l₁ l₂ : Array α} (p : l₁ ~ l₂) : | ||
(l₁.push x).push y ~ (l₂.push y).push x := by | ||
cases l₁; cases l₂ | ||
simp only [perm_toArray] at p | ||
simp only [push_toArray, List.append_assoc, singleton_append, perm_toArray] | ||
exact p.append (Perm.swap' _ _ Perm.nil) | ||
|
||
theorem swap_perm {as : Array α} {i j : Nat} (h₁ : i < as.size) (h₂ : j < as.size) : | ||
as.swap i j ~ as := by | ||
simp only [swap, perm_iff_toList_perm, toList_set] | ||
apply set_set_perm | ||
|
||
end Array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/- | ||
Copyright (c) 2024 Lean FRO. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Kim Morrison | ||
-/ | ||
prelude | ||
import Init.Data.List.Nat.TakeDrop | ||
import Init.Data.List.Perm | ||
|
||
namespace List | ||
|
||
/-- Helper lemma for `set_set_perm`-/ | ||
private theorem set_set_perm' {as : List α} {i j : Nat} (h₁ : i < as.length) (h₂ : i + j < as.length) | ||
(hj : 0 < j) : | ||
(as.set i as[i + j]).set (i + j) as[i] ~ as := by | ||
have : as = | ||
as.take i ++ as[i] :: (as.take (i + j)).drop (i + 1) ++ as[i + j] :: as.drop (i + j + 1) := by | ||
simp only [getElem_cons_drop, append_assoc, cons_append] | ||
rw [← drop_append_of_le_length] | ||
· simp | ||
· simp; omega | ||
conv => lhs; congr; congr; rw [this] | ||
conv => rhs; rw [this] | ||
rw [set_append_left _ _ (by simp; omega)] | ||
rw [set_append_right _ _ (by simp; omega)] | ||
rw [set_append_right _ _ (by simp; omega)] | ||
simp only [length_append, length_take, length_set, length_cons, length_drop] | ||
rw [(show i - min i as.length = 0 by omega)] | ||
rw [(show i + j - (min i as.length + (min (i + j) as.length - (i + 1) + 1)) = 0 by omega)] | ||
simp only [set_cons_zero] | ||
simp only [append_assoc] | ||
apply Perm.append_left | ||
apply cons_append_cons_perm | ||
|
||
theorem set_set_perm {as : List α} {i j : Nat} (h₁ : i < as.length) (h₂ : j < as.length) : | ||
(as.set i as[j]).set j as[i] ~ as := by | ||
if h₃ : i = j then | ||
simp [h₃] | ||
else | ||
if h₃ : i < j then | ||
let j' := j - i | ||
have t : j = i + j' := by omega | ||
generalize j' = j' at t | ||
subst t | ||
exact set_set_perm' _ _ (by omega) | ||
else | ||
rw [set_comm _ _ _ (by omega)] | ||
let i' := i - j | ||
have t : i = j + i' := by omega | ||
generalize i' = i' at t | ||
subst t | ||
apply set_set_perm' _ _ (by omega) | ||
|
||
end List |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.