Polynomial derivative: Difference between revisions

Content added Content deleted
(→‎{{header|Raku}}: Add a Raku example)
m (→‎{{header|Raku}}: trap an edge condition for exponents > 9 (doesn't matter here))
Line 135: Line 135:
sub pretty (@poly) {
sub pretty (@poly) {
my $p = join '+', (^@poly).reverse.map: { @poly[$_] ~ "x{.&super}" }
my $p = join '+', (^@poly).reverse.map: { @poly[$_] ~ "x{.&super}" }
$p.=subst(/'+-'/, '-', :g).subst(/^'+'/, '').subst(/'x¹'/, 'x').subst(/'x⁰'/, '')\
$p.=subst(/['+'|'-']'0x'<[⁰¹²³⁴⁵⁶⁷⁸⁹]>*/, '', :g).subst(/''<?before <-[⁰¹²³⁴⁵⁶⁷⁸⁹]>>/, 'x')\
.subst(/['+'|'-']'0x'<[⁰¹²³⁴⁵⁶⁷⁸⁹]>*/, '', :g).subst(/(['+'|'-'|^])'1x'/, {"$0x"}, :g) || 0
.subst(/'x⁰'$/, '').subst(/'+-'/, '-', :g).subst(/(['+'|'-'|^])'1x'/, {"$0x"}, :g) || 0
}
}