7
Definitions
- An algebraic number is a number that is a zero of a non-zero polynomial with integer coefficients. For example, the square root of
2
is algebraic, because it is a zero ofx^2 - 2
. - The corresponding polynomial is called the minimal polynomial of the algebraic number, provided that the polynomial is irreducible over
ℚ
.
Task
Given the minimal polynomials of two algebraic numbers, construct a set of numbers that are the sum of two numbers, one from the root of one polynomial, and one from the other. Then, construct a polynomial having those numbers as roots. Output the polynomial. Note that all roots are to be used, including complex roots.
Example
- The two roots of
x^2-2
are√2
and-√2
. - The two roots of
x^2-3
are√3
and-√3
. - Pick one from a polynomial, one from the other, and form 4 sums:
√2+√3
,√2-√3
,-√2+√3
,-√2-√3
. - A polynomial containing those four roots is
x^4-10x^2+1
Input
Two polynomials in any reasonable format (e.g. list of coefficients). They will have degree at least 1
.
Output
One polynomial in the same format, with integer coefficients.
You are not required to output an irreducible polynomial over ℚ
.
Testcases
Format: input, input, output.
x^4 - 10 x^2 + 1
x^2 + 1
x^8 - 16 x^6 + 88 x^4 + 192 x^2 + 144
x^3 - 3 x^2 + 3 x - 4
x^2 - 2
x^6 - 6 x^5 + 9 x^4 - 2 x^3 + 9 x^2 - 60 x + 50
4x^2 - 5
2x - 1
x^2 - x - 1
2x^2 - 5
2x - 1
4x^2 - 4 x - 9
x^2 - 2
x^2 - 2
x^3 - 8 x
The outputs are irreducible over ℚ
here. However, as stated above, you do not need to output irreducible polynomials over ℚ
.
Scoring
This is code-golf. Shortest answer in bytes wins.
Would you mind making your first test case a worked example? The second polynomial only has imaginary roots, and I'm not sure what implications this has wrt your challenge. – Dennis – 2017-05-15T15:13:45.417
@LuisMendo what should the answer be? – Leaky Nun – 2017-05-15T15:16:44.087
@Dennis I already have a worked example... – Leaky Nun – 2017-05-15T15:17:14.263
I'm aware of that. You don't mention complex roots anywhere though. – Dennis – 2017-05-15T15:17:53.963
@LeakyNun I get
4*x^2 - 4*x - 9
, but I'm not sure – Luis Mendo – 2017-05-15T15:18:58.857@LuisMendo culpa mea. – Leaky Nun – 2017-05-15T15:19:45.843
@Dennis I've added the clarification. – Leaky Nun – 2017-05-15T15:20:16.777
@LuisMendo added. – Leaky Nun – 2017-05-15T15:27:59.273
Your spec currently seems to allow cases like
x^2-2
andx^2-8
, or evenx^2-2
andx^2-2
again. Can you (either prohibit these or) add corresponding test cases? – Greg Martin – 2017-05-15T17:39:28.220@GregMartin testcase added. – Leaky Nun – 2017-05-15T17:52:51.390
Your last test's output has only three zeros, is this an oversight or do we have to merge repeated roots of the intermediate result during our simplification ...or is
x^4-8x^2
acceptable too (like Luis' answer is yielding)? – Jonathan Allan – 2017-05-15T19:05:17.343@JonathanAllan I'm assuming that's what the comment about irreducible polynomials is referring to. So, you can do either. – Ørjan Johansen – 2017-05-16T01:33:02.013
Come to think of it, an irreducible polynomial is quite stronger than just merging roots. I don't think it always is the case that you can give an irreducible polynomial, because e.g. one of the root sums could be
0
. Example:x^2+x+1
andx^2-x+1
. – Ørjan Johansen – 2017-05-16T01:38:02.293@ØrjanJohansen I think a definition would help - I have never come across the term before anyway! – Jonathan Allan – 2017-05-16T01:43:11.053
@JonathanAllan It means that the polynomial is not a product of two polynomials of smaller degree > 0, with rational coefficients. A polynomial with duplicated (complex) roots is never irreducible, but irreducible is stronger in general. – Ørjan Johansen – 2017-05-16T01:45:57.500
@ØrjanJohansen Ah thanks. So infinity many outputs are acceptable then (e.g. double all the coefficients). I do think things like this should be defined in specifications otherwise they're open to misinterpretation. – Jonathan Allan – 2017-05-16T01:52:17.253