Math Wiki
m (→‎AND (Conjunction): Format using AWB)
 
(17 intermediate revisions by 9 users not shown)
Line 1: Line 1:
 
'''Boolean logic''' is a complete system for [[logical operation]]s. It was named after [[George Boole]], an English mathematician at University College Cork who first defined an [[algebraic system]] of [[logic]] in the mid 19th century. Boolean logic has many applications in electronics, computer hardware and software. In 1938, [[Claude Shannon]] showed how electric circuits with relays were a model for Boolean logic. This fact soon proved enormously consequential with the emergence of the electronic computer.
 
'''Boolean logic''' is a complete system for [[logical operation]]s. It was named after [[George Boole]], an English mathematician at University College Cork who first defined an [[algebraic system]] of [[logic]] in the mid 19th century. Boolean logic has many applications in electronics, computer hardware and software. In 1938, [[Claude Shannon]] showed how electric circuits with relays were a model for Boolean logic. This fact soon proved enormously consequential with the emergence of the electronic computer.
   
Boolean logic is used extensively in creating computer programs particularly to control flow of the program. 'If' statements are flow control instructions which are encountered in nearly every computer language and which use boolean logic. The 'if' statment returns a value of either true or false and the program is redirected accordingly.
+
Boolean logic is used extensively in creating computer programs particularly to control flow of the program. 'If' statements are flow control instructions which are encountered in nearly every computer language and which use boolean logic. The 'if' statement returns a value of either true or false and the program is redirected accordingly.
  +
==Boolean Values==
  +
Boolean expressions can only output two possible values:
  +
*True: Abbreviated as the number 1 or the letter T.
  +
*False: Abbreviated as the number 0 or the letter F.
  +
==Operators==
  +
===Elementary===
  +
These three operators are the key operators in boolean expressions, AND and OR are binary operators, meaning they take in two values and output one value, NOT is a unary operator, it takes in one value and outputs one value.
  +
====AND (Conjunction)====
  +
Both inputs must be true for the output to be true. This operator is commutative and associative.
  +
{| border="0" cellpadding="1" cellspacing="1" class="article-table" style="width: 500px;"
  +
|-
  +
! scope="col"|<math>P</math>
  +
! scope="col"|<math>Q</math>
  +
! scope="col"|<math>P \land Q</math>
  +
|-
  +
|0
  +
|0
  +
|0
  +
|-
  +
|0
  +
|1
  +
|0
  +
|-
  +
|1
  +
|0
  +
|0
  +
|-
  +
|1
  +
|1
  +
|1
  +
|}
  +
A conjunction of two boolean values analogous to an intersection of two sets <math>A \cup B</math> in [[set theory]] and multiplication in [[arithmetic]], this is evident when combining probablities in [[statistics]]; the probability of both A and B occurring is given by <math>P(A) \times P(B) </math> or <math>P(A) \bullet P(B) </math>.
  +
Because of the analogy to multiplication, in electronics/electrical engineering, a conjunction is written as <math>A \bullet B</math>.
   
  +
When constructing switching circuits, an AND gate is reprsented as two switches in series, both switches must be closed for the current to flow.
==Boolean Statements==
 
   
  +
<gallery>
===True and False===
 
  +
El and gate-1-.gif|AND gate.
  +
Boo1-1-.gif|The AND gate as two switches in series.
  +
</gallery>
  +
====OR (Disjunction)====
  +
In everyday language, ''or ''usually means one input or the other however, in boolean algebra, it means one input, the other or both i.e. at least one input must be true for the output for be true. See XOR below for the operator that corresponds to the "one or the other" definition of ''or''. The disjunction operator is commutative and associative, it is also distributive over the conjunction operator
  +
{| border="0" cellpadding="1" cellspacing="1" class="article-table" style="width: 500px;"
  +
|-
  +
! scope="col"|<math>P</math>
  +
! scope="col"|<math>Q</math>
  +
! scope="col"|<math>P \lor Q</math>
  +
|-
  +
|0
  +
|0
  +
|0
  +
|-
  +
|0
  +
|1
  +
|1
  +
|-
  +
|1
  +
|0
  +
|1
  +
|-
  +
|1
  +
|1
  +
|1
  +
|}
  +
Just like how a conjunction is analogous to an intersection of two sets and the product of two numbers, a logical disjunction is analogous to a union (where being true is replaced by presence in one set, the other or both) and addition (the probability of event A occurring, event B occurring or both is given by adding together the probabilities). In electronics, the disjunction of two boolean values is written as <math>A+B</math>.
  +
====NOT (Negation)====
  +
Unlike the previous operators, a negation is a unary operator, it takes in one input and outputs one output.
  +
{| border="0" cellpadding="1" cellspacing="1" class="article-table" style="width: 500px;"
  +
|-
  +
! scope="col"|<math>P</math>
  +
! scope="col"|<math>\neg P</math>
  +
|-
  +
|0
  +
|1
  +
|-
  +
|1
  +
|0
  +
|}
  +
In electronics, the notation is a bar over the statement.
   
  +
<math>\neg P</math> is instead written as <math>\overline{P}</math>
Boolean logic statements can only return one of two values - true or false.
 
  +
and <math>\neg (A \lor B)</math> would be written as <math>\overline{A + B}</math>.
   
  +
===Compound===
===Boolean Operators ''and'', ''or'' and ''equals''===
 
  +
These operators can be made from the elementary operators. You may have come across some of the symbols used to represent them in other areas of maths before, their relationship will be explained further in the sections below.
  +
====XOR (Exclusive OR)====
  +
As explained in the section dealing with the OR (Disjunction)  operator, in boolean algebra, ''or'' means one, the other or both in contrast to the common meaning which is one or the other, in boolean algebra, the XOR operator means this. It is like the disjunction except if both inputs are true, it outputs false i.e. both outputs must be different from one another for the XOR operator to output true.
  +
====Implication====
  +
The implication outputs true as long as both inputs are the same and the second input can still be true if the first input is false. Unlike the conjunction and disjunction operators, it is not commutative.
  +
{| border="0" cellpadding="1" cellspacing="1" class="article-table" style="width: 500px;"
  +
|-
  +
! scope="col"|<math>P</math>
  +
! scope="col"|<math>Q</math>
  +
! scope="col"|<math>P \Rightarrow Q=\neg (P \land \neg Q)= \neg P \lor Q</math>
  +
|-
  +
|0
  +
|0
  +
|1
  +
|-
  +
|0
  +
|1
  +
|1
  +
|-
  +
|1
  +
|0
  +
|0
  +
|-
  +
|1
  +
|1
  +
|1
  +
|}
  +
====Sufficiency====
  +
The sufficiency is similar the implication, however the second input cannot be true if the first input is false and the second input may not be true if the first input is. Like the implication operator, it is not commutative. If you are swapping the order of the inputs you must change the direction the arrow faces.
  +
{| border="0" cellpadding="1" cellspacing="1" class="article-table" style="width: 500px;"
  +
|-
  +
! scope="col"|<math>P</math>
  +
! scope="col"|<math>Q</math>
  +
! scope="col"|<math>P \Leftarrow Q=\neg (\neg P \land Q)= P \lor \neg Q</math>
  +
|-
  +
|0
  +
|0
  +
|1
  +
|-
  +
|0
  +
|1
  +
|0
  +
|-
  +
|1
  +
|0
  +
|1
  +
|-
  +
|1
  +
|1
  +
|1
  +
|}
   
  +
====XNOR (Equivalence)====
The main operators in Boolean statements are ''and'', ''or'' and ''equals''.
 
  +
==Laws==
To keep the statements succinct we use symbols to represent each of these operators. Programming languages use a range of abbreviations for these operators but in mathematics the following are used:
 
  +
===Identities===
  +
<math>P \land 1 \Leftrightarrow P</math>
   
and - <math> \land </math>
+
<math>P \land 0 \Leftrightarrow 0</math>
   
or - <math>\lor</math>
+
<math>P \lor 1 \Leftrightarrow 1</math>
   
equals - <math>=</math>
+
<math>P \lor 0 \Leftrightarrow P</math>
  +
===Absorption===
   
  +
===Commutativity===
Equals is used to test whether the value on the left side of the statement is equivalent to the value on the right side. If it is then the returned value is true.
 
  +
===Associativity===
  +
===Distributivity===
  +
===De Morgan's===
  +
<math>\neg (P \land Q) \Leftrightarrow \neg P \lor \neg Q </math>
   
  +
<math>\neg (P \lor Q) \Leftrightarrow \neg P \land \neg Q </math>
e.g. <math>2+3=5</math> returns true. We can read this as "The statement ''two plus three equals five'' is true."
 
   
  +
==Relationship to other Disciplines==
while <math>3+4=6</math> returns false. We can read this as "The statement ''three plus four equals six'' is false."
 
  +
===[[Set theory|Set Theory]]===
(Note that the addition operator, +, is not a boolean operator)
 
  +
Each binary operator has an analogous operation in set theory. The laws mentioned above are also valid, especially De Morgan's laws.
  +
===[[Formal logic|Formal Logic]]===
  +
TBA
  +
===[[Arithmetic]]===
   
  +
The relational operators used in arithmetic and algebra such as equals, greater than etc. relate two arithmetical expressions that each have a numerical value; the LHS and the RHS. Equals forms an equation. Equals does not output a numerical value but it can output ''binary ''value, despite the inputs being numerical. With that in mind, this concept can be extended to the other relational operaotrs such as not equal to (analogous to the XOR operator).
These statements can now be combined using the ''and'' operator or the ''or'' operator as follows:
 
   
  +
The following means that the <math>1+4=5</math> is always true.
<math>(2+3=5) \land (4+2=6)</math> returns true because both statements are true. (The brackets are only added to clarify what is happening.)
 
  +
<math>1+4=5 \Leftrightarrow 1</math>
   
  +
===Electronics===
This can be read as follows: Because ''two plus three equals five'' is true '''and''' ''four plus two equals six'' is true then the overall statement is true.
 
  +
Boolean expressions can be represented visually as a logic circuit with the symbols seen previously, logic circuits are abstracted versions of transistor circuits which are an advanced form of switching circuit, also seen previously. Every micro-processing chip in the computer you are using have many transistors, and each of them run on the principles of boolean logic
   
  +
A switch may only take two states; ON (True) or OFF (False) hence the use of boolean logic. Being limited to two states required a new way to represent more information, a decimal (base 10) system was inadequate, binary numerals (base 2) was needed.
Conversely we have this:
 
   
  +
The following logic circuit is known as an "Adder circuit".
<math>(2+3=5) \land (4+2=7)</math> returns false because one statement is true while one is false and with the 'and' operator it is necessary for both statements to be true for the overall one to return true.
 
  +
All three inputs; A, B and C<suB>in</suB> can only be 1 or 0 because they are boolean values. The circuit has two outputs which must also be boolean values. Both of these together can represent a number in binary. The "S" represents how many units or how many 2<sup>0</sup> which is 1 in both binary and decimal, the "C<sub>out</sub>" represents how many  2<suP>1</suP> which is 10 in binary. The highest number achievable with this is <math>1+2=3</math> or <math>10+1=11</math> in binary, the lowest is <math>0+0=0</math>.
  +
[[File:Full-adder_logic_diagram.svg]]
   
  +
To go higher, everyday quantities such as 8, 16 or something larger such as 4294967295 requires an enormous quantity of transistors (switches) and with the invention of the micro-processor, this allowed such massive circuits to be possible. The part of a computer's CPU (Central Processing Unit) called the ALU (Arithmetic Logic Unit), as the name suggests is what does the arithmetic for the computer, and it does this using circuits built from millions of transistors, allowing it to do arithmetic with numbers far beyond 3.
This can be read as follows: ''two plus three equals five'' is true '''and''' ''four plus two equals seven'' is false so the overall statement is false.
 
 
The ''''or'''' operator works differently from the ''and'' operator. With ''or'' it is only necessary that one part of the statement is true for the overall statement to be true.
 
Thus:
 
 
<math>(2+3=5) \lor (4+2=7)</math> returns true because one statement is true while one is false and with the ''or'' operator it is only necessary for one statement to be true for the overall one to return true.
 
 
If both statments are true then the overall statement is still true.
 
 
Since all this can become quite verbose we use another abbreviation to help. Instead of showing statements such as <math>(2+3=5)</math> we represent a true statement by the value <math>1</math> and any false statement by the value <math>0</math>.
 
 
Now our statement <math>(2+3=5) \land (4+2=6)</math> becomes <math>1 \land 1</math> which is true and therefore equals <math>1</math>.
 
 
Further our statement <math>(2+3=5) \land (4+2=7)</math> becomes <math>1 \land 0</math> which is false and therefore equals <math>0</math>.
 
 
Extending this to our ''or'' statements we get:
 
 
<math>1 \lor 0 = 1</math>
 
and <math>1 \lor 1 = 1</math>
 
 
===Truth Tables===
 
 
This now allows us to introduce the concept of truth tables. Truth tables allow us to show the results of our boolean statements in concise form.
 
 
For '''And''' we have
 
 
<math>0 \land 0 = 0</math>
 
 
<math>0 \land 1 = 0</math>
 
 
<math>1 \land 0 = 0</math>
 
 
<math>1 \land 1 = 1</math>
 
 
<math>0 \land 0 = 0</math> If statement 1 is false and statement 2 is false then the result is false
 
 
<math>0 \land 1 = 0</math> If statement 1 is false and statement 2 is true then the result is false
 
 
<math>1 \land 0 = 0</math> If statement 1 is true and statement 2 is false then the result is false
 
 
<math>1 \land 1 = 1</math> If statement 1 is true and statement 2 is true then the result is true
 
 
For '''Or''' we have
 
 
<math>0 \lor 0 = 0</math>
 
 
<math>1 \lor 0 = 1</math>
 
 
<math>0 \lor 1 = 1</math>
 
 
<math>1 \lor 1 = 1</math>
 
 
<math>0 \lor 0 = 0</math> If statement 1 is false or statement 2 is false then the result is false
 
 
<math>1 \lor 0 = 1</math> If statement 1 is true or statement 2 is false then the result is true
 
 
<math>0 \lor 1 = 1</math> If statement 1 is false or statement 2 is true then the result is true
 
 
<math>1 \lor 1 = 1</math> If statement 1 is true or statement 2 is true then the result is true
 
 
===English example===
 
 
We can also see that these types of statements can be used in normal English. For example, "You will pass the course if you pass subject A and subject B". From our truth tables for the ''and'' operator we can see that this means the person must pass both subjects. If they fail either subject or if they fail both they will fail the course.
 
 
Alternatively the statement could be "You will pass the course if you pass either subject A or subject B". This means they can pass either or both. This agrees with our truth table for ''or''.
 
 
===Boolean Operators - the ''not'' operator===
 
 
The ''''not'''' operator reverses the value of the statement. This makes sense since ''not true'' is obviously ''false'' and vice versa.
 
 
We represent ''not'' as follows:
 
 
not - <math>\lnot</math>
 
 
The Truth Table for ''not'' is
 
 
<math>\lnot 0 = 1</math>
 
 
<math>\lnot 1 = 0</math>
 
 
<math>\lnot 0 = 1</math> not false is true
 
 
<math>\lnot 1 = 0</math> not true is false
 
 
===Combining Boolean Operators===
 
 
These operators can now be combined to form complex statements
 
 
{{stub}}
 
   
  +
===Programming===
  +
See [[Boolean logic in Programming Languages]].
 
[[Category:Logic]]
 
[[Category:Logic]]

Latest revision as of 16:45, 12 December 2017

Boolean logic is a complete system for logical operations. It was named after George Boole, an English mathematician at University College Cork who first defined an algebraic system of logic in the mid 19th century. Boolean logic has many applications in electronics, computer hardware and software. In 1938, Claude Shannon showed how electric circuits with relays were a model for Boolean logic. This fact soon proved enormously consequential with the emergence of the electronic computer.

Boolean logic is used extensively in creating computer programs particularly to control flow of the program. 'If' statements are flow control instructions which are encountered in nearly every computer language and which use boolean logic. The 'if' statement returns a value of either true or false and the program is redirected accordingly.

Boolean Values

Boolean expressions can only output two possible values:

  • True: Abbreviated as the number 1 or the letter T.
  • False: Abbreviated as the number 0 or the letter F.

Operators

Elementary

These three operators are the key operators in boolean expressions, AND and OR are binary operators, meaning they take in two values and output one value, NOT is a unary operator, it takes in one value and outputs one value.

AND (Conjunction)

Both inputs must be true for the output to be true. This operator is commutative and associative.

0 0 0
0 1 0
1 0 0
1 1 1

A conjunction of two boolean values analogous to an intersection of two sets in set theory and multiplication in arithmetic, this is evident when combining probablities in statistics; the probability of both A and B occurring is given by or . Because of the analogy to multiplication, in electronics/electrical engineering, a conjunction is written as .

When constructing switching circuits, an AND gate is reprsented as two switches in series, both switches must be closed for the current to flow.

OR (Disjunction)

In everyday language, or usually means one input or the other however, in boolean algebra, it means one input, the other or both i.e. at least one input must be true for the output for be true. See XOR below for the operator that corresponds to the "one or the other" definition of or. The disjunction operator is commutative and associative, it is also distributive over the conjunction operator

0 0 0
0 1 1
1 0 1
1 1 1

Just like how a conjunction is analogous to an intersection of two sets and the product of two numbers, a logical disjunction is analogous to a union (where being true is replaced by presence in one set, the other or both) and addition (the probability of event A occurring, event B occurring or both is given by adding together the probabilities). In electronics, the disjunction of two boolean values is written as .

NOT (Negation)

Unlike the previous operators, a negation is a unary operator, it takes in one input and outputs one output.

0 1
1 0

In electronics, the notation is a bar over the statement.

is instead written as and would be written as .

Compound

These operators can be made from the elementary operators. You may have come across some of the symbols used to represent them in other areas of maths before, their relationship will be explained further in the sections below.

XOR (Exclusive OR)

As explained in the section dealing with the OR (Disjunction)  operator, in boolean algebra, or means one, the other or both in contrast to the common meaning which is one or the other, in boolean algebra, the XOR operator means this. It is like the disjunction except if both inputs are true, it outputs false i.e. both outputs must be different from one another for the XOR operator to output true.

Implication

The implication outputs true as long as both inputs are the same and the second input can still be true if the first input is false. Unlike the conjunction and disjunction operators, it is not commutative.

0 0 1
0 1 1
1 0 0
1 1 1

Sufficiency

The sufficiency is similar the implication, however the second input cannot be true if the first input is false and the second input may not be true if the first input is. Like the implication operator, it is not commutative. If you are swapping the order of the inputs you must change the direction the arrow faces.

0 0 1
0 1 0
1 0 1
1 1 1

XNOR (Equivalence)

Laws

Identities

Absorption

Commutativity

Associativity

Distributivity

De Morgan's

Relationship to other Disciplines

Set Theory

Each binary operator has an analogous operation in set theory. The laws mentioned above are also valid, especially De Morgan's laws.

Formal Logic

TBA

Arithmetic

The relational operators used in arithmetic and algebra such as equals, greater than etc. relate two arithmetical expressions that each have a numerical value; the LHS and the RHS. Equals forms an equation. Equals does not output a numerical value but it can output binary value, despite the inputs being numerical. With that in mind, this concept can be extended to the other relational operaotrs such as not equal to (analogous to the XOR operator).

The following means that the is always true.

Electronics

Boolean expressions can be represented visually as a logic circuit with the symbols seen previously, logic circuits are abstracted versions of transistor circuits which are an advanced form of switching circuit, also seen previously. Every micro-processing chip in the computer you are using have many transistors, and each of them run on the principles of boolean logic

A switch may only take two states; ON (True) or OFF (False) hence the use of boolean logic. Being limited to two states required a new way to represent more information, a decimal (base 10) system was inadequate, binary numerals (base 2) was needed.

The following logic circuit is known as an "Adder circuit". All three inputs; A, B and Cin can only be 1 or 0 because they are boolean values. The circuit has two outputs which must also be boolean values. Both of these together can represent a number in binary. The "S" represents how many units or how many 20 which is 1 in both binary and decimal, the "Cout" represents how many  21 which is 10 in binary. The highest number achievable with this is or in binary, the lowest is . Full-adder logic diagram

To go higher, everyday quantities such as 8, 16 or something larger such as 4294967295 requires an enormous quantity of transistors (switches) and with the invention of the micro-processor, this allowed such massive circuits to be possible. The part of a computer's CPU (Central Processing Unit) called the ALU (Arithmetic Logic Unit), as the name suggests is what does the arithmetic for the computer, and it does this using circuits built from millions of transistors, allowing it to do arithmetic with numbers far beyond 3.

Programming

See Boolean logic in Programming Languages.