math.log10 on complex, real part

?

Percentage Accurate: 51.3% → 99.7%
Time: 8.2s
Precision: binary64
Cost: 38720

?

\[\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) \]
(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)

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 5 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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 50.4%

    \[\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}} \]
    Step-by-step derivation

    [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} \]
  3. Applied egg-rr99.0%

    \[\leadsto \color{blue}{\log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\log 0.1}\right)}\right)} \]
    Step-by-step derivation

    [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) \]
  4. Applied egg-rr99.7%

    \[\leadsto \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\log 10}\right)\right)\right)}}\right) \]
    Step-by-step derivation

    [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) \]
  5. Final simplification99.7%

    \[\leadsto \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) \]

Alternatives

Alternative 1
Accuracy99.7%
Cost38720
\[\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) \]
Alternative 2
Accuracy99.1%
Cost19456
\[\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10} \]
Alternative 3
Accuracy44.1%
Cost13252
\[\begin{array}{l} \mathbf{if}\;im \leq 8.8 \cdot 10^{-30}:\\ \;\;\;\;\frac{\log \left(\frac{-1}{re}\right)}{\log 0.1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log 10}\\ \end{array} \]
Alternative 4
Accuracy3.0%
Cost12992
\[\frac{\log im}{\log 0.1} \]
Alternative 5
Accuracy27.1%
Cost12992
\[\frac{\log im}{\log 10} \]

Reproduce?

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)))