Boolean Logic: 7.1 Boolean Operators or Logical Operators
Boolean Logic: 7.1 Boolean Operators or Logical Operators
Boolean Logic: 7.1 Boolean Operators or Logical Operators
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
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
Notation: C=A’
A Not A
0 1
1 0
This operator returns true output for the events which are true if and
only if one of the motivating events are true.
Notation: C=AB
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
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
IF (age < 12 OR weight < 48) THEN do not sit in the front passenger
seat.
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 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.
8.3 Connectives
Connectives are used to construct complex and larger propositions by combining
simple propositions.
Elements of Connectives
AND ( )
OR ()
NOT ()
IF_AND_ONLY_IF ()
AND Conjunction
OR Disjunction
If---then Implication
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 PQ
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 PQ
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 PQ
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 PQ
F F T
F T F
T F F
T T T
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’