math.log10 on complex, real part

?

Percentage Accurate: 51.7% → 99.6%
Time: 13.0s
Precision: binary64
Cost: 32320

?

\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
\[\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \sqrt[3]{{\left(\mathsf{log1p}\left(9\right)\right)}^{-3}} \]
(FPCore (re im)
 :precision binary64
 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
(FPCore (re im)
 :precision binary64
 (* (log (hypot re im)) (cbrt (pow (log1p 9.0) -3.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(hypot(re, im)) * cbrt(pow(log1p(9.0), -3.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.hypot(re, im)) * Math.cbrt(Math.pow(Math.log1p(9.0), -3.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 Float64(log(hypot(re, im)) * cbrt((log1p(9.0) ^ -3.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[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] * N[Power[N[Power[N[Log[1 + 9.0], $MachinePrecision], -3.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \sqrt[3]{{\left(\mathsf{log1p}\left(9\right)\right)}^{-3}}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 17 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 53.1%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Simplified99.1%

    \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}} \]
  3. Applied egg-rr99.0%

    \[\leadsto \color{blue}{\sqrt[3]{\frac{{\log \left(\mathsf{hypot}\left(re, im\right)\right)}^{3}}{{\log 10}^{3}}}} \]
  4. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \sqrt[3]{{\left(\mathsf{log1p}\left(9\right)\right)}^{-3}}} \]
  5. Final simplification99.5%

    \[\leadsto \log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \sqrt[3]{{\left(\mathsf{log1p}\left(9\right)\right)}^{-3}} \]

Alternatives

Alternative 1
Accuracy99.1%
Cost19968
\[\left(\left(\left(\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10} + 3\right) + -1\right) + -1\right) + -1 \]
Alternative 2
Accuracy99.1%
Cost19840
\[\left(\left(\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10} + 2\right) + -1\right) + -1 \]
Alternative 3
Accuracy99.1%
Cost19712
\[\left(\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10} + 1\right) + -1 \]
Alternative 4
Accuracy99.1%
Cost19456
\[\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10} \]
Alternative 5
Accuracy44.5%
Cost13772
\[\begin{array}{l} t_0 := \log \left(\frac{-1}{re}\right)\\ \mathbf{if}\;re \leq -5.5 \cdot 10^{-44}:\\ \;\;\;\;\left(1 - \frac{t_0}{\log 10}\right) + -1\\ \mathbf{elif}\;re \leq -1.15 \cdot 10^{-69}:\\ \;\;\;\;\frac{1}{\log 0.1 \cdot \frac{-1}{\log im}}\\ \mathbf{elif}\;re \leq -7 \cdot 10^{-133}:\\ \;\;\;\;\frac{-1}{\frac{\log 10}{t_0}}\\ \mathbf{else}:\\ \;\;\;\;\left(\left(2 + \frac{\log im}{\log 10}\right) + -1\right) + -1\\ \end{array} \]
Alternative 6
Accuracy44.6%
Cost13644
\[\begin{array}{l} t_0 := \log \left(\frac{-1}{re}\right)\\ \mathbf{if}\;re \leq -1.65 \cdot 10^{-45}:\\ \;\;\;\;\frac{-t_0}{\log 10}\\ \mathbf{elif}\;re \leq -6.5 \cdot 10^{-70}:\\ \;\;\;\;\frac{-\log im}{\log 0.1}\\ \mathbf{elif}\;re \leq -6.8 \cdot 10^{-133}:\\ \;\;\;\;\frac{-1}{\frac{\log 10}{t_0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\log \left(\frac{1}{im}\right)}{\log 10}\\ \end{array} \]
Alternative 7
Accuracy44.6%
Cost13644
\[\begin{array}{l} t_0 := \log \left(\frac{-1}{re}\right)\\ \mathbf{if}\;re \leq -1.2 \cdot 10^{-45}:\\ \;\;\;\;\frac{-t_0}{\log 10}\\ \mathbf{elif}\;re \leq -6 \cdot 10^{-71}:\\ \;\;\;\;\frac{1}{\log 0.1 \cdot \frac{-1}{\log im}}\\ \mathbf{elif}\;re \leq -6.6 \cdot 10^{-133}:\\ \;\;\;\;\frac{-1}{\frac{\log 10}{t_0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\log \left(\frac{1}{im}\right)}{\log 10}\\ \end{array} \]
Alternative 8
Accuracy44.6%
Cost13644
\[\begin{array}{l} t_0 := \log \left(\frac{-1}{re}\right)\\ \mathbf{if}\;re \leq -5.6 \cdot 10^{-46}:\\ \;\;\;\;\left(1 - \frac{t_0}{\log 10}\right) + -1\\ \mathbf{elif}\;re \leq -1.95 \cdot 10^{-70}:\\ \;\;\;\;\frac{1}{\log 0.1 \cdot \frac{-1}{\log im}}\\ \mathbf{elif}\;re \leq -3.8 \cdot 10^{-133}:\\ \;\;\;\;\frac{-1}{\frac{\log 10}{t_0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\log \left(\frac{1}{im}\right)}{\log 10}\\ \end{array} \]
Alternative 9
Accuracy44.6%
Cost13580
\[\begin{array}{l} \mathbf{if}\;re \leq -4.4 \cdot 10^{-43}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log 10}\\ \mathbf{elif}\;re \leq -4.8 \cdot 10^{-71}:\\ \;\;\;\;\frac{-\log im}{\log 0.1}\\ \mathbf{elif}\;re \leq -2.3 \cdot 10^{-133}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\log \left(\frac{1}{im}\right)}{\log 10}\\ \end{array} \]
Alternative 10
Accuracy44.5%
Cost13453
\[\begin{array}{l} \mathbf{if}\;re \leq -5 \cdot 10^{-43} \lor \neg \left(re \leq -2.2 \cdot 10^{-70}\right) \land re \leq -7 \cdot 10^{-133}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \end{array} \]
Alternative 11
Accuracy44.5%
Cost13452
\[\begin{array}{l} t_0 := \frac{\log \left(-re\right)}{\log 10}\\ \mathbf{if}\;re \leq -3.6 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -1.9 \cdot 10^{-70}:\\ \;\;\;\;\frac{-\log im}{\log 0.1}\\ \mathbf{elif}\;re \leq -7 \cdot 10^{-133}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \end{array} \]
Alternative 12
Accuracy44.6%
Cost13452
\[\begin{array}{l} \mathbf{if}\;re \leq -2.4 \cdot 10^{-46}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log 10}\\ \mathbf{elif}\;re \leq -5.1 \cdot 10^{-71}:\\ \;\;\;\;\frac{-\log im}{\log 0.1}\\ \mathbf{elif}\;re \leq -7 \cdot 10^{-133}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \end{array} \]
Alternative 13
Accuracy2.9%
Cost12992
\[\frac{\log im}{\log 0.1} \]
Alternative 14
Accuracy27.7%
Cost12992
\[\frac{\log im}{\log 10} \]
Alternative 15
Accuracy3.1%
Cost320
\[\frac{1}{\frac{1}{0}} \]
Alternative 16
Accuracy2.5%
Cost192
\[\frac{1}{0} \]

Reproduce?

herbie shell --seed 2023161 
(FPCore (re im)
  :name "math.log10 on complex, real part"
  :precision binary64
  (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))