math.log/1 on complex, real part

Percentage Accurate: 52.4% → 100.0%
Time: 6.3s
Alternatives: 7
Speedup: 0.6×

Specification

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

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

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

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

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

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

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

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

Alternative 1: 100.0% accurate, 0.6× speedup?

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

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

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

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

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

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

      \[\leadsto \log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right) \]
    5. lower-hypot.f64100.0

      \[\leadsto \log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)} \]
  4. Applied rewrites100.0%

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

Alternative 2: 25.7% accurate, 0.9× speedup?

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

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

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

    \[\leadsto \color{blue}{\log im} \]
  4. Step-by-step derivation
    1. lower-log.f6428.7

      \[\leadsto \color{blue}{\log im} \]
  5. Applied rewrites28.7%

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

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

      \[\leadsto \log im + \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{1}{2}} \]
    2. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \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} \]
    4. log-recN/A

      \[\leadsto \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} \]
    5. mul-1-negN/A

      \[\leadsto \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} \]
    6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} - \left(\color{blue}{\left(\mathsf{neg}\left(\log im\right)\right)} \cdot -1\right) \cdot -1 \]
    14. distribute-lft-neg-outN/A

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \left(\log im \cdot -1\right) \cdot -1} \]
  8. Applied rewrites27.4%

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

Alternative 3: 27.5% accurate, 1.2× speedup?

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

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

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

\\
\log im
\end{array}
Derivation
  1. Initial program 55.0%

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

    \[\leadsto \color{blue}{\log im} \]
  4. Step-by-step derivation
    1. lower-log.f6428.7

      \[\leadsto \color{blue}{\log im} \]
  5. Applied rewrites28.7%

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

Alternative 4: 3.3% accurate, 3.8× speedup?

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

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

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

\\
\frac{\frac{0.5 \cdot re}{im} \cdot re}{im}
\end{array}
Derivation
  1. Initial program 55.0%

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

    \[\leadsto \color{blue}{\log im} \]
  4. Step-by-step derivation
    1. lower-log.f6428.7

      \[\leadsto \color{blue}{\log im} \]
  5. Applied rewrites28.7%

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

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

      \[\leadsto \log im + \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{1}{2}} \]
    2. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \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} \]
    4. log-recN/A

      \[\leadsto \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} \]
    5. mul-1-negN/A

      \[\leadsto \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} \]
    6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} - \left(\color{blue}{\left(\mathsf{neg}\left(\log im\right)\right)} \cdot -1\right) \cdot -1 \]
    14. distribute-lft-neg-outN/A

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \left(\log im \cdot -1\right) \cdot -1} \]
  8. Applied rewrites27.4%

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

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

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

        \[\leadsto \frac{\frac{0.5 \cdot re}{im} \cdot re}{im} \]
      2. Add Preprocessing

      Alternative 5: 3.3% accurate, 3.8× speedup?

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

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

        \[\leadsto \color{blue}{\log im} \]
      4. Step-by-step derivation
        1. lower-log.f6428.7

          \[\leadsto \color{blue}{\log im} \]
      5. Applied rewrites28.7%

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

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

          \[\leadsto \log im + \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{1}{2}} \]
        2. fp-cancel-sign-sub-invN/A

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

          \[\leadsto \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} \]
        4. log-recN/A

          \[\leadsto \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} \]
        5. mul-1-negN/A

          \[\leadsto \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} \]
        6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

          \[\leadsto \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} - \left(\color{blue}{\left(\mathsf{neg}\left(\log im\right)\right)} \cdot -1\right) \cdot -1 \]
        14. distribute-lft-neg-outN/A

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

          \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \left(\log im \cdot -1\right) \cdot -1} \]
      8. Applied rewrites27.4%

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

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

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

            \[\leadsto \frac{0.5 \cdot re}{im} \cdot \frac{re}{\color{blue}{im}} \]
          2. Add Preprocessing

          Alternative 6: 3.0% accurate, 3.8× speedup?

          \[\begin{array}{l} \\ \left(\frac{\frac{0.5}{im}}{im} \cdot re\right) \cdot re \end{array} \]
          (FPCore (re im) :precision binary64 (* (* (/ (/ 0.5 im) im) re) re))
          double code(double re, double im) {
          	return (((0.5 / im) / im) * re) * re;
          }
          
          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) / im) * re) * re
          end function
          
          public static double code(double re, double im) {
          	return (((0.5 / im) / im) * re) * re;
          }
          
          def code(re, im):
          	return (((0.5 / im) / im) * re) * re
          
          function code(re, im)
          	return Float64(Float64(Float64(Float64(0.5 / im) / im) * re) * re)
          end
          
          function tmp = code(re, im)
          	tmp = (((0.5 / im) / im) * re) * re;
          end
          
          code[re_, im_] := N[(N[(N[(N[(0.5 / im), $MachinePrecision] / im), $MachinePrecision] * re), $MachinePrecision] * re), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \left(\frac{\frac{0.5}{im}}{im} \cdot re\right) \cdot re
          \end{array}
          
          Derivation
          1. Initial program 55.0%

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

            \[\leadsto \color{blue}{\log im} \]
          4. Step-by-step derivation
            1. lower-log.f6428.7

              \[\leadsto \color{blue}{\log im} \]
          5. Applied rewrites28.7%

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

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

              \[\leadsto \log im + \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{1}{2}} \]
            2. fp-cancel-sign-sub-invN/A

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

              \[\leadsto \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} \]
            4. log-recN/A

              \[\leadsto \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} \]
            5. mul-1-negN/A

              \[\leadsto \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} \]
            6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

              \[\leadsto \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} - \left(\color{blue}{\left(\mathsf{neg}\left(\log im\right)\right)} \cdot -1\right) \cdot -1 \]
            14. distribute-lft-neg-outN/A

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

              \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \left(\log im \cdot -1\right) \cdot -1} \]
          8. Applied rewrites27.4%

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

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

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

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

              Alternative 7: 3.0% accurate, 4.6× speedup?

              \[\begin{array}{l} \\ \left(\frac{0.5}{im \cdot im} \cdot re\right) \cdot re \end{array} \]
              (FPCore (re im) :precision binary64 (* (* (/ 0.5 (* im im)) re) re))
              double code(double re, double im) {
              	return ((0.5 / (im * im)) * re) * re;
              }
              
              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 * im)) * re) * re
              end function
              
              public static double code(double re, double im) {
              	return ((0.5 / (im * im)) * re) * re;
              }
              
              def code(re, im):
              	return ((0.5 / (im * im)) * re) * re
              
              function code(re, im)
              	return Float64(Float64(Float64(0.5 / Float64(im * im)) * re) * re)
              end
              
              function tmp = code(re, im)
              	tmp = ((0.5 / (im * im)) * re) * re;
              end
              
              code[re_, im_] := N[(N[(N[(0.5 / N[(im * im), $MachinePrecision]), $MachinePrecision] * re), $MachinePrecision] * re), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              \left(\frac{0.5}{im \cdot im} \cdot re\right) \cdot re
              \end{array}
              
              Derivation
              1. Initial program 55.0%

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

                \[\leadsto \color{blue}{\log im} \]
              4. Step-by-step derivation
                1. lower-log.f6428.7

                  \[\leadsto \color{blue}{\log im} \]
              5. Applied rewrites28.7%

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

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

                  \[\leadsto \log im + \color{blue}{\frac{{re}^{2}}{{im}^{2}} \cdot \frac{1}{2}} \]
                2. fp-cancel-sign-sub-invN/A

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

                  \[\leadsto \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} \]
                4. log-recN/A

                  \[\leadsto \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} \]
                5. mul-1-negN/A

                  \[\leadsto \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} \]
                6. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                  \[\leadsto \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} - \left(\color{blue}{\left(\mathsf{neg}\left(\log im\right)\right)} \cdot -1\right) \cdot -1 \]
                14. distribute-lft-neg-outN/A

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

                  \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \left(\log im \cdot -1\right) \cdot -1} \]
              8. Applied rewrites27.4%

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

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

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

                Reproduce

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