Logic Function

October 25, 2009
by Lee Morgan (lrm07)

Here’s the function I tried to show in class; I had put in a couple last minute fixes that actually ended up making it break more often, but now as far as I can tell it corresponds with sentential logic exactly, except that for coding reasons it requires parentheses around negated clauses, which sentential does not. The function is based on the more rigorous definition of sentential, which requires parentheses inserted with every connective (in practice, logicians often leave out the outermost parentheses).

;Determines if the argument is a well-formed formula of sentential logic with basic letters P-S.
;Example calls: (wff? 'P) (wff? '(P v Q)) (wff? '(~ (~ (P & (Q (R v S))))) all return #t
; (wff? 23) (wff? '(P Q v)) (wff? '(P v Q v R)) return #f

(define letters '(P Q R S))
(define connectives '(v & => ))
(define negated '(~P ~Q ~R ~S))

(define wff?
(lambda (formula)
(let ((letter? (lambda (a)
;asks if the argument is a basic letter of sentential
(if (or (member a letters)
(member a negated))
;these conditions check syntactic rules
((letter? formula)
((list? formula)
((equal? (cdr formula) '())
((equal? (cddr formula) '())
((if (or (and (and (wff? (car formula)) (and (wff? (third formula)) (eq? (cdddr formula) '())))
(member (second formula) connectives))
(and (equal? (car formula) '~) (and (wff? (second formula)) (eq? (cddr formula) '()))))
(else #f)))
(else #f)))))

Tags: ,

One Response to “Logic Function”

  1.   asm09 Says:

    whenever you have something like “(if condition #t #f)”… you can always use simply “condition”, which stands for a boolean value anyway. the extra ‘if’ is not doing anything but passing along the value that “condition” already returns. Sorry if I’m not making any sense.

Leave a Reply

You must be logged in to post a comment.