Skip to content

Commit 2d7f266

Browse files
committed
add simp attribute
1 parent 5da271c commit 2d7f266

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lean/extra/attributes.lean

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import lean.extra.attrs.dummy
22
import lean.extra.attrs.tag
33
import lean.extra.attrs.parametric
4+
import lean.extra.attrs.simp
45
/-
56
# Attributes
67
@@ -58,6 +59,26 @@ We'll see you at [`./attrs/parametric.lean`](./attrs/dummy.lean).
5859
@[myParam 20 important] def h2 (x : Nat) := 2*x + 1
5960

6061

62+
/-
63+
## Using `simpAttr`
64+
-/
65+
66+
@[my_simp] theorem f_eq : f x = x + 2 := rfl
67+
@[my_simp] theorem g_eq : g x = x + 1 := rfl
68+
69+
example : f x + g x = 2*x + 3 := by
70+
simp_arith -- does not appy f_eq and g_eq
71+
simp_arith [f, g]
72+
73+
example : f x + g x = 2*x + 3 := by
74+
simp_arith [my_simp]
75+
76+
example : f x = id (x + 2) := by
77+
simp
78+
simp [my_simp]
79+
80+
81+
6182
/-
6283
## Using `dummy_attr`
6384

lean/extra/attrs/around.lean

+9
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ initialize renameExtension : SimplePersistentEnvExtension (Name × Name) RenameM
3434
name := `renameMapExtension
3535
addEntryFn := RenameMap.insertPair
3636
addImportedFn := fun es => mkStateFromImportedEntries (RenameMap.insertPair) {} es
37+
initial := sorry
3738
}
3839

40+
/-
41+
The key is Name × Name, and the value is RenameMap.
42+
The entires are written into the `olean` files.
43+
The functions `addEntryFn` tells us how to compute the values from the keys.
44+
So the values are "just" a caching mechanism for the keys, where the keys tell us
45+
what data is to be stored.
46+
-/
47+
3948
def findRename? (env : Environment) : Name → Option Name :=
4049
(renameExtension.getState env).find?
4150

lean/extra/attrs/simp.lean

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
register_simp_attr fooSimp "my own foo simp attribute"
2+
3+

0 commit comments

Comments
 (0)