用Tupper自我指涉公式造图

摘要:
塔珀的自指公式是杰夫·塔珀发现的一个自指公式:这个公式的二维图像与公式本身的外观相同。在许多数学和计算机科学课程中,这个公式被用作绘制公式图像的练习。这个公式在他2001年的SIGGRAPH论文中首次被提及。本文主要讨论了他开发的GrafEq公式绘图程序的相关方法。这个公式是一个不等式:其中表示底函数,mod表示模除法。

塔珀自指公式杰夫·塔珀(Jeff Tupper)发现的自指公式:此公式的二维图像与公式本身外观一样。此公式在众多数学计算机科学课程里被用作绘制公式图像的练习作业。

公式最初于他2001年SIGGRAPH的论文中提及。此论文主要讨论他开发的GrafEq公式作图程序的相关方法。

此公式是个不等式

{1over 2} < leftlfloor mathrm{mod}left(leftlfloor {y over 17} ight floor 2^{-17 lfloor x floor - mathrm{mod}(lfloor y floor, 17)},2 ight) ight floor

其中lfloor cdot floor表示地板函数mod表示模除。如果让常数k等于:

4858450636189713423582095962494202044581400587983244549483093085061934704708809928450644769865524364849997247024915119110411605739177407856919754326571855442057210445735883681829823754139634338225199452191651284348332905131193199953502413758765239264874613394906870130562295813219481113685339535565290850023875092856892694555974281546386510730049106723058933586052544096664351265349363643957125565695936815184334857605266940161251266951421550539554519153785457525756590740540157929001765967965480064427829131488548259914721248506352686630476300

  

@鄙视下维基百科给出的k是错的

时,然后将在0 le x le 105k le y le k + 16所示范围中符合以上不等式的点(x,y-k)绘制出来,结果会是这样:

Tupper's self referential formula plot.svg

函数的结果是函数本身图像,其实这个函数可以绘制任何图像,然后发给你心爱的人说,我发现个函数,k=多少多少时,会出现love you之类的,

我果然是理科生....=.=

过程是这样的,

  1. 我们绘制一个单色位图
  2. 然后我们将位图转换为2进制数值
  3. 逆向这个公式得到k
  4. =.= 检查图形美不美

1. 打开个文本

在107*17的范围内绘制图形如下,love YR ,哈哈YR是谁呢,注意长宽空格都算在内的

用Tupper自我指涉公式造图第6张

2.上代码,tupper.txt就是上面的文件

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 import math
 4 
 5 def Base2_to_10(x):
 6     ans = 0
 7     i = 0
 8     while x > 0:
 9         if x%10 == 1: ans += 2**i
10         x /= 10
11         i += 1
12     return ans
13 def input():
14     bar = ""
15     for line in open('tupper.txt'):
16         for i in line[:-1]:
17             bar += i
18     code = ["0" for i in xrange(17*107)]
19     for i in xrange(17*107-1):
20         #print i
21         x = i%107
22         y = 16- i/107
23         if bar[i] == "0":
24             code[17*x+y] = "1"
25     str = "".join(code)    
26     return Base2_to_10(int(str[::-1]))*17
27 str = input()
28 print str

3 得到str

17395801135847186519514533766577166712920244599511619806806360198319443964624090437973069690063751432629635277541067512742591237154706476089604919941282726117482657226986792284460049763364287128660374652834353819138510460422151182573412890443751441495242184763277437223648251193921175808287491778837040326348124920816742193510432149378864985078857052059037920621670314430604882179347284818468370754314529752114472995398250019563369691397252465478396117000433401686853725151310746693542808908025107928533841248521147887035746484088

  

4.用官方的代码跑一下效果

用Tupper自我指涉公式造图第7张用Tupper自我指涉公式造图第8张
 1 """
 2 Copyright (c) 2012, 2013 The PyPedia Project, http://www.pypedia.com
 3 <br>All rights reserved.
 4 
 5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 
 6 
 7 # Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
 8 # Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
 9 
10 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
11 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
12 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
13 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
14 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
16 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
17 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 
21 http://www.opensource.org/licenses/BSD-2-Clause
22 """
23 
24 __pypdoc__ = """
25 Method: Tupper_self_referential_formula
26 Link: http://www.pypedia.com/index.php/Tupper_self_referential_formula
27 Retrieve date: Tue, 11 Mar 2014 03:15:49 +0200
28 
29 
30 
31 Plots the [http://en.wikipedia.org/wiki/Tupper's_self-referential_formula Tupper's_self-referential_formula]:
32 : <math>{1over 2} < leftlfloor mathrm{mod}left(leftlfloor {y over 17} 
ight
floor 2^{-17 lfloor x 
floor - mathrm{mod}(lfloor y
floor, 17)},2
ight)
ight
floor</math>
33 
34 The plot is the very same formula that generates the plot. 
35 
36 [[Category:Validated]]
37 [[Category:Algorithms]]
38 [[Category:Math]]
39 [[Category:Inequalities]]
40 
41 
42 """
43 
44 def Tupper_self_referential_formula(): 
45         k = 17395801135847186519514533766577166712920244599511619806806360198319443964624090437973069690063751432629635277541067512742591237154706476089604919941282726117482657226986792284460049763364287128660374652834353819138510460422151182573412890443751441495242184763277437223648251193921175808287491778837040326348124920816742193510432149378864985078857052059037920621670314430604882179347284818468370754314529752114472995398250019563369691397252465478396117000433401686853725151310746693542808908025107928533841248521147887035746484088
46         #love yiran
47      
48         
49     def f(x,y):
50         d = ((-17 * x) - (y % 17))
51         e = reduce(lambda x,y: x*y, [2 for x in range(-d)]) if d else 1
52         f = ((y / 17) / e)
53         g = f % 2
54         return 0.5 < g
55 
56     for y in range(k+16, k-1, -1):
57         line = ""
58         for x in range(0, 107):
59             if f(x,y):
60                 line += "@"
61             else:
62                 line += " "
63         print line
64 
65 
66 #Method name =Tupper_self_referential_formula()
67 if __name__ == '__main__':
68    # print __pypdoc__
69 
70     returned = Tupper_self_referential_formula()
71     if returned:
72         print str(returned)
Tupper_self_referential_formula.py

5.得到效果

用Tupper自我指涉公式造图第9张

love 依然~~

参考:

http://www.matrix67.com/blog/archives/301

http://www.zhihu.com/question/22506052/answer/21583549

http://zh.wikipedia.org/wiki/%E5%A1%94%E7%8F%80%E8%87%AA%E6%8C%87%E5%85%AC%E5%BC%8F

免责声明:文章转载自《用Tupper自我指涉公式造图》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇基于以太坊发布属于自己的数字货币(代币)完整版maven生命周期(转)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

华硕路由器Asus RT-ACRH17 OpenWrt,刷openwrt教程

系统设置-启用SSH打开并使用putty登录到命令行控制台以查找ART分区,输入cat/proc/mtd查看并使用dd命令,将mtd3和mtd4复制到tmp文件夹cd/tmpddif=/dev/mtd3of=/tmp/Factory。binddif=/dev/mtd4of=/tmp/Factory2.bin使用winScp将tmp下的文件复制到计算机上,并保...

C# 如何提取SaveFileDialog的保存路径

直接使用代码1publicTestOne()2{3InitializeComponent();4SaveFileDialog();//调用打开SaveFileDialog保存对话框5}67#区域保存对话框8privateevoidSaveFileDialog()9{10//startlocalFilePath,fileNameExt,newFileName,...

mini.DataGrid使用说明

√√√ ajaxOptionsObjectajax配置对象。√√√ idFieldString是行数据的唯一字段。设置为“client”之后,客户端将排序√√√√ totalCountNumber记录总数√√√ defaultColumnWidthNumber默认列宽100√√√√ showColumnsBoolean显示标头true√√√√ showPag...

前端chrome浏览器调试总结

以下选项允许您选择要捕获的项目。...

axios 处理超时问题 记录

前言:记录最近两天处理请求超时的逻辑。...

selenium自动化之鼠标操作

,selenium为我们提供了一个处理此类事件的类——ActionChains。ActionChains可以模拟鼠标操作,例如单击、双击、右键单击、拖动等。鼠标移动时演示页面的截图:demo1.使用鼠标移动到WriteonOver按钮的顶部。python脚本如下:读取鼠标移动代码,首先定义浏览器驱动程序,最大化窗口,打开测试页面URL,定位到测试按钮顶部,定...