### Logic Function

Sunday, October 25th, 2009

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)) #t #f)))) (cond ;these conditions check syntactic rules ((letter? formula) #t) ((list? formula) (cond ((equal? (cdr formula) '()) #f) ((equal? (cddr formula) '()) #f) ((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) '())))) #t #f)) (else #f))) (else #f)))))```
{"ft_lang_label":"__label__en","ft_lang_prob":0.7942649,"math_prob":0.9731639,"size":1472,"snap":"2019-43-2019-47","text_gpt3_token_len":432,"char_repetition_ratio":0.13828337,"word_repetition_ratio":0.008333334,"special_character_ratio":0.31861413,"punctuation_ratio":0.12411348,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.999824,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-22T00:35:38Z\",\"WARC-Record-ID\":\"<urn:uuid:e3fceaad-b47d-4bec-b9fc-b51d2ff9296c>\",\"Content-Length\":\"16509\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7ba78c05-84c3-450c-b737-f94b76412d27>\",\"WARC-Concurrent-To\":\"<urn:uuid:807250bd-7e87-4cb5-9b84-cf35e3e5acdd>\",\"WARC-IP-Address\":\"192.101.188.1\",\"WARC-Target-URI\":\"http://codeimmersion.i3ci.hampshire.edu/tag/recursion/\",\"WARC-Payload-Digest\":\"sha1:V5SF5ASIQ73M4QXGBSXJJHMQIPZA3LOY\",\"WARC-Block-Digest\":\"sha1:INVLGNTSA5XM7HQJGKYBXM7QBKJWSBVI\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496671053.31_warc_CC-MAIN-20191121231600-20191122015600-00251.warc.gz\"}"}