diff options
| author | filliatr | 1999-11-19 09:11:35 +0000 |
|---|---|---|
| committer | filliatr | 1999-11-19 09:11:35 +0000 |
| commit | 5865d4d79f052cfb190e728e8618cb05e2ac845f (patch) | |
| tree | 530892b92888f132d18c799d2a3ad221dcaa965c /tactics | |
| parent | f9f2c2bc695033f93a0b7352027678c4ca305ccd (diff) | |
discriminations nets
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@123 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'tactics')
| -rw-r--r-- | tactics/btermdn.ml | 52 | ||||
| -rw-r--r-- | tactics/btermdn.mli | 21 | ||||
| -rw-r--r-- | tactics/dn.ml | 2 | ||||
| -rw-r--r-- | tactics/nbtermdn.ml | 75 | ||||
| -rw-r--r-- | tactics/nbtermdn.mli | 30 | ||||
| -rw-r--r-- | tactics/termdn.ml | 68 | ||||
| -rw-r--r-- | tactics/termdn.mli | 27 |
7 files changed, 274 insertions, 1 deletions
diff --git a/tactics/btermdn.ml b/tactics/btermdn.ml new file mode 100644 index 0000000000..3015e651b1 --- /dev/null +++ b/tactics/btermdn.ml @@ -0,0 +1,52 @@ + +(* $Id$ *) + +open Term +open Termdn + +(* Discrimination nets with bounded depth. + See the module dn.ml for further explanations. + Eduardo (5/8/97). *) + +let dnet_depth = ref 8 + +let bounded_constr_pat_discr (t,depth) = + if depth = 0 then + None + else + match constr_pat_discr t with + | None -> None + | Some (c,l) -> Some(c,List.map (fun c -> (c,depth-1)) l) + +let bounded_constr_val_discr (t,depth) = + if depth = 0 then + None + else + match constr_val_discr t with + | None -> None + | Some (c,l) -> Some(c,List.map (fun c -> (c,depth-1)) l) + +type 'a t = (lbl,constr * int,'a) Dn.under_t + +let newdn () = Dn.create bounded_constr_pat_discr + +let ex_termdn = newdn() + +let inDN tdn = { + Dn.args = ex_termdn.Dn.args; + Dn.tm = tdn } + +let outDN dn = dn.Dn.tm + +let create () = outDN (newdn()) + +let add dn (c,v) = outDN (Dn.add (inDN dn) ((c,!dnet_depth),v)) + +let rmv dn (c,v) = outDN (Dn.rmv (inDN dn) ((c,!dnet_depth),v)) + +let lookup dn t = + List.map + (fun ((c,_),v) -> (c,v)) + (Dn.lookup (inDN dn) bounded_constr_val_discr (t,!dnet_depth)) + +let app f dn = Dn.app (fun ((c,_),v) -> f(c,v)) (inDN dn) diff --git a/tactics/btermdn.mli b/tactics/btermdn.mli new file mode 100644 index 0000000000..882f0bbb9c --- /dev/null +++ b/tactics/btermdn.mli @@ -0,0 +1,21 @@ + +(* $Id$ *) + +(*i*) +open Generic +open Term +(*i*) + +(* Discrimination nets with bounded depth. *) + +type 'a t + +val create : unit -> 'a t + +val add : 'a t -> (constr * 'a) -> 'a t +val rmv : 'a t -> (constr * 'a) -> 'a t + +val lookup : 'a t -> constr -> (constr * 'a) list +val app : ((constr * 'a) -> unit) -> 'a t -> unit + +val dnet_depth : int ref diff --git a/tactics/dn.ml b/tactics/dn.ml index 55112ba798..33ce0df5db 100644 --- a/tactics/dn.ml +++ b/tactics/dn.ml @@ -31,7 +31,7 @@ type ('lbl,'pat,'inf) t = { tm : ('lbl,'pat,'inf) under_t; args : ('lbl,'pat) dn_args } -let create dna = {tm = Tlm.create(); args = dna} +let create dna = { tm = Tlm.empty; args = dna } let path_of dna = let rec path_of_deferred = function diff --git a/tactics/nbtermdn.ml b/tactics/nbtermdn.ml new file mode 100644 index 0000000000..ec5de39c03 --- /dev/null +++ b/tactics/nbtermdn.ml @@ -0,0 +1,75 @@ + +(* $Id$ *) + +open Util +open Names +open Generic +open Term +open Libobject +open Library + +(* Named, bounded-depth, term-discrimination nets. + Implementation: + Term-patterns are stored in discrimination-nets, which are + themselves stored in a hash-table, indexed by the first label. + They are also stored by name in a table on-the-side, so that we can + override them if needed. *) + +(* The former comments are from Chet. + See the module dn.ml for further explanations. + Eduardo (5/8/97) *) + +type ('na,'a) t = { + mutable table : ('na,constr * 'a) Gmap.t; + mutable patterns : (Termdn.lbl option,'a Btermdn.t) Gmap.t } + +type ('na,'a) frozen_t = + ('na,constr * 'a) Gmap.t * (Termdn.lbl option,'a Btermdn.t) Gmap.t + +let create () = + { table = Gmap.empty; + patterns = Gmap.empty } + +let get_dn dnm hkey = + try Gmap.find hkey dnm with Not_found -> Btermdn.create () + +let add dn (na,(pat,valu)) = + let hkey = option_app fst (Termdn.constr_pat_discr pat) in + dn.table <- Gmap.add na (pat,valu) dn.table; + let dnm = dn.patterns in + dn.patterns <- Gmap.add hkey (Btermdn.add (get_dn dnm hkey) (pat,valu)) dnm + +let rmv dn na = + let (pat,valu) = Gmap.find na dn.table in + let hkey = option_app fst (Termdn.constr_pat_discr pat) in + dn.table <- Gmap.remove na dn.table; + let dnm = dn.patterns in + dn.patterns <- Gmap.add hkey (Btermdn.rmv (get_dn dnm hkey) (pat,valu)) dnm + +let in_dn dn na = Gmap.mem na dn.table + +let remap ndn na (pat,valu) = + rmv ndn na; + add ndn (na,(pat,valu)) + +let lookup dn valu = + let hkey = option_app fst (Termdn.constr_val_discr valu) in + try Btermdn.lookup (Gmap.find hkey dn.patterns) valu with Not_found -> [] + +let app f dn = Gmap.iter f dn.table + +let dnet_depth = Btermdn.dnet_depth + +let freeze dn = (dn.table, dn.patterns) + +let unfreeze (fnm,fdnm) dn = + dn.table <- fnm; + dn.patterns <- fdnm + +let empty dn = + dn.table <- Gmap.empty; + dn.patterns <- Gmap.empty + +let to2lists dn = + (Gmap.to_list dn.table, Gmap.to_list dn.patterns) + diff --git a/tactics/nbtermdn.mli b/tactics/nbtermdn.mli new file mode 100644 index 0000000000..e94a21e9d5 --- /dev/null +++ b/tactics/nbtermdn.mli @@ -0,0 +1,30 @@ + +(* $Id$ *) + +(*i*) +open Generic +open Term +(*i*) + +(* Named, bounded-depth, term-discrimination nets. *) + +type ('na,'a) t +type ('na,'a) frozen_t + +val create : unit -> ('na,'a) t + +val add : ('na,'a) t -> ('na * (constr * 'a)) -> unit +val rmv : ('na,'a) t -> 'na -> unit +val in_dn : ('na,'a) t -> 'na -> bool +val remap : ('na,'a) t -> 'na -> (constr * 'a) -> unit + +val lookup : ('na,'a) t -> constr -> (constr * 'a) list +val app : ('na -> (constr * 'a) -> unit) -> ('na,'a) t -> unit + +val dnet_depth : int ref + +val freeze : ('na,'a) t -> ('na,'a) frozen_t +val unfreeze : ('na,'a) frozen_t -> ('na,'a) t -> unit +val empty : ('na,'a) t -> unit +val to2lists : ('na,'a) t -> ('na * (Term.constr * 'a)) list * + (Termdn.lbl option * 'a Btermdn.t) list diff --git a/tactics/termdn.ml b/tactics/termdn.ml new file mode 100644 index 0000000000..f1f8374c9b --- /dev/null +++ b/tactics/termdn.ml @@ -0,0 +1,68 @@ + +(* $Id$ *) + +open Util +open Generic +open Term + +(* Discrimination nets of terms. + See the module dn.ml for further explanations. + Eduardo (5/8/97) *) + +type lbl = + | TERM of constr + | DOPER of sorts oper + | DLAMBDA + +type 'a t = (lbl,constr,'a) Dn.t + +(*If we have: f a b c ..., decomp gives: (f,[a;b;c;...])*) + +let decomp = + let rec decrec acc = function + | DOPN(AppL,cl) -> decrec (array_app_tl cl acc) (array_hd cl) + | DOP2(Cast,c1,_) -> decrec acc c1 + | c -> (c,acc) + in + decrec [] + +let constr_pat_discr t = + if not(occur_meta t) then + None + else + match decomp t with + (* | DOPN(Const _,_) as c,l -> Some(TERM c,l) *) + | DOPN(MutInd _,_) as c,l -> Some(TERM c,l) + | DOPN(MutConstruct _,_) as c,l -> Some(TERM c,l) + | VAR _ as c,l -> Some(TERM c,l) + | c -> None + +let constr_val_discr t = + match decomp t with + (* DOPN(Const _,_) as c,l -> Some(TERM c,l) *) + | DOPN(MutInd _,_) as c,l -> Some(TERM c,l) + | DOPN(MutConstruct _,_) as c,l -> Some(TERM c,l) + | VAR _ as c,l -> Some(TERM c,l) + | c -> None + +(* Les deux fonctions suivantes ecrasaient les precedentes, + ajout d'un suffixe _nil CP 16/08 *) + +let constr_pat_discr_nil t = + match constr_pat_discr t with + | None -> None + | Some (c,_) -> Some(c,[]) + +let constr_val_discr_nil t = + match constr_val_discr t with + | None -> None + | Some (c,_) -> Some(c,[]) + +let create () = Dn.create constr_pat_discr + +let add = Dn.add +let rmv = Dn.rmv + +let lookup dn t = Dn.lookup dn constr_val_discr t + +let app f dn = Dn.app f dn diff --git a/tactics/termdn.mli b/tactics/termdn.mli new file mode 100644 index 0000000000..95cfc62438 --- /dev/null +++ b/tactics/termdn.mli @@ -0,0 +1,27 @@ + +(* $Id$ *) + +(*i*) +open Generic +open Term +(*i*) + +(* Discrimination nets of terms. *) + +type lbl = + | TERM of constr + | DOPER of sorts oper + | DLAMBDA + +type 'a t = (lbl,constr,'a) Dn.t + +val create : unit -> 'a t + +val add : 'a t -> (constr * 'a) -> 'a t +val rmv : 'a t -> (constr * 'a) -> 'a t + +val lookup : 'a t -> constr -> (constr * 'a) list +val app : ((constr * 'a) -> unit) -> 'a t -> unit + +val constr_pat_discr : constr -> (lbl * constr list) option +val constr_val_discr : constr -> (lbl * constr list) option |
