Is there an easy way to learn truth tables?

9.9k views Asked by At

I'm following an online tutorial for Ruby and I'm at a point where it's mentioning truth tables and how I need to learn them before proceeding.

Is there an easy way to learn them? Do I just need to learn what constitutes as true and false?

4

There are 4 answers

0
Joshua Cheek On BEST ANSWER

You don't need truth tables to learn Ruby, though they're not that hard, they look scarier than they are.

To learn what this tutorial is trying to teach you, go to the command line and type irb which will open up an interactive Ruby for you, called a REPL. You can play around with the boolean expressions, which just means code that deals with true and false:

1.9.3-p0 :001 > true || false
 => true 
1.9.3-p0 :002 > (true || false) && false
 => false 
1.9.3-p0 :003 > false && true
 => false 
1.9.3-p0 :004 > false ^ true
 => true 
1.9.3-p0 :005 > !true
 => false 
1.9.3-p0 :006 > !!true
 => true
1.9.3-p0 :007 > exit

Whatever they're trying to teach you with truth tables, you can learn better with a little experimentation in an interactive environment.

0
Jakob Weisblat On

You really just need to memorize your basic three, OR, AND and NOT, and the rest can be computed from there:

         (and)    (OR)  (not)
P    Q    P&Q     P|Q     ~P
T    T    T        T      F
T    F    F        T      T
F    T    F        T
F    F    F        F

XOR is just (P&Q)|(~(P|Q))

NAND is just ~(P&Q).

Once you understand the basic three, anything else is easy.

1
DigitalRoss On

Do not memorize truth tables

What's important is understanding the functions that are used to compute truth tables. When you understand the functions the truth tables will be obvious.

A OR  B: Either A or B    # cream OR sugar, T if either (or both), F if neither
A AND B: Both A and B     # cream AND sugar, T only when the coffee has both
A XOR B: One but not both # T only if sugar but no cream or if cream but no sugar
NOT   A: Kind of obvious  # NOT sugar, true if the tea has no sugar

A NAND B: NOT (A AND B)   # T unless both cream and sugar are in the tea
A NOR  B: NOT (A OR B)    # T only if there is no sugar and also no cream
0
steenslag On

It might help if you substitute those abstract true and false values for obvious true and false statements. Is this statement true?

Sugar is sweet AND grass is blue.

No, that's clearly false. (T&F = F)

Sugar is sweet OR grass is blue.

Yes, that's true. (T|F = T)

Sugar is sweet OR 1+1=2

Is the only one worth learning, computers think this is true. (T|T = T)