?

Average Accuracy: 58.7% → 99.3%
Time: 16.9s
Precision: binary64
Cost: 20288

?

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

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original58.7%
Target99.3%
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 58.7%

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

    \[\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]58.7

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

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

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

    add-sqr-sqrt [=>]58.7

    \[ \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 [=>]58.7

    \[ \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 [=>]58.7

    \[ \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.6

    \[ \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-rr98.3%

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

    [Start]73.6

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

    div-sub [=>]73.6

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

    associate-/l* [=>]85.4

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

    associate-/r/ [=>]84.7

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

    *-commutative [=>]84.7

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

    associate-/l* [=>]97.4

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

    associate-/r/ [=>]98.3

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

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

    [Start]98.3

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

    *-commutative [=>]98.3

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

    clear-num [=>]98.3

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

    un-div-inv [=>]98.3

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

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

    [Start]98.3

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

    *-commutative [=>]98.3

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

    frac-2neg [=>]98.3

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

    associate-*r/ [=>]98.6

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

    associate-*l/ [=>]85.7

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

    *-commutative [=>]85.7

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

    associate-/r/ [=>]85.0

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

    *-commutative [=>]85.0

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

    metadata-eval [=>]85.0

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

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

    [Start]85.0

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

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

Alternatives

Alternative 1
Accuracy87.3%
Cost14788
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := c \cdot b - a \cdot d\\ \mathbf{if}\;\frac{t_1}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+244}:\\ \;\;\;\;t_0 \cdot \frac{t_1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \left(b - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)\\ \end{array} \]
Alternative 2
Accuracy83.3%
Cost13896
\[\begin{array}{l} \mathbf{if}\;c \leq -2 \cdot 10^{-173}:\\ \;\;\;\;\left(b + a \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{-141}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)\\ \end{array} \]
Alternative 3
Accuracy83.3%
Cost13896
\[\begin{array}{l} t_0 := \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\\ \mathbf{if}\;c \leq -2 \cdot 10^{-173}:\\ \;\;\;\;\left(b + t_0\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 3.4 \cdot 10^{-142}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - t_0\right)\\ \end{array} \]
Alternative 4
Accuracy81.7%
Cost2000
\[\begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := b \cdot \frac{c}{t_0} - \frac{a \cdot d}{t_0}\\ t_2 := \frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{if}\;d \leq -2.1 \cdot 10^{+152}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-99}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 1.66 \cdot 10^{+97}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Accuracy81.1%
Cost1488
\[\begin{array}{l} t_0 := \frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{if}\;d \leq -1.2 \cdot 10^{+152}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{-90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.8 \cdot 10^{-96}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 3 \cdot 10^{+97}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Accuracy75.5%
Cost1032
\[\begin{array}{l} t_0 := \frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{if}\;d \leq -1.25 \cdot 10^{+152}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -5.8 \cdot 10^{-11}:\\ \;\;\;\;\frac{-a}{\frac{c \cdot c + d \cdot d}{d}}\\ \mathbf{elif}\;d \leq 7.2 \cdot 10^{+58}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Accuracy76.1%
Cost968
\[\begin{array}{l} \mathbf{if}\;c \leq -270000:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{-42}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \end{array} \]
Alternative 8
Accuracy69.7%
Cost841
\[\begin{array}{l} \mathbf{if}\;c \leq -6.6 \cdot 10^{-14} \lor \neg \left(c \leq 4 \cdot 10^{-42}\right):\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
Alternative 9
Accuracy75.5%
Cost841
\[\begin{array}{l} \mathbf{if}\;c \leq -0.015 \lor \neg \left(c \leq 4.5 \cdot 10^{-42}\right):\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \end{array} \]
Alternative 10
Accuracy76.2%
Cost841
\[\begin{array}{l} \mathbf{if}\;c \leq -400000000 \lor \neg \left(c \leq 3.5 \cdot 10^{-42}\right):\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \end{array} \]
Alternative 11
Accuracy63.3%
Cost520
\[\begin{array}{l} \mathbf{if}\;c \leq -4100000000:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.8 \cdot 10^{-22}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 12
Accuracy40.9%
Cost192
\[\frac{b}{c} \]

Error

Reproduce?

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