2017-09-17 120 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的解决方案?