Ask Your Question

Revision history [back]

If your complex numbers are floating-point numbers, then it is likely that they differ by a very small amount due to numerical rounding, so that they are actually different. If you want more help, you should provide details of what you want to achieve, with the code you proudced so far.

It is important to understand that there is no such thing like "complex numbers" in Sage but various representations, with advantages and drawbacks.

If your complex numbers are floating-point numbers, then it is likely that they differ by a very small amount due to numerical rounding, so that they are actually different. If you want more help, you should provide details of what you want to achieve, with the code you proudced so far.different, see for example :

sage: {0.1 + 0.2, 0.3}
{0.300000000000000, 0.300000000000000}

There is nothing wring here since:

sage: (0.1 + 0.2).sign_mantissa_exponent()
(1, 5404319552844596, -54)
sage: (0.3).sign_mantissa_exponent()
(1, 5404319552844595, -54)

It is important to understand that there is no such thing like "complex numbers" in Sage but various representations, with advantages and drawbacks.

If you want more help, you should provide details of what you want to achieve, with the code you proudced so far.

If your complex numbers are floating-point numbers, then it is likely that they differ by a very small amount due to numerical rounding, so that they are actually different, see for example :

sage: {0.1 + 0.2, 0.3}
{0.300000000000000, 0.300000000000000}

There is nothing wring wrong here since:

sage: (0.1 + 0.2).sign_mantissa_exponent()
(1, 5404319552844596, -54)
sage: (0.3).sign_mantissa_exponent()
(1, 5404319552844595, -54)

It is important to understand that there is no such thing like "complex numbers" in Sage but various representations, with advantages and drawbacks.

If you want more help, you should provide details of what you want to achieve, with the code you proudced so far.

If your complex numbers are floating-point numbers, then it is likely that they differ by a very small amount due to numerical rounding, so that they are actually different, see for example :

sage: {0.1 + 0.2, 0.3}
{0.300000000000000, 0.300000000000000}

There is nothing wrong here since:

sage: (0.1 + 0.2).sign_mantissa_exponent()
(1, 5404319552844596, -54)
sage: (0.3).sign_mantissa_exponent()
(1, 5404319552844595, -54)

It is important to understand that there is no such thing like "complex numbers" in Sage but various representations, with advantages and drawbacks.

If you want more help, you should provide details of what you want to achieve, with the code you proudced so far.

EDIT

Given the added details, here is a possible solution : since your polynomials have integer entries, their roots are algebraic, hence you could work with thes field of algebraic numbers. If i try to follow your way, here is a proposal:

sage: x = polygen(ZZ)
sage: P1, P2 = (x^3+1, x^6+2*x^3+1)
sage: r1 = P1.roots(QQbar, multiplicities=False)
sage: r2 = P2.roots(QQbar, multiplicities=False)
sage: r1
[-1,
 0.500000000000000? - 0.866025403784439?*I,
 0.500000000000000? + 0.866025403784439?*I]
sage: r2
[-1,
 0.500000000000000? - 0.866025403784439?*I,
 0.500000000000000? + 0.866025403784439?*I]
sage: s1 = set(r1)
sage: s2 = set(r2)
sage: s1 | s2
{-1,
 0.500000000000000? - 0.866025403784439?*I,
 0.500000000000000? + 0.866025403784439?*I}

If your complex numbers are floating-point numbers, then it is likely that they differ by a very small amount due to numerical rounding, so that they are actually different, see for example :

sage: {0.1 + 0.2, 0.3}
{0.300000000000000, 0.300000000000000}

There is nothing wrong here since:

sage: (0.1 + 0.2).sign_mantissa_exponent()
(1, 5404319552844596, -54)
sage: (0.3).sign_mantissa_exponent()
(1, 5404319552844595, -54)

It is important to understand that there is no such thing like "complex numbers" in Sage but various representations, with advantages and drawbacks.

If you want more help, you should provide details of what you want to achieve, with the code you proudced so far.

EDIT

Given the added details, here is a possible solution : since your polynomials have integer entries, their roots are algebraic, hence you could work with thes field of algebraic numbers. If i try to follow your way, here is a proposal:

sage: x = polygen(ZZ)
sage: P1, P2 = (x^3+1, x^6+2*x^3+1)
sage: r1 = P1.roots(QQbar, multiplicities=False)
sage: r2 = P2.roots(QQbar, multiplicities=False)
sage: r1
[-1,
 0.500000000000000? - 0.866025403784439?*I,
 0.500000000000000? + 0.866025403784439?*I]
sage: r2
[-1,
 0.500000000000000? - 0.866025403784439?*I,
 0.500000000000000? + 0.866025403784439?*I]
sage: s1 = set(r1)
sage: s2 = set(r2)
sage: s1 | s2
{-1,
 0.500000000000000? - 0.866025403784439?*I,
 0.500000000000000? + 0.866025403784439?*I}

You can learn about the different representations of real and complex numbers in Sage in this worksheet