Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Denumerate logic sentences [Common Lisp]

Name: Anonymous 2015-03-06 3:04

Example usage:
> (logic-from-list (doit 5))
"p0^p1" ; This is the 5th logic sentence in my denumeration


If you're wondering about the denumeration scheme, it's simply assigning to each number a list of binary numbers. These binary numbers correspond to the horn clause for them, and that's how the logic sentence is produced.
E.g.
> (doit 17)
(0 0 1 1
> (logic-from-list *)
"~p0^~p1^p2^p3"


Variables are conveniently named pn

Anyway, enjoy the code lisp weenies.
(defun new-variable (prefix)
(let ((counter -1))
(lambda ()
(format nil "~A~D" prefix (incf counter)))))

(defun logic-from-list (list)
(let ((variable (new-variable "p")))
(reduce (lambda (x y)
(concatenate 'string x "^" y))
(loop for x in list
append (list (concatenate 'string
(if (zerop x)
"~"
"")
(funcall variable)))))))
(defun complement-num (x)
(if (eq x 0) 1 0))

(defun how-many-vars (number)
(if (< number 2)
1
(do ((i 0 (1+ i)))
((> (expt 2 i) (+ number 2))
(1- i)))))

(defun f (vars id)
"6 vars: id from 0 to 2^5 is normal
from 2^5 to 2^6 is complementary of 2^6 - i"
(if (>= id (expt 2 (1- vars)))
(mapcar #'complement-num
(f vars (- (expt 2 vars) id 1)))
(let ((*print-base* 2))
(let ((result
(loop for x across (write-to-string id)
collect (if (eq x #\0) 0 1))))
(if (> vars (length result))
(append (make-list (- vars (length result))
:initial-element 0)
result)
result)))))

(defun doit (id)
(let ((vars (how-many-vars id)))
(f vars (- id (expt 2 vars) -2))))

(defun doit-2 (values)
(let ((vars (log (length values) 2)))
(when (zerop (nth-value 1 (floor vars)))
(if (every #'zerop values)
(concatenate 'string
"~("
(doit-2 (make-list (length values)
:initial-element 1))
")")
(reduce (lambda (x y)
(concatenate 'string "(" x ")v(" y ")"))
(loop for i in (reverse values)
for j from 0
if (not (zerop i)) collect (logic-from-list
(f (floor vars) j))))))))

Name: Anonymous 2015-03-06 5:11

>>1
That was MIT Quality!

Name: Mentifex 2015-03-06 12:16

>>2
This website seems more upscale today, more witty, up-with-life, non-gloomy, glad to be alive, all-around suffused with chimerical human happiness. What went wrong? How soon can we get back to pessimism, mal de mer, and the alluebliche geistige Umnachtuing of Friedrich Nietzsche?
http://ai.neocities.org/gonzo.html
https://aa5new.wordpress.com/2015/02/24/mindforth-genial-oder-absurd
http://www.reddit.com/r/singularity/comments/2xblbs/whats_the_best_book_on_singularity/coyw8dx

Name: Anonymous 2015-03-06 12:46

>>3
nietzsche is a dumb german chimp nigger

Name: Anonymous 2015-03-06 12:55

>>3
stay on reddit, nigger

Name: dubsmon 2015-03-06 13:29

. ,.
T."-._..---.._,-"/|
l|"-. _.v._ (" |
[l /.'_ \; _~"-.`-t
Y " _(o} _{o)._ ^.|
j T ,-<v>-. T ]
\ l ( /-^-\ ) ! !
\. \. "~" ./ /c-..,__
^r- .._ .- .-" `- . ~"--.

Name: Anonymous 2015-03-06 16:59

>>4-5
Nice Amerifat brohurt.

Name: Anonymous 2015-03-06 17:19

>>7
More like schoolboy hurt. Only schoolboys use the word "nigger" to denote anything they don't like.

Name: Anonymous 2015-03-06 22:02

>>8
stay in school, nigger

Name: Anonymous 2015-03-06 23:22

>>8
Nigger, that's nigger.
You don't know what you're talking about.

Name: dubsmon 2015-03-06 23:42

>>10
Only schoolboys use the word "nigger" to denote anything they don't like.

Name: dubsmon 2015-03-07 1:05

>>11
nice dubs

Don't change these.
Name: Email:
Entire Thread Thread List