X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Facic_procedural%2Fprocedural2.ml;h=ff8f864eabb31320e8af90737ae1501be4085434;hb=HEAD;hp=06fc9b35843bf330a0020cd836acd47d443e52aa;hpb=8ed18544e1591dd3068e2d9095b05d0c4349209c;p=helm.git diff --git a/helm/software/components/acic_procedural/procedural2.ml b/helm/software/components/acic_procedural/procedural2.ml index 06fc9b358..ff8f864ea 100644 --- a/helm/software/components/acic_procedural/procedural2.ml +++ b/helm/software/components/acic_procedural/procedural2.ml @@ -26,6 +26,7 @@ module C = Cic module I = CicInspect module S = CicSubstitution +module R = CicReduction module TC = CicTypeChecker module Un = CicUniv module UM = UriManager @@ -53,11 +54,12 @@ type status = { max_depth: int option; depth : int; defaults : bool; + cr : bool; context : C.context; case : int list } -let debug = ref true +let debug = ref false (* helpers ******************************************************************) @@ -168,13 +170,20 @@ let get_sub_names head l = let get_type msg st t = H.get_type msg st.context (H.cic t) let get_uri_of_head = function - | C.AConst (_, u, _) - | C.AAppl (_, C.AConst (_, u, _) :: _) -> Some (u, 0, 0) - | C.AMutInd (_, u, i, _) - | C.AAppl (_, C.AMutInd (_, u, i, _) :: _) -> Some (u, succ i, 0) - | C.AMutConstruct (_, u, i, j, _) - | C.AAppl (_, C.AMutConstruct (_, u, i, j, _) :: _) -> Some (u, succ i, j) - | _ -> None + | C.AConst (_, u, _) -> + Some (u, 0, 0, 0) + | C.AAppl (_, C.AConst (_, u, _) :: vs) -> + Some (u, 0, 0, List.length vs) + | C.AMutInd (_, u, i, _) -> + Some (u, succ i, 0, 0) + | C.AAppl (_, C.AMutInd (_, u, i, _) :: vs) -> + Some (u, succ i, 0, List.length vs) + | C.AMutConstruct (_, u, i, j, _) -> + Some (u, succ i, j, 0) + | C.AAppl (_, C.AMutConstruct (_, u, i, j, _) :: vs) -> + Some (u, succ i, j, List.length vs) + | _ -> + None let get_uri_of_apply = function | T.Exact (t, _) @@ -183,31 +192,47 @@ let get_uri_of_apply = function let is_reflexivity st step = match get_uri_of_apply step with - | None -> false - | Some (uri, i, j) -> st.defaults && Obj.is_eq_URI uri && i = 1 && j = 1 + | None -> false + | Some (uri, i, j, n) -> + st.defaults && Obj.is_eq_URI uri && i = 1 && j = 1 && n = 0 + +let is_ho_reflexivity st step = + match get_uri_of_apply step with + | None -> false + | Some (uri, i, j, n) -> + st.defaults && Obj.is_eq_URI uri && i = 1 && j = 1 && n > 0 + +let are_convertible st pred sx dx = + let pred, sx, dx = H.cic pred, H.cic sx, H.cic dx in + let sx, dx = C.Appl [pred; sx], C.Appl [pred; dx] in + fst (R.are_convertible st.context sx dx Un.default_ugraph) (* proof construction *******************************************************) let anonymous_premise = C.Name "UNNAMED" -let mk_exp_args hd tl classes synth qs = +let mk_lapply_args hd tl classes = + let map _ = Cn.meta "" in + let args = List.rev_map map tl in + if args = [] then hd else C.AAppl ("", hd :: args) + +let mk_apply_args hd tl classes synth qs = let exp = ref 0 in - let meta id = C.AImplicit (id, None) in let map v (cl, b) = if I.overlaps synth cl - then if b then v, v else meta "", v - else meta "", meta "" + then if b then v, v else Cn.meta "", v + else Cn.meta "", Cn.meta "" in let rec rev a = function | [] -> a | hd :: tl -> - if snd hd <> meta "" then incr exp; + if snd hd <> Cn.meta "" then incr exp; rev (snd hd :: a) tl in let rec aux = function | [] -> [] | hd :: tl -> - if fst hd = meta "" then aux tl else rev [] (hd :: tl) + if fst hd = Cn.meta "" then aux tl else rev [] (hd :: tl) in let args = T.list_rev_map2 map tl classes in let args = aux args in @@ -227,7 +252,7 @@ let mk_convert st ?name sty ety note = note sname (ppterm csty) (ppterm cety) else "" in - if H.alpha_equivalence ~flatten:true st.context csty cety then [T.Note note] else + if H.alpha ~flatten:true st.context csty cety then [T.Note note] else let sty, ety = H.acic_bc st.context sty, H.acic_bc st.context ety in match name with | None -> [T.Change (sty, ety, None, e, note)] @@ -253,6 +278,8 @@ let get_intro = function let mk_preamble st what script = match script with | step :: script when is_reflexivity st step -> + T.Reflexivity (T.note_of_step step) :: script + | step :: script when is_ho_reflexivity st step -> convert st what @ T.Reflexivity (T.note_of_step step) :: script | T.Exact _ :: _ -> script | _ -> convert st what @ script @@ -294,11 +321,18 @@ let mk_rewrite st dtext where qs tl direction t ity = let a = ref "" in Ut.pp_term (fun s -> a := !a ^ s) [] st.context t; !a in assert (List.length tl = 5); - let predicate = List.nth tl 2 in - let dtext = if !debug then dtext ^ ppterm (H.cic predicate) else dtext in - let e = Cn.mk_pattern 1 ity predicate in + let pred, sx, dx = List.nth tl 2, List.nth tl 1, List.nth tl 4 in + let dtext = if !debug then dtext ^ ppterm (H.cic pred) else dtext in + let e = Cn.mk_pattern 1 ity pred in let script = [T.Branch (qs, "")] in - if (Cn.does_not_occur e) then script else + if Cn.does_not_occur e then script else + if st.cr && are_convertible st pred sx dx then + let dtext = "convertible rewrite" ^ dtext in + let ity, ety, e = Cn.beta sx pred, Cn.beta dx pred, Cn.hole "" in + let city, cety = H.cic ity, H.cic ety in + if H.alpha ~flatten:true st.context city cety then script else + T.Change (ity, ety, None, e, dtext) :: script + else T.Rewrite (direction, where, None, e, dtext) :: script let rec proc_lambda st what name v t = @@ -319,8 +353,8 @@ and proc_letin st what name v w t = let script = if proceed then let st, hyp, rqv = match get_inner_types st what, get_inner_types st v with | Some (C.ALetIn (_, _, iv, iw, _), _), _ when - H.alpha_equivalence ~flatten:true st.context (H.cic v) (H.cic iv) && - H.alpha_equivalence ~flatten:true st.context (H.cic w) (H.cic iw) + H.alpha ~flatten:true st.context (H.cic v) (H.cic iv) && + H.alpha ~flatten:true st.context (H.cic w) (H.cic iw) -> st, C.Def (H.cic v, H.cic w), [T.Intros (Some 1, [intro], dtext)] | _, Some (ity, ety) -> @@ -329,6 +363,26 @@ and proc_letin st what name v w t = mk_fwd_rewrite st dtext intro tl true v t ity ety | C.AAppl (_, hd :: tl) when is_fwd_rewrite_left st hd tl -> mk_fwd_rewrite st dtext intro tl false v t ity ety + | C.AAppl (_, hd :: tl) -> + let ty = match get_inner_types st hd with + | Some (ity, _) -> H.cic ity + | None -> get_type "TC3" st hd + in + let classes, _ = Cl.classify st.context ty in + let parsno, argsno = List.length classes, List.length tl in + let decurry = parsno - argsno in + if decurry <> 0 then begin +(* FG: we fall back in the cut case *) + assert (Ut.is_sober st.context (H.cic ety)); + let ety = H.acic_bc st.context ety in + let qs = [proc_proof (next st) v; [T.Id ""]] in + st, [T.Branch (qs, ""); T.Cut (intro, ety, dtext)] + end else + let names, synth = get_sub_names hd tl, I.S.empty in + let qs = proc_bkd_proofs (next st) synth names classes tl in + let hd = mk_lapply_args hd tl classes in + let qs = [T.Id ""] :: qs in + st, [T.Branch (qs, ""); T.LApply (intro, hd, dtext)] | v -> assert (Ut.is_sober st.context (H.cic ety)); let ety = H.acic_bc st.context ety in @@ -409,7 +463,7 @@ and proc_appl st what hd tl = in if List.length qs <> List.length names then let qs = proc_bkd_proofs (next st) synth [] classes tl in - let b, hd, qs = mk_exp_args hd tl classes synth qs in + let b, hd, qs = mk_apply_args hd tl classes synth qs in script @ [tactic b hd (dtext ^ text); T.Branch (qs, "")] else if is_rewrite_right st hd then script2 @ mk_rewrite st dtext where qs tl2 false what ity @@ -424,7 +478,7 @@ and proc_appl st what hd tl = | _ -> let names = get_sub_names hd tl in let qs = proc_bkd_proofs (next st) synth names classes tl in - let b, hd, qs = mk_exp_args hd tl classes synth qs in + let b, hd, qs = mk_apply_args hd tl classes synth qs in script @ [tactic b hd (dtext ^ text); T.Branch (qs, "")] else [T.Exact (what, dtext)] @@ -526,6 +580,7 @@ let init ~ids_to_inner_sorts ~ids_to_inner_types params context = max_depth = List.fold_left depth_map None params; depth = 0; defaults = not (List.mem G.IPNoDefaults params); + cr = List.mem G.IPCR params; context = context; case = [] }