[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NAND & NOR now n-ary; Bug in BITWISE-EQV? implementation

This page is part of the web mail archives of SRFI 33 from before July 7th, 2015. The new archives for SRFI 33 contain all messages, not just those from before July 7th, 2015.

I went ahead & changed nand & nor to be n-ary, as Marc suggested.

I also discovered a bug in the spec for n-ary eqv. This is true:
  (eqv i j) = (not (xor i j))
But it does not generalise to the n-ary case. That is, it is *NOT TRUE* that
  (eqv i ...)  =  (not (xor i ...))

This buggy n-ary definition appears in the spec and the implementation of
n-ary eqv. Here is the bogus definition from the reference implementation:

  (define (bitwise-eqv . args) (bitwise-not (apply bitwise-xor args)))

Nope. To use the not-xor definition, you must fold it across the args; 
you can't save the not operation until the very end. So this is correct:

  (define (bitwise-eqv . args)
    (reduce (lambda (a b) (bitwise-not (bitwise-xor a b))) 
	    -1 args))

or, sticking to the R5RS core:

(define (bitwise-eqv . args)
  (let lp ((args args) (ans -1))
    (if (pair? args)
        (lp (cdr args) (bitwise-not (bitwise-xor ans (car args))))

I have changed the SRFI accordingly. The new draft is at
and will propagate out to the standard url
in the hands of esteemed editor Solsona in the near future.

If anyone knows of a simpler n-ary definition of eqv that could
be simply expressed in terms of n-ary primitives like and, or and 
xor, I would like to see it.