Skip to content

Instantly share code, notes, and snippets.

@junpeitsuji junpeitsuji/hasse.rb
Last active Jan 4, 2018

Embed
What would you like to do?
楕円曲線のハッセの定理を確認するRubyプログラム
# 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
You can’t perform that action at this time.