Leibniz Ejercicios PDF

You might also like

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

References

Logic (Mathematics 1BA1) A Logical Approach To Discrete Math


D. Gries & F. B. Schneider, Springer 1994.

Rozenn Dahyot Logic And Discrete Mathematics - A Computer Science Perspective


John Olarte
Room 128 Lloyd Institute
W. K. Grassman & J.-P. Tremblay, Prentice 1996.
U. Nacional
School of Computer Science and Statistics

June 2015
Trinity College Dublin, IRELAND
Introduction to Logic
https://www.cs.tcd.ie/Rozenn.Dahyot/
Bogota, Colombia
Rozenn.Dahyot@cs.tcd.ie
M. Huggard & Mark Dukes, Trinity College textbook 2002.

Week 1 - January 2007 Boolean Algebra with Computer Applications


G. E. Williams, McGraw-Hill 1970.

I ntroduction to Logic I ntroduction to Logic

Logic is central in many areas:


If we had some exact language...or at least a kind of truly
Maths philosophic writing, in which the ideas were reduced to a kind of

Philosophy alphabet of human thought, then all that follows rationally from

Linguistic what is given could be found by a kind of calculus, just as

Computer Science arithmetical or geometrical problems are solved.

etc. Leibniz (1646-1716)


Sometimes our logical reasoning is faulty and errors can result. The idea of machines that reason has been around for a long time.
Consequently arised the need of identifying the laws of logic.

Expressions State and Evaluation


Denitions.
Mathematical expressions are made up of constants, variables and Denitions.
operators. A state is a list of variables with specic values assigned to them.
Parentheses are used to indicate aggregation (i.e. to bring together Evaluation of an expression E in a state means replacing all

different expressions). variables in E by their values in the state and simplifying the
expression.
Example:
3 × (x + 2) = 5 Example:
If we have E as x + y + z, then E evaluated in the state (x, 1), (y, 3) and
The constants are 2 and 5, the variable is x, the operators are ×, +
(z, 5) is simply 1 + 3 + 5 = 9.
and =. The parentheses bring together x and 2. 3 × (x + 2) denotes
the product of 3 and (x + 2).
Textual Substitution Exercise: Textual substitution
Textual Substitution. 1 Let the variables x, y, z be in the state (x, 1), (y, 42), (z, 5). Evaluate
If we have an expression E containing some variable x, then we can
the following expressions in this state:
replace every occurrence of x in E with the expression (R). This
operation, called textual substitution takes precedence over all (i) 2x + 3y − z (v) 5x − z + 1
other operations, and is written as E[x := R]. (ii) 2 + x + 4yz (vi) 7x2 + y − yz
(iii) 32 (vii) xyz
(iv) x + y(z − x) + z ÷ x (viii) (y − 2x) ÷ z
Example:
Let E be the expression (x + 1)(x − y) and let R = y + z. Then
2 Perform the following substitutions:

E[x := R] = ((x + 1)(x − y))[x := y + z] (i) x[x := 4] (v) (x + y · x + z)[x := −z]


= (((y + z) + 1)((y + z) − y)) (ii) (x)[x := x · y · z] (vi) (1 + 2 + 3)[k := π]
= (y + z + 1)(y + z − y) (iii) (m · x + c)[x := −1] (vii) (7 + x · z + u · v)[u := 4]
= (y + z + 1)z (iv) m · x + c[x := −1] (viii) (e = v · c)[v := m · c]

Remarks on Parentheses Remarks on Parentheses

The order in which parentheses are placed is important.

Example: BODMAS Brackets Order Division Multiplication Addition


The expression m = (y2 − y1 )/(x2 − x1 ) gives the slope Subtraction.
of a line with points (x1 , y1 ) and (x2 , y2 ). Without the
y
parentheses we would have m = y2 − 1 − x1 which The Reverse Polish Notation
x2
does not give the slope. http://www.hpmuseum.org/rpn.htm

Similarily in textual substitution, E[x := R] means replace every x BODMAS rule http://www.calculator.org/rpn.html
in E with (R). The reason that we replace x by (R) rather than R
is for rigor. This way we avoid making mistakes when working
with the new expression.

Simultaneous Substitution & Iterated Simultaneous Substitution


Substitution
Simultaneous substitution is the act of replacing all the variables at
once.
The simultaneous substitution E[x, y := R1 , R2 ] means replace every x
W hat happens if we want to substitute more than one variable in an by (R1 ) and every y by (R2 ).
expression?
Example of Simultaneous substitution:
There are two different ways we can do this: If E is x + 2y + 3z, R1 is b − 2a, R2 is a and R3 is 0, then
simultaneous substitution,
E[x, y, z := R1 , R2 , R3 ] = (x + 2y + 3z)[x, y, z := b − 2a, a, 0]
= ((b − 2a) + 2(a) + 3(0))
iterated substitution.
= (b − 2a + 2a + 0)
= b
I terated Substitution I terated Substitution
Iterated substitution is the act of applying substitutions to an Note that when doing iterated substitution, the order in which the
expression one-by-one. E[x := R1 ][y := R2 ] means rst do E[x := R1 ] substitutions are done is important.
and call it E′ . Then do E′ [y := R2 ].
Example of Iterated substitution:
Example of Iterated substitution: E is the expression x + 2y + 3z, R1 is 2y, R2 is z and R3 is 2. Compute
If E is the expression x + 2y + 3z, R1 is 2y, R2 is z and R3 is 2, then E[y := R2 ][x := R1 ][z := R3 ]

E[x := R1 ][y := R2 ][z := R3 ] = (x + 2y + 3z)[x := 2y][y := z][z := 2] E[y := R2 ][x := R1 ][z := R3 ] = (x + 2y + 3z)[y := z][x := 2y][z := 2]
= ((2y) + 2y + 3z)[y := z][z := 2] = (x + 2(z) + 3z)[x := 2y][z := 2]
= ((2(z)) + 2(z) + 3z)[z := 2] = (x + 5z)[x := 2y][z := 2]
= ((2((2))) + 2((2)) + 3(2)) = ((2y) + 5z)[z := 2]
= (4 + 4 + 6) = 14 = (2y + 10)

Simultaneous & Iterated Substitution Remark on assignement :=

Denition:
x := E evaluates expression E and stores the result in variable x.
Simultaneous (x + 2y)[x, y := y, x] =
Assignment x := E is read x becomes E.

Example: To increment x in a loop (program)


Iterated (x + 2y)[x := y][y := x] = x := x + 1

On the other hand, to write (x = x + 1) (equivalent to 1 = 0) is false.

Summary Substitution as an Inference Rule


you know about:
expressions, operators, variables, states, evaluation of
expression, Inference Rule Substitution:
If E is true, then E[v := R] must be true for any expression R.
Iterated & Simultaneous Textual Substitution, Written as E E[v := R]

difference between assignment and equality, Example:


if E dened as x + y = y + x is a true, the substitution rule allows us to
d
Prece ence of textual substitution. conclude that b + 3 = 3 + b is also true (this is E[x, y := b, 3]).

d
Prece ence is t he characteristic of operators that indicates when
they will be evaluated when they appear in complex expressions
4 laws of Equality Using the Inference Rule Leibniz

Example:
Four laws of equality
Let X = 2x + 1, Y = y − 3x and E be the expression (z + 1)(z − 1). The
1 Reexivity x=x Inference Rule Leibniz gives
X=Y 2x + 1 = y − 3x
2 Symmetry (x = y) = (y = x) yielding
E[z := X] = E[z := Y] E[z := 2x + 1] = E[z := y − 3x]

X = Y, Y = Z From this we may derive


3 Transitivity
X=Z
E[z:=X] E[z:=Y]

Inference rule Leibniz if X = Y is true


z }| { z }| {
4 (2x + 1 + 1)(2x + 1 − 1) = (y − 3x + 1)(y − 3x − 1)
E[z := X] = E[z := Y] is true.
  giving
X=Y
i.e. 2x(2x + 2) = (y − 3x + 1)(y − 3x − 1)
E[z := X] = E[z := Y]

Exercise: Leibniz's Inference Rule Solution: Leibniz's Inference Rule


Computing E[z := X] = E[z := Y] gives:
(i) (4z + y)[z := x] = (4z + y)[z := x + 2]
gives (4x + y) = (4x + 8 + y)
Apply Inference Rule Leibniz to the following (where substitution
takes place in the variable z): (ii) (4x + z)[z := x] = (4x + z)[z := x + 2]
gives 5x = 5x + 2
(i) X = x, Y = x + 2 and E = 4z + y
(ii) X = x, Y = x + 2 and E = 4x + z (iii) (2x − z)[z := 2x + 1] = (2x − z)[z := −w]
(iii) X = 2x + 1, Y = −w and E = 2x − z gives −1 = 2x + w
(iv) X = 2w + 1, Y = a + 3w − 5 and E = 2z − 4w − 10
(v) X = x, Y = x + 2 and E = 2 (iv) (2z − 4w − 10)[z := 2w + 1] = (2z − 4w − 10)[z := a + 3w − 5]
gives −8 = 2a + 2w − 20

(v) (2)[z := x] = (2)[z := x + 2]


gives 2 = 2

G. W. Leibniz (1646-1716) Function evaluation

Notice that if z is a variable in an expression E, then we can dene a


function f such that f (z) is the expression E. Then the textual
substitution E[z := R] may be written as f (R).

Denition:
f .z is the new notation for f (z)

Example:
Let E be the expression 2x − y + m. Then we could dene
f (x) = 2x − y + m = E. Performing the substitution E[x := y] is the same
as f (y).
Example and exercises Reasoning using Leibniz
The purpose of this section is to
Example introduce a method for proving the equality of two expressions,

Let f be the function f (x) = x2 + 3x + 4. Then and


introduce a format for such proofs.
f .3 = f (3) = (3)2 + 3(3) + 4 = 9 + 9 + 4 = 22

The Format:
1 Let f (x) = 2x − 1 and g(x) = x2 − 1. Evaluate the following Let us suppose that two expressions E0 and E1 are equal. A proof

that both are equal will take the following format:


(i) f .1 (v) f .g.3
(ii) g.1 (vi) g.f .3 E0
(iii) f .3 (vii) f .g.f .1 = h The reason i
(iv) g.10 (viii) g.g.x E1

In the angle brackets hi, we explain the reason or inference rule by


which we derive the fact that E0 is equal to E1 .

Reasoning using Leibniz Reasoning using Leibniz


Using Leibniz
The basic form of this reasoning/proof process when using
Inference Rule Leibniz is:
Example:
Let 1 + 2j = 3k and 2k = p. E0 is 3 + 4j and E1 is 1 + 3p. Show E0 = E1 : E[z := X]
= h Since X = Y i
3 + 4j E[z := Y]
= h 1 + 2j=3k, and multiply this by 2 i
1 + 6k
= h 2k=p, and multiply this by 3 i Example:
1 + 3p Let E be the expression 1 + 2z. Let X = 1 + 2j and Y = 3k. Then
performing Inference Rule Leibniz gives
1 + 2(1 + 2j)
= h 1+2j=3k i
1 + 6k

Assignement Statement Assignement Statement

Denitions:
Execution of the assignment statement x := E evaluates expression Example:
E and stores the result in the variable x. Let our statement be x := x + 1. If x > 0 (precondition) then the state
Let S be a statement. A precondition, P, of S is an assertion about in which the statement terminates must have x > 1. Hence one
the variables of S in which the statement S may be executed. A Hoare triple is:
postcondition, Q, of S is an assertion about the states in which S {x > 0} x := x + 1 {x > 1}
may terminate. This Hoare triple is said to be valid because the execution of
We represent this situation by a Hoare triple. in which x > 0 terminates in a state in which x > 1.
x := x + 1

{P} S {Q}
Assignement Statement Exercise: Assignement Statement

Example:
This Hoare triple 1 Decide whether the following triples are valid.

{x = 5} x := x + 1 {x = 7} (i) {x > 0} x := x2 {x < 0}


(ii) {x > 0} x := x − 1 {x > 1}
is not a valid because the execution of x := x + 1 with x = 5 does not (iii) {x even} x := x/2 {x odd}
terminate in a state in which x = 7.

Solution: Assignement Statement Conditions on Assignment


Conditions on assignment.
Given an assignment x := E and a postcondition R, we may write down the
precondition to complete the Hoare triple:

{R[x := E]} x := E {R}

1 Solution (i) non valid Example:


Let x := x + 1 and let R be the postcondition {x > 6}. Then our precondition is
(ii) non valid
(iii) non valid P = R[x := x + 1]
= ( x > 6 )[x := x + 1]
= ( (x + 1) > 6 )
= x>5

Hence we have the Hoare triple:

{x > 5} x := x + 1 {x > 6}

Exercise: Conditions on Assignment Solution: Conditions on Assignment


1 Find the suitable precondition P in order to make each of the following
Hoare triples valid.

(i) {P} x := 2x + 1 {x > 3}


(ii) {P} x := 2x {x > 15}
(iii) {P} x := x + y {x = y} 1 (i) x>1
(iv) {P} x := 7 {x = y} (ii) x> ln 15
ln 2
2 The following is a function dened in the C-programming language. (iii) x=0
int newfunction(int n) (iv) y=7
{
2 x ∈] − ∞; −10[ ∪ ]60; +∞[
int answer;
answer = n*n - 50*n - 600;
return answer;
}
What is the precondition P such that:
{P} x := newfunction (x) {x > 0}

You might also like