(1-t)3p1 + 3(1-t)2tp2 + 3(1-t)t2p3 + t3p4
=
t3(-p1 + 3p2 - 3p3 + p4) + t2(3p1 - 6p2 + 3p3) + t(-3p1 + 3p2) + p1
    
    
# peek the binomial coefficients for any N
sympy.expand((t+f)**N)

# convert a specific formula to a polynomial
b = f**3*p1 + 3*f**2*t*p2 + 3*f*t**2*p3 + t**3*p4
collect(expand(b.subs(f, 1-t)), t)
    

If you have found a bug, please report it at the Codeberg project page.

If you have a suggestion or a question, please write Oleksandr Kaleniuk, Ph. D., Senior lecturer at DTE / IATE / ISKPI.