Reputation: 3887
Does racket's datalog (https://docs.racket-lang.org/datalog) support 'datalog with negation' ?
Upvotes: 1
Views: 413
Reputation: 1
Datalog with Negation Is Failure involves a new positive subgoal when a negation is encountered that succeeds when the subgoal fails, backtracking any bindings made after the negative goal. Furthermore special restrictions need to implace to prevent contradictory rules from conflicting with each other. This is called stratification. See also: Stratified negation
Upvotes: -1
Reputation: 498
This is the best I was able to come up with:
#lang racket
(require datalog)
(define prices (make-theory))
(datalog prices
(! (price a 1))
(! (price b 2))
(! (price c 3))
(! (price d -5))
(! (price e 5))
)
(define (notgt x y)
(not (> x y)
))
(datalog prices
(! (:- (notgt X Y)
(notgt X Y :- #t))
))
(datalog prices
(! (:- (al2 X)
(price X Y)
(notgt Y 2)
)))
(datalog prices (? (al2 X)))
Problem is that predicates must all return true and cannot be complex, so you cannto write there something like (not (= Y 2))
. And it looks like negation is not in racket's datalog, but I am not expert on this matter. There is also another datalog implementation in racket: https://github.com/rntz/datafun But I have no idea if that is any better.
Upvotes: 1