Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91385 > unrolled thread
| Started by | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| First post | 2015-05-28 23:50 +0200 |
| Last post | 2015-05-29 19:07 -0400 |
| Articles | 5 on this page of 25 — 11 participants |
Back to article view | Back to comp.lang.python
Logic problem: need better logic for desired thruth table. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-28 23:50 +0200
Re: Logic problem: need better logic for desired thruth table. (thruth table to logic/boolean operations generator sought/needed) "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-28 23:55 +0200
Re: Logic problem: need better logic for desired thruth table. (thruth table to logic/boolean operations generator sought/needed) "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-29 00:07 +0200
Re: Logic problem: need better logic for desired thruth table. (thruth table to logic/boolean operations generator sought/needed) "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-29 00:08 +0200
Re: Logic problem: need better logic for desired thruth table. (thruth table to logic/boolean operations generator sought/needed) "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-29 00:12 +0200
Re: Logic problem: need better logic for desired thruth table. (thruth table to logic/boolean operations generator sought/needed) "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-29 04:45 +0200
Re: Logic problem: need better logic for desired thruth table. (thruth table to logic/boolean operations generator sought/needed) "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-29 04:56 +0200
Re: Logic problem: need better logic for desired thruth table. (thruth table to logic/boolean operations generator sought/needed) Grant Edwards <invalid@invalid.invalid> - 2015-05-28 22:13 +0000
Re: Logic problem: need better logic for desired thruth table. (thruth table to logic/boolean operations generator sought/needed) Grant Edwards <invalid@invalid.invalid> - 2015-05-28 22:15 +0000
Re: Logic problem: need better logic for desired thruth table. sohcahtoa82@gmail.com - 2015-05-28 14:58 -0700
Re: Logic problem: need better logic for desired thruth table. Michael Torrie <torriem@gmail.com> - 2015-05-28 16:16 -0600
Re: Logic problem: need better logic for desired thruth table. Grant Edwards <invalid@invalid.invalid> - 2015-05-28 22:54 +0000
Re: Logic problem: need better logic for desired thruth table. Grant Edwards <invalid@invalid.invalid> - 2015-05-28 23:03 +0000
Re: Logic problem: need better logic for desired thruth table. Michael Torrie <torriem@gmail.com> - 2015-05-28 18:52 -0600
Re: Logic problem: need better logic for desired thruth table. sohcahtoa82@gmail.com - 2015-05-28 17:15 -0700
Re: Logic problem: need better logic for desired thruth table. Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-28 23:25 +0000
Re: Logic problem: need better logic for desired thruth table. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-29 04:46 +0200
Re: Logic problem: need better logic for desired thruth table. Grant Edwards <invalid@invalid.invalid> - 2015-05-28 22:01 +0000
Re: Logic problem: need better logic for desired thruth table. Grant Edwards <invalid@invalid.invalid> - 2015-05-28 22:11 +0000
Re: Logic problem: need better logic for desired thruth table. Tim Chase <python.list@tim.thechases.com> - 2015-05-28 17:02 -0500
Re: Logic problem: need better logic for desired thruth table. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-05-29 01:13 +0300
Re: Logic problem: need better logic for desired thruth table. Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-05-28 18:39 -0400
Re: Logic problem: need better logic for desired thruth table. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-28 23:56 +0100
Re: Logic problem: need better logic for desired thruth table. Paul <nospam@needed.com> - 2015-05-28 19:21 -0400
Re: Logic problem: need better logic for desired thruth table. M Philbrook <jamie_ka1lpa@charter.net> - 2015-05-29 19:07 -0400
Page 2 of 2 — ← Prev page 1 [2]
| From | Jussi Piitulainen <jpiitula@ling.helsinki.fi> |
|---|---|
| Date | 2015-05-29 01:13 +0300 |
| Message-ID | <lf5zj4o1hcf.fsf@ling.helsinki.fi> |
| In reply to | #91385 |
Skybuck Flying writes: > 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 That's A >= B, where True >= False: >>> BB = False, True >>> print(*((A, B, A >= B) for A in BB for B in BB), sep = '\n') (False, False, True) (False, True, False) (True, False, True) (True, True, True) >>>
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2015-05-28 18:39 -0400 |
| Message-ID | <YOM9x.125121$AJ4.46857@fx02.iad> |
| In reply to | #91385 |
On Thursday May 28 2015 17:50, in comp.lang.c, "Skybuck Flying"
<skybuck2000@hotmail.com> 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
Seems simple enough: C == A || !B
18:38 $ cat testlogic.c
#include <stdio.h>
#include <stdlib.h>
/*
** A = input
** B = input
** C = output
**
** A B C:
** -------
** F F T
** F T F
** T F T
** T T T
*/
int testlogic(int a, int b)
{
return (a || !b);
}
int main(void)
{
/* A B C */
int ttable[4][3] = { {0,0,1}, /* F F T */
{0,1,0}, /* F T F */
{1,0,1}, /* T F T */
{1,1,1} /* T T T */
};
int rc = EXIT_SUCCESS;
int i, max;
for (i = 0, max = sizeof(ttable) / sizeof(ttable[0]); i < max ; ++i)
if (testlogic(ttable[i][0],ttable[i][1]) != ttable[i][2])
{
printf("testlogic failed on test %d\n",i);
rc = EXIT_FAILURE;
}
if (rc == EXIT_SUCCESS) puts("SUCCESS");
return rc;
}
18:39 $ cc -o testlogic testlogic.c
18:39 $ ./testlogic
SUCCESS
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2015-05-28 23:56 +0100 |
| Message-ID | <mailman.148.1432853790.5151.python-list@python.org> |
| In reply to | #91402 |
On 28/05/2015 23:39, Lew Pitcher wrote:
> On Thursday May 28 2015 17:50, in comp.lang.c, "Skybuck Flying"
> <skybuck2000@hotmail.com> 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
>
> Seems simple enough: C == A || !B
>
> 18:38 $ cat testlogic.c
> #include <stdio.h>
> #include <stdlib.h>
>
> /*
> ** A = input
> ** B = input
> ** C = output
> **
> ** A B C:
> ** -------
> ** F F T
> ** F T F
> ** T F T
> ** T T T
> */
>
> int testlogic(int a, int b)
> {
> return (a || !b);
> }
>
> int main(void)
> {
> /* A B C */
> int ttable[4][3] = { {0,0,1}, /* F F T */
> {0,1,0}, /* F T F */
> {1,0,1}, /* T F T */
> {1,1,1} /* T T T */
> };
> int rc = EXIT_SUCCESS;
> int i, max;
>
> for (i = 0, max = sizeof(ttable) / sizeof(ttable[0]); i < max ; ++i)
> if (testlogic(ttable[i][0],ttable[i][1]) != ttable[i][2])
> {
> printf("testlogic failed on test %d\n",i);
> rc = EXIT_FAILURE;
> }
>
> if (rc == EXIT_SUCCESS) puts("SUCCESS");
>
> return rc;
> }
> 18:39 $ cc -o testlogic testlogic.c
> 18:39 $ ./testlogic
> SUCCESS
>
>
Strangest looking Python I've ever seen. Or is it a case of "Get thee
behind me, Satan" :)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Paul <nospam@needed.com> |
|---|---|
| Date | 2015-05-28 19:21 -0400 |
| Message-ID | <mk87rk$i6r$1@dont-email.me> |
| In reply to | #91385 |
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
[toc] | [prev] | [next] | [standalone]
| From | M Philbrook <jamie_ka1lpa@charter.net> |
|---|---|
| Date | 2015-05-29 19:07 -0400 |
| Message-ID | <MPG.2fd2bb3541a5a620989bf2@news.eternal-september.org> |
| In reply to | #91385 |
In article <3794b$55678d83$5419aafe$56138@news.ziggo.nl>, skybuck2000 @hotmail.com says... > > 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) First maintain a bit table, something that your code can reference as Bools via bit operations.. In your case it's more less simple.. A combine of 3 bits gives you the value of 7 this this can be used as the OR operation AND operation. If value = 7 then..... OR Operation. If Value <> 0 then.... Xor Operation, If Value in [1,2,4] then.... If you need to build the "Value" Product from dangling booleans. Value := (Value Shl 1) OR Byte(YourBool); Since the compiler only uses the first bit for native booleans this works out. Do the above for all three bools to build a final value.. Or you can simply mask off a bit as your boolean value from a VALUE location, which makes it faster in the longrun... Does that do anything for you ? Jamie
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web