2017-09-17 36 views
0

我明白,爲了使這個功能起作用,crtHasSolution必須是真實的,我很難證明n可能是一個解決方案任何想法或提示如何編寫或檢查haskell?Haskell中國剩餘定理

我知道N的條件是它必須大於或等於0且小於m,這是所有mod基的乘積。

notes from where conclusion came from

crtHasSolution :: [Integer] -> [Integer] -> Bool 
crtHasSolution as ms = length as > 0 && 
         length ms > 0 && 
         length as == length ms && 
         all (>=0) as && 
         all (>=2) ms && 
         pairwise_coprime ms 

-- Is a given number a solution to a CRT problem? 
-- usage: crtIsSolution n as ms = ans 
-- assures: ans == True, if crtHasSolution as ms == True and n is a solution 
--   ans == False, otherwise 

crtIsSolution :: Integer -> [Integer] -> [Integer] -> Bool 
crtIsSolution n as ms = crtHasSolution as ms && 
         n >= 0 && 
         n < m 
         where m = 

code

+2

你到目前爲止嘗試了什麼?如果你能展示你的嘗試,那麼會更好,然後我們會在你卡住的地方幫助你。 – Sibi

+0

如果你看看我已經嘗試過的代碼圖片,但我不知道如果這是正確的 – ale

+5

供將來參考,只需複製/粘貼你的代碼,而不是截圖它。 – rampion

回答

4

wikipedia

這是很容易檢查的x的值是否是一個解決方案:它足以計算的歐幾里德除法的餘數x[m_i]

如果x `mod` m_i /= a_i任何i,然後x不是解決辦法。

這意味功課,所以不是給你一個班輪,計算這個,我要給你的落實crtIsSolution n as ms一些引導性問題:

  • n如果ms解決方案和as是空的?
  • 如果你可以計算n `mod` m_0 == a_0是否n是否是ms_0as_0的解決方案,你可以計算n是否是m_0:ms_0a_0:as_0的解決方案?