| Alternative 1 | |
|---|---|
| Accuracy | 72.9% |
| Cost | 1628 |
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ 1.0 (hypot c d)) (/ (fma a c (* d b)) (hypot c d)))))
(if (<= d -6.2e+119)
(+ (/ b d) (/ (/ c d) (/ d a)))
(if (<= d -1.1e-70)
t_0
(if (<= d 2.1e-224)
(+ (/ a c) (/ (* b (/ d c)) c))
(if (<= d 8.2e+100) t_0 (+ (/ b d) (* (/ c d) (/ a d)))))))))double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
double t_0 = (1.0 / hypot(c, d)) * (fma(a, c, (d * b)) / hypot(c, d));
double tmp;
if (d <= -6.2e+119) {
tmp = (b / d) + ((c / d) / (d / a));
} else if (d <= -1.1e-70) {
tmp = t_0;
} else if (d <= 2.1e-224) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (d <= 8.2e+100) {
tmp = t_0;
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function code(a, b, c, d) t_0 = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(d * b)) / hypot(c, d))) tmp = 0.0 if (d <= -6.2e+119) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) / Float64(d / a))); elseif (d <= -1.1e-70) tmp = t_0; elseif (d <= 2.1e-224) tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c)); elseif (d <= 8.2e+100) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); end return tmp end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.2e+119], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.1e-70], t$95$0, If[LessEqual[d, 2.1e-224], N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8.2e+100], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -6.2 \cdot 10^{+119}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\
\mathbf{elif}\;d \leq -1.1 \cdot 10^{-70}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-224}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 8.2 \cdot 10^{+100}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
| Original | 59.2% |
|---|---|
| Target | 99.2% |
| Herbie | 83.8% |
if d < -6.1999999999999999e119Initial program 34.0%
Taylor expanded in c around 0 73.1%
Simplified85.2%
[Start]73.1 | \[ \frac{b}{d} + \frac{c \cdot a}{{d}^{2}}
\] |
|---|---|
*-commutative [<=]73.1 | \[ \frac{b}{d} + \frac{\color{blue}{a \cdot c}}{{d}^{2}}
\] |
unpow2 [=>]73.1 | \[ \frac{b}{d} + \frac{a \cdot c}{\color{blue}{d \cdot d}}
\] |
times-frac [=>]85.2 | \[ \frac{b}{d} + \color{blue}{\frac{a}{d} \cdot \frac{c}{d}}
\] |
Applied egg-rr85.3%
[Start]85.2 | \[ \frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}
\] |
|---|---|
clear-num [=>]85.2 | \[ \frac{b}{d} + \color{blue}{\frac{1}{\frac{d}{a}}} \cdot \frac{c}{d}
\] |
associate-*l/ [=>]85.3 | \[ \frac{b}{d} + \color{blue}{\frac{1 \cdot \frac{c}{d}}{\frac{d}{a}}}
\] |
*-un-lft-identity [<=]85.3 | \[ \frac{b}{d} + \frac{\color{blue}{\frac{c}{d}}}{\frac{d}{a}}
\] |
if -6.1999999999999999e119 < d < -1.0999999999999999e-70 or 2.10000000000000006e-224 < d < 8.2000000000000006e100Initial program 73.7%
Applied egg-rr82.0%
[Start]73.7 | \[ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\] |
|---|---|
*-un-lft-identity [=>]73.7 | \[ \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d}
\] |
add-sqr-sqrt [=>]73.7 | \[ \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}
\] |
times-frac [=>]73.7 | \[ \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}
\] |
hypot-def [=>]73.7 | \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}
\] |
fma-def [=>]73.7 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}}
\] |
hypot-def [=>]82.0 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}
\] |
if -1.0999999999999999e-70 < d < 2.10000000000000006e-224Initial program 66.3%
Applied egg-rr81.1%
[Start]66.3 | \[ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\] |
|---|---|
*-un-lft-identity [=>]66.3 | \[ \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d}
\] |
add-sqr-sqrt [=>]66.3 | \[ \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}
\] |
times-frac [=>]66.3 | \[ \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}
\] |
hypot-def [=>]66.3 | \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}
\] |
fma-def [=>]66.3 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}}
\] |
hypot-def [=>]81.1 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}
\] |
Taylor expanded in c around inf 82.0%
Simplified86.6%
[Start]82.0 | \[ \frac{a}{c} + \frac{d \cdot b}{{c}^{2}}
\] |
|---|---|
*-commutative [<=]82.0 | \[ \frac{a}{c} + \frac{\color{blue}{b \cdot d}}{{c}^{2}}
\] |
unpow2 [=>]82.0 | \[ \frac{a}{c} + \frac{b \cdot d}{\color{blue}{c \cdot c}}
\] |
associate-/r* [=>]87.2 | \[ \frac{a}{c} + \color{blue}{\frac{\frac{b \cdot d}{c}}{c}}
\] |
*-commutative [=>]87.2 | \[ \frac{a}{c} + \frac{\frac{\color{blue}{d \cdot b}}{c}}{c}
\] |
associate-/l* [=>]85.9 | \[ \frac{a}{c} + \frac{\color{blue}{\frac{d}{\frac{c}{b}}}}{c}
\] |
associate-/r/ [=>]86.6 | \[ \frac{a}{c} + \frac{\color{blue}{\frac{d}{c} \cdot b}}{c}
\] |
if 8.2000000000000006e100 < d Initial program 37.9%
Taylor expanded in c around 0 74.4%
Simplified82.9%
[Start]74.4 | \[ \frac{b}{d} + \frac{c \cdot a}{{d}^{2}}
\] |
|---|---|
*-commutative [<=]74.4 | \[ \frac{b}{d} + \frac{\color{blue}{a \cdot c}}{{d}^{2}}
\] |
unpow2 [=>]74.4 | \[ \frac{b}{d} + \frac{a \cdot c}{\color{blue}{d \cdot d}}
\] |
times-frac [=>]82.9 | \[ \frac{b}{d} + \color{blue}{\frac{a}{d} \cdot \frac{c}{d}}
\] |
Final simplification83.8%
| Alternative 1 | |
|---|---|
| Accuracy | 72.9% |
| Cost | 1628 |
| Alternative 2 | |
|---|---|
| Accuracy | 73.0% |
| Cost | 1628 |
| Alternative 3 | |
|---|---|
| Accuracy | 73.3% |
| Cost | 1628 |
| Alternative 4 | |
|---|---|
| Accuracy | 73.7% |
| Cost | 1628 |
| Alternative 5 | |
|---|---|
| Accuracy | 81.1% |
| Cost | 1488 |
| Alternative 6 | |
|---|---|
| Accuracy | 68.9% |
| Cost | 1232 |
| Alternative 7 | |
|---|---|
| Accuracy | 69.4% |
| Cost | 1232 |
| Alternative 8 | |
|---|---|
| Accuracy | 63.8% |
| Cost | 456 |
| Alternative 9 | |
|---|---|
| Accuracy | 41.5% |
| Cost | 192 |
herbie shell --seed 2023136
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))