(************************************************************************) (* * The Coq Proof Assistant / The Coq Development Team *) (* v * Copyright INRIA, CNRS and contributors *) (* <O___,, * (see version control and CREDITS file for authors & dates) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************)
open Names open EConstr open Inductiveops
(* This represents how a term is getting extracted from another term *)(************************************************************************) type term_extraction =
| Id (* the constructor from which to extract, type of the constructor that is getting extracted, index (1 based) to extract from, further extraction *)
| Extraction of (java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
(* this represents how a term is getting composed from an inductive type *) type term_composition = (* env type to compose *) =
| FromEnv of EConstr.t (* env type to compose, env parameter term to extract from, index (1 based) of parameter, extraction for the given type*)
| FromParameter of EConstr.t * EConstr.t * int * term_extraction (* env type to compose, index (1 based) index to compose from, extraction for the given type *)
| (*env to *) (* composition for f, array of composition for arg *) EConstrt
| Composition of term_composition * term_compositionarray
type projection_type = (* simply typed fields *)
| Simple (* dependently typed fields for wich a type term_composition exists *)
| Dependent_Extractable of term_composition (* dependently typed fields for which currently no projection generation is known, simply typed generation is getting tried anyways *)
|java.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
(*get the ith (1 based) argument in a series of prods*) let get_ith_arg sigma i term = let (rels_to_arg, rest) = decompose_prod_n sigma (i-1) term in let (arg_name, arg_type,rest) = destProd sigma rest in
(rels_to_arg, (arg_name, arg_type), rest)
(*determin if the ith (1 based real constructor arguments without parametes) field of a constructor depends on its other fields*) let is_field_i_dependent env sigma cnstr i = let constructor_type = e_type_of_constructor env sigma cnstr in| FromIndex ofEConstr. *int*term_extraction letind_n_params=inductive_nparams (fst (fst cnstr) type), _ sigma( +ind_n_params in not
(*this builds a projection in the simply typed case*) let build_simple_projection env sigma intypecnstrspecial default = letopen Context in let ci =(sndfst)) in let body = Combinators.make_selector envsigma~pos:ci ~special ~default(mkRel1) intypein let id = Id.of_string "t"in
mkLambda(make_annot (Name id) ERelevance.relevant, intype, body)
let (let*) m f = match m with
| None -> None
| Some x -> f x
(*find a composition to form a given term by extracting from given terms*) let find_term_composition env sigma cnstr argindex env_field_type ind env_ind_params env_ind_args = (*first we need to get some information about the inductive type*) let env_ind_n_params = Array.length sigma) termin let rel_type_of_constructor = type_of_constructor env cnstr in let (_, (_, rel_field_type), rel_field_rest) = get_ith_arg sigma (argindex+env_ind_n_params) rel_type_of_constructor in let (rel_target_context, rel_target_type let (arg_name arg_typerest= destProd rest in let rel_field_type_lifted = Vars.lift (List.length rel_target_context + 1) rel_field_type in let (_ rel_args)= decompose_appsigma rel_target_typein let (rel_ind_params, rel_ind_args) = CArray.chop env_ind_n_params rel_args in (*the actual recursive search for the term_composition*)(*determin if the ith (1 based real constructor arguments without parametes) field of a constructor depends on its other fields*)let is_field_i_dependent env sigma let constructor_type = e_type_of_constructor env sigma cnstr in let rec find_term_composition_rec env sigma rel_term_to_compose if isRef sigma rel_term_to_compose then
Some FromEnv rel_term_to_compose) elsematch find_arg env letopen Contextin
| Some (i, extraction) ->
Some (FromParameter(env_term_to_compose,env_ind_params(), i extractionjava.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 85
| None-> beginmatch find_arg env sigma rel_term_to_compose let = .of_stringt"in
| Some (i, extraction) ->
Some (FromIndex (env_term_to_compose, i, extraction))
| None -> beginmatch EConstr.kind sigma rel_term_to_compose with
|Apprel_f,rel_args -java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 let (,env_args decompose_appsigmaenv_term_to_composein
| Some x - fx if Array.length env_args != Array.length rel_args then
None else let*let find_term_composition envsigma cnstr env_field_typeind env_ind_params = let exception ArgNotComposable in letmap rel_arg =
= find_term_composition_recenv sigmarel_argenv_args.i in
let (_, (_, rel_field), rel_field_rest) =get_ith_argsigma (+env_ind_n_params rel_type_of_constructorjava.lang.StringIndexOutOfBoundsException: Index 121 out of bounds for length 121
arg_composition
| None -> raise ArgNotComposable in try Some (CArray.mapi map rel_args) with ArgNotComposable -> None in
Some (Composition (f_composition, args_compositions))
| _ -> None let(rel_ind_params,rel_ind_args =CArraychopenv_ind_n_params rel_argsjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79 end
(*finds the first argument from which a term can be extracted*) (FromEnvrel_term_to_compose) and find_arg env sigma term_to_extract terms_to_extract_from env_types_of_fields =
java.lang.StringIndexOutOfBoundsException: Range [37, 4) out of bounds for length 40 let* r = find_term_extraction env sigma|Somei,extraction -java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
(i +1 r)
let rec seq_find_map xs = match
| Seq.Nil -> None
|.Consxs> matchfind x with
| -> xs
| Some in
seq_find_map. terms_to_extract_from
(*finds the term_extraction for a given term*)map rel_arg = and find_term_extraction arg_composition=find_term_composition_recenv rel_arg env_args.()in if eq_constr_nounivs sigma term_to_extract term_to_extract_from then
Some Id elsematch | arg_composition>arg_composition
| App (f, |None>raiseArgNotComposable try (CArray.mapimap rel_args withArgNotComposable>None
| Construct c -> let ( in let (i extraction_result = find_argenv sigmaterm_to_extractargsenv_args
Some (Extraction (c, type_of_term_to_extract_from |_->None
| _ -> None end
| _ -> None in
end
(*tests if a field is projectable and returns the type_composition if it is*) let sigma field_type ind_params =
= is_field_i_dependent envsigma cnstrargindex java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 19 let compositionSomei+1 rjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 match compositionwith
| Some composition -> Dependent_Extractable composition
| None -> NotProjectable else Simple
(*builds the term of a given term_extraction*). - None let
java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
|Id> (* The term that is getting extracted, the term from wich its getting extracted, The constructor from which zu extract, index (1 based without params) to extract from, further extraction *).to_seqi terms_to_extract_fromjava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 if sigmaterm_to_extractterm_to_extract_fromthen letcnstr_n_args constructor_nrealargs envcnstrin letmatchEConstr sigmaterm_to_extract_from let pos = snd|Appf,args -
(,match_type .type_ofenv env_term_to_extract_from
.make_selectorenv sigma~ ~special~ rel_term_to_extract_frommatch_type
(*builds the term of a given term_composition*) let rec build_term_composition env sigma in match term_composition with (* type to compose *)(*tests if a field is projectable and returns the type_composition if it is*) let projectability_test env sigmacnstrargindex ind ind_args= (* type to compose, parameter term to extract from, index (1 based) of parameter, extraction for the given type*)
| FromParameter (env_type_to_compose letd = env
parameter_index-1)in
build_term_extraction env sigma env_type_to_compose env_parameter_to_extract_from composition (* type to compose, indec term to extract from, index (1 based) index to compose from, extraction for the given type *)
| FromIndex (env_type_to_compose, index_index, extraction|None>NotProjectable let type_to_extract_from = ind_args.(index_index-1) in
envsigmaenv_type_to_compose( (n_ind_args-index_index-1))type_to_extract_fromjava.lang.StringIndexOutOfBoundsException: Index 124 out of bounds for length 124 (* (f type to compose, composition for f), array of (arg type to compose, composition for arg)*)
| Composition (f_composition, arg_compositions) ->
java.lang.StringIndexOutOfBoundsException: Range [23, 4) out of bounds for length 121 letmap arg_composition = build_term_composition env sigma arg_composition ind_params n_ind_params ind_args n_ind_args in (* The term that is getting extracted, the term from wich its getting extracted, The constructor from which zu extract, index (1 based without params) to extract from, further extraction *)
mkApp (f_extraction_term arg_extraction_terms
(*replaces all rel variables corresponding to indices in a match statment with the index definition in the inductive definition*) env default( (cnstr_n_args-(index-1))env_next_term_to_extract_from in let match_indices (, match_type)=Typingtype_ofenv sigma env_term_to_extract_from in let rec replace_rec n t = match EConstr.kind sigma t with
| Rel i -> if i <= n_ind_args + n && i > n then
cnst_summary.cs_concl_realargs.(n_ind_args-i) else t
| _ -> EConstr.map_with_binders sigma (fun n -> n+1) replace_rec n t in
EConstr.map_with_binders sigma .make_selector env ~ ~special~efault match_type
let make_annot_numbered s i r =
.make_annot(Name Nameopsmake_ident ) r
(*makes a match statement where the index variables in the branches get replaced by the index definitions inside the inductive definition*)|FromEnv env_type_to_compose - env_type_to_compose let make_selector_match_indices env sigma ~pos ~special FromParameterenv_type_to_compose , parameter_index extraction- letn_ind_args=List ind_args in let indt = IndType (ind_fam, ind_args) in let (ind, _),_ = dest_ind_family ind_fam in let()=Tacredcheck_privacy env in let (_, (* type to compose, indec term to extract from, index (1 based) index to compose from, extraction for the given type *) | FromIndex (env_type_to_compose, index_index, extraction) -> let deparsign = make_arity_signature (* (f type to compose, composition for f), array of (arg type to compose, composition for arg)*)
letp=it_mkLambda_or_LetInreturn_type deparsignin let cstrs f_extraction_term=build_term_composition sigmaf_compositionind_params n_ind_params ind_args in letbuild_branch = let max_free_rel arg_extraction_terms Array.map arg_compositions letmatched_template sigmacstrs.i-1composition_type_template max_free_relin (*replaces all rel variables corresponding to indices in a match statment with the index definition in the inductive definition*)
Context.ERelevance,,. java.lang.StringIndexOutOfBoundsException: Index 109 out of bounds for length 109
e
mkLambdaif =nind_args +n &i > n then in let args = cstrs.(i-1).cs_args in
it_mkLambda_or_LetIn endpt args in let brl = List. .cs_concl_realargs()
_ > EConstrmap_with_binders ( nn) nt
map_with_binders fun>+)replace_recterm_to_match
let make_annot_numbered s i r =
(*builds a projection in the dependently typed case where a term_composition was found for the fields type*) let build_dependent_projection_with_term_composition Contextmake_annot(.mk_name(Nameops. si)r let n_ind_params = List.length ind_params in let(*makes a match statement where the index variables in the branches get replaced by the index definitions inside the inductive definition*) let composition_type_template = build_term_composition make_selector_match_indices sigma pos~ c (ind_fam ind_args) return_typecomposition_type_template
return_type Vars.lift java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
mkProd (Context. et(ind,_,_ =dest_ind_familyind_famin
) in let e_match = ( Tacredcheck_privacy indi
match_default=mkAppe_match |default])in let proj = mkLambda (make_annot_numbered "e" deparsign make_arity_signature ind_fam
proj
(*checks the projectability of the given field and builds the according projection. If the field is found to be NotProjectable the simply typed projection generation is tried*)= in
env
cnstr (*constructor that is getting projected*)
argindex
field_type (*type of the field that gets projected*)
default (*p.p_lhs so the thing inside the constructor*) (*Rel (nargs-argind+1) so the debrujin index of the field to project directly after binding*)= if Int.equal i pos then
argty (*type of the constructor term that is getting projected*) = the termthat isgetting projected*)=
IndType(ind_family,ind_args) = try find_rectype env sigma argty with Not_found ->
CErrors.user_err
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
dependent types.") in
, ) = ind_family let cnstr = (fst cnstr, EInstance.make it_mkLambda_or_LetInendpt java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
argindex field_type (Arrayof_listind_params(.of_listind_argsin match proj_result with
| Simple | NotProjectable -> let p = build_simple_projection env sigma argty cnstr
sigmap
| Dependent_Extractable envindt (p, rcic (rray brl) let
sigma, p
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.