?

Average Error: 26.2 → 0.9
Time: 14.3s
Precision: binary64
Cost: 20224

?

\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
\[\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (/ (- (* c (/ b (hypot c d))) (/ a (/ (hypot c d) d))) (hypot c d)))
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 ((c * (b / hypot(c, d))) - (a / (hypot(c, d) / d))) / hypot(c, d);
}
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 ((c * (b / Math.hypot(c, d))) - (a / (Math.hypot(c, d) / d))) / Math.hypot(c, d);
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
def code(a, b, c, d):
	return ((c * (b / math.hypot(c, d))) - (a / (math.hypot(c, d) / d))) / math.hypot(c, d)
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(Float64(c * Float64(b / hypot(c, d))) - Float64(a / Float64(hypot(c, d) / d))) / hypot(c, d))
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 = ((c * (b / hypot(c, d))) - (a / (hypot(c, d) / d))) / hypot(c, d);
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[(N[(c * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}{\mathsf{hypot}\left(c, d\right)}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original26.2
Target0.4
Herbie0.9
\[\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. Applied egg-rr0.8

    \[\leadsto \color{blue}{\frac{\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot c - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}} \]
  5. Applied egg-rr0.9

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

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

Alternatives

Alternative 1
Error0.8
Cost20224
\[\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - a \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} \]
Alternative 2
Error6.7
Cost15881
\[\begin{array}{l} t_0 := \frac{b \cdot c - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{+296}\right):\\ \;\;\;\;\frac{b - a \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(d \cdot a - b \cdot c\right)}{-\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 3
Error6.7
Cost15817
\[\begin{array}{l} t_0 := b \cdot c - d \cdot a\\ t_1 := \frac{t_0}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 5 \cdot 10^{+296}\right):\\ \;\;\;\;\frac{b - a \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 4
Error5.5
Cost14672
\[\begin{array}{l} t_0 := \frac{d}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{b}{\frac{c \cdot c + d \cdot d}{c}} - t_0 \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -1.02 \cdot 10^{+129}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;c \leq -6.2 \cdot 10^{-182}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.1 \cdot 10^{-165}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{elif}\;c \leq 3.35 \cdot 10^{+69}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot t_0}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 5
Error5.4
Cost14672
\[\begin{array}{l} t_0 := \frac{b}{\frac{c \cdot c + d \cdot d}{c}}\\ t_1 := \frac{d}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -1.02 \cdot 10^{+129}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-136}:\\ \;\;\;\;t_0 + \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}} \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 1.62 \cdot 10^{-165}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{elif}\;c \leq 3.35 \cdot 10^{+69}:\\ \;\;\;\;t_0 - t_1 \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot t_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 6
Error10.3
Cost13900
\[\begin{array}{l} t_0 := c \cdot c + d \cdot d\\ \mathbf{if}\;c \leq -7 \cdot 10^{+125}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq -1.8 \cdot 10^{-114}:\\ \;\;\;\;\frac{b}{\frac{t_0}{c}} - \frac{d \cdot a}{t_0}\\ \mathbf{elif}\;c \leq 8.2 \cdot 10^{-79}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 7
Error10.6
Cost7568
\[\begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \frac{b}{\frac{t_0}{c}} - \frac{d \cdot a}{t_0}\\ \mathbf{if}\;d \leq -3.5 \cdot 10^{+90}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 5 \cdot 10^{-159}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{+66}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 8
Error10.8
Cost2000
\[\begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \frac{b}{\frac{t_0}{c}} - \frac{d \cdot a}{t_0}\\ t_2 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -1.66 \cdot 10^{+96}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d \leq -2.2 \cdot 10^{-80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 8 \cdot 10^{-159}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error12.7
Cost1488
\[\begin{array}{l} t_0 := \frac{b \cdot c - d \cdot a}{c \cdot c + d \cdot d}\\ t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -1.5 \cdot 10^{+99}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -3.4 \cdot 10^{-77}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 4.3 \cdot 10^{-74}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;d \leq 1.06 \cdot 10^{-11}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 10^{+20}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error15.0
Cost1032
\[\begin{array}{l} t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -5.4 \cdot 10^{+87}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{-35}:\\ \;\;\;\;\frac{-d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3 \cdot 10^{+20}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error19.1
Cost841
\[\begin{array}{l} \mathbf{if}\;d \leq -1.85 \cdot 10^{-35} \lor \neg \left(d \leq 1.06 \cdot 10^{+20}\right):\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \end{array} \]
Alternative 12
Error14.7
Cost841
\[\begin{array}{l} \mathbf{if}\;d \leq -1.4 \cdot 10^{-23} \lor \neg \left(d \leq 3.6 \cdot 10^{+19}\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \end{array} \]
Alternative 13
Error24.3
Cost520
\[\begin{array}{l} \mathbf{if}\;c \leq -9 \cdot 10^{-52}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.1 \cdot 10^{+113}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 14
Error37.0
Cost324
\[\begin{array}{l} \mathbf{if}\;d \leq -4 \cdot 10^{+136}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 15
Error56.9
Cost192
\[\frac{a}{d} \]

Error

Reproduce?

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