## How to calculate (Cyclotomic Polynomials)

The following program calculates cyclotomic polynomials.
Further informations are here.

``````
10   'poly.ub
20   L%=1000:dim A%(L%),B%(L%),W%(L%)
30   input N%
40   '
50   ' main loop
60   '
70   Ka%=0:A%(0)=1
80   for D%=1 to N%
90     if or{N%@D%>0,moeb(N%\D%)<=0} then 110
100     gosub 210:gosub 250
110   next D%
120   for D%=1 to N%
130     if or{N%@D%>0,moeb(N%\D%)>=0} then 150
140     gosub 210:gosub 360
150   next D%
160   gosub 480:' print
170   print:goto 30
180   '
190   ' set (x^d - 1)
200   '
210   Kb%=D%:B%(Kb%)=1:B%(0)=-1:for I%=1 to Kb%-1:B%(I%)=0:next I%:return
220   '
230   ' w = a * b
240   '
250   Kw%=Ka%+Kb%:for I%=0 to Kw%:W%(I%)=0:next I%
260   for I%=0 to Ka%
270     for J%=0 to Kb%:K%=I%+J%
280       W%(K%)=W%(K%)+A%(I%)*B%(J%)
290     next J%
300   next I%
310   Ka%=Kw%:for I%=0 to Ka%:A%(I%)=W%(I%):next I%:return
320   return
330   '
340   ' w = a / b
350   '
360   Kw%=Ka%-Kb%
370   for I%=Kw% to 0 step -1
380     W%(I%)=A%(I%+Kb%)\B%(Kb%)
390     for J%=I% to I%+Kb%
400       A%(J%)=A%(J%)-W%(I%)*B%(J%-I%)
410     next J%
420   next I%
430   Ka%=Kw%:for I%=0 to Ka%:A%(I%)=W%(I%):next I%:return
440   return
450   '
460   ' pretty print
470   '
480   for I%=Ka% to 0 step -1
490     if A%(I%)<>0 then cancel for:goto 510
500   next I%
510   if I%=0 then print A%(I%);:return
520   if A%(I%)<>1 then print A%(I%);
530   print "x";
540   if I%>1 then print "^";cutspc(str(I%));
550   for J%=I%-1 to 0 step -1
560   ' coefficient
570     if A%(J%)=0 then 660
580     if A%(J%)>1 then print "+";cutspc(str(A%(J%)));
590     if A%(J%)=1 then print "+";
600     if A%(J%)=-1 then print "-";
610     if A%(J%)<-1 then print "-";cutspc(str(abs(A%(J%))));
620     if J%=0 then print cutspc(str(abs(A%(0))));
630   ' term
640     if J%>0 then print "x";
650     if J%>1 then print "^";cutspc(str(J%));
660   next J%:return
``````

E-mail : kc2h-msm@asahi-net.or.jp
Hisanori Mishima