roots_of_unity_convergents.sf 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/ruby
  2. # Daniel "Trizen" Șuteu
  3. # Date: 11 October 2019
  4. # https://github.com/trizen
  5. # Convergents of roots of unity, listed as sequences of numerators and denominators of real and imaginary parts.
  6. # OEIS:
  7. # https://oeis.org/A011922 -- a(n) = 15*a(n-1) - 15*a(n-2) + a(n-3).
  8. # https://oeis.org/A103974 -- Smaller sides (a) in (a,a,a+1)-integer triangle with integer area.
  9. # See also:
  10. # https://www.youtube.com/watch?v=o5C1OyQbrEs
  11. # https://en.wikipedia.org/wiki/Root_of_unity
  12. # https://en.wikipedia.org/wiki/Eisenstein_integer
  13. func roots_of_unity(n) {
  14. n.of { |j|
  15. exp(2i * Num.pi / n * j)
  16. }
  17. }
  18. for k in (3..7 -> primes) {
  19. say "\n=> Roots of unity of #{k}:"
  20. for r in (roots_of_unity(k)) {
  21. next if (r == 1)
  22. say "x = #{r}"
  23. var C = r.convergents(15)
  24. say ("Nu(Re(x)) = ", C.map{.re.rat_approx.nu})
  25. say ("De(Re(x)) = ", C.map{.re.rat_approx.de})
  26. say ("Nu(Im(x)) = ", C.map{.im.rat_approx.nu})
  27. say ("De(Im(x)) = ", C.map{.im.rat_approx.de})
  28. say ''
  29. }
  30. }
  31. __END__
  32. => Roots of unity of 3:
  33. x = -0.5+0.866025403784438646763723170752936183471402626905i
  34. Nu(Re(x)) = [0, -2, -8, -32, -120, -450, -1680, -6272, -23408, -87362, -326040, -1216800, -4541160, -16947842, -63250208]
  35. De(Re(x)) = [1, 5, 17, 65, 241, 901, 3361, 12545, 46817, 174725, 652081, 2433601, 9082321, 33895685, 126500417]
  36. Nu(Im(x)) = [1, 4, 15, 56, 209, 780, 2911, 10864, 40545, 151316, 564719, 2107560, 7865521, 29354524, 109552575]
  37. De(Im(x)) = [1, 5, 17, 65, 241, 901, 3361, 12545, 46817, 174725, 652081, 2433601, 9082321, 33895685, 126500417]
  38. x = -0.5-0.866025403784438646763723170752936183471402626905i
  39. Nu(Re(x)) = [-1, -2, -1, -33, -1, -451, -1, -6273, -1, -87363, -1, -1216801, -1, -16947843, -1]
  40. De(Re(x)) = [1, 3, 2, 65, 2, 901, 2, 12545, 2, 174725, 2, 2433601, 2, 33895685, 2]
  41. Nu(Im(x)) = [-1, -4, -5, -56, -19, -780, -71, -10864, -265, -151316, -989, -2107560, -3691, -29354524, -13775]
  42. De(Im(x)) = [1, 5, 6, 65, 22, 901, 82, 12545, 306, 174725, 1142, 2433601, 4262, 33895685, 15906]
  43. => Roots of unity of 5:
  44. x = 0.309016994374947424102293417182819058860154589903+0.951056516295153572116439333379382143405698634126i
  45. Nu(Re(x)) = [0, 1, 16, 57, 1948, 9019, 32844, 2028611, 3542021, 474881310, 1895983219, 1280028867514, 2658566913576, 17030620025436, 65463913188168]
  46. De(Re(x)) = [1, 3, 53, 185, 6305, 29186, 106285, 6564722, 11462221, 1536748201, 6135530581, 4142260428437, 8603303255065, 55112244101281, 211845673150057]
  47. Nu(Im(x)) = [1, 9, 50, 176, 5996, 27757, 101083, 6243421, 10901220, 1461534390, 5835236340, 3939523772656, 8182227622393, 52414858880172, 201477207898295]
  48. De(Im(x)) = [1, 10, 53, 185, 6305, 29186, 106285, 6564722, 11462221, 1536748201, 6135530581, 4142260428437, 8603303255065, 55112244101281, 211845673150057]
  49. x = -0.809016994374947424102293417182819058860154589903+0.587785252292473129168705954639072768597652437643i
  50. Nu(Re(x)) = [-1, -4, -664, -1431, -3503, -44940, -2454768, -4246777, -672365808, -2685216455, -11626806116, -66296467189, -221363860747, -13445650202341, -30334630507552]
  51. De(Re(x)) = [1, 5, 821, 1769, 4330, 55549, 3034261, 5249305, 831089845, 3319110073, 14371522721, 81946940114, 273620779645, 16619737651778, 37495665379673]
  52. Nu(Im(x)) = [1, 2, 482, 1040, 509, 32651, 1783494, 3085464, 488502354, 1950923952, 8447369108, 48167202869, 160830258996, 9768836688685, 22039399135065]
  53. De(Im(x)) = [1, 3, 821, 1769, 866, 55549, 3034261, 5249305, 831089845, 3319110073, 14371522721, 81946940114, 273620779645, 16619737651778, 37495665379673]
  54. x = -0.809016994374947424102293417182819058860154589903-0.587785252292473129168705954639072768597652437643i
  55. Nu(Re(x)) = [-1, -4, -664, -1431, -3503, -44940, -2454768, -4246777, -672365808, -2685216455, -11626806116, -66296467189, -221363860747, -13445650202341, -30334630507552]
  56. De(Re(x)) = [1, 5, 821, 1769, 4330, 55549, 3034261, 5249305, 831089845, 3319110073, 14371522721, 81946940114, 273620779645, 16619737651778, 37495665379673]
  57. Nu(Im(x)) = [-1, -2, -482, -1040, -509, -32651, -1783494, -3085464, -488502354, -1950923952, -8447369108, -48167202869, -160830258996, -9768836688685, -22039399135065]
  58. De(Im(x)) = [1, 3, 821, 1769, 866, 55549, 3034261, 5249305, 831089845, 3319110073, 14371522721, 81946940114, 273620779645, 16619737651778, 37495665379673]
  59. x = 0.309016994374947424102293417182819058860154589903-0.951056516295153572116439333379382143405698634126i
  60. Nu(Re(x)) = [0, 1, 16, 57, 1948, 9019, 32844, 2028611, 3542021, 474881310, 1895983219, 1280028867514, 2658566913576, 17030620025436, 65463913188168]
  61. De(Re(x)) = [1, 3, 53, 185, 6305, 29186, 106285, 6564722, 11462221, 1536748201, 6135530581, 4142260428437, 8603303255065, 55112244101281, 211845673150057]
  62. Nu(Im(x)) = [-1, -9, -50, -176, -5996, -27757, -101083, -6243421, -10901220, -1461534390, -5835236340, -3939523772656, -8182227622393, -52414858880172, -201477207898295]
  63. De(Im(x)) = [1, 10, 53, 185, 6305, 29186, 106285, 6564722, 11462221, 1536748201, 6135530581, 4142260428437, 8603303255065, 55112244101281, 211845673150057]
  64. => Roots of unity of 7:
  65. x = 0.623489801858733530525004884004239810632274730896+0.781831482468029808708444526674057750232334518709i
  66. Nu(Re(x)) = [1, 2, 18, 280, 59536, 305561, 1095011, 25814546, 41052240, 1304790951, 3070638383, 36646125384, 94284610728, 16883626299421, 67440220586956]
  67. De(Re(x)) = [1, 3, 29, 449, 95489, 490082, 1756261, 41403317, 65842681, 2092722202, 4924921585, 58775821633, 151220774497, 27079234093466, 108165715599365]
  68. Nu(Im(x)) = [1, 4, 68, 351, 74656, 383161, 1373100, 32370416, 51477881, 1636156101, 3850458744, 45952787760, 118229162305, 21171397735393, 84567361779267]
  69. De(Im(x)) = [1, 5, 87, 449, 95489, 490082, 1756261, 41403317, 65842681, 2092722202, 4924921585, 58775821633, 151220774497, 27079234093466, 108165715599365]
  70. x = -0.222520933956314404288902564496794759466355568765+0.97492791218182360701813168299393121723278580062i
  71. Nu(Re(x)) = [0, -1, -9, -161, -1136, -1131989, -1432630, -18395260, -419985265, -238337977, -6961671983, -6362417021, -145981494537, -425219649569, -2912668218757]
  72. De(Re(x)) = [1, 4, 41, 724, 5105, 5087113, 6438181, 82667549, 1887396649, 1071081146, 31285469905, 28592442553, 656034881489, 1910919759362, 13089412159885]
  73. Nu(Im(x)) = [1, 1, 40, 353, 4977, 4959569, 12553525, 80594901, 1840075675, 2088453811, 30501077856, 55751140645, 639586717329, 931504505671, 12761233268724]
  74. De(Im(x)) = [1, 1, 41, 362, 5105, 5087113, 12876362, 82667549, 1887396649, 2142162292, 31285469905, 57184885106, 656034881489, 955459879681, 13089412159885]
  75. x = -0.900968867902419126236102319507445051165919162132+0.433883739117558120475768332848358754609990727787i
  76. Nu(Re(x)) = [-1, -4, -23, -80, -9, -2296, -8023, -118456, -175780, -5657401, -13301491, -81141409, -311264145, -720322290817, -3571354487034]
  77. De(Re(x)) = [1, 5, 26, 89, 10, 2549, 8905, 131477, 195101, 6279242, 14763541, 90060170, 345477137, 799497426026, 3963904430293]
  78. Nu(Im(x)) = [0, 2, 11, 39, 13, 1106, 3864, 57046, 84651, 2724461, 6405660, 39075643, 149896912, 346888932619, 1719873675720]
  79. De(Im(x)) = [1, 5, 26, 89, 30, 2549, 8905, 131477, 195101, 6279242, 14763541, 90060170, 345477137, 799497426026, 3963904430293]
  80. x = -0.900968867902419126236102319507445051165919162132-0.433883739117558120475768332848358754609990727787i
  81. Nu(Re(x)) = [-1, -4, -23, -80, -9, -2296, -8023, -118456, -175780, -5657401, -13301491, -81141409, -311264145, -720322290817, -3571354487034]
  82. De(Re(x)) = [1, 5, 26, 89, 10, 2549, 8905, 131477, 195101, 6279242, 14763541, 90060170, 345477137, 799497426026, 3963904430293]
  83. Nu(Im(x)) = [0, -2, -11, -39, -13, -1106, -3864, -57046, -84651, -2724461, -6405660, -39075643, -149896912, -346888932619, -1719873675720]
  84. De(Im(x)) = [1, 5, 26, 89, 30, 2549, 8905, 131477, 195101, 6279242, 14763541, 90060170, 345477137, 799497426026, 3963904430293]
  85. x = -0.222520933956314404288902564496794759466355568765-0.97492791218182360701813168299393121723278580062i
  86. Nu(Re(x)) = [0, -1, -9, -161, -1136, -1131989, -1432630, -18395260, -419985265, -238337977, -6961671983, -6362417021, -145981494537, -425219649569, -2912668218757]
  87. De(Re(x)) = [1, 4, 41, 724, 5105, 5087113, 6438181, 82667549, 1887396649, 1071081146, 31285469905, 28592442553, 656034881489, 1910919759362, 13089412159885]
  88. Nu(Im(x)) = [-1, -1, -40, -353, -4977, -4959569, -12553525, -80594901, -1840075675, -2088453811, -30501077856, -55751140645, -639586717329, -931504505671, -12761233268724]
  89. De(Im(x)) = [1, 1, 41, 362, 5105, 5087113, 12876362, 82667549, 1887396649, 2142162292, 31285469905, 57184885106, 656034881489, 955459879681, 13089412159885]
  90. x = 0.623489801858733530525004884004239810632274730896-0.781831482468029808708444526674057750232334518709i
  91. Nu(Re(x)) = [1, 2, 18, 280, 59536, 305561, 1095011, 25814546, 41052240, 1304790951, 3070638383, 36646125384, 94284610728, 16883626299421, 67440220586956]
  92. De(Re(x)) = [1, 3, 29, 449, 95489, 490082, 1756261, 41403317, 65842681, 2092722202, 4924921585, 58775821633, 151220774497, 27079234093466, 108165715599365]
  93. Nu(Im(x)) = [-1, -4, -68, -351, -74656, -383161, -1373100, -32370416, -51477881, -1636156101, -3850458744, -45952787760, -118229162305, -21171397735393, -84567361779267]
  94. De(Im(x)) = [1, 5, 87, 449, 95489, 490082, 1756261, 41403317, 65842681, 2092722202, 4924921585, 58775821633, 151220774497, 27079234093466, 108165715599365]