From 7cbe92334fb4a959eb6a6cf22a406eb2f9d1f0fb Mon Sep 17 00:00:00 2001 From: pingu Date: Tue, 25 Nov 2025 22:05:40 +0100 Subject: [PATCH] Small changes to the values --- 3or4/4.org | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/3or4/4.org b/3or4/4.org index 08ebfa2..87d74ee 100644 --- a/3or4/4.org +++ b/3or4/4.org @@ -27,6 +27,8 @@ Implement $\chi$ substitution as a $\chi$ program. You should construct a $\chi$ \[ subst \ulcorner x \urcorner \ulcorner e \urcorner \ulcorner e' \urcorner \Downarrow \ulcorner e' [ x \leftarrow e] \urcorner \] You do not need to prove formally that this property is satisfied, but please test your code. You can for instance test that this implementation of substitution matches the one from the last assignment. The [[https://chalmers.instructure.com/courses/36941/file_contents/course%20files/chi/Chi.hs][wrapper module]] ([[https://chalmers.instructure.com/courses/36941/file_contents/course%20files/chi/Chi.html][documentation]]) contains some testing procedures, as well as routines for representing natural numbers and $\chi$ abstract syntax as constructor trees. +** Answer +See =Self.hs= * (2p) Implement a $\chi$ self-interpreter. You should construct a $\chi$ expression, let us call it /eval/, that satisfies the following properties: @@ -36,17 +38,19 @@ Implement a $\chi$ self-interpreter. You should construct a $\chi$ expression, l You do not need to prove formally that these properties are satisfied, but please test your code. Make sure that the following examples are implemented correctly: - The program $\text{eval}\ \ulcorner e \urcorner$ should fail to terminate when e is any of the following programs: + $\text{C}()\ \text{C}()$ - + $\text{case}\ \lambda x.x\ \text{of}\ {}$ - + $\text{case}\ \text{C}()\ \text{of}\ { \text{C}(x) \rightarrow \text{C}() }$ - + $\text{case}\ \text{C}(\text{C}())\ \text{of}\ { \text{C}() \rightarrow \text{C}() }$ - + $\text{case}\ \text{C}(\text{C}())\ \text{of}\ { \text{C}() \rightarrow \text{C}(); \text{C}(x) \rightarrow x }$ - + $\text{case} \text{C}()\ \text{of}\ { \text{D}() \rightarrow \text{D}() }$ + + $\text{case}\ \lambda x.x\ \text{of}\ \{\}$ + + $\text{case}\ \text{C}()\ \text{of}\ \{ \text{C}(x) \rightarrow \text{C}() \}$ + + $\text{case}\ \text{C}(\text{C}())\ \text{of}\ \{ \text{C}() \rightarrow \text{C}() \}$ + + $\text{case}\ \text{C}(\text{C}())\ \text{of}\ \{ \text{C}() \rightarrow \text{C}(); \text{C}(x) \rightarrow x \}$ + + $\text{case}\ \text{C}()\ \text{of}\ \{ \text{D}() \rightarrow \text{D}() \}$ + $(\lambda x.\lambda y.x) (\text{rec}\ x = x)$ - The following programs should terminate with specific results: - + The program $\text{eval}\ \ulcorner case C(D(),E()) of { C(x, x) \rightarrow x } \urcorner$ should terminate with the value $\ulcorner E() \urcorner$. - + The program $\text{eval}\ \ulcorner case C(\lambda x.x, Zero()) of { C(f, x) \rightarrow f x } \urcorner$ should terminate with the value $\ulcorner Zero() \urcorner$. - + The program $\text{eval}\ \ulcorner case (\lambda x.x) C() of { C() \rightarrow C() } \urcorner$ should terminate with the value $\ulcorner C() \urcorner$. + + The program $\text{eval}\ \ulcorner \text{case}\ C(D(),E())\ \text{of}\ \{ C(x, x) \rightarrow x \} \urcorner$ should terminate with the value $\ulcorner E() \urcorner$. + + The program $\text{eval}\ \ulcorner \text{case}\ C(\lambda x.x, Zero())\ \text{of}\ \{ C(f, x) \rightarrow f x \} \urcorner$ should terminate with the value $\ulcorner Zero() \urcorner$. + + The program $\text{eval}\ \ulcorner \text{case}\ (\lambda x.x) C()\ \text{of}\ \{ C() \rightarrow C() \} \urcorner$ should terminate with the value $\ulcorner C() \urcorner$. + The program $\text{eval}\ \ulcorner ((\lambda x.x)(\lambda x.x))(\lambda x.x) \urcorner$ should terminate with the value $\ulcorner \lambda x.x \urcorner$. For full credit your implementation must evaluate addition of natural numbers correctly, i.e. $\text{eval} \ulcorner \text{add}\ \ulcorner m \urcorner \ \ulcorner n \urcorner \urcorner$ must terminate with the value $\ulcorner \ulcorner m + n \urcorner \urcorner$, for arbitrary (small) $m, n \in \mathbb{N}$ (where add is an implementation of addition). The wrapper module contains some testing procedures that you can use. +** Answer +See =Self.hs=