Debian Codegraph @

vernac/recLemmas.ml

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 Util
12 open Constr
13 open Declarations
14
15 module RelDecl = Context.Rel.Declaration
16
17 let find_mutually_recursive_statements sigma ctxs ccls =
18 let inds = List.map2 (fun ctx ccl ->
19 let (hyps,ccl) = EConstr.decompose_prod_decls sigma ccl in
20 let hyps = hyps @ ctx in
21 let whnf_hyp_hds = EConstr.map_rel_context_in_env
22 (fun env c -> fst (Reductionops.whd_all_stack env sigma c))
23 (Global.env()) hyps in
24 let ind_hyps =
25 List.flatten (List.map_i (fun i decl ->
26 let t = RelDecl.get_type decl in
27 match EConstr.kind sigma t with
28 | Ind ((kn,_ as ind),u) when
29 let mind = Global.lookup_mind kn in
30 mind.mind_finite <> Declarations.CoFinite ->
31 [ind,i]
32 | _ ->
33 []) 0 (List.rev (List.filter Context.Rel.Declaration.is_local_assum whnf_hyp_hds))) in
34 let ind_ccl =
35 let cclenv = EConstr.push_rel_context hyps (Global.env()) in
36 let whnf_ccl,_ = Reductionops.whd_all_stack cclenv sigma ccl in
37 match EConstr.kind sigma whnf_ccl with
38 | Ind ((kn,_ as ind),u) when (Global.lookup_mind kn).mind_finite == Declarations.CoFinite ->
39 [ind,0]
40 | _ ->
41 [] in
42 ind_hyps,ind_ccl) ctxs ccls in
43 let inds_hyps,ind_ccls = List.split inds in
44 let of_same_mutind ((kn,_),_) = function ((kn',_),_) -> Environ.QMutInd.equal (Global.env ()) kn kn' in
45 (* Check if all conclusions are coinductive in the same type *)
46 (* (degenerated cartesian product since there is at most one coind ccl) *)
47 let same_indccl =
48 List.cartesians_filter (fun hyp oks ->
49 if List.for_all (of_same_mutind hyp) oks
50 then Some (hyp::oks) else None) [] ind_ccls in
51 let common_same_indhyp =
52 List.cartesians_filter (fun hyp oks ->
53 if List.for_all (of_same_mutind hyp) oks
54 then Some (hyp::oks) else None) [] inds_hyps in
55 let possibly_cofix = not (List.is_empty same_indccl) in (* all conclusions are coinductive *)
56 let possible_fix_indices =
57 match common_same_indhyp with
58 | [] -> []
59 | _::_ ->
60 (* assume the largest indices as possible *)
61 List.map (List.map snd) inds_hyps in
62 if not possibly_cofix && List.is_empty possible_fix_indices then
63 CErrors.user_err Pp.(str
64 ("Cannot find common (mutual) inductive premises or coinductive" ^
65 " conclusions in the statements."));
66 Pretyping.{possibly_cofix; possible_fix_indices}