Discussion in 'Homework Help' started by Yami, May 15, 2016.

1. ### Yami Thread Starter Member

Jan 18, 2016
51
0
Just wanted to check if my working is correct

File size:
76.2 KB
Views:
20
2. ### WBahn Moderator

Mar 31, 2012
17,454
4,701
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 likes this.
3. ### Yami Thread Starter Member

Jan 18, 2016
51
0
Thanks for your advice. However all day I've been thinking of how I would create a truth table for the first equation

4. ### WBahn Moderator

Mar 31, 2012
17,454
4,701
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

5. ### MrAl Well-Known Member

Jun 17, 2014
2,214
435
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.

6. ### WBahn Moderator

Mar 31, 2012
17,454
4,701
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.

7. ### MrAl Well-Known Member

Jun 17, 2014
2,214
435
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.

8. ### WBahn Moderator

Mar 31, 2012
17,454
4,701
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?

9. ### MrAl Well-Known Member

Jun 17, 2014
2,214
435
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.

Jan 18, 2016
51
0

File size:
78.2 KB
Views:
2