math.log/1 on complex, real part

Percentage Accurate: 52.5% → 100.0%
Time: 8.3s
Alternatives: 9
Speedup: 1.0×

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.5% 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: 100.0% accurate, 1.0× 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.1%

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

      \[\leadsto \mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right) \]
    3. hypot-lowering-hypot.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right) \]
  3. Simplified100.0%

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

Alternative 2: 27.8% accurate, 1.9× speedup?

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

\\
\log \left(im - \frac{re \cdot -0.5}{\frac{im}{re}}\right)
\end{array}
Derivation
  1. Initial program 55.1%

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

      \[\leadsto \mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right) \]
    3. hypot-lowering-hypot.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in im around inf

    \[\leadsto \mathsf{log.f64}\left(\color{blue}{\left(im \cdot \left(1 + \frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)\right)}\right) \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

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

      \[\leadsto \mathsf{log.f64}\left(\mathsf{*.f64}\left(im, \left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}} + 1\right)\right)\right) \]
    3. +-lowering-+.f64N/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{*.f64}\left(im, \mathsf{+.f64}\left(\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right), 1\right)\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{*.f64}\left(im, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\frac{{re}^{2}}{{im}^{2}}\right)\right), 1\right)\right)\right) \]
    5. unpow2N/A

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

      \[\leadsto \mathsf{log.f64}\left(\mathsf{*.f64}\left(im, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(re \cdot \frac{re}{{im}^{2}}\right)\right), 1\right)\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{*.f64}\left(im, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \left(\frac{re}{{im}^{2}}\right)\right)\right), 1\right)\right)\right) \]
    8. unpow2N/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{*.f64}\left(im, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \left(\frac{re}{im \cdot im}\right)\right)\right), 1\right)\right)\right) \]
    9. associate-/r*N/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{*.f64}\left(im, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \left(\frac{\frac{re}{im}}{im}\right)\right)\right), 1\right)\right)\right) \]
    10. /-lowering-/.f64N/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{*.f64}\left(im, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\left(\frac{re}{im}\right), im\right)\right)\right), 1\right)\right)\right) \]
    11. /-lowering-/.f6421.3%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{*.f64}\left(im, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, im\right), im\right)\right)\right), 1\right)\right)\right) \]
  7. Simplified21.3%

    \[\leadsto \log \color{blue}{\left(im \cdot \left(0.5 \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right) + 1\right)\right)} \]
  8. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \mathsf{log.f64}\left(\left(im \cdot \left(1 + \frac{1}{2} \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right)\right)\right)\right) \]
    2. distribute-rgt-inN/A

      \[\leadsto \mathsf{log.f64}\left(\left(1 \cdot im + \left(\frac{1}{2} \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right)\right) \cdot im\right)\right) \]
    3. fma-defineN/A

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

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{fma}\left(1, im, \left(\left(\frac{1}{2} \cdot re\right) \cdot \frac{\frac{re}{im}}{im}\right) \cdot im\right)\right)\right) \]
    5. div-invN/A

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

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

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{fma}\left(1, im, \left(\left(\frac{1}{2} \cdot re\right) \cdot \frac{re}{im}\right) \cdot \left(\frac{1}{im} \cdot im\right)\right)\right)\right) \]
    8. lft-mult-inverseN/A

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

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{fma}\left(1, im, \left(\frac{1}{2} \cdot re\right) \cdot \frac{re}{im}\right)\right)\right) \]
    10. remove-double-negN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{fma}\left(1, im, \mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\frac{1}{2} \cdot re\right) \cdot \frac{re}{im}\right)\right)\right)\right)\right)\right) \]
    11. distribute-rgt-neg-outN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{fma}\left(1, im, \mathsf{neg}\left(\left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\frac{re}{im}\right)\right)\right)\right)\right)\right) \]
    12. fmm-defN/A

      \[\leadsto \mathsf{log.f64}\left(\left(1 \cdot im - \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\frac{re}{im}\right)\right)\right)\right) \]
    13. *-lft-identityN/A

      \[\leadsto \mathsf{log.f64}\left(\left(im - \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\frac{re}{im}\right)\right)\right)\right) \]
    14. --lowering--.f64N/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{\_.f64}\left(im, \left(\left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\frac{re}{im}\right)\right)\right)\right)\right) \]
    15. distribute-rgt-neg-outN/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{\_.f64}\left(im, \left(\mathsf{neg}\left(\left(\frac{1}{2} \cdot re\right) \cdot \frac{re}{im}\right)\right)\right)\right) \]
    16. clear-numN/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{\_.f64}\left(im, \left(\mathsf{neg}\left(\left(\frac{1}{2} \cdot re\right) \cdot \frac{1}{\frac{im}{re}}\right)\right)\right)\right) \]
    17. un-div-invN/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{\_.f64}\left(im, \left(\mathsf{neg}\left(\frac{\frac{1}{2} \cdot re}{\frac{im}{re}}\right)\right)\right)\right) \]
    18. distribute-neg-fracN/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{\_.f64}\left(im, \left(\frac{\mathsf{neg}\left(\frac{1}{2} \cdot re\right)}{\frac{im}{re}}\right)\right)\right) \]
    19. /-lowering-/.f64N/A

      \[\leadsto \mathsf{log.f64}\left(\mathsf{\_.f64}\left(im, \mathsf{/.f64}\left(\left(\mathsf{neg}\left(\frac{1}{2} \cdot re\right)\right), \left(\frac{im}{re}\right)\right)\right)\right) \]
  9. Applied egg-rr21.7%

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

Alternative 3: 28.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \log im \end{array} \]
(FPCore (re im) :precision binary64 (log im))
double code(double re, double im) {
	return log(im);
}
real(8) function code(re, im)
    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.1%

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

      \[\leadsto \mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right) \]
    3. hypot-lowering-hypot.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right) \]
  3. Simplified100.0%

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

    \[\leadsto \color{blue}{\log im} \]
  6. Step-by-step derivation
    1. log-lowering-log.f6422.1%

      \[\leadsto \mathsf{log.f64}\left(im\right) \]
  7. Simplified22.1%

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

Alternative 4: 3.3% accurate, 18.8× speedup?

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

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

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

      \[\leadsto \mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right) \]
    3. hypot-lowering-hypot.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right) \]
  3. Simplified100.0%

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

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

      \[\leadsto \mathsf{+.f64}\left(\log im, \color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}\right) \]
    2. log-lowering-log.f64N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{{re}^{2}}{{im}^{2}}\right)}\right)\right) \]
    4. unpow2N/A

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{re}{{im}^{2}}\right)}\right)\right)\right) \]
    7. unpow2N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \left(\frac{\frac{re}{im}}{\color{blue}{im}}\right)\right)\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\left(\frac{re}{im}\right), \color{blue}{im}\right)\right)\right)\right) \]
    10. /-lowering-/.f6420.5%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, im\right), im\right)\right)\right)\right) \]
  7. Simplified20.5%

    \[\leadsto \color{blue}{\log im + 0.5 \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right)} \]
  8. Taylor expanded in im around 0

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
  9. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{2} \cdot {re}^{2}}{\color{blue}{{im}^{2}}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot {re}^{2}\right), \color{blue}{\left({im}^{2}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left({re}^{2}\right)\right), \left({\color{blue}{im}}^{2}\right)\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(re \cdot re\right)\right), \left({im}^{2}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left({im}^{2}\right)\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left(im \cdot \color{blue}{im}\right)\right) \]
    7. *-lowering-*.f642.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
  10. Simplified2.6%

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(re \cdot re\right)}{im \cdot im}} \]
  11. Step-by-step derivation
    1. clear-numN/A

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im \cdot im}{\left(\frac{1}{2} \cdot re\right) \cdot \color{blue}{re}}\right)\right) \]
    4. times-fracN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\frac{1}{2} \cdot re} \cdot \color{blue}{\frac{im}{re}}\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right) \cdot re} \cdot \frac{im}{re}\right)\right) \]
    6. distribute-lft-neg-inN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\mathsf{neg}\left(\frac{-1}{2} \cdot re\right)} \cdot \frac{im}{re}\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)} \cdot \frac{im}{re}\right)\right) \]
    8. associate-/r/N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\color{blue}{\frac{\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)}{\frac{im}{re}}}}\right)\right) \]
    9. distribute-neg-fracN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\mathsf{neg}\left(\frac{re \cdot \frac{-1}{2}}{\frac{im}{re}}\right)}\right)\right) \]
    10. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \color{blue}{\left(\mathsf{neg}\left(\frac{re \cdot \frac{-1}{2}}{\frac{im}{re}}\right)\right)}\right)\right) \]
    11. associate-/r/N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\mathsf{neg}\left(\frac{re \cdot \frac{-1}{2}}{im} \cdot re\right)\right)\right)\right) \]
    12. associate-*l/N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\mathsf{neg}\left(\frac{\left(re \cdot \frac{-1}{2}\right) \cdot re}{im}\right)\right)\right)\right) \]
    13. distribute-neg-fracN/A

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{\left(\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)\right) \cdot re}{im}\right)\right)\right) \]
    15. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{re \cdot \left(\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)\right)}{im}\right)\right)\right) \]
    16. associate-/l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(re \cdot \color{blue}{\frac{\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)}{im}}\right)\right)\right) \]
    17. clear-numN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(re \cdot \frac{1}{\color{blue}{\frac{im}{\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)}}}\right)\right)\right) \]
    18. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(re \cdot \frac{1}{\frac{im}{\mathsf{neg}\left(\frac{-1}{2} \cdot re\right)}}\right)\right)\right) \]
    19. distribute-lft-neg-inN/A

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(re \cdot \frac{1}{\frac{im}{\frac{1}{2} \cdot re}}\right)\right)\right) \]
    21. un-div-invN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{re}{\color{blue}{\frac{im}{\frac{1}{2} \cdot re}}}\right)\right)\right) \]
  12. Applied egg-rr3.2%

    \[\leadsto \color{blue}{\frac{1}{\frac{im}{\frac{re}{\frac{im}{re \cdot 0.5}}}}} \]
  13. Step-by-step derivation
    1. associate-/r*N/A

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{re}{\frac{im}{re}} \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \]
    3. clear-numN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{1}{\frac{\frac{im}{re}}{re}} \cdot \frac{1}{2}\right)\right)\right) \]
    4. associate-/r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{1}{\frac{im}{re \cdot re}} \cdot \frac{1}{2}\right)\right)\right) \]
    5. associate-*l/N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{1 \cdot \frac{1}{2}}{\color{blue}{\frac{im}{re \cdot re}}}\right)\right)\right) \]
    6. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{\frac{1}{2}}{\frac{\color{blue}{im}}{re \cdot re}}\right)\right)\right) \]
    7. /-lowering-/.f64N/A

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \mathsf{/.f64}\left(\frac{1}{2}, \left(\frac{\frac{im}{re}}{\color{blue}{re}}\right)\right)\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\left(\frac{im}{re}\right), \color{blue}{re}\right)\right)\right)\right) \]
    10. /-lowering-/.f643.2%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{/.f64}\left(im, re\right), re\right)\right)\right)\right) \]
  14. Applied egg-rr3.2%

    \[\leadsto \frac{1}{\frac{im}{\color{blue}{\frac{0.5}{\frac{\frac{im}{re}}{re}}}}} \]
  15. Add Preprocessing

Alternative 5: 3.3% accurate, 23.0× speedup?

\[\begin{array}{l} \\ \frac{\frac{re}{im \cdot \frac{2}{re}}}{im} \end{array} \]
(FPCore (re im) :precision binary64 (/ (/ re (* im (/ 2.0 re))) im))
double code(double re, double im) {
	return (re / (im * (2.0 / re))) / im;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (re / (im * (2.0d0 / re))) / im
end function
public static double code(double re, double im) {
	return (re / (im * (2.0 / re))) / im;
}
def code(re, im):
	return (re / (im * (2.0 / re))) / im
function code(re, im)
	return Float64(Float64(re / Float64(im * Float64(2.0 / re))) / im)
end
function tmp = code(re, im)
	tmp = (re / (im * (2.0 / re))) / im;
end
code[re_, im_] := N[(N[(re / N[(im * N[(2.0 / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / im), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{re}{im \cdot \frac{2}{re}}}{im}
\end{array}
Derivation
  1. Initial program 55.1%

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

      \[\leadsto \mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right) \]
    3. hypot-lowering-hypot.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right) \]
  3. Simplified100.0%

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

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

      \[\leadsto \mathsf{+.f64}\left(\log im, \color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}\right) \]
    2. log-lowering-log.f64N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{{re}^{2}}{{im}^{2}}\right)}\right)\right) \]
    4. unpow2N/A

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{re}{{im}^{2}}\right)}\right)\right)\right) \]
    7. unpow2N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \left(\frac{\frac{re}{im}}{\color{blue}{im}}\right)\right)\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\left(\frac{re}{im}\right), \color{blue}{im}\right)\right)\right)\right) \]
    10. /-lowering-/.f6420.5%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, im\right), im\right)\right)\right)\right) \]
  7. Simplified20.5%

    \[\leadsto \color{blue}{\log im + 0.5 \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right)} \]
  8. Taylor expanded in im around 0

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
  9. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{2} \cdot {re}^{2}}{\color{blue}{{im}^{2}}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot {re}^{2}\right), \color{blue}{\left({im}^{2}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left({re}^{2}\right)\right), \left({\color{blue}{im}}^{2}\right)\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(re \cdot re\right)\right), \left({im}^{2}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left({im}^{2}\right)\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left(im \cdot \color{blue}{im}\right)\right) \]
    7. *-lowering-*.f642.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
  10. Simplified2.6%

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(re \cdot re\right)}{im \cdot im}} \]
  11. Step-by-step derivation
    1. clear-numN/A

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im \cdot im}{\left(\frac{1}{2} \cdot re\right) \cdot \color{blue}{re}}\right)\right) \]
    4. times-fracN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\frac{1}{2} \cdot re} \cdot \color{blue}{\frac{im}{re}}\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right) \cdot re} \cdot \frac{im}{re}\right)\right) \]
    6. distribute-lft-neg-inN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\mathsf{neg}\left(\frac{-1}{2} \cdot re\right)} \cdot \frac{im}{re}\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)} \cdot \frac{im}{re}\right)\right) \]
    8. associate-/r/N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\color{blue}{\frac{\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)}{\frac{im}{re}}}}\right)\right) \]
    9. distribute-neg-fracN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{im}{\mathsf{neg}\left(\frac{re \cdot \frac{-1}{2}}{\frac{im}{re}}\right)}\right)\right) \]
    10. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \color{blue}{\left(\mathsf{neg}\left(\frac{re \cdot \frac{-1}{2}}{\frac{im}{re}}\right)\right)}\right)\right) \]
    11. associate-/r/N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\mathsf{neg}\left(\frac{re \cdot \frac{-1}{2}}{im} \cdot re\right)\right)\right)\right) \]
    12. associate-*l/N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\mathsf{neg}\left(\frac{\left(re \cdot \frac{-1}{2}\right) \cdot re}{im}\right)\right)\right)\right) \]
    13. distribute-neg-fracN/A

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{\left(\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)\right) \cdot re}{im}\right)\right)\right) \]
    15. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{re \cdot \left(\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)\right)}{im}\right)\right)\right) \]
    16. associate-/l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(re \cdot \color{blue}{\frac{\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)}{im}}\right)\right)\right) \]
    17. clear-numN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(re \cdot \frac{1}{\color{blue}{\frac{im}{\mathsf{neg}\left(re \cdot \frac{-1}{2}\right)}}}\right)\right)\right) \]
    18. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(re \cdot \frac{1}{\frac{im}{\mathsf{neg}\left(\frac{-1}{2} \cdot re\right)}}\right)\right)\right) \]
    19. distribute-lft-neg-inN/A

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(re \cdot \frac{1}{\frac{im}{\frac{1}{2} \cdot re}}\right)\right)\right) \]
    21. un-div-invN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(im, \left(\frac{re}{\color{blue}{\frac{im}{\frac{1}{2} \cdot re}}}\right)\right)\right) \]
  12. Applied egg-rr3.2%

    \[\leadsto \color{blue}{\frac{1}{\frac{im}{\frac{re}{\frac{im}{re \cdot 0.5}}}}} \]
  13. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{\frac{re}{\frac{im}{re \cdot \frac{1}{2}}}}{\color{blue}{im}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{re}{\frac{im}{re \cdot \frac{1}{2}}}\right), \color{blue}{im}\right) \]
    3. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, \left(\frac{im}{re \cdot \frac{1}{2}}\right)\right), im\right) \]
    4. div-invN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, \left(im \cdot \frac{1}{re \cdot \frac{1}{2}}\right)\right), im\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, \mathsf{*.f64}\left(im, \left(\frac{1}{re \cdot \frac{1}{2}}\right)\right)\right), im\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, \mathsf{*.f64}\left(im, \left(\frac{1}{\frac{1}{2} \cdot re}\right)\right)\right), im\right) \]
    7. associate-/r*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, \mathsf{*.f64}\left(im, \left(\frac{\frac{1}{\frac{1}{2}}}{re}\right)\right)\right), im\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, \mathsf{*.f64}\left(im, \left(\frac{2}{re}\right)\right)\right), im\right) \]
    9. /-lowering-/.f643.2%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, \mathsf{*.f64}\left(im, \mathsf{/.f64}\left(2, re\right)\right)\right), im\right) \]
  14. Applied egg-rr3.2%

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

Alternative 6: 3.3% accurate, 23.0× speedup?

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

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

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

      \[\leadsto \mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right) \]
    3. hypot-lowering-hypot.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right) \]
  3. Simplified100.0%

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

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

      \[\leadsto \mathsf{+.f64}\left(\log im, \color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}\right) \]
    2. log-lowering-log.f64N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{{re}^{2}}{{im}^{2}}\right)}\right)\right) \]
    4. unpow2N/A

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{re}{{im}^{2}}\right)}\right)\right)\right) \]
    7. unpow2N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \left(\frac{\frac{re}{im}}{\color{blue}{im}}\right)\right)\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\left(\frac{re}{im}\right), \color{blue}{im}\right)\right)\right)\right) \]
    10. /-lowering-/.f6420.5%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, im\right), im\right)\right)\right)\right) \]
  7. Simplified20.5%

    \[\leadsto \color{blue}{\log im + 0.5 \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right)} \]
  8. Taylor expanded in im around 0

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
  9. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{2} \cdot {re}^{2}}{\color{blue}{{im}^{2}}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot {re}^{2}\right), \color{blue}{\left({im}^{2}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left({re}^{2}\right)\right), \left({\color{blue}{im}}^{2}\right)\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(re \cdot re\right)\right), \left({im}^{2}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left({im}^{2}\right)\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left(im \cdot \color{blue}{im}\right)\right) \]
    7. *-lowering-*.f642.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
  10. Simplified2.6%

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(re \cdot re\right)}{im \cdot im}} \]
  11. Step-by-step derivation
    1. *-commutativeN/A

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

      \[\leadsto \frac{re \cdot re}{im} \cdot \color{blue}{\frac{\frac{1}{2}}{im}} \]
    3. *-lowering-*.f64N/A

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

      \[\leadsto \mathsf{*.f64}\left(\left(re \cdot \frac{re}{im}\right), \left(\frac{\color{blue}{\frac{1}{2}}}{im}\right)\right) \]
    5. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(\left(re \cdot \frac{1}{\frac{im}{re}}\right), \left(\frac{\frac{1}{2}}{im}\right)\right) \]
    6. div-invN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{re}{\frac{im}{re}}\right), \left(\frac{\color{blue}{\frac{1}{2}}}{im}\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(re, \left(\frac{im}{re}\right)\right), \left(\frac{\color{blue}{\frac{1}{2}}}{im}\right)\right) \]
    8. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(re, \mathsf{/.f64}\left(im, re\right)\right), \left(\frac{\frac{1}{2}}{im}\right)\right) \]
    9. /-lowering-/.f643.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(re, \mathsf{/.f64}\left(im, re\right)\right), \mathsf{/.f64}\left(\frac{1}{2}, \color{blue}{im}\right)\right) \]
  12. Applied egg-rr3.2%

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

Alternative 7: 3.3% accurate, 23.0× speedup?

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

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

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

      \[\leadsto \mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right) \]
    3. hypot-lowering-hypot.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right) \]
  3. Simplified100.0%

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

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

      \[\leadsto \mathsf{+.f64}\left(\log im, \color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}\right) \]
    2. log-lowering-log.f64N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{{re}^{2}}{{im}^{2}}\right)}\right)\right) \]
    4. unpow2N/A

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{re}{{im}^{2}}\right)}\right)\right)\right) \]
    7. unpow2N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \left(\frac{\frac{re}{im}}{\color{blue}{im}}\right)\right)\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\left(\frac{re}{im}\right), \color{blue}{im}\right)\right)\right)\right) \]
    10. /-lowering-/.f6420.5%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, im\right), im\right)\right)\right)\right) \]
  7. Simplified20.5%

    \[\leadsto \color{blue}{\log im + 0.5 \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right)} \]
  8. Taylor expanded in im around 0

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
  9. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{2} \cdot {re}^{2}}{\color{blue}{{im}^{2}}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot {re}^{2}\right), \color{blue}{\left({im}^{2}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left({re}^{2}\right)\right), \left({\color{blue}{im}}^{2}\right)\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(re \cdot re\right)\right), \left({im}^{2}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left({im}^{2}\right)\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left(im \cdot \color{blue}{im}\right)\right) \]
    7. *-lowering-*.f642.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
  10. Simplified2.6%

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(re \cdot re\right)}{im \cdot im}} \]
  11. Step-by-step derivation
    1. associate-/l*N/A

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{re \cdot re}{im \cdot im}} \]
    2. times-fracN/A

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

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

      \[\leadsto \left(\frac{\frac{-1}{2}}{-1} \cdot \frac{re}{im}\right) \cdot \frac{re}{im} \]
    5. times-fracN/A

      \[\leadsto \frac{\frac{-1}{2} \cdot re}{-1 \cdot im} \cdot \frac{\color{blue}{re}}{im} \]
    6. *-commutativeN/A

      \[\leadsto \frac{re \cdot \frac{-1}{2}}{-1 \cdot im} \cdot \frac{re}{im} \]
    7. neg-mul-1N/A

      \[\leadsto \frac{re \cdot \frac{-1}{2}}{\mathsf{neg}\left(im\right)} \cdot \frac{re}{im} \]
    8. *-lowering-*.f64N/A

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

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

      \[\leadsto \mathsf{*.f64}\left(\left(re \cdot \frac{\mathsf{neg}\left(\frac{1}{2}\right)}{\mathsf{neg}\left(im\right)}\right), \left(\frac{re}{im}\right)\right) \]
    11. frac-2negN/A

      \[\leadsto \mathsf{*.f64}\left(\left(re \cdot \frac{\frac{1}{2}}{im}\right), \left(\frac{re}{im}\right)\right) \]
    12. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(\left(re \cdot \frac{1}{\frac{im}{\frac{1}{2}}}\right), \left(\frac{re}{im}\right)\right) \]
    13. un-div-invN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{re}{\frac{im}{\frac{1}{2}}}\right), \left(\frac{\color{blue}{re}}{im}\right)\right) \]
    14. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(re, \left(\frac{im}{\frac{1}{2}}\right)\right), \left(\frac{\color{blue}{re}}{im}\right)\right) \]
    15. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(re, \mathsf{/.f64}\left(im, \frac{1}{2}\right)\right), \left(\frac{re}{im}\right)\right) \]
    16. /-lowering-/.f643.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(re, \mathsf{/.f64}\left(im, \frac{1}{2}\right)\right), \mathsf{/.f64}\left(re, \color{blue}{im}\right)\right) \]
  12. Applied egg-rr3.2%

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

Alternative 8: 3.0% accurate, 23.0× speedup?

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

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

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

      \[\leadsto \mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right) \]
    3. hypot-lowering-hypot.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right) \]
  3. Simplified100.0%

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

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

      \[\leadsto \mathsf{+.f64}\left(\log im, \color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}\right) \]
    2. log-lowering-log.f64N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{{re}^{2}}{{im}^{2}}\right)}\right)\right) \]
    4. unpow2N/A

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{re}{{im}^{2}}\right)}\right)\right)\right) \]
    7. unpow2N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \left(\frac{\frac{re}{im}}{\color{blue}{im}}\right)\right)\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\left(\frac{re}{im}\right), \color{blue}{im}\right)\right)\right)\right) \]
    10. /-lowering-/.f6420.5%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, im\right), im\right)\right)\right)\right) \]
  7. Simplified20.5%

    \[\leadsto \color{blue}{\log im + 0.5 \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right)} \]
  8. Taylor expanded in im around 0

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
  9. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{2} \cdot {re}^{2}}{\color{blue}{{im}^{2}}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot {re}^{2}\right), \color{blue}{\left({im}^{2}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left({re}^{2}\right)\right), \left({\color{blue}{im}}^{2}\right)\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(re \cdot re\right)\right), \left({im}^{2}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left({im}^{2}\right)\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left(im \cdot \color{blue}{im}\right)\right) \]
    7. *-lowering-*.f642.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
  10. Simplified2.6%

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(re \cdot re\right)}{im \cdot im}} \]
  11. Step-by-step derivation
    1. *-commutativeN/A

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{2} \cdot \frac{re}{im \cdot im}\right), \color{blue}{re}\right) \]
    8. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{2} \cdot \frac{1}{\frac{im \cdot im}{re}}\right), re\right) \]
    9. un-div-invN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{2}}{\frac{im \cdot im}{re}}\right), re\right) \]
    10. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, \left(\frac{im \cdot im}{re}\right)\right), re\right) \]
    11. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\left(im \cdot im\right), re\right)\right), re\right) \]
    12. *-lowering-*.f642.8%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(im, im\right), re\right)\right), re\right) \]
  12. Applied egg-rr2.8%

    \[\leadsto \color{blue}{\frac{0.5}{\frac{im \cdot im}{re}} \cdot re} \]
  13. Final simplification2.8%

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

Alternative 9: 2.8% accurate, 23.0× speedup?

\[\begin{array}{l} \\ \frac{0.5}{im \cdot im} \cdot \left(re \cdot re\right) \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);
}
real(8) function code(re, im)
    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(0.5 / Float64(im * im)) * Float64(re * re))
end
function tmp = code(re, im)
	tmp = (0.5 / (im * im)) * (re * re);
end
code[re_, im_] := N[(N[(0.5 / N[(im * im), $MachinePrecision]), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{0.5}{im \cdot im} \cdot \left(re \cdot re\right)
\end{array}
Derivation
  1. Initial program 55.1%

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

      \[\leadsto \mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right) \]
    2. hypot-defineN/A

      \[\leadsto \mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right) \]
    3. hypot-lowering-hypot.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right) \]
  3. Simplified100.0%

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

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

      \[\leadsto \mathsf{+.f64}\left(\log im, \color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}\right)}\right) \]
    2. log-lowering-log.f64N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{{re}^{2}}{{im}^{2}}\right)}\right)\right) \]
    4. unpow2N/A

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{re}{{im}^{2}}\right)}\right)\right)\right) \]
    7. unpow2N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \left(\frac{\frac{re}{im}}{\color{blue}{im}}\right)\right)\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\left(\frac{re}{im}\right), \color{blue}{im}\right)\right)\right)\right) \]
    10. /-lowering-/.f6420.5%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \mathsf{/.f64}\left(\mathsf{/.f64}\left(re, im\right), im\right)\right)\right)\right) \]
  7. Simplified20.5%

    \[\leadsto \color{blue}{\log im + 0.5 \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right)} \]
  8. Taylor expanded in im around 0

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{re}^{2}}{{im}^{2}}} \]
  9. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{2} \cdot {re}^{2}}{\color{blue}{{im}^{2}}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot {re}^{2}\right), \color{blue}{\left({im}^{2}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left({re}^{2}\right)\right), \left({\color{blue}{im}}^{2}\right)\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(re \cdot re\right)\right), \left({im}^{2}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left({im}^{2}\right)\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \left(im \cdot \color{blue}{im}\right)\right) \]
    7. *-lowering-*.f642.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
  10. Simplified2.6%

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(re \cdot re\right)}{im \cdot im}} \]
  11. Step-by-step derivation
    1. *-commutativeN/A

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

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

      \[\leadsto \frac{\frac{1}{2}}{im \cdot im} \cdot \color{blue}{\left(re \cdot re\right)} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{2}}{im \cdot im}\right), \color{blue}{\left(re \cdot re\right)}\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, \left(im \cdot im\right)\right), \left(\color{blue}{re} \cdot re\right)\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(im, im\right)\right), \left(re \cdot re\right)\right) \]
    7. *-lowering-*.f642.6%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(im, im\right)\right), \mathsf{*.f64}\left(re, \color{blue}{re}\right)\right) \]
  12. Applied egg-rr2.6%

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

Reproduce

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