1 (* Copyright (C) 2002, 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/.
27 module DTI = DoubleTypeInference
28 module ET = EqualityTactics
30 module LO = LibraryObjects
31 module PEH = ProofEngineHelpers
32 module PESR = ProofEngineStructuralRules
33 module PET = ProofEngineTypes
34 module S = CicSubstitution
36 module TC = CicTypeChecker
38 (* FG: This should be replaced by T.try_tactic *)
39 let try_tactic ~tactic =
40 let try_tactic status =
41 try PET.apply_tactic tactic status with
42 | PET.Fail _ -> PET.apply_tactic T.id_tac status
44 PET.mk_tactic try_tactic
46 let rec lift_rewrite_tac ~context ~direction ~pattern equality =
47 let lift_rewrite_tac status =
48 let (proof, goal) = status in
49 let (_, metasenv, _, _, _) = proof in
50 let _, new_context, _ = CicUtil.lookup_meta goal metasenv in
51 let n = List.length new_context - List.length context in
52 let equality = if n > 0 then S.lift n equality else equality in
53 PET.apply_tactic (ET.rewrite_tac ~direction ~pattern equality []) status
55 PET.mk_tactic lift_rewrite_tac
58 let msg0 = lazy "Subst: not found in context"
59 let msg1 = lazy "Subst: not a simple equality"
60 let msg2 = lazy "Subst: recursive equation"
63 let hole = C.Implicit (Some `Hole) in
64 let subst_tac status =
65 let (proof, goal) = status in
66 let (_, metasenv, _, _, _) = proof in
67 let _, context, _ = CicUtil.lookup_meta goal metasenv in
68 let what = match PEH.get_rel context hyp with
70 | None -> raise (PET.Fail msg0)
72 let ty, _ = TC.type_of_aux' metasenv context what CicUniv.empty_ugraph in
73 let direction, i, t = match ty with
74 | (C.Appl [(C.MutInd (uri, 0, [])); _; C.Rel i; t])
75 when LO.is_eq_URI uri -> `LeftToRight, i, t
76 | (C.Appl [(C.MutInd (uri, 0, [])); _; t; C.Rel i])
77 when LO.is_eq_URI uri -> `RightToLeft, i, t
78 | _ -> raise (PET.Fail msg1)
81 let tactic = lift_rewrite_tac ~context ~direction ~pattern what in
84 let var = match PEH.get_name context i with
86 | None -> raise (PET.Fail msg0)
88 if DTI.does_not_occur i t then () else raise (PET.Fail msg2);
89 let map self = function
90 | Some (C.Name s, _) when s <> self ->
91 Some (rewrite (None, [(s, hole)], None))
94 let rew_hips = HEL.list_rev_map_filter (map hyp) context in
95 let rew_concl = rewrite (None, [], Some hole) in
96 let clear = PESR.clear ~hyps:[hyp; var] in
97 let tactics = List.rev_append (rew_concl :: rew_hips) [clear] in
98 PET.apply_tactic (T.seq ~tactics) status
100 PET.mk_tactic subst_tac
103 let subst hyp = try_tactic ~tactic:(subst_tac hyp) in
105 | Some (C.Name s, _) -> Some (subst s)
108 let subst_tac status =
109 let (proof, goal) = status in
110 let (_, metasenv, _, _, _) = proof in
111 let _, context, _ = CicUtil.lookup_meta goal metasenv in
112 let tactics = HEL.list_rev_map_filter map context in
113 PET.apply_tactic (T.seq ~tactics) status
115 PET.mk_tactic subst_tac