(defun similarity (a b) (/ (float (dot-product a b)) (float (* (magnitude a) (magnitude b))))) (defun dot-product (a b) (if (null a) 0 (+ (* (first a) (first b)) (dot-product (rest a) (rest b))))) (defun magnitude (a) (sqrt (sum-of-squares a))) (defun sum-of-squares (a) (if (null a) 0 (+ (square (first a)) (sum-of-squares (rest a))))) (defun diff-angle (a b) (let ((k (similarity a b))) (if (> k 1) (setf k 1.0)) (radians-to-degrees (acos k)))) (defun radians-to-degrees (theta) (* theta (/ 180.0 pi)))