Add nor and nand operators

This commit is contained in:
2024-09-03 18:47:44 -07:00
parent 51f99a87ab
commit 5a0371ae15

View File

@ -128,12 +128,14 @@ line."))
'((open-paren "(") '((open-paren "(")
(close-paren ")") (close-paren ")")
(and "/\\" "and" "&&" "&" "∧" ".") (and "/\\" "and" "&&" "&" "∧" ".")
(nand "nand" "↑" "⊼")
(or "\\/" "or" "||" "|" "∥" "+" "") (or "\\/" "or" "||" "|" "∥" "+" "")
(nor "nor" "↓" "⊽")
(xor "xor" "⊕" "⊻" "↮" "≢" "^" "!=") (xor "xor" "⊕" "⊻" "↮" "≢" "^" "!=")
(not "¬" "~" "!" "not") (not "¬" "~" "!" "not")
(implies "->" ">" "=>" "⇒" "⟹" "→" "⊃" "implies") (implies "->" ">" "=>" "⇒" "⟹" "→" "⊃" "implies")
(converse "<-" "<" "<=" "←" "⇐" "⟸" "⊂" "converse") (converse "<-" "<" "<=" "←" "⇐" "⟸" "⊂" "converse")
(iff "<->" "<>" "<=>" "⇔" "↔" "≡" "iff" "=" "==")) (iff "<->" "<>" "<=>" "⇔" "↔" "≡" "iff" "=" "==" "xnor" "⊙"))
"Alist table of operator symbols and their possible string representations.") "Alist table of operator symbols and their possible string representations.")
(defun operator-symbol (oper-str) (defun operator-symbol (oper-str)
@ -147,8 +149,10 @@ line."))
(case oper (case oper
(not 1) (not 1)
(and 2) (and 2)
(nand 2)
(xor 3) (xor 3)
(or 4) (or 4)
(nor 4)
(implies 5) (implies 5)
(converse 5) (converse 5)
(iff 6) (iff 6)
@ -166,6 +170,8 @@ and the maximum number (or nil for infinity) as a second value."
(implies (values 2 2)) (implies (values 2 2))
(converse (values 2 2)) (converse (values 2 2))
(iff (values 2 2)) (iff (values 2 2))
(nand (values 2 nil))
(nor (values 2 2))
(t (error "unknown operator: ~S" oper)))) (t (error "unknown operator: ~S" oper))))
(defun interpret-operand (oper-str) (defun interpret-operand (oper-str)
@ -398,7 +404,9 @@ found variables."
(defconstant operator-ascii-lookup-alist (defconstant operator-ascii-lookup-alist
'((and . "&") '((and . "&")
(nand . "nand")
(or . "|") (or . "|")
(nor . "nor")
(xor . "^") (xor . "^")
(not . "~") (not . "~")
(implies . "->") (implies . "->")
@ -412,7 +420,9 @@ found variables."
(defconstant operator-unicode-lookup-alist (defconstant operator-unicode-lookup-alist
'((and . "∧") '((and . "∧")
(nand . "⊼")
(or . "") (or . "")
(nor . "⊽")
(xor . "⊕") (xor . "⊕")
(not . "¬") (not . "¬")
(implies . "→") (implies . "→")
@ -426,7 +436,9 @@ found variables."
(defconstant operator-latex-lookup-alist (defconstant operator-latex-lookup-alist
'((and . "\\land") '((and . "\\land")
(nand . "\\uparrow")
(or . "\\lor") (or . "\\lor")
(nor . "\\downarrow")
(xor . "\\oplus") (xor . "\\oplus")
(not . "\\lnot ") (not . "\\lnot ")
(implies . "\\to") (implies . "\\to")
@ -589,8 +601,12 @@ NOTE: the second value does not include individual variables, literal values
;; using `eval' ;; using `eval'
(and (and
(apply 'logical-and arg-values)) (apply 'logical-and arg-values))
(nand
(not (apply 'logical-and arg-values)))
(or (or
(apply 'logical-or arg-values)) (apply 'logical-or arg-values))
(nor
(not (apply 'logical-or arg-values)))
(xor (xor
(apply 'logical-xor arg-values)) (apply 'logical-xor arg-values))
(not (not