Average Error: 26.2 → 1.0
Time: 15.0s
Precision: binary64
Cost: 20352
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
\[\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a\right) \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (* (/ 1.0 (hypot c d)) (- (* c (/ b (hypot c d))) (* (/ d (hypot c d)) a))))
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) {
	return (1.0 / hypot(c, d)) * ((c * (b / hypot(c, d))) - ((d / hypot(c, d)) * a));
}
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) {
	return (1.0 / Math.hypot(c, d)) * ((c * (b / Math.hypot(c, d))) - ((d / Math.hypot(c, d)) * a));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
def code(a, b, c, d):
	return (1.0 / math.hypot(c, d)) * ((c * (b / math.hypot(c, d))) - ((d / math.hypot(c, d)) * a))
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)
	return Float64(Float64(1.0 / hypot(c, d)) * Float64(Float64(c * Float64(b / hypot(c, d))) - Float64(Float64(d / hypot(c, d)) * a)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
function tmp = code(a, b, c, d)
	tmp = (1.0 / hypot(c, d)) * ((c * (b / hypot(c, d))) - ((d / hypot(c, d)) * a));
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_] := N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(c * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original26.2
Target0.4
Herbie1.0
\[\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. Initial program 26.2

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Applied egg-rr16.9

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}} \]
  3. Applied egg-rr1.0

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

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

Alternatives

Alternative 1
Error10.6
Cost14288
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -1.22 \cdot 10^{+181}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{-130}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{-105}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 1.95 \cdot 10^{+135}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \end{array} \]
Alternative 2
Error12.1
Cost14160
\[\begin{array}{l} t_0 := \frac{\frac{c}{d}}{\frac{d}{b}} - \frac{a}{d}\\ \mathbf{if}\;d \leq -6.8 \cdot 10^{+159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -2.05 \cdot 10^{+76}:\\ \;\;\;\;\frac{-a}{d + \frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq -1.18 \cdot 10^{+24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 3.4 \cdot 10^{-115}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{\frac{a}{\frac{c}{d}}}{c}, \frac{b}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - a\right)\\ \end{array} \]
Alternative 3
Error13.8
Cost13904
\[\begin{array}{l} \mathbf{if}\;c \leq -4.7 \cdot 10^{+69}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq -3.2 \cdot 10^{+36}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq -4.8 \cdot 10^{-129}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 1.4 \cdot 10^{-34}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 4
Error12.9
Cost7628
\[\begin{array}{l} t_0 := \frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ t_1 := c \cdot b - d \cdot a\\ \mathbf{if}\;c \leq -7.9 \cdot 10^{+73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -3.4 \cdot 10^{+36}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq -1.35 \cdot 10^{-127}:\\ \;\;\;\;\frac{t_1}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{-36}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 5.8 \cdot 10^{+109}:\\ \;\;\;\;\frac{t_1}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error12.9
Cost1620
\[\begin{array}{l} t_0 := \frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ t_1 := \frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{if}\;c \leq -5.8 \cdot 10^{+69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -3.4 \cdot 10^{+36}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq -1.45 \cdot 10^{-130}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 2.8 \cdot 10^{-35}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 3 \cdot 10^{+109}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error17.9
Cost1497
\[\begin{array}{l} t_0 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -4 \cdot 10^{+159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.55 \cdot 10^{+75}:\\ \;\;\;\;\frac{-a}{d + \frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq -4.4 \cdot 10^{+17}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{elif}\;d \leq 1.55 \cdot 10^{-62} \lor \neg \left(d \leq 3.4 \cdot 10^{+103}\right) \land d \leq 7.8 \cdot 10^{+180}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error17.9
Cost1496
\[\begin{array}{l} t_0 := \frac{\frac{c}{d}}{\frac{d}{b}} - \frac{a}{d}\\ t_1 := \frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{if}\;d \leq -6.2 \cdot 10^{+159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -2.9 \cdot 10^{+74}:\\ \;\;\;\;\frac{-a}{d + \frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{+20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.55 \cdot 10^{-62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 3.4 \cdot 10^{+103}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 7.8 \cdot 10^{+180}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]
Alternative 8
Error17.6
Cost1233
\[\begin{array}{l} t_0 := \frac{b}{c} - d \cdot \frac{a}{c \cdot c}\\ \mathbf{if}\;c \leq -4.6 \cdot 10^{+69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -2.15 \cdot 10^{+36}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq -1.26 \cdot 10^{-43} \lor \neg \left(c \leq 1.22 \cdot 10^{-52}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \end{array} \]
Alternative 9
Error19.9
Cost1232
\[\begin{array}{l} \mathbf{if}\;c \leq -1.25 \cdot 10^{+70}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -1150000:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{elif}\;c \leq -1.12 \cdot 10^{-42}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.1 \cdot 10^{-33}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 10
Error16.2
Cost1232
\[\begin{array}{l} t_0 := \frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{if}\;c \leq -2.66 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -1350000:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{elif}\;c \leq -4.2 \cdot 10^{-45}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c}\\ \mathbf{elif}\;c \leq 3.1 \cdot 10^{-49}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error19.9
Cost1105
\[\begin{array}{l} \mathbf{if}\;c \leq -4.5 \cdot 10^{+69}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -1150000 \lor \neg \left(c \leq -1.35 \cdot 10^{-42}\right) \land c \leq 2.2 \cdot 10^{-36}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 12
Error23.5
Cost785
\[\begin{array}{l} \mathbf{if}\;c \leq -6.4 \cdot 10^{+69}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -2.8 \cdot 10^{+36} \lor \neg \left(c \leq -4.5 \cdot 10^{-50}\right) \land c \leq 9 \cdot 10^{-34}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 13
Error23.7
Cost784
\[\begin{array}{l} \mathbf{if}\;c \leq -7.3 \cdot 10^{+70}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -3.4 \cdot 10^{+36}:\\ \;\;\;\;c \cdot \frac{\frac{b}{d}}{d}\\ \mathbf{elif}\;c \leq -4.2 \cdot 10^{-50}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 9.5 \cdot 10^{-35}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 14
Error37.0
Cost192
\[\frac{b}{c} \]

Error

Reproduce

herbie shell --seed 2022356 
(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))))