Question 6 Perform the following substitutions:1. {y z/x} (fn x : int ⇒ y x)2. {z x/x} (fn y : int ⇒ y x)3. {z x/x} (fn z : int ⇒ (fn x : int ⇒ y x) x z)
Question
Question 6 Perform the following substitutions:1. {y z/x} (fn x : int ⇒ y x)2. {z x/x} (fn y : int ⇒ y x)3. {z x/x} (fn z : int ⇒ (fn x : int ⇒ y x) x z)
Solution
Substitution is the process of replacing occurrences of a variable in an expression with another expression. The notation {e1/x} e2 means "substitute e1 for x in e2".
{y z/x} (fn x : int ⇒ y x)
In this case, we are substituting y z for x in the expression (fn x : int ⇒ y x). However, x is bound by the function abstraction fn x : int ⇒ y x, so it is not replaced. The result is the same as the original expression:
(fn x : int ⇒ y x)
{z x/x} (fn y : int ⇒ y x)
Here, we are substituting z x for x in the expression (fn y : int ⇒ y x). The x in y x is free, so it is replaced:
(fn y : int ⇒ y (z x))
{z x/x} (fn z : int ⇒ (fn x : int ⇒ y x) x z)
In this case, we are substituting z x for x in the expression (fn z : int ⇒ (fn x : int ⇒ y x) x z). The x in y x and x z are bound by their nearest function abstractions, so they are not replaced. The x in (fn x : int ⇒ y x) x z is free, so it is replaced:
(fn z : int ⇒ (fn x : int ⇒ y x) (z x) z)
Similar Questions
Exercise 4 (Nested substitution) (20 Marks)Question 7 For the language variant featuring while, if-statement and functions (no recursion), showthe following statement.{E3/y} {E2/x} E1 = {({E3/y} E2)/x} {E3/y} E1where x and y are variable with x̸ = y, and E1, E2 and E3 expressions with x̸ ∈ fv(E3). Clearly state yourproof strategy and mark the places where the assumptions are used.
Question 5 Calculate the free variables of the following expressions:1. x + (fn y : int ⇒ z)2. (fn y : int ⇒ (fn y : int ⇒ (fn y : int ⇒ y)))3. while !l0 ≥ y do l0 := xDraw also their abstract syntax trees (up to alpha equivalence)
What is substitution? Convincing somebody else to do your maths homework for you.1Replacing the variable in an equation with the value you calculated for it.2Re-writing the equation so it doesn't contain any variables.3
1. Simplify the following logic expressions using algebraic manipulation:F ABCD BCD ACD
boolean foo(int urn) { return false; } int dip(boolean let) { if(let) { return 1; } else { return -1; }}void setup() { int a = 5; boolean b = foo(a+5); float c = dip(4>3);}Formal parameter for foo is Answer 1 Question 6Actual parameter for foo is Answer 2 Question 6Return type of foo is Answer 3 Question 6Formal parameter for dip is Answer 4 Question 6Actual parameter for dip is Answer 5 Question 6Return type of dip is Answer 6 Question 6
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.