class Complex {
    final Number real, imag

    static final Complex i = [0,1] as Complex

    Complex(Number r, Number i = 0) { (real, imag) = [r, i] }

    Complex(Map that) { (real, imag) = [that.real ?: 0, that.imag ?: 0] }

    Complex plus (Complex c) { [real + c.real, imag + c.imag] as Complex }
    Complex plus (Number n) { [real + n, imag] as Complex }

    Complex minus (Complex c) { [real - c.real, imag - c.imag] as Complex }
    Complex minus (Number n) { [real - n, imag] as Complex }

    Complex multiply (Complex c) { [real*c.real - imag*c.imag , imag*c.real + real*c.imag] as Complex }
    Complex multiply (Number n) { [real*n , imag*n] as Complex }

    Complex div (Complex c) { this * c.recip() }
    Complex div (Number n) { this * (1/n) }

    Complex negative () { [-real, -imag] as Complex }

    
    Complex bitwiseNegate () { [real, -imag] as Complex }