Debian Codegraph @

kernel/term.mli

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Names
12 open Constr
13
14 (** {5 Derived constructors} *)
15
16 (** non-dependent product [t1 -> t2], an alias for
17 [forall (_:t1), t2]. Beware [t_2] is NOT lifted.
18 Eg: in context [A:Prop], [A->A] is built by [(mkArrow (mkRel 1) (mkRel 2))]
19 *)
20 val mkArrow : types -> Sorts.relevance -> types -> constr
21
22 val mkArrowR : types -> types -> constr
23 (** For an always-relevant domain *)
24
25 (** Named version of the functions from [Term]. *)
26 val mkNamedLambda : Id.t binder_annot -> types -> constr -> constr
27 val mkNamedLetIn : Id.t binder_annot -> constr -> types -> constr -> constr
28 val mkNamedProd : Id.t binder_annot -> types -> types -> types
29
30 (** Constructs either [(x:t)c] or [[x=b:t]c] *)
31 val mkProd_or_LetIn : Constr.rel_declaration -> types -> types
32 val mkProd_wo_LetIn : Constr.rel_declaration -> types -> types
33 val mkNamedProd_or_LetIn : Constr.named_declaration -> types -> types
34 val mkNamedProd_wo_LetIn : Constr.named_declaration -> types -> types
35
36 (** Constructs either [[x:t]c] or [[x=b:t]c] *)
37 val mkLambda_or_LetIn : Constr.rel_declaration -> constr -> constr
38 val mkNamedLambda_or_LetIn : Constr.named_declaration -> constr -> constr
39
40 (** {5 Other term constructors. } *)
41
42 (** [applist (f,args)] and its variants work as [mkApp] *)
43
44 val applist : constr * constr list -> constr
45 val applistc : constr -> constr list -> constr
46 val appvect : constr * constr array -> constr
47 val appvectc : constr -> constr array -> constr
48
49 (** [prodn n l b] = [forall (x_1:T_1)...(x_n:T_n), b]
50 where [l] is [(x_n,T_n)...(x_1,T_1)...]. *)
51 val prodn : int -> (Name.t binder_annot * constr) list -> constr -> constr
52
53 (** [compose_prod l b]
54 @return [forall (x_1:T_1)...(x_n:T_n), b]
55 where [l] is [(x_n,T_n)...(x_1,T_1)].
56 Inverse of [decompose_prod]. *)
57 val compose_prod : (Name.t binder_annot * constr) list -> constr -> constr
58
59 (** [lamn n l b]
60 @return [fun (x_1:T_1)...(x_n:T_n) => b]
61 where [l] is [(x_n,T_n)...(x_1,T_1)...]. *)
62 val lamn : int -> (Name.t binder_annot * constr) list -> constr -> constr
63
64 (** [compose_lam l b]
65 @return [fun (x_1:T_1)...(x_n:T_n) => b]
66 where [l] is [(x_n,T_n)...(x_1,T_1)].
67 Inverse of [it_destLam] *)
68 val compose_lam : (Name.t binder_annot * constr) list -> constr -> constr
69
70 (** [to_lambda n l]
71 @return [fun (x_1:T_1)...(x_n:T_n) => T]
72 where [l] is [forall (x_1:T_1)...(x_n:T_n), T] *)
73 val to_lambda : int -> constr -> constr
74
75 (** [to_prod n l]
76 @return [forall (x_1:T_1)...(x_n:T_n), T]
77 where [l] is [fun (x_1:T_1)...(x_n:T_n) => T] *)
78 val to_prod : int -> constr -> constr
79
80 val it_mkLambda_or_LetIn : constr -> Constr.rel_context -> constr
81 val it_mkProd_wo_LetIn : types -> Constr.rel_context -> types
82 val it_mkProd_or_LetIn : types -> Constr.rel_context -> types
83
84 (** In [lambda_applist c args], [c] is supposed to have the form
85 [λΓ.c] with [Γ] without let-in; it returns [c] with the variables
86 of [Γ] instantiated by [args]. *)
87 val lambda_applist : constr -> constr list -> constr
88 val lambda_appvect : constr -> constr array -> constr
89
90 (** In [lambda_applist_decls n c args], [c] is supposed to have the
91 form [λΓ.c] with [Γ] of length [n] and possibly with let-ins; it
92 returns [c] with the assumptions of [Γ] instantiated by [args] and
93 the local definitions of [Γ] expanded. *)
94 val lambda_applist_decls : int -> constr -> constr list -> constr
95 val lambda_appvect_decls : int -> constr -> constr array -> constr
96
97 (** pseudo-reduction rule *)
98
99 (** [prod_appvect] [forall (x1:B1;...;xn:Bn), B] [a1...an]
100 @return [B[a1...an]] *)
101 val prod_appvect : types -> constr array -> types
102 val prod_applist : types -> constr list -> types
103
104 (** In [prod_appvect_decls n c args], [c] is supposed to have the
105 form [∀Γ.c] with [Γ] of length [n] and possibly with let-ins; it
106 returns [c] with the assumptions of [Γ] instantiated by [args] and
107 the local definitions of [Γ] expanded. *)
108 val prod_appvect_decls : int -> types -> constr array -> types
109 val prod_applist_decls : int -> types -> constr list -> types
110
111 (** {5 Other term destructors. } *)
112
113 (** Transforms a product term {% $ %}(x_1:T_1)..(x_n:T_n)T{% $ %} into the pair
114 {% $ %}([(x_n,T_n);...;(x_1,T_1)],T){% $ %}, where {% $ %}T{% $ %} is not a product. *)
115 val decompose_prod : constr -> (Name.t binder_annot * constr) list * constr
116
117 (** Transforms a lambda term {% $ %}[x_1:T_1]..[x_n:T_n]T{% $ %} into the pair
118 {% $ %}([(x_n,T_n);...;(x_1,T_1)],T){% $ %}, where {% $ %}T{% $ %} is not a lambda. *)
119 val decompose_lambda : constr -> (Name.t binder_annot * constr) list * constr
120
121 (** Given a positive integer n, decompose a product term
122 {% $ %}(x_1:T_1)..(x_n:T_n)T{% $ %}
123 into the pair {% $ %}([(xn,Tn);...;(x1,T1)],T){% $ %}.
124 Raise a user error if not enough products. *)
125 val decompose_prod_n : int -> constr -> (Name.t binder_annot * constr) list * constr
126
127 (** Given a positive integer {% $ %}n{% $ %}, decompose a lambda term
128 {% $ %}[x_1:T_1]..[x_n:T_n]T{% $ %} into the pair {% $ %}([(x_n,T_n);...;(x_1,T_1)],T){% $ %}.
129 Raise a user error if not enough lambdas. *)
130 val decompose_lambda_n : int -> constr -> (Name.t binder_annot * constr) list * constr
131
132 (** Extract the premisses and the conclusion of a term of the form
133 "(xi:Ti) ... (xj:=cj:Tj) ..., T" where T is not a product nor a let *)
134 val decompose_prod_decls : types -> Constr.rel_context * types
135
136 (** Idem with lambda's and let's *)
137 val decompose_lambda_decls : constr -> Constr.rel_context * constr
138
139 (** Idem but extract the first [n] premisses, counting let-ins. *)
140 val decompose_prod_n_decls : int -> types -> Constr.rel_context * types
141
142 (** Idem but extracting simultaneously the first [n] premisses, counting let-ins, in a term and its type. *)
143 val decompose_lambda_prod_n_decls : int -> constr -> types -> Constr.rel_context * constr * types
144
145 (** Idem for lambdas, including let-ins but _not_ counting them;
146 This is typically the function to use to extract the context of a Fix
147 up to and including the decreasing argument, counting as many lambda's
148 as given by the decreasing index + 1 *)
149 val decompose_lambda_n_assum : int -> constr -> Constr.rel_context * constr
150
151 (** Idem, counting let-ins *)
152 val decompose_lambda_n_decls : int -> constr -> Constr.rel_context * constr
153
154 (** Return the premisses/parameters of a type/term (let-in included) *)
155 val prod_decls : types -> Constr.rel_context
156 val lambda_decls : constr -> Constr.rel_context
157
158 (** Return the first n-th premisses/parameters of a type (let included and counted) *)
159 val prod_n_decls : int -> types -> Constr.rel_context
160
161 (** Return the first n-th premisses/parameters of a term (let included but not counted) *)
162 val lam_n_assum : int -> constr -> Constr.rel_context
163
164 (** Remove the premisses/parameters of a type/term *)
165 val strip_prod : types -> types
166 val strip_lam : constr -> constr
167
168 (** Remove the first n-th premisses/parameters of a type/term *)
169 val strip_prod_n : int -> types -> types
170 val strip_lam_n : int -> constr -> constr
171
172 (** Remove the premisses/parameters of a type/term (including let-in) *)
173 val strip_prod_decls : types -> types
174 val strip_lambda_decls : constr -> constr
175
176 (** {5 ... } *)
177 (** An "arity" is a term of the form [[x1:T1]...[xn:Tn]s] with [s] a sort.
178 Such a term can canonically be seen as the pair of a context of types
179 and of a sort *)
180
181 type arity = Constr.rel_context * Sorts.t
182
183 (** Build an "arity" from its canonical form *)
184 val mkArity : arity -> types
185
186 (** Destruct an "arity" into its canonical form *)
187 val destArity : types -> arity
188
189 (** Tell if a term has the form of an arity *)
190 val isArity : types -> bool