1 (* Copyright (C) 2003-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 module UM = UriManager
33 module S = Set.Make (Int)
36 let predicate x = S.mem x s1 in
39 let get_rels_from_premise h t =
40 let rec aux d g = function
44 if i < d then g else fun a -> g (S.add (i - d + h + 1) a)
45 | C.Appl ss -> List.fold_left (aux d) g ss
48 | C.MutConstruct (_, _, _, ss)
50 let map g (_, t) = aux d g t in
51 List.fold_left map g ss
57 List.fold_left map g ss
58 | C.Cast (t1, t2) -> aux d (aux d g t2) t1
59 | C.Lambda (_, t1, t2)
60 | C.Prod (_, t1, t2) -> aux d (aux (succ d) g t2) t1
61 | C.LetIn (_, t1, ty, t2) ->
62 aux d (aux d (aux (succ d) g t2) ty) t1
63 | C.MutCase (_, _, t1, t2, ss) ->
64 aux d (aux d (List.fold_left (aux d) g ss) t2) t1
66 let k = List.length ss in
67 let map g (_, _, t1, t2) = aux d (aux (d + k) g t2) t1 in
68 List.fold_left map g ss
70 let k = List.length ss in
71 let map g (_, t1, t2) = aux d (aux (d + k) g t2) t1 in
72 List.fold_left map g ss
77 let get_mutinds_of_uri u t =
78 let rec aux g = function
82 | C.Appl ss -> List.fold_left aux g ss
84 | C.MutConstruct (_, _, _, ss)
86 let map g (_, t) = aux g t in
87 List.fold_left map g ss
88 | C.MutInd (uri, tyno, ss) ->
89 let map g (_, t) = aux g t in
90 let g = List.fold_left map g ss in
91 if UM.eq u uri then fun a -> g (S.add tyno a) else g
97 List.fold_left map g ss
98 | C.Cast (t1, t2) -> aux (aux g t2) t1
99 | C.Lambda (_, t1, t2)
100 | C.Prod (_, t1, t2) -> aux (aux g t2) t1
101 | C.LetIn (_, t1, ty, t2) -> aux (aux (aux g t2) ty) t1
102 | C.MutCase (_, _, t1, t2, ss) ->
103 aux (aux (List.fold_left aux g ss) t2) t1
105 let map g (_, _, t1, t2) = aux (aux g t2) t1 in
106 List.fold_left map g ss
108 let map g (_, t1, t2) = aux (aux g t2) t1 in
109 List.fold_left map g ss
114 let count_nodes ~meta n t =
115 let offset = if meta then 1 else 0 in
116 let rec aux n = function
117 | C.Implicit _ -> offset + n
121 List.fold_left aux (List.length ts - 1 + n) ts
123 | C.MutConstruct (_, _, _, ss)
124 | C.MutInd (_, _, ss)
126 let map n (_, t) = aux n t in
127 List.fold_left map (succ n) ss
133 List.fold_left map (n + offset) ss
134 | C.Cast (t1, t2) -> aux (aux (offset + n) t2) t1
135 | C.Lambda (_, t1, t2)
136 | C.Prod (_, t1, t2) -> aux (aux (succ n) t2) t1
137 | C.LetIn (_, t1, ty, t2) -> aux (aux (aux (offset + 1 + n) t2) ty) t1
138 | C.MutCase (_, _, t1, t2, ss) ->
139 aux (aux (List.fold_left aux (offset + 1 + n) ss) t2) t1
141 let map n (_, _, t1, t2) = aux (aux n t2) t1 in
142 List.fold_left map (2 + n) ss
144 let map n (_, t1, t2) = aux (aux n t2) t1 in
145 List.fold_left map (2 + n) ss