Advertisement
qwerty1000000

sqrt2

Apr 3rd, 2024
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
REBOL 2.63 KB | None | 0 0
  1. print "sqrt 2"
  2.  
  3. sqrt: :square-root
  4.  
  5. x: (1 + sqrt 2)
  6.  
  7. {
  8.  
  9. 1 3  7  17 41 99
  10.  
  11. 1 =
  12. 2 = 3 - 1
  13. 3 =
  14. 4 = 3 + 1       >1 , <=4    , f 4 = [ 3 1]      
  15. --------------                
  16. 5 = 7 - 3 + 1 ,  >4 , >=11 , f 5  = [7 -3 1]
  17. 6 = 7 - 1                  , f 6 =  [7 -1]
  18. 7 =
  19. 8 = 7 + 1
  20. 9 = 7 + 3 - 1
  21. 10 = 7 + 3
  22. 11 = 7 + 3 + 1              . f 11 = [7 3 1]
  23. ------------------
  24. 12 = 17 - 7 + 3 - 1   >11 , <=28  , f 12 = [18 -7 1]
  25. 13
  26. 14
  27. 15
  28. 16 = 17 - 1
  29. 17 =
  30. 18 = 17 + 1
  31. 19 = 17 + 3 - 1
  32.  
  33. 28 = 17 + 7 + 3  + 1
  34. --------------------------
  35. 47 =
  36. }
  37.  
  38. {
  39. >> f 50 == [41 7 3 -1]
  40.  
  41. 41 / sqrt 2 = 29
  42. 7 / sqrt 2 = 5
  43. 3 / sqrt 2  = 2
  44. -1 / sqrt 2 = -1
  45.  
  46. 29 + 5 + 2 - 1 = 35 , 50 / sqrt 2 = 35.35533905932737 , (50 * 50) - (2 * ( 35 * 35)) = 50
  47.  
  48. 100 / sqrt 2 = 70.71067811865474
  49. 50 *  sqrt 2 = 70.71067811865476
  50.  
  51. 200 / sqrt 2 = 141.42135623730948
  52. 100 * sqrt 2 = 141.42135623730948
  53. }
  54.  
  55.  
  56. index: [0 1  3  7  17 41 99 ]
  57.  
  58. m: 0
  59.  
  60. limit: clear copy [] ;
  61. foreach n index [ m: m + n  insert tail limit m ]
  62.  
  63.  
  64.  
  65. ;---------------------------------
  66.  
  67. f: func [ n /local m tmp i][
  68.  
  69.   i: 1
  70.  
  71.   tmp: clear copy []
  72.  
  73.    for m -1 + length? limit 1  -1 [
  74.  
  75. if all [ n > limit/:m n <= limit/(m + 1) ][n: n - index/(m + 1 )  insert tail tmp   index/(m + 1) * i  if n < 0 [ i: i * -1 ] n: abs n ]
  76.  
  77. ]
  78. return tmp
  79. ]
  80. ;----------------------
  81.  
  82.  
  83. fn: func [ n /local m tmp i][
  84.  
  85.   i: 1
  86.  
  87.   tmp: clear copy []
  88.  
  89.    for m -1 + length? limit 1  -1 [
  90.  
  91. if all [ n > limit/:m n <= limit/(m + 1) ][n: n - index/(m + 1 )  insert tail tmp   (m ) * i  if n < 0 [ i: i * -1 ] n: abs n ]
  92.  
  93. ]
  94. return tmp
  95. ]
  96.  
  97. ;-----------------------
  98.  
  99. gn: func [ n /local v u m ][
  100.  
  101. v:  fn  n
  102.  
  103. u: clear copy []
  104.  
  105. foreach m v [ insert tail u reduce [reduce [sign? m (abs m) - 1 ]]]
  106.  
  107. return u
  108.  
  109. ]
  110.  
  111. ;------------------
  112.  
  113.  
  114. g: func [ v /local a b y n ][ a: 0 b: 0 n: 0 y: x  foreach  m v [ n: n + 1 if all [ n = length? v 1 = abs m ][y: 1]    a: a +  ((sign? m) * power y abs m) b: b +  ((sign? m) / power y  abs m ) ] return a * b ]
  115.  
  116. ;---------------------------------------------------------
  117.  
  118. h: func [ v /local a b y n ][ a: 0 b: 0 n: 0 y: x  foreach  m v [   a: a +  ((sign? m/1) * power y abs m/2)
  119.  
  120.  b: b + either 1 = mod m/2 2 [((-1 * sign? m/1) / power y  abs m/2 )][ ((sign? m/1) / power y  abs m/2 ) ]
  121.  
  122. ] return a * b ]
  123.  
  124.  
  125.  ;---------------------------------------------------------------------
  126.  
  127. ;==============================
  128. {
  129. (1+x^6+x^7)*(1+1/x^6-1/x^7)  =x^7+x^6+x+1 = 679                                              ;(x^2 - 2 x - 1) (x^12 + 3 x^11 + 7 x^10 + 17 x^9 + 41 x^8 + 99 x^7 + 240 x^6 - 99 x^5 + 41 x^4 - 17 x^3 + 7 x^2 - 3 x + 1)  (3 * 2 + 1)  
  130. }
  131.  
  132. halt
Tags: sqrt2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement