Rudolf Adamkovič Personal site


Truth table

Construct the truth table for the statement

\[\begin{equation*}
  P \implies Q \> \equiv \> \lnot P \lor Q.
\end{equation*}
\]
(define (boolean-product length)
  "Return a list of all Boolean sequences of LENGTH."
  (let more-rows ((row (- (expt 2 length) 1)))
    (if (< row 0) (list)
        (cons (let more-columns ((column (- length 1)))
                (if (< column 0) (list)
                    (cons (even? (quotient row (expt 2 column)))
                          (more-columns (- column 1)))))
              (more-rows (- row 1))))))
(define (truth-table procedure arity)
  "Return a truth table for PROCEDURE with ARITY."
  (map (lambda (inputs)
         (append inputs (list (apply procedure inputs))))
       (boolean-product arity)))
(define (org-truth-table procedure headers)
  (append (list (map (lambda (header)
                       (string-append "\\(" header "\\)"))
                     headers))
          (list (list))
          (list (append (list "/")
                        (make-list (- (length headers) 2) "")
                        (list "<")))
          (map (lambda (row)
                 (map (lambda (value)
                        (if value
                            "true"
                            "false"))
                      row))
               (truth-table procedure
                            (- (length headers)
                               1)))))
(org-truth-table (lambda (p q) (or (not p) q))
                 '("P" "Q" "P \\implies Q"))
\(P\)\(Q\)\(P \implies Q\)
falsefalsetrue
falsetruetrue
truefalsefalse
truetruetrue

(Levin 2021, sec. 0.2; Poole and Mackworth 2017, sec. 5.1)


© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.