• Tupper's selfreferential formula


    Link: http://en.wikipedia.org/wiki/Tupper's_self-referential_formula


    code(matlab)

    % use the symbolic toolbox to represent the big integer k 
    k =  sym(['960939379918958884971672962127852754715004339660129306651505519271702802395266424689642842174350' ... 
        '718121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995' ... 
        '165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183' ... 
        '454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874' ... 
        '461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014' ... 
        '655997933798537483143786841806593422227898388722980000748404719']); 
     
    [x,y] = meshgrid(0:1:106, 0:1:16); 
     
    % evaluate the tupper formula 
    tupper = rem(floor(floor((y+k)/17) .* 2.^(-17*x - rem((y+k), 17))), 2); 
     
    % convert from symbolic to Matlab's native double precision 
    tupper = double(tupper); 
     
    % display it! 
    image(fliplr((1-tupper)*255)); 
    colormap gray 
    axis equal 
     
    title('Tupper''s (not-so-)self-referential formula!'); 
    set(gca, 'XTick', [], 'YTick', []); 

    code(java)

    function (x,y) {
      // floor(y/17)  <br/>
      var v = dup(y);
      divInt_(v,17);
      
      //negative exponent of 2, rewritten as a bitwise right shift.    <br/>
      var e = mult(x, k17);
      add_(e, mod(y,k17));
      
      var sh = parseInt(bigInt2str(e,10));
      if (sh>0) {
            rightShift_(v, sh-1);
            //final modulo to recover pixel bit.    <br/>
          mod_(v, k4);
          return greater(v,k1);
      } else {
            //final modulo to recover pixel bit.    <br/>
          mod_(v, k2);
          return greater(v,k0);
      }
    }
    Plot ranges:
    X:[ 0, 105]
    Y:[ 960939379918958884971672962127852754715004339660129306651505519271702802395266424689642842174350718121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014655997933798537483143786841806593422227898388722980000748404719, 960939379918958884971672962127852754715004339660129306651505519271702802395266424689642842174350718121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014655997933798537483143786841806593422227898388722980000748404735]
  • 相关阅读:
    VC++2012编程演练数据结构《25》线索二叉树
    VC++2012编程演练数据结构《26》最大堆二叉树
    VC++2012编程演练数据结构《19》散列文件
    VC++2012编程演练数据结构《21》二叉排序树
    VC++2012编程演练数据结构《23》二叉树排序
    VC++2012编程演练数据结构《22》常规排序算法
    VC++2012编程演练数据结构《27》最小堆二叉树
    VC++2012编程演练数据结构《20》索引文件
    自从来到了上海,开始工作以来就没怎么到博客园
    Graphics 单元中的类
  • 原文地址:https://www.cnblogs.com/emituofo/p/2488153.html
Copyright © 2020-2023  润新知