#### Yami

Joined Jan 18, 2016
233
Just wanted to check if my working is correct

#### WBahn

Joined Mar 31, 2012
24,970
Here's an idea, RRittesh: Instead of always asking people to tell you if your "working is correct," how about making at least some effort to check your own work first?

You have an equation with three variables. That's only eight possible combinations. So make a truth table for the original equation and one for the final equation and compare them.

• Yami

#### Yami

Joined Jan 18, 2016
233
Here's an idea, RRittesh: Instead of always asking people to tell you if your "working is correct," how about making at least some effort to check your own work first?

You have an equation with three variables. That's only eight possible combinations. So make a truth table for the original equation and one for the final equation and compare them.
Thanks for your advice. However all day I've been thinking of how I would create a truth table for the first equation #### WBahn

Joined Mar 31, 2012
24,970
Thanks for your advice. However all day I've been thinking of how I would create a truth table for the first equation If you don't know how to create a truth table, then you need to step back to basics before you even attempt to work problems like this.

Make truth tables for the following equations:

W = A + B
X = AB
Y = A' + B
Z = A'B

#### MrAl

Joined Jun 17, 2014
6,785
Hi,

Very good idea about using two truth tables to check for equivalence.

I almost always do this too, using a short program to test such as:

for a=0 to 1 do
for b=0 to 1 do
for c=0 to 1 do
x=equation1(a,b,c)
y=equation2(a,b,c)
if x!=y then
print("truth tables do not match")
end if
end for
end for
end for

In the above equation1 is a function that calls the first function to be compared with the second function which would be equation2. So if you wanted to compare these two:
abc'
((abc')')'

just code them as two different functions and use a program like that. For more variables use more letters like d,e,f, etc. Even 8 variables runs pretty fast on modern machines.

#### WBahn

Joined Mar 31, 2012
24,970
And to make that program even more affective, any time that the two don't match print out the variables and what the result of each equation was so that you can verify that each is correct (you may have a bug in one of your functions) and, if they are, get some hints as to what might be going wrong.

#### MrAl

Joined Jun 17, 2014
6,785
And to make that program even more affective, any time that the two don't match print out the variables and what the result of each equation was so that you can verify that each is correct (you may have a bug in one of your functions) and, if they are, get some hints as to what might be going wrong.
Hi,

The idea with the functions is to make them so simple that they almost cant be wrong. For example:
function1(a,b,c)
y=and(a,b)
y=and(y,not(c))
return y
end function

or if you write multi variable logic functions first:
function1(a,b,c)
y=and(a,b,not(c))
return y
end function

I've tested some very complicated logic statements using this kind of idea, building up the statement line by line instead of trying to do it all in one line when it gets complicated.

#### WBahn

Joined Mar 31, 2012
24,970
Hi,

The idea with the functions is to make them so simple that they almost cant be wrong. For example:
Ah, famous last words. I'll bet you've made the occasional typo and put x when it should have been y or something comparable.

But even if you never make this kind of mistake, the whole point of running the program is because you expect, at least occasionally, for the two functions being tested to end up not being the same. Why limit yourself to a, "Truth tables do not match," message when it would be so easy to actually get the information about which rows, specifically, don't match and which functions output which result?

#### MrAl

Joined Jun 17, 2014
6,785
Ah, famous last words. I'll bet you've made the occasional typo and put x when it should have been y or something comparable.

But even if you never make this kind of mistake, the whole point of running the program is because you expect, at least occasionally, for the two functions being tested to end up not being the same. Why limit yourself to a, "Truth tables do not match," message when it would be so easy to actually get the information about which rows, specifically, don't match and which functions output which result?
Hello,

Well i mean 'dirt' simple. If we cant get y=and(a,b) right, then we will never get anything to work without hours of rechecking and retyping I have found in the past that if the functions dont match then i check the functions over again to make sure i got them right. It's very hard to accidentally get them to match if they are really yield different results for any set of a,b,c etc.

#### Yami

Joined Jan 18, 2016
233
If you don't know how to create a truth table, then you need to step back to basics before you even attempt to work problems like this.

Make truth tables for the following equations:

W = A + B
X = AB
Y = A' + B
Z = A'B