NAND & NOR now n-ary; Bug in BITWISE-EQV? implementation shivers@xxxxxx (21 Jul 2002 17:14 UTC)
|
Re: NAND & NOR now n-ary; Bug in BITWISE-EQV? implementation
Marc Feeley
(21 Jul 2002 17:45 UTC)
|
Re: NAND & NOR now n-ary; Bug in BITWISE-EQV? implementation
Aladdin Petrofsky
(21 Jul 2002 19:09 UTC)
|
The boolean eqv function & n-ary generalisation of associative ops
shivers@xxxxxx
(21 Jul 2002 19:07 UTC)
|
Re: The boolean eqv function & n-ary generalisation of associative ops
Alfresco Petrofsky
(21 Jul 2002 19:57 UTC)
|
NAND & NOR now n-ary; Bug in BITWISE-EQV? implementation shivers@xxxxxx 21 Jul 2002 17:14 UTC
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)))) ans))) I have changed the SRFI accordingly. The new draft is at http://www.cc.gatech.edu/~shivers/srfi/srfi-33.txt and will propagate out to the standard url http://srfi.schemers.org/srfi-33/srfi-33.html 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. -Olin