Perl Monk, Perl Meditation PerlMonks

### Re^3: Bit operations for beginners

by BrowserUk (Pope)
 on Jun 28, 2005 at 01:05 UTC ( #470432=note: print w/replies, xml ) Need Help??

in reply to Re^2: Bit operations for beginners
in thread Bit operations for beginners

p xor q === [something very long]

Hell's teeth! You weren't kidding.

I remember xor as (p and not q) or (q and not p) and it's been something like 30 years since I played with nand and nor expansions, so I expanded that:

```xor === (p and not q) or (q and not p)

expand the 'not's
=== (p and (q nor q)) or (q and (p nor p))

expand the 'and's
=== ((p nor p) nor ((q nor q) nor (q nor q)))
or ((q nor q) nor ((p nor p) nor (p nor p)))

expand the 'or's
=== (((p nor p) nor ((q nor q) nor (q nor q)))
nor ((q nor q) nor ((p nor p) nor (p nor p))))
nor (((q nor q) nor ((p nor p) nor (p nor p)))
nor ((p nor p) nor ((q nor q) nor (q nor q))))

Then it struck me that ((x nor x) nor (x nor x)) is x, which reduces it to

```    === (((p nor p) nor q) nor ((q nor q) nor p))
nor (((q nor q) nor p) nor ((p nor p) nor q))

It's certainly more digestable (just :), but are there any other reductions in there?

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^4: Bit operations for beginners
by kaif (Friar) on Jun 28, 2005 at 16:50 UTC

Yeah, you might enjoy:

(p nor q) nor ((p nor p) nor (q nor q))

Remember that nor returns true only if both arguments are false. So, we want to return true if the inputs aren't both false or both true. The former is simply p nor q and the latter is (not p) nor (not q) and we use the expansion of not.

Create A New User
Node Status?
node history
Node Type: note [id://470432]
help
Chatterbox?
 [Corion]: Somehow I'm happy that my Javascript mostly targets Firefox nowadays :) [Corion]: But my conundrum currently is how to do lightweight SQL for maintaining my user database, instead of home-cooking too much of an ORM ;) [Corion]: But maybe Just Enough of an ORM might be the ticket, that is, just locked hashes read from the DB :)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-03-21 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (267 votes). Check out past polls.

Notices?