Polynomial derivative: Difference between revisions
Content added Content deleted
m (→{{header|Factor}}: show full implementation) |
JsfasdF256 (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
{{draft task}} |
{{draft task}} |
||
Given a polynomial, represented by an ordered list of its coefficients by increasing degree (e.g. [-1, 6, 5] represents 5x<sup>2</sup>+6x-1), calculate the polynomial representing the derivative. For example, the derivative of the aforementioned polynomial is 10x+6, represented by [6, 10]. |
Given a polynomial, represented by an ordered list of its coefficients by increasing degree (e.g. [-1, 6, 5] represents 5x<sup>2</sup>+6x-1), calculate the polynomial representing the derivative. For example, the derivative of the aforementioned polynomial is 10x+6, represented by [6, 10]. Test cases: 5, -3x+4, 5x<sup>2</sup>+6x-1, x<sup>3</sup>-2x<sup>2</sup>+3x-4, -x<sup>4</sup>-x<sup>3</sup>+x+1 |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
Revision as of 02:26, 9 November 2021
Polynomial derivative is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Given a polynomial, represented by an ordered list of its coefficients by increasing degree (e.g. [-1, 6, 5] represents 5x2+6x-1), calculate the polynomial representing the derivative. For example, the derivative of the aforementioned polynomial is 10x+6, represented by [6, 10]. Test cases: 5, -3x+4, 5x2+6x-1, x3-2x2+3x-4, -x4-x3+x+1
Factor
<lang factor>USING: math.polynomials prettyprint ;
{ -1 6 5 } pdiff .</lang>
- Output:
{ 6 10 }
The implementation of pdiff
:
<lang factor>USING: kernel math.vectors sequences ; IN: math.polynomials
- pdiff ( p -- p' ) dup length <iota> v* rest ;</lang>