Thạch, 15 byte
Æṛ‘Ė’Uj€“x^”j”+
Điều này sử dụng Æṛđể xây dựng các hệ số của một đa thức monic với các gốc đã cho. Hãy thử trực tuyến!
Làm thế nào nó hoạt động
Æṛ‘Ė’Uj€“x^”j”+ Main link. Argument: A (list of roots)
Æṛ Yield the coefficients of a monic polynomial with roots A.
‘ Increment each root by 1.
Ė Enumerate the roots, yielding
[[1, coeff. of x^0 + 1], ... [n + 1, coeff. of x^n + 1]].
’ Decrement all involved integers, yielding
[[0, coeff. of x^0], ... [n, coeff. of x^n]].
U Upend to yield [[coeff. of x^0, 0], ... [coeff. of x^n, n]].
j€“x^” Join each pair, separating by 'x^'.
j”+ Join the pairs, separating by '+'.
Phiên bản thay thế, 24 byte
1WW;ð0;_×µ/‘Ė’Uj€“x^”j”+
Điều này sử dụng không có tích hợp liên quan đến đa thức. Hãy thử trực tuyến!
Làm thế nào nó hoạt động
1WW;ð0;_×µ/‘Ė’Uj€“x^”j”+ Main link. Argument: A (list of roots)
1WW Yield [[1]].
; Concatenate with A.
ð µ/ Reduce [[1]] + A by the following, dyadic chain:
0; Prepend a zero to the left argument (initially [1]).
This multiplies the left argument by "x".
× Take the product of both, unaltered arguments.
This multiplies the left argument by "r", where r is
the root specified in the right argument.
_ Subtract.
This computes the left argument multiplied by "x-r".
‘Ė’Uj€“x^”j”+ As before.
numpy.polynào?