| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 38720 |
\[\log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left({\left({\log 10}^{-0.5}\right)}^{2}\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) (pow (pow (log 10.0) -0.5) 2.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), pow(pow(log(10.0), -0.5), 2.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.pow(Math.pow(Math.log(10.0), -0.5), 2.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.pow(math.pow(math.log(10.0), -0.5), 2.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) ^ ((log(10.0) ^ -0.5) ^ 2.0))) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))) / log(10.0); end
function tmp = code(re, im) tmp = log((hypot(re, im) ^ ((log(10.0) ^ -0.5) ^ 2.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[Power[N[Power[N[Log[10.0], $MachinePrecision], -0.5], $MachinePrecision], 2.0], $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({\left({\log 10}^{-0.5}\right)}^{2}\right)}\right)
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 52.9%
Simplified99.1%
[Start]52.9% | \[ \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.0% | \[ \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.8%
[Start]99.0% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\log 0.1}\right)}\right)
\] |
|---|---|
frac-2neg [=>]99.0% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\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)
\] |
neg-log [=>]98.5% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{1}{\color{blue}{\log \left(\frac{1}{0.1}\right)}}\right)}\right)
\] |
metadata-eval [=>]98.5% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{1}{\log \color{blue}{10}}\right)}\right)
\] |
add-sqr-sqrt [=>]98.5% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{1}{\color{blue}{\sqrt{\log 10} \cdot \sqrt{\log 10}}}\right)}\right)
\] |
associate-/r* [=>]99.8% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left(\frac{\frac{1}{\sqrt{\log 10}}}{\sqrt{\log 10}}\right)}}\right)
\] |
un-div-inv [<=]99.8% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left(\frac{1}{\sqrt{\log 10}} \cdot \frac{1}{\sqrt{\log 10}}\right)}}\right)
\] |
pow2 [=>]99.8% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left({\left(\frac{1}{\sqrt{\log 10}}\right)}^{2}\right)}}\right)
\] |
inv-pow [=>]99.8% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left({\color{blue}{\left({\left(\sqrt{\log 10}\right)}^{-1}\right)}}^{2}\right)}\right)
\] |
sqrt-pow2 [=>]99.8% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left({\color{blue}{\left({\log 10}^{\left(\frac{-1}{2}\right)}\right)}}^{2}\right)}\right)
\] |
metadata-eval [=>]99.8% | \[ \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left({\left({\log 10}^{\color{blue}{-0.5}}\right)}^{2}\right)}\right)
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 38720 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 19456 |
| Alternative 3 | |
|---|---|
| Accuracy | 43.8% |
| Cost | 13188 |
| Alternative 4 | |
|---|---|
| Accuracy | 43.8% |
| Cost | 13188 |
| Alternative 5 | |
|---|---|
| Accuracy | 3.1% |
| Cost | 12992 |
| Alternative 6 | |
|---|---|
| Accuracy | 26.6% |
| Cost | 12992 |
herbie shell --seed 2023272
(FPCore (re im)
:name "math.log10 on complex, real part"
:precision binary64
(/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))