(defun pix (p x y z)
  ;; If we have a term p(t1,t2,t3), where t1 has length x, t2 has length y,
  ;; and t3 has length z, then calculate the length of the expanded term.
  ;; p is the pixley term to use.
  (ecase p
	 (2   (+ (* 12 x) (* 24 y) (* 16 z) 51))  ;; Pixley-2
	 (3   (+ (* 2 x)  (* 3 y)  (* 3 z) 7))    ;; Pixley-3
	 (4   (+ (* 2 x)  (* 4 y)  (* 2 z) 7))    ;; Pixley-4
	 (5   (+ (* 3 x)  (* 2 y)  (* 3 z) 7))    ;; Pixley-5
	 (6   (+ (* 3 x)  (* 3 y)  (* 2 z) 7))    ;; Pixley-6
	 (7   (+ (* 4 x)  (* 2 y)  (* 2 z) 7))    ;; Pixley-7
	 (8   (+ (* 2 x)  (* 2 y)  (* 4 z) 7))    ;; Pixley-8
	 ))

(setq orient 'best)  ;; This should be 'best, 'worst, or 'fixed.

(defun nonab (p a b)   ;; nonabsorption -> absorption
  ;; We are free to swap a and b, and also to swap the second and fourth
  ;; arguments of pix.
  (ecase orient
	 (best  (min (pix p 1 a b) (pix p a b 1) (pix p 1 b a) (pix p b a 1)))
	 (worst (max (pix p 1 a b) (pix p a b 1) (pix p 1 b a) (pix p b a 1)))
	 (fixed (pix p 1 a b))
	 ))

(defun ab (p a b)  ;; pair of absorptions -> one absorption
  (nonab p (pix p 1 a 1) (pix p 1 b 1)))

(defun schema1 (p f)
  (pix p (pix p 1 1 1) (pix p f 1 1) 1))

(defun schema2 (p f1 f2)
  (pix p (pix p f1 1 f2) 1 (pix p 1 1 (pix p 1 1 1))))

(defun meredith (p)  ;; naive algorithm with Meredith basis
  ;; 2-basis, with 7=7 and 7=1.
  (+ 2 (schema1 p (ab p 7 (nonab p 7 7)))))

(defun veroff (p)  ;; naive algorithm with W17 and commutativity
  ;; 2-basis, with 3=3 and 13=1.
  (+ 2 (schema1 p (ab p 13 (nonab p 3 3)))))

(defun veroff2 (p)  ;; naive algorithm with V27a and commutativity
  ;; 2-basis, with 3=3 and 9=1.
  (+ 2 (schema1 p (ab p 9 (nonab p 3 3)))))

(defun mccune1a (p)  ;; naive algorithm with V27a and simple absorber
  ;; 2-basis, with 7=1 and 9=1.
  (+ 2 (schema1 p (ab p 9 7))))

(defun mccune1 (p)  ;; naive algorithm with W17 and simple absorber
  ;; 2-basis, with 7=1 and 13=1.
  (+ 2 (schema1 p (ab p 13 7))))

(defun mccune2 (p)  ;; f1-f2 schema with V27a and simple absorber (7=1)
  ;; 2-basis, with 7=1 and 9=1 (schema2)
  ;; We have a choice here, lets do both!
  (list (+ 2 (schema2 p 9 7))
	(+ 2 (schema2 p 7 9))
	))

(defun clever (p)  ;; the best Sheffer axiom so far (121) ?  no!
  ;; Pixley basis with a 13=1.
  (+ 2 (schema1 p 13)))

(defun clever2 (p)  ;; the best Sheffer axiom so far (105) ?
  ;; Pixley basis with a 9=1.
  (+ 2 (schema1 p 9)))

(defun three-bases (strat)
  (progn
    (setq orient strat)
    (format t "~%")
    (format t "meredith ~a: ~a.~%" strat (list (meredith 2)
					       (meredith 3)
					       (meredith 4)
					       (meredith 5)
					       (meredith 6)
					       (meredith 7)
					       (meredith 8)
					      
					       ))
    (format t "veroff   ~a: ~a.~%" strat (list (veroff 2)
					     (veroff 3)
					     (veroff 4)
					     (veroff 5)
					     (veroff 6)
					     (veroff 7)
					     (veroff 8)))
    (format t "veroff2  ~a: ~a.~%" strat (list (veroff2 2)
					     (veroff2 3)
					     (veroff2 4)
					     (veroff2 5)
					     (veroff2 6)
					     (veroff2 7)
					     (veroff2 8)))
    (format t "mccune   ~a: ~a.~%" strat (list (mccune1 2)
					      (mccune1 4)
					      (mccune1 5)
					      (mccune1 6)
					      (mccune1 7)
					      (mccune1 8)))
    (format t "mccune1a ~a: ~a.~%" strat (list (mccune1a 2)
					      (mccune1a 4)
					      (mccune1a 5)
					      (mccune1a 6)
					      (mccune1a 7)
					      (mccune1a 8)))
    ))
    
(defun all ()
  (progn
    (three-bases 'fixed)
    (three-bases 'best)
    (three-bases 'worst)

    ;; best/wost strategy is irrelevant
    (format t "~%mccune, schema-2:  ~a.~%" (list (mccune2 2)
					(mccune2 3)
					(mccune2 4)
					(mccune2 5)
					(mccune2 6)
					(mccune2 7)
					(mccune2 8)))

    ;; best/wost strategy is irrelevant
    ;;
    (format t "~%clever:  ~a.~%" (list (clever 2)
				       (clever 3)
				       (clever 4)
				       (clever 5)
				       (clever 6)
				       (clever 7)
				       (clever 8)))
    (format t "~%clever2: ~a.~%" (list (clever2 2)
				       (clever2 3)
				       (clever2 4)
				       (clever2 5)
				       (clever2 6)
				       (clever2 7)
				       (clever2 8)))
    ))

