math.log/1 on complex, real part

Percentage Accurate: 52.2% → 100.0%
Time: 7.8s
Alternatives: 8
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 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 52.2% 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 57.2%

    \[\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.2% accurate, 1.8× speedup?

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

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

    \[\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-/.f6428.9%

      \[\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. Simplified28.9%

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

Alternative 3: 26.2% accurate, 1.9× speedup?

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

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

    \[\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-/.f6427.9%

      \[\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. Simplified27.9%

    \[\leadsto \color{blue}{\log im + 0.5 \cdot \left(re \cdot \frac{\frac{re}{im}}{im}\right)} \]
  8. Final simplification27.9%

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

Alternative 4: 27.9% 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 57.2%

    \[\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.f6429.5%

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

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

Alternative 5: 3.3% accurate, 18.8× speedup?

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

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

    \[\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-/.f6427.9%

      \[\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. Simplified27.9%

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

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

    \[\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-/l*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{im \cdot \color{blue}{\left(\frac{im}{re} \cdot \frac{2}{re}\right)}} \]
  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 57.2%

    \[\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-/.f6427.9%

      \[\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. Simplified27.9%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{2} \cdot re}{im} \cdot \frac{1}{\color{blue}{\frac{im}{re}}} \]
    2. un-div-invN/A

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{re}{\frac{im}{re}}\right), \color{blue}{\left(\frac{\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.3%

      \[\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) \]
  14. Applied egg-rr3.3%

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

Alternative 7: 2.6% accurate, 23.0× speedup?

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

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

    \[\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-/.f6427.9%

      \[\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. Simplified27.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{\mathsf{neg}\left(\frac{1}{2}\right)}{\frac{\frac{im}{re}}{{\left({im}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}\right), re\right) \]
    18. pow-powN/A

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

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

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{\mathsf{neg}\left(\frac{1}{2}\right)}{\frac{\frac{im}{re}}{{im}^{-1}}}\right), re\right) \]
    21. inv-powN/A

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

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

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

    \[\leadsto \color{blue}{\frac{-0.5}{\frac{im}{\frac{re}{im}}}} \cdot re \]
  15. Final simplification2.7%

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

Alternative 8: 2.6% accurate, 23.0× speedup?

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

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

    \[\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-/.f6427.9%

      \[\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. Simplified27.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-0.5}{\frac{im}{re}}} \cdot \frac{re}{im} \]
  15. Final simplification2.7%

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

Reproduce

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