4 ms·
To save everyone a click: integer1 0 0 1 1 integer2 0 1 0 1 Operation Performed ---------
by phoe-krk 4y ago
To save everyone a click:
integer1 0 0 1 1
integer2 0 1 0 1 Operation Performed
----------------------------------------------------------------
boole-clr 0 0 0 0 always 0
boole-set 1 1 1 1 always 1
boole-1 0 0 1 1 integer1
boole-2 0 1 0 1 integer2
boole-c1 1 1 0 0 complement of integer1
boole-c2 1 0 1 0 complement of integer2
boole-and 0 0 0 1 and
boole-ior 0 1 1 1 inclusive or
boole-xor 0 1 1 0 exclusive or
boole-eqv 1 0 0 1 equivalence (exclusive nor)
boole-nand 1 1 1 0 not-and
boole-nor 1 0 0 0 not-or
boole-andc1 0 1 0 0 and complement of integer1 with integer2
boole-andc2 0 0 1 0 and integer1 with complement of integer2
boole-orc1 1 1 0 1 or complement of integer1 with integer2
boole-orc2 1 0 1 1 or integer1 with complement of integer2
- zachbeane 4y agoAlso, some context from comp.lang.lisp is available at https://www.xach.com/naggum/articles/3250122499743574%40naggum.no.html https://www.xach.com/naggum/articles/3250122499743574%40nagg...
- lisper 4y agoAnd to save everyone from having to read that: | Can someone explain why the BOOLE function is a single function with sixteen ops rather than sixteen functions. It's because there are only four possible inputs to a two-input boolean gate, and so there are only 2^4=16 possible boolean gates. Furthermore there is a straightforward representation of those gates as an ordered sequence of four bits that specify the output of the gate for each of the four possible combinations of inputs (though the CL standard does not actually require implementations to use this representation, and not all do).
- DonaldFisk 4y agoMACLISP also had a BOOLE function, which had an extra argument with 16 possible values., e.g. (BOOLE 1 x y) was equivalent to x & y (1 = 0001 => AND) (BOOLE 6 x y) was equivalent to x ^ y (6 = 0110 => XOR) (BOOLE 7 x y) was equivalent to x | y (7 = 0111 => OR) (BOOLE 14 x y) was equivalent to ~(x & y) (14 = 1110 => NAND) i.e. the first argument always corresponds to the values in the binary operation table (as shown in your table). But in Common Lisp, the values are in an arbitrary order with, e.g. boole-and = 6 instead of 1 (0001), boole-xor = 8 instead of 6 (0110), and boole-nand = 10 instead of 14 (1110). As well as being arbitrary, this unnecessarily breaks backward compatibility with MACLISP.
- Jtsummers 4y agoboole-and 0 0 0 1 and boole-nand 1 1 1 0 not-and While boole-and appears in the 6th (counting from 0) position, it still has a binary representation here of 1, and boole-nand is (reasonably) its complement with 14. It seems the table has been reordered for some reason for this presentation. It seems to present 0-ary, 1-ary, 2-ary operations in that order, which doesn't correspond to the order of the binary representation.
- kazinator 4y agoThe order is implementation-specific. For the values I cared to sample below, CLISP seems to have sane values that reflect the truth tables: [1]> boole-clr 0 [2]> boole-set 15 [3]> boole-and 8 [4]> boole-ior 14 [5]> boole-nand 7 Obviously, values with this property are not unique; they depend on the bit combination order. boole-and and boole-ior could plausibly be 1 and 7. IMHO, the latitude in the spec should be interpreted as accommodating this truth table ordering variation, and not as an invitation for arbitrarily enumerating the functions so that the values don't make sense as truth tables. That is to say, it should be possible to perform logical operations on the values whose interpretation is that the truth tables are combined accordingly, such that these two are equivalent: (boole (logior boole-xxx boole-yyy) a b) <--> (logior (boole boole-xxx a b) (boole boole-yyy a b)) No matter how boole-and is defined, (logior boole-and boole-nand) should produce 15, which should be the value of boole-set. The vector indexing trick recommended in the boole function's example should only be necessary for a program which needs the operators to have concrete values corresponding to a particular choice of truth table bit order. It should not be necessary for obtaining indexing which has the above good behavior with respect to being able to use logical operators on the truth tables in order to combine them. Indeed, the implementation from which you are reporting seems to have a broken numbering. For the boole-xor function, we need to see a value that has two zeros and two ones. If it's not one of the values 2, 5, 9, 6, 10, 12, then the numbering is broken. It is inescapable that boole-clr and boole-set must be 0 and 15.
- deleted 4y ago[deleted]