| Alternative 1 | |
|---|---|
| Accuracy | 77.2% |
| Cost | 1752 |
(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 b) (* d a)) (hypot c d)) (hypot c d))))
(if (<= d -5.6e+162)
(- (/ (/ c (/ d b)) d) (/ a d))
(if (<= d -5.8e-149)
t_0
(if (<= d 3.1e-158)
(/ (- b (/ d (/ c a))) c)
(if (<= d 920000000000.0)
t_0
(/ (- (* b (/ c d)) a) (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) {
double t_0 = (((c * b) - (d * a)) / hypot(c, d)) / hypot(c, d);
double tmp;
if (d <= -5.6e+162) {
tmp = ((c / (d / b)) / d) - (a / d);
} else if (d <= -5.8e-149) {
tmp = t_0;
} else if (d <= 3.1e-158) {
tmp = (b - (d / (c / a))) / c;
} else if (d <= 920000000000.0) {
tmp = t_0;
} else {
tmp = ((b * (c / d)) - a) / hypot(c, d);
}
return tmp;
}
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) {
double t_0 = (((c * b) - (d * a)) / Math.hypot(c, d)) / Math.hypot(c, d);
double tmp;
if (d <= -5.6e+162) {
tmp = ((c / (d / b)) / d) - (a / d);
} else if (d <= -5.8e-149) {
tmp = t_0;
} else if (d <= 3.1e-158) {
tmp = (b - (d / (c / a))) / c;
} else if (d <= 920000000000.0) {
tmp = t_0;
} else {
tmp = ((b * (c / d)) - a) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
def code(a, b, c, d): t_0 = (((c * b) - (d * a)) / math.hypot(c, d)) / math.hypot(c, d) tmp = 0 if d <= -5.6e+162: tmp = ((c / (d / b)) / d) - (a / d) elif d <= -5.8e-149: tmp = t_0 elif d <= 3.1e-158: tmp = (b - (d / (c / a))) / c elif d <= 920000000000.0: tmp = t_0 else: tmp = ((b * (c / d)) - a) / math.hypot(c, 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(Float64(Float64(Float64(c * b) - Float64(d * a)) / hypot(c, d)) / hypot(c, d)) tmp = 0.0 if (d <= -5.6e+162) tmp = Float64(Float64(Float64(c / Float64(d / b)) / d) - Float64(a / d)); elseif (d <= -5.8e-149) tmp = t_0; elseif (d <= 3.1e-158) tmp = Float64(Float64(b - Float64(d / Float64(c / a))) / c); elseif (d <= 920000000000.0) tmp = t_0; else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / hypot(c, d)); end return tmp end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
function tmp_2 = code(a, b, c, d) t_0 = (((c * b) - (d * a)) / hypot(c, d)) / hypot(c, d); tmp = 0.0; if (d <= -5.6e+162) tmp = ((c / (d / b)) / d) - (a / d); elseif (d <= -5.8e-149) tmp = t_0; elseif (d <= 3.1e-158) tmp = (b - (d / (c / a))) / c; elseif (d <= 920000000000.0) tmp = t_0; else tmp = ((b * (c / d)) - a) / hypot(c, d); end tmp_2 = 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[(N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.6e+162], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.8e-149], t$95$0, If[LessEqual[d, 3.1e-158], N[(N[(b - N[(d / N[(c / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 920000000000.0], t$95$0, N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\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}\;d \leq -5.6 \cdot 10^{+162}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}}}{d} - \frac{a}{d}\\
\mathbf{elif}\;d \leq -5.8 \cdot 10^{-149}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 3.1 \cdot 10^{-158}:\\
\;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\
\mathbf{elif}\;d \leq 920000000000:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
Results
| Original | 58.4% |
|---|---|
| Target | 99.3% |
| Herbie | 83.4% |
if d < -5.59999999999999981e162Initial program 31.2%
Applied egg-rr54.5%
[Start]31.2 | \[ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\] |
|---|---|
*-un-lft-identity [=>]31.2 | \[ \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d}
\] |
add-sqr-sqrt [=>]31.2 | \[ \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 [=>]31.2 | \[ \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 [=>]31.2 | \[ \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 [=>]54.5 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}
\] |
Applied egg-rr54.6%
[Start]54.5 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}
\] |
|---|---|
associate-*l/ [=>]54.6 | \[ \color{blue}{\frac{1 \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}}
\] |
*-un-lft-identity [<=]54.6 | \[ \frac{\color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
Applied egg-rr54.2%
[Start]54.6 | \[ \frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}
\] |
|---|---|
add-cube-cbrt [=>]54.2 | \[ \frac{\frac{\color{blue}{\left(\sqrt[3]{b \cdot c - a \cdot d} \cdot \sqrt[3]{b \cdot c - a \cdot d}\right) \cdot \sqrt[3]{b \cdot c - a \cdot d}}}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}
\] |
add-sqr-sqrt [=>]54.2 | \[ \frac{\frac{\left(\sqrt[3]{b \cdot c - a \cdot d} \cdot \sqrt[3]{b \cdot c - a \cdot d}\right) \cdot \sqrt[3]{b \cdot c - a \cdot d}}{\color{blue}{\sqrt{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{\mathsf{hypot}\left(c, d\right)}}}}{\mathsf{hypot}\left(c, d\right)}
\] |
times-frac [=>]54.2 | \[ \frac{\color{blue}{\frac{\sqrt[3]{b \cdot c - a \cdot d} \cdot \sqrt[3]{b \cdot c - a \cdot d}}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{\sqrt[3]{b \cdot c - a \cdot d}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}}{\mathsf{hypot}\left(c, d\right)}
\] |
pow2 [=>]54.2 | \[ \frac{\frac{\color{blue}{{\left(\sqrt[3]{b \cdot c - a \cdot d}\right)}^{2}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{\sqrt[3]{b \cdot c - a \cdot d}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
Simplified54.4%
[Start]54.2 | \[ \frac{\frac{{\left(\sqrt[3]{b \cdot c - a \cdot d}\right)}^{2}}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{\sqrt[3]{b \cdot c - a \cdot d}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
|---|---|
associate-*l/ [=>]54.2 | \[ \frac{\color{blue}{\frac{{\left(\sqrt[3]{b \cdot c - a \cdot d}\right)}^{2} \cdot \frac{\sqrt[3]{b \cdot c - a \cdot d}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}}{\mathsf{hypot}\left(c, d\right)}
\] |
associate-*r/ [=>]54.2 | \[ \frac{\frac{\color{blue}{\frac{{\left(\sqrt[3]{b \cdot c - a \cdot d}\right)}^{2} \cdot \sqrt[3]{b \cdot c - a \cdot d}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
unpow2 [=>]54.2 | \[ \frac{\frac{\frac{\color{blue}{\left(\sqrt[3]{b \cdot c - a \cdot d} \cdot \sqrt[3]{b \cdot c - a \cdot d}\right)} \cdot \sqrt[3]{b \cdot c - a \cdot d}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
rem-3cbrt-lft [=>]54.4 | \[ \frac{\frac{\frac{\color{blue}{b \cdot c - a \cdot d}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
*-commutative [=>]54.4 | \[ \frac{\frac{\frac{\color{blue}{c \cdot b} - a \cdot d}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
Taylor expanded in c around 0 76.1%
Simplified89.4%
[Start]76.1 | \[ -1 \cdot \frac{a}{d} + \frac{c \cdot b}{{d}^{2}}
\] |
|---|---|
+-commutative [=>]76.1 | \[ \color{blue}{\frac{c \cdot b}{{d}^{2}} + -1 \cdot \frac{a}{d}}
\] |
mul-1-neg [=>]76.1 | \[ \frac{c \cdot b}{{d}^{2}} + \color{blue}{\left(-\frac{a}{d}\right)}
\] |
unsub-neg [=>]76.1 | \[ \color{blue}{\frac{c \cdot b}{{d}^{2}} - \frac{a}{d}}
\] |
unpow2 [=>]76.1 | \[ \frac{c \cdot b}{\color{blue}{d \cdot d}} - \frac{a}{d}
\] |
associate-/r* [=>]81.6 | \[ \color{blue}{\frac{\frac{c \cdot b}{d}}{d}} - \frac{a}{d}
\] |
associate-/l* [=>]89.4 | \[ \frac{\color{blue}{\frac{c}{\frac{d}{b}}}}{d} - \frac{a}{d}
\] |
if -5.59999999999999981e162 < d < -5.8e-149 or 3.10000000000000018e-158 < d < 9.2e11Initial program 72.1%
Applied egg-rr81.2%
[Start]72.1 | \[ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\] |
|---|---|
*-un-lft-identity [=>]72.1 | \[ \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d}
\] |
add-sqr-sqrt [=>]72.1 | \[ \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 [=>]72.1 | \[ \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 [=>]72.1 | \[ \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 [=>]81.2 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}
\] |
Applied egg-rr81.4%
[Start]81.2 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}
\] |
|---|---|
associate-*l/ [=>]81.4 | \[ \color{blue}{\frac{1 \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}}
\] |
*-un-lft-identity [<=]81.4 | \[ \frac{\color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
if -5.8e-149 < d < 3.10000000000000018e-158Initial program 62.7%
Taylor expanded in c around inf 83.9%
Simplified87.4%
[Start]83.9 | \[ -1 \cdot \frac{a \cdot d}{{c}^{2}} + \frac{b}{c}
\] |
|---|---|
+-commutative [=>]83.9 | \[ \color{blue}{\frac{b}{c} + -1 \cdot \frac{a \cdot d}{{c}^{2}}}
\] |
mul-1-neg [=>]83.9 | \[ \frac{b}{c} + \color{blue}{\left(-\frac{a \cdot d}{{c}^{2}}\right)}
\] |
unsub-neg [=>]83.9 | \[ \color{blue}{\frac{b}{c} - \frac{a \cdot d}{{c}^{2}}}
\] |
unpow2 [=>]83.9 | \[ \frac{b}{c} - \frac{a \cdot d}{\color{blue}{c \cdot c}}
\] |
times-frac [=>]87.4 | \[ \frac{b}{c} - \color{blue}{\frac{a}{c} \cdot \frac{d}{c}}
\] |
Applied egg-rr81.5%
[Start]87.4 | \[ \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}
\] |
|---|---|
clear-num [=>]87.4 | \[ \frac{b}{c} - \color{blue}{\frac{1}{\frac{c}{a}}} \cdot \frac{d}{c}
\] |
frac-times [=>]81.5 | \[ \frac{b}{c} - \color{blue}{\frac{1 \cdot d}{\frac{c}{a} \cdot c}}
\] |
*-un-lft-identity [<=]81.5 | \[ \frac{b}{c} - \frac{\color{blue}{d}}{\frac{c}{a} \cdot c}
\] |
Applied egg-rr88.9%
[Start]81.5 | \[ \frac{b}{c} - \frac{d}{\frac{c}{a} \cdot c}
\] |
|---|---|
associate-/r* [=>]88.9 | \[ \frac{b}{c} - \color{blue}{\frac{\frac{d}{\frac{c}{a}}}{c}}
\] |
sub-div [=>]88.9 | \[ \color{blue}{\frac{b - \frac{d}{\frac{c}{a}}}{c}}
\] |
if 9.2e11 < d Initial program 47.1%
Applied egg-rr61.6%
[Start]47.1 | \[ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\] |
|---|---|
*-un-lft-identity [=>]47.1 | \[ \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d}
\] |
add-sqr-sqrt [=>]47.1 | \[ \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 [=>]47.1 | \[ \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 [=>]47.1 | \[ \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 [=>]61.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)}}
\] |
Applied egg-rr61.7%
[Start]61.6 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}
\] |
|---|---|
associate-*l/ [=>]61.7 | \[ \color{blue}{\frac{1 \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}}
\] |
*-un-lft-identity [<=]61.7 | \[ \frac{\color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
Taylor expanded in c around 0 74.0%
Simplified78.4%
[Start]74.0 | \[ \frac{\frac{c \cdot b}{d} + -1 \cdot a}{\mathsf{hypot}\left(c, d\right)}
\] |
|---|---|
mul-1-neg [=>]74.0 | \[ \frac{\frac{c \cdot b}{d} + \color{blue}{\left(-a\right)}}{\mathsf{hypot}\left(c, d\right)}
\] |
unsub-neg [=>]74.0 | \[ \frac{\color{blue}{\frac{c \cdot b}{d} - a}}{\mathsf{hypot}\left(c, d\right)}
\] |
associate-/l* [=>]79.0 | \[ \frac{\color{blue}{\frac{c}{\frac{d}{b}}} - a}{\mathsf{hypot}\left(c, d\right)}
\] |
associate-/r/ [=>]78.4 | \[ \frac{\color{blue}{\frac{c}{d} \cdot b} - a}{\mathsf{hypot}\left(c, d\right)}
\] |
Final simplification83.4%
| Alternative 1 | |
|---|---|
| Accuracy | 77.2% |
| Cost | 1752 |
| Alternative 2 | |
|---|---|
| Accuracy | 73.1% |
| Cost | 1232 |
| Alternative 3 | |
|---|---|
| Accuracy | 73.1% |
| Cost | 1232 |
| Alternative 4 | |
|---|---|
| Accuracy | 73.3% |
| Cost | 1232 |
| Alternative 5 | |
|---|---|
| Accuracy | 67.6% |
| Cost | 1106 |
| Alternative 6 | |
|---|---|
| Accuracy | 67.9% |
| Cost | 1104 |
| Alternative 7 | |
|---|---|
| Accuracy | 61.6% |
| Cost | 785 |
| Alternative 8 | |
|---|---|
| Accuracy | 45.5% |
| Cost | 456 |
| Alternative 9 | |
|---|---|
| Accuracy | 11.2% |
| Cost | 192 |
herbie shell --seed 2023147
(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))))