?

Average Error: 26.0 → 0.9
Time: 14.3s
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.0
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.0

    \[\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-rr0.9

    \[\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 simplification0.9

    \[\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
Error9.9
Cost14288
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := t_0 \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;d \leq -2.5 \cdot 10^{+121}:\\ \;\;\;\;t_0 \cdot \mathsf{fma}\left(-1, \frac{c}{\frac{d}{b}}, a\right)\\ \mathbf{elif}\;d \leq -8.5 \cdot 10^{-181}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{-84}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{+63}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 2
Error11.5
Cost13700
\[\begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -8.5 \cdot 10^{+121}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \mathsf{fma}\left(-1, \frac{c}{\frac{d}{b}}, a\right)\\ \mathbf{elif}\;d \leq -3.3 \cdot 10^{-143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 5 \cdot 10^{-69}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \mathbf{elif}\;d \leq 7 \cdot 10^{+60}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 3
Error11.6
Cost7568
\[\begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ t_1 := c \cdot \frac{b}{d}\\ \mathbf{if}\;d \leq -8 \cdot 10^{+120}:\\ \;\;\;\;\frac{a - t_1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-145}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 6.4 \cdot 10^{-63}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \mathbf{elif}\;d \leq 9 \cdot 10^{+63}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1 - a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 4
Error11.7
Cost7172
\[\begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -8.5 \cdot 10^{+119}:\\ \;\;\;\;\frac{a - c \cdot \frac{b}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 6.6 \cdot 10^{-68}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+60}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\ \end{array} \]
Alternative 5
Error11.8
Cost1488
\[\begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ t_1 := \frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -6.5 \cdot 10^{+119}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 8 \cdot 10^{-72}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error15.5
Cost1100
\[\begin{array}{l} t_0 := \frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -4.6 \cdot 10^{+162}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-70}:\\ \;\;\;\;\frac{-a}{d + \frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 4.9 \cdot 10^{+57}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error17.3
Cost969
\[\begin{array}{l} \mathbf{if}\;d \leq -5 \cdot 10^{-70} \lor \neg \left(d \leq 3.1 \cdot 10^{+89}\right):\\ \;\;\;\;\frac{-a}{d + \frac{c}{\frac{d}{c}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{d \cdot a}{c}\right)\\ \end{array} \]
Alternative 8
Error17.6
Cost905
\[\begin{array}{l} \mathbf{if}\;d \leq -5 \cdot 10^{-70} \lor \neg \left(d \leq 3.1 \cdot 10^{+89}\right):\\ \;\;\;\;\frac{-a}{d + \frac{c}{\frac{d}{c}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
Alternative 9
Error19.6
Cost841
\[\begin{array}{l} \mathbf{if}\;d \leq -8.2 \cdot 10^{-13} \lor \neg \left(d \leq 1.75 \cdot 10^{+103}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
Alternative 10
Error23.3
Cost521
\[\begin{array}{l} \mathbf{if}\;d \leq -1.46 \cdot 10^{-12} \lor \neg \left(d \leq 6 \cdot 10^{+90}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 11
Error34.0
Cost456
\[\begin{array}{l} \mathbf{if}\;d \leq -2.2 \cdot 10^{+177}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{elif}\;d \leq 6.1 \cdot 10^{+209}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]
Alternative 12
Error56.9
Cost192
\[\frac{a}{d} \]

Error

Reproduce?

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