1 / 22

Discrete Structures Lecture 2 Textual Substitution and Equality Read: Ch 1.1 - 1.4 (This lecture)

Discrete Structures Lecture 2 Textual Substitution and Equality Read: Ch 1.1 - 1.4 (This lecture) Ch 1.5 - 1.6 (Next lecture). What is an expression?. A constant (e.g. 41 ) is an expression. A variable (e.g. x ) is an expression. If E is an expression, then ( E ) is an expression.

Télécharger la présentation

Discrete Structures Lecture 2 Textual Substitution and Equality Read: Ch 1.1 - 1.4 (This lecture)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Discrete Structures Lecture 2 Textual Substitution and Equality Read: Ch 1.1 - 1.4 (This lecture) Ch 1.5 - 1.6 (Next lecture)

  2. What is an expression? • A constant (e.g. 41) is an expression. • A variable (e.g. x) is an expression. • If E is an expression, then (E) is an expression. • If ˚ is a unary prefix operator and E is an expression then ˚E is an expression, with operand E. • If * is a binary infix operator and D and E are expressions, then D*E is an expression, with operands D and E.

  3. Textual Substitution Suppose we have an expression, E, given by: 2•x + x•y + 3 Replace all occurrences of x with a: 2•a + a•y + 3 Formally, we write: E[x := a] Expression E, with all occurrences of x replaced with a.

  4. General Formula for Textual Substitution expressionsE and R, E[x := R]variablex is an expression that is the same as E but with all occurrences of x replaced by “(R)”.

  5. more Textual Substitution (x+y+y2)[y := z+y] what are we replacing? the y’s in x + y + y 2 with what? (z+y) note: occurrences in replacement expression z+y are NOT replaced. x+(z+y)+(z+y)2 x+z+y+(z+y)2

  6. Textual Substitution Examples Expression: (x•y+x)[x:=b+2] Result: (b+2)•y + (b+2) Unnecessary-parens: (b+2)•y + b+2 Expression: x•y+x[x:=b+2] Result:x•y +(b+2) Unnecessary-parens:x•y + b+2

  7. Simultaneous Textual Substitution E[x := R] expressions E and R(a list of expressions), x (a list of distinctvariables) is an expression that is the same as E but with all occurrences of the x variables replaced by the corresponding expressions of R, each enclosed in parentheses.

  8. Simultaneous Examples Expression: x[x,y:=b+2,x+2] Result: (b+2) Unnecessary-parens: b+2 Expression: (x•y+x)[x,y:=a+b,x+7] Result:(a+b)•(x+7)+(a+b) Unnecessary-parens:(a+b)•(x+7)+a+b

  9. Sequential Textual Substitution Textual substitution is left associative. E[x := R][y := Q] is defined to be (E[x := R])[y := Q] which is a copy of E in which every occurrence of x has been replaced by R and then every y has been replaced by Q.

  10. Sequence versus Simultaneous Expression: (x+2•y)[x,y:=y,x] Final answer: y+2•x Expression: (x+2•y)[x:=y][y:=x] First substitution:(y+2•y)[y:=x] Final answer: x+2•x

  11. Inference Rule The inference rule provides a mechanism for deriving "truths" or theorems. A theorem is an expression that is true in all states. The inference rule is written as follows: (Expression or list of Expressions) Epremise/hypothesis if true Rconclusion then also true

  12. Inference Rule Substitution(1.1) Epremise/hypothesis if true E[v := F]conclusion then also true expression E , a list of variables v, and a corresponding list of expressions F This rule asserts that if expression E is a theorem, then so is E with all occurrences of the variables of v replaced by the corresponding expressions of F.

  13. Example E is 2•x/2 = x We can use inference rule substitution to show: 2•x/2 = x (2•x/2 = x)[x := j+5] OR 2•x/2 = x 2•(j+5)/2 = j+5

  14. Problem 1.6 Inference rule Substitution (1.1) stands for an infinite number of inference rules, each of which is constructed by instantiating expression E, list of variables v, and list of expressions F with different expressions and variables. Example: Show three different instantiations of the inference rule, where E is x < y V x >= y. OR

  15. Possible Solution 1.6 x < y V x >= y (x < y V x >= y)[x,y := 1,2] or, after textual substitution x < y V x >=y 1 < 2 V 1 >= 2

  16. Two more solutions for 1.6 x < y V x >= y a+b < 5 V a+b >= 5 from (x < y V x >= y)[x,y := a+b,5] x < y V x >=y 16-y < x V 16-y >= x from (x < y V x >= y)[x,y := 16-y,x]

  17. Four Laws that Characterize Equality (1.2) Reflexivity: x=x (1.3) Symmetry (commutativity?):(x=y)=(y=x) (1.4) Transitivity:X = Y, Y = Z X = Z if x+y=w+1 and w+1=7 we conclude that x+y=7

  18. Four Laws that Characterize Equality - continued (1.5) Leibniz:X = Y E[z:=X] = E[z:=Y] note: z is defined for a replacement variable, not replacement of an expression. 2•y+1 = 5 x+(2•y+1)•w = ? useX:2•y+1, Y:5,E: x+z•w, z: z 2•y+1 = 5 x+(2•y+1)•w = • x+5•w

  19. Function Evaluation g(z) = 3•z+6 Function g computes the value 3•w+6 for any argument w. The argument is designated in a function application. Instead of using the above conventional notation, the text will usually use: g.z: 3•z+6

  20. Function Evaluation Example g.z: 3•z+6 g.8 = <apply function> 3•8+6 = <arithmetic> 30

  21. Function Application defined as Textual Substitution g.z: E defines function g, then function application g.X for any argument X is defined by g.X= E[z:=X].

  22. Leibniz reformulated (1.8) Leibniz: X = Y g.X = g.Y This property of equality and function application holds for any function g and expressions X andY.

More Related