Computer Mathematics CH3
Computer Mathematics CH3
(LOGICAL OPERATIONS)
The Concept of Logical Expressions.
What is Logical Expressions?
➢It is a useful declarative sentence with a meaning that can be true or false, so that the sentence is
either true or false, but it is not true or false at the same time.
➢True or (truth) , false or (falsity), called values of the truth value of the statement (Value Truth).
➢So a logical expression: is a set of logical variables linked to each other by logical operations,
➢ for example: P ^ q v r, from this example, the logical expression here consists of three variables, r,
q, and p, and they are linked by operations NOT and AND and OR.
➢ For example: P ^ q v r, from this example, the logical expression here consists of three variables, r, q, and p, and
they are linked by operations NOT and AND and OR.
➢Examples
➢•Riyadh, the capital of Saudi Arabia "T sincere phrase"
➢•The sum of the internal corners of a triangle equals 180. T
➢•4 / 2 = 1 "false or incorrect statement"
➢These sentences are considered declarative sentences because we can answer them with true or false
Examples:
•Where are you going?
•Do your homework
Therefore, these two sentences are not declarative sentences, and we cannot answer them true or false ,so
we do not consider them mathematically as an expression Logical.
Logical Operations
1- Logical Variable
It is any variable that can take only one of two values, we mention simple expressions in as : p, q, r, s . For
example:
2- logical operations
Are the operations that can be performed in the Logical Variables .Some of these operations are basic
operations ,like: NOT , AND and OR
and some are Non-core operations, such as NAND, NOR, and XOR operations , and These operations
can be expressed using basic operations.
Compound Proposition
➢ What is a compound proposition?
➢ It is a statement made up of two or more propositions joined by the connectives, the truth of a compound proposition is defined by the
truth value of the statement composed of it and the type of the conjunction that connects between its components. Q P a simple
statement, we can create a compound proposition by using logical tools.
➢Therefore, many logical expressions are compounded, by which we mean, a compound of sub and simple expressions connected by
various connectors. The statements that cannot be broken down into simpler expressions called “ Primitive statements”.
➢The truth of a statement can only be identified by the partial truth value it contains in addition to the connector that used to form these
compound propositions.
Note:
The output of the connection process is a compound proposition that relies only on the truth value of its component
and the conjunctions that exist. We refer to the simple partial expressions ( variable ) as p,q,r,s.
Logical operation:
➢ p^q is only true in one case, when q and p are true at the same time, and p^q are false in all other cases.
➢The value truth of proposition can be summarized in a table which we usually call “ the truth table”
Example:
Let’s take these four expressions as example:
1- Riyadh is the capital of the Kingdom and Jeddah is one of the cities of the Kingdom (?).
➢ It can be read as p or q, and the truth value of the statement pvq identified by the truth value of the partial statement for
each of q and p.
➢ pvq is true If one or both of the qvp subexpressions are true, pvq is false ,in only one case, if the qvq is false at the
same time.
➢ The value truth of proposition can be summarized in a table which we usually call “ the truth table”
Example:
1- Riyadh is the capital of the Kingdom OR Jeddah is one of the cities of the Kingdom (?)
➢Using symbols, if the proposition is p, It will be written in this way: (¬p). and will be read as the following: negation
p, the truth value of (¬p) identified by the truth value p.
➢The value truth of ¬p can be summarized in a table which we usually call “ the truth table”
Example:
Let’s take these four expressions as an example:
1- To negate the proposition: the door is closed= it is not true the door is closed or the door is not
closed.
2- To negate the proposition: this thoob is white= it is not true the thoob is white or the thoob is not
white .
3- To negate the proposition: all students are smart= is not true all students are smart, but it is
wrong to say “ all students are stupid” because it is not a negation of the proposition.
(XOR):
➢ We can form a new compound proposition by using two partial simple statements connected by XOR
connecters and we can refer to the new proposition as: q⊕p.
➢ It can be read as p XOR q and the truth value of the statement p XOR q is identified by the truth value of the
partial statement for each of q and p.
➢ XOR q is true if the value of the two propositions equals one of them.
➢The value truth of p XOR q can be summarized in a table which we usually call “ the truth table”
XNOR :
➢ The output value equals one, if the values of the two propositions A and B are equal,and this value represents
negations output NOT for the value resulted from applying XOR gate on inputs, its symbol:
NOR :
➢ It is NOT OR which is a negation of OR
➢The value resulting from it, is applying negation on the value resulting from applying OR in propositions
values, the symbol of the gate are as follows:
NAND :
➢ It is an and negation (Not and).
➢ It gathers between two logical operations, where gate Not negates the value resulting from AND gate.
Truth Table
Truth table
➢ It is not necessary that compound propositions contain two sub-propositions, only p and q, however, we can
form a compound proposition by using multiple sub-propositions or several frequent connectors.
➢To calculate all possible cases through ( The number of possible proportions) ( calculating Probabilities)
➢ A truth table is a mathematical table used in logic, specifically in Boolean algebra and calculating expressions to
calculate functional values from Boolean expressions.
➢ Truth tables can be used to find out if a given expression is true for all input values or false.
➢ Before creating the truth table, it is necessary to know the number of probabilities, and this is done by knowing
the number of expressions, and then the possible cases are calculated by following the law described above
How to create truth table?
➢ If we have a compound statement of several sub-expressions, let it be for example 3 sub-expressions ( p,q,r),
as a result, the truth table will contain two rows in order to cover all possible cases since 2²=4.
➢ If we have a compound propositions of several sub-expressions, let's take, for example, 3 sub-expressions p,
the truth table will contain two rows in order to cover all possible cases since 21=2.
How to create truth table?
➢ If we have a compound proposition of several sub-propositions , let it be 3 sub-propositions (p,q.r) the truth
table will contain eight ows in order to cover all possible cases since 23=8.
Expressions and truth table
➢ Let this be the symbol P ( p,q,r .. ) for a compound proposition of a number of Boolean subexpressions while
p,q,r is the expressions or variables. There are a number of logical links ¬,v, ^.
➢The truth values of this compound proposition are identified by truth values of the expressions or variables it
contains, that is, the truth values of the compound expression are known when the values of the truth of the
variables are known.
Example:
Find the truth table for the following compound proposition (p^ ¬q) ¬.
Note:
● The actual truth table for this proposition has only two columns for the proposition p and q, for the remaining
columns, we've used stages to find a solution.
● In order to avoid using a large number of parentheses, we usually follow a certain order for calculating the
conjunctions as follows: the negative operation comes before the conjunction operation, and the latter comes
before the disjunction operation.
● ¬p^q means (¬p)^q and not (p^q) ¬
Compatibility \Tautology and Contradiction
➢ The proposition usually contains true in all cases, i.e. the last column or output is always true for any of the
variables' truth value. In this case we call the proposition Compatibility\ Tautology because it is always true.
➢ Conversely, that is, when the output is always false,That is, the last column only contains an F, so in this case,
the proposition is a contradiction.
Example:
Clarify, why(p v p) v q¬ is Compatibility\ Tautology?
We can notice that it contains only T, so the output will be Compatibility\ Tautology, accordingly
, we will write ¬p v ( p v q )=
T= ¬p v ( p v q ).
Example:
Clarify that, (p∧q)∧¬(p∨q) is a contradiction?
We can notice that (p∧q)∧¬(p∨q) it contains only F, so the output will be Contradiction , accordingly, we will write
(p∧q)∧¬(p∨q) = F.
Logical equivalence
➢Propositions p and q are said to be logically equivalent if they produce the same truth value. We refer to it as P(p,q. .) ≡
Q(p,q, … ) so, ≡ is the equivalence symbol.
➢ Answer: We calculate the truth table for the two propositions as follows.
➢We notice that the last column of ¬ (p∧q ) and ¬p∨¬q are equal , so we write: ¬ ( p ∧ q) ≡ ¬p ∨ ¬q.
Algebraic expression \Laws of Algebra
➢Let assume the random subexpressions are: p,q,r.
➢In the following table you will find the algebraic laws as they can be accessed using the truth table :
(p ∨ q) ∨ r ≡ p ∨ (q ∨ r).
We can notice that the truth values of (p ∨q) ∨r , which are in the fifth column, and the truth
values in the seventh column are equal, i.e. they have the same value, so we the output as
following :
(p ∨ q) ∨ r ≡ p ∨ ( q ∨ r).
Example: An example of Absorption Laws:
Prove the true of statement : (p ^ q) v p ≡ p.
Answer:
We can notice that the first column p is equal to the last column ( p ^ q ) vp, so: ( p ^ q ) vp≡p.
Example: Clarify the following, using Algebraic expression laws:
a) ¬(p∨q)∨(¬p∧q)≡¬p.
➢ It should be read in this way: "p requires q", or in this way: "p only if q".
➢ In the conditional proposition, the sentence that comes immediately after the word (if), is called the hypothesis.
➢In the conditional proposition, the sentence that comes immediately after the word “ then” called the “ result”.
➢ The proposition p→q is false if q is false, and p is true, but in all other cases it is always true.
➢ The truth able of the p→q proposition can be summarized by the table that it is called the truth table :
Verbal expression Symbols Example
In summary:
Example:
Example:
False: The hypothesis is true, and the result is false, because Mecca is not located in Iraq.
False: The hypothesis is true and the result is false, because the number 7 is odd and is not divided by 5.
4- If the white color results from mixing blue and red, then 3-2=0.
True: the hypothesis is false because mixing red and blue produces violet. The result is also false.
Notes on the conditional propositions
➢ We can replace the conditional link → by connecting the disjunction v as following:
p→q≡¬p∨q
➢The It is clear that the third and last column are equal, winch means p→q ≡ ¬ p ∨q, in another word, if p then q,
equals “ the negation of p and q”
Example: An example :
● Compare the following expressions:
p→q, q→p, ¬p→¬q, ¬q→¬p.
p→q ≡ ¬q→¬p
q → p ≡ ¬p → ¬q
Hence, there is the convers q→p, ¬p→¬q the inverse, and ¬q→¬p the contrapositive.
Verbal expression Symbols
the converse results from replacing the hypothesis by the result in the q→p
conditional statement q → p
the inverse results from negating both of the hypothesis and the ~p →~q
result.
the contrapositive results from negating both of the hypothesis and ~q→~p
the result when the conditional statement convered.
This duble conditional statement is true whenever both p and q are true or false at the same time and is false in the
remaining cases.
The truth value of the proposition p→q can be summarized in the truth table: