Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 00394b7

Browse files
committed
feat(tactic/simps): implement prefix names (#7596)
* You can now write `initialize_simps_projections equiv (to_fun → coe as_prefix)` to add the projection name as a prefix to the simp lemmas: if you then write `@[simps coe] def foo ...` you get a lemma named `coe_foo`. * Remove the `short_name` option from `simps_cfg`. This was unused and not that useful. * Refactor some tuples used in the functions into structures. * Implements one item of #5489.
1 parent 1f566bc commit 00394b7

File tree

5 files changed

+243
-125
lines changed

5 files changed

+243
-125
lines changed

src/data/list/defs.lean

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ namespace list
1717

1818
open function nat native (rb_map mk_rb_map rb_map.of_list)
1919
universes u v w x
20-
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
21-
20+
variables {α β γ δ ε ζ : Type*}
2221
instance [decidable_eq α] : has_sdiff (list α) :=
2322
⟨ list.diff ⟩
2423

@@ -936,4 +935,28 @@ Asynchronous version of `list.map`.
936935
meta def map_async_chunked {α β} (f : α → β) (xs : list α) (chunk_size := 1024) : list β :=
937936
((xs.to_chunks chunk_size).map (λ xs, task.delay (λ _, list.map f xs))).bind task.get
938937

938+
/-!
939+
We add some n-ary versions of `list.zip_with` for functions with more than two arguments.
940+
These can also be written in terms of `list.zip` or `list.zip_with`.
941+
For example, `zip_with3 f xs ys zs` could also be written as
942+
`zip_with id (zip_with f xs ys) zs`
943+
or as
944+
`(zip xs $ zip ys zs).map $ λ ⟨x, y, z⟩, f x y z`.
945+
-/
946+
947+
/-- Ternary version of `list.zip_with`. -/
948+
def zip_with3 (f : α → β → γ → δ) : list α → list β → list γ → list δ
949+
| (x::xs) (y::ys) (z::zs) := f x y z :: zip_with3 xs ys zs
950+
| _ _ _ := []
951+
952+
/-- Quaternary version of `list.zip_with`. -/
953+
def zip_with4 (f : α → β → γ → δ → ε) : list α → list β → list γ → list δ → list ε
954+
| (x::xs) (y::ys) (z::zs) (u::us) := f x y z u :: zip_with4 xs ys zs us
955+
| _ _ _ _ := []
956+
957+
/-- Quinary version of `list.zip_with`. -/
958+
def zip_with5 (f : α → β → γ → δ → ε → ζ) : list α → list β → list γ → list δ → list ε → list ζ
959+
| (x::xs) (y::ys) (z::zs) (u::us) (v::vs) := f x y z u v :: zip_with5 xs ys zs us vs
960+
| _ _ _ _ _ := []
961+
939962
end list

src/meta/expr.lean

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,22 @@ meta def sanitize_name : name → name
9595
| (name.mk_string s p) := name.mk_string s $ sanitize_name p
9696
| (name.mk_numeral s p) := name.mk_string sformat!"n{s}" $ sanitize_name p
9797

98-
/-- Append a string to the last component of a name -/
98+
/-- Append a string to the last component of a name. -/
9999
def append_suffix : name → string → name
100100
| (mk_string s n) s' := mk_string (s ++ s') n
101101
| n _ := n
102102

103+
/-- Update the last component of a name. -/
104+
def update_last (f : string → string) : name → name
105+
| (mk_string s n) := mk_string (f s) n
106+
| n := n
107+
108+
/-- `append_to_last nm s is_prefix` adds `s` to the last component of `nm`,
109+
either as prefix or as suffix (specified by `is_prefix`), separated by `_`.
110+
Used by `simps_add_projections`. -/
111+
def append_to_last (nm : name) (s : string) (is_prefix : bool) : name :=
112+
nm.update_last $ λ s', if is_prefix then s ++ "_" ++ s' else s' ++ "_" ++ s
113+
103114
/-- The first component of a name, turning a number to a string -/
104115
meta def head : name → string
105116
| (mk_string s anonymous) := s

src/tactic/reserved_notation.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ reserve prefix `#where`:max
3939

4040
-- used in `tactic/simps.lean`
4141
reserve notation `initialize_simps_projections`
42+
reserve notation `as_prefix`
4243

4344
-- used in `tactic/lift.lean`
4445
reserve notation `to`

0 commit comments

Comments
 (0)