Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/Init/Data/Range/Polymorphic/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,14 @@ public theorem Rxc.Iterator.pairwise_toList_upwardEnumerableLt [LE α] [Decidabl
· apply ihy (out := a)
simp_all [Rxc.Iterator.isPlausibleStep_iff, Rxc.Iterator.step]

theorem Rxc.Iterator.nodup_toList [LE α] [DecidableLE α]
[PRange.UpwardEnumerable α] [Rxc.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
[PRange.LawfulUpwardEnumerableLE α]
{it : Iter (α := Rxc.Iterator α) α} :
it.toList.Nodup := by
apply (Rxc.Iterator.pairwise_toList_upwardEnumerableLt it).imp
apply PRange.UpwardEnumerable.ne_of_lt

public theorem Rxo.Iterator.pairwise_toList_upwardEnumerableLt [LT α] [DecidableLT α]
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLT α]
[Rxo.IsAlwaysFinite α]
Expand All @@ -558,6 +566,14 @@ public theorem Rxo.Iterator.pairwise_toList_upwardEnumerableLt [LT α] [Decidabl
· apply ihy (out := a)
simp_all [Rxo.Iterator.isPlausibleStep_iff, Rxo.Iterator.step]

theorem Rxo.Iterator.nodup_toList [LT α] [DecidableLT α]
[PRange.UpwardEnumerable α] [Rxo.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
[PRange.LawfulUpwardEnumerableLT α]
{it : Iter (α := Rxo.Iterator α) α} :
it.toList.Nodup := by
apply (Rxo.Iterator.pairwise_toList_upwardEnumerableLt it).imp
apply PRange.UpwardEnumerable.ne_of_lt

public theorem Rxi.Iterator.pairwise_toList_upwardEnumerableLt
[UpwardEnumerable α] [LawfulUpwardEnumerable α]
[Rxi.IsAlwaysFinite α]
Expand All @@ -581,6 +597,13 @@ public theorem Rxi.Iterator.pairwise_toList_upwardEnumerableLt
· apply ihy (out := a)
simp_all [Rxi.Iterator.isPlausibleStep_iff, Rxi.Iterator.step]

theorem Rxi.Iterator.nodup_toList
[PRange.UpwardEnumerable α] [Rxi.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
{it : Iter (α := Rxi.Iterator α) α} :
it.toList.Nodup := by
apply (Rxi.Iterator.pairwise_toList_upwardEnumerableLt it).imp
apply PRange.UpwardEnumerable.ne_of_lt

namespace Rcc

variable {r : Rcc α}
Expand Down Expand Up @@ -658,6 +681,13 @@ public theorem pairwise_toList_upwardEnumerableLt [LE α] [DecidableLE α]
rw [Internal.toList_eq_toList_iter]
apply Rxc.Iterator.pairwise_toList_upwardEnumerableLt

public theorem nodup_toList [LE α] [DecidableLE α]
[PRange.UpwardEnumerable α] [Rxc.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
[PRange.LawfulUpwardEnumerableLE α]
{a b : α} :
(a...=b).toList.Nodup := by
simpa [Internal.toList_eq_toList_iter] using Std.Rxc.Iterator.nodup_toList

public theorem pairwise_toList_ne [LE α] [DecidableLE α]
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLE α]
[Rxc.IsAlwaysFinite α] :
Expand Down Expand Up @@ -913,6 +943,13 @@ public theorem pairwise_toList_upwardEnumerableLt [LE α] [LT α] [DecidableLT
rw [Internal.toList_eq_toList_iter]
apply Rxo.Iterator.pairwise_toList_upwardEnumerableLt

public theorem nodup_toList [LT α] [DecidableLT α]
[PRange.UpwardEnumerable α] [Rxo.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
[PRange.LawfulUpwardEnumerableLT α]
{a b : α} :
(a...b).toList.Nodup := by
simpa [Internal.toList_eq_toList_iter] using Std.Rxo.Iterator.nodup_toList

public theorem pairwise_toList_ne [LE α] [LT α] [DecidableLT α]
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLT α]
[Rxo.IsAlwaysFinite α] :
Expand Down Expand Up @@ -1124,6 +1161,11 @@ public theorem pairwise_toList_upwardEnumerableLt [LE α]
rw [Internal.toList_eq_toList_iter]
apply Rxi.Iterator.pairwise_toList_upwardEnumerableLt

public theorem nodup_toList
[PRange.UpwardEnumerable α] [Rxi.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
{a : α} : (a...*).toList.Nodup := by
simpa [Internal.toList_eq_toList_iter] using Std.Rxi.Iterator.nodup_toList

public theorem pairwise_toList_ne [LE α]
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α] :
r.toList.Pairwise (fun a b => a ≠ b) :=
Expand Down Expand Up @@ -1363,6 +1405,13 @@ public theorem pairwise_toList_upwardEnumerableLt [LE α] [DecidableLE α]
rw [Internal.toList_eq_toList_iter]
apply Rxc.Iterator.pairwise_toList_upwardEnumerableLt

public theorem nodup_toList [LE α] [DecidableLE α]
[PRange.UpwardEnumerable α] [Rxc.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
[PRange.LawfulUpwardEnumerableLE α]
{a b : α} :
(a<...=b).toList.Nodup := by
simpa [Internal.toList_eq_toList_iter] using Std.Rxc.Iterator.nodup_toList

public theorem pairwise_toList_ne [LE α] [DecidableLE α]
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLE α]
[Rxc.IsAlwaysFinite α] :
Expand Down Expand Up @@ -1588,6 +1637,13 @@ public theorem pairwise_toList_upwardEnumerableLt [LT α] [DecidableLT α]
rw [Internal.toList_eq_toList_iter]
apply Rxo.Iterator.pairwise_toList_upwardEnumerableLt

public theorem nodup_toList [LT α] [DecidableLT α]
[PRange.UpwardEnumerable α] [Rxo.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
[PRange.LawfulUpwardEnumerableLT α]
{a b : α} :
(a<...b).toList.Nodup := by
simpa [Internal.toList_eq_toList_iter] using Std.Rxo.Iterator.nodup_toList

public theorem pairwise_toList_ne [LT α] [DecidableLT α]
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLT α]
[Rxo.IsAlwaysFinite α] :
Expand Down Expand Up @@ -1823,6 +1879,11 @@ public theorem pairwise_toList_upwardEnumerableLt
rw [Internal.toList_eq_toList_iter]
apply Rxi.Iterator.pairwise_toList_upwardEnumerableLt

public theorem nodup_toList
[PRange.UpwardEnumerable α] [Rxi.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
{a : α} : (a<...*).toList.Nodup := by
simpa [Internal.toList_eq_toList_iter] using Std.Rxi.Iterator.nodup_toList

public theorem pairwise_toList_ne
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α] :
r.toList.Pairwise (fun a b => a ≠ b) :=
Expand Down Expand Up @@ -2072,6 +2133,13 @@ public theorem pairwise_toList_upwardEnumerableLt [LE α] [DecidableLE α] [Leas
r.toList.Pairwise (fun a b => UpwardEnumerable.LT a b) := by
simp [toList_eq_toList_rcc, Rcc.pairwise_toList_upwardEnumerableLt]

public theorem nodup_toList [LE α] [DecidableLE α] [Least? α]
[PRange.UpwardEnumerable α] [Rxc.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
[PRange.LawfulUpwardEnumerableLE α]
{a : α} :
(*...=a).toList.Nodup := by
simpa [Internal.toList_eq_toList_iter] using Std.Rxc.Iterator.nodup_toList

public theorem pairwise_toList_ne [LE α] [DecidableLE α] [Least? α]
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLE α]
[LawfulUpwardEnumerableLeast? α] [Rxc.IsAlwaysFinite α] :
Expand Down Expand Up @@ -2395,6 +2463,13 @@ public theorem pairwise_toList_upwardEnumerableLt [LT α] [DecidableLT α] [Leas
· exact Roo.pairwise_toList_upwardEnumerableLt
· simp

public theorem nodup_toList [LT α] [DecidableLT α] [Least? α]
[PRange.UpwardEnumerable α] [Rxo.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α]
[PRange.LawfulUpwardEnumerableLT α]
{a : α} :
(*...a).toList.Nodup := by
simpa [Internal.toList_eq_toList_iter] using Std.Rxo.Iterator.nodup_toList

public theorem pairwise_toList_ne [LT α] [DecidableLT α] [Least? α]
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLT α]
[LawfulUpwardEnumerableLeast? α] [Rxo.IsAlwaysFinite α] :
Expand Down Expand Up @@ -2688,6 +2763,11 @@ public theorem pairwise_toList_upwardEnumerableLt [Least? α]
· simp
· exact Rci.pairwise_toList_upwardEnumerableLt

public theorem nodup_toList [Least? α]
[PRange.UpwardEnumerable α] [Rxi.IsAlwaysFinite α] [PRange.LawfulUpwardEnumerable α] :
(*...* : Std.Rii α).toList.Nodup := by
simpa [Internal.toList_eq_toList_iter] using Std.Rxi.Iterator.nodup_toList

public theorem pairwise_toList_ne [Least? α]
[UpwardEnumerable α] [LawfulUpwardEnumerable α]
[LawfulUpwardEnumerableLeast? α] [Rxi.IsAlwaysFinite α] :
Expand Down
6 changes: 3 additions & 3 deletions src/Init/Data/Slice/Array/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ end SubarrayIterator

namespace Subarray

theorem internalIter_eq {α : Type u} {s : Subarray α} :
theorem Internal.iter_eq {α : Type u} {s : Subarray α} :
Internal.iter s = ⟨⟨s⟩⟩ :=
rfl

theorem toList_internalIter {α : Type u} {s : Subarray α} :
theorem Internal.toList_iter {α : Type u} {s : Subarray α} :
(Internal.iter s).toList =
(s.array.toList.take s.stop).drop s.start := by
simp [SubarrayIterator.toList_eq, Internal.iter_eq_toIteratorIter, ToIterator.iter_eq]
Expand Down Expand Up @@ -223,7 +223,7 @@ public theorem Subarray.toList_eq {xs : Subarray α} :
change aslice.toList = _
have : aslice.toList = lslice.toList := by
rw [ListSlice.toList_eq]
simp +instances only [aslice, lslice, Std.Slice.toList, toList_internalIter]
simp +instances only [aslice, lslice, Std.Slice.toList, Internal.toList_iter]
apply List.ext_getElem
· have : stop - start ≤ array.size - start := by omega
simp [Subarray.start, Subarray.stop, *, Subarray.array]
Expand Down
20 changes: 9 additions & 11 deletions src/Init/Data/Slice/InternalLemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,45 @@ theorem Internal.iter_eq_toIteratorIter {γ : Type u}
Internal.iter s = ToIterator.iter s :=
(rfl)

theorem forIn_internalIter {γ : Type u} {β : Type v}
theorem Internal.forIn_iter {γ : Type u} {β : Type v}
{m : Type w → Type x} [Monad m] {δ : Type w}
[ToIterator (Slice γ) Id α β]
[Iterator α Id β]
[IteratorLoop α Id m]
[LawfulIteratorLoop α Id m]
[Finite α Id] {s : Slice γ}
[Iterator α Id β] [IteratorLoop α Id m]
{s : Slice γ}
{init : δ} {f : β → δ → m (ForInStep δ)} :
ForIn.forIn (Internal.iter s) init f = ForIn.forIn s init f :=
(rfl)

theorem Internal.size_eq_length_internalIter [ToIterator (Slice γ) Id α β]
theorem Internal.size_eq_length_iter [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [Finite α Id]
[IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id]
{s : Slice γ} [SliceSize γ] [LawfulSliceSize γ] :
s.size = (Internal.iter s).length := by
simp only [Slice.size, iter, LawfulSliceSize.lawful, ← Iter.length_toList_eq_length]

theorem Internal.toArray_eq_toArray_internalIter {s : Slice γ} [ToIterator (Slice γ) Id α β]
theorem Internal.toArray_eq_toArray_iter {s : Slice γ} [ToIterator (Slice γ) Id α β]
[Iterator α Id β]
[Finite α Id] :
s.toArray = (Internal.iter s).toArray :=
(rfl)

theorem Internal.toList_eq_toList_internalIter {s : Slice γ} [ToIterator (Slice γ) Id α β]
theorem Internal.toList_eq_toList_iter {s : Slice γ} [ToIterator (Slice γ) Id α β]
[Iterator α Id β]
[Finite α Id] :
s.toList = (Internal.iter s).toList :=
(rfl)

theorem Internal.toListRev_eq_toListRev_internalIter {s : Slice γ} [ToIterator (Slice γ) Id α β]
theorem Internal.toListRev_eq_toListRev_iter {s : Slice γ} [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [Finite α Id] :
s.toListRev = (Internal.iter s).toListRev :=
(rfl)

theorem fold_internalIter [ToIterator (Slice γ) Id α β]
theorem Internal.fold_iter [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [IteratorLoop α Id Id] [Iterators.Finite α Id] {s : Slice γ} :
(Internal.iter s).fold (init := init) f = s.foldl (init := init) f := by
rfl

theorem foldM_internalIter {m : Type w → Type w'} [Monad m] [ToIterator (Slice γ) Id α β]
theorem Internal.foldM_iter {m : Type w → Type w'} [Monad m] [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [IteratorLoop α Id m] [Iterators.Finite α Id] {s : Slice γ} {f : δ → β → m δ} :
(Internal.iter s).foldM (init := init) f = s.foldlM (init := init) f := by
rfl
71 changes: 48 additions & 23 deletions src/Init/Data/Slice/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import all Init.Data.Slice.Operations
import Init.Data.Iterators.Lemmas.Consumers
public import Init.Data.List.Control
public import Init.Data.Iterators.Consumers.Collect

import Init.Data.Slice.InternalLemmas

public section

open Std Std.Iterators

namespace Std.Slice

variable {γ : Type u} {α β : Type v}

@[simp]
public theorem forIn_toList {γ : Type u} {β : Type v}
theorem forIn_toList {γ : Type u} {β : Type v}
{m : Type w → Type x} [Monad m] [LawfulMonad m] {δ : Type w}
[ToIterator (Slice γ) Id α β]
[Iterator α Id β]
Expand All @@ -30,10 +31,10 @@ public theorem forIn_toList {γ : Type u} {β : Type v}
[Finite α Id] {s : Slice γ}
{init : δ} {f : β → δ → m (ForInStep δ)} :
ForIn.forIn s.toList init f = ForIn.forIn s init f := by
rw [← forIn_internalIter, ← Iter.forIn_toList, Slice.toList]
rw [← Internal.forIn_iter, ← Iter.forIn_toList, Slice.toList]

@[simp]
public theorem forIn_toArray {γ : Type u} {β : Type v}
theorem forIn_toArray {γ : Type u} {β : Type v}
{m : Type w → Type x} [Monad m] [LawfulMonad m] {δ : Type w}
[ToIterator (Slice γ) Id α β]
[Iterator α Id β]
Expand All @@ -42,46 +43,70 @@ public theorem forIn_toArray {γ : Type u} {β : Type v}
[Finite α Id] {s : Slice γ}
{init : δ} {f : β → δ → m (ForInStep δ)} :
ForIn.forIn s.toArray init f = ForIn.forIn s init f := by
rw [← forIn_internalIter, ← Iter.forIn_toArray, Slice.toArray]
rw [← Internal.forIn_iter, ← Iter.forIn_toArray, Slice.toArray]

theorem Internal.foldlM_iter [Monad m] [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [IteratorLoop α Id m]
{s : Slice γ} {init : δ} {f : δ → β → m δ} :
(Internal.iter s).foldM (init := init) f = s.foldlM (init := init) f :=
(rfl)

theorem foldlM_toList [Monad m] [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [IteratorLoop α Id m] [LawfulIteratorLoop α Id m]
[Finite α Id] [LawfulMonad m] {s : Slice γ} {init : δ} {f : δ → β → m δ} :
s.toList.foldlM (init := init) f = s.foldlM (init := init) f := by
simp [← Internal.foldlM_iter, ← Iter.foldlM_toList, Slice.toList]

theorem foldlM_toArray [Monad m] [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [IteratorLoop α Id m] [LawfulIteratorLoop α Id m]
[Finite α Id] [LawfulMonad m] {s : Slice γ} {init : δ} {f : δ → β → m δ} :
s.toArray.foldlM (init := init) f = s.foldlM (init := init) f := by
simp [← Internal.foldlM_iter, ← Iter.foldlM_toArray, Slice.toArray]

theorem Internal.foldl_iter [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [IteratorLoop α Id Id]
{s : Slice γ} {init : δ} {f : δ → β → δ} :
(Internal.iter s).fold (init := init) f = s.foldl (init := init) f :=
(rfl)

theorem foldl_toList [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id]
[Finite α Id] {s : Slice γ} {init : δ} {f : δ → β → δ} :
s.toList.foldl (init := init) f = s.foldl (init := init) f := by
simp [← Internal.foldl_iter, ← Iter.foldl_toList, Slice.toList]

theorem foldl_toArray [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id]
[Finite α Id] {s : Slice γ} {init : δ} {f : δ → β → δ} :
s.toArray.foldl (init := init) f = s.foldl (init := init) f := by
simp [← Internal.foldl_iter, ← Iter.foldl_toArray, Slice.toArray]

@[simp, grind =, suggest_for ListSlice.size_toArray ListSlice.size_toArray_eq_size]
public theorem size_toArray_eq_size [ToIterator (Slice γ) Id α β]
theorem size_toArray_eq_size [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [SliceSize γ] [LawfulSliceSize γ]
[Finite α Id]
{s : Slice γ} :
s.toArray.size = s.size := by
letI : IteratorLoop α Id Id := .defaultImplementation
rw [Internal.size_eq_length_internalIter, Internal.toArray_eq_toArray_internalIter, Iter.size_toArray_eq_length]
rw [Internal.size_eq_length_iter, Internal.toArray_eq_toArray_iter, Iter.size_toArray_eq_length]

@[simp, grind =, suggest_for ListSlice.length_toList ListSlice.length_toList_eq_size]
public theorem length_toList_eq_size [ToIterator (Slice γ) Id α β]
theorem length_toList_eq_size [ToIterator (Slice γ) Id α β]
[Iterator α Id β] {s : Slice γ}
[SliceSize γ] [LawfulSliceSize γ]
[Finite α Id] :
s.toList.length = s.size := by
letI : IteratorLoop α Id Id := .defaultImplementation
rw [Internal.size_eq_length_internalIter, Internal.toList_eq_toList_internalIter, Iter.length_toList_eq_length]
rw [Internal.size_eq_length_iter, Internal.toList_eq_toList_iter, Iter.length_toList_eq_length]

@[simp, grind =]
public theorem length_toListRev_eq_size [ToIterator (Slice γ) Id α β]
theorem length_toListRev_eq_size [ToIterator (Slice γ) Id α β]
[Iterator α Id β] {s : Slice γ}
[IteratorLoop α Id Id.{v}] [SliceSize γ] [LawfulSliceSize γ]
[Finite α Id]
[LawfulIteratorLoop α Id Id] :
s.toListRev.length = s.size := by
rw [Internal.size_eq_length_internalIter, Internal.toListRev_eq_toListRev_internalIter,
rw [Internal.size_eq_length_iter, Internal.toListRev_eq_toListRev_iter,
Iter.length_toListRev_eq_length]

public theorem foldlM_toList {m} [Monad m] [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [LawfulMonad m] [IteratorLoop α Id m] [LawfulIteratorLoop α Id m]
[Iterators.Finite α Id] {s : Slice γ} {f} :
s.toList.foldlM (init := init) f = s.foldlM (m := m) (init := init) f := by
simp [Internal.toList_eq_toList_internalIter, Iter.foldlM_toList, foldM_internalIter]

public theorem foldl_toList [ToIterator (Slice γ) Id α β]
[Iterator α Id β] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id]
[Iterators.Finite α Id] {s : Slice γ} :
s.toList.foldl (init := init) f = s.foldl (init := init) f := by
simp [Internal.toList_eq_toList_internalIter, Iter.foldl_toList, fold_internalIter]

end Std.Slice
Loading
Loading