前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >“神奇”的拉马努金矩阵

“神奇”的拉马努金矩阵

作者头像
滚神大人
发布2019-09-10 19:47:54
8680
发布2019-09-10 19:47:54
举报
文章被收录于专栏:趣Python趣Python

我们先来聊聊拉马努金。

斯里尼瓦瑟·拉马努金(泰米尔语:ஸ்ரீனிவாஸ ராமானுஜன் ஐயங்கார்,ISO 15919转写:Srīṉivāsa Rāmāṉujan Aiyaṅkār,又译拉马努詹、罗摩奴詹,1887年12月22日-1920年4月26日)是那个年代最神奇的数学天才之一。尽管没有受过高等教育,他却沉迷数论,尤爱牵涉π、质数等数学常数的求和公式,以及整数分拆。(来自维基百科)

他是20世纪的天才数学家,却英年早逝。

他自学成才却留下了大量没有留下证明的公式,启发了后来的大量研究。

他的伯乐哈代(注:就是那个《哈代数论》的作者)曾在对他的一次采访中说他自己对数学最伟大的贡献是发现了拉马努金,并把拉马努金的天才比作至少和数学巨人欧拉(e^iπ + 1 = 0,了解一下)和雅可比(雅可比行列式,记得吧!)的相当。

“每个正整数都是拉马努金的朋友。”

感兴趣的朋友可以去看一下2015年出的电影《知无涯者》。

我们今天来研究下神奇的拉马努金矩阵。

<此动图由excel,画图板和Python程序生成>

这个矩阵的第一行是拉马努金的生辰。然后这个矩阵的行,列,对角线,动图中所有颜色相同的数之和均等与第一行之和,即139。

我们今天用程序来推导下这个矩阵是否有唯一解?是否神奇?

首先,4维矩阵总共有16个变量,第一行变量已经确定,那么剩余12个变量,恒等式的数量肯定超过了12个,需要对多余的变量做检验即可。

我们发现,在4维矩阵中,只要再假定2个变量,就可以推导出其他所有的变量,我们再检查其他的变量就好了。

代码语言:javascript
复制
# coding=utf-8

'''
拉瓦努金矩阵
ref1 -> https://www.imsc.res.in/~rao/ramanujan/newnow/magicsqr.htm
ref2 -> http://leninkumarkoppoju.blogspot.com/2014/07/ramanujans-magic-square.html

22    12    18    87
88    17    9     25
10    24    89    16
19    86    23    11
'''

(a, b, c, d) = (22, 12, 18, 87)
#(a, b, c, d) = (12, 17, 19, 96)
(e, f, g, h) = (0, 0, 0, 0)
(i, j, k, l) = (0, 0, 0, 0)
(m, n, o, p) = (0, 0, 0, 0)

def check_single_not_suit(checked, all):
    return (checked in all) or (checked <= 0)

def check_SR_magic_sqr(abcd):
    count = 0
    a, b, c, d = (abcd)
    x = 4*max(abcd)
    y = sum(abcd)

    for f in range(1, x):
        for k in range(1, x):
            all = [a, b, c, d, f]
            if check_single_not_suit(k, all):continue
            all.append(k)
            p = y - a - f - k
            if check_single_not_suit(p, all):continue
            all.append(p)
            e = y - a - b - f
            if check_single_not_suit(e, all):continue
            all.append(e)
            m = y - a - d - p
            if check_single_not_suit(m, all):continue
            all.append(m)
            i = y - a - e - m
            if check_single_not_suit(i, all):continue
            all.append(i)
            j = y - e - f - i
            if check_single_not_suit(j, all):continue
            all.append(j)
            n = y - b - f - j
            if check_single_not_suit(n, all):continue
            all.append(n)
            o = y - m - n - p
            if check_single_not_suit(o, all):continue
            all.append(o)
            g = y - c - k - o
            if check_single_not_suit(g, all):continue
            all.append(g)
            h = y - e - f - g
            if check_single_not_suit(h, all):continue
            all.append(h)
            l = y - d - h - p
            if check_single_not_suit(l, all):continue
            all.append(l)
            if ((y == c + d + g + h) and (y == i + j + m + n) and \
                (y == k + l + o + p) and (y == i + j + k + l) and \
                (y == b + c + n + o) and (y == e + i + h + l) and \
                (y == d + g + j + m) and (y == f + g + j + k) and \
                (y == b + e + l + o) and (y == c + h + i + n) and \
                (y == g + h + k + l)):
                print(a, b, c, d)
                print(e, f, g, h)
                print(i, j, k, l)
                print(m, n, o, p)
                print('\n')
                count += 1
    return count

def main():
    count = check_SR_magic_sqr((a, b, c, d))
    print('total count is {}'.format(count))

if __name__ == "__main__":
    main()
    pass

结果表明,并没有唯一解,有很多解。

代码语言:javascript
复制
 ...
(22, 12, 18, 87)
(57, 48, 20, 14)
(31, 3, 68, 37)
(29, 76, 33, 1)


(22, 12, 18, 87)
(56, 49, 23, 11)
(33, 1, 66, 39)
(28, 77, 32, 2)


(22, 12, 18, 87)
(56, 49, 21, 13)
(32, 2, 67, 38)
(29, 76, 33, 1)


total count is 228
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-04-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 趣Python 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档