Skip to content

Instantly share code, notes, and snippets.

@KatagiriSo
Last active November 2, 2017 08:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KatagiriSo/7a611bd9b9e25b4db13e77d4bbf84d9e to your computer and use it in GitHub Desktop.
Save KatagiriSo/7a611bd9b9e25b4db13e77d4bbf84d9e to your computer and use it in GitHub Desktop.
剰余環のイデアルの計算
import Data.Set
-- リストから同一要素を除く
red ::Ord a => [a] -> [a]
red x = toList(fromList x)
-- ただ型に名前をつけただけ
type Z_pZ = Integer
-- pを法とするZの剰余環の
z_pz :: Integer -> [Z_pZ]
z_pz p = red [mod x p| x<-[0..p-1]]
-- Z_pZのyの生成するイデアル
ideal :: Integer -> Z_pZ -> [Z_pZ]
ideal p y = red [mod (x*y) p |x<-(z_pz p)]
-- 型に名前をつけただけ。
type Ideal = [Z_pZ]
-- Z_pZのイデアルを並べる
ideals :: Integer -> [Ideal]
ideals p = red [ideal p y|y<-[0..p-1]]
-- 素イデアルを並べる
primeIdeals :: Integer -> [Ideal]
primeIdeals p = [ideal| ideal <- ideals p, isPrimeIdeal p ideal]
-- このイデアルが素イデアルか
isPrimeIdeal::Integer -> Ideal -> Bool
isPrimeIdeal p ideal = (ideal /= z_pz p) && (Prelude.foldl (&&) True [elem x ideal || elem y ideal |x<-(z_pz p), y<-(z_pz p), elem (mod (x*y) p) ideal])
-- 上記の途中経過表示用
checkPrimeIdeal p ideal = [(x,elem x ideal,y, elem y ideal,mod (x*y) p, elem (mod (x*y) p) ideal) |x<-(z_pz p), y<-(z_pz p), elem (mod (x*y) p) ideal]
-- 素イデアルでない場合、判例を表示する。
counterExamplePrimeIdeal p ideal = Prelude.filter counterExample (checkPrimeIdeal p ideal)
where counterExample (_, xIsIncludeIdeal, _, yIsIncludeIdeal, _, xyIsIncludeIdeal) = not(xIsIncludeIdeal) && not(yIsIncludeIdeal) && xyIsIncludeIdeal
@KatagiriSo
Copy link
Author

素イデアルの取得をつけてみた。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment