Python oneliner to differentiate polynomial list

From wikiluntti
Revision as of 12:14, 5 August 2021 by Mol (talk | contribs) (→‎Theory)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Introduction

Oneliners are powerful and often beautiful solutions to programming challenges (see Acklamization).

Theory

Let the polynomial be described in ascending order, thus is written as a list [2, 3, 5, 1]. The derivative equals a list [3, 10, 3]

poly = [2, 3, 5, 1]  # Degrees starting from zero
print( [(i+1)*j for i,j in enumerate( poly[1:] )] )