Anonymous user
Chinese remainder theorem: Difference between revisions
→{{header|Maxima}}
imported>Maxima enthusiast No edit summary |
imported>Maxima enthusiast |
||
Line 2,056:
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
/* Function that checks pairwise coprimality */
cn:apply("*",N),▼
sublist(cartesian_product_list(makelist(i,i,length(lst)),makelist(i,i,length(lst))),lambda([x],x[1]#x[2])),
makelist(gcdex(cn/N[i],N[i]),i,1,length(N)),▼
makelist(
makelist(apply(
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(
▲ cn:apply("*",N),
▲ makelist(gcdex(cn/N[i],N[i]),i,1,length(N)),
makelist(A[i]*%%[i][1]*cn/N[i],i,1,length(N)),
apply("+",%%),
mod(%%,cn));
Alis:[2,3,2]$
Nlis:[3,5,7]$
Line 2,069 ⟶ 2,078:
23
</pre>
=={{header|Modula-2}}==
|