#lang scheme ;; Implement resolution for propositional logic ;; ;; written by mike slattery - feb 2010 ;; modified mcs - mar 2010 ;; The function inconsistent? added to do ;; "proofs" easily. If you add the negation of a ;; sentence s to ;; the knowledge base (KB) and find the result ;; is inconsistent, then you know s follows ;; logically from the KB. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (resolve-unit u lst) ;; given a literal u and a list of literals ;; return lst minus -u if -u in lst ;; otherwise, add u to the *set* lst and return (cond ((null? lst) (list u)) ((member u lst) lst) (else (let ((not-u (negate-unit u))) (if (member not-u lst) (remove not-u lst) (cons u lst)))) )) (define (negate-unit u) (if (list? u) (cadr u) (list 'not u) )) (define (contains-negative? u lst) ;; u is a literal, lst is a list of literals ;; return true if lst contains the negative of ;; u (list? (member (negate-unit u) lst)) ) (define (count-complements lst1 lst2) ;; return number of pairs of negatives (cond ((null? lst1) 0) ((contains-negative? (car lst1) lst2) (+ 1 (count-complements (cdr lst1) lst2))) (else (count-complements (cdr lst1) lst2)) )) (define (resolve lst1 lst2) (cond ((null? lst1) lst2) (else (resolve-unit (car lst1) (resolve (cdr lst1) lst2))) )) (define (canonical lst) (sort lst string