| Alternative 1 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 20352 |
\[\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)
\]
(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)
Results
| Original | 59.8% |
|---|---|
| Target | 99.3% |
| Herbie | 97.5% |
Initial program 59.8%
Applied egg-rr73.8%
[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)}}
\] |
Applied egg-rr98.2%
[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)
\] |
Applied egg-rr68.4%
[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)
\] |
Simplified97.5%
[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)
\] |
Final simplification97.5%
| Alternative 1 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 20352 |
| Alternative 2 | |
|---|---|
| Accuracy | 85.9% |
| Cost | 14160 |
| Alternative 3 | |
|---|---|
| Accuracy | 82.2% |
| Cost | 14032 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 14028 |
| Alternative 5 | |
|---|---|
| Accuracy | 83.6% |
| Cost | 14028 |
| Alternative 6 | |
|---|---|
| Accuracy | 82.0% |
| Cost | 2000 |
| Alternative 7 | |
|---|---|
| Accuracy | 73.6% |
| Cost | 1497 |
| Alternative 8 | |
|---|---|
| Accuracy | 73.3% |
| Cost | 1496 |
| Alternative 9 | |
|---|---|
| Accuracy | 82.0% |
| Cost | 1488 |
| Alternative 10 | |
|---|---|
| Accuracy | 68.2% |
| Cost | 1106 |
| Alternative 11 | |
|---|---|
| Accuracy | 68.9% |
| Cost | 1105 |
| Alternative 12 | |
|---|---|
| Accuracy | 62.8% |
| Cost | 520 |
| Alternative 13 | |
|---|---|
| Accuracy | 44.9% |
| Cost | 456 |
| Alternative 14 | |
|---|---|
| Accuracy | 10.8% |
| Cost | 192 |
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))))