?

Average Accuracy: 59.0% → 98.3%
Time: 15.4s
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

Original59.0%
Target99.3%
Herbie98.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-rr72.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)}} \]
    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 [=>]72.9

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

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

    div-sub [=>]72.9

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

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

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

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

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

    \[\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
Accuracy82.7%
Cost17744
\[\begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\frac{b \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;t_0 \leq -1 \cdot 10^{-269}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\frac{\frac{c}{\frac{\mathsf{hypot}\left(d, c\right)}{b}}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+307}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a\right)\\ \end{array} \]
Alternative 2
Accuracy81.4%
Cost17744
\[\begin{array}{l} t_0 := c \cdot b - d \cdot a\\ t_1 := \frac{t_0}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+203}:\\ \;\;\;\;\frac{b \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;t_1 \leq -1 \cdot 10^{-269}:\\ \;\;\;\;t_0 \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{\frac{c}{\frac{\mathsf{hypot}\left(d, c\right)}{b}}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+307}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a\right)\\ \end{array} \]
Alternative 3
Accuracy87.7%
Cost15816
\[\begin{array}{l} t_0 := c \cdot b - d \cdot a\\ t_1 := \frac{t_0}{c \cdot c + d \cdot d}\\ t_2 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+212}:\\ \;\;\;\;\frac{b \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+307}:\\ \;\;\;\;t_2 \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot \left(b - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a\right)\\ \end{array} \]
Alternative 4
Accuracy79.0%
Cost7564
\[\begin{array}{l} \mathbf{if}\;d \leq -0.65:\\ \;\;\;\;\frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{-118}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 3.7 \cdot 10^{+50}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\ \end{array} \]
Alternative 5
Accuracy78.8%
Cost1356
\[\begin{array}{l} t_0 := \frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -0.6:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 8 \cdot 10^{-120}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{+51}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Accuracy76.4%
Cost969
\[\begin{array}{l} \mathbf{if}\;d \leq -0.56 \lor \neg \left(d \leq 4.2 \cdot 10^{-37}\right):\\ \;\;\;\;\frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \end{array} \]
Alternative 7
Accuracy69.9%
Cost841
\[\begin{array}{l} \mathbf{if}\;d \leq -0.62 \lor \neg \left(d \leq 13.8\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
Alternative 8
Accuracy70.5%
Cost841
\[\begin{array}{l} \mathbf{if}\;d \leq -0.65 \lor \neg \left(d \leq 0.75\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \end{array} \]
Alternative 9
Accuracy64.1%
Cost521
\[\begin{array}{l} \mathbf{if}\;d \leq -0.6 \lor \neg \left(d \leq 8500\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 10
Accuracy13.4%
Cost456
\[\begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{-38}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{+71}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]
Alternative 11
Accuracy44.9%
Cost456
\[\begin{array}{l} \mathbf{if}\;d \leq -2.5 \cdot 10^{+109}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{elif}\;d \leq 1.52 \cdot 10^{+88}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]
Alternative 12
Accuracy7.8%
Cost192
\[\frac{a}{c} \]

Error

Reproduce?

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