?

Average Accuracy: 59.0% → 99.3%
Time: 16.1s
Precision: binary64
Cost: 26816

?

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

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original59.0%
Target99.4%
Herbie99.3%
\[\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 59.0%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Applied egg-rr73.3%

    \[\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)}} \]
    Proof

    [Start]59.0

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

    *-un-lft-identity [=>]59.0

    \[ \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]

    add-sqr-sqrt [=>]59.0

    \[ \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]

    times-frac [=>]59.0

    \[ \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]

    hypot-def [=>]59.0

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

    hypot-def [=>]73.3

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

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

    [Start]73.3

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

    associate-*l/ [=>]73.5

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

    *-un-lft-identity [<=]73.5

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

    div-sub [=>]73.5

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

    div-sub [=>]73.5

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

    associate-/l* [=>]85.4

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

    associate-/l* [=>]99.2

    \[ \frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\color{blue}{\frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}}{\mathsf{hypot}\left(c, d\right)} \]
  4. Applied egg-rr99.3%

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

    [Start]99.2

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

    clear-num [=>]99.1

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

    associate-/r/ [=>]99.2

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

    clear-num [<=]99.3

    \[ \frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\color{blue}{\frac{d}{\mathsf{hypot}\left(c, d\right)}} \cdot a}{\mathsf{hypot}\left(c, d\right)} \]
  5. Final simplification99.3%

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

Alternatives

Alternative 1
Accuracy98.9%
Cost20352
\[\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right) \]
Alternative 2
Accuracy89.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 2 \cdot 10^{+285}\right):\\ \;\;\;\;\frac{b}{c} - \frac{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\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 3
Accuracy78.8%
Cost14162
\[\begin{array}{l} \mathbf{if}\;c \leq -4.6 \cdot 10^{-10} \lor \neg \left(c \leq -1.45 \cdot 10^{-161} \lor \neg \left(c \leq -1.25 \cdot 10^{-202}\right) \land c \leq 1.55 \cdot 10^{-31}\right):\\ \;\;\;\;\frac{b}{c} - \frac{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \end{array} \]
Alternative 4
Accuracy82.5%
Cost7760
\[\begin{array}{l} t_0 := \frac{b \cdot c - d \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ t_1 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -4.9 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -6 \cdot 10^{-133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{-172}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{+100}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy82.5%
Cost1488
\[\begin{array}{l} t_0 := \frac{b \cdot c - d \cdot a}{c \cdot c + d \cdot d}\\ t_1 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -5.2 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -3.8 \cdot 10^{-130}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{-172}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 5.4 \cdot 10^{+100}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Accuracy69.4%
Cost1106
\[\begin{array}{l} \mathbf{if}\;d \leq -8.6 \cdot 10^{+91} \lor \neg \left(d \leq 1.5 \cdot 10^{-60} \lor \neg \left(d \leq 3.15 \cdot 10^{-19}\right) \land d \leq 2.35 \cdot 10^{+116}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
Alternative 7
Accuracy76.0%
Cost1032
\[\begin{array}{l} \mathbf{if}\;c \leq -5.5 \cdot 10^{-10}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{-29}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} + \frac{d \cdot \frac{a}{c}}{-c}\\ \end{array} \]
Alternative 8
Accuracy76.1%
Cost969
\[\begin{array}{l} \mathbf{if}\;c \leq -1.05 \cdot 10^{-9} \lor \neg \left(c \leq 5.6 \cdot 10^{-33}\right):\\ \;\;\;\;\frac{-1}{c} \cdot \left(d \cdot \frac{a}{c} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \end{array} \]
Alternative 9
Accuracy75.9%
Cost968
\[\begin{array}{l} \mathbf{if}\;c \leq -4 \cdot 10^{-8}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{-29}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(d \cdot \frac{a}{c} - b\right)\\ \end{array} \]
Alternative 10
Accuracy63.7%
Cost520
\[\begin{array}{l} \mathbf{if}\;c \leq -6.6 \cdot 10^{-9}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{-30}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 11
Accuracy14.6%
Cost456
\[\begin{array}{l} \mathbf{if}\;c \leq -27000000000:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 3.5 \cdot 10^{+91}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
Alternative 12
Accuracy42.6%
Cost456
\[\begin{array}{l} \mathbf{if}\;c \leq -4.5 \cdot 10^{-217}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 2.25 \cdot 10^{-67}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 13
Accuracy8.5%
Cost192
\[\frac{a}{c} \]

Error

Reproduce?

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