?

Average Accuracy: 59.8% → 97.5%
Time: 16.5s
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}{\frac{\mathsf{hypot}\left(c, d\right)}{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(d / Float64(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[(d / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / a), $MachinePrecision]), $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}{\frac{\mathsf{hypot}\left(c, d\right)}{a}}\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original59.8%
Target99.3%
Herbie97.5%
\[\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.8%

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

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

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

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

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

    add-sqr-sqrt [=>]59.8

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

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

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

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

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

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

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

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

    \[ \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-rr68.4%

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

    [Start]98.2

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

    expm1-log1p-u [=>]80.6

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

    expm1-udef [=>]68.7

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

    associate-/r/ [<=]68.4

    \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot c - \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{d}{\frac{\mathsf{hypot}\left(c, d\right)}{a}}}\right)} - 1\right)\right) \]
  5. Simplified97.5%

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

    [Start]68.4

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

    expm1-def [=>]80.3

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

    expm1-log1p [=>]97.5

    \[ \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) \]
  6. Final simplification97.5%

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

Alternatives

Alternative 1
Accuracy98.2%
Cost20352
\[\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - a \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right) \]
Alternative 2
Accuracy85.9%
Cost14160
\[\begin{array}{l} t_0 := \frac{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -2.8 \cdot 10^{+63}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -9 \cdot 10^{-169}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-110}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{elif}\;c \leq 1.32 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - a \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right)\\ \end{array} \]
Alternative 3
Accuracy82.2%
Cost14032
\[\begin{array}{l} t_0 := \left(c \cdot b - d \cdot a\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{if}\;c \leq -3.05 \cdot 10^{+62}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-115}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{+127}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \end{array} \]
Alternative 4
Accuracy83.7%
Cost14028
\[\begin{array}{l} \mathbf{if}\;c \leq -3.05 \cdot 10^{+63}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{-124}:\\ \;\;\;\;\left(c \cdot b - d \cdot a\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{elif}\;c \leq 3 \cdot 10^{-99}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - a \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right)\\ \end{array} \]
Alternative 5
Accuracy83.6%
Cost14028
\[\begin{array}{l} \mathbf{if}\;c \leq -3.05 \cdot 10^{+63}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -2 \cdot 10^{-120}:\\ \;\;\;\;\left(c \cdot b - d \cdot a\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{elif}\;c \leq 2.8 \cdot 10^{-99}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \frac{d}{\frac{\mathsf{hypot}\left(c, d\right)}{a}}\right)\\ \end{array} \]
Alternative 6
Accuracy82.0%
Cost2000
\[\begin{array}{l} t_0 := c \cdot b - d \cdot a\\ t_1 := c \cdot c + d \cdot d\\ \mathbf{if}\;c \leq -1.9 \cdot 10^{+63}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -2.1 \cdot 10^{-129}:\\ \;\;\;\;\frac{t_0}{t_1}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{-104}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{+123}:\\ \;\;\;\;\frac{d \cdot a + \left(t_0 - d \cdot a\right)}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \end{array} \]
Alternative 7
Accuracy73.6%
Cost1497
\[\begin{array}{l} t_0 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -1.18 \cdot 10^{+173}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.35 \cdot 10^{+130}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;d \leq -7.5 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2700000000000:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 2.5 \cdot 10^{+97} \lor \neg \left(d \leq 1.15 \cdot 10^{+114}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 8
Accuracy73.3%
Cost1496
\[\begin{array}{l} t_0 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -1.18 \cdot 10^{+173}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.35 \cdot 10^{+130}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{+15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2000000000000:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 9.8 \cdot 10^{+88}:\\ \;\;\;\;\frac{-a}{\frac{c \cdot c + d \cdot d}{d}}\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{+114}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Accuracy82.0%
Cost1488
\[\begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -2.7 \cdot 10^{+63}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -5.3 \cdot 10^{-129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 9.8 \cdot 10^{-104}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \mathbf{elif}\;c \leq 5.7 \cdot 10^{+128}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \end{array} \]
Alternative 10
Accuracy68.2%
Cost1106
\[\begin{array}{l} \mathbf{if}\;d \leq -1.18 \cdot 10^{+173} \lor \neg \left(d \leq -1.7 \cdot 10^{+130}\right) \land \left(d \leq -135000000000 \lor \neg \left(d \leq 102000000000\right)\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
Alternative 11
Accuracy68.9%
Cost1105
\[\begin{array}{l} t_0 := \frac{-a}{d}\\ \mathbf{if}\;d \leq -1.55 \cdot 10^{+173}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{+130}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;d \leq -1.25 \cdot 10^{+17} \lor \neg \left(d \leq 2.5 \cdot 10^{+15}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \end{array} \]
Alternative 12
Accuracy62.8%
Cost520
\[\begin{array}{l} \mathbf{if}\;c \leq -1.9 \cdot 10^{-7}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.12 \cdot 10^{-61}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 13
Accuracy44.9%
Cost456
\[\begin{array}{l} \mathbf{if}\;d \leq -3.25 \cdot 10^{+184}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{elif}\;d \leq 4.6 \cdot 10^{+219}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]
Alternative 14
Accuracy10.8%
Cost192
\[\frac{a}{d} \]

Error

Reproduce?

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