How to resolve the algorithm Cyclotomic polynomial step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cyclotomic polynomial step by step in the Raku programming language

Table of Contents

Problem Statement

The nth Cyclotomic polynomial, for any positive integer n, is the unique irreducible polynomial of largest degree with integer coefficients that is a divisor of x^n − 1, and is not a divisor of x^k − 1 for any k < n.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Cyclotomic polynomial step by step in the Raku programming language

Source code in the raku programming language

use Math::Polynomial::Cyclotomic:from ;

say 'First 30 cyclotomic polynomials:';
my $iterator = cyclo_poly_iterate(1);
say "Φ($_) = " ~ super $iterator().Str for 1..30;

say "\nSmallest cyclotomic polynomial with |n| as a coefficient:";
say "Φ(1) has a coefficient magnitude: 1";

my $index = 0;
for 2..9 -> $coefficient {
    loop {
        $index += 5;
        my \Φ = cyclo_poly($index);
        next unless Φ ~~ / $coefficient\* /;
        say "Φ($index) has a coefficient magnitude: $coefficient";
        $index -= 5;
        last;
    }
}

sub super ($str) {
    $str.subst( / '^' (\d+) /, { $0.trans([<0123456789>.comb] => [<⁰¹²³⁴⁵⁶⁷⁸⁹>.comb]) }, :g)
}


  

You may also check:How to resolve the algorithm Playfair cipher step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Sequence of primorial primes step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the Astro programming language
You may also check:How to resolve the algorithm Loops/For step by step in the UnixPipes programming language
You may also check:How to resolve the algorithm Balanced brackets step by step in the JavaScript programming language