0% found this document useful (0 votes)
8 views

Computer Mathematics CH3

Logical expressions are declarative sentences that can be either true or false. A logical expression consists of logical variables connected by logical operations like AND, OR, and NOT. Truth tables are used to calculate the functional values of Boolean expressions by listing out all possible combinations of true and false values for the variables. They determine if a given logical expression is true for all inputs or always false, known as a tautology or contradiction.

Uploaded by

abos3od
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Computer Mathematics CH3

Logical expressions are declarative sentences that can be either true or false. A logical expression consists of logical variables connected by logical operations like AND, OR, and NOT. Truth tables are used to calculate the functional values of Boolean expressions by listing out all possible combinations of true and false values for the variables. They determine if a given logical expression is true for all inputs or always false, known as a tautology or contradiction.

Uploaded by

abos3od
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

LOGIC EXPRESSIONS AND OPERATIONS

(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).

➢If a statement is true, it will be denoted by “T” or 1,

➢ and if it is false, it will be denoted by “F” or 0.

➢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.

An example of compound proposition:


● Omar is a good student, and Nasser is a smart boy.
● The figure ABCD is a square, and the length of each side is 4 cm.

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:

1- the operation of conjunction: “ And”, its code: ^.

2- the operation of disjunction: “ Or “ its code: v

3- the operation of negation: “ Not” its code: ¬

4- ( the operation of ExclusiveOR)(XOR) where (Nor) means (NOT XOR).

5- the operation of (NOT OR)(NOR).

6- the operation of (NOTAND)(NAND).


The operation of conjunction ( “ And” “ ^”)
➢ we can form a new compound proposition by using two partial simple statements connected with conjunction
words ( “ And” “ ^”), we refer to this new statement with p^q. And read this way:p and q, the truth value of the
statement read this way: p^q it relies on the truth value of the partial expression for each q and p.

➢ 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 (?).

2-Riyadh is the capital of the Kingdom and 5= 2+4 (?).

3- Jeddah is the capital of the Kingdom 6 and It is divided by 2 (?).

4- The number of days of the week is 6 and 0 is a natural number.


Disjunction: (v) (or)
➢ We can form a new compound proposition by using two sub simple propositions connected by disjunction means (v)
or (OR) we refer to this new statement as: pvq.

➢ 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 (?)

2-Riyadh is the capital of the Kingdom OR 5= 2+4 (?).

3- Jeddah is the capital of the Kingdom 6 OR It is divided by 2 (?).

4- The number of days of the week is 6 OR 0 is a natural number.


Negation (Not) ( ¬)
➢ A new statement can be formed from a statement by using negative form, and this is done by adding the words
“not.”It is true that.” before the statement.

➢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.

➢ If p is true, ¬p will be false and if p is false, ¬p will be true.

➢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.

Example: using truth table between the following equivalence:

➢ 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 :

Substitution Law\ Identity element


Commutative Laws.

Aggregation laws\ Complement Laws


Associative Laws.

Distributive Laws Double Complementation law

Zero growth law


De Morgan's Laws.
Example: An example of Associative Laws\ aggregation laws:
Applying the law of aggregation laws 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.

Phases of solving Reason


Example: Clarify the following, using Algebraic expression laws:

Phases of solving Reason


Conditional Propositions
➢a proposition of the form ( if p then q), where p and q are subexpressions, is called a conditional proposition and is referred to
as: p→q.

➢ 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

conditional proposition: ( if… then). ● p→q. if the shape is square, then it is


Should be read as rectangular.
follows :
( if p… then q)
( or p lead to q)
● In the conditional proposition, the sentence that p shape is square
comes immediately after the word (if), is called the
hypothesis

● In the conditional proposition, the sentence that q it is rectangular


comes immediately after the word “ then” called the “
result”.

In summary:
Example:
Example:

Determine the true value for each conditional proposition:

1- If you live in Mecca, then you live in Iraq.

False: The hypothesis is true, and the result is false, because Mecca is not located in Iraq.

2- If tomorrow is Thursday then today is Wednesday.

True, because Thursday comes after Wednesday.

3- If the number is odd, it is divided by five.

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

➢ We can also check with the truth table.

➢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.

From this table we conclude that:

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

conditional statement is the statement that can be written in a form p→q


of ( if p then q) .

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.

A brief of Converse, Inverse, Contrapositive


Negotiation of the conditional statement
➢ ¬ ( p→q)

Note: by using Morgan law, we will have:


¬(p→q) ≡ ¬(¬p ∨ q) ≡ p∧¬q.
Double Negation Laws statement
It means, ( if and only if), and refered to as: p→q.

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:

Example: prove the following using the table:


p↔q ≡ (p→q) ∧ (q→p).
Example:
Example: prove the following using the table:
p ⊕ q ≡ ¬ (p ↔ q).
Note: Priority conjunction tool
Conjunctions by order:
1 ¬ (negation).
2 ^ ( and)
3 V ( or )
4 → conditional statement
5 ↔ binary statement

¬ p ^ q means (¬p) ^q.


(p ^ q) →r means ( P ^ q →r)

It is better to use brackets to give the priority for the operations


between brackets.

You might also like