math.log10 on complex, real part

Percentage Accurate: 51.4% → 98.3%
Time: 4.4s
Alternatives: 3
Speedup: 1.1×

Specification

?
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
(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]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}

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.4% accurate, 1.0× speedup?

\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
(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]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}

Alternative 1: 98.3% accurate, 1.0× speedup?

\[\frac{1}{\frac{2.302585092994046}{\log \left(\mathsf{max}\left(\left|re\right|, \left|im\right|\right)\right)}} \]
(FPCore (re im)
  :precision binary64
  (/ 1.0 (/ 2.302585092994046 (log (fmax (fabs re) (fabs im))))))
double code(double re, double im) {
	return 1.0 / (2.302585092994046 / log(fmax(fabs(re), fabs(im))));
}
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 = 1.0d0 / (2.302585092994046d0 / log(fmax(abs(re), abs(im))))
end function
public static double code(double re, double im) {
	return 1.0 / (2.302585092994046 / Math.log(fmax(Math.abs(re), Math.abs(im))));
}
def code(re, im):
	return 1.0 / (2.302585092994046 / math.log(fmax(math.fabs(re), math.fabs(im))))
function code(re, im)
	return Float64(1.0 / Float64(2.302585092994046 / log(fmax(abs(re), abs(im)))))
end
function tmp = code(re, im)
	tmp = 1.0 / (2.302585092994046 / log(max(abs(re), abs(im))));
end
code[re_, im_] := N[(1.0 / N[(2.302585092994046 / N[Log[N[Max[N[Abs[re], $MachinePrecision], N[Abs[im], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\frac{2.302585092994046}{\log \left(\mathsf{max}\left(\left|re\right|, \left|im\right|\right)\right)}}
Derivation
  1. Initial program 51.4%

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

    \[\leadsto \frac{\color{blue}{-1 \cdot \log \left(\frac{1}{im}\right)}}{\log 10} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \frac{-1 \cdot \color{blue}{\log \left(\frac{1}{im}\right)}}{\log 10} \]
    2. lower-log.f64N/A

      \[\leadsto \frac{-1 \cdot \log \left(\frac{1}{im}\right)}{\log 10} \]
    3. lower-/.f6427.6%

      \[\leadsto \frac{-1 \cdot \log \left(\frac{1}{im}\right)}{\log 10} \]
  4. Applied rewrites27.6%

    \[\leadsto \frac{\color{blue}{-1 \cdot \log \left(\frac{1}{im}\right)}}{\log 10} \]
  5. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{-1 \cdot \log \left(\frac{1}{im}\right)}{\log 10}} \]
    2. div-flipN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{-1 \cdot \log \left(\frac{1}{im}\right)}}} \]
    3. lower-unsound-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{-1 \cdot \log \left(\frac{1}{im}\right)}}} \]
    4. lower-unsound-/.f6427.5%

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

      \[\leadsto \frac{1}{\frac{\log 10}{-1 \cdot \color{blue}{\log \left(\frac{1}{im}\right)}}} \]
    6. mul-1-negN/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}} \]
    7. lift-log.f64N/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}} \]
    8. lift-/.f64N/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}} \]
    9. log-recN/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\log im\right)\right)\right)}} \]
    10. remove-double-negN/A

      \[\leadsto \frac{1}{\frac{\log 10}{\log im}} \]
    11. lower-log.f6427.5%

      \[\leadsto \frac{1}{\frac{\log 10}{\log im}} \]
  6. Applied rewrites27.5%

    \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{\log im}}} \]
  7. Evaluated real constant27.5%

    \[\leadsto \frac{1}{\frac{\color{blue}{2.302585092994046}}{\log im}} \]
  8. Add Preprocessing

Alternative 2: 98.3% accurate, 1.1× speedup?

\[\frac{\log \left(\mathsf{max}\left(\left|re\right|, \left|im\right|\right)\right)}{2.302585092994046} \]
(FPCore (re im)
  :precision binary64
  (/ (log (fmax (fabs re) (fabs im))) 2.302585092994046))
double code(double re, double im) {
	return log(fmax(fabs(re), fabs(im))) / 2.302585092994046;
}
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(fmax(abs(re), abs(im))) / 2.302585092994046d0
end function
public static double code(double re, double im) {
	return Math.log(fmax(Math.abs(re), Math.abs(im))) / 2.302585092994046;
}
def code(re, im):
	return math.log(fmax(math.fabs(re), math.fabs(im))) / 2.302585092994046
function code(re, im)
	return Float64(log(fmax(abs(re), abs(im))) / 2.302585092994046)
end
function tmp = code(re, im)
	tmp = log(max(abs(re), abs(im))) / 2.302585092994046;
end
code[re_, im_] := N[(N[Log[N[Max[N[Abs[re], $MachinePrecision], N[Abs[im], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / 2.302585092994046), $MachinePrecision]
\frac{\log \left(\mathsf{max}\left(\left|re\right|, \left|im\right|\right)\right)}{2.302585092994046}
Derivation
  1. Initial program 51.4%

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

    \[\leadsto \frac{\color{blue}{-1 \cdot \log \left(\frac{1}{im}\right)}}{\log 10} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \frac{-1 \cdot \color{blue}{\log \left(\frac{1}{im}\right)}}{\log 10} \]
    2. lower-log.f64N/A

      \[\leadsto \frac{-1 \cdot \log \left(\frac{1}{im}\right)}{\log 10} \]
    3. lower-/.f6427.6%

      \[\leadsto \frac{-1 \cdot \log \left(\frac{1}{im}\right)}{\log 10} \]
  4. Applied rewrites27.6%

    \[\leadsto \frac{\color{blue}{-1 \cdot \log \left(\frac{1}{im}\right)}}{\log 10} \]
  5. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{-1 \cdot \log \left(\frac{1}{im}\right)}{\log 10}} \]
    2. div-flipN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{-1 \cdot \log \left(\frac{1}{im}\right)}}} \]
    3. lower-unsound-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{-1 \cdot \log \left(\frac{1}{im}\right)}}} \]
    4. lower-unsound-/.f6427.5%

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

      \[\leadsto \frac{1}{\frac{\log 10}{-1 \cdot \color{blue}{\log \left(\frac{1}{im}\right)}}} \]
    6. mul-1-negN/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}} \]
    7. lift-log.f64N/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}} \]
    8. lift-/.f64N/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}} \]
    9. log-recN/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\log im\right)\right)\right)}} \]
    10. remove-double-negN/A

      \[\leadsto \frac{1}{\frac{\log 10}{\log im}} \]
    11. lower-log.f6427.5%

      \[\leadsto \frac{1}{\frac{\log 10}{\log im}} \]
  6. Applied rewrites27.5%

    \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{\log im}}} \]
  7. Evaluated real constant27.5%

    \[\leadsto \frac{1}{\frac{\color{blue}{2.302585092994046}}{\log im}} \]
  8. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{2592480341699211}{1125899906842624}}{\log im}}} \]
    2. lift-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{2592480341699211}{1125899906842624}}{\log im}}} \]
    3. div-flip-revN/A

      \[\leadsto \color{blue}{\frac{\log im}{\frac{2592480341699211}{1125899906842624}}} \]
    4. lower-/.f6427.6%

      \[\leadsto \color{blue}{\frac{\log im}{2.302585092994046}} \]
  9. Applied rewrites27.6%

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

Alternative 3: 97.8% accurate, 1.1× speedup?

\[\log \left(\mathsf{max}\left(\left|re\right|, \left|im\right|\right)\right) \cdot 0.43429448190325176 \]
(FPCore (re im)
  :precision binary64
  (* (log (fmax (fabs re) (fabs im))) 0.43429448190325176))
double code(double re, double im) {
	return log(fmax(fabs(re), fabs(im))) * 0.43429448190325176;
}
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(fmax(abs(re), abs(im))) * 0.43429448190325176d0
end function
public static double code(double re, double im) {
	return Math.log(fmax(Math.abs(re), Math.abs(im))) * 0.43429448190325176;
}
def code(re, im):
	return math.log(fmax(math.fabs(re), math.fabs(im))) * 0.43429448190325176
function code(re, im)
	return Float64(log(fmax(abs(re), abs(im))) * 0.43429448190325176)
end
function tmp = code(re, im)
	tmp = log(max(abs(re), abs(im))) * 0.43429448190325176;
end
code[re_, im_] := N[(N[Log[N[Max[N[Abs[re], $MachinePrecision], N[Abs[im], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 0.43429448190325176), $MachinePrecision]
\log \left(\mathsf{max}\left(\left|re\right|, \left|im\right|\right)\right) \cdot 0.43429448190325176
Derivation
  1. Initial program 51.4%

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

    \[\leadsto \frac{\color{blue}{-1 \cdot \log \left(\frac{1}{im}\right)}}{\log 10} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \frac{-1 \cdot \color{blue}{\log \left(\frac{1}{im}\right)}}{\log 10} \]
    2. lower-log.f64N/A

      \[\leadsto \frac{-1 \cdot \log \left(\frac{1}{im}\right)}{\log 10} \]
    3. lower-/.f6427.6%

      \[\leadsto \frac{-1 \cdot \log \left(\frac{1}{im}\right)}{\log 10} \]
  4. Applied rewrites27.6%

    \[\leadsto \frac{\color{blue}{-1 \cdot \log \left(\frac{1}{im}\right)}}{\log 10} \]
  5. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{-1 \cdot \log \left(\frac{1}{im}\right)}{\log 10}} \]
    2. div-flipN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{-1 \cdot \log \left(\frac{1}{im}\right)}}} \]
    3. lower-unsound-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{-1 \cdot \log \left(\frac{1}{im}\right)}}} \]
    4. lower-unsound-/.f6427.5%

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

      \[\leadsto \frac{1}{\frac{\log 10}{-1 \cdot \color{blue}{\log \left(\frac{1}{im}\right)}}} \]
    6. mul-1-negN/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}} \]
    7. lift-log.f64N/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}} \]
    8. lift-/.f64N/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}} \]
    9. log-recN/A

      \[\leadsto \frac{1}{\frac{\log 10}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\log im\right)\right)\right)}} \]
    10. remove-double-negN/A

      \[\leadsto \frac{1}{\frac{\log 10}{\log im}} \]
    11. lower-log.f6427.5%

      \[\leadsto \frac{1}{\frac{\log 10}{\log im}} \]
  6. Applied rewrites27.5%

    \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{\log im}}} \]
  7. Evaluated real constant27.5%

    \[\leadsto \frac{1}{\frac{\color{blue}{2.302585092994046}}{\log im}} \]
  8. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{2592480341699211}{1125899906842624}}{\log im}}} \]
    2. lift-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{2592480341699211}{1125899906842624}}{\log im}}} \]
    3. div-flip-revN/A

      \[\leadsto \color{blue}{\frac{\log im}{\frac{2592480341699211}{1125899906842624}}} \]
    4. mult-flipN/A

      \[\leadsto \color{blue}{\log im \cdot \frac{1}{\frac{2592480341699211}{1125899906842624}}} \]
    5. metadata-evalN/A

      \[\leadsto \log im \cdot \color{blue}{\frac{1125899906842624}{2592480341699211}} \]
    6. lower-*.f6427.4%

      \[\leadsto \color{blue}{\log im \cdot 0.43429448190325176} \]
  9. Applied rewrites27.4%

    \[\leadsto \color{blue}{\log im \cdot 0.43429448190325176} \]
  10. Add Preprocessing

Reproduce

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