
RULES

;;; Actions

(puton
 if
 (clear ?obj ?s)
 (clear ?dst ?s)
 (on ?obj ?src ?s)
 and-if
 (not (equal-constants? '?obj '?dst))
 (not (equal-constants? '?obj '?src))
 (not (equal-constants? '?src '?dst))
 then
 (on ?obj ?dst (move ?obj ?src ?dst ?s)))

(clear1
 if
 (on ?obj ?src ?s)
 (clear ?obj ?s)
 (clear ?dst ?s)
 and-if
 (not (equal-constants? '?obj '?dst))
 (not (equal-constants? '?obj '?src))
 (not (equal-constants? '?src '?dst))
 then
 (clear ?src (move ?obj ?src ?dst ?s)))

;;; Frame axioms

(frame-table
 if 
 then
 (clear table ?s))

(frame-clear
 if
 (clear ?x ?s)
 (on ?obj ?src ?s)
 (clear ?dst ?s)
 (clear ?obj ?s)
 and-if
 (not (equal-constants? '?x '?dst))
 (not (equal-constants? '?obj '?dst))
 (not (equal-constants? '?obj '?src))
 (not (equal-constants? '?src '?dst))
 then
 (clear ?x (move ?obj ?src ?dst ?s)))

(frame-on
 if
 (on ?x ?y ?s)
 (on ?obj ?src ?s)
 (clear ?dst ?s)
 (clear ?obj ?s)
 and-if
 (not (equal-constants? '?x '?obj))
 (not (equal-constants? '?obj '?dst))
 (not (equal-constants? '?obj '?src))
 (not (equal-constants? '?src '?dst))
 then
 (on ?x ?y (move ?obj ?src ?dst ?s)))

;;; Trivial AND

(and2
 if 
 (on ?x1 ?x2 ?s)
 (on ?x3 ?x4 ?s)
 then
 (and 
  (on ?x1 ?x2 ?s)
  (on ?x3 ?x4 ?s)))

(and3
 if 
 (on ?x1 ?x2 ?s)
 (on ?x3 ?x4 ?s)
 (on ?x5 ?x6 ?s)
 then
 (and 
  (on ?x1 ?x2 ?s)
  (on ?x3 ?x4 ?s)
  (on ?x5 ?x6 ?s)))

ASSERTIONS

(clear table initial)
(clear b initial)
(on b c initial)
(on c a initial)
(on a table initial)

CODE

(define (ask-plan-simple)
  (backchain
   '(and (on c table (? plan)) (on b table (? plan)) (on a table (? plan)))
	))

(define (ask-plan-hard)
  (backchain
   '(and (on c table (? plan)) (on b c (? plan)) (on a b (? plan)))
	))

(define (equal-constants? a b)
 (and (symbol? a) (symbol? b) (eq? a b)))