Code
Diff
  • from math import prod
    
  • 1
    from functools import reduce
    
    2
    from operator import __mul__
    
    3
    def prod(numbers):
    
    4
        return reduce(__mul__, numbers) if numbers else 0
    
    1+
    from math import prod
    
Code
Diff
  • from functools import reduce
    from operator import __mul__
    def prod(numbers):
        return reduce(__mul__, numbers) if numbers else 0
  • 1+
    from functools import reduce
    
    2+
    from operator import __mul__
    
    11
    def prod(numbers):
    
    2
        if numbers == []: return 0
    
    3
        product = 1
    
    4
        for number in numbers:
    
    5
            product *= number
    
    6
        return product
    
    4+
        return reduce(__mul__, numbers) if numbers else 0
    

A polynomial can be written in the form ax^n + bx^n-1 +.. z
Degree will be <=8.

Return an array of the unique real roots.

e.g. a=1, b=3, c=2, d=0 --> [0, -1, -2]

import numpy
import re
def real_solutions(a='x',b='x',c='x',d='x',e='x',f='x',g='x',h='x'):
    arr = [x for x in [a,b,c,d,e,f,g,h] if isinstance(x,int)]
    b = numpy.roots(arr).tolist()
    return list(dict.fromkeys([round(x.real,5) for x in b if abs(x.imag)<1e-5]))