Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
剰余環のイデアルの計算
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

This comment has been minimized.

Show comment Hide comment
@KatagiriSo

KatagiriSo Jul 8, 2016

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

Owner

KatagiriSo commented Jul 8, 2016

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

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