math.log10 on complex, imaginary part

Percentage Accurate: 98.7% → 99.8%
Time: 4.3s
Alternatives: 2
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{\tan^{-1}_* \frac{im}{re}}{\log 10} \end{array} \]
(FPCore (re im) :precision binary64 (/ (atan2 im re) (log 10.0)))
double code(double re, double im) {
	return atan2(im, re) / log(10.0);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = atan2(im, re) / log(10.0d0)
end function
public static double code(double re, double im) {
	return Math.atan2(im, re) / Math.log(10.0);
}
def code(re, im):
	return math.atan2(im, re) / math.log(10.0)
function code(re, im)
	return Float64(atan(im, re) / log(10.0))
end
function tmp = code(re, im)
	tmp = atan2(im, re) / log(10.0);
end
code[re_, im_] := N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\tan^{-1}_* \frac{im}{re}}{\log 10}
\end{array}

Sampling outcomes in binary64 precision:

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.

Accuracy vs Speed?

Herbie found 2 alternatives:

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

Initial Program: 98.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\tan^{-1}_* \frac{im}{re}}{\log 10} \end{array} \]
(FPCore (re im) :precision binary64 (/ (atan2 im re) (log 10.0)))
double code(double re, double im) {
	return atan2(im, re) / log(10.0);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = atan2(im, re) / log(10.0d0)
end function
public static double code(double re, double im) {
	return Math.atan2(im, re) / Math.log(10.0);
}
def code(re, im):
	return math.atan2(im, re) / math.log(10.0)
function code(re, im)
	return Float64(atan(im, re) / log(10.0))
end
function tmp = code(re, im)
	tmp = atan2(im, re) / log(10.0);
end
code[re_, im_] := N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\tan^{-1}_* \frac{im}{re}}{\log 10}
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{-\tan^{-1}_* \frac{im}{re}}{\log 0.1} \end{array} \]
(FPCore (re im) :precision binary64 (/ (- (atan2 im re)) (log 0.1)))
double code(double re, double im) {
	return -atan2(im, re) / log(0.1);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = -atan2(im, re) / log(0.1d0)
end function
public static double code(double re, double im) {
	return -Math.atan2(im, re) / Math.log(0.1);
}
def code(re, im):
	return -math.atan2(im, re) / math.log(0.1)
function code(re, im)
	return Float64(Float64(-atan(im, re)) / log(0.1))
end
function tmp = code(re, im)
	tmp = -atan2(im, re) / log(0.1);
end
code[re_, im_] := N[((-N[ArcTan[im / re], $MachinePrecision]) / N[Log[0.1], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{-\tan^{-1}_* \frac{im}{re}}{\log 0.1}
\end{array}
Derivation
  1. Initial program 98.7%

    \[\frac{\tan^{-1}_* \frac{im}{re}}{\log 10} \]
  2. Step-by-step derivation
    1. frac-2neg98.7%

      \[\leadsto \color{blue}{\frac{-\tan^{-1}_* \frac{im}{re}}{-\log 10}} \]
    2. div-inv98.6%

      \[\leadsto \color{blue}{\left(-\tan^{-1}_* \frac{im}{re}\right) \cdot \frac{1}{-\log 10}} \]
    3. neg-log99.8%

      \[\leadsto \left(-\tan^{-1}_* \frac{im}{re}\right) \cdot \frac{1}{\color{blue}{\log \left(\frac{1}{10}\right)}} \]
    4. metadata-eval99.8%

      \[\leadsto \left(-\tan^{-1}_* \frac{im}{re}\right) \cdot \frac{1}{\log \color{blue}{0.1}} \]
  3. Applied egg-rr99.8%

    \[\leadsto \color{blue}{\left(-\tan^{-1}_* \frac{im}{re}\right) \cdot \frac{1}{\log 0.1}} \]
  4. Step-by-step derivation
    1. associate-*r/99.8%

      \[\leadsto \color{blue}{\frac{\left(-\tan^{-1}_* \frac{im}{re}\right) \cdot 1}{\log 0.1}} \]
    2. *-rgt-identity99.8%

      \[\leadsto \frac{\color{blue}{-\tan^{-1}_* \frac{im}{re}}}{\log 0.1} \]
  5. Simplified99.8%

    \[\leadsto \color{blue}{\frac{-\tan^{-1}_* \frac{im}{re}}{\log 0.1}} \]
  6. Final simplification99.8%

    \[\leadsto \frac{-\tan^{-1}_* \frac{im}{re}}{\log 0.1} \]

Alternative 2: 98.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\tan^{-1}_* \frac{im}{re}}{\log 10} \end{array} \]
(FPCore (re im) :precision binary64 (/ (atan2 im re) (log 10.0)))
double code(double re, double im) {
	return atan2(im, re) / log(10.0);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = atan2(im, re) / log(10.0d0)
end function
public static double code(double re, double im) {
	return Math.atan2(im, re) / Math.log(10.0);
}
def code(re, im):
	return math.atan2(im, re) / math.log(10.0)
function code(re, im)
	return Float64(atan(im, re) / log(10.0))
end
function tmp = code(re, im)
	tmp = atan2(im, re) / log(10.0);
end
code[re_, im_] := N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\tan^{-1}_* \frac{im}{re}}{\log 10}
\end{array}
Derivation
  1. Initial program 98.7%

    \[\frac{\tan^{-1}_* \frac{im}{re}}{\log 10} \]
  2. Final simplification98.7%

    \[\leadsto \frac{\tan^{-1}_* \frac{im}{re}}{\log 10} \]

Reproduce

?
herbie shell --seed 2023196 
(FPCore (re im)
  :name "math.log10 on complex, imaginary part"
  :precision binary64
  (/ (atan2 im re) (log 10.0)))