/**
 * This function performs arithmetic operations with complex numbers.
 *
 * @param real1 The real part of the first complex number.
 * @param imag1 The imaginary part of the first complex number.
 * @param real2 The real part of the second complex number.
 * @param imag2 The imaginary part of the second complex number.
 * @param operation The arithmetic operation to be performed: "+" for addition, "-" for subtraction, "*" for multiplication, "/" for division.
 * @return The result of the arithmetic operation performed on the complex numbers.
 */
fun complexOperation(real1: Double, imag1: Double, real2: Double, imag2: Double, operation: String): Pair<Double, Double> {

    return when (operation) {
        "+" -> Pair(real1 + real2, imag1 + imag2)
        "-" -> Pair(real1 - real2, imag1 - imag2)
        "*" -> Pair((real1 * real2) - (imag1 * imag2), (real1 * imag2) + (imag1 * real2))
        "/" -> {
            val denominator = (real2 * real2) + (imag2 * imag2)
            val realPart = ((real1 * real2) + (imag1 * imag2)) / denominator
            val imagPart = ((imag1 * real2) - (real1 * imag2)) / denominator
            Pair(realPart, imagPart)
        }
        else -> throw IllegalArgumentException("Invalid operation: $operation")
    }
}
/**
 * This function performs arithmetic operations with complex numbers.
 *
 * @param real1 The real part of the first complex number.
 * @param imag1 The imaginary part of the first complex number.
 * @param real2 The real part of the second complex number.
 * @param imag2 The imaginary part of the second complex number.
 * @param operation The arithmetic operation to be performed: "+" for addition, "-" for subtraction, "*" for multiplication, "/" for division.
 * @return The result of the arithmetic operation performed on the complex numbers.
 */
fun complexOperation(real1: Double, imag1: Double, real2: Double, imag2: Double, operation: String): Pair<Double, Double> {
/**
 * This function performs arithmetic operations with complex numbers.
 *
 * @param real1 The real part of the first complex number.
 * @param imag1 The imaginary part of the first complex number.
 * @param real2 The real part of the second complex number.
 * @param imag2 The imaginary part of the second complex number.
 * @param operation The arithmetic operation to be performed: "+" for addition, "-" for subtraction, "*" for multiplication, "/" for division.
 * @return The result of the arithmetic operation performed on the complex numbers.
 */
fun complexOperation(real1: Double, imag1: Double, real2: Double, imag2: Double, operation: String): Pair<Double, Double> {

    return when (operation) {
        "+" -> Pair(real1 + real2, imag1 + imag2)
        "-" -> Pair(real1 - real2, imag1 - imag2)
        "*" -> Pair((real1 * real2) - (imag1 * imag2), (real1 * imag2) + (imag1 * real2))
        "/" -> {
            val denominator = (real2 * real2) + (imag2 * imag2)
            val realPart = ((real1 * real2) + (imag1 * imag2)) / denominator
            val imagPart = ((imag1 * real2) - (real1 * imag2)) / denominator
            Pair(realPart, imagPart)
        }
        else -> throw IllegalArgumentException("Invalid operation: $operation")
    }
}