File tree Expand file tree Collapse file tree 3 files changed +22
-7
lines changed Expand file tree Collapse file tree 3 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -304,11 +304,19 @@ This is encoded in `LawfulClosedOpenIntersection`.
304
304
class ClosedOpenIntersection (shape : RangeShape) (α : Type w) where
305
305
intersection : PRange shape α → PRange ⟨.closed, .open⟩ α → PRange ⟨.closed, .open⟩ α
306
306
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
+ -/
307
311
class LawfulClosedOpenIntersection (shape : RangeShape) (α : Type w)
308
312
[ClosedOpenIntersection shape α]
309
313
[SupportsLowerBound shape.lower α] [SupportsUpperBound shape.upper α]
310
314
[SupportsLowerBound .closed α]
311
315
[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
+ -/
312
320
mem_intersection_iff {a : α} {r : PRange ⟨shape.lower, shape.upper⟩ α}
313
321
{s : PRange ⟨.closed, .open⟩ α} :
314
322
a ∈ ClosedOpenIntersection.intersection r s ↔ a ∈ r ∧ a ∈ s
Original file line number Diff line number Diff line change @@ -30,10 +30,12 @@ instance {shape} {α : Type u} [ClosedOpenIntersection shape Nat] :
30
30
instance {s : Subarray α} : ToIterator s Id α :=
31
31
.of _
32
32
(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
39
34
|>.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
Original file line number Diff line number Diff line change @@ -27,23 +27,28 @@ def Internal.iter (s : Slice γ) [ToIterator s Id β] :=
27
27
ToIterator.iter s
28
28
29
29
/--
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`.
31
33
-/
32
34
@[always_inline, inline]
33
35
def size (s : Slice g) [ToIterator s Id β] [Iterator (ToIterator.State s Id) Id β]
34
36
[IteratorSize (ToIterator.State s Id) Id] :=
35
37
Internal.iter s |>.size
36
38
39
+ /-- Allocates a new array that contains the elements of the slice. -/
37
40
@[always_inline, inline]
38
41
def toArray (s : Slice g) [ToIterator s Id β] [Iterator (ToIterator.State s Id) Id β]
39
42
[IteratorCollect (ToIterator.State s Id) Id Id] [Finite (ToIterator.State s Id) Id] : Array β :=
40
43
Internal.iter s |>.toArray
41
44
45
+ /-- Allocates a new list that contains the elements of the slice. -/
42
46
@[always_inline, inline]
43
47
def toList (s : Slice g) [ToIterator s Id β] [Iterator (ToIterator.State s Id) Id β]
44
48
[IteratorCollect (ToIterator.State s Id) Id Id] [Finite (ToIterator.State s Id) Id] : List β :=
45
49
Internal.iter s |>.toList
46
50
51
+ /-- Allocates a new list that contains the elements of the slice in reverse order. -/
47
52
@[always_inline, inline]
48
53
def toListRev (s : Slice g) [ToIterator s Id β] [Iterator (ToIterator.State s Id) Id β]
49
54
[IteratorCollect (ToIterator.State s Id) Id Id] [Finite (ToIterator.State s Id) Id] : List β :=
You can’t perform that action at this time.
0 commit comments