state[var]
The current truth assignment of each variable.
PC[var]
A list of the clauses that contain this
variable as a positive literal.
NC[var]
A list of the clauses that contain this
variable as a negative literal.
V[clause]
A list of the variables that appear in
this clause.
Len[clause]
The number of variable in this clause.
Sat[clause]
The number of variables in this clause
whose current values make this clause true.
Unsat
The number of unsatisfied clauses.
Your top-level function should be
(defun walksat (clauses ntrials nflips) ...)It should accept input in the form
(((not a) (not b)) (a b) (c (not d) e))which means there are three clauses:
-a or -b a or b c or -d or eIt should return a truth assignment in the form
((a . 0) (b . 1) (c . 1) (d . 0) (e . 0))
CommonLisp supports arrays as follows:
(setf *a* (make-array 100 :element-type 'fixnum :initial-element
0))
fixnum
s (i.e.,
32-bit integers). The array is filled with zeros.(setf *b* (make-array 100 :element-type t :initial-element nil))
nil
(elt *a* index)
index
to
index into the array. Arrays are indexed starting from 0.
(setf (elt *a* 20) -10)
The syntax for multidimensional arrays is somewhat more complex (you won't need them for this assignment):
;; create a 10 by 20 by 10 array (setf *3da* (make-array '(10 20 10) :element-type 'fixnum :initial-element 0)) ;; access the element with indexes 0 5 1. (aref *3da* 0 5 1) ;; change its value (setf (aref *3da* 0 5 1) -10) ;; Code can be written to handle arrays with an unknown number of dimensions ;; Let a be an array with an unknown number of dimensions ;; Let indexes be a list with the appropriate number of indexes ;; To access an element: (apply #'aref a indexes) ;; To modify an element (setf (apply #'aref a indexes) -10)