math.cube on complex, imaginary part

Percentage Accurate: 82.9% → 99.3%
Time: 6.8s
Alternatives: 10
Speedup: 1.3×

Specification

?
\[\begin{array}{l} \\ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (+
  (* (- (* x.re x.re) (* x.im x.im)) x.im)
  (* (+ (* x.re x.im) (* x.im x.re)) x.re)))
double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = (((x_46re * x_46re) - (x_46im * x_46im)) * x_46im) + (((x_46re * x_46im) + (x_46im * x_46re)) * x_46re)
end function
public static double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
def code(x_46_re, x_46_im):
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re)
function code(x_46_re, x_46_im)
	return Float64(Float64(Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im)) * x_46_im) + Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_re))
end
function tmp = code(x_46_re, x_46_im)
	tmp = (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
end
code[x$46$re_, x$46$im_] := N[(N[(N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision] + N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\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 10 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: 82.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (+
  (* (- (* x.re x.re) (* x.im x.im)) x.im)
  (* (+ (* x.re x.im) (* x.im x.re)) x.re)))
double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = (((x_46re * x_46re) - (x_46im * x_46im)) * x_46im) + (((x_46re * x_46im) + (x_46im * x_46re)) * x_46re)
end function
public static double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
def code(x_46_re, x_46_im):
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re)
function code(x_46_re, x_46_im)
	return Float64(Float64(Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im)) * x_46_im) + Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_re))
end
function tmp = code(x_46_re, x_46_im)
	tmp = (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
end
code[x$46$re_, x$46$im_] := N[(N[(N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision] + N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\end{array}

Alternative 1: 99.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \leq -3.4 \cdot 10^{+119} \lor \neg \left(x.im \leq 4 \cdot 10^{+93}\right):\\ \;\;\;\;-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(3 \cdot \left(x.im \cdot x.re\right)\right) - {x.im}^{3}\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (or (<= x.im -3.4e+119) (not (<= x.im 4e+93)))
   (+ -3.0 (* x.im (* (+ x.im x.re) (- x.re x.im))))
   (- (* x.re (* 3.0 (* x.im x.re))) (pow x.im 3.0))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -3.4e+119) || !(x_46_im <= 4e+93)) {
		tmp = -3.0 + (x_46_im * ((x_46_im + x_46_re) * (x_46_re - x_46_im)));
	} else {
		tmp = (x_46_re * (3.0 * (x_46_im * x_46_re))) - pow(x_46_im, 3.0);
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if ((x_46im <= (-3.4d+119)) .or. (.not. (x_46im <= 4d+93))) then
        tmp = (-3.0d0) + (x_46im * ((x_46im + x_46re) * (x_46re - x_46im)))
    else
        tmp = (x_46re * (3.0d0 * (x_46im * x_46re))) - (x_46im ** 3.0d0)
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -3.4e+119) || !(x_46_im <= 4e+93)) {
		tmp = -3.0 + (x_46_im * ((x_46_im + x_46_re) * (x_46_re - x_46_im)));
	} else {
		tmp = (x_46_re * (3.0 * (x_46_im * x_46_re))) - Math.pow(x_46_im, 3.0);
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if (x_46_im <= -3.4e+119) or not (x_46_im <= 4e+93):
		tmp = -3.0 + (x_46_im * ((x_46_im + x_46_re) * (x_46_re - x_46_im)))
	else:
		tmp = (x_46_re * (3.0 * (x_46_im * x_46_re))) - math.pow(x_46_im, 3.0)
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if ((x_46_im <= -3.4e+119) || !(x_46_im <= 4e+93))
		tmp = Float64(-3.0 + Float64(x_46_im * Float64(Float64(x_46_im + x_46_re) * Float64(x_46_re - x_46_im))));
	else
		tmp = Float64(Float64(x_46_re * Float64(3.0 * Float64(x_46_im * x_46_re))) - (x_46_im ^ 3.0));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	tmp = 0.0;
	if ((x_46_im <= -3.4e+119) || ~((x_46_im <= 4e+93)))
		tmp = -3.0 + (x_46_im * ((x_46_im + x_46_re) * (x_46_re - x_46_im)));
	else
		tmp = (x_46_re * (3.0 * (x_46_im * x_46_re))) - (x_46_im ^ 3.0);
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[Or[LessEqual[x$46$im, -3.4e+119], N[Not[LessEqual[x$46$im, 4e+93]], $MachinePrecision]], N[(-3.0 + N[(x$46$im * N[(N[(x$46$im + x$46$re), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$46$re * N[(3.0 * N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[x$46$im, 3.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq -3.4 \cdot 10^{+119} \lor \neg \left(x.im \leq 4 \cdot 10^{+93}\right):\\
\;\;\;\;-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x.re \cdot \left(3 \cdot \left(x.im \cdot x.re\right)\right) - {x.im}^{3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < -3.40000000000000013e119 or 4.00000000000000017e93 < x.im

    1. Initial program 68.2%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. *-commutative68.2%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re \]
      2. flip-+0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}} \cdot x.re \]
      3. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      4. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{x.im \cdot x.im - x.im \cdot x.im}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      5. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{0}} \cdot x.re \]
      6. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{x.im - x.im}} \cdot x.re \]
      7. flip-+75.3%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.im + x.im\right)} \cdot x.re \]
      8. *-commutative75.3%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{x.re \cdot \left(x.im + x.im\right)} \]
      9. distribute-lft-in75.3%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    3. Applied egg-rr75.3%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    4. Step-by-step derivation
      1. +-commutative75.3%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
      2. add-cube-cbrt75.3%

        \[\leadsto \color{blue}{\left(\sqrt[3]{x.re \cdot x.im + x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}\right) \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}} + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im \]
      3. fma-def75.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{x.re \cdot x.im + x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}, \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}, \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im\right)} \]
    5. Applied egg-rr0.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{0}{0}, \frac{0}{0}, x.im \cdot \left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)\right)} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)} \]

    if -3.40000000000000013e119 < x.im < 4.00000000000000017e93

    1. Initial program 92.6%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. +-commutative92.6%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
      2. *-commutative92.6%

        \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} \]
      3. sub-neg92.6%

        \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \color{blue}{\left(x.re \cdot x.re + \left(-x.im \cdot x.im\right)\right)} \]
      4. distribute-lft-in92.6%

        \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot \left(x.re \cdot x.re\right) + x.im \cdot \left(-x.im \cdot x.im\right)\right)} \]
      5. associate-+r+92.6%

        \[\leadsto \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + x.im \cdot \left(-x.im \cdot x.im\right)} \]
      6. distribute-rgt-neg-out92.6%

        \[\leadsto \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + \color{blue}{\left(-x.im \cdot \left(x.im \cdot x.im\right)\right)} \]
      7. unsub-neg92.6%

        \[\leadsto \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right)} \]
      8. associate-*r*99.7%

        \[\leadsto \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot x.re\right) \cdot x.re}\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
      9. distribute-rgt-out99.7%

        \[\leadsto \color{blue}{x.re \cdot \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) + x.im \cdot x.re\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
      10. *-commutative99.7%

        \[\leadsto x.re \cdot \left(\left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
      11. count-299.7%

        \[\leadsto x.re \cdot \left(\color{blue}{2 \cdot \left(x.im \cdot x.re\right)} + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
      12. distribute-lft1-in99.7%

        \[\leadsto x.re \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \left(x.im \cdot x.re\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
      13. metadata-eval99.7%

        \[\leadsto x.re \cdot \left(\color{blue}{3} \cdot \left(x.im \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
      14. *-commutative99.7%

        \[\leadsto x.re \cdot \color{blue}{\left(\left(x.im \cdot x.re\right) \cdot 3\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
      15. *-commutative99.7%

        \[\leadsto x.re \cdot \left(\color{blue}{\left(x.re \cdot x.im\right)} \cdot 3\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
      16. associate-*r*99.7%

        \[\leadsto x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 3\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
      17. cube-unmult99.8%

        \[\leadsto x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - \color{blue}{{x.im}^{3}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3}} \]
    4. Taylor expanded in x.re around 0 99.8%

      \[\leadsto x.re \cdot \color{blue}{\left(3 \cdot \left(x.re \cdot x.im\right)\right)} - {x.im}^{3} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq -3.4 \cdot 10^{+119} \lor \neg \left(x.im \leq 4 \cdot 10^{+93}\right):\\ \;\;\;\;-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(3 \cdot \left(x.im \cdot x.re\right)\right) - {x.im}^{3}\\ \end{array} \]

Alternative 2: 93.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + x.re \cdot \left(x.im \cdot x.re + x.im \cdot x.re\right)\\ \mathbf{if}\;t_0 \leq 4 \cdot 10^{+304}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re + x.re\right)\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (let* ((t_0
         (+
          (* x.im (- (* x.re x.re) (* x.im x.im)))
          (* x.re (+ (* x.im x.re) (* x.im x.re))))))
   (if (<= t_0 4e+304)
     t_0
     (* x.im (+ (* (+ x.im x.re) (- x.re x.im)) (+ x.re x.re))))))
double code(double x_46_re, double x_46_im) {
	double t_0 = (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) + (x_46_re * ((x_46_im * x_46_re) + (x_46_im * x_46_re)));
	double tmp;
	if (t_0 <= 4e+304) {
		tmp = t_0;
	} else {
		tmp = x_46_im * (((x_46_im + x_46_re) * (x_46_re - x_46_im)) + (x_46_re + x_46_re));
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x_46im * ((x_46re * x_46re) - (x_46im * x_46im))) + (x_46re * ((x_46im * x_46re) + (x_46im * x_46re)))
    if (t_0 <= 4d+304) then
        tmp = t_0
    else
        tmp = x_46im * (((x_46im + x_46re) * (x_46re - x_46im)) + (x_46re + x_46re))
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im) {
	double t_0 = (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) + (x_46_re * ((x_46_im * x_46_re) + (x_46_im * x_46_re)));
	double tmp;
	if (t_0 <= 4e+304) {
		tmp = t_0;
	} else {
		tmp = x_46_im * (((x_46_im + x_46_re) * (x_46_re - x_46_im)) + (x_46_re + x_46_re));
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	t_0 = (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) + (x_46_re * ((x_46_im * x_46_re) + (x_46_im * x_46_re)))
	tmp = 0
	if t_0 <= 4e+304:
		tmp = t_0
	else:
		tmp = x_46_im * (((x_46_im + x_46_re) * (x_46_re - x_46_im)) + (x_46_re + x_46_re))
	return tmp
function code(x_46_re, x_46_im)
	t_0 = Float64(Float64(x_46_im * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im))) + Float64(x_46_re * Float64(Float64(x_46_im * x_46_re) + Float64(x_46_im * x_46_re))))
	tmp = 0.0
	if (t_0 <= 4e+304)
		tmp = t_0;
	else
		tmp = Float64(x_46_im * Float64(Float64(Float64(x_46_im + x_46_re) * Float64(x_46_re - x_46_im)) + Float64(x_46_re + x_46_re)));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	t_0 = (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) + (x_46_re * ((x_46_im * x_46_re) + (x_46_im * x_46_re)));
	tmp = 0.0;
	if (t_0 <= 4e+304)
		tmp = t_0;
	else
		tmp = x_46_im * (((x_46_im + x_46_re) * (x_46_re - x_46_im)) + (x_46_re + x_46_re));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := Block[{t$95$0 = N[(N[(x$46$im * N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x$46$re * N[(N[(x$46$im * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 4e+304], t$95$0, N[(x$46$im * N[(N[(N[(x$46$im + x$46$re), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision] + N[(x$46$re + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + x.re \cdot \left(x.im \cdot x.re + x.im \cdot x.re\right)\\
\mathbf{if}\;t_0 \leq 4 \cdot 10^{+304}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re + x.re\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.im) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.re)) < 3.9999999999999998e304

    1. Initial program 96.7%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]

    if 3.9999999999999998e304 < (+.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.im) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.re))

    1. Initial program 55.7%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. *-commutative55.7%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re \]
      2. flip-+0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}} \cdot x.re \]
      3. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      4. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{x.im \cdot x.im - x.im \cdot x.im}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      5. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{0}} \cdot x.re \]
      6. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{x.im - x.im}} \cdot x.re \]
      7. flip-+62.3%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.im + x.im\right)} \cdot x.re \]
      8. *-commutative62.3%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{x.re \cdot \left(x.im + x.im\right)} \]
      9. distribute-lft-in62.3%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    3. Applied egg-rr62.3%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    4. Step-by-step derivation
      1. +-commutative62.3%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
      2. distribute-rgt-out62.3%

        \[\leadsto \color{blue}{x.im \cdot \left(x.re + x.re\right)} + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im \]
      3. *-commutative62.3%

        \[\leadsto x.im \cdot \left(x.re + x.re\right) + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} \]
      4. distribute-lft-out71.5%

        \[\leadsto \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right)\right)} \]
      5. difference-of-squares91.2%

        \[\leadsto x.im \cdot \left(\left(x.re + x.re\right) + \color{blue}{\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)}\right) \]
    5. Applied egg-rr91.2%

      \[\leadsto \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + x.re \cdot \left(x.im \cdot x.re + x.im \cdot x.re\right) \leq 4 \cdot 10^{+304}:\\ \;\;\;\;x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + x.re \cdot \left(x.im \cdot x.re + x.im \cdot x.re\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re + x.re\right)\right)\\ \end{array} \]

Alternative 3: 87.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \leq -32000000000000:\\ \;\;\;\;x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re \cdot \left(x.im + x.re\right) - x.im \cdot \left(x.im + x.re\right)\right)\right)\\ \mathbf{elif}\;x.im \leq 7.8 \cdot 10^{-97}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re + \left(x.re + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re + x.re\right)\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (<= x.im -32000000000000.0)
   (* x.im (+ (+ x.re x.re) (- (* x.re (+ x.im x.re)) (* x.im (+ x.im x.re)))))
   (if (<= x.im 7.8e-97)
     (* (* x.im x.re) (+ x.re (+ x.re x.re)))
     (* x.im (+ (* (+ x.im x.re) (- x.re x.im)) (+ x.re x.re))))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if (x_46_im <= -32000000000000.0) {
		tmp = x_46_im * ((x_46_re + x_46_re) + ((x_46_re * (x_46_im + x_46_re)) - (x_46_im * (x_46_im + x_46_re))));
	} else if (x_46_im <= 7.8e-97) {
		tmp = (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re));
	} else {
		tmp = x_46_im * (((x_46_im + x_46_re) * (x_46_re - x_46_im)) + (x_46_re + x_46_re));
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if (x_46im <= (-32000000000000.0d0)) then
        tmp = x_46im * ((x_46re + x_46re) + ((x_46re * (x_46im + x_46re)) - (x_46im * (x_46im + x_46re))))
    else if (x_46im <= 7.8d-97) then
        tmp = (x_46im * x_46re) * (x_46re + (x_46re + x_46re))
    else
        tmp = x_46im * (((x_46im + x_46re) * (x_46re - x_46im)) + (x_46re + x_46re))
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im) {
	double tmp;
	if (x_46_im <= -32000000000000.0) {
		tmp = x_46_im * ((x_46_re + x_46_re) + ((x_46_re * (x_46_im + x_46_re)) - (x_46_im * (x_46_im + x_46_re))));
	} else if (x_46_im <= 7.8e-97) {
		tmp = (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re));
	} else {
		tmp = x_46_im * (((x_46_im + x_46_re) * (x_46_re - x_46_im)) + (x_46_re + x_46_re));
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if x_46_im <= -32000000000000.0:
		tmp = x_46_im * ((x_46_re + x_46_re) + ((x_46_re * (x_46_im + x_46_re)) - (x_46_im * (x_46_im + x_46_re))))
	elif x_46_im <= 7.8e-97:
		tmp = (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re))
	else:
		tmp = x_46_im * (((x_46_im + x_46_re) * (x_46_re - x_46_im)) + (x_46_re + x_46_re))
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if (x_46_im <= -32000000000000.0)
		tmp = Float64(x_46_im * Float64(Float64(x_46_re + x_46_re) + Float64(Float64(x_46_re * Float64(x_46_im + x_46_re)) - Float64(x_46_im * Float64(x_46_im + x_46_re)))));
	elseif (x_46_im <= 7.8e-97)
		tmp = Float64(Float64(x_46_im * x_46_re) * Float64(x_46_re + Float64(x_46_re + x_46_re)));
	else
		tmp = Float64(x_46_im * Float64(Float64(Float64(x_46_im + x_46_re) * Float64(x_46_re - x_46_im)) + Float64(x_46_re + x_46_re)));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	tmp = 0.0;
	if (x_46_im <= -32000000000000.0)
		tmp = x_46_im * ((x_46_re + x_46_re) + ((x_46_re * (x_46_im + x_46_re)) - (x_46_im * (x_46_im + x_46_re))));
	elseif (x_46_im <= 7.8e-97)
		tmp = (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re));
	else
		tmp = x_46_im * (((x_46_im + x_46_re) * (x_46_re - x_46_im)) + (x_46_re + x_46_re));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[LessEqual[x$46$im, -32000000000000.0], N[(x$46$im * N[(N[(x$46$re + x$46$re), $MachinePrecision] + N[(N[(x$46$re * N[(x$46$im + x$46$re), $MachinePrecision]), $MachinePrecision] - N[(x$46$im * N[(x$46$im + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$im, 7.8e-97], N[(N[(x$46$im * x$46$re), $MachinePrecision] * N[(x$46$re + N[(x$46$re + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(N[(N[(x$46$im + x$46$re), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision] + N[(x$46$re + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq -32000000000000:\\
\;\;\;\;x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re \cdot \left(x.im + x.re\right) - x.im \cdot \left(x.im + x.re\right)\right)\right)\\

\mathbf{elif}\;x.im \leq 7.8 \cdot 10^{-97}:\\
\;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re + \left(x.re + x.re\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re + x.re\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x.im < -3.2e13

    1. Initial program 86.2%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. *-commutative86.2%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re \]
      2. flip-+0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}} \cdot x.re \]
      3. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      4. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{x.im \cdot x.im - x.im \cdot x.im}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      5. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{0}} \cdot x.re \]
      6. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{x.im - x.im}} \cdot x.re \]
      7. flip-+82.6%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.im + x.im\right)} \cdot x.re \]
      8. *-commutative82.6%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{x.re \cdot \left(x.im + x.im\right)} \]
      9. distribute-lft-in82.6%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    3. Applied egg-rr82.6%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    4. Step-by-step derivation
      1. +-commutative82.6%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
      2. distribute-rgt-out82.6%

        \[\leadsto \color{blue}{x.im \cdot \left(x.re + x.re\right)} + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im \]
      3. *-commutative82.6%

        \[\leadsto x.im \cdot \left(x.re + x.re\right) + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} \]
      4. distribute-lft-out90.2%

        \[\leadsto \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right)\right)} \]
      5. difference-of-squares93.2%

        \[\leadsto x.im \cdot \left(\left(x.re + x.re\right) + \color{blue}{\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)}\right) \]
    5. Applied egg-rr93.2%

      \[\leadsto \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \]
    6. Step-by-step derivation
      1. sub-neg93.2%

        \[\leadsto x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re + x.im\right) \cdot \color{blue}{\left(x.re + \left(-x.im\right)\right)}\right) \]
      2. distribute-lft-in87.2%

        \[\leadsto x.im \cdot \left(\left(x.re + x.re\right) + \color{blue}{\left(\left(x.re + x.im\right) \cdot x.re + \left(x.re + x.im\right) \cdot \left(-x.im\right)\right)}\right) \]
      3. +-commutative87.2%

        \[\leadsto x.im \cdot \left(\left(x.re + x.re\right) + \left(\color{blue}{\left(x.im + x.re\right)} \cdot x.re + \left(x.re + x.im\right) \cdot \left(-x.im\right)\right)\right) \]
      4. +-commutative87.2%

        \[\leadsto x.im \cdot \left(\left(x.re + x.re\right) + \left(\left(x.im + x.re\right) \cdot x.re + \color{blue}{\left(x.im + x.re\right)} \cdot \left(-x.im\right)\right)\right) \]
    7. Applied egg-rr87.2%

      \[\leadsto x.im \cdot \left(\left(x.re + x.re\right) + \color{blue}{\left(\left(x.im + x.re\right) \cdot x.re + \left(x.im + x.re\right) \cdot \left(-x.im\right)\right)}\right) \]

    if -3.2e13 < x.im < 7.7999999999999997e-97

    1. Initial program 88.2%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Taylor expanded in x.re around inf 80.0%

      \[\leadsto \color{blue}{{x.re}^{2}} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Simplified80.0%

      \[\leadsto \color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    4. Step-by-step derivation
      1. *-commutative80.0%

        \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) \cdot x.re \]
      2. distribute-lft-in80.0%

        \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(x.im \cdot \left(x.re + x.re\right)\right)} \cdot x.re \]
      3. *-commutative80.0%

        \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right)} \cdot x.re \]
    5. Applied egg-rr80.0%

      \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right)} \cdot x.re \]
    6. Step-by-step derivation
      1. +-commutative80.0%

        \[\leadsto \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right) \cdot x.re + \left(x.re \cdot x.re\right) \cdot x.im} \]
      2. associate-*l*80.0%

        \[\leadsto \color{blue}{\left(x.re + x.re\right) \cdot \left(x.im \cdot x.re\right)} + \left(x.re \cdot x.re\right) \cdot x.im \]
      3. *-commutative80.0%

        \[\leadsto \left(x.re + x.re\right) \cdot \color{blue}{\left(x.re \cdot x.im\right)} + \left(x.re \cdot x.re\right) \cdot x.im \]
      4. associate-*l*91.5%

        \[\leadsto \left(x.re + x.re\right) \cdot \left(x.re \cdot x.im\right) + \color{blue}{x.re \cdot \left(x.re \cdot x.im\right)} \]
      5. distribute-rgt-out91.6%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(\left(x.re + x.re\right) + x.re\right)} \]
      6. *-commutative91.6%

        \[\leadsto \color{blue}{\left(x.im \cdot x.re\right)} \cdot \left(\left(x.re + x.re\right) + x.re\right) \]
    7. Applied egg-rr91.6%

      \[\leadsto \color{blue}{\left(x.im \cdot x.re\right) \cdot \left(\left(x.re + x.re\right) + x.re\right)} \]

    if 7.7999999999999997e-97 < x.im

    1. Initial program 78.4%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. *-commutative78.4%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re \]
      2. flip-+0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}} \cdot x.re \]
      3. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      4. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{x.im \cdot x.im - x.im \cdot x.im}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      5. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{0}} \cdot x.re \]
      6. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{x.im - x.im}} \cdot x.re \]
      7. flip-+71.1%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.im + x.im\right)} \cdot x.re \]
      8. *-commutative71.1%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{x.re \cdot \left(x.im + x.im\right)} \]
      9. distribute-lft-in71.1%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    3. Applied egg-rr71.1%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    4. Step-by-step derivation
      1. +-commutative71.1%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
      2. distribute-rgt-out71.1%

        \[\leadsto \color{blue}{x.im \cdot \left(x.re + x.re\right)} + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im \]
      3. *-commutative71.1%

        \[\leadsto x.im \cdot \left(x.re + x.re\right) + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} \]
      4. distribute-lft-out75.9%

        \[\leadsto \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right)\right)} \]
      5. difference-of-squares91.3%

        \[\leadsto x.im \cdot \left(\left(x.re + x.re\right) + \color{blue}{\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)}\right) \]
    5. Applied egg-rr91.3%

      \[\leadsto \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification90.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq -32000000000000:\\ \;\;\;\;x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re \cdot \left(x.im + x.re\right) - x.im \cdot \left(x.im + x.re\right)\right)\right)\\ \mathbf{elif}\;x.im \leq 7.8 \cdot 10^{-97}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re + \left(x.re + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re + x.re\right)\right)\\ \end{array} \]

Alternative 4: 90.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\\ \mathbf{if}\;x.im \leq -31000000000000:\\ \;\;\;\;-3 + x.im \cdot t_0\\ \mathbf{elif}\;x.im \leq 7.8 \cdot 10^{-97}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re + \left(x.re + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(t_0 + \left(x.re + x.re\right)\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (let* ((t_0 (* (+ x.im x.re) (- x.re x.im))))
   (if (<= x.im -31000000000000.0)
     (+ -3.0 (* x.im t_0))
     (if (<= x.im 7.8e-97)
       (* (* x.im x.re) (+ x.re (+ x.re x.re)))
       (* x.im (+ t_0 (+ x.re x.re)))))))
double code(double x_46_re, double x_46_im) {
	double t_0 = (x_46_im + x_46_re) * (x_46_re - x_46_im);
	double tmp;
	if (x_46_im <= -31000000000000.0) {
		tmp = -3.0 + (x_46_im * t_0);
	} else if (x_46_im <= 7.8e-97) {
		tmp = (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re));
	} else {
		tmp = x_46_im * (t_0 + (x_46_re + x_46_re));
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x_46im + x_46re) * (x_46re - x_46im)
    if (x_46im <= (-31000000000000.0d0)) then
        tmp = (-3.0d0) + (x_46im * t_0)
    else if (x_46im <= 7.8d-97) then
        tmp = (x_46im * x_46re) * (x_46re + (x_46re + x_46re))
    else
        tmp = x_46im * (t_0 + (x_46re + x_46re))
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im) {
	double t_0 = (x_46_im + x_46_re) * (x_46_re - x_46_im);
	double tmp;
	if (x_46_im <= -31000000000000.0) {
		tmp = -3.0 + (x_46_im * t_0);
	} else if (x_46_im <= 7.8e-97) {
		tmp = (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re));
	} else {
		tmp = x_46_im * (t_0 + (x_46_re + x_46_re));
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	t_0 = (x_46_im + x_46_re) * (x_46_re - x_46_im)
	tmp = 0
	if x_46_im <= -31000000000000.0:
		tmp = -3.0 + (x_46_im * t_0)
	elif x_46_im <= 7.8e-97:
		tmp = (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re))
	else:
		tmp = x_46_im * (t_0 + (x_46_re + x_46_re))
	return tmp
function code(x_46_re, x_46_im)
	t_0 = Float64(Float64(x_46_im + x_46_re) * Float64(x_46_re - x_46_im))
	tmp = 0.0
	if (x_46_im <= -31000000000000.0)
		tmp = Float64(-3.0 + Float64(x_46_im * t_0));
	elseif (x_46_im <= 7.8e-97)
		tmp = Float64(Float64(x_46_im * x_46_re) * Float64(x_46_re + Float64(x_46_re + x_46_re)));
	else
		tmp = Float64(x_46_im * Float64(t_0 + Float64(x_46_re + x_46_re)));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	t_0 = (x_46_im + x_46_re) * (x_46_re - x_46_im);
	tmp = 0.0;
	if (x_46_im <= -31000000000000.0)
		tmp = -3.0 + (x_46_im * t_0);
	elseif (x_46_im <= 7.8e-97)
		tmp = (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re));
	else
		tmp = x_46_im * (t_0 + (x_46_re + x_46_re));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := Block[{t$95$0 = N[(N[(x$46$im + x$46$re), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$46$im, -31000000000000.0], N[(-3.0 + N[(x$46$im * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$im, 7.8e-97], N[(N[(x$46$im * x$46$re), $MachinePrecision] * N[(x$46$re + N[(x$46$re + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(t$95$0 + N[(x$46$re + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\\
\mathbf{if}\;x.im \leq -31000000000000:\\
\;\;\;\;-3 + x.im \cdot t_0\\

\mathbf{elif}\;x.im \leq 7.8 \cdot 10^{-97}:\\
\;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re + \left(x.re + x.re\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x.im \cdot \left(t_0 + \left(x.re + x.re\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x.im < -3.1e13

    1. Initial program 86.2%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. *-commutative86.2%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re \]
      2. flip-+0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}} \cdot x.re \]
      3. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      4. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{x.im \cdot x.im - x.im \cdot x.im}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      5. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{0}} \cdot x.re \]
      6. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{x.im - x.im}} \cdot x.re \]
      7. flip-+82.6%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.im + x.im\right)} \cdot x.re \]
      8. *-commutative82.6%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{x.re \cdot \left(x.im + x.im\right)} \]
      9. distribute-lft-in82.6%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    3. Applied egg-rr82.6%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    4. Step-by-step derivation
      1. +-commutative82.6%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
      2. add-cube-cbrt82.6%

        \[\leadsto \color{blue}{\left(\sqrt[3]{x.re \cdot x.im + x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}\right) \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}} + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im \]
      3. fma-def82.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{x.re \cdot x.im + x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}, \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}, \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im\right)} \]
    5. Applied egg-rr0.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{0}{0}, \frac{0}{0}, x.im \cdot \left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)\right)} \]
    6. Simplified93.2%

      \[\leadsto \color{blue}{-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)} \]

    if -3.1e13 < x.im < 7.7999999999999997e-97

    1. Initial program 88.2%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Taylor expanded in x.re around inf 80.0%

      \[\leadsto \color{blue}{{x.re}^{2}} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Simplified80.0%

      \[\leadsto \color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    4. Step-by-step derivation
      1. *-commutative80.0%

        \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) \cdot x.re \]
      2. distribute-lft-in80.0%

        \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(x.im \cdot \left(x.re + x.re\right)\right)} \cdot x.re \]
      3. *-commutative80.0%

        \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right)} \cdot x.re \]
    5. Applied egg-rr80.0%

      \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right)} \cdot x.re \]
    6. Step-by-step derivation
      1. +-commutative80.0%

        \[\leadsto \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right) \cdot x.re + \left(x.re \cdot x.re\right) \cdot x.im} \]
      2. associate-*l*80.0%

        \[\leadsto \color{blue}{\left(x.re + x.re\right) \cdot \left(x.im \cdot x.re\right)} + \left(x.re \cdot x.re\right) \cdot x.im \]
      3. *-commutative80.0%

        \[\leadsto \left(x.re + x.re\right) \cdot \color{blue}{\left(x.re \cdot x.im\right)} + \left(x.re \cdot x.re\right) \cdot x.im \]
      4. associate-*l*91.5%

        \[\leadsto \left(x.re + x.re\right) \cdot \left(x.re \cdot x.im\right) + \color{blue}{x.re \cdot \left(x.re \cdot x.im\right)} \]
      5. distribute-rgt-out91.6%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(\left(x.re + x.re\right) + x.re\right)} \]
      6. *-commutative91.6%

        \[\leadsto \color{blue}{\left(x.im \cdot x.re\right)} \cdot \left(\left(x.re + x.re\right) + x.re\right) \]
    7. Applied egg-rr91.6%

      \[\leadsto \color{blue}{\left(x.im \cdot x.re\right) \cdot \left(\left(x.re + x.re\right) + x.re\right)} \]

    if 7.7999999999999997e-97 < x.im

    1. Initial program 78.4%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. *-commutative78.4%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re \]
      2. flip-+0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}} \cdot x.re \]
      3. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      4. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{x.im \cdot x.im - x.im \cdot x.im}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      5. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{0}} \cdot x.re \]
      6. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{x.im - x.im}} \cdot x.re \]
      7. flip-+71.1%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.im + x.im\right)} \cdot x.re \]
      8. *-commutative71.1%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{x.re \cdot \left(x.im + x.im\right)} \]
      9. distribute-lft-in71.1%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    3. Applied egg-rr71.1%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    4. Step-by-step derivation
      1. +-commutative71.1%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
      2. distribute-rgt-out71.1%

        \[\leadsto \color{blue}{x.im \cdot \left(x.re + x.re\right)} + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im \]
      3. *-commutative71.1%

        \[\leadsto x.im \cdot \left(x.re + x.re\right) + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} \]
      4. distribute-lft-out75.9%

        \[\leadsto \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right)\right)} \]
      5. difference-of-squares91.3%

        \[\leadsto x.im \cdot \left(\left(x.re + x.re\right) + \color{blue}{\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)}\right) \]
    5. Applied egg-rr91.3%

      \[\leadsto \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) + \left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification91.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq -31000000000000:\\ \;\;\;\;-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)\\ \mathbf{elif}\;x.im \leq 7.8 \cdot 10^{-97}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re + \left(x.re + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re + x.re\right)\right)\\ \end{array} \]

Alternative 5: 90.9% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \leq -31000000000000 \lor \neg \left(x.im \leq 37000000\right):\\ \;\;\;\;-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.im \cdot x.re + \left(x.im \cdot x.re\right) \cdot 2\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (or (<= x.im -31000000000000.0) (not (<= x.im 37000000.0)))
   (+ -3.0 (* x.im (* (+ x.im x.re) (- x.re x.im))))
   (* x.re (+ (* x.im x.re) (* (* x.im x.re) 2.0)))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -31000000000000.0) || !(x_46_im <= 37000000.0)) {
		tmp = -3.0 + (x_46_im * ((x_46_im + x_46_re) * (x_46_re - x_46_im)));
	} else {
		tmp = x_46_re * ((x_46_im * x_46_re) + ((x_46_im * x_46_re) * 2.0));
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if ((x_46im <= (-31000000000000.0d0)) .or. (.not. (x_46im <= 37000000.0d0))) then
        tmp = (-3.0d0) + (x_46im * ((x_46im + x_46re) * (x_46re - x_46im)))
    else
        tmp = x_46re * ((x_46im * x_46re) + ((x_46im * x_46re) * 2.0d0))
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -31000000000000.0) || !(x_46_im <= 37000000.0)) {
		tmp = -3.0 + (x_46_im * ((x_46_im + x_46_re) * (x_46_re - x_46_im)));
	} else {
		tmp = x_46_re * ((x_46_im * x_46_re) + ((x_46_im * x_46_re) * 2.0));
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if (x_46_im <= -31000000000000.0) or not (x_46_im <= 37000000.0):
		tmp = -3.0 + (x_46_im * ((x_46_im + x_46_re) * (x_46_re - x_46_im)))
	else:
		tmp = x_46_re * ((x_46_im * x_46_re) + ((x_46_im * x_46_re) * 2.0))
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if ((x_46_im <= -31000000000000.0) || !(x_46_im <= 37000000.0))
		tmp = Float64(-3.0 + Float64(x_46_im * Float64(Float64(x_46_im + x_46_re) * Float64(x_46_re - x_46_im))));
	else
		tmp = Float64(x_46_re * Float64(Float64(x_46_im * x_46_re) + Float64(Float64(x_46_im * x_46_re) * 2.0)));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	tmp = 0.0;
	if ((x_46_im <= -31000000000000.0) || ~((x_46_im <= 37000000.0)))
		tmp = -3.0 + (x_46_im * ((x_46_im + x_46_re) * (x_46_re - x_46_im)));
	else
		tmp = x_46_re * ((x_46_im * x_46_re) + ((x_46_im * x_46_re) * 2.0));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[Or[LessEqual[x$46$im, -31000000000000.0], N[Not[LessEqual[x$46$im, 37000000.0]], $MachinePrecision]], N[(-3.0 + N[(x$46$im * N[(N[(x$46$im + x$46$re), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$re * N[(N[(x$46$im * x$46$re), $MachinePrecision] + N[(N[(x$46$im * x$46$re), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq -31000000000000 \lor \neg \left(x.im \leq 37000000\right):\\
\;\;\;\;-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x.re \cdot \left(x.im \cdot x.re + \left(x.im \cdot x.re\right) \cdot 2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < -3.1e13 or 3.7e7 < x.im

    1. Initial program 79.4%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. *-commutative79.4%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re \]
      2. flip-+0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}} \cdot x.re \]
      3. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      4. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{\color{blue}{x.im \cdot x.im - x.im \cdot x.im}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re \]
      5. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{0}} \cdot x.re \]
      6. +-inverses0.0%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \frac{x.im \cdot x.im - x.im \cdot x.im}{\color{blue}{x.im - x.im}} \cdot x.re \]
      7. flip-+77.1%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.im + x.im\right)} \cdot x.re \]
      8. *-commutative77.1%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{x.re \cdot \left(x.im + x.im\right)} \]
      9. distribute-lft-in77.1%

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    3. Applied egg-rr77.1%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)} \]
    4. Step-by-step derivation
      1. +-commutative77.1%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right) + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
      2. add-cube-cbrt77.1%

        \[\leadsto \color{blue}{\left(\sqrt[3]{x.re \cdot x.im + x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}\right) \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}} + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im \]
      3. fma-def77.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{x.re \cdot x.im + x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}, \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}, \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im\right)} \]
    5. Applied egg-rr0.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{0}{0}, \frac{0}{0}, x.im \cdot \left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)\right)} \]
    6. Simplified95.3%

      \[\leadsto \color{blue}{-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)} \]

    if -3.1e13 < x.im < 3.7e7

    1. Initial program 89.9%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Taylor expanded in x.re around inf 75.1%

      \[\leadsto \color{blue}{{x.re}^{2}} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Simplified75.1%

      \[\leadsto \color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    4. Step-by-step derivation
      1. *-commutative75.1%

        \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) \cdot x.re \]
      2. distribute-lft-in75.1%

        \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(x.im \cdot \left(x.re + x.re\right)\right)} \cdot x.re \]
      3. *-commutative75.1%

        \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right)} \cdot x.re \]
    5. Applied egg-rr75.1%

      \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right)} \cdot x.re \]
    6. Step-by-step derivation
      1. associate-*l*84.9%

        \[\leadsto \color{blue}{x.re \cdot \left(x.re \cdot x.im\right)} + \left(\left(x.re + x.re\right) \cdot x.im\right) \cdot x.re \]
      2. *-commutative84.9%

        \[\leadsto x.re \cdot \left(x.re \cdot x.im\right) + \color{blue}{x.re \cdot \left(\left(x.re + x.re\right) \cdot x.im\right)} \]
      3. distribute-lft-out85.0%

        \[\leadsto \color{blue}{x.re \cdot \left(x.re \cdot x.im + \left(x.re + x.re\right) \cdot x.im\right)} \]
      4. *-commutative85.0%

        \[\leadsto x.re \cdot \left(\color{blue}{x.im \cdot x.re} + \left(x.re + x.re\right) \cdot x.im\right) \]
      5. count-285.0%

        \[\leadsto x.re \cdot \left(x.im \cdot x.re + \color{blue}{\left(2 \cdot x.re\right)} \cdot x.im\right) \]
      6. associate-*l*85.0%

        \[\leadsto x.re \cdot \left(x.im \cdot x.re + \color{blue}{2 \cdot \left(x.re \cdot x.im\right)}\right) \]
      7. *-commutative85.0%

        \[\leadsto x.re \cdot \left(x.im \cdot x.re + 2 \cdot \color{blue}{\left(x.im \cdot x.re\right)}\right) \]
    7. Applied egg-rr85.0%

      \[\leadsto \color{blue}{x.re \cdot \left(x.im \cdot x.re + 2 \cdot \left(x.im \cdot x.re\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq -31000000000000 \lor \neg \left(x.im \leq 37000000\right):\\ \;\;\;\;-3 + x.im \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re - x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.im \cdot x.re + \left(x.im \cdot x.re\right) \cdot 2\right)\\ \end{array} \]

Alternative 6: 55.8% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \left(x.im \cdot x.re\right) \cdot \left(x.re + \left(x.re + x.re\right)\right) \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (* (* x.im x.re) (+ x.re (+ x.re x.re))))
double code(double x_46_re, double x_46_im) {
	return (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re));
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = (x_46im * x_46re) * (x_46re + (x_46re + x_46re))
end function
public static double code(double x_46_re, double x_46_im) {
	return (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re));
}
def code(x_46_re, x_46_im):
	return (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re))
function code(x_46_re, x_46_im)
	return Float64(Float64(x_46_im * x_46_re) * Float64(x_46_re + Float64(x_46_re + x_46_re)))
end
function tmp = code(x_46_re, x_46_im)
	tmp = (x_46_im * x_46_re) * (x_46_re + (x_46_re + x_46_re));
end
code[x$46$re_, x$46$im_] := N[(N[(x$46$im * x$46$re), $MachinePrecision] * N[(x$46$re + N[(x$46$re + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x.im \cdot x.re\right) \cdot \left(x.re + \left(x.re + x.re\right)\right)
\end{array}
Derivation
  1. Initial program 84.5%

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  2. Taylor expanded in x.re around inf 49.0%

    \[\leadsto \color{blue}{{x.re}^{2}} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  3. Simplified49.0%

    \[\leadsto \color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  4. Step-by-step derivation
    1. *-commutative49.0%

      \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) \cdot x.re \]
    2. distribute-lft-in49.0%

      \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(x.im \cdot \left(x.re + x.re\right)\right)} \cdot x.re \]
    3. *-commutative49.0%

      \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right)} \cdot x.re \]
  5. Applied egg-rr49.0%

    \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right)} \cdot x.re \]
  6. Step-by-step derivation
    1. +-commutative49.0%

      \[\leadsto \color{blue}{\left(\left(x.re + x.re\right) \cdot x.im\right) \cdot x.re + \left(x.re \cdot x.re\right) \cdot x.im} \]
    2. associate-*l*49.0%

      \[\leadsto \color{blue}{\left(x.re + x.re\right) \cdot \left(x.im \cdot x.re\right)} + \left(x.re \cdot x.re\right) \cdot x.im \]
    3. *-commutative49.0%

      \[\leadsto \left(x.re + x.re\right) \cdot \color{blue}{\left(x.re \cdot x.im\right)} + \left(x.re \cdot x.re\right) \cdot x.im \]
    4. associate-*l*53.8%

      \[\leadsto \left(x.re + x.re\right) \cdot \left(x.re \cdot x.im\right) + \color{blue}{x.re \cdot \left(x.re \cdot x.im\right)} \]
    5. distribute-rgt-out53.8%

      \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(\left(x.re + x.re\right) + x.re\right)} \]
    6. *-commutative53.8%

      \[\leadsto \color{blue}{\left(x.im \cdot x.re\right)} \cdot \left(\left(x.re + x.re\right) + x.re\right) \]
  7. Applied egg-rr53.8%

    \[\leadsto \color{blue}{\left(x.im \cdot x.re\right) \cdot \left(\left(x.re + x.re\right) + x.re\right)} \]
  8. Final simplification53.8%

    \[\leadsto \left(x.im \cdot x.re\right) \cdot \left(x.re + \left(x.re + x.re\right)\right) \]

Alternative 7: 50.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ 3 \cdot \left(x.im \cdot \left(x.re \cdot x.re\right)\right) \end{array} \]
(FPCore (x.re x.im) :precision binary64 (* 3.0 (* x.im (* x.re x.re))))
double code(double x_46_re, double x_46_im) {
	return 3.0 * (x_46_im * (x_46_re * x_46_re));
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = 3.0d0 * (x_46im * (x_46re * x_46re))
end function
public static double code(double x_46_re, double x_46_im) {
	return 3.0 * (x_46_im * (x_46_re * x_46_re));
}
def code(x_46_re, x_46_im):
	return 3.0 * (x_46_im * (x_46_re * x_46_re))
function code(x_46_re, x_46_im)
	return Float64(3.0 * Float64(x_46_im * Float64(x_46_re * x_46_re)))
end
function tmp = code(x_46_re, x_46_im)
	tmp = 3.0 * (x_46_im * (x_46_re * x_46_re));
end
code[x$46$re_, x$46$im_] := N[(3.0 * N[(x$46$im * N[(x$46$re * x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
3 \cdot \left(x.im \cdot \left(x.re \cdot x.re\right)\right)
\end{array}
Derivation
  1. Initial program 84.5%

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  2. Step-by-step derivation
    1. +-commutative84.5%

      \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
    2. *-commutative84.5%

      \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} \]
    3. sub-neg84.5%

      \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \color{blue}{\left(x.re \cdot x.re + \left(-x.im \cdot x.im\right)\right)} \]
    4. distribute-lft-in81.8%

      \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot \left(x.re \cdot x.re\right) + x.im \cdot \left(-x.im \cdot x.im\right)\right)} \]
    5. associate-+r+81.8%

      \[\leadsto \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + x.im \cdot \left(-x.im \cdot x.im\right)} \]
    6. distribute-rgt-neg-out81.8%

      \[\leadsto \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + \color{blue}{\left(-x.im \cdot \left(x.im \cdot x.im\right)\right)} \]
    7. unsub-neg81.8%

      \[\leadsto \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right)} \]
    8. associate-*r*86.5%

      \[\leadsto \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot x.re\right) \cdot x.re}\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    9. distribute-rgt-out86.5%

      \[\leadsto \color{blue}{x.re \cdot \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) + x.im \cdot x.re\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    10. *-commutative86.5%

      \[\leadsto x.re \cdot \left(\left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    11. count-286.5%

      \[\leadsto x.re \cdot \left(\color{blue}{2 \cdot \left(x.im \cdot x.re\right)} + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    12. distribute-lft1-in86.5%

      \[\leadsto x.re \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \left(x.im \cdot x.re\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    13. metadata-eval86.5%

      \[\leadsto x.re \cdot \left(\color{blue}{3} \cdot \left(x.im \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    14. *-commutative86.5%

      \[\leadsto x.re \cdot \color{blue}{\left(\left(x.im \cdot x.re\right) \cdot 3\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    15. *-commutative86.5%

      \[\leadsto x.re \cdot \left(\color{blue}{\left(x.re \cdot x.im\right)} \cdot 3\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    16. associate-*r*86.5%

      \[\leadsto x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 3\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    17. cube-unmult86.6%

      \[\leadsto x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - \color{blue}{{x.im}^{3}} \]
  3. Simplified86.6%

    \[\leadsto \color{blue}{x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3}} \]
  4. Taylor expanded in x.re around 0 86.6%

    \[\leadsto x.re \cdot \color{blue}{\left(3 \cdot \left(x.re \cdot x.im\right)\right)} - {x.im}^{3} \]
  5. Step-by-step derivation
    1. associate-*r*86.6%

      \[\leadsto \color{blue}{\left(x.re \cdot 3\right) \cdot \left(x.re \cdot x.im\right)} - {x.im}^{3} \]
    2. fma-neg88.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re \cdot 3, x.re \cdot x.im, -{x.im}^{3}\right)} \]
  6. Applied egg-rr88.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re \cdot 3, x.re \cdot x.im, -{x.im}^{3}\right)} \]
  7. Taylor expanded in x.re around inf 49.1%

    \[\leadsto \color{blue}{3 \cdot \left({x.re}^{2} \cdot x.im\right)} \]
  8. Step-by-step derivation
    1. unpow249.1%

      \[\leadsto 3 \cdot \left(\color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im\right) \]
    2. *-commutative49.1%

      \[\leadsto 3 \cdot \color{blue}{\left(x.im \cdot \left(x.re \cdot x.re\right)\right)} \]
  9. Simplified49.1%

    \[\leadsto \color{blue}{3 \cdot \left(x.im \cdot \left(x.re \cdot x.re\right)\right)} \]
  10. Final simplification49.1%

    \[\leadsto 3 \cdot \left(x.im \cdot \left(x.re \cdot x.re\right)\right) \]

Alternative 8: 34.6% accurate, 3.8× speedup?

\[\begin{array}{l} \\ x.im \cdot \left(x.re \cdot x.re\right) \end{array} \]
(FPCore (x.re x.im) :precision binary64 (* x.im (* x.re x.re)))
double code(double x_46_re, double x_46_im) {
	return x_46_im * (x_46_re * x_46_re);
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = x_46im * (x_46re * x_46re)
end function
public static double code(double x_46_re, double x_46_im) {
	return x_46_im * (x_46_re * x_46_re);
}
def code(x_46_re, x_46_im):
	return x_46_im * (x_46_re * x_46_re)
function code(x_46_re, x_46_im)
	return Float64(x_46_im * Float64(x_46_re * x_46_re))
end
function tmp = code(x_46_re, x_46_im)
	tmp = x_46_im * (x_46_re * x_46_re);
end
code[x$46$re_, x$46$im_] := N[(x$46$im * N[(x$46$re * x$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x.im \cdot \left(x.re \cdot x.re\right)
\end{array}
Derivation
  1. Initial program 84.5%

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  2. Taylor expanded in x.re around inf 49.0%

    \[\leadsto \color{blue}{{x.re}^{2}} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  3. Simplified49.0%

    \[\leadsto \color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  4. Step-by-step derivation
    1. *-commutative49.0%

      \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re \]
    2. expm1-log1p-u38.2%

      \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x.re \cdot x.im + x.re \cdot x.im\right)\right)} \cdot x.re \]
    3. expm1-udef28.9%

      \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(x.re \cdot x.im + x.re \cdot x.im\right)} - 1\right)} \cdot x.re \]
  5. Applied egg-rr0.0%

    \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{0}{0}\right)} - 1\right)} \cdot x.re \]
  6. Simplified19.9%

    \[\leadsto \left(x.re \cdot x.re\right) \cdot x.im + \color{blue}{-3} \cdot x.re \]
  7. Taylor expanded in x.re around inf 34.3%

    \[\leadsto \color{blue}{{x.re}^{2} \cdot x.im} \]
  8. Step-by-step derivation
    1. unpow234.3%

      \[\leadsto \color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im \]
    2. *-commutative34.3%

      \[\leadsto \color{blue}{x.im \cdot \left(x.re \cdot x.re\right)} \]
  9. Simplified34.3%

    \[\leadsto \color{blue}{x.im \cdot \left(x.re \cdot x.re\right)} \]
  10. Final simplification34.3%

    \[\leadsto x.im \cdot \left(x.re \cdot x.re\right) \]

Alternative 9: 4.5% accurate, 9.5× speedup?

\[\begin{array}{l} \\ -x.im \end{array} \]
(FPCore (x.re x.im) :precision binary64 (- x.im))
double code(double x_46_re, double x_46_im) {
	return -x_46_im;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = -x_46im
end function
public static double code(double x_46_re, double x_46_im) {
	return -x_46_im;
}
def code(x_46_re, x_46_im):
	return -x_46_im
function code(x_46_re, x_46_im)
	return Float64(-x_46_im)
end
function tmp = code(x_46_re, x_46_im)
	tmp = -x_46_im;
end
code[x$46$re_, x$46$im_] := (-x$46$im)
\begin{array}{l}

\\
-x.im
\end{array}
Derivation
  1. Initial program 84.5%

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  2. Step-by-step derivation
    1. +-commutative84.5%

      \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
    2. *-commutative84.5%

      \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} \]
    3. sub-neg84.5%

      \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \color{blue}{\left(x.re \cdot x.re + \left(-x.im \cdot x.im\right)\right)} \]
    4. distribute-lft-in81.8%

      \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot \left(x.re \cdot x.re\right) + x.im \cdot \left(-x.im \cdot x.im\right)\right)} \]
    5. associate-+r+81.8%

      \[\leadsto \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + x.im \cdot \left(-x.im \cdot x.im\right)} \]
    6. distribute-rgt-neg-out81.8%

      \[\leadsto \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + \color{blue}{\left(-x.im \cdot \left(x.im \cdot x.im\right)\right)} \]
    7. unsub-neg81.8%

      \[\leadsto \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right)} \]
    8. associate-*r*86.5%

      \[\leadsto \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot x.re\right) \cdot x.re}\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    9. distribute-rgt-out86.5%

      \[\leadsto \color{blue}{x.re \cdot \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) + x.im \cdot x.re\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    10. *-commutative86.5%

      \[\leadsto x.re \cdot \left(\left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    11. count-286.5%

      \[\leadsto x.re \cdot \left(\color{blue}{2 \cdot \left(x.im \cdot x.re\right)} + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    12. distribute-lft1-in86.5%

      \[\leadsto x.re \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \left(x.im \cdot x.re\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    13. metadata-eval86.5%

      \[\leadsto x.re \cdot \left(\color{blue}{3} \cdot \left(x.im \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    14. *-commutative86.5%

      \[\leadsto x.re \cdot \color{blue}{\left(\left(x.im \cdot x.re\right) \cdot 3\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    15. *-commutative86.5%

      \[\leadsto x.re \cdot \left(\color{blue}{\left(x.re \cdot x.im\right)} \cdot 3\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    16. associate-*r*86.5%

      \[\leadsto x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 3\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    17. cube-unmult86.6%

      \[\leadsto x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - \color{blue}{{x.im}^{3}} \]
  3. Simplified86.6%

    \[\leadsto \color{blue}{x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3}} \]
  4. Taylor expanded in x.re around 0 86.6%

    \[\leadsto x.re \cdot \color{blue}{\left(3 \cdot \left(x.re \cdot x.im\right)\right)} - {x.im}^{3} \]
  5. Taylor expanded in x.re around inf 49.1%

    \[\leadsto \color{blue}{3 \cdot \left({x.re}^{2} \cdot x.im\right)} \]
  6. Simplified4.3%

    \[\leadsto \color{blue}{-x.im} \]
  7. Final simplification4.3%

    \[\leadsto -x.im \]

Alternative 10: 2.7% accurate, 19.0× speedup?

\[\begin{array}{l} \\ -3 \end{array} \]
(FPCore (x.re x.im) :precision binary64 -3.0)
double code(double x_46_re, double x_46_im) {
	return -3.0;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = -3.0d0
end function
public static double code(double x_46_re, double x_46_im) {
	return -3.0;
}
def code(x_46_re, x_46_im):
	return -3.0
function code(x_46_re, x_46_im)
	return -3.0
end
function tmp = code(x_46_re, x_46_im)
	tmp = -3.0;
end
code[x$46$re_, x$46$im_] := -3.0
\begin{array}{l}

\\
-3
\end{array}
Derivation
  1. Initial program 84.5%

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  2. Step-by-step derivation
    1. +-commutative84.5%

      \[\leadsto \color{blue}{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im} \]
    2. *-commutative84.5%

      \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} \]
    3. sub-neg84.5%

      \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \color{blue}{\left(x.re \cdot x.re + \left(-x.im \cdot x.im\right)\right)} \]
    4. distribute-lft-in81.8%

      \[\leadsto \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot \left(x.re \cdot x.re\right) + x.im \cdot \left(-x.im \cdot x.im\right)\right)} \]
    5. associate-+r+81.8%

      \[\leadsto \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + x.im \cdot \left(-x.im \cdot x.im\right)} \]
    6. distribute-rgt-neg-out81.8%

      \[\leadsto \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + \color{blue}{\left(-x.im \cdot \left(x.im \cdot x.im\right)\right)} \]
    7. unsub-neg81.8%

      \[\leadsto \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right)} \]
    8. associate-*r*86.5%

      \[\leadsto \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot x.re\right) \cdot x.re}\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    9. distribute-rgt-out86.5%

      \[\leadsto \color{blue}{x.re \cdot \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) + x.im \cdot x.re\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    10. *-commutative86.5%

      \[\leadsto x.re \cdot \left(\left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    11. count-286.5%

      \[\leadsto x.re \cdot \left(\color{blue}{2 \cdot \left(x.im \cdot x.re\right)} + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    12. distribute-lft1-in86.5%

      \[\leadsto x.re \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \left(x.im \cdot x.re\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    13. metadata-eval86.5%

      \[\leadsto x.re \cdot \left(\color{blue}{3} \cdot \left(x.im \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    14. *-commutative86.5%

      \[\leadsto x.re \cdot \color{blue}{\left(\left(x.im \cdot x.re\right) \cdot 3\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    15. *-commutative86.5%

      \[\leadsto x.re \cdot \left(\color{blue}{\left(x.re \cdot x.im\right)} \cdot 3\right) - x.im \cdot \left(x.im \cdot x.im\right) \]
    16. associate-*r*86.5%

      \[\leadsto x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 3\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right) \]
    17. cube-unmult86.6%

      \[\leadsto x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - \color{blue}{{x.im}^{3}} \]
  3. Simplified86.6%

    \[\leadsto \color{blue}{x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3}} \]
  4. Taylor expanded in x.re around 0 60.4%

    \[\leadsto \color{blue}{-1 \cdot {x.im}^{3}} \]
  5. Simplified2.8%

    \[\leadsto \color{blue}{-3} \]
  6. Final simplification2.8%

    \[\leadsto -3 \]

Developer target: 91.7% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right) \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (+ (* (* x.re x.im) (* 2.0 x.re)) (* (* x.im (- x.re x.im)) (+ x.re x.im))))
double code(double x_46_re, double x_46_im) {
	return ((x_46_re * x_46_im) * (2.0 * x_46_re)) + ((x_46_im * (x_46_re - x_46_im)) * (x_46_re + x_46_im));
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = ((x_46re * x_46im) * (2.0d0 * x_46re)) + ((x_46im * (x_46re - x_46im)) * (x_46re + x_46im))
end function
public static double code(double x_46_re, double x_46_im) {
	return ((x_46_re * x_46_im) * (2.0 * x_46_re)) + ((x_46_im * (x_46_re - x_46_im)) * (x_46_re + x_46_im));
}
def code(x_46_re, x_46_im):
	return ((x_46_re * x_46_im) * (2.0 * x_46_re)) + ((x_46_im * (x_46_re - x_46_im)) * (x_46_re + x_46_im))
function code(x_46_re, x_46_im)
	return Float64(Float64(Float64(x_46_re * x_46_im) * Float64(2.0 * x_46_re)) + Float64(Float64(x_46_im * Float64(x_46_re - x_46_im)) * Float64(x_46_re + x_46_im)))
end
function tmp = code(x_46_re, x_46_im)
	tmp = ((x_46_re * x_46_im) * (2.0 * x_46_re)) + ((x_46_im * (x_46_re - x_46_im)) * (x_46_re + x_46_im));
end
code[x$46$re_, x$46$im_] := N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] * N[(2.0 * x$46$re), $MachinePrecision]), $MachinePrecision] + N[(N[(x$46$im * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision] * N[(x$46$re + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right)
\end{array}

Reproduce

?
herbie shell --seed 2023257 
(FPCore (x.re x.im)
  :name "math.cube on complex, imaginary part"
  :precision binary64

  :herbie-target
  (+ (* (* x.re x.im) (* 2.0 x.re)) (* (* x.im (- x.re x.im)) (+ x.re x.im)))

  (+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re)))