(defun sgn (x) "Signal of x." (cond ((< x 0) -1) (t 1))) (defun absx (x) "Absolute value of x." (cond ((< x 0) -x) (t x))) (defun delta (i j) "Kronecker's delta." (cond ((= i j) 1) (t 0))) (defun factorial (n) "Factorial function." (cond ((= n 1) 1) (t (* n (factorial (- n 1)))))) (defun gcd (m n) "Euclidean algorithm for the greatest common divisor." (cond ((> m n) (gcd n m)) ((= 0 (rem* n m)) m) (t (gcd (rem* n m) m)))) (defun sqrt (a x tol) "Heron method for sqrt(a)." (cond ((< (abs (- (* x x) a)) tol) x) (t (sqrt a (* .5 (+ x (/ a x))) tol)))) (defun and. (p q) "Logical and." (cond (p q) (t nil))) (defun or. (p q) "Logical or." (cond (p t) (t q))) (defun neg (p) "Logical negation." (cond (p nil) (t t))) (defun implies (p q) (cond (p q) (t t)))
Created: NaN
Last updated: 23-01-2025 [00:04]
For attribution, please cite this page as:
Charters, T., "Some functions from McCarthy paper in Emacs Lisp": https://nexp.pt/jmcfunctions.html (23-01-2025 [00:04])
(cc-by-sa) Tiago Charters - tiagocharters@nexp.pt