Last active
November 2, 2017 08:25
-
-
Save KatagiriSo/7a611bd9b9e25b4db13e77d4bbf84d9e to your computer and use it in GitHub Desktop.
剰余環のイデアルの計算
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
素イデアルの取得をつけてみた。