| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 38720 |
\[\log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\log 10}\right)\right)\right)}\right)
\]

(FPCore (re im) :precision binary64 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
(FPCore (re im) :precision binary64 (log (pow (hypot re im) (log1p (expm1 (/ 1.0 (log 10.0)))))))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im)))) / log(10.0);
}
double code(double re, double im) {
return log(pow(hypot(re, im), log1p(expm1((1.0 / log(10.0))))));
}
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(10.0);
}
public static double code(double re, double im) {
return Math.log(Math.pow(Math.hypot(re, im), Math.log1p(Math.expm1((1.0 / Math.log(10.0))))));
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im)))) / math.log(10.0)
def code(re, im): return math.log(math.pow(math.hypot(re, im), math.log1p(math.expm1((1.0 / math.log(10.0))))))
function code(re, im) return Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(10.0)) end
function code(re, im) return log((hypot(re, im) ^ log1p(expm1(Float64(1.0 / log(10.0)))))) end
code[re_, im_] := N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
code[re_, im_] := N[Log[N[Power[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision], N[Log[1 + N[(Exp[N[(1.0 / N[Log[10.0], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\log 10}\right)\right)\right)}\right)
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 50.4%
Simplified99.1%
[Start]50.4% | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\] |
|---|---|
hypot-def [=>]99.1% | \[ \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10}
\] |
Applied egg-rr99.0%
[Start]99.1% | \[ \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}
\] |
|---|---|
add-log-exp [=>]99.1% | \[ \color{blue}{\log \left(e^{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}}\right)}
\] |
div-inv [=>]98.5% | \[ \log \left(e^{\color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{1}{\log 10}}}\right)
\] |
exp-to-pow [=>]98.5% | \[ \log \color{blue}{\left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{1}{\log 10}\right)}\right)}
\] |
frac-2neg [=>]98.5% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left(\frac{-1}{-\log 10}\right)}}\right)
\] |
metadata-eval [=>]98.5% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{\color{blue}{-1}}{-\log 10}\right)}\right)
\] |
neg-log [=>]99.0% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\color{blue}{\log \left(\frac{1}{10}\right)}}\right)}\right)
\] |
metadata-eval [=>]99.0% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\log \color{blue}{0.1}}\right)}\right)
\] |
Applied egg-rr99.7%
[Start]99.0% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\log 0.1}\right)}\right)
\] |
|---|---|
metadata-eval [<=]99.0% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{\color{blue}{-1}}{\log 0.1}\right)}\right)
\] |
metadata-eval [<=]99.0% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\log \color{blue}{\left(\frac{1}{10}\right)}}\right)}\right)
\] |
metadata-eval [<=]99.0% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\log \left(\frac{1}{\color{blue}{1 + 9}}\right)}\right)}\right)
\] |
neg-log [<=]98.5% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\color{blue}{-\log \left(1 + 9\right)}}\right)}\right)
\] |
log1p-udef [<=]98.5% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{-\color{blue}{\mathsf{log1p}\left(9\right)}}\right)}\right)
\] |
frac-2neg [<=]98.5% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left(\frac{1}{\mathsf{log1p}\left(9\right)}\right)}}\right)
\] |
log1p-expm1-u [=>]99.7% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\mathsf{log1p}\left(9\right)}\right)\right)\right)}}\right)
\] |
log1p-udef [=>]99.7% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\color{blue}{\log \left(1 + 9\right)}}\right)\right)\right)}\right)
\] |
metadata-eval [=>]99.7% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\log \color{blue}{10}}\right)\right)\right)}\right)
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 38720 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 19456 |
| Alternative 3 | |
|---|---|
| Accuracy | 44.1% |
| Cost | 13252 |
| Alternative 4 | |
|---|---|
| Accuracy | 3.0% |
| Cost | 12992 |
| Alternative 5 | |
|---|---|
| Accuracy | 27.1% |
| Cost | 12992 |
herbie shell --seed 2023178
(FPCore (re im)
:name "math.log10 on complex, real part"
:precision binary64
(/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))