quadratic equations complex numbers Algorithm

Complete the square on a quadratic equation in standard form outcomes in the quadratic formula, which expresses the solutions in terms of a, b, and c. solution to problems that can be expressed in terms of quadratic equations were known as early as 2000 BC.A quadratic equation always has two beginnings, if complex beginnings are included and a double root is counted for two. 

The Bakhshali Manuscript write in India in the 7th century ad contained an algebraic formula for solve quadratic equations, as well as quadratic indeterminate equations (originally of type ax / c = y).Babylonian mathematicians from circa 400 BC and Chinese mathematicians from circa 200 BC used geometric methods of dissection to solve quadratic equations with positive beginnings. He also described the method of complete the square and recognized that the discriminant must be positive, which was proven by his contemporary' Abd al-Hamīd ibn Turk (central Asia, 9th century) who give geometric figures to prove that if the discriminant is negative, a quadratic equation has no solution.
from cmath import sqrt
from typing import Tuple


def quadratic_roots(a: int, b: int, c: int) -> Tuple[complex, complex]:
    """
    Given the numerical coefficients a, b and c,
    calculates the roots for any quadratic equation of the form ax^2 + bx + c

    >>> quadratic_roots(a=1, b=3, c=-4)
    (1.0, -4.0)
    >>> quadratic_roots(5, 6, 1)
    (-0.2, -1.0)
    >>> quadratic_roots(1, -6, 25)
    ((3+4j), (3-4j))
    """

    if a == 0:
        raise ValueError("Coefficient 'a' must not be zero.")
    delta = b * b - 4 * a * c

    root_1 = (-b + sqrt(delta)) / (2 * a)
    root_2 = (-b - sqrt(delta)) / (2 * a)

    return (
        root_1.real if not root_1.imag else root_1,
        root_2.real if not root_2.imag else root_2,
    )


def main():
    solutions = quadratic_roots(a=5, b=6, c=1)
    print("The solutions are: {} and {}".format(*solutions))


if __name__ == "__main__":
    main()

LANGUAGE:

DARK MODE: