Cyclotomic polynomial: Difference between revisions

→‎{{header|Sidef}}: replaced with built-in solution
m (syntax highlighting fixup automation)
(→‎{{header|Sidef}}: replaced with built-in solution)
Line 4,371:
 
=={{header|Sidef}}==
Built-in:
Solution based on polynomial interpolation (slow).
<syntaxhighlight lang="ruby">varsay Poly"First =30 require('Math:cyclotomic polynomials:Polynomial')"
Poly.string_config(Hash(fold_sign => true, prefix => "", suffix => ""))
 
func poly_interpolation(v) {
v.len.of {|n| v.len.of {|k| n**k } }.msolve(v)
}
 
say "First 30 cyclotomic polynomials:"
for k in (1..30) {
var a =say ("Φ(#{k+1}).of {= ", cyclotomic(k, _) })
var Φ = poly_interpolation(a)
say ("Φ(#{k}) = ", Poly.new(Φ...))
}
 
say "\nSmallest cyclotomic polynomial with n or -n as a coefficient:"
for n in (1..10) { # very slow
var k = (1..Inf -> first {|k|
poly_interpolation(cyclotomic(k+1).ofcoeffs.any { cyclotomic(k, _) }).first { tail.abs == n }
})
say "Φ(#{k}) has coefficient with magnitude #{n}"
}</syntaxhighlight>
 
Slightly faster solution, using the '''Math::Polynomial::Cyclotomic''' Perl module.
<syntaxhighlight lang="ruby">var Poly = require('Math::Polynomial')
require('Math::Polynomial::Cyclotomic')
 
Poly.string_config(Hash(fold_sign => true, prefix => "", suffix => ""))
 
say "First 30 cyclotomic polynomials:"
for k in (1..30) {
say ("Φ(#{k}) = ", Poly.new.cyclotomic(k))
}
 
say "\nSmallest cyclotomic polynomial with n or -n as a coefficient:"
for n in (1..10) {
var p = Poly.new
var k = (1..Inf -> first {|k|
[p.cyclotomic(k).coeff].first { .abs == n }
})
say "Φ(#{k}) has coefficient with magnitude = #{n}"
}</syntaxhighlight>
 
Line 4,458 ⟶ 4,429:
^C
</pre>
 
=={{header|Visual Basic .NET}}==
{{trans|C++}}
2,747

edits