-
Notifications
You must be signed in to change notification settings - Fork 9
/
abstraction.ml
36 lines (33 loc) · 1 KB
/
abstraction.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(*
* Abstraction specific to ornamental search
*)
open Constr
open Debruijn
open Indexing
open Names
open Apputils
open Reducers
(*
* Given an application and the index of the argument, abstract by the argument
*)
let abstract_arg env sigma i typ =
let arg = get_arg i typ in
let sigma, arg_typ = reduce_type env sigma arg in
let args = reindex i (mkRel 1) (shift_all (unfold_args typ)) in
sigma, mkLambda (Anonymous, arg_typ, mkAppl (first_fun typ, args))
(* Replace all occurrences of the first term in the second term with Rel 1,
* lifting de Bruijn indices as needed. The notion of term equality is modulo
* alpha, casts, application grouping, and universes.
*)
let abstract_subterm sub term =
let rec surgery (nb, sub) term =
match eq_constr_head sub term with
| Some args ->
mkApp (mkRel (nb + 1), args)
| None ->
Constr.map_with_binders
(fun (nb, sub) -> nb + 1, shift sub)
surgery
(nb, sub)
term
in surgery (0, shift sub) (shift term)