5

Does MiniKanren have the "not" operator?

For example, how would one represent Prolog's

a :- b, not(c)

a is true if b is true and c is not (Prolog uses negation as failure, i.e. not(c) is considered proven if c can not be proven)

Prolog's not also works with non-ground expressions, e.g.

a(X, d(Y)) :- b(d(X), d(Y)), not(c(d(X)))
logi-kal
  • 7,107
  • 6
  • 31
  • 43
MWB
  • 11,740
  • 6
  • 46
  • 91

2 Answers2

4

According to https://github.com/zhjhxxxjh/ykanren the answer is no.

soegaard
  • 30,661
  • 4
  • 57
  • 106
3

There is no not operator in minikanren, but you can achieve something similar with conda:

(defmacro not
  "fail if the given goal succeeds, use with extreme caution"
  [goal]
  `(conda 
     [~goal fail]
     [succeed]))

See my similar question on Google Groups

Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
  • Do I understand it correctly that this differs from Prolog's not? (see edit) – MWB Aug 14 '17 at 00:12
  • @MaxB I would think it's the same as Prolog's not, because they both succeed if-and-only-if their argument cannot be proven at that particular moment. However, I'm new to logic programming and negation is tricky, so I wouldn't be surprised if I'm wrong. – Gordon Gustafson Aug 15 '17 at 06:46
  • As I understood, this construct in miniKanren can't handle variables, as in the second example. – MWB Aug 15 '17 at 22:40
  • @MaxB Why not? If there is *any* substitution that makes `goal` succeed, `(not goal)` will fail, regardless of whether goal has to bind variables in order to succeed. Are you thinking of projection with something like `pred` in core.logic? – Gordon Gustafson Aug 16 '17 at 00:00
  • 1
    So how does Minikanren propose to deal with problems that are usually aptly expressed with negation then? As I see it, negation is a fundamental operation in logic, and a logical language that lacks it (in one form or the other) has a serious limitation. Any recommendations/insights into this problem? – eazar001 May 03 '19 at 22:15
  • 2
    Giving a full general, appropriate semantics to negation in logic programming is IMHO tricky business. I'd point you to Shepherdson or Apt for good recent(-ish) surveys of the area. Succinctly though, you might find some behavior of Prolog's `not` isn't wholly satisfactory. We've punted. In the implementations you're likely to run across you'll find negated equality constraints and perhaps negated subterm constraints. Unlike relations generally, these constraints are required to be atomic operations and guaranteed to terminate. More here, if you like: hdl.handle.net/2022/25183 – Jason Hemann Jul 20 '20 at 17:28