math.log10 on complex, real part

Percentage Accurate: 51.2% → 99.1%
Time: 4.3s
Alternatives: 6
Speedup: 0.8×

Specification

?
\[\begin{array}{l} \\ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \end{array} \]
(FPCore (re im)
 :precision binary64
 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
double code(double re, double im) {
	return log(sqrt(((re * re) + (im * im)))) / log(10.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)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = log(sqrt(((re * re) + (im * im)))) / log(10.0d0)
end function
public static double code(double re, double im) {
	return Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(10.0);
}
def code(re, im):
	return math.log(math.sqrt(((re * re) + (im * im)))) / math.log(10.0)
function code(re, im)
	return Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(10.0))
end
function tmp = code(re, im)
	tmp = log(sqrt(((re * re) + (im * im)))) / 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]
\begin{array}{l}

\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\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 6 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.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \end{array} \]
(FPCore (re im)
 :precision binary64
 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
double code(double re, double im) {
	return log(sqrt(((re * re) + (im * im)))) / log(10.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)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = log(sqrt(((re * re) + (im * im)))) / log(10.0d0)
end function
public static double code(double re, double im) {
	return Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(10.0);
}
def code(re, im):
	return math.log(math.sqrt(((re * re) + (im * im)))) / math.log(10.0)
function code(re, im)
	return Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(10.0))
end
function tmp = code(re, im)
	tmp = log(sqrt(((re * re) + (im * im)))) / 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]
\begin{array}{l}

\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\end{array}

Alternative 1: 99.1% accurate, 0.8× speedup?

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

\\
\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}
\end{array}
Derivation
  1. Initial program 50.4%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-sqrt.f64N/A

      \[\leadsto \frac{\log \color{blue}{\left(\sqrt{re \cdot re + im \cdot im}\right)}}{\log 10} \]
    2. lift-+.f64N/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)}{\log 10} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + im \cdot im}\right)}{\log 10} \]
    4. lift-*.f64N/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    5. lower-hypot.f6499.1

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  4. Applied rewrites99.1%

    \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  5. Add Preprocessing

Alternative 2: 26.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\log \left(\mathsf{fma}\left(re \cdot \frac{re}{im}, 0.5, im\right)\right)}{\log 10} \end{array} \]
(FPCore (re im)
 :precision binary64
 (/ (log (fma (* re (/ re im)) 0.5 im)) (log 10.0)))
double code(double re, double im) {
	return log(fma((re * (re / im)), 0.5, im)) / log(10.0);
}
function code(re, im)
	return Float64(log(fma(Float64(re * Float64(re / im)), 0.5, im)) / log(10.0))
end
code[re_, im_] := N[(N[Log[N[(N[(re * N[(re / im), $MachinePrecision]), $MachinePrecision] * 0.5 + im), $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\log \left(\mathsf{fma}\left(re \cdot \frac{re}{im}, 0.5, im\right)\right)}{\log 10}
\end{array}
Derivation
  1. Initial program 50.4%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-sqrt.f64N/A

      \[\leadsto \frac{\log \color{blue}{\left(\sqrt{re \cdot re + im \cdot im}\right)}}{\log 10} \]
    2. lift-+.f64N/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)}{\log 10} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + im \cdot im}\right)}{\log 10} \]
    4. lift-*.f64N/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    5. lower-hypot.f6499.1

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  4. Applied rewrites99.1%

    \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  5. Taylor expanded in re around 0

    \[\leadsto \frac{\log \color{blue}{\left(im + \frac{1}{2} \cdot \frac{{re}^{2}}{im}\right)}}{\log 10} \]
  6. Step-by-step derivation
    1. Applied rewrites29.8%

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{fma}\left(re \cdot \frac{re}{im}, 0.5, im\right)\right)}}{\log 10} \]
    2. Final simplification29.8%

      \[\leadsto \frac{\log \left(\mathsf{fma}\left(re \cdot \frac{re}{im}, 0.5, im\right)\right)}{\log 10} \]
    3. Add Preprocessing

    Alternative 3: 26.3% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \frac{\log im}{\log 10} \end{array} \]
    (FPCore (re im) :precision binary64 (/ (log im) (log 10.0)))
    double code(double re, double im) {
    	return log(im) / log(10.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)
    use fmin_fmax_functions
        real(8), intent (in) :: re
        real(8), intent (in) :: im
        code = log(im) / log(10.0d0)
    end function
    
    public static double code(double re, double im) {
    	return Math.log(im) / Math.log(10.0);
    }
    
    def code(re, im):
    	return math.log(im) / math.log(10.0)
    
    function code(re, im)
    	return Float64(log(im) / log(10.0))
    end
    
    function tmp = code(re, im)
    	tmp = log(im) / log(10.0);
    end
    
    code[re_, im_] := N[(N[Log[im], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{\log im}{\log 10}
    \end{array}
    
    Derivation
    1. Initial program 50.4%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \frac{\log \color{blue}{im}}{\log 10} \]
    4. Step-by-step derivation
      1. Applied rewrites30.0%

        \[\leadsto \frac{\log \color{blue}{im}}{\log 10} \]
      2. Add Preprocessing

      Alternative 4: 3.3% accurate, 1.6× speedup?

      \[\begin{array}{l} \\ \frac{\frac{0.5}{im} \cdot \left(re \cdot \frac{re}{im}\right)}{\log 10} \end{array} \]
      (FPCore (re im)
       :precision binary64
       (/ (* (/ 0.5 im) (* re (/ re im))) (log 10.0)))
      double code(double re, double im) {
      	return ((0.5 / im) * (re * (re / im))) / log(10.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)
      use fmin_fmax_functions
          real(8), intent (in) :: re
          real(8), intent (in) :: im
          code = ((0.5d0 / im) * (re * (re / im))) / log(10.0d0)
      end function
      
      public static double code(double re, double im) {
      	return ((0.5 / im) * (re * (re / im))) / Math.log(10.0);
      }
      
      def code(re, im):
      	return ((0.5 / im) * (re * (re / im))) / math.log(10.0)
      
      function code(re, im)
      	return Float64(Float64(Float64(0.5 / im) * Float64(re * Float64(re / im))) / log(10.0))
      end
      
      function tmp = code(re, im)
      	tmp = ((0.5 / im) * (re * (re / im))) / log(10.0);
      end
      
      code[re_, im_] := N[(N[(N[(0.5 / im), $MachinePrecision] * N[(re * N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{\frac{0.5}{im} \cdot \left(re \cdot \frac{re}{im}\right)}{\log 10}
      \end{array}
      
      Derivation
      1. Initial program 50.4%

        \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
      2. Add Preprocessing
      3. Taylor expanded in re around 0

        \[\leadsto \frac{\color{blue}{\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}}}{\log 10} \]
      4. Step-by-step derivation
        1. Applied rewrites26.8%

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{0.5}{im}, \frac{re \cdot re}{im}, \log im\right)}}{\log 10} \]
        2. Taylor expanded in re around inf

          \[\leadsto \frac{\frac{1}{2} \cdot \color{blue}{\frac{{re}^{2}}{{im}^{2}}}}{\log 10} \]
        3. Step-by-step derivation
          1. Applied rewrites3.5%

            \[\leadsto \frac{\frac{0.5}{im} \cdot \color{blue}{\left(re \cdot \frac{re}{im}\right)}}{\log 10} \]
          2. Add Preprocessing

          Alternative 5: 3.4% accurate, 1.6× speedup?

          \[\begin{array}{l} \\ \frac{\left(\frac{re}{im} \cdot 0.5\right) \cdot \frac{re}{im}}{\log 10} \end{array} \]
          (FPCore (re im)
           :precision binary64
           (/ (* (* (/ re im) 0.5) (/ re im)) (log 10.0)))
          double code(double re, double im) {
          	return (((re / im) * 0.5) * (re / im)) / log(10.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)
          use fmin_fmax_functions
              real(8), intent (in) :: re
              real(8), intent (in) :: im
              code = (((re / im) * 0.5d0) * (re / im)) / log(10.0d0)
          end function
          
          public static double code(double re, double im) {
          	return (((re / im) * 0.5) * (re / im)) / Math.log(10.0);
          }
          
          def code(re, im):
          	return (((re / im) * 0.5) * (re / im)) / math.log(10.0)
          
          function code(re, im)
          	return Float64(Float64(Float64(Float64(re / im) * 0.5) * Float64(re / im)) / log(10.0))
          end
          
          function tmp = code(re, im)
          	tmp = (((re / im) * 0.5) * (re / im)) / log(10.0);
          end
          
          code[re_, im_] := N[(N[(N[(N[(re / im), $MachinePrecision] * 0.5), $MachinePrecision] * N[(re / im), $MachinePrecision]), $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \frac{\left(\frac{re}{im} \cdot 0.5\right) \cdot \frac{re}{im}}{\log 10}
          \end{array}
          
          Derivation
          1. Initial program 50.4%

            \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
          2. Add Preprocessing
          3. Taylor expanded in re around 0

            \[\leadsto \frac{\color{blue}{\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}}}{\log 10} \]
          4. Step-by-step derivation
            1. Applied rewrites26.8%

              \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{0.5}{im}, \frac{re \cdot re}{im}, \log im\right)}}{\log 10} \]
            2. Taylor expanded in re around inf

              \[\leadsto \frac{\frac{1}{2} \cdot \color{blue}{\frac{{re}^{2}}{{im}^{2}}}}{\log 10} \]
            3. Step-by-step derivation
              1. Applied rewrites3.5%

                \[\leadsto \frac{\frac{0.5}{im} \cdot \color{blue}{\left(re \cdot \frac{re}{im}\right)}}{\log 10} \]
              2. Step-by-step derivation
                1. Applied rewrites2.8%

                  \[\leadsto \frac{\frac{\left(re \cdot re\right) \cdot 0.5}{im \cdot \color{blue}{im}}}{\log 10} \]
                2. Step-by-step derivation
                  1. Applied rewrites3.6%

                    \[\leadsto \frac{\left(\frac{re}{im} \cdot 0.5\right) \cdot \color{blue}{\frac{re}{im}}}{\log 10} \]
                  2. Add Preprocessing

                  Alternative 6: 2.8% accurate, 1.7× speedup?

                  \[\begin{array}{l} \\ \frac{\frac{\left(re \cdot re\right) \cdot 0.5}{im \cdot im}}{\log 10} \end{array} \]
                  (FPCore (re im)
                   :precision binary64
                   (/ (/ (* (* re re) 0.5) (* im im)) (log 10.0)))
                  double code(double re, double im) {
                  	return (((re * re) * 0.5) / (im * im)) / log(10.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)
                  use fmin_fmax_functions
                      real(8), intent (in) :: re
                      real(8), intent (in) :: im
                      code = (((re * re) * 0.5d0) / (im * im)) / log(10.0d0)
                  end function
                  
                  public static double code(double re, double im) {
                  	return (((re * re) * 0.5) / (im * im)) / Math.log(10.0);
                  }
                  
                  def code(re, im):
                  	return (((re * re) * 0.5) / (im * im)) / math.log(10.0)
                  
                  function code(re, im)
                  	return Float64(Float64(Float64(Float64(re * re) * 0.5) / Float64(im * im)) / log(10.0))
                  end
                  
                  function tmp = code(re, im)
                  	tmp = (((re * re) * 0.5) / (im * im)) / log(10.0);
                  end
                  
                  code[re_, im_] := N[(N[(N[(N[(re * re), $MachinePrecision] * 0.5), $MachinePrecision] / N[(im * im), $MachinePrecision]), $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
                  
                  \begin{array}{l}
                  
                  \\
                  \frac{\frac{\left(re \cdot re\right) \cdot 0.5}{im \cdot im}}{\log 10}
                  \end{array}
                  
                  Derivation
                  1. Initial program 50.4%

                    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
                  2. Add Preprocessing
                  3. Taylor expanded in re around 0

                    \[\leadsto \frac{\color{blue}{\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}}}{\log 10} \]
                  4. Step-by-step derivation
                    1. Applied rewrites26.8%

                      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{0.5}{im}, \frac{re \cdot re}{im}, \log im\right)}}{\log 10} \]
                    2. Taylor expanded in re around inf

                      \[\leadsto \frac{\frac{1}{2} \cdot \color{blue}{\frac{{re}^{2}}{{im}^{2}}}}{\log 10} \]
                    3. Step-by-step derivation
                      1. Applied rewrites3.5%

                        \[\leadsto \frac{\frac{0.5}{im} \cdot \color{blue}{\left(re \cdot \frac{re}{im}\right)}}{\log 10} \]
                      2. Step-by-step derivation
                        1. Applied rewrites2.8%

                          \[\leadsto \frac{\frac{\left(re \cdot re\right) \cdot 0.5}{im \cdot \color{blue}{im}}}{\log 10} \]
                        2. Add Preprocessing

                        Reproduce

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