Logical operations: Difference between revisions

m
Line 1,857:
An alternate approach, based on a probabilistic interpretation, uses <code>*</code> for logical and, <code>-.</code> for logical negation and derives the others: <code>(*&.-.)</code> for logical or, <code>(-.@*)</code> for not-and, <code>(-.@*&.-.)</code> for not-or, <code>(* *&.-. -.@*&.-.)</code> for exclusive or, and <code>(*&.-. -.)~</code> for logical implication. You get the same results for simple truth values this way, but you also get consistent treatment for values between 0 and 1.
 
That said, J also supports truth valued operations on the binary representations of integers. (This is the concept of "packed binary", roughly speaking). For example <code>2b10001 &nbsp;b.</code> is '''and''', <code>2b10111&nbsp;b.</code> is '''or''', <code>2b11110 &nbsp;b.</code> is '''nand''', etc. (the last four bits of the control argument to <code>b.</code> represent the desired binary truth table, while the prefix of that control argument in these examples specifies "packed binary"). Thus:
 
<lang J> (2b10001 b. table/~i.4);(2b10110 b. table/~i.4);<2b10000 b. table/~i.4
6,951

edits