Chinese remainder theorem: Difference between revisions
Content added Content deleted
imported>Maxima enthusiast No edit summary |
imported>Maxima enthusiast |
||
Line 2,056: | Line 2,056: | ||
=={{header|Maxima}}== |
=={{header|Maxima}}== |
||
<syntaxhighlight lang="maxima"> |
<syntaxhighlight lang="maxima"> |
||
/* Function that checks pairwise coprimality */ |
|||
check_pwc(lst):=block( |
|||
⚫ | |||
sublist(cartesian_product_list(makelist(i,i,length(lst)),makelist(i,i,length(lst))),lambda([x],x[1]#x[2])), |
|||
⚫ | |||
makelist( |
makelist([lst[%%[i][1]],lst[%%[i][2]]],i,length(%%)), |
||
apply( |
makelist(apply('gcd,%%[i]),i,length(%%)), |
||
if length(unique(%%))>1 then false)$ |
|||
/* Chinese remainder function */ |
|||
c_remainder(A,N):=if check_pwc(N)=false then "chinese remainder theorem not applicable" else block( |
|||
⚫ | |||
⚫ | |||
makelist(A[i]*%%[i][1]*cn/N[i],i,1,length(N)), |
|||
apply("+",%%), |
|||
mod(%%,cn)); |
|||
Alis:[2,3,2]$ |
Alis:[2,3,2]$ |
||
Nlis:[3,5,7]$ |
Nlis:[3,5,7]$ |
||
Line 2,069: | Line 2,078: | ||
23 |
23 |
||
</pre> |
</pre> |
||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |