| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 20352 |
\[\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)
\]
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d) :precision binary64 (- (/ (/ b (/ (hypot c d) c)) (hypot c d)) (/ (* (/ d (hypot 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) {
return ((b / (hypot(c, d) / c)) / hypot(c, d)) - (((d / hypot(c, d)) * a) / hypot(c, d));
}
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 ((b / (Math.hypot(c, d) / c)) / Math.hypot(c, d)) - (((d / Math.hypot(c, d)) * a) / Math.hypot(c, d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
def code(a, b, c, d): return ((b / (math.hypot(c, d) / c)) / math.hypot(c, d)) - (((d / math.hypot(c, d)) * a) / math.hypot(c, d))
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(Float64(b / Float64(hypot(c, d) / c)) / hypot(c, d)) - Float64(Float64(Float64(d / hypot(c, d)) * a) / hypot(c, d))) 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 = ((b / (hypot(c, d) / c)) / hypot(c, d)) - (((d / hypot(c, d)) * a) / hypot(c, d)); 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[(N[(b / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}
Results
| Original | 59.0% |
|---|---|
| Target | 99.4% |
| Herbie | 99.3% |
Initial program 59.0%
Applied egg-rr73.3%
[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 [=>]73.3 | \[ \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-rr99.2%
[Start]73.3 | \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}
\] |
|---|---|
associate-*l/ [=>]73.5 | \[ \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 [<=]73.5 | \[ \frac{\color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
div-sub [=>]73.5 | \[ \frac{\color{blue}{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)} - \frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}
\] |
div-sub [=>]73.5 | \[ \color{blue}{\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}}
\] |
associate-/l* [=>]85.4 | \[ \frac{\color{blue}{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}
\] |
associate-/l* [=>]99.2 | \[ \frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\color{blue}{\frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}}{\mathsf{hypot}\left(c, d\right)}
\] |
Applied egg-rr99.3%
[Start]99.2 | \[ \frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}{\mathsf{hypot}\left(c, d\right)}
\] |
|---|---|
clear-num [=>]99.1 | \[ \frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\color{blue}{\frac{1}{\frac{\frac{\mathsf{hypot}\left(c, d\right)}{d}}{a}}}}{\mathsf{hypot}\left(c, d\right)}
\] |
associate-/r/ [=>]99.2 | \[ \frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{d}} \cdot a}}{\mathsf{hypot}\left(c, d\right)}
\] |
clear-num [<=]99.3 | \[ \frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\color{blue}{\frac{d}{\mathsf{hypot}\left(c, d\right)}} \cdot a}{\mathsf{hypot}\left(c, d\right)}
\] |
Final simplification99.3%
| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 20352 |
| Alternative 2 | |
|---|---|
| Accuracy | 89.7% |
| Cost | 15817 |
| Alternative 3 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 14162 |
| Alternative 4 | |
|---|---|
| Accuracy | 82.5% |
| Cost | 7760 |
| Alternative 5 | |
|---|---|
| Accuracy | 82.5% |
| Cost | 1488 |
| Alternative 6 | |
|---|---|
| Accuracy | 69.4% |
| Cost | 1106 |
| Alternative 7 | |
|---|---|
| Accuracy | 76.0% |
| Cost | 1032 |
| Alternative 8 | |
|---|---|
| Accuracy | 76.1% |
| Cost | 969 |
| Alternative 9 | |
|---|---|
| Accuracy | 75.9% |
| Cost | 968 |
| Alternative 10 | |
|---|---|
| Accuracy | 63.7% |
| Cost | 520 |
| Alternative 11 | |
|---|---|
| Accuracy | 14.6% |
| Cost | 456 |
| Alternative 12 | |
|---|---|
| Accuracy | 42.6% |
| Cost | 456 |
| Alternative 13 | |
|---|---|
| Accuracy | 8.5% |
| Cost | 192 |
herbie shell --seed 2023142
(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))))