math.log/2 on complex, real part

Percentage Accurate: 51.0% → 99.2%
Time: 4.6s
Alternatives: 3
Speedup: 1.4×

Specification

?
\[\begin{array}{l} \\ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \end{array} \]
(FPCore (re im base)
 :precision binary64
 (/
  (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0))
  (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
	return ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(re, im, base)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    code = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
	return ((Math.log(Math.sqrt(((re * re) + (im * im)))) * Math.log(base)) + (Math.atan2(im, re) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base):
	return ((math.log(math.sqrt(((re * re) + (im * im)))) * math.log(base)) + (math.atan2(im, re) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base)
	return Float64(Float64(Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * log(base)) + Float64(atan(im, re) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0)))
end
function tmp = code(re, im, base)
	tmp = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
end
code[re_, im_, base_] := N[(N[(N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(N[ArcTan[im / re], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(0.0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\end{array}

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 3 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: 51.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \end{array} \]
(FPCore (re im base)
 :precision binary64
 (/
  (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0))
  (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
	return ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(re, im, base)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    code = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
	return ((Math.log(Math.sqrt(((re * re) + (im * im)))) * Math.log(base)) + (Math.atan2(im, re) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base):
	return ((math.log(math.sqrt(((re * re) + (im * im)))) * math.log(base)) + (math.atan2(im, re) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base)
	return Float64(Float64(Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * log(base)) + Float64(atan(im, re) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0)))
end
function tmp = code(re, im, base)
	tmp = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
end
code[re_, im_, base_] := N[(N[(N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(N[ArcTan[im / re], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(0.0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\end{array}

Alternative 1: 99.2% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{\log base}{\frac{1}{\log base}}} \end{array} \]
(FPCore (re im base)
 :precision binary64
 (/
  (+ (* (log (hypot re im)) (log base)) 0.0)
  (/ (log base) (/ 1.0 (log base)))))
double code(double re, double im, double base) {
	return ((log(hypot(re, im)) * log(base)) + 0.0) / (log(base) / (1.0 / log(base)));
}
public static double code(double re, double im, double base) {
	return ((Math.log(Math.hypot(re, im)) * Math.log(base)) + 0.0) / (Math.log(base) / (1.0 / Math.log(base)));
}
def code(re, im, base):
	return ((math.log(math.hypot(re, im)) * math.log(base)) + 0.0) / (math.log(base) / (1.0 / math.log(base)))
function code(re, im, base)
	return Float64(Float64(Float64(log(hypot(re, im)) * log(base)) + 0.0) / Float64(log(base) / Float64(1.0 / log(base))))
end
function tmp = code(re, im, base)
	tmp = ((log(hypot(re, im)) * log(base)) + 0.0) / (log(base) / (1.0 / log(base)));
end
code[re_, im_, base_] := N[(N[(N[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision] / N[(N[Log[base], $MachinePrecision] / N[(1.0 / N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{\log base}{\frac{1}{\log base}}}
\end{array}
Derivation
  1. Initial program 51.0%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  2. Step-by-step derivation
    1. lift-sqrt.f64N/A

      \[\leadsto \frac{\log \color{blue}{\left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. lift-*.f64N/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    4. lift-+.f64N/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    5. lower-hypot.f6499.2

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  3. Applied rewrites99.2%

    \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  4. Taylor expanded in re around 0

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
  5. Step-by-step derivation
    1. Applied rewrites99.2%

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0 \cdot 0}} \]
      2. metadata-eval99.2

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0}} \]
      3. lift-+.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base + 0}} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base} + 0} \]
      5. lift-log.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base} \cdot \log base + 0} \]
      6. lift-log.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \color{blue}{\log base} + 0} \]
      7. pow2N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{{\log base}^{2}} + 0} \]
      8. +-rgt-identityN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{{\log base}^{2}}} \]
      9. pow2N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base}} \]
      10. lift-log.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base} \cdot \log base} \]
      11. lift-log.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \color{blue}{\log base}} \]
      12. lift-*.f6499.2

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base}} \]
    3. Applied rewrites99.2%

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base}} \]
    4. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base}} \]
      2. lift-log.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base} \cdot \log base} \]
      3. lift-log.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \color{blue}{\log base}} \]
      4. pow2N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{{\log base}^{2}}} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{{\log base}^{\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)}}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{{\log base}^{\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(2\right)\right)}\right)\right)}} \]
      7. pow-flipN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\frac{1}{{\log base}^{\left(\mathsf{neg}\left(2\right)\right)}}}} \]
      8. pow-flipN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{1}{\color{blue}{\frac{1}{{\log base}^{2}}}}} \]
      9. metadata-evalN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{1}{\frac{\color{blue}{1 \cdot 1}}{{\log base}^{2}}}} \]
      10. pow2N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{1}{\frac{1 \cdot 1}{\color{blue}{\log base \cdot \log base}}}} \]
      11. frac-timesN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{1}{\color{blue}{\frac{1}{\log base} \cdot \frac{1}{\log base}}}} \]
      12. associate-/r*N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\frac{\frac{1}{\frac{1}{\log base}}}{\frac{1}{\log base}}}} \]
      13. inv-powN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{\frac{1}{\color{blue}{{\log base}^{-1}}}}{\frac{1}{\log base}}} \]
      14. pow-flipN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{\color{blue}{{\log base}^{\left(\mathsf{neg}\left(-1\right)\right)}}}{\frac{1}{\log base}}} \]
      15. metadata-evalN/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{{\log base}^{\color{blue}{1}}}{\frac{1}{\log base}}} \]
      16. unpow1N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{\color{blue}{\log base}}{\frac{1}{\log base}}} \]
      17. lower-/.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\frac{\log base}{\frac{1}{\log base}}}} \]
      18. lift-log.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{\color{blue}{\log base}}{\frac{1}{\log base}}} \]
      19. lift-log.f64N/A

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{\log base}{\frac{1}{\color{blue}{\log base}}}} \]
      20. lift-/.f6499.2

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\frac{\log base}{\color{blue}{\frac{1}{\log base}}}} \]
    5. Applied rewrites99.2%

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\frac{\log base}{\frac{1}{\log base}}}} \]
    6. Add Preprocessing

    Alternative 2: 99.2% accurate, 1.4× speedup?

    \[\begin{array}{l} \\ \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base} \end{array} \]
    (FPCore (re im base)
     :precision binary64
     (/ (+ (* (log (hypot re im)) (log base)) 0.0) (* (log base) (log base))))
    double code(double re, double im, double base) {
    	return ((log(hypot(re, im)) * log(base)) + 0.0) / (log(base) * log(base));
    }
    
    public static double code(double re, double im, double base) {
    	return ((Math.log(Math.hypot(re, im)) * Math.log(base)) + 0.0) / (Math.log(base) * Math.log(base));
    }
    
    def code(re, im, base):
    	return ((math.log(math.hypot(re, im)) * math.log(base)) + 0.0) / (math.log(base) * math.log(base))
    
    function code(re, im, base)
    	return Float64(Float64(Float64(log(hypot(re, im)) * log(base)) + 0.0) / Float64(log(base) * log(base)))
    end
    
    function tmp = code(re, im, base)
    	tmp = ((log(hypot(re, im)) * log(base)) + 0.0) / (log(base) * log(base));
    end
    
    code[re_, im_, base_] := N[(N[(N[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision] / N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base}
    \end{array}
    
    Derivation
    1. Initial program 51.0%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. lift-sqrt.f64N/A

        \[\leadsto \frac{\log \color{blue}{\left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
      4. lift-+.f64N/A

        \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
      5. lower-hypot.f6499.2

        \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    3. Applied rewrites99.2%

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    4. Taylor expanded in re around 0

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
    5. Step-by-step derivation
      1. Applied rewrites99.2%

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0 \cdot 0}} \]
        2. metadata-eval99.2

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0}} \]
        3. lift-+.f64N/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base + 0}} \]
        4. lift-*.f64N/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base} + 0} \]
        5. lift-log.f64N/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base} \cdot \log base + 0} \]
        6. lift-log.f64N/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \color{blue}{\log base} + 0} \]
        7. pow2N/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{{\log base}^{2}} + 0} \]
        8. +-rgt-identityN/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{{\log base}^{2}}} \]
        9. pow2N/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base}} \]
        10. lift-log.f64N/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base} \cdot \log base} \]
        11. lift-log.f64N/A

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\log base \cdot \color{blue}{\log base}} \]
        12. lift-*.f6499.2

          \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base}} \]
      3. Applied rewrites99.2%

        \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \log base + 0}{\color{blue}{\log base \cdot \log base}} \]
      4. Add Preprocessing

      Alternative 3: 26.8% accurate, 4.4× speedup?

      \[\begin{array}{l} \\ \frac{\log im}{\log base} \end{array} \]
      (FPCore (re im base) :precision binary64 (/ (log im) (log base)))
      double code(double re, double im, double base) {
      	return log(im) / log(base);
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(re, im, base)
      use fmin_fmax_functions
          real(8), intent (in) :: re
          real(8), intent (in) :: im
          real(8), intent (in) :: base
          code = log(im) / log(base)
      end function
      
      public static double code(double re, double im, double base) {
      	return Math.log(im) / Math.log(base);
      }
      
      def code(re, im, base):
      	return math.log(im) / math.log(base)
      
      function code(re, im, base)
      	return Float64(log(im) / log(base))
      end
      
      function tmp = code(re, im, base)
      	tmp = log(im) / log(base);
      end
      
      code[re_, im_, base_] := N[(N[Log[im], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{\log im}{\log base}
      \end{array}
      
      Derivation
      1. Initial program 51.0%

        \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
      2. Taylor expanded in re around 0

        \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
      3. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \frac{\log im}{\color{blue}{\log base}} \]
        2. lower-log.f64N/A

          \[\leadsto \frac{\log im}{\log \color{blue}{base}} \]
        3. lift-log.f6426.8

          \[\leadsto \frac{\log im}{\log base} \]
      4. Applied rewrites26.8%

        \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
      5. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 2025116 
      (FPCore (re im base)
        :name "math.log/2 on complex, real part"
        :precision binary64
        (/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))