Text-based interpreter: recursive, fixed-point, fix-expression, letrec-expression

Source: Internet
Author: User
Tags eval expression

One notable feature of this series is that the headlines are getting longer. Suddenly found today is Reading Festival, reading Festival more reading.

= = Below is a meaningless passage.

I am a person who enjoys the pleasure of learning knowledge and enjoys sharing it. I think most of the knowledge can be learned as long as it takes some time. A few years ago, I was hooked on differential geometry. I tell every friend that it's fun to take a little time and energy to learn. They replied, alas, there is no time to know where to go. Later on, I was fascinated by quantum mechanics. I say to every friend that it's worth learning, just take a little time and energy. They answered, alas, too much trouble to learn. Later, I was hooked on the language of programming. I say to every friend that you can master this if you squeeze a little time. They replied, "I don't know what I've been doing. Now, they're all married, and I'm still single.

= = Then, the body begins

No move.

Alas, it is also a mathematical concept, it is not a practical meaning of the section. But as a recursive-related common sense, it has to be mentioned. In other words, as a common sense, I am probably a distortion of values, the importance of ranking upside down. It is said that many research program languages, the study of partial differential equations of the people are like this.

Then, a--er--something $x$ is called the fixed point of the function $f$ if it satisfies the following conditions: \[(f; x) = x \]

What is the relationship between fixed points and recursion? $ ({Y} \ f) $ is not only a recursive function on the $f$ of an auxiliary function, but also a fixed point for a $f$. The proofs are as follows: \begin{eqnarray*} ({Y} \ f) &=& (\lambda X. (\lambda v. (v; v) \ \lambda F. (x \; (f; f)) \; f) \ &=& (\lambda x. (\lambda v. (v; v) \ \lambda p. (x \; (p; p)) \; f) \ &=& (\lambda v. (v; v) \ \lambda P. (f; (p; p)) \ &=& (\lambda P. (f;; (p; p)) \; \lambda P. (f; (p; p)) \ &=& (f \; (\lambda P. (f;; (p; p)) \; \lambda P. (f; (p; p))) \ &=& (f \; (\lambda v. (v; v) \ \lambda p. (f \; (p; p))) \ &=& (f \; (\lambda X. (\lambda v. (v; v) \ \lambda p. (x \; (p; p)) \; f) \ &=& (f \; ({y} \ f) \end{eqnarray*} The recursive function must be a fixed point of a function $f$ because the recursive function can certainly be written as a form of $ ({y} \ f) $ (see the previous mkdouble construction method).

Add Fix expression

It is always too troublesome to construct a recursive function with Y-combination. So we need an expression that can directly construct a recursive function. Let's look at what elements this expression requires. First of all, recursive functions to call themselves, need a point to their own variables, recorded as $x_1$. Second, the recursive function has a parameter, which is recorded as $x_2$. Finally, the function body of the recursive function is recorded as $m$. To construct a recursive function is to look for a fixed point, so this expression is called the fix expression (fixed point). Fix expression Long this sample: \[({fix} \; X_1 \; X_2 \; M) \] The easiest way to add a fix expression is to define it as a macro: \[({fix} \; X_1 \; X_2 \; M) = ({Y} \ \lambda X_1.\lambda x_2.m) \] But doing so reintroduced the Y-combo. This time in another way, not to define macros, but to add the fix expression syntax: \begin{eqnarray*} M, N, L &=& ... \ &|& ({fix} \; X_1 \; X_2 \; M) \end{eqnarray*}

Now examine the evaluation process for the fix expression. The result of the fix expression is a function, and the argument is $x_2$: \[eval ({fix} \; X_1 \; X_2 \; M) = \lambda x_2.? \] The function of the most suitable place at the question mark is $m$, but $m$ contains the free variable $x_1$, before using $m$ to get rid of $x_1$ first. $X _1$ represents the recursive function itself, which is $ ({fix} \; X_1 \; X_2 \; M) $. To remove the free variable $x_1$ in $m$, replace $x_1$ with a recursive function $ ({fix} \; X_1 \; X_2 \; M) $. In summary, the evaluation procedure for the fix expression is: \[eval ({fix} \; X_1 \; X_2 \; M) = \lambda x_2.m[x_1 \leftarrow ({fix} \; X_1 \; X_2 \; M)] \] Code:

Added a new syntax to add the appropriate replacement process (this replacement process is similar to the $\LAMBDA x.m$ replacement process, but a bit troublesome): \begin{eqnarray*} ({fix} \; X_1 \; X_2 \; M) [x_1 \leftarrow N] &=& ({fix} \; X_1 \; X_2 \; M) \ ({fix} \; X_1 \; X_2 \; M) [x_2 \leftarrow N] &=& ({fix} \; X_1 \; X_2 \; M) \ ({fix} \; X_1 \; X_2 \; M) [X_3 \leftarrow N] &=& ({fix} \; X_4 \; X_5 \; M[x_2 \leftarrow x_5][x_1 \leftarrow x_4][x_3 \leftarrow N] \ & where &x_3 \neq x_1, x_3 \neq x_2, \ &&X_4 \ Notin FV (n), X_4 \notin FV (m) \backslash\{x_1\}, \ &&x_5 \notin FV (n), X_5 \notin FV (m) \backslash\{x_2\} \end{eqna rray*} code:

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.