| Alternative 1 | |
|---|---|
| Accuracy | 95.0% |
| Cost | 46476 |

(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ c (hypot c d))) (t_1 (/ b (hypot c d))))
(if (<= d -1.3e+154)
(- (* (/ c d) (/ b d)) (/ a d))
(if (<= d -1e-180)
(fma t_0 t_1 (/ (- a) (/ (pow (hypot c d) 2.0) d)))
(if (<= d 2e-251)
(/ (- b (/ a (/ c d))) c)
(fma
t_0
t_1
(/ (* (sqrt d) (/ (- a) (hypot c d))) (/ (hypot c d) (sqrt 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) {
double t_0 = c / hypot(c, d);
double t_1 = b / hypot(c, d);
double tmp;
if (d <= -1.3e+154) {
tmp = ((c / d) * (b / d)) - (a / d);
} else if (d <= -1e-180) {
tmp = fma(t_0, t_1, (-a / (pow(hypot(c, d), 2.0) / d)));
} else if (d <= 2e-251) {
tmp = (b - (a / (c / d))) / c;
} else {
tmp = fma(t_0, t_1, ((sqrt(d) * (-a / hypot(c, d))) / (hypot(c, d) / sqrt(d))));
}
return tmp;
}
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) t_0 = Float64(c / hypot(c, d)) t_1 = Float64(b / hypot(c, d)) tmp = 0.0 if (d <= -1.3e+154) tmp = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d)); elseif (d <= -1e-180) tmp = fma(t_0, t_1, Float64(Float64(-a) / Float64((hypot(c, d) ^ 2.0) / d))); elseif (d <= 2e-251) tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); else tmp = fma(t_0, t_1, Float64(Float64(sqrt(d) * Float64(Float64(-a) / hypot(c, d))) / Float64(hypot(c, d) / sqrt(d)))); end return tmp 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_] := Block[{t$95$0 = N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.3e+154], N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1e-180], N[(t$95$0 * t$95$1 + N[((-a) / N[(N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2e-251], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(t$95$0 * t$95$1 + N[(N[(N[Sqrt[d], $MachinePrecision] * N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / N[Sqrt[d], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{+154}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\
\mathbf{elif}\;d \leq -1 \cdot 10^{-180}:\\
\;\;\;\;\mathsf{fma}\left(t_0, t_1, \frac{-a}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)\\
\mathbf{elif}\;d \leq 2 \cdot 10^{-251}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, t_1, \frac{\sqrt{d} \cdot \frac{-a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}\right)\\
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 61.5% |
|---|---|
| Target | 99.4% |
| Herbie | 95.0% |
if d < -1.29999999999999994e154Initial program 23.3%
Taylor expanded in c around 0 72.6%
Simplified83.5%
[Start]72.6% | \[ -1 \cdot \frac{a}{d} + \frac{c \cdot b}{{d}^{2}}
\] |
|---|---|
+-commutative [=>]72.6% | \[ \color{blue}{\frac{c \cdot b}{{d}^{2}} + -1 \cdot \frac{a}{d}}
\] |
mul-1-neg [=>]72.6% | \[ \frac{c \cdot b}{{d}^{2}} + \color{blue}{\left(-\frac{a}{d}\right)}
\] |
unsub-neg [=>]72.6% | \[ \color{blue}{\frac{c \cdot b}{{d}^{2}} - \frac{a}{d}}
\] |
unpow2 [=>]72.6% | \[ \frac{c \cdot b}{\color{blue}{d \cdot d}} - \frac{a}{d}
\] |
times-frac [=>]83.5% | \[ \color{blue}{\frac{c}{d} \cdot \frac{b}{d}} - \frac{a}{d}
\] |
if -1.29999999999999994e154 < d < -1e-180Initial program 79.3%
Applied egg-rr93.1%
[Start]79.3% | \[ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\] |
|---|---|
div-sub [=>]77.8% | \[ \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}
\] |
*-commutative [=>]77.8% | \[ \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}
\] |
add-sqr-sqrt [=>]77.8% | \[ \frac{c \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}
\] |
times-frac [=>]78.4% | \[ \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}
\] |
fma-neg [=>]78.4% | \[ \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{c \cdot c + d \cdot d}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)}
\] |
hypot-def [=>]78.4% | \[ \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)
\] |
hypot-def [=>]89.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)
\] |
associate-/l* [=>]93.1% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{a}{\frac{c \cdot c + d \cdot d}{d}}}\right)
\] |
add-sqr-sqrt [=>]93.1% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}{d}}\right)
\] |
pow2 [=>]93.1% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{\color{blue}{{\left(\sqrt{c \cdot c + d \cdot d}\right)}^{2}}}{d}}\right)
\] |
hypot-def [=>]93.1% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}{d}}\right)
\] |
if -1e-180 < d < 2.00000000000000003e-251Initial program 65.9%
Applied egg-rr78.2%
[Start]65.9% | \[ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\] |
|---|---|
div-sub [=>]60.2% | \[ \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}
\] |
*-commutative [=>]60.2% | \[ \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}
\] |
add-sqr-sqrt [=>]60.2% | \[ \frac{c \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}
\] |
times-frac [=>]68.2% | \[ \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}
\] |
fma-neg [=>]68.2% | \[ \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{c \cdot c + d \cdot d}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)}
\] |
hypot-def [=>]68.2% | \[ \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)
\] |
hypot-def [=>]80.5% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)
\] |
associate-/l* [=>]78.2% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{a}{\frac{c \cdot c + d \cdot d}{d}}}\right)
\] |
add-sqr-sqrt [=>]78.2% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}{d}}\right)
\] |
pow2 [=>]78.2% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{\color{blue}{{\left(\sqrt{c \cdot c + d \cdot d}\right)}^{2}}}{d}}\right)
\] |
hypot-def [=>]78.2% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}{d}}\right)
\] |
Taylor expanded in c around inf 80.5%
Simplified80.5%
[Start]80.5% | \[ -1 \cdot \frac{a \cdot d}{{c}^{2}} + \frac{b}{c}
\] |
|---|---|
+-commutative [=>]80.5% | \[ \color{blue}{\frac{b}{c} + -1 \cdot \frac{a \cdot d}{{c}^{2}}}
\] |
mul-1-neg [=>]80.5% | \[ \frac{b}{c} + \color{blue}{\left(-\frac{a \cdot d}{{c}^{2}}\right)}
\] |
unsub-neg [=>]80.5% | \[ \color{blue}{\frac{b}{c} - \frac{a \cdot d}{{c}^{2}}}
\] |
*-commutative [<=]80.5% | \[ \frac{b}{c} - \frac{\color{blue}{d \cdot a}}{{c}^{2}}
\] |
unpow2 [=>]80.5% | \[ \frac{b}{c} - \frac{d \cdot a}{\color{blue}{c \cdot c}}
\] |
Applied egg-rr98.3%
[Start]80.5% | \[ \frac{b}{c} - \frac{d \cdot a}{c \cdot c}
\] |
|---|---|
*-un-lft-identity [=>]80.5% | \[ \color{blue}{1 \cdot \left(\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\right)}
\] |
associate-/r* [=>]98.3% | \[ 1 \cdot \left(\frac{b}{c} - \color{blue}{\frac{\frac{d \cdot a}{c}}{c}}\right)
\] |
sub-div [=>]98.3% | \[ 1 \cdot \color{blue}{\frac{b - \frac{d \cdot a}{c}}{c}}
\] |
Simplified98.3%
[Start]98.3% | \[ 1 \cdot \frac{b - \frac{d \cdot a}{c}}{c}
\] |
|---|---|
*-lft-identity [=>]98.3% | \[ \color{blue}{\frac{b - \frac{d \cdot a}{c}}{c}}
\] |
*-commutative [<=]98.3% | \[ \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c}
\] |
associate-/l* [=>]98.3% | \[ \frac{b - \color{blue}{\frac{a}{\frac{c}{d}}}}{c}
\] |
if 2.00000000000000003e-251 < d Initial program 58.5%
Applied egg-rr76.9%
[Start]58.5% | \[ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\] |
|---|---|
div-sub [=>]56.8% | \[ \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}
\] |
*-commutative [=>]56.8% | \[ \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}
\] |
add-sqr-sqrt [=>]56.7% | \[ \frac{c \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}
\] |
times-frac [=>]60.8% | \[ \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}
\] |
fma-neg [=>]60.8% | \[ \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{c \cdot c + d \cdot d}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)}
\] |
hypot-def [=>]60.8% | \[ \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)
\] |
hypot-def [=>]74.6% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)
\] |
associate-/l* [=>]76.9% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{a}{\frac{c \cdot c + d \cdot d}{d}}}\right)
\] |
add-sqr-sqrt [=>]76.9% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}{d}}\right)
\] |
pow2 [=>]76.9% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{\color{blue}{{\left(\sqrt{c \cdot c + d \cdot d}\right)}^{2}}}{d}}\right)
\] |
hypot-def [=>]76.9% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}{d}}\right)
\] |
Applied egg-rr96.7%
[Start]76.9% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)
\] |
|---|---|
*-un-lft-identity [=>]76.9% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{\color{blue}{1 \cdot a}}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)
\] |
add-sqr-sqrt [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1 \cdot a}{\color{blue}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}} \cdot \sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}}\right)
\] |
times-frac [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{1}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}} \cdot \frac{a}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}}\right)
\] |
unpow2 [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\sqrt{\frac{\color{blue}{\mathsf{hypot}\left(c, d\right) \cdot \mathsf{hypot}\left(c, d\right)}}{d}}} \cdot \frac{a}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}\right)
\] |
hypot-udef [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\sqrt{\frac{\color{blue}{\sqrt{c \cdot c + d \cdot d}} \cdot \mathsf{hypot}\left(c, d\right)}{d}}} \cdot \frac{a}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}\right)
\] |
hypot-udef [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\sqrt{\frac{\sqrt{c \cdot c + d \cdot d} \cdot \color{blue}{\sqrt{c \cdot c + d \cdot d}}}{d}}} \cdot \frac{a}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}\right)
\] |
add-sqr-sqrt [<=]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\sqrt{\frac{\color{blue}{c \cdot c + d \cdot d}}{d}}} \cdot \frac{a}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}\right)
\] |
+-commutative [<=]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\sqrt{\frac{\color{blue}{d \cdot d + c \cdot c}}{d}}} \cdot \frac{a}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}\right)
\] |
sqrt-div [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\color{blue}{\frac{\sqrt{d \cdot d + c \cdot c}}{\sqrt{d}}}} \cdot \frac{a}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}\right)
\] |
+-commutative [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\frac{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}{\sqrt{d}}} \cdot \frac{a}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}\right)
\] |
hypot-udef [<=]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(c, d\right)}}{\sqrt{d}}} \cdot \frac{a}{\sqrt{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}}\right)
\] |
unpow2 [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}} \cdot \frac{a}{\sqrt{\frac{\color{blue}{\mathsf{hypot}\left(c, d\right) \cdot \mathsf{hypot}\left(c, d\right)}}{d}}}\right)
\] |
hypot-udef [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}} \cdot \frac{a}{\sqrt{\frac{\color{blue}{\sqrt{c \cdot c + d \cdot d}} \cdot \mathsf{hypot}\left(c, d\right)}{d}}}\right)
\] |
hypot-udef [=>]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}} \cdot \frac{a}{\sqrt{\frac{\sqrt{c \cdot c + d \cdot d} \cdot \color{blue}{\sqrt{c \cdot c + d \cdot d}}}{d}}}\right)
\] |
add-sqr-sqrt [<=]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}} \cdot \frac{a}{\sqrt{\frac{\color{blue}{c \cdot c + d \cdot d}}{d}}}\right)
\] |
+-commutative [<=]76.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}} \cdot \frac{a}{\sqrt{\frac{\color{blue}{d \cdot d + c \cdot c}}{d}}}\right)
\] |
Simplified96.8%
[Start]96.7% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}} \cdot \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}\right)
\] |
|---|---|
associate-*l/ [=>]96.7% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{1 \cdot \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}}\right)
\] |
*-lft-identity [=>]96.7% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{\color{blue}{\frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}}}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}\right)
\] |
associate-/r/ [=>]96.8% | \[ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{\color{blue}{\frac{a}{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{d}}}{\frac{\mathsf{hypot}\left(c, d\right)}{\sqrt{d}}}\right)
\] |
Final simplification94.6%
| Alternative 1 | |
|---|---|
| Accuracy | 95.0% |
| Cost | 46476 |
| Alternative 2 | |
|---|---|
| Accuracy | 85.2% |
| Cost | 14660 |
| Alternative 3 | |
|---|---|
| Accuracy | 78.9% |
| Cost | 13900 |
| Alternative 4 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 7436 |
| Alternative 5 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 1356 |
| Alternative 6 | |
|---|---|
| Accuracy | 75.9% |
| Cost | 969 |
| Alternative 7 | |
|---|---|
| Accuracy | 76.0% |
| Cost | 968 |
| Alternative 8 | |
|---|---|
| Accuracy | 71.6% |
| Cost | 841 |
| Alternative 9 | |
|---|---|
| Accuracy | 63.4% |
| Cost | 520 |
| Alternative 10 | |
|---|---|
| Accuracy | 10.1% |
| Cost | 192 |
| Alternative 11 | |
|---|---|
| Accuracy | 43.4% |
| Cost | 192 |
herbie shell --seed 2023263
(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))))