X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fmatita%2FmatitaEngine.ml;h=522a5157053161e990ebdef8172cef7070e2b5a7;hb=fb53caa837dad54352753c100094027dd8e45334;hp=2ac69a57502a31b0487f89b39caec8ac46921355;hpb=358cefe50cccd4cb7d8e2a9cecb7efcb5780b8a3;p=helm.git diff --git a/helm/matita/matitaEngine.ml b/helm/matita/matitaEngine.ml index 2ac69a575..522a51570 100644 --- a/helm/matita/matitaEngine.ml +++ b/helm/matita/matitaEngine.ml @@ -30,8 +30,10 @@ let tactic_of_ast = function | TacticAst.Reflexivity _ -> Tactics.reflexivity | TacticAst.Assumption _ -> Tactics.assumption | TacticAst.Contradiction _ -> Tactics.contradiction + | TacticAst.Discriminate (_,term) -> Tactics.discriminate term | TacticAst.Exists _ -> Tactics.exists | TacticAst.Fourier _ -> Tactics.fourier + | TacticAst.Generalize (_,term,pat) -> Tactics.generalize term pat | TacticAst.Goal (_, n) -> Tactics.set_goal n | TacticAst.Left _ -> Tactics.left | TacticAst.Right _ -> Tactics.right @@ -49,81 +51,37 @@ let tactic_of_ast = function Tactics.elim_intros term | TacticAst.ElimType (_, term) -> Tactics.elim_type term | TacticAst.Replace (_, what, with_what) -> Tactics.replace ~what ~with_what - | TacticAst.Auto (_,num) -> - AutoTactic.auto_tac ~num (MatitaDb.instance ()) + | TacticAst.Auto (_,depth) -> +(* AutoTactic.auto_tac ~num (MatitaDb.instance ()) *) + AutoTactic.auto_tac_new ?depth ~dbd:(MatitaDb.instance ()) () | TacticAst.Change (_, what, with_what, _) -> Tactics.change ~what ~with_what (* (* TODO Zack a lot more of tactics to be implemented here ... *) | TacticAst.Change_pattern of 'term pattern * 'term * 'ident option | TacticAst.Change of 'term * 'term * 'ident option | TacticAst.Decompose of 'ident * 'ident list - | TacticAst.Discriminate of 'ident | TacticAst.Fold of reduction_kind * 'term | TacticAst.Injection of 'ident | TacticAst.Replace_pattern of 'term pattern * 'term *) | TacticAst.LetIn (loc,term,name) -> Tactics.letin term ~mk_fresh_name_callback:(namer_of [name]) - | TacticAst.ReduceAt (_,reduction_kind,ident,path) -> - ProofEngineTypes.mk_tactic - (fun (((_,metasenv,_,_),goal) as status) -> - let metano,context,ty = CicUtil.lookup_meta goal metasenv in - let where, also_in_hypotheses = - if ident = "goal" then - ty, false - else - let hyp = - try - List.find (function - | Some (Cic.Name name,entry) when name = ident -> true - | _ -> false) - context - with - Not_found -> - raise (ProofEngineTypes.Fail - (ident ^ " is not an hypothesis")) - in - (match hyp with - | Some (_, Cic.Decl term) -> term - | Some (_, Cic.Def (term,ty)) -> term - | None -> assert false),true - in - let pointers = CicUtil.select ~term:where ~context:path in - (match reduction_kind with - | `Normalize -> - ProofEngineTypes.apply_tactic - (Tactics.normalize ~also_in_hypotheses ~terms:(Some pointers)) - status - | `Reduce -> - ProofEngineTypes.apply_tactic - (Tactics.reduce ~also_in_hypotheses ~terms:(Some pointers)) - status - | `Simpl -> - ProofEngineTypes.apply_tactic - (Tactics.simpl ~also_in_hypotheses ~terms:(Some pointers)) - status - | `Whd -> - ProofEngineTypes.apply_tactic - (Tactics.whd ~also_in_hypotheses ~terms:(Some pointers)) - status)) - | TacticAst.Reduce (_,reduction_kind,opts) -> - let terms, also_in_hypotheses = - match opts with - | Some (l,`Goal) -> Some l, false - | Some (l,`Everywhere) -> Some l, true - | None -> None, false - in + | TacticAst.Reduce (_, reduction_kind, pattern) -> (match reduction_kind with - | `Normalize -> Tactics.normalize ~also_in_hypotheses ~terms - | `Reduce -> Tactics.reduce ~also_in_hypotheses ~terms - | `Simpl -> Tactics.simpl ~also_in_hypotheses ~terms - | `Whd -> Tactics.whd ~also_in_hypotheses ~terms) - | TacticAst.Rewrite (_,dir,t,ident) -> + | `Normalize -> Tactics.normalize ~pattern + | `Reduce -> Tactics.reduce ~pattern + | `Simpl -> Tactics.simpl ~pattern + | `Whd -> Tactics.whd ~pattern) + | TacticAst.Rewrite (_, dir, t, pattern) -> if dir = `Left then - EqualityTactics.rewrite_tac ~term:t + EqualityTactics.rewrite_tac ~where:pattern ~term:t () else - EqualityTactics.rewrite_back_tac ~term:t - | _ -> assert false + EqualityTactics.rewrite_back_tac ~where:pattern ~term:t () + | TacticAst.FwdSimpl (_, term) -> + Tactics.fwd_simpl ~term ~dbd:(MatitaDb.instance ()) + | TacticAst.LApply (_, term) -> + let f (name, term) = Cic.Name name, term in + Tactics.lapply term let eval_tactical status tac = let apply_tactic tactic = @@ -206,11 +164,11 @@ let eval_coercion status coercion = let context = [] in let src_uri = let ty_src = CicReduction.whd context ty_src in - UriManager.uri_of_string (CicUtil.uri_of_term ty_src) + CicUtil.uri_of_term ty_src in let tgt_uri = let ty_tgt = CicReduction.whd context ty_tgt in - UriManager.uri_of_string (CicUtil.uri_of_term ty_tgt) + CicUtil.uri_of_term ty_tgt in let new_coercions = (* also adds them to the Db *) @@ -230,8 +188,8 @@ let generate_elimination_principles uri status = List.fold_left (fun status sort -> elim sort status) status [ Cic.Prop; Cic.Set; (Cic.Type (CicUniv.fresh ())) ] -let generate_projections uri status = - let projections = CicRecord.projections_of uri in +let generate_projections uri fields status = + let projections = CicRecord.projections_of uri fields in List.fold_left (fun status (uri, name, bo) -> try @@ -282,7 +240,7 @@ let eval_command status cmd = {status with aliases = DisambiguateTypes.Environment.add (DisambiguateTypes.Id id) - ("boh?",(fun _ _ _ -> CicUtil.term_of_uri uri)) + ("boh?",(fun _ _ _ -> CicUtil.term_of_uri (UriManager.uri_of_string uri))) status.aliases } | TacticAst.Symbol_alias (symb, instance, desc) -> {status with aliases = @@ -323,12 +281,17 @@ let eval_command status cmd = let status = MatitaSync.add_obj uri obj status in match obj with Cic.Constant _ -> status - | Cic.InductiveDefinition (_,_,_,attrs) - when List.mem (`Class `Record) attrs -> + | Cic.InductiveDefinition (_,_,_,attrs) -> let status = generate_elimination_principles uri status in - generate_projections uri status - | Cic.InductiveDefinition (_,_,_,_) -> - generate_elimination_principles uri status + let rec get_record_attrs = + function + [] -> None + | (`Class (`Record fields))::_ -> Some fields + | _::tl -> get_record_attrs tl + in + (match get_record_attrs attrs with + None -> status (* not a record *) + | Some fields -> generate_projections uri fields status) | Cic.CurrentProof _ | Cic.Variable _ -> assert false @@ -402,10 +365,14 @@ let disambiguate_obj status obj = in status, cic -let disambiguate_closedtypes status terms = - let term = CicAst.pack terms in - let status, term = disambiguate_term status term in - status, CicUtil.unpack term +let disambiguate_pattern aliases (hyp_paths ,goal_path) = + let interp path = Disambiguate.interpretate_path [] aliases path in + let goal_path = + match goal_path with + | None -> None + | Some path -> Some (interp path) in + let hyp_paths = List.map (fun (name, path) -> name, interp path) hyp_paths in + (hyp_paths ,goal_path) let disambiguate_tactic status = function | TacticAst.Transitivity (loc, term) -> @@ -437,43 +404,37 @@ let disambiguate_tactic status = function let status, cic1 = disambiguate_term status what in let status, cic2 = disambiguate_term status with_what in status, TacticAst.Replace (loc, cic1, cic2) - | TacticAst.Change (loc, what, with_what, ident) -> + | TacticAst.Change (loc, what, with_what, pattern) -> let status, cic1 = disambiguate_term status what in let status, cic2 = disambiguate_term status with_what in - status, TacticAst.Change (loc, cic1, cic2, ident) + let pattern = disambiguate_pattern status.aliases pattern in + status, TacticAst.Change (loc, cic1, cic2, pattern) + | TacticAst.Generalize (loc,term,pattern) -> + let status,term = disambiguate_term status term in + let pattern = disambiguate_pattern status.aliases pattern in + status, TacticAst.Generalize(loc,term,pattern) + | TacticAst.Discriminate (loc,term) -> + let status,term = disambiguate_term status term in + status, TacticAst.Discriminate(loc,term) (* (* TODO Zack a lot more of tactics to be implemented here ... *) | TacticAst.Change_pattern of 'term pattern * 'term * 'ident option | TacticAst.Change of 'term * 'term * 'ident option | TacticAst.Decompose of 'ident * 'ident list - | TacticAst.Discriminate of 'ident | TacticAst.Fold of reduction_kind * 'term | TacticAst.Injection of 'ident | TacticAst.Replace_pattern of 'term pattern * 'term *) - | TacticAst.LetIn (loc,term,name) -> + | TacticAst.LetIn (loc, term, name) -> let status, term = disambiguate_term status term in status, TacticAst.LetIn (loc,term,name) - | TacticAst.ReduceAt (loc, reduction_kind, ident, path) -> - let path = Disambiguate.interpretate_path [] status.aliases path in - status, TacticAst.ReduceAt(loc, reduction_kind, ident, path) - | TacticAst.Reduce (loc, reduction_kind, opts) -> - let status, opts = - match opts with - | None -> status, None - | Some (l,pat) -> - let status, l = - List.fold_right (fun t (status,acc) -> - let status',t' = disambiguate_term status t in - status', t'::acc) - l (status,[]) - in - status, Some (l, pat) - in - status, TacticAst.Reduce (loc, reduction_kind, opts) - | TacticAst.Rewrite (loc,dir,t,ident) -> + | TacticAst.Reduce (loc, reduction_kind, pattern) -> + let pattern = disambiguate_pattern status.aliases pattern in + status, TacticAst.Reduce(loc, reduction_kind, pattern) + | TacticAst.Rewrite (loc, dir, t, pattern) -> let status, term = disambiguate_term status t in - status, TacticAst.Rewrite (loc,dir,term,ident) + let pattern = disambiguate_pattern status.aliases pattern in + status, TacticAst.Rewrite (loc, dir, term, pattern) | TacticAst.Intros (loc, num, names) -> status, TacticAst.Intros (loc, num, names) | TacticAst.Auto (loc,num) -> status, TacticAst.Auto (loc,num) @@ -488,9 +449,12 @@ let disambiguate_tactic status = function | TacticAst.Split loc -> status, TacticAst.Split loc | TacticAst.Symmetry loc -> status, TacticAst.Symmetry loc | TacticAst.Goal (loc, g) -> status, TacticAst.Goal (loc, g) - | x -> - print_endline ("Not yet implemented:" ^ TacticAstPp.pp_tactic x); - assert false + | TacticAst.FwdSimpl (loc, term) -> + let status, term = disambiguate_term status term in + status, TacticAst.FwdSimpl (loc, term) + | TacticAst.LApply (loc, term) -> + let status, term = disambiguate_term status term in + status, TacticAst.LApply (loc, term) let rec disambiguate_tactical status = function | TacticAst.Tactic (loc, tactic) ->