math.log10 on complex, real part

Percentage Accurate: 51.6% → 99.0%
Time: 7.9s
Alternatives: 11
Speedup: 0.8×

Specification

?
\[\begin{array}{l} \\ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \end{array} \]
(FPCore (re im)
 :precision binary64
 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
double code(double re, double im) {
	return log(sqrt(((re * re) + (im * im)))) / log(10.0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 11 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.6% 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.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \log \left(\mathsf{hypot}\left(im, re\right)\right)\\ t_1 := \log 0.1 \cdot t\_0\\ \frac{\mathsf{fma}\left(0, \log 10, t\_1 \cdot t\_0\right)}{t\_1 \cdot \left(-\log 0.1\right)} \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (log (hypot im re))) (t_1 (* (log 0.1) t_0)))
   (/ (fma 0.0 (log 10.0) (* t_1 t_0)) (* t_1 (- (log 0.1))))))
double code(double re, double im) {
	double t_0 = log(hypot(im, re));
	double t_1 = log(0.1) * t_0;
	return fma(0.0, log(10.0), (t_1 * t_0)) / (t_1 * -log(0.1));
}
function code(re, im)
	t_0 = log(hypot(im, re))
	t_1 = Float64(log(0.1) * t_0)
	return Float64(fma(0.0, log(10.0), Float64(t_1 * t_0)) / Float64(t_1 * Float64(-log(0.1))))
end
code[re_, im_] := Block[{t$95$0 = N[Log[N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Log[0.1], $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(N[(0.0 * N[Log[10.0], $MachinePrecision] + N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 * (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \log \left(\mathsf{hypot}\left(im, re\right)\right)\\
t_1 := \log 0.1 \cdot t\_0\\
\frac{\mathsf{fma}\left(0, \log 10, t\_1 \cdot t\_0\right)}{t\_1 \cdot \left(-\log 0.1\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 51.7%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Add Preprocessing
  3. Applied rewrites99.1%

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

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

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

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

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

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

      \[\leadsto \frac{\log \left(\frac{1}{\sqrt{\color{blue}{\mathsf{fma}\left(im, im, re \cdot re\right)}}}\right)}{\log \frac{1}{10}} \]
    7. pow1/2N/A

      \[\leadsto \frac{\log \left(\frac{1}{\color{blue}{{\left(\mathsf{fma}\left(im, im, re \cdot re\right)\right)}^{\frac{1}{2}}}}\right)}{\log \frac{1}{10}} \]
    8. lift-fma.f64N/A

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

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

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

      \[\leadsto \frac{\log \left(\frac{1}{{\color{blue}{\left(re \cdot re + im \cdot im\right)}}^{\frac{1}{2}}}\right)}{\log \frac{1}{10}} \]
    12. pow1/2N/A

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

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

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

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

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

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

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

      \[\leadsto \frac{0 - \color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right)}}{\log \frac{1}{10}} \]
    20. flip--N/A

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

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

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

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

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

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

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

      \[\leadsto \frac{\mathsf{fma}\left(0, \log 10, \left(\log \frac{1}{10} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)\right) \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)\right)}{\left(\log \frac{1}{10} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\log \frac{1}{10}}\right)\right)} \]
    5. lower-neg.f6499.1

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

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

Alternative 2: 99.0% accurate, 0.7× speedup?

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

\\
\frac{\log \left(\mathsf{hypot}\left(im, re\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. Add Preprocessing
  3. Applied rewrites99.1%

    \[\leadsto \color{blue}{\frac{-\log \left(\mathsf{hypot}\left(im, re\right)\right)}{\log 0.1}} \]
  4. Final simplification99.1%

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

Alternative 3: 99.1% accurate, 0.8× speedup?

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

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

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Add Preprocessing
  3. Applied rewrites99.0%

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

Alternative 4: 25.7% accurate, 1.0× speedup?

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

\\
\frac{\mathsf{fma}\left(\frac{0.5 \cdot re}{im}, \frac{re}{im}, \log im\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. Add Preprocessing
  3. Applied rewrites99.1%

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

    \[\leadsto \frac{-\color{blue}{\left(\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
  5. Step-by-step derivation
    1. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{-1}{2}} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}{\log \frac{1}{10}} \]
    3. *-commutativeN/A

      \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}}\right)}{\log \frac{1}{10}} \]
    4. fp-cancel-sub-sign-invN/A

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

      \[\leadsto \frac{-\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\log im\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\frac{{re}^{2}}{{im}^{2}}\right)\right) \cdot \frac{-1}{2}\right)}{\log \frac{1}{10}} \]
    6. log-recN/A

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

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

      \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) - \frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}\right)}}{\log \frac{1}{10}} \]
    9. *-commutativeN/A

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

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

      \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
    12. +-commutativeN/A

      \[\leadsto \frac{-\color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}}{\log \frac{1}{10}} \]
    13. associate-*r/N/A

      \[\leadsto \frac{-\left(\color{blue}{\frac{\frac{1}{2} \cdot {re}^{2}}{{im}^{2}}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
    14. unpow2N/A

      \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot \color{blue}{\left(re \cdot re\right)}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
    15. associate-*r*N/A

      \[\leadsto \frac{-\left(\frac{\color{blue}{\left(\frac{1}{2} \cdot re\right) \cdot re}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
    16. unpow2N/A

      \[\leadsto \frac{-\left(\frac{\left(\frac{1}{2} \cdot re\right) \cdot re}{\color{blue}{im \cdot im}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
    17. times-fracN/A

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

      \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)\right)}\right)}{\log \frac{1}{10}} \]
    19. log-recN/A

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

      \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\log im}\right)}{\log \frac{1}{10}} \]
  6. Applied rewrites22.0%

    \[\leadsto \frac{-\color{blue}{\mathsf{fma}\left(\frac{0.5 \cdot re}{im}, \frac{re}{im}, \log im\right)}}{\log 0.1} \]
  7. Final simplification22.0%

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

Alternative 5: 25.7% accurate, 1.0× speedup?

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

\\
\frac{\mathsf{fma}\left(\frac{0.5 \cdot re}{im}, \frac{re}{im}, \log im\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. Add Preprocessing
  3. Taylor expanded in re around 0

    \[\leadsto \frac{\color{blue}{\log im}}{\log 10} \]
  4. Step-by-step derivation
    1. lower-log.f6423.5

      \[\leadsto \frac{\color{blue}{\log im}}{\log 10} \]
  5. Applied rewrites23.5%

    \[\leadsto \frac{\color{blue}{\log im}}{\log 10} \]
  6. Taylor expanded in re around 0

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2} \cdot \log 10} + \frac{\log im}{\log 10}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{\frac{\log im}{\log 10} + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2} \cdot \log 10}} \]
    2. associate-/r*N/A

      \[\leadsto \frac{\log im}{\log 10} + \frac{1}{2} \cdot \color{blue}{\frac{\frac{{re}^{2}}{{im}^{2}}}{\log 10}} \]
    3. associate-*r/N/A

      \[\leadsto \frac{\log im}{\log 10} + \color{blue}{\frac{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}}{\log 10}} \]
    4. div-add-revN/A

      \[\leadsto \color{blue}{\frac{\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}}{\log 10}} \]
    5. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}}{\log 10}} \]
  8. Applied rewrites21.9%

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

Alternative 6: 27.4% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \frac{\log im}{-\log 0.1} \end{array} \]
(FPCore (re im) :precision binary64 (/ (log im) (- (log 0.1))))
double code(double re, double im) {
	return log(im) / -log(0.1);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = log(im) / -log(0.1d0)
end function
public static double code(double re, double im) {
	return Math.log(im) / -Math.log(0.1);
}
def code(re, im):
	return math.log(im) / -math.log(0.1)
function code(re, im)
	return Float64(log(im) / Float64(-log(0.1)))
end
function tmp = code(re, im)
	tmp = log(im) / -log(0.1);
end
code[re_, im_] := N[(N[Log[im], $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}

\\
\frac{\log im}{-\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. Add Preprocessing
  3. Taylor expanded in re around 0

    \[\leadsto \frac{\color{blue}{\log im}}{\log 10} \]
  4. Step-by-step derivation
    1. lower-log.f6423.5

      \[\leadsto \frac{\color{blue}{\log im}}{\log 10} \]
  5. Applied rewrites23.5%

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

      \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
    2. frac-2neg-revN/A

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\log im\right)}{\log \frac{1}{10}}} \]
    8. lower-neg.f6423.5

      \[\leadsto \frac{\color{blue}{-\log im}}{\log 0.1} \]
  7. Applied rewrites23.5%

    \[\leadsto \color{blue}{\frac{-\log im}{\log 0.1}} \]
  8. Final simplification23.5%

    \[\leadsto \frac{\log im}{-\log 0.1} \]
  9. Add Preprocessing

Alternative 7: 27.4% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \frac{\log im}{\log 10} \end{array} \]
(FPCore (re im) :precision binary64 (/ (log im) (log 10.0)))
double code(double re, double im) {
	return log(im) / log(10.0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

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

\\
\frac{\log im}{\log 10}
\end{array}
Derivation
  1. Initial program 51.7%

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

    \[\leadsto \frac{\color{blue}{\log im}}{\log 10} \]
  4. Step-by-step derivation
    1. lower-log.f6423.5

      \[\leadsto \frac{\color{blue}{\log im}}{\log 10} \]
  5. Applied rewrites23.5%

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

Alternative 8: 3.3% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \frac{\frac{0.5}{im} \cdot \left(\frac{re}{im} \cdot re\right)}{-\log 0.1} \end{array} \]
(FPCore (re im)
 :precision binary64
 (/ (* (/ 0.5 im) (* (/ re im) re)) (- (log 0.1))))
double code(double re, double im) {
	return ((0.5 / im) * ((re / im) * re)) / -log(0.1);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = ((0.5d0 / im) * ((re / im) * re)) / -log(0.1d0)
end function
public static double code(double re, double im) {
	return ((0.5 / im) * ((re / im) * re)) / -Math.log(0.1);
}
def code(re, im):
	return ((0.5 / im) * ((re / im) * re)) / -math.log(0.1)
function code(re, im)
	return Float64(Float64(Float64(0.5 / im) * Float64(Float64(re / im) * re)) / Float64(-log(0.1)))
end
function tmp = code(re, im)
	tmp = ((0.5 / im) * ((re / im) * re)) / -log(0.1);
end
code[re_, im_] := N[(N[(N[(0.5 / im), $MachinePrecision] * N[(N[(re / im), $MachinePrecision] * re), $MachinePrecision]), $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{0.5}{im} \cdot \left(\frac{re}{im} \cdot re\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. Add Preprocessing
  3. Applied rewrites99.1%

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

    \[\leadsto \frac{-\color{blue}{\left(\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
  5. Step-by-step derivation
    1. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{-1}{2}} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}{\log \frac{1}{10}} \]
    3. *-commutativeN/A

      \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}}\right)}{\log \frac{1}{10}} \]
    4. fp-cancel-sub-sign-invN/A

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

      \[\leadsto \frac{-\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\log im\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\frac{{re}^{2}}{{im}^{2}}\right)\right) \cdot \frac{-1}{2}\right)}{\log \frac{1}{10}} \]
    6. log-recN/A

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

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

      \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) - \frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}\right)}}{\log \frac{1}{10}} \]
    9. *-commutativeN/A

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

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

      \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
    12. +-commutativeN/A

      \[\leadsto \frac{-\color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}}{\log \frac{1}{10}} \]
    13. associate-*r/N/A

      \[\leadsto \frac{-\left(\color{blue}{\frac{\frac{1}{2} \cdot {re}^{2}}{{im}^{2}}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
    14. unpow2N/A

      \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot \color{blue}{\left(re \cdot re\right)}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
    15. associate-*r*N/A

      \[\leadsto \frac{-\left(\frac{\color{blue}{\left(\frac{1}{2} \cdot re\right) \cdot re}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
    16. unpow2N/A

      \[\leadsto \frac{-\left(\frac{\left(\frac{1}{2} \cdot re\right) \cdot re}{\color{blue}{im \cdot im}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
    17. times-fracN/A

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

      \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)\right)}\right)}{\log \frac{1}{10}} \]
    19. log-recN/A

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

      \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\log im}\right)}{\log \frac{1}{10}} \]
  6. Applied rewrites22.0%

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

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

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

        \[\leadsto \frac{-\frac{0.5}{im} \cdot \left(\frac{re}{im} \cdot re\right)}{\log 0.1} \]
      2. Final simplification3.5%

        \[\leadsto \frac{\frac{0.5}{im} \cdot \left(\frac{re}{im} \cdot re\right)}{-\log 0.1} \]
      3. Add Preprocessing

      Alternative 9: 3.3% accurate, 1.6× speedup?

      \[\begin{array}{l} \\ \frac{re \cdot \left(\frac{re}{im} \cdot \frac{0.5}{im}\right)}{-\log 0.1} \end{array} \]
      (FPCore (re im)
       :precision binary64
       (/ (* re (* (/ re im) (/ 0.5 im))) (- (log 0.1))))
      double code(double re, double im) {
      	return (re * ((re / im) * (0.5 / im))) / -log(0.1);
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(re, im)
      use fmin_fmax_functions
          real(8), intent (in) :: re
          real(8), intent (in) :: im
          code = (re * ((re / im) * (0.5d0 / im))) / -log(0.1d0)
      end function
      
      public static double code(double re, double im) {
      	return (re * ((re / im) * (0.5 / im))) / -Math.log(0.1);
      }
      
      def code(re, im):
      	return (re * ((re / im) * (0.5 / im))) / -math.log(0.1)
      
      function code(re, im)
      	return Float64(Float64(re * Float64(Float64(re / im) * Float64(0.5 / im))) / Float64(-log(0.1)))
      end
      
      function tmp = code(re, im)
      	tmp = (re * ((re / im) * (0.5 / im))) / -log(0.1);
      end
      
      code[re_, im_] := N[(N[(re * N[(N[(re / im), $MachinePrecision] * N[(0.5 / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{re \cdot \left(\frac{re}{im} \cdot \frac{0.5}{im}\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. Add Preprocessing
      3. Applied rewrites99.1%

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

        \[\leadsto \frac{-\color{blue}{\left(\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
      5. Step-by-step derivation
        1. fp-cancel-sign-sub-invN/A

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

          \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{-1}{2}} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}{\log \frac{1}{10}} \]
        3. *-commutativeN/A

          \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}}\right)}{\log \frac{1}{10}} \]
        4. fp-cancel-sub-sign-invN/A

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

          \[\leadsto \frac{-\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\log im\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\frac{{re}^{2}}{{im}^{2}}\right)\right) \cdot \frac{-1}{2}\right)}{\log \frac{1}{10}} \]
        6. log-recN/A

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

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

          \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) - \frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}\right)}}{\log \frac{1}{10}} \]
        9. *-commutativeN/A

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

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

          \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
        12. +-commutativeN/A

          \[\leadsto \frac{-\color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}}{\log \frac{1}{10}} \]
        13. associate-*r/N/A

          \[\leadsto \frac{-\left(\color{blue}{\frac{\frac{1}{2} \cdot {re}^{2}}{{im}^{2}}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
        14. unpow2N/A

          \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot \color{blue}{\left(re \cdot re\right)}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
        15. associate-*r*N/A

          \[\leadsto \frac{-\left(\frac{\color{blue}{\left(\frac{1}{2} \cdot re\right) \cdot re}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
        16. unpow2N/A

          \[\leadsto \frac{-\left(\frac{\left(\frac{1}{2} \cdot re\right) \cdot re}{\color{blue}{im \cdot im}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
        17. times-fracN/A

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

          \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)\right)}\right)}{\log \frac{1}{10}} \]
        19. log-recN/A

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

          \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\log im}\right)}{\log \frac{1}{10}} \]
      6. Applied rewrites22.0%

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

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

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

            \[\leadsto \frac{-re \cdot \left(\frac{re}{im} \cdot \color{blue}{\frac{0.5}{im}}\right)}{\log 0.1} \]
          2. Final simplification3.5%

            \[\leadsto \frac{re \cdot \left(\frac{re}{im} \cdot \frac{0.5}{im}\right)}{-\log 0.1} \]
          3. Add Preprocessing

          Alternative 10: 3.0% accurate, 1.7× speedup?

          \[\begin{array}{l} \\ \frac{\left(0.5 \cdot re\right) \cdot \frac{re}{im \cdot im}}{-\log 0.1} \end{array} \]
          (FPCore (re im)
           :precision binary64
           (/ (* (* 0.5 re) (/ re (* im im))) (- (log 0.1))))
          double code(double re, double im) {
          	return ((0.5 * re) * (re / (im * im))) / -log(0.1);
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(re, im)
          use fmin_fmax_functions
              real(8), intent (in) :: re
              real(8), intent (in) :: im
              code = ((0.5d0 * re) * (re / (im * im))) / -log(0.1d0)
          end function
          
          public static double code(double re, double im) {
          	return ((0.5 * re) * (re / (im * im))) / -Math.log(0.1);
          }
          
          def code(re, im):
          	return ((0.5 * re) * (re / (im * im))) / -math.log(0.1)
          
          function code(re, im)
          	return Float64(Float64(Float64(0.5 * re) * Float64(re / Float64(im * im))) / Float64(-log(0.1)))
          end
          
          function tmp = code(re, im)
          	tmp = ((0.5 * re) * (re / (im * im))) / -log(0.1);
          end
          
          code[re_, im_] := N[(N[(N[(0.5 * re), $MachinePrecision] * N[(re / N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \frac{\left(0.5 \cdot re\right) \cdot \frac{re}{im \cdot im}}{-\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. Add Preprocessing
          3. Applied rewrites99.1%

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

            \[\leadsto \frac{-\color{blue}{\left(\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
          5. Step-by-step derivation
            1. fp-cancel-sign-sub-invN/A

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

              \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{-1}{2}} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}{\log \frac{1}{10}} \]
            3. *-commutativeN/A

              \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}}\right)}{\log \frac{1}{10}} \]
            4. fp-cancel-sub-sign-invN/A

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

              \[\leadsto \frac{-\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\log im\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\frac{{re}^{2}}{{im}^{2}}\right)\right) \cdot \frac{-1}{2}\right)}{\log \frac{1}{10}} \]
            6. log-recN/A

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

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

              \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) - \frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}\right)}}{\log \frac{1}{10}} \]
            9. *-commutativeN/A

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

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

              \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
            12. +-commutativeN/A

              \[\leadsto \frac{-\color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}}{\log \frac{1}{10}} \]
            13. associate-*r/N/A

              \[\leadsto \frac{-\left(\color{blue}{\frac{\frac{1}{2} \cdot {re}^{2}}{{im}^{2}}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
            14. unpow2N/A

              \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot \color{blue}{\left(re \cdot re\right)}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
            15. associate-*r*N/A

              \[\leadsto \frac{-\left(\frac{\color{blue}{\left(\frac{1}{2} \cdot re\right) \cdot re}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
            16. unpow2N/A

              \[\leadsto \frac{-\left(\frac{\left(\frac{1}{2} \cdot re\right) \cdot re}{\color{blue}{im \cdot im}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
            17. times-fracN/A

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

              \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)\right)}\right)}{\log \frac{1}{10}} \]
            19. log-recN/A

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

              \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\log im}\right)}{\log \frac{1}{10}} \]
          6. Applied rewrites22.0%

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

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

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

                \[\leadsto \frac{-\left(0.5 \cdot re\right) \cdot \frac{re}{\color{blue}{im \cdot im}}}{\log 0.1} \]
              2. Final simplification3.1%

                \[\leadsto \frac{\left(0.5 \cdot re\right) \cdot \frac{re}{im \cdot im}}{-\log 0.1} \]
              3. Add Preprocessing

              Alternative 11: 2.8% accurate, 1.7× speedup?

              \[\begin{array}{l} \\ \frac{0.5 \cdot \frac{re \cdot re}{im \cdot im}}{-\log 0.1} \end{array} \]
              (FPCore (re im)
               :precision binary64
               (/ (* 0.5 (/ (* re re) (* im im))) (- (log 0.1))))
              double code(double re, double im) {
              	return (0.5 * ((re * re) / (im * im))) / -log(0.1);
              }
              
              module fmin_fmax_functions
                  implicit none
                  private
                  public fmax
                  public fmin
              
                  interface fmax
                      module procedure fmax88
                      module procedure fmax44
                      module procedure fmax84
                      module procedure fmax48
                  end interface
                  interface fmin
                      module procedure fmin88
                      module procedure fmin44
                      module procedure fmin84
                      module procedure fmin48
                  end interface
              contains
                  real(8) function fmax88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmax44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmax84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmax48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                  end function
                  real(8) function fmin88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmin44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmin84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmin48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                  end function
              end module
              
              real(8) function code(re, im)
              use fmin_fmax_functions
                  real(8), intent (in) :: re
                  real(8), intent (in) :: im
                  code = (0.5d0 * ((re * re) / (im * im))) / -log(0.1d0)
              end function
              
              public static double code(double re, double im) {
              	return (0.5 * ((re * re) / (im * im))) / -Math.log(0.1);
              }
              
              def code(re, im):
              	return (0.5 * ((re * re) / (im * im))) / -math.log(0.1)
              
              function code(re, im)
              	return Float64(Float64(0.5 * Float64(Float64(re * re) / Float64(im * im))) / Float64(-log(0.1)))
              end
              
              function tmp = code(re, im)
              	tmp = (0.5 * ((re * re) / (im * im))) / -log(0.1);
              end
              
              code[re_, im_] := N[(N[(0.5 * N[(N[(re * re), $MachinePrecision] / N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              \frac{0.5 \cdot \frac{re \cdot re}{im \cdot im}}{-\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. Add Preprocessing
              3. Applied rewrites99.1%

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

                \[\leadsto \frac{-\color{blue}{\left(\log im + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
              5. Step-by-step derivation
                1. fp-cancel-sign-sub-invN/A

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

                  \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{-1}{2}} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}{\log \frac{1}{10}} \]
                3. *-commutativeN/A

                  \[\leadsto \frac{-\left(\log im - \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}}\right)}{\log \frac{1}{10}} \]
                4. fp-cancel-sub-sign-invN/A

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

                  \[\leadsto \frac{-\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\log im\right)\right)\right)\right)} + \left(\mathsf{neg}\left(\frac{{re}^{2}}{{im}^{2}}\right)\right) \cdot \frac{-1}{2}\right)}{\log \frac{1}{10}} \]
                6. log-recN/A

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

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

                  \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) - \frac{{re}^{2}}{{im}^{2}} \cdot \frac{-1}{2}\right)}}{\log \frac{1}{10}} \]
                9. *-commutativeN/A

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

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

                  \[\leadsto \frac{-\color{blue}{\left(-1 \cdot \log \left(\frac{1}{im}\right) + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}}{\log \frac{1}{10}} \]
                12. +-commutativeN/A

                  \[\leadsto \frac{-\color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}}{\log \frac{1}{10}} \]
                13. associate-*r/N/A

                  \[\leadsto \frac{-\left(\color{blue}{\frac{\frac{1}{2} \cdot {re}^{2}}{{im}^{2}}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
                14. unpow2N/A

                  \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot \color{blue}{\left(re \cdot re\right)}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
                15. associate-*r*N/A

                  \[\leadsto \frac{-\left(\frac{\color{blue}{\left(\frac{1}{2} \cdot re\right) \cdot re}}{{im}^{2}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
                16. unpow2N/A

                  \[\leadsto \frac{-\left(\frac{\left(\frac{1}{2} \cdot re\right) \cdot re}{\color{blue}{im \cdot im}} + -1 \cdot \log \left(\frac{1}{im}\right)\right)}{\log \frac{1}{10}} \]
                17. times-fracN/A

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

                  \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{im}\right)\right)\right)}\right)}{\log \frac{1}{10}} \]
                19. log-recN/A

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

                  \[\leadsto \frac{-\left(\frac{\frac{1}{2} \cdot re}{im} \cdot \frac{re}{im} + \color{blue}{\log im}\right)}{\log \frac{1}{10}} \]
              6. Applied rewrites22.0%

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

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

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

                    \[\leadsto \frac{-0.5 \cdot \frac{re \cdot re}{\color{blue}{im \cdot im}}}{\log 0.1} \]
                  2. Final simplification2.8%

                    \[\leadsto \frac{0.5 \cdot \frac{re \cdot re}{im \cdot im}}{-\log 0.1} \]
                  3. Add Preprocessing

                  Reproduce

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