2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Logical Operators
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# Logical Operators
  
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Conjunction a.k.a. "AND" (&&)
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								P& & Q returns True if both P and Q are True. If either P or Q (or both) are False, then P& & Q is False.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| P | Q | AND(P,Q) |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								|---|---|---|
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| T | T | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| T | F | F |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | T | F |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | F | F |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Disjunction a.k.a. "OR" (||)
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								P||Q returns True if at least one of P or Q (or both P and Q) is True. Only returns False if P and Q are both False.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| P | Q | OR(P,Q) |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								|---|---|---|
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| T | T | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| T | F | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | T | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | F | F |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Negation a.k.a. "NOT" (!)
  
						 
					
						
							
								
									
										
										
										
											2019-02-13 19:57:26 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Returns the opposite value. Ex. if P is true, then !P is False, and if P is False, then !P is true. This is the only logical operator that works on only one input, which makes it a unary operator.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| P | Q | NOT(P) | NOT(Q) |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								|---|---|---|---|
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| T | T | F | F |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| T | F | F | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | T | T | F |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | F | T | T |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## XOR ("eXclusive or")
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Is known as **exclusive or** . Similar to OR, but returns False if both P and Q are true. That is, XOR returns true if one and only one of P or Q is True.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Note: XOR is unique among the logical operators because, by combining several together, you can form all of the other logical operators using only XOR.
							 
						 
					
						
							
								
									
										
										
										
											2018-11-03 19:11:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| P | Q | XOR(P,Q) |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								|---|---|---|
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| T | T | F |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| T | F | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | T | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | F | F |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Implication (P -> Q)
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Read as "if P, then Q" or "P implies Q".
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Only returns False when P is True and Q is False. Otherwise the implication is True.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Note: Implications are often used for direct mathematical proofs. P represents the hypothesis, while Q is the conclusion.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 19:57:26 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The only time the conditional is False is when a True value leads to a False value. 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| P | Q | IF(P,Q) |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								|---|---|---|
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| T | T | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| T | F | F |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | T | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | F | T |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Logical Equivalence (iff: if and only if)
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"P if and only if Q" is the same as "P implies Q AND Q implies P". In other words, the truth tables for P and Q are identical for all truth values.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This is known as the biconditional. It is the equivalent of P -> Q **AND**  Q -> P. It means that both conditionals must be satisfied in order for the biconditional to be true.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can easily see that the output of the IFF operator in the truth table is the same as the ANDing of columns 3 and 4.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| P | Q | IF(P,Q) | IF(Q,P) | IFF(P,Q) |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								|---|---|---|---|---|
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| T | T | T | T | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| T | F | F | T | F |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | T | T | F | F |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | F | T | T | T |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-14 05:13:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Condensed Tables
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								For binary operators, a condensed form of truth table is also used, where the row headings and the column headings specify the operands and the table cells specify the result. For example, the condensed table for AND operator (^ sign):< / br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| ^ | F | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								|---|---|---|
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| F | F | T |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| T | T | T |
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Additional Resources
  
						 
					
						
							
								
									
										
										
										
											2019-03-28 09:35:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  [Logical Operators in JavaScript ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators ) 
						 
					
						
							
								
									
										
										
										
											2019-02-13 20:56:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  [Logical Operators in PHP ](http://php.net/manual/en/language.operators.logical.php ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  [Logical Operators in C++ ](http://en.cppreference.com/w/cpp/language/operator_logical ) 
						 
					
						
							
								
									
										
										
										
											2019-02-14 05:13:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  [Wikipedia, Truth table ](https://en.wikipedia.org/wiki/Truth_table )