Last active
January 4, 2018 08:27
-
-
Save junpeitsuji/e63df84c95217cbe018500bdd81a61d0 to your computer and use it in GitHub Desktop.
楕円曲線のハッセの定理を確認するRubyプログラム
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hasse's theorem | |
require 'prime' | |
require 'set' | |
# F_p 上の楕円曲線 y^2 = x^3 - x の有理点をカウントする | |
def count_elliptic_points_over_finite_field p | |
points = Set.new | |
# 無限遠点を追加 | |
points << [] | |
# 無限遠点以外の有理点をカウント | |
p.times do |x| | |
p.times do |y| | |
if (y*y - (x*x*x - x)) % p == 0 | |
points << [x, y] | |
end | |
end | |
end | |
return points | |
end | |
# 1000 以下の素数 p について | |
# 有理点の個数をカウントする | |
Prime.each(100) do |prime| | |
n_p = count_elliptic_points_over_finite_field(prime).size | |
puts "#{prime}, #{(prime+1 - n_p).abs}" | |
end | |
=begin | |
puts "<table>" | |
Prime.each(100) do |prime| | |
n_p = count_elliptic_points_over_finite_field(prime).size | |
puts "<tr><td>[tex: #{prime}]</td><td>[tex: #{n_p}]</td><td>[tex: #{prime+1 - n_p}]</td></tr>" | |
end | |
puts "</table>" | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment