?

Average Error: 25.9 → 16.1
Time: 8.0s
Precision: binary64
Cost: 1488

?

\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
\[\begin{array}{l} t_0 := -\frac{x.re}{y.im}\\ t_1 := \frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{if}\;y.im \leq -9 \cdot 10^{+87}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.im \leq -1.3 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y.im \leq 3.3 \cdot 10^{-133}:\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{elif}\;y.im \leq 1.2 \cdot 10^{+125}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (- (/ x.re y.im)))
        (t_1
         (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im)))))
   (if (<= y.im -9e+87)
     t_0
     (if (<= y.im -1.3e-82)
       t_1
       (if (<= y.im 3.3e-133)
         (/ x.im y.re)
         (if (<= y.im 1.2e+125) t_1 t_0))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = -(x_46_re / y_46_im);
	double t_1 = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	double tmp;
	if (y_46_im <= -9e+87) {
		tmp = t_0;
	} else if (y_46_im <= -1.3e-82) {
		tmp = t_1;
	} else if (y_46_im <= 3.3e-133) {
		tmp = x_46_im / y_46_re;
	} else if (y_46_im <= 1.2e+125) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    code = ((x_46im * y_46re) - (x_46re * y_46im)) / ((y_46re * y_46re) + (y_46im * y_46im))
end function
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = -(x_46re / y_46im)
    t_1 = ((x_46im * y_46re) - (x_46re * y_46im)) / ((y_46re * y_46re) + (y_46im * y_46im))
    if (y_46im <= (-9d+87)) then
        tmp = t_0
    else if (y_46im <= (-1.3d-82)) then
        tmp = t_1
    else if (y_46im <= 3.3d-133) then
        tmp = x_46im / y_46re
    else if (y_46im <= 1.2d+125) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = -(x_46_re / y_46_im);
	double t_1 = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	double tmp;
	if (y_46_im <= -9e+87) {
		tmp = t_0;
	} else if (y_46_im <= -1.3e-82) {
		tmp = t_1;
	} else if (y_46_im <= 3.3e-133) {
		tmp = x_46_im / y_46_re;
	} else if (y_46_im <= 1.2e+125) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	return ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	t_0 = -(x_46_re / y_46_im)
	t_1 = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
	tmp = 0
	if y_46_im <= -9e+87:
		tmp = t_0
	elif y_46_im <= -1.3e-82:
		tmp = t_1
	elif y_46_im <= 3.3e-133:
		tmp = x_46_im / y_46_re
	elif y_46_im <= 1.2e+125:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(Float64(x_46_im * y_46_re) - Float64(x_46_re * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
end
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = Float64(-Float64(x_46_re / y_46_im))
	t_1 = Float64(Float64(Float64(x_46_im * y_46_re) - Float64(x_46_re * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
	tmp = 0.0
	if (y_46_im <= -9e+87)
		tmp = t_0;
	elseif (y_46_im <= -1.3e-82)
		tmp = t_1;
	elseif (y_46_im <= 3.3e-133)
		tmp = Float64(x_46_im / y_46_re);
	elseif (y_46_im <= 1.2e+125)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = -(x_46_re / y_46_im);
	t_1 = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	tmp = 0.0;
	if (y_46_im <= -9e+87)
		tmp = t_0;
	elseif (y_46_im <= -1.3e-82)
		tmp = t_1;
	elseif (y_46_im <= 3.3e-133)
		tmp = x_46_im / y_46_re;
	elseif (y_46_im <= 1.2e+125)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$im * y$46$re), $MachinePrecision] - N[(x$46$re * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = (-N[(x$46$re / y$46$im), $MachinePrecision])}, Block[{t$95$1 = N[(N[(N[(x$46$im * y$46$re), $MachinePrecision] - N[(x$46$re * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$im, -9e+87], t$95$0, If[LessEqual[y$46$im, -1.3e-82], t$95$1, If[LessEqual[y$46$im, 3.3e-133], N[(x$46$im / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 1.2e+125], t$95$1, t$95$0]]]]]]
\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\begin{array}{l}
t_0 := -\frac{x.re}{y.im}\\
t_1 := \frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\
\mathbf{if}\;y.im \leq -9 \cdot 10^{+87}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y.im \leq -1.3 \cdot 10^{-82}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y.im \leq 3.3 \cdot 10^{-133}:\\
\;\;\;\;\frac{x.im}{y.re}\\

\mathbf{elif}\;y.im \leq 1.2 \cdot 10^{+125}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 3 regimes
  2. if y.im < -9.0000000000000005e87 or 1.2e125 < y.im

    1. Initial program 39.8

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around 0 15.6

      \[\leadsto \color{blue}{-1 \cdot \frac{x.re}{y.im}} \]
    3. Simplified15.6

      \[\leadsto \color{blue}{-\frac{x.re}{y.im}} \]
      Proof

      [Start]15.6

      \[ -1 \cdot \frac{x.re}{y.im} \]

      rational.json-simplify-2 [=>]15.6

      \[ \color{blue}{\frac{x.re}{y.im} \cdot -1} \]

      rational.json-simplify-9 [=>]15.6

      \[ \color{blue}{-\frac{x.re}{y.im}} \]

    if -9.0000000000000005e87 < y.im < -1.3e-82 or 3.30000000000000009e-133 < y.im < 1.2e125

    1. Initial program 15.9

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]

    if -1.3e-82 < y.im < 3.30000000000000009e-133

    1. Initial program 21.3

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around inf 16.9

      \[\leadsto \color{blue}{\frac{x.im}{y.re}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification16.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -9 \cdot 10^{+87}:\\ \;\;\;\;-\frac{x.re}{y.im}\\ \mathbf{elif}\;y.im \leq -1.3 \cdot 10^{-82}:\\ \;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{elif}\;y.im \leq 3.3 \cdot 10^{-133}:\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{elif}\;y.im \leq 1.2 \cdot 10^{+125}:\\ \;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{else}:\\ \;\;\;\;-\frac{x.re}{y.im}\\ \end{array} \]

Alternatives

Alternative 1
Error23.2
Cost1364
\[\begin{array}{l} t_0 := \frac{y.re \cdot x.im}{y.re \cdot y.re + y.im \cdot y.im}\\ t_1 := -\frac{x.re}{y.im}\\ \mathbf{if}\;y.re \leq -1.45 \cdot 10^{+113}:\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{elif}\;y.re \leq -2.5 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y.re \leq -150:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.re \leq 8 \cdot 10^{-45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y.re \leq 1.15 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.re}\\ \end{array} \]
Alternative 2
Error22.6
Cost520
\[\begin{array}{l} t_0 := -\frac{x.re}{y.im}\\ \mathbf{if}\;y.im \leq -9.5 \cdot 10^{-33}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.im \leq 3 \cdot 10^{-5}:\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error37.8
Cost192
\[\frac{x.im}{y.re} \]

Error

Reproduce?

herbie shell --seed 2023077 
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  :precision binary64
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))