Skip to content

Commit 7b8230d

Browse files
committed
example: reduction surgery
1 parent bafd106 commit 7b8230d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ all the dependencies installed first (see [coq-elpi.opam](coq-elpi.opam)).
128128
subterms out (one way to skin the cat, there are many)
129129
- [record import](examples/example_import_projections.v) gives short names
130130
to record projections applied to the given record instance.
131+
- [reduction surgery](examples/example_reduction_surgery.v) implements
132+
a tactic fine tuning cbv with a list of allowed unfoldings taken from a
133+
module.
131134

132135
### Applications written in Coq-Elpi
133136

_CoqProject.examples

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ examples/example_record_to_sigma.v
2020
examples/example_fuzzer.v
2121
examples/example_generalize.v
2222
examples/example_import_projections.v
23+
examples/example_reduction_surgery.v
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(**
2+
This file mocks up a reduction tactic unfolding only constants
3+
from a given module.
4+
*)
5+
6+
From elpi Require Import elpi.
7+
8+
Elpi Tactic reduce.
9+
Elpi Accumulate lp:{{
10+
11+
pred gref->redflag i:gref, o:coq.redflag.
12+
gref->redflag (const C) (coq.redflags.const C).
13+
14+
solve (goal _ _ Ty _ [str M] as G) GS :-
15+
coq.locate-module M MP,
16+
coq.env.module MP GREFS,
17+
std.filter GREFS (x\x = const _) CONSTANTS,
18+
std.map CONSTANTS (gr\r\ coq.env.transitive-dependencies gr _ r) DEPS,
19+
std.fold DEPS {coq.gref.set.empty} coq.gref.set.union ALLDEPS,
20+
std.append CONSTANTS {coq.gref.set.elements ALLDEPS} All,
21+
std.map-filter All gref->redflag DELTAFLAGS,
22+
coq.redflags.add coq.redflags.nored
23+
[ coq.redflags.beta, coq.redflags.fix, coq.redflags.match | DELTAFLAGS ]
24+
F,
25+
@redflags! F => coq.reduction.cbv.norm Ty Ty1,
26+
refine {{ _ : lp:Ty1 }} G GS. % to leave a vmcast one needs to call ltac1
27+
28+
}}.
29+
Elpi Typecheck.
30+
31+
32+
Module ToRed.
33+
Definition x := 1.
34+
Definition y := 1.
35+
Definition alias := plus.
36+
End ToRed.
37+
38+
Goal ToRed.x + ToRed.y = let z := 1 in S z.
39+
elpi reduce "ToRed".
40+
match goal with |- 2 = let z := 1 in S z => trivial end.
41+
Show Proof.
42+
Abort.

0 commit comments

Comments
 (0)