(a) Simplify the term syntactically by applying the syntactic conventions and rules. Justify your answer. (2 marks)
- First, we apply the application rule. The term is of the form
where and . - When we apply
with and , we substitute with (from ) and with (from ) in the body of . - The body of
is . Substituting and gives us where and are the values from . - Now we have another application. The term is now
(because we applied the first substitution). - We again apply the application rule. Substitute
with (whatever its value is in the context) in the body of . - The body becomes
. - So the simplified term is
.
- When we apply
(b) Restore the omitted parentheses in the term (but make sure you don’t change the term structure). (2 marks)
- The term should be
. - The innermost lambda expression
needs its own parentheses around the body. - And the whole application of
to the lambda expression and then to also needs appropriate parentheses.
- The innermost lambda expression
(c) Find the normal form of . Justify your answer by showing the reduction sequence. Each step in the reduction sequence should be a single β-reduction step. Underline or otherwise indicate the redex being reduced for each step. (6 marks)
- Let's start with the term
. - The redex is
. We substitute with and with any value (let's say for simplicity, but it doesn't matter in this context as we are just reducing syntactically). - After the first β-reduction, we get
. - Now the new redex is
. We substitute with and with . - After the second β-reduction, we get
. - We can continue this process, but it becomes clear that the term will keep expanding and we won't reach a normal form in a finite number of steps. This is because the function
is being applied to itself repeatedly.
- The redex is
(d) Recall the encoding of natural numbers in lambda calculus (Church Numerals) seen in the lecture:
-
Define exp
whereexp m n
beta-reduces to the Church Numeral representing. Provide a justification of your answer. (6 marks)
- We want to define an
exp
function in lambda calculus. Let's first consider what the operation should do.- If we have
and as Church Numerals, we want to apply the function times to another function, and then apply that result times to the argument .
- If we have
- We define
exp
as follows:-
exp
≡
-
- Justification:
- Let
and (where means applying to times and similarly for ). - First, we consider the inner application
. - Substituting
with and with in the body of , we get .
- Substituting
- Then we apply
to . - Substituting
with and with in the body of , we get . - This means applying the function
(which is applying $f_n^{n}(f)$) times to .
- Substituting
- Finally, we apply the result to
. - So
exp m n f x
will result in applying the functiontimes to and then applying that result to , which is equivalent to the Church Numeral representation of .
- So
- Let
(a) Provide the most general type for the term . Show a type derivation tree to justify your answer. Each node of the tree should correspond to the application of a single typing rule, and be labeled with the typing rule used. Under which contexts is the term type correct? (5 marks)
- Type derivation tree:
- Start with the root node representing the whole term
. - Apply the rule for lambda abstraction. The type of
is of the form where we need to find the types . - For the first application
, we know that has a type and must have a type that is compatible with the argument type of . Let's assume has type and has type . Then has type . So the type of must be . - For the second application
, has type and has type . So must be . - Combining these, the most general type is
. - The term is type correct under the context where the types of variables are assigned as described above (i.e.,
).
- Start with the root node representing the whole term
-
(You don’t need to provide a type derivation, just the term). (4 marks)
- The term
has the given type. - Let's assume
has type , has type , and has type . - Then
has type (by applying the function of type to of type ). - Then
has type (by applying the function of type to of type ). - So
has the type .
- Let's assume
- The term
is not typable because when we try to assign a type to it, we run into a problem. - Let's assume
has type . Then the term is applying the function to itself. But for a function application to be type correct, the type of the function (the first ) must be of the form and the type of the argument (the second ) must be . - In the case of
, we have the same variable being both the function and the argument. If we assume , then for to be type correct, would need to be both and simultaneously, which is not possible for a single type. So the term is not typable.
- Let's assume
- First, we apply the function
to . - The redex is
. We substitute with and with any value (let's say for simplicity). - After the β-reduction, we get
. - Now the new term is
. - The normal form is
. - The type of the original term
is where is the type of , is the type of , and is the result type. If we assume , then the type of is (assuming has a compatible type). So the type of is . - The term
has type . When we apply the first term to the second term, the resulting type is . So the type of the normal form is .
- The redex is
(e) Is typable? Compare this situation with the Subject Reduction that you learned in the lecture. (5 marks)
- The term
is typable. - As we saw in part (d), the type of
is and the type of is . The types are compatible for application.
- As we saw in part (d), the type of
- Regarding Subject Reduction:
- Subject Reduction states that if a term
has a type and reduces to (i.e., ), then also has a type and the type is related to . - In this case, we started with
and reduced it to . The original term had a certain type as we determined, and the reduced term also has a type. - The type of the reduced term is a consequence of the reduction and the typing rules. The fact that the term can be typed before and after reduction is consistent with the idea of Subject Reduction. If the term was not typable before reduction and became typable after reduction (or vice versa), it would violate the principle of Subject Reduction. Here, the typing is consistent throughout the reduction process, which aligns with the concept of Subject Reduction.
- Subject Reduction states that if a term
- Proof:
- We use the rule
notI
(introduction of negation). - Assume
. - We want to show
. - Assume
(for the purpose of notI
). - This leads to a contradiction since we have assumed
and now . - By
notI
, we can conclude. - So
holds by the rule impI
(introduction of implication).
- We use the rule
- Proof:
- Assume
. - Also assume
. - We want to show
. - From
and , by impE
(elimination of implication), we get. - Since we have
and , and assuming (for the purpose of notI
), we getby impE
. - But we already have
, so this is a contradiction. - By
notI
, we can conclude. - So
holds by impI
.
- Assume
- Proof:
- Assume
. - Assume
(for the purpose of notI
). - This leads to a contradiction since we have
and now . - By
notI
, we can conclude. - So
holds by impI
.
- Assume
- Proof:
- Assume
. - We want to show
. - Assume
(for the purpose of notI
). - By De Morgan's law,
is equivalent to . - But we have assumed
, so this is a contradiction. - By
notI
, we can conclude. - So
holds by impI
.
- Assume
- Proof:
- Assume
. - Assume
(for the purpose of notI
). - Since
, then holds vacuously (if the antecedent is false, the implication is true). - But we have assumed
, so this is a contradiction. - By
notI
, we can conclude. - So
holds by impI
.
- Assume
- Proof of
: - Assume
. - Assume
(for the purpose of notI
). - Then
holds, which contradicts . - So by
notI
, we can conclude. - Assume
(for the purpose of notI
). - Then
holds, which contradicts . - So by
notI
, we can conclude. - By
conjI
(introduction of conjunction), we have. - So
holds by the two implications we proved.
- Assume
- Proof:
- Assume
. - Also assume
. - We want to show
. - Assume
(for the purpose of notI
). - From
and , by notE
(elimination of negation), we can conclude. - From
and , by notE
, we can conclude. - By the definition of implication,
is equivalent to . - By
conjunct1
, we have, which contradicts . - By
notI
, we can conclude. - So
holds by impI
.
- Assume
- Proof:
- We want to show
and .
- We want to show
- Proof of
: - Assume
. - Assume
(for the purpose of notI
). - By
exE
(elimination of existential quantifier), there exists a particularsuch that . - But from
, we have , which is a contradiction. - By
notI
, we can conclude, which is equivalent to .
- Assume
- Proof of
: - Assume
. - We want to show
. - Let
be an arbitrary element. - Assume
(for the purpose of notI
). - Then
, which contradicts . - By
notI
, we can conclude. - Since
was arbitrary, we have . - So
.
- Assume
- Proof:
- We know that the order of existential quantifiers does not matter in this case.
- Assume
. - By
exE
, there existand such that . - Then
holds because we have found and such that (with and ). - Conversely, assume
. - By
exE
, there existand such that . - Then
holds. - So
.
- Proof:
- First, we prove
. - Assume
. - Assume
. - We want to show
. - From
, by allE
(elimination of universal quantifier), we can getfor any particular . - Since
holds (because we have for some ), and , by impE
, we can conclude. - So
.
- First, we prove
- Now, we prove
. - Assume
. - We want to show
. - Assume
. - By
exE
, there exists a particularsuch that . - Now assume
(for the purpose of notI
). - Since we have
and , and assuming (for the purpose of notI
), we get a contradiction because. - By
notI
, we can conclude. - So
. - Therefore,
.
- Assume
- Proof:
- First, we prove
. - Assume
. - We want to show
. - Assume
. - By
exE
, there exists a particularsuch that . - Now assume
(for the purpose of notI
). - Assume
. - From
and , by impE
, we get. - By
exE
, there exists asuch that . - But we have assumed
, so this is a contradiction. - By
notI
, we can conclude. - So
.
- First, we prove
- Now, we prove
. - Assume
. - We want to show
. - Assume
. - We want to show
. - Assume
(for the purpose of notI
). - By
notE
, this is equivalent to. - Now assume
for a particular (since ). - From
and , we should have . - But we have
, which is a contradiction. - By
notI
, we can conclude. - So
.
- Assume
- Proof:
- Assume
. - We want to show
. - Let
be an arbitrary element. - We consider two cases:
- Case 1: Assume
. - From
, by allE
, we have. - Since we have assumed
, by impE
, we get. - Then
holds by disjI2
(introduction of disjunction).
- From
- Case 2: Assume
. - Then
holds by disjI1
(introduction of disjunction).
- Then
- Case 1: Assume
- Since
was arbitrary, we have by allI
(introduction of universal quantifier).
- Assume
- Proof:
- Assume
and . - By
exE
, there exists a particularsuch that . - From
, by allE
, we have. - Now assume
(for the purpose of notI
). - Since
, we have . - From
and , by mp
(modus ponens), we get. - Now assume
(for the purpose of notI
). - Since
and , we have by notE
. - But we have
, which is a contradiction. So we can conclude . - Now assume
(for the purpose of notI
). - Since
and , we have . - Then assume
(for the purpose of notI
). - Since
and , we have by notE
. - But we have
, which is a contradiction. So we can conclude . - So we have
. - Since
was obtained from , we have by exI
(introduction of existential quantifier).
- Assume