Skip to content

Commit

Permalink
Merge branch 'main' into finrange
Browse files Browse the repository at this point in the history
  • Loading branch information
fgdorais authored Nov 25, 2024
2 parents c0b56df + 44e2d2e commit 8db191b
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/labels-from-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
if: github.event.pull_request.state == 'closed'
uses: actions-ecosystem/action-remove-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: |
WIP
awaiting-author
Expand All @@ -48,6 +49,7 @@ jobs:
! contains(github.event.pull_request.labels.*.name, 'WIP')
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: WIP

- name: Label unlabeled other PR as awaiting-review
Expand All @@ -59,4 +61,5 @@ jobs:
! contains(github.event.pull_request.labels.*.name, 'WIP')
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: awaiting-review
9 changes: 5 additions & 4 deletions Batteries/Classes/SatisfiesM.lean
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,15 @@ theorem SatisfiesM_EStateM_eq :
rw [EStateM.run_map, EStateM.run]
split <;> simp_all

@[simp] theorem SatisfiesM_ReaderT_eq [Monad m] :
theorem SatisfiesM_ReaderT_eq [Monad m] :
SatisfiesM (m := ReaderT ρ m) p x ↔ ∀ s, SatisfiesM p (x.run s) :=
(exists_congr fun a => by exact ⟨fun eq _ => eq ▸ rfl, funext⟩).trans Classical.skolem.symm

theorem SatisfiesM_StateRefT_eq [Monad m] :
SatisfiesM (m := StateRefT' ω σ m) p x ↔ ∀ s, SatisfiesM p (x s) := by simp [ReaderT.run]
SatisfiesM (m := StateRefT' ω σ m) p x ↔ ∀ s, SatisfiesM p (x s) := by
simp [SatisfiesM_ReaderT_eq, ReaderT.run]

@[simp] theorem SatisfiesM_StateT_eq [Monad m] [LawfulMonad m] :
theorem SatisfiesM_StateT_eq [Monad m] [LawfulMonad m] :
SatisfiesM (m := StateT ρ m) (α := α) p x ↔ ∀ s, SatisfiesM (m := m) (p ·.1) (x.run s) := by
change SatisfiesM (m := StateT ρ m) (α := α) p x ↔ ∀ s, SatisfiesM (m := m) (p ·.1) (x s)
refine .trans ⟨fun ⟨f, eq⟩ => eq ▸ ?_, fun ⟨f, h⟩ => ?_⟩ Classical.skolem.symm
Expand All @@ -201,7 +202,7 @@ theorem SatisfiesM_StateRefT_eq [Monad m] :
· refine ⟨fun s => (fun ⟨⟨a, s'⟩, h⟩ => ⟨⟨a, h⟩, s'⟩) <$> f s, funext fun s => ?_⟩
show _ >>= _ = _; simp [← h]

@[simp] theorem SatisfiesM_ExceptT_eq [Monad m] [LawfulMonad m] :
theorem SatisfiesM_ExceptT_eq [Monad m] [LawfulMonad m] :
SatisfiesM (m := ExceptT ρ m) (α := α) p x ↔
SatisfiesM (m := m) (∀ a, · = .ok a → p a) x.run := by
change _ ↔ SatisfiesM (m := m) (∀ a, · = .ok a → p a) x
Expand Down
18 changes: 13 additions & 5 deletions Batteries/Data/Range/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ theorem forIn'_eq_forIn_range' [Monad m] (r : Std.Range)
suffices ∀ H, forIn' [start:stop:step] init f = forIn (L.pmap Subtype.mk H) init f' from this _
intro H; dsimp only [forIn', Range.forIn']
if h : start < stop then
simp [numElems, Nat.not_le.2 h, L]; split
simp only [numElems, Nat.not_le.2 h, ↓reduceIte, L]; split
· subst step
suffices ∀ n H init,
forIn'.loop start stop 0 f n start (Nat.le_refl _) init =
forIn ((List.range' start n 0).pmap Subtype.mk H) init f' from this _ ..
intro n; induction n with (intro H init; unfold forIn'.loop; simp [*])
intro n; induction n with
(intro H init
unfold forIn'.loop
simp only [↓reduceDIte, Nat.add_zero, List.pmap, List.forIn_cons, List.forIn_nil, h])
| succ n ih => simp [ih (List.forall_mem_cons.1 H).2]; rfl
· next step0 =>
have hstep := Nat.pos_of_ne_zero step0
Expand All @@ -84,10 +87,15 @@ theorem forIn'_eq_forIn_range' [Monad m] (r : Std.Range)
have ih := ih _ _ (Nat.le_trans hle (Nat.le_add_right ..))
(List.forall_mem_cons.1 H).2 (Nat.le_of_succ_le_succ h1) fun i => by
rw [Nat.add_right_comm, Nat.add_assoc, ← Nat.mul_succ, h2, Nat.succ_le_succ_iff]
have := h2 0; simp at this
rw [forIn'.loop]; simp [this, ih]; rfl
have := h2 0
simp only [Nat.mul_zero, Nat.add_zero, Nat.le_zero_eq, Nat.add_one_ne_zero, iff_false,
Nat.not_le] at this
rw [forIn'.loop]
simp only [this, ↓reduceDIte, ih, List.pmap, List.forIn_cons]
rfl
else
simp [List.range', h, numElems_stop_le_start ⟨start, stop, step⟩ (Nat.not_lt.1 h), L]
simp only [numElems_stop_le_start ⟨start, stop, step⟩ (Nat.not_lt.1 h), List.range'_zero,
List.pmap, List.forIn_nil, L]
cases stop <;> unfold forIn'.loop <;> simp [List.forIn', h]

theorem forIn_eq_forIn_range' [Monad m] (r : Std.Range)
Expand Down
7 changes: 3 additions & 4 deletions Batteries/Data/Vector/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Batteries.Data.List.Basic
import Batteries.Data.List.Lemmas
import Batteries.Tactic.Alias
import Batteries.Tactic.Lint.Misc
import Batteries.Tactic.PrintPrefix

/-!
# Vectors
Expand Down Expand Up @@ -252,7 +253,7 @@ Compares two vectors of the same size using a given boolean relation `r`. `isEqv
`true` if and only if `r v[i] w[i]` is true for all indices `i`.
-/
@[inline] def isEqv (v w : Vector α n) (r : α → α → Bool) : Bool :=
Array.isEqvAux v.toArray w.toArray (by simp) r 0 (by simp)
Array.isEqvAux v.toArray w.toArray (by simp) r n (by simp)

instance [BEq α] : BEq (Vector α n) where
beq a b := isEqv a b (· == ·)
Expand Down Expand Up @@ -294,9 +295,7 @@ Finds the first index of a given value in a vector using `==` for comparison. Re
no element of the index matches the given value.
-/
@[inline] def indexOf? [BEq α] (v : Vector α n) (x : α) : Option (Fin n) :=
match v.toArray.indexOf? x with
| some res => some (res.cast v.size_toArray)
| none => none
(v.toArray.indexOf? x).map (Fin.cast v.size_toArray)

/-- Returns `true` when `v` is a prefix of the vector `w`. -/
@[inline] def isPrefixOf [BEq α] (v : Vector α m) (w : Vector α n) : Bool :=
Expand Down
Loading

0 comments on commit 8db191b

Please sign in to comment.