Advertisement
Guest User

sat.scm

a guest
Jul 1st, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.77 KB | None | 0 0
  1. (define (tautology? p #!optional arity)
  2.   (contradiction? (compose N p)
  3.     (procedure-arity/default p arity)))
  4.  
  5. (define valid? tautology?)
  6.  
  7. (define (contradiction? p #!optional arity)
  8.   (not (satisfiable? p
  9.          (procedure-arity/default p arity))))
  10.  
  11. (define unsatisfiable? contradiction?)
  12.  
  13. (define (contingent? p #!optional arity)
  14.   (let ((arity (procedure-arity/default p arity)))
  15.     (and (not (tautology? p arity))
  16.          (not (contradiction? p arity)))))
  17.  
  18. (define (satisfiable? p #!optional arity)
  19.   (any (lambda (interpretation)
  20.          (= (apply p interpretation) 1))
  21.        (cartesian-power
  22.          '(0 1)
  23.          (procedure-arity/default p arity))))
  24.  
  25. (define (invalid? p #!optional arity)
  26.   (not (tautology? p
  27.          (procedure-arity/default p arity))))
  28.  
  29. (define (equivalent? p q #!optional arity)
  30.   (tautology? (compose E p q)
  31.     (max (procedure-arity/default p arity)
  32.          (procedure-arity/default q arity))))
  33.  
  34. (define ((compose p . formulas) . interpretations)
  35.   (apply p
  36.          (map (lambda (q) (apply q interpretations))
  37.               formulas)))
  38.  
  39. (define (procedure-arity/default p arity)
  40.   (if (not (default-object? arity))
  41.     arity
  42.     (procedure-arity-min (procedure-arity p))))
  43.  
  44. (define (cartesian-power A n)
  45.   (if (= n 0)
  46.     '(())
  47.     (cartesian-product A (cartesian-power A (- n 1)))))
  48.  
  49. (define (cartesian-product A B)
  50.   (append-map
  51.     (lambda (x)
  52.       (map (lambda (y)
  53.              (append
  54.                (if (list? x) x (list x))
  55.                (if (list? y) y (list y))))
  56.            B))
  57.     A))
  58.  
  59. (define (N p)
  60.   (cond ((= p 0) 1)
  61.         ((= p 1) 0)))
  62.  
  63. (define (K p q)
  64.   (cond ((and (= p 0) (= q 0)) 0)
  65.         ((and (= p 0) (= q 1)) 0)
  66.         ((and (= p 1) (= q 0)) 0)
  67.         ((and (= p 1) (= q 1)) 1)))
  68.  
  69. (define (A p q) (N (K (N p) (N q))))
  70.  
  71. (define (C p q) (A (N p) q))
  72.  
  73. (define (E p q) (K (C p q) (C q p)))
  74.  
  75. (for-each
  76.   (lambda (p) (display (tautology? p)) (newline))
  77.   (list
  78.     ; modus ponens
  79.     (lambda (p q) (C (K (C p q) p) q))
  80.     ; affirmatio consequentis
  81.     (lambda (p q) (C (K (C p q) q) p))
  82.     ; negatio antecedentis
  83.     (lambda (p q) (C (K (C p q) (N p)) (N q)))
  84.     ; modus tollens
  85.     (lambda (p q) (C (K (C p q) (N q)) (N p)))
  86.     ; syllogismus hypotheticus
  87.     (lambda (p q r) (C (K (C p q) (C q r)) (C p r)))
  88.     ; De Morgan's laws
  89.     (lambda (p q) (E (N (K p q)) (A (N p) (N q))))
  90.     (lambda (p q) (E (N (A p q)) (K (N p) (N q))))
  91.     ; Peirce's law
  92.     (lambda (p q) (C (C (C p q) p) p))
  93.     ; reductio ad absurdum
  94.     (lambda (p) (C (C p (N p)) (N p)))
  95.     ; consequentia mirabilis
  96.     (lambda (p) (C (C (N p) p) p))
  97.     ; proof by contradiction
  98.     (lambda (p q) (C (C p (K q (N q))) (N p)))
  99.     ; indirect proof
  100.     (lambda (p q) (C (C (N p) (K q (N q))) p))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement