-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove cross-cutting dep (#729)
... Data.Array.Lemmas -> Data.Fin.Lemmas
- Loading branch information
Showing
7 changed files
with
96 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/- | ||
Copyright (c) 2021 Mario Carneiro. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Mario Carneiro, Gabriel Ebner | ||
-/ | ||
|
||
/-! # Bootstrapping properties of Arrays -/ | ||
|
||
namespace Array | ||
|
||
@[simp] theorem size_ofFn_go {n} (f : Fin n → α) (i acc) : | ||
(ofFn.go f i acc).size = acc.size + (n - i) := by | ||
if hin : i < n then | ||
unfold ofFn.go | ||
have : 1 + (n - (i + 1)) = n - i := | ||
Nat.sub_sub .. ▸ Nat.add_sub_cancel' (Nat.le_sub_of_add_le (Nat.add_comm .. ▸ hin)) | ||
rw [dif_pos hin, size_ofFn_go f (i+1), size_push, Nat.add_assoc, this] | ||
else | ||
have : n - i = 0 := Nat.sub_eq_zero_of_le (Nat.le_of_not_lt hin) | ||
unfold ofFn.go | ||
simp [hin, this] | ||
termination_by n - i | ||
|
||
@[simp] theorem size_ofFn (f : Fin n → α) : (ofFn f).size = n := by simp [ofFn] | ||
|
||
theorem getElem_ofFn_go (f : Fin n → α) (i) {acc k} | ||
(hki : k < n) (hin : i ≤ n) (hi : i = acc.size) | ||
(hacc : ∀ j, ∀ hj : j < acc.size, acc[j] = f ⟨j, Nat.lt_of_lt_of_le hj (hi ▸ hin)⟩) : | ||
haveI : acc.size + (n - acc.size) = n := Nat.add_sub_cancel' (hi ▸ hin) | ||
(ofFn.go f i acc)[k]'(by simp [*]) = f ⟨k, hki⟩ := by | ||
unfold ofFn.go | ||
if hin : i < n then | ||
have : 1 + (n - (i + 1)) = n - i := | ||
Nat.sub_sub .. ▸ Nat.add_sub_cancel' (Nat.le_sub_of_add_le (Nat.add_comm .. ▸ hin)) | ||
simp only [dif_pos hin] | ||
rw [getElem_ofFn_go f (i+1) _ hin (by simp [*]) (fun j hj => ?hacc)] | ||
cases (Nat.lt_or_eq_of_le <| Nat.le_of_lt_succ (by simpa using hj)) with | ||
| inl hj => simp [get_push, hj, hacc j hj] | ||
| inr hj => simp [get_push, *] | ||
else | ||
simp [hin, hacc k (Nat.lt_of_lt_of_le hki (Nat.le_of_not_lt (hi ▸ hin)))] | ||
termination_by n - i | ||
|
||
@[simp] theorem getElem_ofFn (f : Fin n → α) (i : Nat) (h) : | ||
(ofFn f)[i] = f ⟨i, size_ofFn f ▸ h⟩ := | ||
getElem_ofFn_go _ _ _ (by simp) (by simp) nofun |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import Std.Data.List.Basic | ||
import Std.Data.List.Count | ||
import Std.Data.List.Init.Attach | ||
import Std.Data.List.Init.Lemmas | ||
import Std.Data.List.Lemmas | ||
import Std.Data.List.Pairwise | ||
import Std.Data.List.Perm |
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,39 @@ | ||
/- | ||
Copyright (c) 2014 Parikshit Khanna. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro | ||
-/ | ||
|
||
/-! # Bootstrapping properties of Lists -/ | ||
|
||
namespace List | ||
|
||
@[ext] theorem ext : ∀ {l₁ l₂ : List α}, (∀ n, l₁.get? n = l₂.get? n) → l₁ = l₂ | ||
| [], [], _ => rfl | ||
| a :: l₁, [], h => nomatch h 0 | ||
| [], a' :: l₂, h => nomatch h 0 | ||
| a :: l₁, a' :: l₂, h => by | ||
have h0 : some a = some a' := h 0 | ||
injection h0 with aa; simp only [aa, ext fun n => h (n+1)] | ||
|
||
theorem ext_get {l₁ l₂ : List α} (hl : length l₁ = length l₂) | ||
(h : ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩) : l₁ = l₂ := | ||
ext fun n => | ||
if h₁ : n < length l₁ then by | ||
rw [get?_eq_get, get?_eq_get, h n h₁ (by rwa [← hl])] | ||
else by | ||
have h₁ := Nat.le_of_not_lt h₁ | ||
rw [get?_len_le h₁, get?_len_le]; rwa [← hl] | ||
|
||
@[simp] theorem get_map (f : α → β) {l n} : get (map f l) n = f (get l ⟨n, length_map l f ▸ n.2⟩) := | ||
Option.some.inj <| by rw [← get?_eq_get, get?_map, get?_eq_get]; rfl | ||
|
||
/-! ### foldl / foldr -/ | ||
|
||
theorem foldl_map (f : β₁ → β₂) (g : α → β₂ → α) (l : List β₁) (init : α) : | ||
(l.map f).foldl g init = l.foldl (fun x y => g x (f y)) init := by | ||
induction l generalizing init <;> simp [*] | ||
|
||
theorem foldr_map (f : α₁ → α₂) (g : α₂ → β → β) (l : List α₁) (init : β) : | ||
(l.map f).foldr g init = l.foldr (fun x y => g (f x) y) init := by | ||
induction l generalizing init <;> simp [*] |
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