Cyclotomic polynomial: Difference between revisions

Change the output to improve readibility.
(Change the output to improve readibility.)
Line 3,056:
 
####################################################################################################
# Superscripts and subscripts.
 
const Superscripts: array['0'..'9', string] = ["⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹"]
const
Superscripts: array['0'..'9', string] = ["⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹"]
Subscripts: array['0'..'9', string] = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"]
 
func superscript(n: Natural): string =
Line 3,068 ⟶ 3,066:
for d in $n:
result.add(Superscripts[d])
 
#---------------------------------------------------------------------------------------------------
 
func subscript(n: Natural): string =
## Return the Unicode string to use to represent an index.
for d in $n:
result.add(Subscripts[d])
 
 
Line 3,360 ⟶ 3,351:
echo "Cyclotomic polynomials for n ⩽ 30:"
for i in 1..30:
echo &"Φ{subscript'(' & $i & ')':<24} = {cycloPoly(i)}"
 
echo ""
Line 3,370 ⟶ 3,361:
let cyclo = cycloPoly(n)
if cyclo.hasCoeffAbs(i):
echo &"Φ{subscript'(' & $n & ')':67} has coefficient with magnitude = {i}"
dec n
break</lang>
Line 3,378 ⟶ 3,369:
 
<pre>Cyclotomic polynomials for n ⩽ 30:
Φ₁Φ(1) = x-1
Φ₂Φ(2) = x+1
Φ₃Φ(3) = x²+x+1
Φ₄Φ(4) = x²+1
Φ₅Φ(5) = x⁴+x³+x²+x+1
Φ₆Φ(6) = x²-x+1
Φ₇Φ(7) = x⁶+x⁵+x⁴+x³+x²+x+1
Φ₈Φ(8) = x⁴+1
Φ₉Φ(9) = x⁶+x³+1
Φ₁₀Φ(10) = x⁴-x³+x²-x+1
Φ₁₁Φ(11) = x¹⁰+x⁹+x⁸+x⁷+x⁶+x⁵+x⁴+x³+x²+x+1
Φ₁₂Φ(12) = x⁴-x²+1
Φ₁₃Φ(13) = x¹²+x¹¹+x¹⁰+x⁹+x⁸+x⁷+x⁶+x⁵+x⁴+x³+x²+x+1
Φ₁₄Φ(14) = x⁶-x⁵+x⁴-x³+x²-x+1
Φ₁₅Φ(15) = x⁸-x⁷+x⁵-x⁴+x³-x+1
Φ₁₆Φ(16) = x⁸+1
Φ₁₇Φ(17) = x¹⁶+x¹⁵+x¹⁴+x¹³+x¹²+x¹¹+x¹⁰+x⁹+x⁸+x⁷+x⁶+x⁵+x⁴+x³+x²+x+1
Φ₁₈Φ(18) = x⁶-x³+1
Φ₁₉Φ(19) = x¹⁸+x¹⁷+x¹⁶+x¹⁵+x¹⁴+x¹³+x¹²+x¹¹+x¹⁰+x⁹+x⁸+x⁷+x⁶+x⁵+x⁴+x³+x²+x+1
Φ₂₀Φ(20) = x⁸-x⁶+x⁴-x²+1
Φ₂₁Φ(21) = x¹²-x¹¹+x⁹-x⁸+x⁶-x⁴+x³-x+1
Φ₂₂Φ(22) = x¹⁰-x⁹+x⁸-x⁷+x⁶-x⁵+x⁴-x³+x²-x+1
Φ₂₃Φ(23) = x²²+x²¹+x²⁰+x¹⁹+x¹⁸+x¹⁷+x¹⁶+x¹⁵+x¹⁴+x¹³+x¹²+x¹¹+x¹⁰+x⁹+x⁸+x⁷+x⁶+x⁵+x⁴+x³+x²+x+1
Φ₂₄Φ(24) = x⁸-x⁴+1
Φ₂₅Φ(25) = x²⁰+x¹⁵+x¹⁰+x⁵+1
Φ₂₆Φ(26) = x¹²-x¹¹+x¹⁰-x⁹+x⁸-x⁷+x⁶-x⁵+x⁴-x³+x²-x+1
Φ₂₇Φ(27) = x¹⁸+x⁹+1
Φ₂₈Φ(28) = x¹²-x¹⁰+x⁸-x⁶+x⁴-x²+1
Φ₂₉Φ(29) = x²⁸+x²⁷+x²⁶+x²⁵+x²⁴+x²³+x²²+x²¹+x²⁰+x¹⁹+x¹⁸+x¹⁷+x¹⁶+x¹⁵+x¹⁴+x¹³+x¹²+x¹¹+x¹⁰+x⁹+x⁸+x⁷+x⁶+x⁵+x⁴+x³+x²+x+1
Φ₃₀Φ(30) = x⁸+x⁷-x⁵-x⁴-x³+x+1
 
Smallest cyclotomic polynomial with n or -n as a coefficient:
Φ₁ Φ(1) has coefficient with magnitude = 1
Φ₁₀₅ Φ(105) has coefficient with magnitude = 2
Φ₃₈₅ Φ(385) has coefficient with magnitude = 3
Φ₁₃₆₅ Φ(1365) has coefficient with magnitude = 4
Φ₁₇₈₅ Φ(1785) has coefficient with magnitude = 5
Φ₂₈₀₅ Φ(2805) has coefficient with magnitude = 6
Φ₃₁₃₅ Φ(3135) has coefficient with magnitude = 7
Φ₆₅₄₅ Φ(6545) has coefficient with magnitude = 8
Φ₆₅₄₅ Φ(6545) has coefficient with magnitude = 9
Φ₁₀₄₆₅ Φ(10465) has coefficient with magnitude = 10</pre>
 
=={{header|Perl}}==
Anonymous user