Cyclotomic polynomial: Difference between revisions
Content added Content deleted
(add parigp) |
(add fermat) |
||
Line 1,348: | Line 1,348: | ||
CP[6545] has coefficient with magnitude = 9 |
CP[6545] has coefficient with magnitude = 9 |
||
CP[10465] has coefficient with magnitude = 10</pre> |
CP[10465] has coefficient with magnitude = 10</pre> |
||
=={{header|Fermat}}== |
|||
This isn't terribly efficient if you have to calculate many cyclotomics- store them in an array rather than using recursion instead if you need to do that- but it showcases Fermat's strength at polynomial expressions. |
|||
<lang fermat> |
|||
&(J=x); {adjoin x as the variable in the polynomials} |
|||
Func Cyclotomic(n) = |
|||
if n=1 then x-1 fi; {first cyclotomic polynomial is x^n-1} |
|||
r:=x^n-1; {caclulate cyclotomic by division} |
|||
for d = 1 to n-1 do |
|||
if Divides(d,n) then |
|||
r:=r\Cyclotomic(d) |
|||
fi; |
|||
od; |
|||
r.; {return the polynomial} |
|||
Func Hascoef(n, k) = |
|||
p:=Cyclotomic(n); |
|||
for d = 0 to Deg(p) do |
|||
if |(Coef(p,d))|=k then Return(1) fi |
|||
od; |
|||
0.; |
|||
for d = 1 to 30 do |
|||
!!(d,' : ',Cyclotomic(d)) |
|||
od; |
|||
for m = 1 to 10 do |
|||
i:=1; |
|||
while not Hascoef(i, m) do |
|||
i:+ |
|||
od; |
|||
!!(m,' : ',i); |
|||
od;</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |