From 414dc18cdbc1f431758cfce79b0b7827e2419d39 Mon Sep 17 00:00:00 2001 From: Andrea Asperti Date: Wed, 23 Jul 2003 17:02:54 +0000 Subject: [PATCH] - Lemma added to the list of proof arguments - Lemma used for Const, MutConst and Var in Apply arguments - atomization of complex proofs is now performed also in tactics different from Apply --- helm/ocaml/cic_omdoc/Makefile | 2 +- helm/ocaml/cic_omdoc/cic2content.ml | 185 +++++++++++++++++++--------- helm/ocaml/cic_omdoc/content.ml | 8 ++ helm/ocaml/cic_omdoc/content.mli | 7 ++ helm/ocaml/cic_omdoc/content2cic.ml | 3 + helm/ocaml/cic_omdoc/contentPp.ml | 10 +- 6 files changed, 154 insertions(+), 61 deletions(-) diff --git a/helm/ocaml/cic_omdoc/Makefile b/helm/ocaml/cic_omdoc/Makefile index 33f1b3f07..affeb76d4 100644 --- a/helm/ocaml/cic_omdoc/Makefile +++ b/helm/ocaml/cic_omdoc/Makefile @@ -1,5 +1,5 @@ PACKAGE = cic_omdoc -REQUIRES = helm-cic_proof_checking +REQUIRES = helm-cic_proof_checking helm-mathql_interpreter PREDICATES = INTERFACE_FILES = eta_fixing.mli doubleTypeInference.mli cic2acic.mli \ diff --git a/helm/ocaml/cic_omdoc/cic2content.ml b/helm/ocaml/cic_omdoc/cic2content.ml index 149fd90ec..0e0edf100 100644 --- a/helm/ocaml/cic_omdoc/cic2content.ml +++ b/helm/ocaml/cic_omdoc/cic2content.ml @@ -99,14 +99,21 @@ let get_id = | C.ACoFix (id,_,_) -> id ;; -let test_for_lifting ~ids_to_inner_types = +let test_for_lifting ~ids_to_inner_types ~ids_to_inner_sorts= let module C = Cic in let module C2A = Cic2acic in (* atomic terms are never lifted, according to my policy *) function C.ARel (id,_,_,_) -> false - | C.AVar (id,_,_) -> false - | C.AMeta (id,_,_) -> false + | C.AVar (id,_,_) -> + (try + ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized; + true; + with Not_found -> false) + | C.AMeta (id,_,_) -> + (try + Hashtbl.find ids_to_inner_sorts id = "Prop" + with Not_found -> assert false) | C.ASort (id,_) -> false | C.AImplicit _ -> raise NotImplemented | C.AProd (id,_,_,_) -> false @@ -159,10 +166,11 @@ let test_for_lifting ~ids_to_inner_types = with Not_found -> false) ;; +(* let build_args seed l subproofs ~ids_to_inner_types ~ids_to_inner_sorts = let module C = Cic in let module K = Content in - let rec aux l subrpoofs = + let rec aux l subproofs = match l with [] -> [] | t::l1 -> @@ -197,6 +205,7 @@ let build_args seed l subproofs ~ids_to_inner_types ~ids_to_inner_sorts = hd::(aux l1 subproofs) in aux l subproofs ;; +*) (* transform a proof p into a proof list, concatenating the last conclude element to the apply_context list, in case context is @@ -219,8 +228,9 @@ let flat seed p = let rec serialize seed = function - [] -> [] - | p::tl -> (flat seed p)@(serialize seed tl);; + [] -> [] + | a::l -> (flat seed a)@(serialize seed l) +;; (* top_down = true if the term is a LAMBDA or a decl *) let generate_conversion seed top_down id inner_proof ~ids_to_inner_types = @@ -336,7 +346,92 @@ let build_decl_item seed id n s ~ids_to_inner_sorts = Not_found -> assert false ;; -let rec build_def_item seed id n t ~ids_to_inner_sorts ~ids_to_inner_types = +let rec build_subproofs_and_args seed l ~ids_to_inner_types ~ids_to_inner_sorts = + let module C = Cic in + let module K = Content in + let rec aux = + function + [] -> [],[] + | t::l1 -> + let subproofs,args = aux l1 in + if (test_for_lifting t ~ids_to_inner_types ~ids_to_inner_sorts) then + let new_subproof = + acic2content + seed ~name:"H" ~ids_to_inner_types ~ids_to_inner_sorts t in + let new_arg = + K.Premise + { K.premise_id = gen_id seed; + K.premise_xref = new_subproof.K.proof_id; + K.premise_binder = new_subproof.K.proof_name; + K.premise_n = None + } in + new_subproof::subproofs,new_arg::args + else + let hd = + (match t with + C.ARel (idr,idref,n,b) -> + let sort = + (try Hashtbl.find ids_to_inner_sorts idr + with Not_found -> "Type") in + if sort ="Prop" then + K.Premise + { K.premise_id = gen_id seed; + K.premise_xref = idr; + K.premise_binder = Some b; + K.premise_n = Some n + } + else (K.Term t) + | C.AConst(id,uri,[]) -> + let sort = + (try Hashtbl.find ids_to_inner_sorts id + with Not_found -> "Type") in + if sort ="Prop" then + K.Lemma + { K.lemma_id = gen_id seed; + K.lemma_name = UriManager.name_of_uri uri; + K.lemma_uri = UriManager.string_of_uri uri + } + else (K.Term t) + | C.AMutConstruct(id,uri,tyno,consno,[]) -> + let sort = + (try Hashtbl.find ids_to_inner_sorts id + with Not_found -> "Type") in + if sort ="Prop" then + let inductive_types = + (match CicEnvironment.get_obj uri with + Cic.Constant _ -> assert false + | Cic.Variable _ -> assert false + | Cic.CurrentProof _ -> assert false + | Cic.InductiveDefinition (l,_,_) -> l + ) in + let (_,_,_,constructors) = + List.nth inductive_types tyno in + let name,_ = List.nth constructors (consno - 1) in + K.Lemma + { K.lemma_id = gen_id seed; + K.lemma_name = name; + K.lemma_uri = + UriManager.string_of_uri uri ^ "#xpointer(1/" ^ + string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^ + ")" + } + else (K.Term t) + | _ -> (K.Term t)) in + subproofs,hd::args + in + match (aux l) with + [p],args -> + [{p with K.proof_name = None}], + List.map + (function + K.Premise prem when prem.K.premise_xref = p.K.proof_id -> + K.Premise {prem with K.premise_binder = None} + | i -> i) args + | p,a as c -> c + +and + +build_def_item seed id n t ~ids_to_inner_sorts ~ids_to_inner_types = let module K = Content in try let sort = Hashtbl.find ids_to_inner_sorts id in @@ -414,7 +509,7 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t = else proof in let proof'' = { proof' with - K.proof_name = name; + K.proof_name = None; K.proof_context = ((build_def_item seed id n s ids_to_inner_sorts ids_to_inner_types):> Cic.annterm K.in_proof_context_element) @@ -425,11 +520,15 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t = else raise Not_a_proof | C.AAppl (id,li) -> (try rewrite - seed name id li ids_to_inner_types ids_to_inner_sorts + seed name id li ~ids_to_inner_types ~ids_to_inner_sorts with NotApplicable -> try inductive - seed name id li ids_to_inner_types ids_to_inner_sorts + seed name id li ~ids_to_inner_types ~ids_to_inner_sorts with NotApplicable -> + let subproofs, args = + build_subproofs_and_args + seed li ~ids_to_inner_types ~ids_to_inner_sorts in +(* let args_to_lift = List.filter (test_for_lifting ~ids_to_inner_types) li in let subproofs = @@ -437,7 +536,7 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t = [_] -> List.map aux args_to_lift | _ -> List.map (aux ~name:"H") args_to_lift in let args = build_args seed li subproofs - ~ids_to_inner_types ~ids_to_inner_sorts in + ~ids_to_inner_types ~ids_to_inner_sorts in *) { K.proof_name = name; K.proof_id = gen_id seed; K.proof_context = []; @@ -477,25 +576,17 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t = let pp = List.map2 (fun p (name,_) -> (K.ArgProof (aux ~name p))) patterns constructors in - let apply_context,term = + let context,term = (match - (try Some (Hashtbl.find ids_to_inner_types teid).C2A.annsynthesized - with Not_found -> None) + build_subproofs_and_args + seed ~ids_to_inner_types ~ids_to_inner_sorts [te] with - Some tety -> - let p = (aux te) in - (flat seed p, - K.Premise - { K.premise_id = gen_id seed; - K.premise_xref = p.K.proof_id; - K.premise_binder = p.K.proof_name; - K.premise_n = None - }) - | None -> [],K.Term te) in + l,[t] -> l,t + | _ -> assert false) in { K.proof_name = name; K.proof_id = gen_id seed; K.proof_context = []; - K.proof_apply_context = apply_context; + K.proof_apply_context = serialize seed context; K.proof_conclude = { K.conclude_id = gen_id seed; K.conclude_aref = id; @@ -580,7 +671,7 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t = generate_conversion seed false id t1 ~ids_to_inner_types in aux ?name t -and inductive seed name id li ids_to_inner_types ids_to_inner_sorts = +and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts = let aux ?name = acic2content seed ~ids_to_inner_types ~ids_to_inner_sorts in let module C2A = Cic2acic in let module K = Content in @@ -623,25 +714,9 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts = let no_constructors= List.length constructors in let args_for_cases, other_args = split no_constructors tail_args in - let args_to_lift = - List.filter (test_for_lifting ~ids_to_inner_types) other_args in - let subproofs = - match args_to_lift with - [_] -> List.map aux args_to_lift - | _ -> List.map (aux ~name:"H") args_to_lift in - prerr_endline "****** end subproofs *******"; flush stderr; - let other_method_args = - build_args seed other_args subproofs + let subproofs,other_method_args = + build_subproofs_and_args seed other_args ~ids_to_inner_types ~ids_to_inner_sorts in -(* - let rparams,inductive_arg = - let rec aux = - function - [] -> assert false - | [ia] -> [],ia - | a::tl -> let (p,ia) = aux tl in (a::p,ia) in - aux other_method_args in -*) prerr_endline "****** end other *******"; flush stderr; let method_args= let rec build_method_args = @@ -694,7 +769,7 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts = { K.proof_name = None; K.proof_id = gen_id seed; K.proof_context = []; - K.proof_apply_context = subproofs; + K.proof_apply_context = serialize seed subproofs; K.proof_conclude = { K.conclude_id = gen_id seed; K.conclude_aref = id; @@ -711,7 +786,7 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts = } | _ -> raise NotApplicable -and rewrite seed name id li ids_to_inner_types ids_to_inner_sorts = +and rewrite seed name id li ~ids_to_inner_types ~ids_to_inner_sorts = let aux ?name = acic2content seed ~ids_to_inner_types ~ids_to_inner_sorts in let module C2A = Cic2acic in let module K = Content in @@ -721,19 +796,19 @@ and rewrite seed name id li ids_to_inner_types ids_to_inner_sorts = let uri_str = UriManager.string_of_uri uri in if uri_str = "cic:/Coq/Init/Logic/eq_ind.con" or uri_str = "cic:/Coq/Init/Logic/eq_ind_r.con" then - let subproof = aux (List.nth args 3) in + let subproofs,arg = + (match + build_subproofs_and_args + seed ~ids_to_inner_types ~ids_to_inner_sorts [List.nth args 3] + with + l,[p] -> l,p + | _,_ -> assert false) in let method_args = let rec ma_aux n = function [] -> [] | a::tl -> let hd = - if n = 0 then - K.Premise - { K.premise_id = gen_id seed; - K.premise_xref = subproof.K.proof_id; - K.premise_binder = None; - K.premise_n = None - } + if n = 0 then arg else let aid = get_id a in let asort = (try (Hashtbl.find ids_to_inner_sorts aid) @@ -746,7 +821,7 @@ and rewrite seed name id li ids_to_inner_types ids_to_inner_sorts = { K.proof_name = None; K.proof_id = gen_id seed; K.proof_context = []; - K.proof_apply_context = [subproof]; + K.proof_apply_context = serialize seed subproofs; K.proof_conclude = { K.conclude_id = gen_id seed; K.conclude_aref = id; diff --git a/helm/ocaml/cic_omdoc/content.ml b/helm/ocaml/cic_omdoc/content.ml index a09e25cf2..c3c2295ca 100644 --- a/helm/ocaml/cic_omdoc/content.ml +++ b/helm/ocaml/cic_omdoc/content.ml @@ -123,6 +123,7 @@ and 'term conclude_item = and 'term arg = Aux of string | Premise of premise + | Lemma of lemma | Term of 'term | ArgProof of 'term proof | ArgMethod of string (* ???? *) @@ -133,6 +134,13 @@ and premise = premise_binder : string option; premise_n : int option; } + +and lemma = + { lemma_id: string; + lemma_name: string; + lemma_uri: string + } + ;; type 'term conjecture = id * int * 'term context * 'term diff --git a/helm/ocaml/cic_omdoc/content.mli b/helm/ocaml/cic_omdoc/content.mli index 813a31053..a672cd83c 100644 --- a/helm/ocaml/cic_omdoc/content.mli +++ b/helm/ocaml/cic_omdoc/content.mli @@ -114,6 +114,7 @@ and 'term conclude_item = and 'term arg = Aux of string | Premise of premise + | Lemma of lemma | Term of 'term | ArgProof of 'term proof | ArgMethod of string (* ???? *) @@ -124,6 +125,12 @@ and premise = premise_binder : string option; premise_n : int option; } + +and lemma = + { lemma_id: string; + lemma_name : string; + lemma_uri: string + } ;; type 'term conjecture = id * int * 'term context * 'term diff --git a/helm/ocaml/cic_omdoc/content2cic.ml b/helm/ocaml/cic_omdoc/content2cic.ml index d25d79425..b1151c792 100644 --- a/helm/ocaml/cic_omdoc/content2cic.ml +++ b/helm/ocaml/cic_omdoc/content2cic.ml @@ -207,6 +207,9 @@ let proof2cic deannotate p = with Not_found -> prerr_endline ("Not_found in arg2cic: premise " ^ (match prem.Con.premise_binder with None -> "previous" | Some p -> p) ^ ", xref=" ^ prem.Con.premise_xref); raise Not_found)) + | Con.Lemma lemma -> + MQueryMisc.term_of_cic_textual_parser_uri + (MQueryMisc.cic_textual_parser_uri_of_string lemma.Con.lemma_uri) | Con.Term t -> deannotate t | Con.ArgProof p -> diff --git a/helm/ocaml/cic_omdoc/contentPp.ml b/helm/ocaml/cic_omdoc/contentPp.ml index b51cba99d..58ba4873b 100644 --- a/helm/ocaml/cic_omdoc/contentPp.ml +++ b/helm/ocaml/cic_omdoc/contentPp.ml @@ -130,13 +130,13 @@ and pargs args indent = and parg indent = let module Con = Content in function - Con.Aux n -> prerr_endline ((blanks (indent+1)) ^ n);flush stderr - | Con.Premise prem -> prerr_endline ((blanks (indent+1)) ^ "Premise");flush stderr + Con.Aux n -> prerr_endline ((blanks (indent+1)) ^ n) + | Con.Premise prem -> prerr_endline ((blanks (indent+1)) ^ "Premise") + | Con.Lemma lemma -> prerr_endline ((blanks (indent+1)) ^ "Lemma") | Con.Term t -> - prerr_endline ((blanks (indent+1)) ^ (CicPp.ppterm (Deannotate.deannotate_term t))); - flush stderr + prerr_endline ((blanks (indent+1)) ^ (CicPp.ppterm (Deannotate.deannotate_term t))) | Con.ArgProof p -> pproof p (indent+1) - | Con.ArgMethod s -> prerr_endline ((blanks (indent+1)) ^ "A Method !!!");flush stderr + | Con.ArgMethod s -> prerr_endline ((blanks (indent+1)) ^ "A Method !!!") ;; let print_proof p = pproof p 0; -- 2.39.2