Skip to content

Commit 1c51792

Browse files
committed
cleanups
1 parent c17bbea commit 1c51792

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/Init/Data/Range/Polymorphic/PRange.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,19 @@ This is encoded in `LawfulClosedOpenIntersection`.
304304
class ClosedOpenIntersection (shape : RangeShape) (α : Type w) where
305305
intersection : PRange shape α → PRange ⟨.closed, .open⟩ α → PRange ⟨.closed, .open⟩ α
306306

307+
/--
308+
This typeclass ensures that the intersection according to `ClosedOpenIntersection shape α`
309+
of two ranges contains exactly those elements that are contained in both ranges.
310+
-/
307311
class LawfulClosedOpenIntersection (shape : RangeShape) (α : Type w)
308312
[ClosedOpenIntersection shape α]
309313
[SupportsLowerBound shape.lower α] [SupportsUpperBound shape.upper α]
310314
[SupportsLowerBound .closed α]
311315
[SupportsUpperBound .open α] where
316+
/--
317+
The intersection according to `ClosedOpenIntersection shapee α` of two ranges contains exactly
318+
those elements that are contained in both ranges.
319+
-/
312320
mem_intersection_iff {a : α} {r : PRange ⟨shape.lower, shape.upper⟩ α}
313321
{s : PRange ⟨.closed, .open⟩ α} :
314322
a ∈ ClosedOpenIntersection.intersection r s ↔ a ∈ r ∧ a ∈ s

src/Init/Data/Slice/Array.lean

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ instance {shape} {α : Type u} [ClosedOpenIntersection shape Nat] :
3030
instance {s : Subarray α} : ToIterator s Id α :=
3131
.of _
3232
(PRange.Internal.iter (s.internalRepresentation.start...<s.internalRepresentation.stop)
33-
|>.attachWith (· < s.internalRepresentation.array.size) (by
34-
simp only [Internal.isPlausibleIndirectOutput_iter_iff, Membership.mem,
35-
SupportsUpperBound.IsSatisfied, and_imp]
36-
intro out _ h
37-
have := s.internalRepresentation.stop_le_array_size
38-
omega)
33+
|>.attachWith (· < s.internalRepresentation.array.size) ?h
3934
|>.map fun i => s.internalRepresentation.array[i.1])
35+
where finally
36+
case h =>
37+
simp only [Internal.isPlausibleIndirectOutput_iter_iff, Membership.mem,
38+
SupportsUpperBound.IsSatisfied, and_imp]
39+
intro out _ h
40+
have := s.internalRepresentation.stop_le_array_size
41+
omega

src/Init/Data/Slice/Operations.lean

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,28 @@ def Internal.iter (s : Slice γ) [ToIterator s Id β] :=
2727
ToIterator.iter s
2828

2929
/--
30-
Returns the number of elements -- not necessarily distinct -- in the given slice.
30+
Returns the number of elements with distinct indices in the given slice.
31+
32+
Example: `#[1, 1, 1][0...2] = 2`.
3133
-/
3234
@[always_inline, inline]
3335
def size (s : Slice g) [ToIterator s Id β] [Iterator (ToIterator.State s Id) Id β]
3436
[IteratorSize (ToIterator.State s Id) Id] :=
3537
Internal.iter s |>.size
3638

39+
/-- Allocates a new array that contains the elements of the slice. -/
3740
@[always_inline, inline]
3841
def toArray (s : Slice g) [ToIterator s Id β] [Iterator (ToIterator.State s Id) Id β]
3942
[IteratorCollect (ToIterator.State s Id) Id Id] [Finite (ToIterator.State s Id) Id] : Array β :=
4043
Internal.iter s |>.toArray
4144

45+
/-- Allocates a new list that contains the elements of the slice. -/
4246
@[always_inline, inline]
4347
def toList (s : Slice g) [ToIterator s Id β] [Iterator (ToIterator.State s Id) Id β]
4448
[IteratorCollect (ToIterator.State s Id) Id Id] [Finite (ToIterator.State s Id) Id] : List β :=
4549
Internal.iter s |>.toList
4650

51+
/-- Allocates a new list that contains the elements of the slice in reverse order. -/
4752
@[always_inline, inline]
4853
def toListRev (s : Slice g) [ToIterator s Id β] [Iterator (ToIterator.State s Id) Id β]
4954
[IteratorCollect (ToIterator.State s Id) Id Id] [Finite (ToIterator.State s Id) Id] : List β :=

0 commit comments

Comments
 (0)