Average Error: 26.9 → 12.1
Time: 6.3s
Precision: binary64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := \frac{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{if}\;c \leq -2.9316931711396905 \cdot 10^{+167}:\\ \;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \leq -1.8647556737340625 \cdot 10^{-161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 7.568560534795 \cdot 10^{-251}:\\ \;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 7.649344911276026 \cdot 10^{+60}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{\mathsf{hypot}\left(d, c\right)}\\ \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (/ (- (* c b) (* d a)) (hypot d c)) (hypot d c))))
   (if (<= c -2.9316931711396905e+167)
     (/ (- b) (hypot d c))
     (if (<= c -1.8647556737340625e-161)
       t_0
       (if (<= c 7.568560534795e-251)
         (- (/ (* c b) (* d d)) (/ a d))
         (if (<= c 7.649344911276026e+60)
           t_0
           (/ (- b (/ (* d a) c)) (hypot d c))))))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
	double t_0 = (((c * b) - (d * a)) / hypot(d, c)) / hypot(d, c);
	double tmp;
	if (c <= -2.9316931711396905e+167) {
		tmp = -b / hypot(d, c);
	} else if (c <= -1.8647556737340625e-161) {
		tmp = t_0;
	} else if (c <= 7.568560534795e-251) {
		tmp = ((c * b) / (d * d)) - (a / d);
	} else if (c <= 7.649344911276026e+60) {
		tmp = t_0;
	} else {
		tmp = (b - ((d * a) / c)) / hypot(d, c);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
public static double code(double a, double b, double c, double d) {
	double t_0 = (((c * b) - (d * a)) / Math.hypot(d, c)) / Math.hypot(d, c);
	double tmp;
	if (c <= -2.9316931711396905e+167) {
		tmp = -b / Math.hypot(d, c);
	} else if (c <= -1.8647556737340625e-161) {
		tmp = t_0;
	} else if (c <= 7.568560534795e-251) {
		tmp = ((c * b) / (d * d)) - (a / d);
	} else if (c <= 7.649344911276026e+60) {
		tmp = t_0;
	} else {
		tmp = (b - ((d * a) / c)) / Math.hypot(d, c);
	}
	return tmp;
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
def code(a, b, c, d):
	t_0 = (((c * b) - (d * a)) / math.hypot(d, c)) / math.hypot(d, c)
	tmp = 0
	if c <= -2.9316931711396905e+167:
		tmp = -b / math.hypot(d, c)
	elif c <= -1.8647556737340625e-161:
		tmp = t_0
	elif c <= 7.568560534795e-251:
		tmp = ((c * b) / (d * d)) - (a / d)
	elif c <= 7.649344911276026e+60:
		tmp = t_0
	else:
		tmp = (b - ((d * a) / c)) / math.hypot(d, c)
	return tmp
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(Float64(c * b) - Float64(d * a)) / hypot(d, c)) / hypot(d, c))
	tmp = 0.0
	if (c <= -2.9316931711396905e+167)
		tmp = Float64(Float64(-b) / hypot(d, c));
	elseif (c <= -1.8647556737340625e-161)
		tmp = t_0;
	elseif (c <= 7.568560534795e-251)
		tmp = Float64(Float64(Float64(c * b) / Float64(d * d)) - Float64(a / d));
	elseif (c <= 7.649344911276026e+60)
		tmp = t_0;
	else
		tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / hypot(d, c));
	end
	return tmp
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
function tmp_2 = code(a, b, c, d)
	t_0 = (((c * b) - (d * a)) / hypot(d, c)) / hypot(d, c);
	tmp = 0.0;
	if (c <= -2.9316931711396905e+167)
		tmp = -b / hypot(d, c);
	elseif (c <= -1.8647556737340625e-161)
		tmp = t_0;
	elseif (c <= 7.568560534795e-251)
		tmp = ((c * b) / (d * d)) - (a / d);
	elseif (c <= 7.649344911276026e+60)
		tmp = t_0;
	else
		tmp = (b - ((d * a) / c)) / hypot(d, c);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.9316931711396905e+167], N[((-b) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.8647556737340625e-161], t$95$0, If[LessEqual[c, 7.568560534795e-251], N[(N[(N[(c * b), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.649344911276026e+60], t$95$0, N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;c \leq -2.9316931711396905 \cdot 10^{+167}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\

\mathbf{elif}\;c \leq -1.8647556737340625 \cdot 10^{-161}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 7.568560534795 \cdot 10^{-251}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\

\mathbf{elif}\;c \leq 7.649344911276026 \cdot 10^{+60}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{\mathsf{hypot}\left(d, c\right)}\\


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original26.9
Target0.5
Herbie12.1
\[\begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if c < -2.93169317113969053e167

    1. Initial program 43.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified43.6

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Applied add-sqr-sqrt_binary6443.6

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
    4. Applied *-un-lft-identity_binary6443.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    5. Applied times-frac_binary6443.6

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
    6. Simplified43.6

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    7. Simplified30.4

      \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}} \]
    8. Applied associate-*l/_binary6430.4

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}} \]
    9. Simplified30.4

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}}{\mathsf{hypot}\left(d, c\right)} \]
    10. Taylor expanded in c around -inf 12.4

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\mathsf{hypot}\left(d, c\right)} \]
    11. Simplified12.4

      \[\leadsto \frac{\color{blue}{-b}}{\mathsf{hypot}\left(d, c\right)} \]

    if -2.93169317113969053e167 < c < -1.86475567373406252e-161 or 7.5685605347949994e-251 < c < 7.64934491127602648e60

    1. Initial program 19.2

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified19.2

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Applied add-sqr-sqrt_binary6419.2

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
    4. Applied *-un-lft-identity_binary6419.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    5. Applied times-frac_binary6419.2

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
    6. Simplified19.2

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    7. Simplified12.4

      \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}} \]
    8. Applied associate-*l/_binary6412.2

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}} \]
    9. Simplified12.2

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}}{\mathsf{hypot}\left(d, c\right)} \]

    if -1.86475567373406252e-161 < c < 7.5685605347949994e-251

    1. Initial program 25.4

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified25.4

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Applied add-sqr-sqrt_binary6425.4

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
    4. Applied *-un-lft-identity_binary6425.4

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    5. Applied times-frac_binary6425.4

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
    6. Simplified25.4

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    7. Simplified14.9

      \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}} \]
    8. Applied add-sqr-sqrt_binary6415.1

      \[\leadsto \frac{1}{\color{blue}{\sqrt{\mathsf{hypot}\left(d, c\right)} \cdot \sqrt{\mathsf{hypot}\left(d, c\right)}}} \cdot \frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)} \]
    9. Applied *-un-lft-identity_binary6415.1

      \[\leadsto \frac{\color{blue}{1 \cdot 1}}{\sqrt{\mathsf{hypot}\left(d, c\right)} \cdot \sqrt{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)} \]
    10. Applied times-frac_binary6415.2

      \[\leadsto \color{blue}{\left(\frac{1}{\sqrt{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{1}{\sqrt{\mathsf{hypot}\left(d, c\right)}}\right)} \cdot \frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)} \]
    11. Applied associate-*l*_binary6415.2

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{hypot}\left(d, c\right)}} \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}\right)} \]
    12. Simplified15.1

      \[\leadsto \frac{1}{\sqrt{\mathsf{hypot}\left(d, c\right)}} \cdot \color{blue}{\frac{\frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\sqrt{\mathsf{hypot}\left(d, c\right)}}} \]
    13. Taylor expanded in d around inf 9.0

      \[\leadsto \color{blue}{\frac{c \cdot b}{{d}^{2}} - \frac{a}{d}} \]
    14. Simplified9.0

      \[\leadsto \color{blue}{\frac{b \cdot c}{d \cdot d} - \frac{a}{d}} \]

    if 7.64934491127602648e60 < c

    1. Initial program 37.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified37.6

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Applied add-sqr-sqrt_binary6437.6

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
    4. Applied *-un-lft-identity_binary6437.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    5. Applied times-frac_binary6437.7

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
    6. Simplified37.7

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(d, c\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    7. Simplified25.8

      \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}} \]
    8. Applied associate-*l/_binary6425.7

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}} \]
    9. Simplified25.7

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}}{\mathsf{hypot}\left(d, c\right)} \]
    10. Taylor expanded in c around inf 13.9

      \[\leadsto \frac{\color{blue}{b - \frac{a \cdot d}{c}}}{\mathsf{hypot}\left(d, c\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification12.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.9316931711396905 \cdot 10^{+167}:\\ \;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \leq -1.8647556737340625 \cdot 10^{-161}:\\ \;\;\;\;\frac{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \leq 7.568560534795 \cdot 10^{-251}:\\ \;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 7.649344911276026 \cdot 10^{+60}:\\ \;\;\;\;\frac{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{\mathsf{hypot}\left(d, c\right)}\\ \end{array} \]

Reproduce

herbie shell --seed 2022129 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))

  (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))