math.log/1 on complex, real part

Percentage Accurate: 52.8% → 99.7%
Time: 6.2s
Alternatives: 9
Speedup: 1.2×

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))));
}
real(8) function code(re, im)
    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 9 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.8% 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))));
}
real(8) function code(re, im)
    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: 99.7% accurate, 0.9× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re_m = \left|re\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \mathsf{fma}\left(0.5 \cdot \frac{\frac{re\_m}{im\_m}}{im\_m}, re\_m, \log im\_m\right) \end{array} \]
im_m = (fabs.f64 im)
re_m = (fabs.f64 re)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m)
 :precision binary64
 (fma (* 0.5 (/ (/ re_m im_m) im_m)) re_m (log im_m)))
im_m = fabs(im);
re_m = fabs(re);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return fma((0.5 * ((re_m / im_m) / im_m)), re_m, log(im_m));
}
im_m = abs(im)
re_m = abs(re)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return fma(Float64(0.5 * Float64(Float64(re_m / im_m) / im_m)), re_m, log(im_m))
end
im_m = N[Abs[im], $MachinePrecision]
re_m = N[Abs[re], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[(0.5 * N[(N[(re$95$m / im$95$m), $MachinePrecision] / im$95$m), $MachinePrecision]), $MachinePrecision] * re$95$m + N[Log[im$95$m], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re_m = \left|re\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\mathsf{fma}\left(0.5 \cdot \frac{\frac{re\_m}{im\_m}}{im\_m}, re\_m, \log im\_m\right)
\end{array}
Derivation
  1. Initial program 51.3%

    \[\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 + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \log im} \]
    2. *-lft-identityN/A

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(re \cdot \frac{1}{{im}^{2}}\right) \cdot \frac{1}{2}}, re, \log im\right) \]
    11. associate-/l*N/A

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{re}{im}}}{im} \cdot \frac{1}{2}, re, \log im\right) \]
    18. lower-log.f6424.6

      \[\leadsto \mathsf{fma}\left(\frac{\frac{re}{im}}{im} \cdot 0.5, re, \color{blue}{\log im}\right) \]
  5. Applied rewrites24.6%

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

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

Alternative 2: 99.3% accurate, 1.2× speedup?

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

    \[\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.f6426.8

      \[\leadsto \color{blue}{\log im} \]
  5. Applied rewrites26.8%

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

Alternative 3: 3.5% accurate, 2.5× speedup?

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

    \[\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 + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \log im} \]
    2. *-lft-identityN/A

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(re \cdot \frac{1}{{im}^{2}}\right) \cdot \frac{1}{2}}, re, \log im\right) \]
    11. associate-/l*N/A

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{re}{im}}}{im} \cdot \frac{1}{2}, re, \log im\right) \]
    18. lower-log.f6424.6

      \[\leadsto \mathsf{fma}\left(\frac{\frac{re}{im}}{im} \cdot 0.5, re, \color{blue}{\log im}\right) \]
  5. Applied rewrites24.6%

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

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

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

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

          \[\leadsto \frac{0.5}{im} \cdot \frac{1}{\frac{\frac{im}{re}}{\color{blue}{re}}} \]
        2. Final simplification3.3%

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

        Alternative 4: 3.5% accurate, 3.2× speedup?

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

          \[\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 + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
        4. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \log im} \]
          2. *-lft-identityN/A

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(re \cdot \frac{1}{{im}^{2}}\right) \cdot \frac{1}{2}}, re, \log im\right) \]
          11. associate-/l*N/A

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{re}{im}}}{im} \cdot \frac{1}{2}, re, \log im\right) \]
          18. lower-log.f6424.6

            \[\leadsto \mathsf{fma}\left(\frac{\frac{re}{im}}{im} \cdot 0.5, re, \color{blue}{\log im}\right) \]
        5. Applied rewrites24.6%

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

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

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

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

                \[\leadsto \frac{0.5}{im \cdot \color{blue}{\frac{\frac{im}{re}}{re}}} \]
              2. Final simplification3.3%

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

              Alternative 5: 3.5% accurate, 3.8× speedup?

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

                \[\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 + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
              4. Step-by-step derivation
                1. +-commutativeN/A

                  \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \log im} \]
                2. *-lft-identityN/A

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

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\color{blue}{\left(re \cdot \frac{1}{{im}^{2}}\right) \cdot \frac{1}{2}}, re, \log im\right) \]
                11. associate-/l*N/A

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{re}{im}}}{im} \cdot \frac{1}{2}, re, \log im\right) \]
                18. lower-log.f6424.6

                  \[\leadsto \mathsf{fma}\left(\frac{\frac{re}{im}}{im} \cdot 0.5, re, \color{blue}{\log im}\right) \]
              5. Applied rewrites24.6%

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

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

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

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

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

                  Alternative 6: 3.5% accurate, 3.8× speedup?

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

                    \[\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 + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
                  4. Step-by-step derivation
                    1. +-commutativeN/A

                      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \log im} \]
                    2. *-lft-identityN/A

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(re \cdot \frac{1}{{im}^{2}}\right) \cdot \frac{1}{2}}, re, \log im\right) \]
                    11. associate-/l*N/A

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{re}{im}}}{im} \cdot \frac{1}{2}, re, \log im\right) \]
                    18. lower-log.f6424.6

                      \[\leadsto \mathsf{fma}\left(\frac{\frac{re}{im}}{im} \cdot 0.5, re, \color{blue}{\log im}\right) \]
                  5. Applied rewrites24.6%

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

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

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

                    Alternative 7: 3.1% accurate, 4.3× speedup?

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

                      \[\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 + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
                    4. Step-by-step derivation
                      1. +-commutativeN/A

                        \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \log im} \]
                      2. *-lft-identityN/A

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

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(re \cdot \frac{1}{{im}^{2}}\right) \cdot \frac{1}{2}}, re, \log im\right) \]
                      11. associate-/l*N/A

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{re}{im}}}{im} \cdot \frac{1}{2}, re, \log im\right) \]
                      18. lower-log.f6424.6

                        \[\leadsto \mathsf{fma}\left(\frac{\frac{re}{im}}{im} \cdot 0.5, re, \color{blue}{\log im}\right) \]
                    5. Applied rewrites24.6%

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

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

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

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

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

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

                          Alternative 8: 3.1% accurate, 4.3× speedup?

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

                            \[\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 + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
                          4. Step-by-step derivation
                            1. +-commutativeN/A

                              \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \log im} \]
                            2. *-lft-identityN/A

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

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

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

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

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

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

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

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

                              \[\leadsto \mathsf{fma}\left(\color{blue}{\left(re \cdot \frac{1}{{im}^{2}}\right) \cdot \frac{1}{2}}, re, \log im\right) \]
                            11. associate-/l*N/A

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

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

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

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

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

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

                              \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{re}{im}}}{im} \cdot \frac{1}{2}, re, \log im\right) \]
                            18. lower-log.f6424.6

                              \[\leadsto \mathsf{fma}\left(\frac{\frac{re}{im}}{im} \cdot 0.5, re, \color{blue}{\log im}\right) \]
                          5. Applied rewrites24.6%

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

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

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

                                \[\leadsto \frac{re \cdot \frac{0.5}{im}}{-im} \cdot \left(-re\right) \]
                              2. Taylor expanded in re around 0

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

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

                                Alternative 9: 2.9% accurate, 4.6× speedup?

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

                                  \[\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 + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
                                4. Step-by-step derivation
                                  1. +-commutativeN/A

                                    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + \log im} \]
                                  2. *-lft-identityN/A

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

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

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

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

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

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

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

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

                                    \[\leadsto \mathsf{fma}\left(\color{blue}{\left(re \cdot \frac{1}{{im}^{2}}\right) \cdot \frac{1}{2}}, re, \log im\right) \]
                                  11. associate-/l*N/A

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

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

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

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

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

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

                                    \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{re}{im}}}{im} \cdot \frac{1}{2}, re, \log im\right) \]
                                  18. lower-log.f6424.6

                                    \[\leadsto \mathsf{fma}\left(\frac{\frac{re}{im}}{im} \cdot 0.5, re, \color{blue}{\log im}\right) \]
                                5. Applied rewrites24.6%

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

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

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

                                      \[\leadsto \frac{\left(re \cdot 0.5\right) \cdot re}{im \cdot \color{blue}{im}} \]
                                    2. Final simplification2.8%

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

                                    Reproduce

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