math.log10 on complex, real part

Percentage Accurate: 51.7% → 99.1%
Time: 4.0s
Alternatives: 8
Speedup: 1.7×

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}

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 8 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.7% 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} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \left(\frac{-1}{\log 100} - \frac{-1}{\log 0.01}\right) \cdot \left(-\log im\_m\right) \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m)
 :precision binary64
 (* (- (/ -1.0 (log 100.0)) (/ -1.0 (log 0.01))) (- (log im_m))))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return ((-1.0 / log(100.0)) - (-1.0 / log(0.01))) * -log(im_m);
}
re_m =     private
im_m =     private
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
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_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = (((-1.0d0) / log(100.0d0)) - ((-1.0d0) / log(0.01d0))) * -log(im_m)
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return ((-1.0 / Math.log(100.0)) - (-1.0 / Math.log(0.01))) * -Math.log(im_m);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return ((-1.0 / math.log(100.0)) - (-1.0 / math.log(0.01))) * -math.log(im_m)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(Float64(Float64(-1.0 / log(100.0)) - Float64(-1.0 / log(0.01))) * Float64(-log(im_m)))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = ((-1.0 / log(100.0)) - (-1.0 / log(0.01))) * -log(im_m);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[(N[(-1.0 / N[Log[100.0], $MachinePrecision]), $MachinePrecision] - N[(-1.0 / N[Log[0.01], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Log[im$95$m], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\left(\frac{-1}{\log 100} - \frac{-1}{\log 0.01}\right) \cdot \left(-\log im\_m\right)
\end{array}
Derivation
  1. Initial program 51.7%

    \[\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-/.f6498.3

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

    \[\leadsto \frac{\color{blue}{-1 \cdot \log \left(\frac{1}{im}\right)}}{\log 10} \]
  5. Applied rewrites97.8%

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

      \[\leadsto \color{blue}{\frac{-2}{\log 100}} \cdot \left(-\log im\right) \]
    2. frac-2negN/A

      \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(-2\right)}{\mathsf{neg}\left(\log 100\right)}} \cdot \left(-\log im\right) \]
    3. metadata-evalN/A

      \[\leadsto \frac{\color{blue}{2}}{\mathsf{neg}\left(\log 100\right)} \cdot \left(-\log im\right) \]
    4. metadata-evalN/A

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

      \[\leadsto \frac{1 - -1}{\mathsf{neg}\left(\color{blue}{\log 100}\right)} \cdot \left(-\log im\right) \]
    6. neg-logN/A

      \[\leadsto \frac{1 - -1}{\color{blue}{\log \left(\frac{1}{100}\right)}} \cdot \left(-\log im\right) \]
    7. metadata-evalN/A

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

      \[\leadsto \frac{1 - -1}{\color{blue}{\log \frac{1}{100}}} \cdot \left(-\log im\right) \]
    9. div-subN/A

      \[\leadsto \color{blue}{\left(\frac{1}{\log \frac{1}{100}} - \frac{-1}{\log \frac{1}{100}}\right)} \cdot \left(-\log im\right) \]
    10. metadata-evalN/A

      \[\leadsto \left(\frac{1}{\log \frac{1}{100}} - \frac{\color{blue}{\mathsf{neg}\left(1\right)}}{\log \frac{1}{100}}\right) \cdot \left(-\log im\right) \]
    11. lift-log.f64N/A

      \[\leadsto \left(\frac{1}{\log \frac{1}{100}} - \frac{\mathsf{neg}\left(1\right)}{\color{blue}{\log \frac{1}{100}}}\right) \cdot \left(-\log im\right) \]
    12. metadata-evalN/A

      \[\leadsto \left(\frac{1}{\log \frac{1}{100}} - \frac{\mathsf{neg}\left(1\right)}{\log \color{blue}{\left(\frac{1}{100}\right)}}\right) \cdot \left(-\log im\right) \]
    13. neg-logN/A

      \[\leadsto \left(\frac{1}{\log \frac{1}{100}} - \frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\log 100\right)}}\right) \cdot \left(-\log im\right) \]
    14. lift-log.f64N/A

      \[\leadsto \left(\frac{1}{\log \frac{1}{100}} - \frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\color{blue}{\log 100}\right)}\right) \cdot \left(-\log im\right) \]
    15. frac-2negN/A

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

      \[\leadsto \color{blue}{\left(\frac{1}{\log \frac{1}{100}} - \frac{1}{\log 100}\right)} \cdot \left(-\log im\right) \]
    17. frac-2negN/A

      \[\leadsto \left(\color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\log \frac{1}{100}\right)}} - \frac{1}{\log 100}\right) \cdot \left(-\log im\right) \]
    18. metadata-evalN/A

      \[\leadsto \left(\frac{\color{blue}{-1}}{\mathsf{neg}\left(\log \frac{1}{100}\right)} - \frac{1}{\log 100}\right) \cdot \left(-\log im\right) \]
    19. lift-log.f64N/A

      \[\leadsto \left(\frac{-1}{\mathsf{neg}\left(\color{blue}{\log \frac{1}{100}}\right)} - \frac{1}{\log 100}\right) \cdot \left(-\log im\right) \]
    20. neg-logN/A

      \[\leadsto \left(\frac{-1}{\color{blue}{\log \left(\frac{1}{\frac{1}{100}}\right)}} - \frac{1}{\log 100}\right) \cdot \left(-\log im\right) \]
    21. metadata-evalN/A

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

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

      \[\leadsto \left(\color{blue}{\frac{-1}{\log 100}} - \frac{1}{\log 100}\right) \cdot \left(-\log im\right) \]
    24. frac-2negN/A

      \[\leadsto \left(\frac{-1}{\log 100} - \color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\log 100\right)}}\right) \cdot \left(-\log im\right) \]
    25. metadata-evalN/A

      \[\leadsto \left(\frac{-1}{\log 100} - \frac{\color{blue}{-1}}{\mathsf{neg}\left(\log 100\right)}\right) \cdot \left(-\log im\right) \]
    26. lift-log.f64N/A

      \[\leadsto \left(\frac{-1}{\log 100} - \frac{-1}{\mathsf{neg}\left(\color{blue}{\log 100}\right)}\right) \cdot \left(-\log im\right) \]
    27. neg-logN/A

      \[\leadsto \left(\frac{-1}{\log 100} - \frac{-1}{\color{blue}{\log \left(\frac{1}{100}\right)}}\right) \cdot \left(-\log im\right) \]
    28. metadata-evalN/A

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

      \[\leadsto \left(\frac{-1}{\log 100} - \frac{-1}{\color{blue}{\log \frac{1}{100}}}\right) \cdot \left(-\log im\right) \]
  7. Applied rewrites98.8%

    \[\leadsto \color{blue}{\left(\frac{-1}{\log 100} - \frac{-1}{\log 0.01}\right)} \cdot \left(-\log im\right) \]
  8. Add Preprocessing

Alternative 2: 99.0% accurate, 0.9× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{\log \left(\mathsf{hypot}\left(re\_m, im\_m\right)\right)}{-\log 0.1} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m)
 :precision binary64
 (/ (log (hypot re_m im_m)) (- (log 0.1))))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return log(hypot(re_m, im_m)) / -log(0.1);
}
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return Math.log(Math.hypot(re_m, im_m)) / -Math.log(0.1);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return math.log(math.hypot(re_m, im_m)) / -math.log(0.1)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(log(hypot(re_m, im_m)) / Float64(-log(0.1)))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = log(hypot(re_m, im_m)) / -log(0.1);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[Log[N[Sqrt[re$95$m ^ 2 + im$95$m ^ 2], $MachinePrecision]], $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{\log \left(\mathsf{hypot}\left(re\_m, im\_m\right)\right)}{-\log 0.1}
\end{array}
Derivation
  1. Initial program 51.7%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(im \cdot im\right)\right)}}\right)}{\log 10} \]
    4. sub-flipN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im \cdot im\right)\right)\right)\right)}}\right)}{\log 10} \]
    5. remove-double-negN/A

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

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. sqr-abs-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}}\right)}{\log 10} \]
    8. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    10. fp-cancel-sub-sign-invN/A

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}\right)}{\log 10} \]
    12. distribute-lft-neg-inN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}}\right)}{\log 10} \]
    13. distribute-rgt-neg-outN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}}\right)}{\log 10} \]
    14. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    15. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}}\right)}{\log 10} \]
    16. sqr-abs-revN/A

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

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

    \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  4. Step-by-step derivation
    1. remove-double-negN/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\log 10\right)\right)\right)}} \]
    2. lower-neg.f64N/A

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

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\left(\mathsf{neg}\left(\color{blue}{\log 10}\right)\right)} \]
    4. neg-logN/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\color{blue}{\log \left(\frac{1}{10}\right)}} \]
    5. lower-log.f64N/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\color{blue}{\log \left(\frac{1}{10}\right)}} \]
    6. metadata-eval99.0

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\log \color{blue}{0.1}} \]
  5. Applied rewrites99.0%

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

Alternative 3: 98.8% accurate, 0.9× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{\log \left(\mathsf{hypot}\left(re\_m, im\_m\right)\right)}{\log 10} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m) :precision binary64 (/ (log (hypot re_m im_m)) (log 10.0)))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return log(hypot(re_m, im_m)) / log(10.0);
}
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return Math.log(Math.hypot(re_m, im_m)) / Math.log(10.0);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return math.log(math.hypot(re_m, im_m)) / math.log(10.0)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(log(hypot(re_m, im_m)) / log(10.0))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = log(hypot(re_m, im_m)) / log(10.0);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[Log[N[Sqrt[re$95$m ^ 2 + im$95$m ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{\log \left(\mathsf{hypot}\left(re\_m, im\_m\right)\right)}{\log 10}
\end{array}
Derivation
  1. Initial program 51.7%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(im \cdot im\right)\right)}}\right)}{\log 10} \]
    4. sub-flipN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im \cdot im\right)\right)\right)\right)}}\right)}{\log 10} \]
    5. remove-double-negN/A

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

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. sqr-abs-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}}\right)}{\log 10} \]
    8. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    10. fp-cancel-sub-sign-invN/A

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}\right)}{\log 10} \]
    12. distribute-lft-neg-inN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}}\right)}{\log 10} \]
    13. distribute-rgt-neg-outN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}}\right)}{\log 10} \]
    14. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    15. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}}\right)}{\log 10} \]
    16. sqr-abs-revN/A

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

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

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

Alternative 4: 98.3% accurate, 1.0× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{\log \left(im\_m \cdot 2\right) - \log 2}{\log 10} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m)
 :precision binary64
 (/ (- (log (* im_m 2.0)) (log 2.0)) (log 10.0)))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return (log((im_m * 2.0)) - log(2.0)) / log(10.0);
}
re_m =     private
im_m =     private
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
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_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = (log((im_m * 2.0d0)) - log(2.0d0)) / log(10.0d0)
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return (Math.log((im_m * 2.0)) - Math.log(2.0)) / Math.log(10.0);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return (math.log((im_m * 2.0)) - math.log(2.0)) / math.log(10.0)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(Float64(log(Float64(im_m * 2.0)) - log(2.0)) / log(10.0))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = (log((im_m * 2.0)) - log(2.0)) / log(10.0);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[(N[Log[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision] - N[Log[2.0], $MachinePrecision]), $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{\log \left(im\_m \cdot 2\right) - \log 2}{\log 10}
\end{array}
Derivation
  1. Initial program 51.7%

    \[\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-/.f6498.3

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\log \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im\right)\right)\right)\right)}{\log 10} \]
    10. *-lft-identityN/A

      \[\leadsto \frac{\log \left(1 \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im\right)\right)\right)\right)\right)}{\log 10} \]
    11. *-commutativeN/A

      \[\leadsto \frac{\log \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im\right)\right)\right)\right) \cdot 1\right)}{\log 10} \]
    12. metadata-evalN/A

      \[\leadsto \frac{\log \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im\right)\right)\right)\right) \cdot \frac{2}{2}\right)}{\log 10} \]
    13. associate-*r/N/A

      \[\leadsto \frac{\log \left(\frac{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im\right)\right)\right)\right) \cdot 2}{2}\right)}{\log 10} \]
    14. log-divN/A

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

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

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

      \[\leadsto \frac{\log \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im\right)\right)\right)\right) \cdot 2\right) - \log 2}{\log 10} \]
    18. mul-1-negN/A

      \[\leadsto \frac{\log \left(\left(\mathsf{neg}\left(-1 \cdot im\right)\right) \cdot 2\right) - \log 2}{\log 10} \]
    19. *-commutativeN/A

      \[\leadsto \frac{\log \left(\left(\mathsf{neg}\left(im \cdot -1\right)\right) \cdot 2\right) - \log 2}{\log 10} \]
    20. distribute-rgt-neg-outN/A

      \[\leadsto \frac{\log \left(\left(im \cdot \left(\mathsf{neg}\left(-1\right)\right)\right) \cdot 2\right) - \log 2}{\log 10} \]
    21. metadata-evalN/A

      \[\leadsto \frac{\log \left(\left(im \cdot 1\right) \cdot 2\right) - \log 2}{\log 10} \]
    22. *-rgt-identityN/A

      \[\leadsto \frac{\log \left(im \cdot 2\right) - \log 2}{\log 10} \]
    23. lower-unsound-log.f6498.2

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

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

Alternative 5: 98.3% accurate, 1.2× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{\frac{-2}{\log 0.01}}{\frac{1}{\log im\_m}} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m)
 :precision binary64
 (/ (/ -2.0 (log 0.01)) (/ 1.0 (log im_m))))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return (-2.0 / log(0.01)) / (1.0 / log(im_m));
}
re_m =     private
im_m =     private
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
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_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = ((-2.0d0) / log(0.01d0)) / (1.0d0 / log(im_m))
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return (-2.0 / Math.log(0.01)) / (1.0 / Math.log(im_m));
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return (-2.0 / math.log(0.01)) / (1.0 / math.log(im_m))
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(Float64(-2.0 / log(0.01)) / Float64(1.0 / log(im_m)))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = (-2.0 / log(0.01)) / (1.0 / log(im_m));
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[(-2.0 / N[Log[0.01], $MachinePrecision]), $MachinePrecision] / N[(1.0 / N[Log[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{\frac{-2}{\log 0.01}}{\frac{1}{\log im\_m}}
\end{array}
Derivation
  1. Initial program 51.7%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(im \cdot im\right)\right)}}\right)}{\log 10} \]
    4. sub-flipN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im \cdot im\right)\right)\right)\right)}}\right)}{\log 10} \]
    5. remove-double-negN/A

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

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. sqr-abs-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}}\right)}{\log 10} \]
    8. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    10. fp-cancel-sub-sign-invN/A

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}\right)}{\log 10} \]
    12. distribute-lft-neg-inN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}}\right)}{\log 10} \]
    13. distribute-rgt-neg-outN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}}\right)}{\log 10} \]
    14. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    15. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}}\right)}{\log 10} \]
    16. sqr-abs-revN/A

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

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

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

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

    \[\leadsto \frac{\frac{-2}{\log \frac{1}{100}}}{\color{blue}{\frac{-1}{\log \left(\frac{1}{im}\right)}}} \]
  6. Step-by-step derivation
    1. lower-/.f64N/A

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

      \[\leadsto \frac{\frac{-2}{\log \frac{1}{100}}}{\frac{-1}{\log \left(\frac{1}{im}\right)}} \]
    3. lower-/.f6498.2

      \[\leadsto \frac{\frac{-2}{\log 0.01}}{\frac{-1}{\log \left(\frac{1}{im}\right)}} \]
  7. Applied rewrites98.2%

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

      \[\leadsto \frac{\frac{-2}{\log \frac{1}{100}}}{\frac{-1}{\color{blue}{\log \left(\frac{1}{im}\right)}}} \]
    2. frac-2negN/A

      \[\leadsto \frac{\frac{-2}{\log \frac{1}{100}}}{\frac{\mathsf{neg}\left(-1\right)}{\color{blue}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}}} \]
    3. metadata-evalN/A

      \[\leadsto \frac{\frac{-2}{\log \frac{1}{100}}}{\frac{1}{\mathsf{neg}\left(\color{blue}{\log \left(\frac{1}{im}\right)}\right)}} \]
    4. lower-/.f64N/A

      \[\leadsto \frac{\frac{-2}{\log \frac{1}{100}}}{\frac{1}{\color{blue}{\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)}}} \]
    5. lift-log.f64N/A

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

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

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

      \[\leadsto \frac{\frac{-2}{\log \frac{1}{100}}}{\frac{1}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\log im\right)\right)\right)}} \]
    9. remove-double-neg98.2

      \[\leadsto \frac{\frac{-2}{\log 0.01}}{\frac{1}{\log im}} \]
  9. Applied rewrites98.2%

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

Alternative 6: 98.2% accurate, 1.6× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{-\log im\_m}{\log 0.1} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m) :precision binary64 (/ (- (log im_m)) (log 0.1)))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return -log(im_m) / log(0.1);
}
re_m =     private
im_m =     private
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
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_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = -log(im_m) / log(0.1d0)
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return -Math.log(im_m) / Math.log(0.1);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return -math.log(im_m) / math.log(0.1)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(Float64(-log(im_m)) / log(0.1))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = -log(im_m) / log(0.1);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[((-N[Log[im$95$m], $MachinePrecision]) / N[Log[0.1], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{-\log im\_m}{\log 0.1}
\end{array}
Derivation
  1. Initial program 51.7%

    \[\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-/.f6498.3

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

    \[\leadsto \frac{\color{blue}{-1 \cdot \log \left(\frac{1}{im}\right)}}{\log 10} \]
  5. Applied rewrites98.3%

    \[\leadsto \color{blue}{\frac{-\log im}{\log 0.1}} \]
  6. Add Preprocessing

Alternative 7: 98.2% accurate, 1.7× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{\log im\_m}{\log 10} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m) :precision binary64 (/ (log im_m) (log 10.0)))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return log(im_m) / log(10.0);
}
re_m =     private
im_m =     private
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
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_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = log(im_m) / log(10.0d0)
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return Math.log(im_m) / Math.log(10.0);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return math.log(im_m) / math.log(10.0)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(log(im_m) / log(10.0))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = log(im_m) / log(10.0);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[Log[im$95$m], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{\log im\_m}{\log 10}
\end{array}
Derivation
  1. Initial program 51.7%

    \[\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-/.f6498.3

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

    \[\leadsto \frac{\color{blue}{-1 \cdot \log \left(\frac{1}{im}\right)}}{\log 10} \]
  5. Applied rewrites98.3%

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

Alternative 8: 10.4% accurate, 1.7× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{\log re\_m}{\log 10} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m) :precision binary64 (/ (log re_m) (log 10.0)))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return log(re_m) / log(10.0);
}
re_m =     private
im_m =     private
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
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_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = log(re_m) / log(10.0d0)
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return Math.log(re_m) / Math.log(10.0);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return math.log(re_m) / math.log(10.0)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(log(re_m) / log(10.0))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = log(re_m) / log(10.0);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[Log[re$95$m], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{\log re\_m}{\log 10}
\end{array}
Derivation
  1. Initial program 51.7%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(im \cdot im\right)\right)}}\right)}{\log 10} \]
    4. sub-flipN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im \cdot im\right)\right)\right)\right)}}\right)}{\log 10} \]
    5. remove-double-negN/A

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

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. sqr-abs-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}}\right)}{\log 10} \]
    8. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    10. fp-cancel-sub-sign-invN/A

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}\right)}{\log 10} \]
    12. distribute-lft-neg-inN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}}\right)}{\log 10} \]
    13. distribute-rgt-neg-outN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}}\right)}{\log 10} \]
    14. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}}\right)}{\log 10} \]
    15. sqr-neg-revN/A

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}}\right)}{\log 10} \]
    16. sqr-abs-revN/A

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

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

    \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  4. Step-by-step derivation
    1. remove-double-negN/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\log 10\right)\right)\right)}} \]
    2. lower-neg.f64N/A

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

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\left(\mathsf{neg}\left(\color{blue}{\log 10}\right)\right)} \]
    4. neg-logN/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\color{blue}{\log \left(\frac{1}{10}\right)}} \]
    5. lower-log.f64N/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\color{blue}{\log \left(\frac{1}{10}\right)}} \]
    6. metadata-eval99.0

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\log \color{blue}{0.1}} \]
  5. Applied rewrites99.0%

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\color{blue}{-\log 0.1}} \]
  6. Taylor expanded in re around inf

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

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

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

      \[\leadsto \frac{\log \left(\frac{1}{re}\right)}{\log \frac{1}{10}} \]
    4. lower-log.f6410.4

      \[\leadsto \frac{\log \left(\frac{1}{re}\right)}{\log 0.1} \]
  8. Applied rewrites10.4%

    \[\leadsto \color{blue}{\frac{\log \left(\frac{1}{re}\right)}{\log 0.1}} \]
  9. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \frac{\log \left(\frac{1}{re}\right)}{\color{blue}{\log \frac{1}{10}}} \]
    2. frac-2negN/A

      \[\leadsto \frac{\mathsf{neg}\left(\log \left(\frac{1}{re}\right)\right)}{\color{blue}{\mathsf{neg}\left(\log \frac{1}{10}\right)}} \]
    3. lift-log.f64N/A

      \[\leadsto \frac{\mathsf{neg}\left(\log \left(\frac{1}{re}\right)\right)}{\mathsf{neg}\left(\log \frac{1}{10}\right)} \]
    4. neg-logN/A

      \[\leadsto \frac{\mathsf{neg}\left(\log \left(\frac{1}{re}\right)\right)}{\log \left(\frac{1}{\frac{1}{10}}\right)} \]
    5. metadata-evalN/A

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

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

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

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

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

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

      \[\leadsto \frac{\log re}{\log \color{blue}{10}} \]
    12. lower-log.f6410.4

      \[\leadsto \frac{\log re}{\log \color{blue}{10}} \]
  10. Applied rewrites10.4%

    \[\leadsto \frac{\log re}{\color{blue}{\log 10}} \]
  11. Add Preprocessing

Reproduce

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