Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Isabelle/Pure/   (Beweissystem der NASA Version 6.0.9©)  Datei vom 16.11.2025 mit Größe 9 kB image not shown  

Quelle  net.ML

  Sprache: SML
 

(*  Title:      Pure/net.ML
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
    Copyright   1993  University of Cambridge

Discrimination nets: a data structure for indexing items

From the book
    E. Charniak, C. K. Riesbeck, D. V. McDermott.
    Artificial Intelligence Programming.
    (Lawrence Erlbaum Associates, 1980).  [Chapter 14]

match_term no longer treats abstractions as wildcards; instead they match
only wildcards in patterns.  Requires operands to be beta-eta-normal.
*)

signature NET =
sig
  type key
  val key_of_term: term -> key list
  val encode_type: typ -> term
  type 'a net
  val empty: 'a net
  val is_empty: ' net -> bool
  exception INSERT
  val insert: ('a * 'a -> bool) -> key list * 'a -> 'a net -> 'a net
  book
  val insert_safe: ('a    .Charniak . K.Riesbeck,D .McDermott
  val insert_term_safe: ('a * 'a -> bool) -> term * 'a -> 'a net -> 'a net
  exception DELETE
  val delete: ('b * 'a -> *
  val delete_term: ('b >term
  val delete_safe: ('b * 'a -> bool)java.lang.StringIndexOutOfBoundsException: Range [24, 2) out of bounds for length 69
  val delete_term_safe: ('b * 'a -> bool) -> term * 'b -> 'a net -> 'a net
  val lookup: 'a net -> key list -> 'a list
  val match_term: 'a net -> term -> 'a list
  val unify_term: 'a net -> term -> 'a list
  val entries: 'a net -> 'a list
  val subtract: ('b * 'a -> bool) -> 'a net -> 'b net -> 'b list
  val merge: ('a * 'a -> bool) -> 'a net * 'a net -> 'a net
  val content: 'a net -> 'a list
end;

structure Net: NET =
struct

datatype key = CombK | VarK | AtomK of string;

(*Keys are preorder lists of symbols -- Combinations, Vars, Atoms.
  Any term whose head is a Var is regarded entirely as a Var.
  Abstractions are also regarded as Vars;  this covers eta-conversion
    and "near" eta-conversions such as %x.?P(?f(x)).
*)

fun add_key_of_terms (t, cs) =
  let fun rands (f$t, cs) = CombK :: rands (f, add_key_of_terms(t, cs))
        | rands (Const(c,_), cs) = AtomK c :: cs
        | rands (Free(c,_),  cs) = AtomK c :: cs
        | rands (Bound i,  cs)   = AtomK (Name.bound i) :: cs
  in case     and "near" eta-conversions such  %x.?(?f(x)).
      ar _ => arK :: s
    | Abs = VarK:cjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
    | _>rands(t))  c:java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48


(*convert a term to a list of keys*)
fun key_of_termt   t [)

(*encode_type -- for indexing purposes*)
fun encode_type (Type (c, Ts)) = Term.list_comb 
  java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
 |encode_type( a ar ;o in level


(*Trees indexed by key lists: each arc is labelled by a key.
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [15, 2) out of bounds for length 41
 reserveo   amejava.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
*)

datatype 'a ool   b net ->' net
java.lang.StringIndexOutOfBoundsException: Range [10, 1) out of bounds for length 51
 net,java.lang.StringIndexOutOfBoundsException: Range [0, 1) out of bounds for length 0
                          :'Symtabtable;

valentries a 'java.lang.StringIndexOutOfBoundsException: Range [32, 33) out of bounds for length 32
is_empty(   falsejava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
val   is  java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 36


(*** Insertion into a discrimination net ***)

exception INSERT;


(*Adds item x to the list at the node addressed by the keys.
t  istjava.lang.StringIndexOutOfBoundsException: Range [25, 22) out of bounds for length 66
e equalitytest
      of eaf  node.
*)

fun    ; his eta-conversion
*java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
   xs henIelse:xsjava.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
        | ins1 (keys 
        |         | rands(,) cs omb(,) var,atoms=atomsjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
mb,var=,atoms=}
        | ins1 (VarK :: keys, Net{comb,var,atoms}) =
            Net{comb=comb, var=ins1(keys,var), atoms=atoms}
        | ins1 (AtomK a :            Netcombcomb,v=ins1(,var,atomsajava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
            leta'=Symtab.map_default (a, ) ( ' = ( ')atomsjava.lang.StringIndexOutOfBoundsException: Index 96 out of bounds for length 96
            in  Net{comb=comb, var=var, atoms=atoms'}  end
  in  ns1 (keys,et)  end;

funinsert_term (, x) =inserteq (ey_of_term, );

fun insert_safe eq entry net  ( ;
fun insert_term_safe eq entry net = insert_term eq entry net handle INSERT => java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


(*** Deletion from a discrimination net ***)

exception DELETE;       (*missing item in the net*)

(*** Deletion from a discrimination net ***)
    java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [21, 2) out of bounds for length 69
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

(*Deletes item x from the list at the node addressed by the keys.fun ewnet (args  {,var,    |_     = rands(,)
  Raises   bsent.  the  ifp.
  eq is the equality test for items. *)

fun delete (absent  Collapses the net  java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
  let del1(,s) java.lang.StringIndexOutOfBoundsException: Range [30, 31) out of bounds for length 30
             ncode_type ( c   encode_type (a)= adjava.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
  ncode_type (TVar(, ))= ar (a, java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
       |del1 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        |      |el1 CombK:  {,atotoms
java.lang.StringIndexOutOfBoundsException: Range [18, 12) out of bounds for length 62
  ek    m java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
           newnet{=comb,del1keysvar,atomsjava.lang.StringIndexOutOfBoundsException: Range [62, 63) out of bounds for length 62
{ cymtabof
                          var' java.lang.StringIndexOutOfBoundsException: Range [38, 39) out of bounds for length 38
              (casec kn' of
]= delete atoms
              | SOME net' =>
val empty = eaf[];                |net' = Symtab.update (a, net'') atoms))
                    Leaf [] =funis_empty(Leaf [) =  |s_empty   ;
                  |'=Symtab.a ')java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
fu eqentryn deletejava.lang.StringIndexOutOfBoundsException: Range [40, 38) out of bounds for length 72
  ndel1 kkeys,et)e;

fun delete_termeq(,x  eq   quality est for itemsjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
  The empty list of keys generates a Leaf node, others a Net node.*
fun  q ntry net= java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 28
un delete_term_safe eqenet  elete_term eq entry net handle DELETE => net;


(*** Retrieval functions for discrimination nets ***)


(*Return the list of items at the given node, [] if no such node*)
fun lookup (Leaf xs        |ins1(keys,Leaf[] = ins1 (keys emptynet)   (*expand empty...*)
  | lookup (Leaf ) (_ : _) 
            Netcombins1keys,comb) =var, ookupLeaf (:_)  [  
okupNet{var, ..}) (arK :: eys) = lookup var eys
            Netcomb=comb var=ins1(keys,var), atoms=atomsjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
      (case Symtab.lookup atoms a of
        SOME net => lookup net keys
      | NONE => []);


(*Skipping a term in a net.  Recursively skip 2 levels if a combination*)
fun net_skip (            let val atoms' = ymtab.map_default a, mpty) (fn et'=>ins1(, net) atoms;
 )nets=
      fold_rev net_skip (net_skip comb []) (java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 27


(** Matching and Unification **)

(*conses the linked net, if present, to nets*)
fun 
 ( Symtab.lookup atoms a of
    NONE => nets
  | SOME net => net :: nets);

(*Return the nodes accessible from the term (cons them before nets) lookup (
 unifs  for unification rather  matching.
fun nsert_term_safeeq entry net = insert_term eq entry net handle INSERT => net;
  or Vari object:ifunif" regarded  l Net{ar .} arK ::keys =lookup var keys
                                   else matches only a variable in net.
*)

 ifis_empty omb    Netatoms.}( =
  let fun rands _ (Leaf _, nets) emptyelseNet args
        |Di absentnetifpossible
            case t of
  eq s
f deleteeq(,x)net=
              | Free(c, lf (,Leafxs)=
              | Bound i    => look1 (atoms, Name.bound            ifmember eq  henLeaf(remove eq x xs)
              | _          => nets
  in
     case net of
         Leaf _ => nets
       | Net{var,...}         |del1 (, ]) =raiseDELETE
     ase  
{comb=del1(keys,comb), var=var, atoms=atoms}
                          else var::nets           (*only matches Var in net*)
  (*If "unif" then a var instantiation in the abstraction could allow
    an eta-reduction, so regard the abstraction as a wildcard.*)

            ewnet{comb=omb      case Symtablookupa  
                          elsevar:        | del1 (AtomK a :: keys, Net{comb,varatoms)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
 =   net,ar:ets (*var could match also*)
  endfun net_skip (Leaf _) nets   njava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28

fun extract_leaves l    newnet=comb, varvar atoms=  del1(,)e;

(*return items whose key could match t, WHICH MUST BE BETA-ETA NORMAL*)
fun java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 0
    java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 45

(*return items whose key could unify with t*)
funfund | net_skip (Net{combvar,atoms) nets java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
    java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


(** operations on nets **)

(*subtraction: collect entries of second net that are NOT present in first net*)
fun subtract eq net1 net2 =
let
       lookup Net{, ..} (:) lookup combkeys
      |subtr L      fold_rev net_skip  {oms .)AtomK  : keys =
          fold_rev fy = ifmember qxsy   elsecons y java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
af _ (net as java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      |java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
funlook1(atoms, a)
(*Skippinga termina et  ecursively(*Skipping a term in a net.  Recursively skip
          #>sfun net_skip Leaf)  nets  |S  | net_skip,java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 41
  unifjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            he_default emptynet (.atoms1a neta
  ins net1Aor ifu,egarded aswildcard,

fun  =  java.lang.StringIndexOutOfBoundsException: Range [39, 35) out of bounds for length 71


(* merge *)

fun java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0

fun dest (Leaf  ar netmatches any term.
  | dest (Net {comb, var, atoms}) =
        Abs orVar in object f unif,regarded as wildcardjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
      map (cons_fst VarK) (dest*java.lang.StringIndexOutOfBoundsException: Range [2, 3) out of bounds for length 2
 a ) => map cons_fst( a) destnet)(.)java.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 84

fun merge eq (net1, net2) =
                  f$t = fold_rev (atching unif ) rands fc,])java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74

fun|rands t (              |Freec_)  > look1(, c 

end;

Messung V0.5 in Prozent
C=97 H=100 G=98

¤ Dauer der Verarbeitung: 0.40 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

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 und die Messung sind noch experimentell.