math.cube on complex, imaginary part

Percentage Accurate: 82.0% → 99.8%
Time: 10.5s
Alternatives: 9
Speedup: 1.5×

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 9 alternatives:

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

Initial Program: 82.0% 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.8% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq -4 \cdot 10^{+104} \lor \neg \left(x.im \leq 2 \cdot 10^{+98}\right):\\
\;\;\;\;x.im \cdot \left(2 + \left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < -4e104 or 2e98 < x.im

    1. Initial program 80.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. *-commutative80.5%

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

        \[\leadsto \color{blue}{\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 \]
      3. difference-of-squares87.8%

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

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

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

        \[\leadsto \mathsf{fma}\left(x.re + x.im, \color{blue}{x.im \cdot \left(x.re - x.im\right)}, \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right) \]
      7. *-commutative87.8%

        \[\leadsto \mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), \color{blue}{x.re \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}\right) \]
      8. *-commutative87.8%

        \[\leadsto \mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)\right) \]
      9. distribute-lft-out87.8%

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

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

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

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

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

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

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

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

        \[\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.im \cdot x.re\right) \cdot x.re} \]
      8. +-commutative80.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} \]
    5. Applied egg-rr86.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4e104 < x.im < 2e98

    1. Initial program 94.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. +-commutative94.4%

        \[\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. *-commutative94.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \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.re \cdot x.im + x.re \cdot x.im\right) \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(2 + \left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (<=
      (+
       (* x.im (- (* x.re x.re) (* x.im x.im)))
       (* x.re (+ (* x.re x.im) (* x.re x.im))))
      INFINITY)
   (fma (+ x.re x.im) (* x.im (- x.re x.im)) (* x.re (* x.re (+ x.im x.im))))
   (* x.im (+ 2.0 (* (+ x.re x.im) (- x.re x.im))))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if (((x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) + (x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im)))) <= ((double) INFINITY)) {
		tmp = fma((x_46_re + x_46_im), (x_46_im * (x_46_re - x_46_im)), (x_46_re * (x_46_re * (x_46_im + x_46_im))));
	} else {
		tmp = x_46_im * (2.0 + ((x_46_re + x_46_im) * (x_46_re - x_46_im)));
	}
	return tmp;
}
function code(x_46_re, x_46_im)
	tmp = 0.0
	if (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_re * x_46_im) + Float64(x_46_re * x_46_im)))) <= Inf)
		tmp = fma(Float64(x_46_re + x_46_im), Float64(x_46_im * Float64(x_46_re - x_46_im)), Float64(x_46_re * Float64(x_46_re * Float64(x_46_im + x_46_im))));
	else
		tmp = Float64(x_46_im * Float64(2.0 + Float64(Float64(x_46_re + x_46_im) * Float64(x_46_re - x_46_im))));
	end
	return tmp
end
code[x$46$re_, x$46$im_] := If[LessEqual[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$re * x$46$im), $MachinePrecision] + N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(x$46$re + x$46$im), $MachinePrecision] * N[(x$46$im * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision] + N[(x$46$re * N[(x$46$re * N[(x$46$im + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(2.0 + N[(N[(x$46$re + x$46$im), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\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.re \cdot x.im + x.re \cdot x.im\right) \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x.im \cdot \left(2 + \left(x.re + x.im\right) \cdot \left(x.re - x.im\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)) < +inf.0

    1. Initial program 95.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. Step-by-step derivation
      1. *-commutative95.9%

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

        \[\leadsto \color{blue}{\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 \]
      3. difference-of-squares95.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), \color{blue}{x.re \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}\right) \]
      8. *-commutative99.8%

        \[\leadsto \mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)\right) \]
      9. distribute-lft-out99.8%

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

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

    if +inf.0 < (+.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 0.0%

      \[\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. *-commutative0.0%

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

        \[\leadsto \color{blue}{\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 \]
      3. difference-of-squares37.5%

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

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

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

        \[\leadsto \mathsf{fma}\left(x.re + x.im, \color{blue}{x.im \cdot \left(x.re - x.im\right)}, \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right) \]
      7. *-commutative37.5%

        \[\leadsto \mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), \color{blue}{x.re \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}\right) \]
      8. *-commutative37.5%

        \[\leadsto \mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)\right) \]
      9. distribute-lft-out37.5%

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

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

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

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

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

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

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

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

        \[\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.im \cdot x.re\right) \cdot x.re} \]
      8. +-commutative0.0%

        \[\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} \]
    5. Applied egg-rr31.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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.re \cdot x.im + x.re \cdot x.im\right) \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(2 + \left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)\\ \end{array} \]

Alternative 3: 91.2% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \leq -2.1 \lor \neg \left(x.im \leq 2200000\right):\\ \;\;\;\;x.im \cdot \left(2 + \left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(\left(x.re \cdot x.im\right) \cdot 3\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (or (<= x.im -2.1) (not (<= x.im 2200000.0)))
   (* x.im (+ 2.0 (* (+ x.re x.im) (- x.re x.im))))
   (* x.re (* (* x.re x.im) 3.0))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -2.1) || !(x_46_im <= 2200000.0)) {
		tmp = x_46_im * (2.0 + ((x_46_re + x_46_im) * (x_46_re - x_46_im)));
	} else {
		tmp = x_46_re * ((x_46_re * 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 <= (-2.1d0)) .or. (.not. (x_46im <= 2200000.0d0))) then
        tmp = x_46im * (2.0d0 + ((x_46re + x_46im) * (x_46re - x_46im)))
    else
        tmp = x_46re * ((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 <= -2.1) || !(x_46_im <= 2200000.0)) {
		tmp = x_46_im * (2.0 + ((x_46_re + x_46_im) * (x_46_re - x_46_im)));
	} else {
		tmp = x_46_re * ((x_46_re * x_46_im) * 3.0);
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if (x_46_im <= -2.1) or not (x_46_im <= 2200000.0):
		tmp = x_46_im * (2.0 + ((x_46_re + x_46_im) * (x_46_re - x_46_im)))
	else:
		tmp = x_46_re * ((x_46_re * x_46_im) * 3.0)
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if ((x_46_im <= -2.1) || !(x_46_im <= 2200000.0))
		tmp = Float64(x_46_im * Float64(2.0 + Float64(Float64(x_46_re + x_46_im) * Float64(x_46_re - x_46_im))));
	else
		tmp = Float64(x_46_re * Float64(Float64(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 <= -2.1) || ~((x_46_im <= 2200000.0)))
		tmp = x_46_im * (2.0 + ((x_46_re + x_46_im) * (x_46_re - x_46_im)));
	else
		tmp = x_46_re * ((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, -2.1], N[Not[LessEqual[x$46$im, 2200000.0]], $MachinePrecision]], N[(x$46$im * N[(2.0 + N[(N[(x$46$re + x$46$im), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$re * N[(N[(x$46$re * x$46$im), $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < -2.10000000000000009 or 2.2e6 < x.im

    1. Initial program 86.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. *-commutative86.6%

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

        \[\leadsto \color{blue}{\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 \]
      3. difference-of-squares91.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right) \cdot x.im} + x.re \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]
      4. difference-of-squares86.6%

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

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

        \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.im \cdot x.re}\right) \]
      7. *-commutative86.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.im \cdot x.re\right) \cdot x.re} \]
      8. +-commutative86.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} \]
    5. Applied egg-rr88.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.10000000000000009 < x.im < 2.2e6

    1. Initial program 92.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. Step-by-step derivation
      1. difference-of-squares20.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \left(x.im \cdot {x.re}^{2}\right)} \]
      4. metadata-eval76.0%

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

        \[\leadsto 3 \cdot \left(x.im \cdot \color{blue}{\left(x.re \cdot x.re\right)}\right) \]
    7. Simplified76.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x.re \cdot \left(x.im \cdot \left(3 \cdot x.re\right)\right)\right)\right)} \]
      7. expm1-udef45.5%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(x.re \cdot \left(x.im \cdot \left(3 \cdot x.re\right)\right)\right)} - 1} \]
      8. *-commutative45.5%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(x.im \cdot \left(3 \cdot x.re\right)\right) \cdot x.re}\right)} - 1 \]
      9. associate-*l*41.2%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{x.im \cdot \left(\left(3 \cdot x.re\right) \cdot x.re\right)}\right)} - 1 \]
      10. *-commutative41.2%

        \[\leadsto e^{\mathsf{log1p}\left(x.im \cdot \left(\color{blue}{\left(x.re \cdot 3\right)} \cdot x.re\right)\right)} - 1 \]
    9. Applied egg-rr41.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(x.im \cdot \left(\left(x.re \cdot 3\right) \cdot x.re\right)\right)} - 1} \]
    10. Simplified82.7%

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

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

Alternative 4: 91.9% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.re \leq 2.2 \cdot 10^{+152}:\\ \;\;\;\;x.im \cdot \left(\left(x.re \cdot x.re\right) \cdot 3 - x.im \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (<= x.re 2.2e+152)
   (* x.im (- (* (* x.re x.re) 3.0) (* x.im x.im)))
   (* x.re (* x.im (* x.re 3.0)))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if (x_46_re <= 2.2e+152) {
		tmp = x_46_im * (((x_46_re * x_46_re) * 3.0) - (x_46_im * x_46_im));
	} else {
		tmp = x_46_re * (x_46_im * (x_46_re * 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_46re <= 2.2d+152) then
        tmp = x_46im * (((x_46re * x_46re) * 3.0d0) - (x_46im * x_46im))
    else
        tmp = x_46re * (x_46im * (x_46re * 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_re <= 2.2e+152) {
		tmp = x_46_im * (((x_46_re * x_46_re) * 3.0) - (x_46_im * x_46_im));
	} else {
		tmp = x_46_re * (x_46_im * (x_46_re * 3.0));
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if x_46_re <= 2.2e+152:
		tmp = x_46_im * (((x_46_re * x_46_re) * 3.0) - (x_46_im * x_46_im))
	else:
		tmp = x_46_re * (x_46_im * (x_46_re * 3.0))
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if (x_46_re <= 2.2e+152)
		tmp = Float64(x_46_im * Float64(Float64(Float64(x_46_re * x_46_re) * 3.0) - Float64(x_46_im * x_46_im)));
	else
		tmp = Float64(x_46_re * Float64(x_46_im * Float64(x_46_re * 3.0)));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	tmp = 0.0;
	if (x_46_re <= 2.2e+152)
		tmp = x_46_im * (((x_46_re * x_46_re) * 3.0) - (x_46_im * x_46_im));
	else
		tmp = x_46_re * (x_46_im * (x_46_re * 3.0));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[LessEqual[x$46$re, 2.2e+152], N[(x$46$im * N[(N[(N[(x$46$re * x$46$re), $MachinePrecision] * 3.0), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$re * N[(x$46$im * N[(x$46$re * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.re \leq 2.2 \cdot 10^{+152}:\\
\;\;\;\;x.im \cdot \left(\left(x.re \cdot x.re\right) \cdot 3 - x.im \cdot x.im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.re < 2.1999999999999998e152

    1. Initial program 94.1%

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

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

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

      \[\leadsto \left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right) \cdot x.im + \color{blue}{\left(2 \cdot \left(x.im \cdot x.re\right)\right)} \cdot x.re \]
    5. Taylor expanded in x.im around 0 94.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.1999999999999998e152 < x.re

    1. Initial program 58.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. difference-of-squares78.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 50.1% accurate, 2.7× speedup?

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

\\
3 \cdot \left(\left(x.re \cdot x.re\right) \cdot x.im\right)
\end{array}
Derivation
  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. Step-by-step derivation
    1. difference-of-squares56.7%

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

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

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

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

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

      \[\leadsto x.im \cdot {x.re}^{2} + \color{blue}{2 \cdot \left(x.im \cdot {x.re}^{2}\right)} \]
    3. distribute-rgt1-in51.6%

      \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \left(x.im \cdot {x.re}^{2}\right)} \]
    4. metadata-eval51.6%

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

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

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

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

Alternative 6: 50.1% accurate, 2.7× speedup?

\[\begin{array}{l} \\ x.im \cdot \left(\left(x.re \cdot x.re\right) \cdot 3\right) \end{array} \]
(FPCore (x.re x.im) :precision binary64 (* x.im (* (* x.re x.re) 3.0)))
double code(double x_46_re, double x_46_im) {
	return x_46_im * ((x_46_re * x_46_re) * 3.0);
}
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) * 3.0d0)
end function
public static double code(double x_46_re, double x_46_im) {
	return x_46_im * ((x_46_re * x_46_re) * 3.0);
}
def code(x_46_re, x_46_im):
	return x_46_im * ((x_46_re * x_46_re) * 3.0)
function code(x_46_re, x_46_im)
	return Float64(x_46_im * Float64(Float64(x_46_re * x_46_re) * 3.0))
end
function tmp = code(x_46_re, x_46_im)
	tmp = x_46_im * ((x_46_re * x_46_re) * 3.0);
end
code[x$46$re_, x$46$im_] := N[(x$46$im * N[(N[(x$46$re * x$46$re), $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x.im \cdot \left(\left(x.re \cdot x.re\right) \cdot 3\right)
\end{array}
Derivation
  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. Step-by-step derivation
    1. difference-of-squares56.7%

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

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

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

    \[\leadsto \color{blue}{{x.re}^{2} \cdot \left(x.im + 2 \cdot x.im\right)} \]
  6. Step-by-step derivation
    1. distribute-rgt1-in51.7%

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

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

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

      \[\leadsto \color{blue}{\left(x.im \cdot 3\right)} \cdot {x.re}^{2} \]
    5. associate-*r*51.7%

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

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

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

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

Alternative 7: 56.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right) \end{array} \]
(FPCore (x.re x.im) :precision binary64 (* x.re (* x.im (* x.re 3.0))))
double code(double x_46_re, double x_46_im) {
	return x_46_re * (x_46_im * (x_46_re * 3.0));
}
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 * (x_46re * 3.0d0))
end function
public static double code(double x_46_re, double x_46_im) {
	return x_46_re * (x_46_im * (x_46_re * 3.0));
}
def code(x_46_re, x_46_im):
	return x_46_re * (x_46_im * (x_46_re * 3.0))
function code(x_46_re, x_46_im)
	return Float64(x_46_re * Float64(x_46_im * Float64(x_46_re * 3.0)))
end
function tmp = code(x_46_re, x_46_im)
	tmp = x_46_re * (x_46_im * (x_46_re * 3.0));
end
code[x$46$re_, x$46$im_] := N[(x$46$re * N[(x$46$im * N[(x$46$re * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right)
\end{array}
Derivation
  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. Step-by-step derivation
    1. difference-of-squares56.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 56.1% accurate, 2.7× speedup?

\[\begin{array}{l} \\ x.re \cdot \left(\left(x.re \cdot x.im\right) \cdot 3\right) \end{array} \]
(FPCore (x.re x.im) :precision binary64 (* x.re (* (* x.re x.im) 3.0)))
double code(double x_46_re, double x_46_im) {
	return x_46_re * ((x_46_re * x_46_im) * 3.0);
}
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) * 3.0d0)
end function
public static double code(double x_46_re, double x_46_im) {
	return x_46_re * ((x_46_re * x_46_im) * 3.0);
}
def code(x_46_re, x_46_im):
	return x_46_re * ((x_46_re * x_46_im) * 3.0)
function code(x_46_re, x_46_im)
	return Float64(x_46_re * Float64(Float64(x_46_re * x_46_im) * 3.0))
end
function tmp = code(x_46_re, x_46_im)
	tmp = x_46_re * ((x_46_re * x_46_im) * 3.0);
end
code[x$46$re_, x$46$im_] := N[(x$46$re * N[(N[(x$46$re * x$46$im), $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x.re \cdot \left(\left(x.re \cdot x.im\right) \cdot 3\right)
\end{array}
Derivation
  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. Step-by-step derivation
    1. difference-of-squares56.7%

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

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

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

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

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

      \[\leadsto x.im \cdot {x.re}^{2} + \color{blue}{2 \cdot \left(x.im \cdot {x.re}^{2}\right)} \]
    3. distribute-rgt1-in51.6%

      \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \left(x.im \cdot {x.re}^{2}\right)} \]
    4. metadata-eval51.6%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{x.re \cdot \left(x.im \cdot \left(3 \cdot x.re\right)\right)} \]
    6. expm1-log1p-u40.7%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x.re \cdot \left(x.im \cdot \left(3 \cdot x.re\right)\right)\right)\right)} \]
    7. expm1-udef29.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(x.re \cdot \left(x.im \cdot \left(3 \cdot x.re\right)\right)\right)} - 1} \]
    8. *-commutative29.5%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(x.im \cdot \left(3 \cdot x.re\right)\right) \cdot x.re}\right)} - 1 \]
    9. associate-*l*27.3%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{x.im \cdot \left(\left(3 \cdot x.re\right) \cdot x.re\right)}\right)} - 1 \]
    10. *-commutative27.3%

      \[\leadsto e^{\mathsf{log1p}\left(x.im \cdot \left(\color{blue}{\left(x.re \cdot 3\right)} \cdot x.re\right)\right)} - 1 \]
  9. Applied egg-rr27.3%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(x.im \cdot \left(\left(x.re \cdot 3\right) \cdot x.re\right)\right)} - 1} \]
  10. Simplified55.2%

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

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

Alternative 9: 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 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. Step-by-step derivation
    1. *-commutative89.9%

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

      \[\leadsto \color{blue}{\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 \]
    3. difference-of-squares92.3%

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

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

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

      \[\leadsto \mathsf{fma}\left(x.re + x.im, \color{blue}{x.im \cdot \left(x.re - x.im\right)}, \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right) \]
    7. *-commutative95.9%

      \[\leadsto \mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), \color{blue}{x.re \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}\right) \]
    8. *-commutative95.9%

      \[\leadsto \mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)\right) \]
    9. distribute-lft-out95.9%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
  4. Taylor expanded in x.re around 0 57.8%

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

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

    \[\leadsto -3 \]

Developer target: 91.0% 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 2023275 
(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)))