Formal power series: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: Clean up some unneeded semicolons.)
m (→‎{{header|Perl 6}}: Make coeffs a method in the base class.)
Line 1,101: Line 1,101:


class FPS {
class FPS {
has @.coeffs;
method coeffs { ... }

method differentiate { DerFPS.new(:x(self)) }
method differentiate { DerFPS.new(:x(self)) }
method integrate { IntFPS.new(:x(self)) }
method integrate { IntFPS.new(:x(self)) }
Line 1,116: Line 1,115:
}
}
}
}

class ExplicitFPS is FPS { has @.coeffs }


class SumFPS is FPS {
class SumFPS is FPS {
Line 1,151: Line 1,152:


class IntFPS is FPS {
class IntFPS is FPS {
has FPS $.x is rw;
has FPS $.x;
method coeffs { 0, (0..*).map: { $.x.coeffs[$_] / ($_+1) } }
method coeffs { 0, (0..*).map: { $.x.coeffs[$_] / ($_+1) } }
}
}
Line 1,167: Line 1,168:


# an example for a mixed-type operator:
# an example for a mixed-type operator:
multi infix:<->(Numeric $x, FPS $y) { FPS.new(:coeffs($x, 0 xx *)) - $y }
multi infix:<->(Numeric $x, FPS $y) { ExplicitFPS.new(:coeffs($x, 0 xx *)) - $y }


# define sine and cosine in terms of each other
# define sine and cosine in terms of each other