Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Boolean Logic: 7.1 Boolean Operators or Logical Operators

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Chapter 7

Boolean Logic
Boolean logic is a logic that operates on two symbols. It is a symbolic language.
It is a modern extension of Aristotelian logic where symbols represent statements
of truth. It is a symbolic logic system. Boolean logic was devised for dealing
mathematically with philosophical propositions which have only two possible
values: True and False. It was invented by a Mathematician named George Boole
in 1850 and the logic was named after him. In Boolean logic, logical operators
known as logical connectives are used to express logical thought.
Boolean algebra deals with systems that operate with two possible conditions:
ON and OFF. The states are represented as zero and one. Therefore, binary digits
are considered to be suitable for this representation. In general, Boolean algebra
deals with the rules that govern various operations between the binary variables.
Therefore, Boolean logic is also known as binary logic.
7.1 Boolean Operators or Logical Operators
Boolean variables are manipulated by Boolean operators. The operation or
functionality of Boolean operators are expressed in the form of truth tables.
1. AND operation or Conjunction

This operator produces a true output only if all inputs are true.

Notation: A.B

A B A AND B
0 0 0
0 1 0
1 0 0
1 1 1

Fig. Truth table for AND operator

Here L is the output.


2. OR operation or Disjunction

This operator produces a false output only if all inputs are false.

Notation: A+B
A B A AND B
0 0 0
0 1 1
1 0 1
1 1 1

Fig. Truth table for OR operator


3. NOT operation or Inversion

NOT operator is used to inverse the input. It is a unary operator which


accepts a single input.

Notation: C=A’

A Not A
0 1
1 0

4. Exclusive OR (XOR) Operation

This operator returns true output for the events which are true if and
only if one of the motivating events are true.

Notation: C=AB

A B A XOR B
0 0 0
0 1 1
1 0 1
1 1 0

5. NAND Operation
An ‘AND’ operation followed by a NOT operation results in a NAND
operation.
Notation: F = (A.B)’
A B A NAND B
0 0 1
0 1 1
1 0 1
1 1 0
6. NOR Operation
An OR operation followed by NOT operation results in a NOR operation.
Notation: (A+B)’

A B A NOR B
0 0 1
0 1 0
1 0 0
1 1 0

7.2 Basic Laws of Boolean Algebra

Boolean variables are governed by certain laws.


1. Commutative Law
A+B = B+A
A.B = B.A
2. Associative Law
A+(B+C) = (A+B)+C
A(BC) = (AB)C
3. Distributive Law
A(B+C) = AB+AC
4. A+0 = A
5. A+1 = 1
6. A.0 = 0
7. A.1 = A
8. A+A = A
9. A+A’ = 1
10. A.A = A
11. A.A’ = 0
12. A’’ = A
13. A+AB = A
14. A+A’ B = A+B
15. (A+B)(A+C) = A+BC
7.2.1 De-Morgan’s Theorems
Boolean variables are also governed by De-Morgan’s theorems. The theorems
are stated as follows:
 The inverse of a product is equal to the sum of the complements
(AB)’ = A’ + B’
 The inverse of a sum is equal to product of its complements
(A+B)’ = A’.B’

7.3 Applications of Boolean Logic


Boolean logic can be used to design control systems. There is a car with three
main control systems. A warning lamp should be designed to light if any of the
following conditions occur:
 All systems are down

 Systems A,B down but C is ok

 Systems A,C down but B is ok

 System A down, but B,C are ok

Solution:
There are two possible states for each system.
Assign
System: Down=0, OK=1
Light : Off=0, On = 1
The logic block diagram of the system is shown below:
Prepare the truth table as shown below. The system has 3 control systems with
two states. Therefore, 3 bits are required to represent the states of all the three
systems. Altogether there are 23 = 8 states.
A B C F
0 0 0 1
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 0

Write the logic equations from the truth table.


F=A’ B’ C’ + A’ B’ C + A’ B C’ + A’ B C
Simplify the equation using Boolean laws
F = A’ (B’ C’ + B’ C + B C’ + B C)
= A’ [B’ (C’+C) + B (C’+C)]
= A’ [ B’ . 1 + B. 1]
= A’ [B’+B]
= A’. 1
= A’
F=A’
7.3.1 Applications of Boolean Logic in Programming
In programming, boolean logic is used in selection statements and loop
statements.
Examples:
 The passenger-side air bag may cause injury to children who are
under the age of 12 or who weigh less than 48 pounds. They should
not sit in the front passenger seat of this car.

 IF (age < 12 OR weight < 48) THEN do not sit in the front passenger
seat.

7.3.2 Simplification of Equations using Boolean Logic


Ex. 1
Simplify (XY)’(X’+Y)(X’+X)
(XY)’ (X’+Y) (X’+X)
Applying De-Morgan’s theorem
(X’+Y’) (X’+Y) . 1
= X’ + Y’ Y [(A+B) (A+C) = A+BC]
= X’ + 1
= X’
Ex. 2
Simplify : XY+X(Y+Z)+Y(Y+Z)
XY + XY + XZ + Y.Y + YZ
= XY + XY + XZ + Y + YZ
= XY + XZ + Y [A + AB = A]
= XY + Y + XZ [Rearranging]
= Y (X+ 1) + XZ
= Y. 1 + XZ
= Y + XZ
Chapter 8
Propositional Logic
Propositional logic is a branch of Mathematics that deals with propositions, their
truth values and how they combine. A proposition is a declarative statement that
is either true or false. It cannot be both true and false at the same time. T denotes
true and F denotes false.
Example
 5+2=7
 5+2=2
 The sun rises in the east.
 Milk is white
 The earth is flat

Some sentences are not propositions. For example,

 What time is it?


 Go in a straight line
 Don’t look back

The above sentences are not propositions. In general, questions, commands and
exclamations are not propositions.
8.1 Propositional Logic
A formal language for representing knowledge and for making logical inferences
is known as propositional logic. It is sometimes called as sentential logic or
statement logic.
8.2 Symbolization of Propositional Logic
In Propositional Logic, capital letter is used to represent a simple sentence. Small
case letters are also used in some notations. Simple sentences are relatively short
and do not contain any other sentence as a component.
Ex.
• Grass is green.

• The sky is blue

The first sentence ‘Grass is green’ can be symbolized as G. The second sentence
‘The sky is blue’ can be symbolized as S.
All statements cannot be propositions. Propositional functions are statements
that may be true or false. It is a sentence expressed in a way that would assume
the value of true or false, except that within the sentence is a variable (x) that is
not defined or specified which leaves the sentence undetermined.
For example,
– 5 + n = 12 is not a proposition because it might be true only for some
value of n, eg. n=7.

– It may rain today

– Will there be a thunderstorm?

8.3 Connectives
Connectives are used to construct complex and larger propositions by combining
simple propositions.
Elements of Connectives

 AND ( )

 OR ()

 NOT ()

 IF_THEN (IMPLY) ()

 IF_AND_ONLY_IF ()

Propositions and connectives are the basic elements of propositional logic.


Natural Language and Logical Notation of Connectives
Symbol Natural Language Connectives
Notation (Technical
Notation)
 NOT Negation

 AND Conjunction

 OR Disjunction

 If---then Implication

 If and Only If (Iff) Equivalence


The functionalities of the connectives are specified using truth tables.
NOT
NOT is a unary connective. It takes only one argument. Any proposition can be
prefixed by the word ‘not’ to form a second proposition called as the negation of
the original. If p is an arbitrary proposition then the negation of p is written p.
In truth tables, True is represented as T and false as F.
Truth Table:
P P

T F

F T

AND
Combining any two propositions using AND operator forms another proposition
called as the conjunction of the original propositions. The AND operator is
denoted by the symbol . If p and q are arbitrary propositions, then the
conjunction of p and q is written as p^q and will be true iff both p and q are true.
Truth Table

P Q PQ
F F F
F T F
T F F
T T T

OR
Combining any two propositions using OR operator to form another proposition
is called disjunction of the original propositions. The OR operator is denoted by
the symbol . If p and q are arbitrary propositions, then the disjunction of p and
q is written p  q and will be true if either p is true, or q is true, or both p and q
are true.
Truth Table

P Q PQ
F F F
F T T
T F T
T T T
IF… THEN
There are sentences of the form If p is true (false) then q is true (false). Another
way of saying this is p implies q. In propositional logic, there is a connective called
if … then, that combines two propositions into a new proposition called the
conditional, or implication of the originals. If p and q are arbitrary propositions, then
the conditional of p and q is written as p  q and will be true iff either p is false or
q is true.
Truth Table

P Q PQ
F F T
F T T
T F F
T T T

IF and ONLY IF
Another common form of statement is: p is true if, and only if, q is true. The sense
of such statements is captured using the biconditional operator. If p and q are
arbitrary propositions, then the biconditional of p and q is written: p  q and
will be true iff either
 1. p and q are both true; or
 2. p and q are both false.
Biconditionals are true when both statements (facts) have the exact same truth
value.
Truth Table
P Q PQ
F F T
F T F
T F F
T T T

8.4 Applications of Propositional Logic


Propositional logic is applied in various domains such as a analysis and
synthesis of digital circuits, knowledge representation and machine learning
systems. They are used in querying search engines, querying databases.
8.4.1 Querying Search Engines
A web search engine is a software system to search for information on the World
Wide Web. It is a remotely accessible program that lets you do keyword searches
for information on the Internet. The search engine takes your phrase / keyword
and returns search engine results pages with a list of sites it deems relevant or
connected to your searched keyword.
Consider a situation where you live in a city that has a grocery store named
“Green” You would like to use a search engine to find the phone number and the
hours of operation for this store. You use the term “green”. When this text is
written, the returned results may be:
 Green is a color
 Green Party’s home page
 The website of “Green Climate Fund” ,
 A Wikipedia article titled “Green” ,
 A link to a web page devoted to the “Green and Clean”.

Therefore, you notice that your query did not return the relevant results.
A search query is a phrase that describes the information that the user seeks to
obtain. If you use single-word queries, the word may be ambiguous or frequently
used across many different contexts. It may sometimes be effective, but often fail
to produce the right type of information. It often not specific enough to provide
useful results. Therefore, you need to narrow the focus of your query. You should
construct more specific search queries. The connectives in propositional logic
such as AND, OR, and NOT are one technique that is commonly used to narrow
a search query.
8.4.1.1 Conjunction in Search Queries
A search query returns web pages that contain all the terms or phrases in the
query. By default, all search queries that use more than one word use
conjunction.
For example, if you query for ‘Green Basket’, the search engine will interpret the
above query as ‘Fetch all web pages containing Green AND Basket. To narrow
down the search further, use more words in the query. For example, Green
Basket Coimbatore.
8.4.1.2 Disjunction in Search Queries
Suppose you want to search the details of Green Basket or Green BigBasket but
not both. Then the search query should be “Green AND (Basket or BigBasket)”.
This query correctly expresses your desire to find web pages that contain only
Basket or BigBasket’ but not both.
8.4.1.3 Negation in Search Queries
If you want to exclude any word from a query, use negation. Search engines use
the NOT operator to exclude pages that contain certain words. (Represented by
– symbol) For example, Green AND (Basket or BigBasket) AND –Fresh
Note:
Most search engines require the logical operators to be entered in all capital
letters.
8.4.2 Querying Databases
Databases are software systems designed to efficiently store enormous amounts
of data such that pieces of data in the database can be very quickly located and
retrieved. Most databases store information in tables such that each row of the
table contains a set of data that belongs to a single record. Each column of the
table defines a field and every cell of the table contains one field for one record
of data. A supermarket project may have tables such as Products, Prices,
Customers, Orders and Transaction with relevant columns or fields. Databases
are designed to efficiently locate records in response to well-formed queries.
Although somewhat similar to a web search, a database query requires more
precise structure and is generally written in a language known as SQL
(Structured Query Language). Records in a database are located by issuing a
select statement. The general form of a select statement is:
Select field1, field2, … , field n from table where criteria
Examples:
List out products which have unit price > Rs. 1000
Select * from product where unit_price>1000
List out customers who have bought provisions and transactions exceed Rs.
10,000/-
Select prod_category, sum(amount) from transaction group by customerId
having sum(amount)>10000.
List out orders of cosmetics exceeding Rs. 5000/-
Select orderId, price from orders where price > 5000 and category =
‘cosmetics’
List products in provisions and cosmetics category
Select productId, productName from products where category = ‘cosmetics’
or category = ‘provisions’

You might also like