是否有可能编写一个利用“序列生成函数”打印其自己的源代码的程序?
是否可以编写一个利用“序列生成函数”打印自己的源代码的程序?
我所说的序列生成函数只是一个返回特定区间(即可打印的 ascii 字符(32-126))之外的值的函数。现在的要点是,这个生成的序列应该是程序自己的源代码。如您所见,实现返回任意序列的函数确实很简单,但由于返回的序列必须包含函数本身的实现,因此这是一项非常重要的任务。
这就是这样一个程序(及其相应的输出)的样子,
#include <stdio.h>
int fun(int x) {
ins1;
ins2;
ins3;
.
.
.
return y;
}
int main(void) {
int i;
for ( i=0; i<size of the program; i++ ) {
printf("%c", fun(i));
}
return 0;
}
我个人认为这是不可能的,但由于我不太了解底层问题,所以我在这里发布了我的想法。 我真的很期待听到一些意见!
is it possible to write a program which prints its own source code utilizing a "sequence-generating-function"?
what i call a sequence-generating-function is simply a function which returns a value out of a specific interval (i.e. printable ascii-charecters (32-126)). the point now is, that this generated sequence should be the programs own source-code. as you see, implementing a function which returns an arbitrary sequence is really trivial, but since the returned sequence must contain the implementation of the function itself it is a highly non-trivial task.
this is how such a program (and its corresponding output) could look like
#include <stdio.h>
int fun(int x) {
ins1;
ins2;
ins3;
.
.
.
return y;
}
int main(void) {
int i;
for ( i=0; i<size of the program; i++ ) {
printf("%c", fun(i));
}
return 0;
}
i personally think it is not possible, but since i don't know very much about the underlying matter i posted my thoughts here.
i'm really looking forward to hear some opinions!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您知道如何将数组编码为函数(您似乎在说您已经知道如何执行此操作),那么 克莱恩递归定理保证它可以完成。
但对于怀疑 Thomases 的人来说,这里是一个 C 示例。它有一个程序生成函数,仅使用 +、-、* 或 / 或调用使用它们的其他函数。
如果你有图灵完备性并且可以自由地打印你喜欢的东西,奎因总是可能的。
If you know how to encode an array as a function (you seem to be saying you already know how to do this) then the Kleene Recursion theorem guarantees it can be done.
But for doubting Thomases, here's a C example. It has a program generating function that uses only +, -, *, / or calls other functions that use them.
Quines are always possible if you have Turing completeness and freedom to print what you like.
你指的是奎因。维基百科上关于它的文章非常好,有一些有用的链接。 http://en.wikipedia.org/wiki/Quine_%28computing%29
What you're referring to is a QUINE. Wiki's article on it is pretty good, with some helpful links. http://en.wikipedia.org/wiki/Quine_%28computing%29
要沿着切线飞行,请尝试查看 Tupper 的自指公式。
To fly off at a tangent, try looking at Tupper's Self-Referential Formula.