Modified lines:  264
Added line:  245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 279, 280, 281, 282, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370
Removed line:  214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324
Generated by diff2html
© Yves Bailly, MandrakeSoft S.A. 2001
diff2html is licensed under the GNU GPL.

  support-v1/basic.lisp       support-v2.1/basic.lisp
  507 lines
16148 bytes
Last modified : Wed Jun 29 13:31:22 2005

      515 lines
16236 bytes
Last modified : Wed Jun 29 13:32:19 2005

1 ;;; Mode: Lisp; Package: ocml     1 ;;; Mode: Lisp; Package: ocml
2     2
3 ;;; The Open University     3 ;;; The Open University
4     4
5 (in-package "OCML")     5 (in-package "OCML")
6     6
7 (in-ontology akt-support-ontology)     7 (in-ontology akt-support-ontology)
8     8
9 ;;;Here we introduce a number of definitions, which provide     9 ;;;Here we introduce a number of definitions, which provide
10 ;;;the basic representational layer to define entities in the ontology.     10 ;;;the basic representational layer to define entities in the ontology.
11 ;;;Here we include basic data types, such     11 ;;;Here we include basic data types, such
12 ;;;as strings, lists, sets and numbers, as well as basic logical concepts, such     12 ;;;as strings, lists, sets and numbers, as well as basic logical concepts, such
13 ;;;as FUNCTION and RELATION. It also provides equality constructs and a meta-level     13 ;;;as FUNCTION and RELATION. It also provides equality constructs and a meta-level
14 ;;;relation HOLDS, which takes a rel, say ?rel, and a number of args, say ?args     14 ;;;relation HOLDS, which takes a rel, say ?rel, and a number of args, say ?args
15 ;;;and it is satisfied iff ?rel is satisfied by ?args.     15 ;;;and it is satisfied iff ?rel is satisfied by ?args.
16 ;;;The advantage of expliciting including here the representational layer     16 ;;;The advantage of expliciting including here the representational layer
17 ;;;for the set of AKT ontologies is that these become completely self-contained:     17 ;;;for the set of AKT ontologies is that these become completely self-contained:
18 ;;;all the notions required to specify any concept in the ontology are themselves     18 ;;;all the notions required to specify any concept in the ontology are themselves
19 ;;;to be found in the ontologies     19 ;;;to be found in the ontologies
20     20
21 ;;;BASIC UNIFICATION MECHANISMS     21 ;;;BASIC UNIFICATION MECHANISMS
22     22
23     23
24 ;;;RELATION =     24 ;;;RELATION =
25 (def-relation = (?x ?y)     25 (def-relation = (?x ?y)
26    "True if ?x and ?y do unify"     26    "True if ?x and ?y do unify"
27    :lisp-fun #'(lambda ( x y env)     27    :lisp-fun #'(lambda ( x y env)
28                  (Let ((result (unify x y env)))     28                  (Let ((result (unify x y env)))
29                    (if (eq result :fail)     29                    (if (eq result :fail)
30                        :fail     30                        :fail
31                        (List result)))))     31                        (List result)))))
32     32
33 ;;;RELATION ==     33 ;;;RELATION ==
34 (def-relation == (?x ?y)     34 (def-relation == (?x ?y)
35    "True if ?x and ?y do unify and they also have the same structure.     35    "True if ?x and ?y do unify and they also have the same structure.
36     This means that either they are both atoms, or they are lists with     36     This means that either they are both atoms, or they are lists with
37     the same structure"     37     the same structure"
38    :lisp-fun #'(lambda ( x y env)     38    :lisp-fun #'(lambda ( x y env)
39                  (Let ((result (unify-strong x y env)))     39                  (Let ((result (unify-strong x y env)))
40                    (if (eq result :fail)     40                    (if (eq result :fail)
41                        :fail     41                        :fail
42                        (List result)))))     42                        (List result)))))
43     43
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;     44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45     45
46 (def-class LIST (Intangible-Thing) ?x     46 (def-class LIST (Intangible-Thing) ?x
47    "A class representing lists."     47    "A class representing lists."
48    :iff-def (or (= ?x nil)     48    :iff-def (or (= ?x nil)
49                 (= ?x (?a . ?b)))     49                 (= ?x (?a . ?b)))
50    :prove-by (or (= ?x nil)     50    :prove-by (or (= ?x nil)
51                 (and (variable-bound ?x)     51                 (and (variable-bound ?x)
52                      (= ?x (?a . ?b))))     52                      (= ?x (?a . ?b))))
53    :no-proofs-by (:iff-def))     53    :no-proofs-by (:iff-def))
54     54
55     55
56 (def-instance NIL list     56 (def-instance NIL list
57   "The empty list")     57   "The empty list")
58     58
59 (def-relation NULL (?l)     59 (def-relation NULL (?l)
60    "True if ?l is the empty list"     60    "True if ?l is the empty list"
61    :iff-def (= ?l nil))     61    :iff-def (= ?l nil))
62     62
63 (def-function FIRST (?l)     63 (def-function FIRST (?l)
64    "Takes the first element of a list. If the list is empty     64    "Takes the first element of a list. If the list is empty
65     the function returns :nothing"     65     the function returns :nothing"
66   :constraint (list ?l)     66   :constraint (list ?l)
67   :body (if (== ?l (?a . ?b))     67   :body (if (== ?l (?a . ?b))
68             ?a     68             ?a
69             :nothing))     69             :nothing))
70     70
71 (def-function REST (?l)     71 (def-function REST (?l)
72    "Takes a list as argument, say ?l, removes the first element of ?s     72    "Takes a list as argument, say ?l, removes the first element of ?s
73     and returns the resulting list. If ?l = nil, then :nothing is returned"     73     and returns the resulting list. If ?l = nil, then :nothing is returned"
74   :constraint (list ?l)     74   :constraint (list ?l)
75   :body (if (== ?l (?a . ?b))     75   :body (if (== ?l (?a . ?b))
76             ?b     76             ?b
77             :nothing))     77             :nothing))
78     78
79 (def-function LIST-OF (&rest ?els)     79 (def-function LIST-OF (&rest ?els)
80    "This is the primitive list constructor. It is implemented in terms of     80    "This is the primitive list constructor. It is implemented in terms of
81     the underlying LISP list construction primitive, LIST"     81     the underlying LISP list construction primitive, LIST"
82    :lisp-fun #'(lambda (&rest els)     82    :lisp-fun #'(lambda (&rest els)
83                  (apply #'list els)))     83                  (apply #'list els)))
84     84
85 (def-function APPEND (?l1 &rest ?ls)     85 (def-function APPEND (?l1 &rest ?ls)
86   "Appends together a number of lists. I cannot be bothered giving its operational     86   "Appends together a number of lists. I cannot be bothered giving its operational
87    spec...so you only get a lisp attachment"     87    spec...so you only get a lisp attachment"
88   :constraint (and (list ?l1)(every ?ls list))     88   :constraint (and (list ?l1)(every ?ls list))
89    :lisp-fun #'append)     89    :lisp-fun #'append)
90     90
91     91
92 (def-function CONS (?el ?l)     92 (def-function CONS (?el ?l)
93   "Adds ?el to the beginning of list ?l.     93   "Adds ?el to the beginning of list ?l.
94    Note that this cons is less generic than the lisp function with the same name.     94    Note that this cons is less generic than the lisp function with the same name.
95    Here the 2nd argument must be a list (in lisp, it can also be an atom)."     95    Here the 2nd argument must be a list (in lisp, it can also be an atom)."
96   :constraint (list ?l)     96   :constraint (list ?l)
97   :body (append (list-of ?el)     97   :body (append (list-of ?el)
98                 ?l))     98                 ?l))
99     99
100     100
101 (def-function LENGTH (?l)     101 (def-function LENGTH (?l)
102   "Computes the number of elements in a list"     102   "Computes the number of elements in a list"
103   :constraint (list ?l)     103   :constraint (list ?l)
104   :body (if (= ?l nil)     104   :body (if (= ?l nil)
105           0     105           0
106           (if (== ?l (?first . ?rest))     106           (if (== ?l (?first . ?rest))
107             (+ 1     107             (+ 1
108                (length ?rest)))))     108                (length ?rest)))))
109     109
110 (def-function REMOVE1 (?el ?l)     110 (def-function REMOVE1 (?el ?l)
111   "Removes the first occurrence of ?el in ?l and returns the resulting list.     111   "Removes the first occurrence of ?el in ?l and returns the resulting list.
112    If ?el is not a member of ?l then the result is ?l"     112    If ?el is not a member of ?l then the result is ?l"
113   :constraint (list ?l)     113   :constraint (list ?l)
114   :body (if (= ?l nil)     114   :body (if (= ?l nil)
115           ?l     115           ?l
116           (if (== ?l (?el . ?rest))     116           (if (== ?l (?el . ?rest))
117             ?rest     117             ?rest
118             (if (== ?l (?first . ?rest))     118             (if (== ?l (?first . ?rest))
119               (cons ?first     119               (cons ?first
120                     (remove1 ?el ?rest))))))     120                     (remove1 ?el ?rest))))))
121     121
122 (def-function REMOVE (?el ?l)     122 (def-function REMOVE (?el ?l)
123   "Removes all occurrences of ?el in ?l and returns the resulting list.     123   "Removes all occurrences of ?el in ?l and returns the resulting list.
124    If ?el is not a member of ?l then the result is ?l"     124    If ?el is not a member of ?l then the result is ?l"
125   :constraint (list ?l)     125   :constraint (list ?l)
126   :body (if (= ?l nil)     126   :body (if (= ?l nil)
127           ?l     127           ?l
128           (if (== ?l (?el . ?rest))     128           (if (== ?l (?el . ?rest))
129             (remove ?el ?rest)     129             (remove ?el ?rest)
130             (if (== ?l (?first . ?rest))     130             (if (== ?l (?first . ?rest))
131               (cons ?first     131               (cons ?first
132                     (remove ?el ?rest))))))     132                     (remove ?el ?rest))))))
133     133
134     134
135     135
136     136
137 (def-relation MEMBER (?el ?list)     137 (def-relation MEMBER (?el ?list)
138   "A relation to check whether something is a member of a list"     138   "A relation to check whether something is a member of a list"
139   :constraint (list ?list)     139   :constraint (list ?list)
140   :iff-def (or (== ?list (?el . ?rest))     140   :iff-def (or (== ?list (?el . ?rest))
141                (and (== ?list (?first . ?rest))     141                (and (== ?list (?first . ?rest))
142                     (member ?el ?rest))))     142                     (member ?el ?rest))))
143     143
144 (def-relation EVERY (?l ?rel)     144 (def-relation EVERY (?l ?rel)
145   "True if for each term in ?l, say ?term, (holds ?rel ?term) is true.     145   "True if for each term in ?l, say ?term, (holds ?rel ?term) is true.
146    For instance, (every '(1 2 3) 'number) is satisfied, while     146    For instance, (every '(1 2 3) 'number) is satisfied, while
147    (every '(1 2 pippo) 'number) is not"     147    (every '(1 2 pippo) 'number) is not"
148   :constraint (unary-relation ?rel)     148   :constraint (unary-relation ?rel)
149   :iff-def (or (= ?l nil)     149   :iff-def (or (= ?l nil)
150                (and (== ?l (?first . ?rest))     150                (and (== ?l (?first . ?rest))
151                     (holds ?rel ?first)     151                     (holds ?rel ?first)
152                     (every ?rest ?rel))))     152                     (every ?rest ?rel))))
153     153
154 ;;;FUNCTION BUTLAST     154 ;;;FUNCTION BUTLAST
155 (def-function BUTLAST (?list)     155 (def-function BUTLAST (?list)
156    "Returns all the element of ?list, except the last one.     156    "Returns all the element of ?list, except the last one.
157     If ?list = NIL, then :nothing is returned. If ?list has     157     If ?list = NIL, then :nothing is returned. If ?list has
158     length 1, then nil is returned"     158     length 1, then nil is returned"
159    :constraint (list ?l)     159    :constraint (list ?l)
160    :body (cond ((null ?list) :nothing)     160    :body (cond ((null ?list) :nothing)
161                ((null (rest ?list)) nil)     161                ((null (rest ?list)) nil)
162                ((true)     162                ((true)
163                 (cons (first ?list) (butlast (rest ?list))))))     163                 (cons (first ?list) (butlast (rest ?list))))))
164     164
165     165
166 ;;;FUNCTION LAST     166 ;;;FUNCTION LAST
167 (def-function LAST (?list)     167 (def-function LAST (?list)
168    "Returns the last element of a list. If ?list is empty     168    "Returns the last element of a list. If ?list is empty
169     then :nothing is returned"     169     then :nothing is returned"
170   :constraint (list ?list)     170   :constraint (list ?list)
171   :body (cond ((null ?list) :nothing)     171   :body (cond ((null ?list) :nothing)
172               ((null (rest ?list)) (first ?list))     172               ((null (rest ?list)) (first ?list))
173               ((true) (last (rest ?list)))))     173               ((true) (last (rest ?list)))))
174     174
175     175
176 ;;;;;;;;;;;;;;;;;;;;;;;;     176 ;;;;;;;;;;;;;;;;;;;;;;;;
177     177
178     178
179 ;;;SET     179 ;;;SET
180 (def-class SET (Intangible-Thing)     180 (def-class SET (Intangible-Thing)
181   "A set is something which is not an individual. In cyc sets are distinguished     181   "A set is something which is not an individual. In cyc sets are distinguished
182    from collections. Here we just use the term generically to refer to     182    from collections. Here we just use the term generically to refer to
183    something which denotes a collection of elements, whether abstract or     183    something which denotes a collection of elements, whether abstract or
184    concrete.     184    concrete.
185    Functions and relations represent sets. ")     185    Functions and relations represent sets. ")
186     186
187 (def-axiom BASIC-SET-TYPES-ARE-DISJOINT     187 (def-axiom BASIC-SET-TYPES-ARE-DISJOINT
188   "There are three basic types of sets in our ontology, functions     188   "There are three basic types of sets in our ontology, functions
189    relations and enumerated sets and these do not intersect"     189    relations and enumerated sets and these do not intersect"
190   (subclass-partition set (set-of function relation enumerated-set)))     190   (subclass-partition set (set-of function relation enumerated-set)))
191     191
192     192
193 (def-function SET-OF (&rest ?args)     193 (def-function SET-OF (&rest ?args)
194   "This is the basic set constructor to create a set by enumerating its elements.     194   "This is the basic set constructor to create a set by enumerating its elements.
195    For instance, (setof 1 2) denotes the set {1 2}.     195    For instance, (setof 1 2) denotes the set {1 2}.
196    We represent such a set as a list whose first item is :set"     196    We represent such a set as a list whose first item is :set"
197   :body (cons :set ?args))     197   :body (cons :set ?args))
198     198
199     199
200 (def-class ENUMERATED-SET (set) ?x     200 (def-class ENUMERATED-SET (set) ?x
201   "A set represented as (:set-of el1 el_2...el_n), where no el_i is repeated"     201   "A set represented as (:set-of el1 el_2...el_n), where no el_i is repeated"
202   :constraint (list ?x)     202   :constraint (list ?x)
203   :iff-def (and (= ?x (:set . ?elements))     203   :iff-def (and (= ?x (:set . ?elements))
204                 (not (exists ?el     204                 (not (exists ?el
205                              (and (member ?el ?elements)     205                              (and (member ?el ?elements)
206                                   (member ?el (remove1 ?el ?elements))))))     206                                   (member ?el (remove1 ?el ?elements))))))
207   :prove-by (and (variable-bound ?x)     207   :prove-by (and (variable-bound ?x)
208                  (= ?x (:set . ?elements))     208                  (= ?x (:set . ?elements))
209                  (not (exists ?el     209                  (not (exists ?el
210                               (and (member ?el ?elements)     210                               (and (member ?el ?elements)
211                                    (member ?el (remove1 ?el ?elements))))))     211                                    (member ?el (remove1 ?el ?elements))))))
212   :no-proofs-by (:iff-def))     212   :no-proofs-by (:iff-def))
213     213
214        
215        
216 (def-class INDIVIDUAL (Thing) ?x   3e)    
217   "Something which is not a set. For instance an instance of a class."        
218   :iff-def (not (set ?x))        
219        
220   ;;;the definitions below are effective ways to prove whether        
221   ;;;somebody is an individual in OCML        
222   :prove-by (or        
223              (and (variable-bound ?x)        
224                   (not (set ?x)))        
225              (= ?x nil))        
226   :no-proofs-by (:iff-def)) ;;;:iff-def above is not a good way to prove things!        
227        
228        
229        
230 (def-relation ELEMENT-OF (?el ?set)     214 (def-relation ELEMENT-OF (?el ?set)
231   "A relation to check whether something is an element of a set.     215   "A relation to check whether something is an element of a set.
232    Note that because functions and relations are sets, we can prove     216    Note that because functions and relations are sets, we can prove
233    whether a tuple satisfies a relation or a function using ELEMENT-OF.     217    whether a tuple satisfies a relation or a function using ELEMENT-OF.
234    For instance, (element-of '(1 2 3) '+) is satisfied because     218    For instance, (element-of '(1 2 3) '+) is satisfied because
235    1+2=3 - see definitions below for an operationalization of this approach")     219    1+2=3 - see definitions below for an operationalization of this approach")
236     220
237 (def-rule ELEMENT-OF-ENUMERATED-SET     221 (def-rule ELEMENT-OF-ENUMERATED-SET
238   "An operationalization of element-of, which works with sets represented as lists."     222   "An operationalization of element-of, which works with sets represented as lists."
239   ((element-of ?el ?l) if     223   ((element-of ?el ?l) if
240    (enumerated-set ?l)     224    (enumerated-set ?l)
241    (member ?el (rest ?l))))     225    (member ?el (rest ?l))))
242     226
243 (def-rule ELEMENT-OF-SET-AS-RELATION     227 (def-rule ELEMENT-OF-SET-AS-RELATION
244   "A tuple, say <t1 t2 t3> is an element of relation r iff     228   "A tuple, say <t1 t2 t3> is an element of relation r iff
245    (holds r ti t2 t3) is satisfied"     229    (holds r ti t2 t3) is satisfied"
246   ((element-of ?tuple ?rel) if     230   ((element-of ?tuple ?rel) if
247    (relation ?rel)     231    (relation ?rel)
248    (List ?tuple)     232    (List ?tuple)
249    (sentence-holds (cons ?rel ?tuple))))     233    (sentence-holds (cons ?rel ?tuple))))
250     234
251 (def-rule ELEMENT-OF-SET-AS-FUNCTION     235 (def-rule ELEMENT-OF-SET-AS-FUNCTION
252   "A tuple, say <t1 t2 t3> is an element of function f iff     236   "A tuple, say <t1 t2 t3> is an element of function f iff
253    (= (apply f ti t2) t3) is satisfied"     237    (= (apply f ti t2) t3) is satisfied"
254   ((element-of ?el ?fun) if     238   ((element-of ?el ?fun) if
255    (function ?fun)     239    (function ?fun)
256    (list ?el)     240    (list ?el)
257    (= (last ?el) (apply ?fun (butlast ?el)))))     241    (= (last ?el) (apply ?fun (butlast ?el)))))
258     242
259     243
260     244
      3c) 245 ;;;UNION - The union of a number of sets
        246 ;;;For instance
        247 ;;; (ocml-eval (union (set-of 1 2)(set-of 1 2 3)))
        248 ;;; (:SET 3 2 1)
      2 249 (def-function UNION (&rest ?sets)
        250   :constraint (every ?sets set)
        251   :body (apply set-of (setofall ?x
        252                                 (exists ?set (and (member ?set ?sets)
        253                                                   (element-of ?x ?set))))))
        254
        255
      2 256 (def-function INTERSECTION (&rest ?sets)
        257   :constraint (every ?sets set)
        258   :body (in-environment ((?all . (apply union ?sets)))
        259              (apply set-of (setofall ?x
        260                    (and (element-of ?x ?all)
        261                         (not (exists ?set
        262                                      (and (member ?set ?sets)
        263                                           (not (element-of ?x ?set))))))))))
        264
        265
        266
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;     267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262     268
263 ;;;NUMBER     269 ;;;NUMBER
264 (def-class NUMBER (individual Intangible-thing)   3d) 270 (def-class NUMBER (Quantity)
265   "The class of all numbers"     271   "The class of all numbers"
266   :lisp-fun #'(lambda (x env)     272   :lisp-fun #'(lambda (x env)
267                  (let ((y (unbound-variable? x env)))     273                  (let ((y (unbound-variable? x env)))
268                    (if y ;;if y is unbound we return a 'sample' number     274                    (if y ;;if y is unbound we return a 'sample' number
269                      (list (cons (cons y 0) env))     275                      (list (cons (cons y 0) env))
270                      (if (numberp (instantiate x env)) ;;;make sure to instantiate x     276                      (if (numberp (instantiate x env)) ;;;make sure to instantiate x
271                        (list env)     277                        (list env)
272                        :fail)))))     278                        :fail)))))
        279
      1 280 (def-class REAL-NUMBER (number))
        281
      1 282 (def-class INTEGER (real-number))
273     283
274     284
275 ;;; RELATION <     285 ;;; RELATION <
276 (def-relation < (?x ?y)     286 (def-relation < (?x ?y)
277    "A predicate to test whether a number is less than another"     287    "A predicate to test whether a number is less than another"
278    :constraint (and (number ?x)(number ?y))     288    :constraint (and (number ?x)(number ?y))
279    :lisp-fun #'(lambda (x y env)     289    :lisp-fun #'(lambda (x y env)
280                  (if (< (instantiate x env)     290                  (if (< (instantiate x env)
281                         (instantiate y env))     291                         (instantiate y env))
282 (List env)     292 (List env)
283 :fail)))     293 :fail)))
284 ;;;RELATION >     294 ;;;RELATION >
285 (def-relation > (?x ?y)     295 (def-relation > (?x ?y)
286    "A predicate to test whether a number is greater than another"     296    "A predicate to test whether a number is greater than another"
287    :constraint (and (number ?x)(number ?y))     297    :constraint (and (number ?x)(number ?y))
288    :lisp-fun #'(lambda (x y env)     298    :lisp-fun #'(lambda (x y env)
289                  (if (> (instantiate x env)     299                  (if (> (instantiate x env)
290                         (instantiate y env))     300                         (instantiate y env))
291 (List env)     301 (List env)
292 :fail)))     302 :fail)))
293     303
294     304
295 (def-class POSITIVE-NUMBER (number) ?x     305 (def-class POSITIVE-NUMBER (number) ?x
296   :iff-def (and (number ?x)     306   :iff-def (and (number ?x)
297                 (> ?x 0)))     307                 (> ?x 0)))
298     308
299 (def-class NEGATIVE-NUMBER (number) ?x     309 (def-class NEGATIVE-NUMBER (number) ?x
300   :iff-def (and (number ?x)     310   :iff-def (and (number ?x)
301                 (< ?x 0)))     311                 (< ?x 0)))
302     312
303 (def-class NON-NEGATIVE-NUMBER (number) ?x     313 (def-class NON-NEGATIVE-NUMBER (number) ?x
304    :iff-def (and (number ?x)     314    :iff-def (and (number ?x)
305                  (not (negative-number ?x))))     315                  (not (negative-number ?x))))
306     316
307     317
308 (def-axiom POS-NEG-NUMBERS-EXHAUSTIVE-PARTITION     318 (def-axiom POS-NEG-NUMBERS-EXHAUSTIVE-PARTITION
309   (exhaustive-subclass-partition number (set-of positive-number negative-number)))     319   (exhaustive-subclass-partition number (set-of positive-number negative-number)))
310     320
311     321
312        
313        
314 (def-class INTEGER (number)   2    
315    "The class of all integers"        
316    :lisp-fun #'(lambda (x env)        
317                  (let ((y (unbound-variable? x env)))        
318                    (if y ;;if y is unbound we return a 'sample' integer        
319                      (list (cons (cons y 0) env))        
320                      (if (integerp (instantiate x env)) ;;;make sure to instantiate x        
321                        (list env)        
322                        :fail)))))        
323        
324        
325 (def-class POSITIVE-INTEGER (integer) ?x     322 (def-class POSITIVE-INTEGER (integer) ?x
326   :iff-def (and (integer ?x)     323   :iff-def (and (integer ?x)
327                 (> ?x 0)))     324                 (> ?x 0)))
328     325
329 (def-class NEGATIVE-INTEGER (integer) ?x     326 (def-class NEGATIVE-INTEGER (integer) ?x
330   :iff-def (and (integer ?x)     327   :iff-def (and (integer ?x)
331                 (< ?x 0)))     328                 (< ?x 0)))
332     329
333 (def-class NON-NEGATIVE-INTEGER (integer) ?x     330 (def-class NON-NEGATIVE-INTEGER (integer) ?x
334   :iff-def (and (integer ?x)     331   :iff-def (and (integer ?x)
335                 (not (negative-integer ?x))))     332                 (not (negative-integer ?x))))
336     333
337     334
338 (def-function + (?X &rest ?y)     335 (def-function + (?X &rest ?y)
339   "Adds numbers"     336   "Adds numbers"
340   :constraint (and (number ?x) (number ?y))     337   :constraint (and (number ?x) (number ?y))
341   :lisp-fun #'+)     338   :lisp-fun #'+)
342     339
343 (def-function * (?X ?y)     340 (def-function * (?X ?y)
344   "Multiplies numbers"     341   "Multiplies numbers"
345   :constraint (and (number ?x) (number ?y))     342   :constraint (and (number ?x) (number ?y))
346    :lisp-fun #'*)     343    :lisp-fun #'*)
347     344
348 (def-function SQUARE (?X)     345 (def-function SQUARE (?X)
349   :constraint (number ?x)     346   :constraint (number ?x)
350   :body (* ?X ?X))     347   :body (* ?X ?X))
351     348
352 (def-function - (?X &rest ?y)     349 (def-function - (?X &rest ?y)
353   "Subtracts numbers"     350   "Subtracts numbers"
354   :constraint (and (number ?x) (number ?y))     351   :constraint (and (number ?x) (number ?y))
355   :lisp-fun #'(lambda (x &rest y)     352   :lisp-fun #'(lambda (x &rest y)
356                 (apply #'- x y)))     353                 (apply #'- x y)))
357     354
358 (def-function / (?X ?y)     355 (def-function / (?X ?y)
359   "Divides numbers"     356   "Divides numbers"
360   :constraint (and (number ?x) (number ?y))     357   :constraint (and (number ?x) (number ?y))
361   :lisp-fun #'/)     358   :lisp-fun #'/)
362     359
        360
        361 (def-function log (?number ?base)
        362   :lisp-fun #'log)
        363
        364 (def-function round (?number) -> ?int
        365   :def (integer ?int)
        366   :lisp-fun #'round)
        367
        368
        369
        370
363 ;;;;;;;;;;;;;;;;;;;;;     371 ;;;;;;;;;;;;;;;;;;;;;
364     372
365 (def-class STRING (individual intangible-thing)     373 (def-class STRING (individual intangible-thing)
366    "A primitive class representing strings"     374    "A primitive class representing strings"
367    :lisp-fun #'(lambda (x env)     375    :lisp-fun #'(lambda (x env)
368                   (let ((y (unbound-variable? x env)))     376                   (let ((y (unbound-variable? x env)))
369                    (if y     377                    (if y
370                      (list (cons (cons y "SAMPLE-STRING") env))     378                      (list (cons (cons y "SAMPLE-STRING") env))
371                      (if (stringp (instantiate x env))     379                      (if (stringp (instantiate x env))
372                        (list env)     380                        (list env)
373                        :fail)))))     381                        :fail)))))
374     382
375 ;;;;;;;;;;;;;;;;;;;;;     383 ;;;;;;;;;;;;;;;;;;;;;
376     384
377 (def-class RELATION (set)     385 (def-class RELATION (set)
378   "The class of defined relations. We assume fixed arity"     386   "The class of defined relations. We assume fixed arity"
379   :lisp-fun #'(lambda (x env)     387   :lisp-fun #'(lambda (x env)
380                  (let ((y (unbound-variable? x env)))     388                  (let ((y (unbound-variable? x env)))
381                    (if y     389                    (if y
382                      (mapcar #'(lambda (rel)     390                      (mapcar #'(lambda (rel)
383                                    (cons (cons y rel) env))     391                                    (cons (cons y rel) env))
384                              (all-relations))     392                              (all-relations))
385                      (if (get-relation (instantiate x env)) ;;;make sure to instantiate x     393                      (if (get-relation (instantiate x env)) ;;;make sure to instantiate x
386                        (list env)     394                        (list env)
387                        :fail)))))     395                        :fail)))))
388     396
389     397
390 (def-class UNARY-RELATION (relation) ?r     398 (def-class UNARY-RELATION (relation) ?r
391   :iff-def (and (relation ?r)     399   :iff-def (and (relation ?r)
392                 (= (arity ?r) 1)))     400                 (= (arity ?r) 1)))
393     401
394     402
395 (def-class BINARY-RELATION (relation) ?r     403 (def-class BINARY-RELATION (relation) ?r
396   :iff-def (and (relation ?r)     404   :iff-def (and (relation ?r)
397                 (= (arity ?r) 2)))     405                 (= (arity ?r) 2)))
398     406
399 (def-relation TRUE ()     407 (def-relation TRUE ()
400   "This is always satisfied"     408   "This is always satisfied"
401    :lisp-fun #'(lambda (env) (list env)))     409    :lisp-fun #'(lambda (env) (list env)))
402     410
403 (def-relation FALSE ()     411 (def-relation FALSE ()
404   "This is never satisfied"     412   "This is never satisfied"
405    :lisp-fun #'(lambda (env) :fail))     413    :lisp-fun #'(lambda (env) :fail))
406     414
407     415
408 (def-function ARITY (?x)     416 (def-function ARITY (?x)
409   "The arity of a function or relation. If a function or relation     417   "The arity of a function or relation. If a function or relation
410    has variable arity, then we treat the last argument as if it were     418    has variable arity, then we treat the last argument as if it were
411    a sequence variable. For instance the argument list for + is     419    a sequence variable. For instance the argument list for + is
412    (?x &rest ?y). In this case we say that + has arity 2.     420    (?x &rest ?y). In this case we say that + has arity 2.
413    It is important to note that OCML does not support relations with variable     421    It is important to note that OCML does not support relations with variable
414    arity. The only exception is HOLDS, which has variable arity and is built in     422    arity. The only exception is HOLDS, which has variable arity and is built in
415    the OCML proof system"     423    the OCML proof system"
416     424
417   :constraint (or (function ?X)(relation ?X))     425   :constraint (or (function ?X)(relation ?X))
418   :body (in-environment     426   :body (in-environment
419           ((?l . (the-schema ?x))     427           ((?l . (the-schema ?x))
420            (?n . (length ?l)))     428            (?n . (length ?l)))
421           (if (every ?l variable)     429           (if (every ?l variable)
422             ?n     430             ?n
423             ;we assume that the only non-var can be &rest     431             ;we assume that the only non-var can be &rest
424             (- ?n 1))))     432             (- ?n 1))))
425     433
426 (def-relation VARIABLE (?x)     434 (def-relation VARIABLE (?x)
427   "True of an OCML variable"     435   "True of an OCML variable"
428   :lisp-fun #'(lambda (x env)     436   :lisp-fun #'(lambda (x env)
429                 (if     437                 (if
430                   (variable? (instantiate x env))     438                   (variable? (instantiate x env))
431                   (list env)     439                   (list env)
432                   :fail)))     440                   :fail)))
433     441
434 (def-relation VARIABLE-BOUND (?var)     442 (def-relation VARIABLE-BOUND (?var)
435   "True if ?var is bound in teh current environment"     443   "True if ?var is bound in teh current environment"
436   :lisp-fun #'(lambda (x env)     444   :lisp-fun #'(lambda (x env)
437                 (if     445                 (if
438                   (unbound-variable? x env)     446                   (unbound-variable? x env)
439                   :fail     447                   :fail
440                   (list env))))     448                   (list env))))
441     449
442 (def-function THE-SCHEMA (?x)     450 (def-function THE-SCHEMA (?x)
443   "The schema of a function or relation"     451   "The schema of a function or relation"
444   :constraint (or (function ?X)(relation ?X))     452   :constraint (or (function ?X)(relation ?X))
445   :body (if (relation ?x)     453   :body (if (relation ?x)
446           (relation-schema ?x)     454           (relation-schema ?x)
447           (if (function ?x)     455           (if (function ?x)
448             (function-schema ?x)     456             (function-schema ?x)
449             :nothing)))     457             :nothing)))
450     458
451 (def-function FUNCTION-SCHEMA (?f)     459 (def-function FUNCTION-SCHEMA (?f)
452   :constraint (function ?f)     460   :constraint (function ?f)
453    :lisp-fun #'(lambda (x)     461    :lisp-fun #'(lambda (x)
454                   (rename-variables (schema (get-function x)))))     462                   (rename-variables (schema (get-function x)))))
455     463
456 (def-function RELATION-SCHEMA (?rel)     464 (def-function RELATION-SCHEMA (?rel)
457   :constraint (relation ?rel)     465   :constraint (relation ?rel)
458   :lisp-fun #'(lambda (x)     466   :lisp-fun #'(lambda (x)
459                  (rename-variables (schema (get-relation x)))))     467                  (rename-variables (schema (get-relation x)))))
460     468
461     469
462     470
463 (def-relation HOLDS (?rel &rest ?args)     471 (def-relation HOLDS (?rel &rest ?args)
464   "A meta-level relation which is true iff the sentence (?rel . ?args) is true.     472   "A meta-level relation which is true iff the sentence (?rel . ?args) is true.
465    The length of ?args must be consistent with the arity of the relation"     473    The length of ?args must be consistent with the arity of the relation"
466   :constraint (and (relation ?r)     474   :constraint (and (relation ?r)
467                    (= (arity ?rel)     475                    (= (arity ?rel)
468                       (length ?args))))     476                       (length ?args))))
469     477
470 (def-relation SENTENCE-HOLDS (?sentence)     478 (def-relation SENTENCE-HOLDS (?sentence)
471   "The same as HOLDS, but takes only one argument, a sentence whose truth     479   "The same as HOLDS, but takes only one argument, a sentence whose truth
472    value is to be checked"     480    value is to be checked"
473   :constraint (and (== ?sentence (?rel . ?args ))     481   :constraint (and (== ?sentence (?rel . ?args ))
474                    (relation ?rel)     482                    (relation ?rel)
475                    (= (arity ?rel)     483                    (= (arity ?rel)
476                       (length ?args)))     484                       (length ?args)))
477   :lisp-fun #'(lambda (sent env)     485   :lisp-fun #'(lambda (sent env)
478                 (ask-top-level     486                 (ask-top-level
479                  (cons 'holds (instantiate sent env))     487                  (cons 'holds (instantiate sent env))
480                  :env env     488                  :env env
481                  :all t)))     489                  :all t)))
482     490
483     491
484     492
485 (def-class FUNCTION (set)     493 (def-class FUNCTION (set)
486   "The class of all defined functions"     494   "The class of all defined functions"
487   :lisp-fun #'(lambda (x env)     495   :lisp-fun #'(lambda (x env)
488                  (let ((y (unbound-variable? x env)))     496                  (let ((y (unbound-variable? x env)))
489                    (if y     497                    (if y
490                      (mapcar #'(lambda (rel)     498                      (mapcar #'(lambda (rel)
491                                    (cons (cons y rel) env))     499                                    (cons (cons y rel) env))
492                              (all-functions))     500                              (all-functions))
493                      (if (ocml-function?     501                      (if (ocml-function?
494                           (instantiate x env))     502                           (instantiate x env))
495                        (list env)     503                        (list env)
496                        :fail)))))     504                        :fail)))))
497     505
498     506
499     507
500     508
501 (def-function APPLY (?f ?args)     509 (def-function APPLY (?f ?args)
502   "(apply f (arg1 .....argn)) is the same as     510   "(apply f (arg1 .....argn)) is the same as
503    (f arg1 ....argn)"     511    (f arg1 ....argn)"
504   :constraint (and (function ?f)     512   :constraint (and (function ?f)
505                    (list ?args)))     513                    (list ?args)))
506     514
507     515

Generated by diff2html on Wed Jun 29 13:47:01 2005
Command-line:
./diff2html support-v1/basic.lisp support-v2.1/basic.lisp