'Construct a piecewise polynomial in the power basis
from a polynomial in Bernstein basis.
Parameters
bp : BPoly
A Bernstein basis polynomial, as created by BPoly
extrapolate : bool or \'periodic\', optional
If bool, determines whether to extrapolate to out-of-bounds points
based on first and last intervals, or to return NaNs.
If \'periodic\', periodic extrapolation is used. Default is True.'

@classmethod
def from_bernstein_basis(cls, bp, extrapolate=None):

    dx = np.diff(bp.x)
    k = (bp.c.shape[0] - 1)
    rest = ((None,) * (bp.c.ndim - 2))
    c = np.zeros_like(bp.c)
    for a in range((k + 1)):
        factor = ((((-1) ** a) * comb(k, a)) * bp.c[a])
        for s in range(a, (k + 1)):
            val = (comb((k - a), (s - a)) * ((-1) ** s))
            c[(k - s)] += ((factor * val) / (dx[((slice(None),) + rest)] ** s))
    if (extrapolate is None):
        extrapolate = bp.extrapolate
    return cls.construct_fast(c, bp.x, extrapolate, bp.axis)
