Logic problem: need better logic for desired thruth table.

Paul nospam at needed.com
Thu May 28 19:21:33 EDT 2015


Skybuck Flying wrote:
> Hello,
> 
> I was just coding and ran into a little logic problem which is as follows:
> 
> There are two booleans/variables which can be either false or true.
> 
> The desired thrutle table is:
> 
> A = input
> B = input
> C = output
> 
> A B C:
> -------
> F F T
> F T F
> T F T
> T T T
> 
> Surpisingly enough I don't think there is a casual/common operator for 
> this thruth table.
> 
> AND does not apply.
> OR does not apply.
> XOR does not apply.
> 
> So I would need some combined operators to give the desired result.
> 
> I tried logic below... but funny enough it failed, now I feel like a 
> noob lol and share this funny little fail logic with you.
> 
> Can you improve/fix the logic ?
> 
> This is python code, but this^ logic/thruth table problem basically 
> applies to any programming language:
> 
> # loop has to run if:
> # while DesiredResult==True:
> # Desired truth table for BotWaitForCooldown and CooldownDetected
> # BotWaitForCooldown:  CooldownDetected: Desired Result:
> # False       False    True
> # False       True     False
> # True     False    True
> # True     True     True
> # desired/suiting logic:
> # (BotWaitForCooldown or ((not BotWaitForCooldown) and CooldownDetected))
> 
> def TestLogic( BotWaitForCooldown, CooldownDetected ):
> return BotWaitForCooldown or ((not BotWaitForCooldown) and 
> CooldownDetected) # this logic is flawed, please improve logic.
> 
> if TestLogic( False, False ) == True:
> print "test 1 ok"
> else:
> print "test 1 failed"
> 
> if TestLogic( False, True ) == False:
> print "test 2 ok"
> else:
> print "test 2 failed"
> 
> if TestLogic( True, False ) == True:
> print "test 3 ok"
> else:
> print "test 3 failed"
> 
> if TestLogic( True, True ) == True:
> print "test 4 ok"
> else:
> print "test 4 failed"
> 
> Bye,
>  Skybuck.

If you ever have a really complicated truth table,
you can use Quine McCluskey minimization. At work, I
had no tool for minimizing boolean equations, so I got
some code from another engineer, code that ran on a
mainframe computer. And I converted the code to run
on a personal computer. The computers were so slow
back then, it might take ten to fifteen minutes to
minimize a ten variable truth table. On the mainframe
you could have a 2MB array for storage, whereas on my
personal computer at the time, the memory was segmented
and required some tricks to get enough.

http://en.wikipedia.org/wiki/Quine%E2%80%93McCluskey_algorithm

If it isn't a scam, the source code should be
reasonably short. The program I was using, might have
been on the order of 120 lines of source. This example
is a bit longer, and the couple programs I've been looking
at the source, I don't recognize what they're doing.

http://sourceforge.net/projects/mini-qmc/files/?source=navbar

Your problem isn't large enough to need this sort
of thing, but I thought I'd throw it in as a topic
of general interest. If it's one thing I've learned
over the years, hand-optimization of boolean equations
frequently leads to errors. And it's when you start
engaging your brain, and saying stuff like "I know the
answer", instead of sticking with your boolean algebra,
that errors creep in.

If you need a test case for your QM code, enter an
"XOR tree", as an XOR tree is irreducible and
should cough out the same info, as you entered in
the first place. That was one of my test cases,
when porting the code maybe 30 years ago. (And
no, I didn't keep a copy of the code. We didn't
do stuff like that back then. I didn't even have
a computer at home back then.)

    Paul



More information about the Python-list mailing list