math.cube on complex, imaginary part

Percentage Accurate: 82.4% → 99.8%
Time: 7.1s
Alternatives: 10
Speedup: 0.9×

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.4% 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} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ x.im\_s \cdot \begin{array}{l} \mathbf{if}\;x.im\_m \leq 2 \cdot 10^{+99}:\\ \;\;\;\;\left(x.re \cdot \left(x.im\_m \cdot x.re\right)\right) \cdot 3 - {x.im\_m}^{3}\\ \mathbf{else}:\\ \;\;\;\;x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right) + -1\\ \end{array} \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m)
 :precision binary64
 (*
  x.im_s
  (if (<= x.im_m 2e+99)
    (- (* (* x.re (* x.im_m x.re)) 3.0) (pow x.im_m 3.0))
    (+ (* x.im_m (* (- x.re x.im_m) (+ x.im_m x.re))) -1.0))))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double tmp;
	if (x_46_im_m <= 2e+99) {
		tmp = ((x_46_re * (x_46_im_m * x_46_re)) * 3.0) - pow(x_46_im_m, 3.0);
	} else {
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0;
	}
	return x_46_im_s * tmp;
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    real(8) :: tmp
    if (x_46im_m <= 2d+99) then
        tmp = ((x_46re * (x_46im_m * x_46re)) * 3.0d0) - (x_46im_m ** 3.0d0)
    else
        tmp = (x_46im_m * ((x_46re - x_46im_m) * (x_46im_m + x_46re))) + (-1.0d0)
    end if
    code = x_46im_s * tmp
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double tmp;
	if (x_46_im_m <= 2e+99) {
		tmp = ((x_46_re * (x_46_im_m * x_46_re)) * 3.0) - Math.pow(x_46_im_m, 3.0);
	} else {
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0;
	}
	return x_46_im_s * tmp;
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	tmp = 0
	if x_46_im_m <= 2e+99:
		tmp = ((x_46_re * (x_46_im_m * x_46_re)) * 3.0) - math.pow(x_46_im_m, 3.0)
	else:
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0
	return x_46_im_s * tmp
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = 0.0
	if (x_46_im_m <= 2e+99)
		tmp = Float64(Float64(Float64(x_46_re * Float64(x_46_im_m * x_46_re)) * 3.0) - (x_46_im_m ^ 3.0));
	else
		tmp = Float64(Float64(x_46_im_m * Float64(Float64(x_46_re - x_46_im_m) * Float64(x_46_im_m + x_46_re))) + -1.0);
	end
	return Float64(x_46_im_s * tmp)
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp_2 = code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = 0.0;
	if (x_46_im_m <= 2e+99)
		tmp = ((x_46_re * (x_46_im_m * x_46_re)) * 3.0) - (x_46_im_m ^ 3.0);
	else
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0;
	end
	tmp_2 = x_46_im_s * tmp;
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := N[(x$46$im$95$s * If[LessEqual[x$46$im$95$m, 2e+99], N[(N[(N[(x$46$re * N[(x$46$im$95$m * x$46$re), $MachinePrecision]), $MachinePrecision] * 3.0), $MachinePrecision] - N[Power[x$46$im$95$m, 3.0], $MachinePrecision]), $MachinePrecision], N[(N[(x$46$im$95$m * N[(N[(x$46$re - x$46$im$95$m), $MachinePrecision] * N[(x$46$im$95$m + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < 1.9999999999999999e99

    1. Initial program 86.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. Simplified91.0%

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

    if 1.9999999999999999e99 < x.im

    1. Initial program 61.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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares70.7%

        \[\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 \]
      2. *-commutative70.7%

        \[\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. Applied egg-rr70.7%

      \[\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 \]
    5. Step-by-step derivation
      1. *-commutative70.7%

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

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

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

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

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

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)} \cdot x.re \]
    7. Step-by-step derivation
      1. add-log-exp29.3%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\log \left(e^{\left(x.re \cdot x.im\right) \cdot 2}\right)} \cdot x.re \]
      2. exp-lft-sqr29.3%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im} \cdot e^{x.re \cdot x.im}\right)} \cdot x.re \]
      3. exp-sum29.3%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im + x.re \cdot x.im}\right)} \cdot x.re \]
      4. add-log-exp70.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq 2 \cdot 10^{+99}:\\ \;\;\;\;\left(x.re \cdot \left(x.im \cdot x.re\right)\right) \cdot 3 - {x.im}^{3}\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 98.0% accurate, 0.5× speedup?

\[\begin{array}{l} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ \begin{array}{l} t_0 := x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right)\\ t_1 := t\_0 + x.re \cdot \left(\left(x.im\_m \cdot x.re\right) \cdot 2\right)\\ t_2 := x.re \cdot \left(x.im\_m \cdot x.re + x.im\_m \cdot x.re\right) + \left(x.im\_m \cdot x.re\right) \cdot \left(x.im\_m + x.re\right)\\ x.im\_s \cdot \begin{array}{l} \mathbf{if}\;x.im\_m \leq 6.8 \cdot 10^{-144}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;x.im\_m \leq 2.65 \cdot 10^{-40}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x.im\_m \leq 2.7 \cdot 10^{-40}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;x.im\_m \leq 1.28 \cdot 10^{+32}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0 + -1\\ \end{array} \end{array} \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m)
 :precision binary64
 (let* ((t_0 (* x.im_m (* (- x.re x.im_m) (+ x.im_m x.re))))
        (t_1 (+ t_0 (* x.re (* (* x.im_m x.re) 2.0))))
        (t_2
         (+
          (* x.re (+ (* x.im_m x.re) (* x.im_m x.re)))
          (* (* x.im_m x.re) (+ x.im_m x.re)))))
   (*
    x.im_s
    (if (<= x.im_m 6.8e-144)
      t_2
      (if (<= x.im_m 2.65e-40)
        t_1
        (if (<= x.im_m 2.7e-40)
          t_2
          (if (<= x.im_m 1.28e+32) t_1 (+ t_0 -1.0))))))))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double t_0 = x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re));
	double t_1 = t_0 + (x_46_re * ((x_46_im_m * x_46_re) * 2.0));
	double t_2 = (x_46_re * ((x_46_im_m * x_46_re) + (x_46_im_m * x_46_re))) + ((x_46_im_m * x_46_re) * (x_46_im_m + x_46_re));
	double tmp;
	if (x_46_im_m <= 6.8e-144) {
		tmp = t_2;
	} else if (x_46_im_m <= 2.65e-40) {
		tmp = t_1;
	} else if (x_46_im_m <= 2.7e-40) {
		tmp = t_2;
	} else if (x_46_im_m <= 1.28e+32) {
		tmp = t_1;
	} else {
		tmp = t_0 + -1.0;
	}
	return x_46_im_s * tmp;
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = x_46im_m * ((x_46re - x_46im_m) * (x_46im_m + x_46re))
    t_1 = t_0 + (x_46re * ((x_46im_m * x_46re) * 2.0d0))
    t_2 = (x_46re * ((x_46im_m * x_46re) + (x_46im_m * x_46re))) + ((x_46im_m * x_46re) * (x_46im_m + x_46re))
    if (x_46im_m <= 6.8d-144) then
        tmp = t_2
    else if (x_46im_m <= 2.65d-40) then
        tmp = t_1
    else if (x_46im_m <= 2.7d-40) then
        tmp = t_2
    else if (x_46im_m <= 1.28d+32) then
        tmp = t_1
    else
        tmp = t_0 + (-1.0d0)
    end if
    code = x_46im_s * tmp
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double t_0 = x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re));
	double t_1 = t_0 + (x_46_re * ((x_46_im_m * x_46_re) * 2.0));
	double t_2 = (x_46_re * ((x_46_im_m * x_46_re) + (x_46_im_m * x_46_re))) + ((x_46_im_m * x_46_re) * (x_46_im_m + x_46_re));
	double tmp;
	if (x_46_im_m <= 6.8e-144) {
		tmp = t_2;
	} else if (x_46_im_m <= 2.65e-40) {
		tmp = t_1;
	} else if (x_46_im_m <= 2.7e-40) {
		tmp = t_2;
	} else if (x_46_im_m <= 1.28e+32) {
		tmp = t_1;
	} else {
		tmp = t_0 + -1.0;
	}
	return x_46_im_s * tmp;
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	t_0 = x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))
	t_1 = t_0 + (x_46_re * ((x_46_im_m * x_46_re) * 2.0))
	t_2 = (x_46_re * ((x_46_im_m * x_46_re) + (x_46_im_m * x_46_re))) + ((x_46_im_m * x_46_re) * (x_46_im_m + x_46_re))
	tmp = 0
	if x_46_im_m <= 6.8e-144:
		tmp = t_2
	elif x_46_im_m <= 2.65e-40:
		tmp = t_1
	elif x_46_im_m <= 2.7e-40:
		tmp = t_2
	elif x_46_im_m <= 1.28e+32:
		tmp = t_1
	else:
		tmp = t_0 + -1.0
	return x_46_im_s * tmp
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	t_0 = Float64(x_46_im_m * Float64(Float64(x_46_re - x_46_im_m) * Float64(x_46_im_m + x_46_re)))
	t_1 = Float64(t_0 + Float64(x_46_re * Float64(Float64(x_46_im_m * x_46_re) * 2.0)))
	t_2 = Float64(Float64(x_46_re * Float64(Float64(x_46_im_m * x_46_re) + Float64(x_46_im_m * x_46_re))) + Float64(Float64(x_46_im_m * x_46_re) * Float64(x_46_im_m + x_46_re)))
	tmp = 0.0
	if (x_46_im_m <= 6.8e-144)
		tmp = t_2;
	elseif (x_46_im_m <= 2.65e-40)
		tmp = t_1;
	elseif (x_46_im_m <= 2.7e-40)
		tmp = t_2;
	elseif (x_46_im_m <= 1.28e+32)
		tmp = t_1;
	else
		tmp = Float64(t_0 + -1.0);
	end
	return Float64(x_46_im_s * tmp)
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp_2 = code(x_46_im_s, x_46_re, x_46_im_m)
	t_0 = x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re));
	t_1 = t_0 + (x_46_re * ((x_46_im_m * x_46_re) * 2.0));
	t_2 = (x_46_re * ((x_46_im_m * x_46_re) + (x_46_im_m * x_46_re))) + ((x_46_im_m * x_46_re) * (x_46_im_m + x_46_re));
	tmp = 0.0;
	if (x_46_im_m <= 6.8e-144)
		tmp = t_2;
	elseif (x_46_im_m <= 2.65e-40)
		tmp = t_1;
	elseif (x_46_im_m <= 2.7e-40)
		tmp = t_2;
	elseif (x_46_im_m <= 1.28e+32)
		tmp = t_1;
	else
		tmp = t_0 + -1.0;
	end
	tmp_2 = x_46_im_s * tmp;
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := Block[{t$95$0 = N[(x$46$im$95$m * N[(N[(x$46$re - x$46$im$95$m), $MachinePrecision] * N[(x$46$im$95$m + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[(x$46$re * N[(N[(x$46$im$95$m * x$46$re), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x$46$re * N[(N[(x$46$im$95$m * x$46$re), $MachinePrecision] + N[(x$46$im$95$m * x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(x$46$im$95$m * x$46$re), $MachinePrecision] * N[(x$46$im$95$m + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(x$46$im$95$s * If[LessEqual[x$46$im$95$m, 6.8e-144], t$95$2, If[LessEqual[x$46$im$95$m, 2.65e-40], t$95$1, If[LessEqual[x$46$im$95$m, 2.7e-40], t$95$2, If[LessEqual[x$46$im$95$m, 1.28e+32], t$95$1, N[(t$95$0 + -1.0), $MachinePrecision]]]]]), $MachinePrecision]]]]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
\begin{array}{l}
t_0 := x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right)\\
t_1 := t\_0 + x.re \cdot \left(\left(x.im\_m \cdot x.re\right) \cdot 2\right)\\
t_2 := x.re \cdot \left(x.im\_m \cdot x.re + x.im\_m \cdot x.re\right) + \left(x.im\_m \cdot x.re\right) \cdot \left(x.im\_m + x.re\right)\\
x.im\_s \cdot \begin{array}{l}
\mathbf{if}\;x.im\_m \leq 6.8 \cdot 10^{-144}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;x.im\_m \leq 2.65 \cdot 10^{-40}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x.im\_m \leq 2.7 \cdot 10^{-40}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;x.im\_m \leq 1.28 \cdot 10^{+32}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x.im < 6.80000000000000035e-144 or 2.6500000000000001e-40 < x.im < 2.7e-40

    1. Initial program 82.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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares84.1%

        \[\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 \]
      2. *-commutative84.1%

        \[\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. Applied egg-rr84.1%

      \[\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 \]
    5. Step-by-step derivation
      1. *-commutative84.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(x.im + x.re\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 \]
      6. associate-*l*90.7%

        \[\leadsto \color{blue}{\left(x.im + x.re\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 \]
      7. *-commutative90.7%

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

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

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

    if 6.80000000000000035e-144 < x.im < 2.6500000000000001e-40 or 2.7e-40 < x.im < 1.28e32

    1. Initial program 99.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares99.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 \]
      2. *-commutative99.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. Applied egg-rr99.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 \]
    5. Step-by-step derivation
      1. *-commutative99.8%

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

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

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

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

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

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

    if 1.28e32 < x.im

    1. Initial program 70.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares78.1%

        \[\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 \]
      2. *-commutative78.1%

        \[\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. Applied egg-rr78.1%

      \[\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 \]
    5. Step-by-step derivation
      1. *-commutative78.1%

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

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

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

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

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

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)} \cdot x.re \]
    7. Step-by-step derivation
      1. add-log-exp43.5%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\log \left(e^{\left(x.re \cdot x.im\right) \cdot 2}\right)} \cdot x.re \]
      2. exp-lft-sqr43.5%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im} \cdot e^{x.re \cdot x.im}\right)} \cdot x.re \]
      3. exp-sum43.5%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im + x.re \cdot x.im}\right)} \cdot x.re \]
      4. add-log-exp78.1%

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

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

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)\right)} \]
      7. expm1-undefine78.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq 6.8 \cdot 10^{-144}:\\ \;\;\;\;x.re \cdot \left(x.im \cdot x.re + x.im \cdot x.re\right) + \left(x.im \cdot x.re\right) \cdot \left(x.im + x.re\right)\\ \mathbf{elif}\;x.im \leq 2.65 \cdot 10^{-40}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 2\right)\\ \mathbf{elif}\;x.im \leq 2.7 \cdot 10^{-40}:\\ \;\;\;\;x.re \cdot \left(x.im \cdot x.re + x.im \cdot x.re\right) + \left(x.im \cdot x.re\right) \cdot \left(x.im + x.re\right)\\ \mathbf{elif}\;x.im \leq 1.28 \cdot 10^{+32}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.0% accurate, 0.8× speedup?

\[\begin{array}{l} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ x.im\_s \cdot \begin{array}{l} \mathbf{if}\;x.im\_m \leq 1.28 \cdot 10^{+32}:\\ \;\;\;\;\left(x.im\_m + x.re\right) \cdot \left(x.im\_m \cdot \left(x.re - x.im\_m\right)\right) + x.re \cdot \left(x.im\_m \cdot x.re + x.im\_m \cdot x.re\right)\\ \mathbf{else}:\\ \;\;\;\;x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right) + -1\\ \end{array} \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m)
 :precision binary64
 (*
  x.im_s
  (if (<= x.im_m 1.28e+32)
    (+
     (* (+ x.im_m x.re) (* x.im_m (- x.re x.im_m)))
     (* x.re (+ (* x.im_m x.re) (* x.im_m x.re))))
    (+ (* x.im_m (* (- x.re x.im_m) (+ x.im_m x.re))) -1.0))))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double tmp;
	if (x_46_im_m <= 1.28e+32) {
		tmp = ((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) + (x_46_re * ((x_46_im_m * x_46_re) + (x_46_im_m * x_46_re)));
	} else {
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0;
	}
	return x_46_im_s * tmp;
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    real(8) :: tmp
    if (x_46im_m <= 1.28d+32) then
        tmp = ((x_46im_m + x_46re) * (x_46im_m * (x_46re - x_46im_m))) + (x_46re * ((x_46im_m * x_46re) + (x_46im_m * x_46re)))
    else
        tmp = (x_46im_m * ((x_46re - x_46im_m) * (x_46im_m + x_46re))) + (-1.0d0)
    end if
    code = x_46im_s * tmp
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double tmp;
	if (x_46_im_m <= 1.28e+32) {
		tmp = ((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) + (x_46_re * ((x_46_im_m * x_46_re) + (x_46_im_m * x_46_re)));
	} else {
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0;
	}
	return x_46_im_s * tmp;
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	tmp = 0
	if x_46_im_m <= 1.28e+32:
		tmp = ((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) + (x_46_re * ((x_46_im_m * x_46_re) + (x_46_im_m * x_46_re)))
	else:
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0
	return x_46_im_s * tmp
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = 0.0
	if (x_46_im_m <= 1.28e+32)
		tmp = Float64(Float64(Float64(x_46_im_m + x_46_re) * Float64(x_46_im_m * Float64(x_46_re - x_46_im_m))) + Float64(x_46_re * Float64(Float64(x_46_im_m * x_46_re) + Float64(x_46_im_m * x_46_re))));
	else
		tmp = Float64(Float64(x_46_im_m * Float64(Float64(x_46_re - x_46_im_m) * Float64(x_46_im_m + x_46_re))) + -1.0);
	end
	return Float64(x_46_im_s * tmp)
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp_2 = code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = 0.0;
	if (x_46_im_m <= 1.28e+32)
		tmp = ((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) + (x_46_re * ((x_46_im_m * x_46_re) + (x_46_im_m * x_46_re)));
	else
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0;
	end
	tmp_2 = x_46_im_s * tmp;
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := N[(x$46$im$95$s * If[LessEqual[x$46$im$95$m, 1.28e+32], N[(N[(N[(x$46$im$95$m + x$46$re), $MachinePrecision] * N[(x$46$im$95$m * N[(x$46$re - x$46$im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x$46$re * N[(N[(x$46$im$95$m * x$46$re), $MachinePrecision] + N[(x$46$im$95$m * x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$46$im$95$m * N[(N[(x$46$re - x$46$im$95$m), $MachinePrecision] * N[(x$46$im$95$m + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
x.im\_s \cdot \begin{array}{l}
\mathbf{if}\;x.im\_m \leq 1.28 \cdot 10^{+32}:\\
\;\;\;\;\left(x.im\_m + x.re\right) \cdot \left(x.im\_m \cdot \left(x.re - x.im\_m\right)\right) + x.re \cdot \left(x.im\_m \cdot x.re + x.im\_m \cdot x.re\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < 1.28e32

    1. Initial program 85.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares86.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 \]
      2. *-commutative86.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. Applied egg-rr86.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 \]
    5. Step-by-step derivation
      1. *-commutative86.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(x.im + x.re\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 \]
      6. associate-*l*92.3%

        \[\leadsto \color{blue}{\left(x.im + x.re\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 \]
      7. *-commutative92.3%

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

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

    if 1.28e32 < x.im

    1. Initial program 70.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares78.1%

        \[\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 \]
      2. *-commutative78.1%

        \[\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. Applied egg-rr78.1%

      \[\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 \]
    5. Step-by-step derivation
      1. *-commutative78.1%

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

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

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

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

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

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)} \cdot x.re \]
    7. Step-by-step derivation
      1. add-log-exp43.5%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\log \left(e^{\left(x.re \cdot x.im\right) \cdot 2}\right)} \cdot x.re \]
      2. exp-lft-sqr43.5%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im} \cdot e^{x.re \cdot x.im}\right)} \cdot x.re \]
      3. exp-sum43.5%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im + x.re \cdot x.im}\right)} \cdot x.re \]
      4. add-log-exp78.1%

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

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

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)\right)} \]
      7. expm1-undefine78.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq 1.28 \cdot 10^{+32}:\\ \;\;\;\;\left(x.im + x.re\right) \cdot \left(x.im \cdot \left(x.re - x.im\right)\right) + x.re \cdot \left(x.im \cdot x.re + x.im \cdot x.re\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 93.4% accurate, 0.9× speedup?

\[\begin{array}{l} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ \begin{array}{l} t_0 := x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right)\\ x.im\_s \cdot \begin{array}{l} \mathbf{if}\;x.im\_m \leq 1.28 \cdot 10^{+32}:\\ \;\;\;\;t\_0 + x.re \cdot \left(\left(x.im\_m \cdot x.re\right) \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 + -1\\ \end{array} \end{array} \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m)
 :precision binary64
 (let* ((t_0 (* x.im_m (* (- x.re x.im_m) (+ x.im_m x.re)))))
   (*
    x.im_s
    (if (<= x.im_m 1.28e+32)
      (+ t_0 (* x.re (* (* x.im_m x.re) 2.0)))
      (+ t_0 -1.0)))))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double t_0 = x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re));
	double tmp;
	if (x_46_im_m <= 1.28e+32) {
		tmp = t_0 + (x_46_re * ((x_46_im_m * x_46_re) * 2.0));
	} else {
		tmp = t_0 + -1.0;
	}
	return x_46_im_s * tmp;
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x_46im_m * ((x_46re - x_46im_m) * (x_46im_m + x_46re))
    if (x_46im_m <= 1.28d+32) then
        tmp = t_0 + (x_46re * ((x_46im_m * x_46re) * 2.0d0))
    else
        tmp = t_0 + (-1.0d0)
    end if
    code = x_46im_s * tmp
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double t_0 = x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re));
	double tmp;
	if (x_46_im_m <= 1.28e+32) {
		tmp = t_0 + (x_46_re * ((x_46_im_m * x_46_re) * 2.0));
	} else {
		tmp = t_0 + -1.0;
	}
	return x_46_im_s * tmp;
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	t_0 = x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))
	tmp = 0
	if x_46_im_m <= 1.28e+32:
		tmp = t_0 + (x_46_re * ((x_46_im_m * x_46_re) * 2.0))
	else:
		tmp = t_0 + -1.0
	return x_46_im_s * tmp
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	t_0 = Float64(x_46_im_m * Float64(Float64(x_46_re - x_46_im_m) * Float64(x_46_im_m + x_46_re)))
	tmp = 0.0
	if (x_46_im_m <= 1.28e+32)
		tmp = Float64(t_0 + Float64(x_46_re * Float64(Float64(x_46_im_m * x_46_re) * 2.0)));
	else
		tmp = Float64(t_0 + -1.0);
	end
	return Float64(x_46_im_s * tmp)
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp_2 = code(x_46_im_s, x_46_re, x_46_im_m)
	t_0 = x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re));
	tmp = 0.0;
	if (x_46_im_m <= 1.28e+32)
		tmp = t_0 + (x_46_re * ((x_46_im_m * x_46_re) * 2.0));
	else
		tmp = t_0 + -1.0;
	end
	tmp_2 = x_46_im_s * tmp;
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := Block[{t$95$0 = N[(x$46$im$95$m * N[(N[(x$46$re - x$46$im$95$m), $MachinePrecision] * N[(x$46$im$95$m + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(x$46$im$95$s * If[LessEqual[x$46$im$95$m, 1.28e+32], N[(t$95$0 + N[(x$46$re * N[(N[(x$46$im$95$m * x$46$re), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
\begin{array}{l}
t_0 := x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right)\\
x.im\_s \cdot \begin{array}{l}
\mathbf{if}\;x.im\_m \leq 1.28 \cdot 10^{+32}:\\
\;\;\;\;t\_0 + x.re \cdot \left(\left(x.im\_m \cdot x.re\right) \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < 1.28e32

    1. Initial program 85.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares86.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 \]
      2. *-commutative86.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. Applied egg-rr86.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 \]
    5. Step-by-step derivation
      1. *-commutative86.8%

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

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

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

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

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

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

    if 1.28e32 < x.im

    1. Initial program 70.8%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares78.1%

        \[\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 \]
      2. *-commutative78.1%

        \[\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. Applied egg-rr78.1%

      \[\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 \]
    5. Step-by-step derivation
      1. *-commutative78.1%

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

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

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

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

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

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)} \cdot x.re \]
    7. Step-by-step derivation
      1. add-log-exp43.5%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\log \left(e^{\left(x.re \cdot x.im\right) \cdot 2}\right)} \cdot x.re \]
      2. exp-lft-sqr43.5%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im} \cdot e^{x.re \cdot x.im}\right)} \cdot x.re \]
      3. exp-sum43.5%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im + x.re \cdot x.im}\right)} \cdot x.re \]
      4. add-log-exp78.1%

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

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

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)\right)} \]
      7. expm1-undefine78.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq 1.28 \cdot 10^{+32}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 71.5% accurate, 1.1× speedup?

\[\begin{array}{l} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ x.im\_s \cdot \begin{array}{l} \mathbf{if}\;x.re \leq 2.7 \cdot 10^{+166}:\\ \;\;\;\;x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right) - x.im\_m \cdot x.re\\ \mathbf{else}:\\ \;\;\;\;\left(x.im\_m + x.re\right) \cdot \left(x.im\_m \cdot \left(x.re - x.im\_m\right)\right) - x.re\\ \end{array} \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m)
 :precision binary64
 (*
  x.im_s
  (if (<= x.re 2.7e+166)
    (- (* x.im_m (* (- x.re x.im_m) (+ x.im_m x.re))) (* x.im_m x.re))
    (- (* (+ x.im_m x.re) (* x.im_m (- x.re x.im_m))) x.re))))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double tmp;
	if (x_46_re <= 2.7e+166) {
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) - (x_46_im_m * x_46_re);
	} else {
		tmp = ((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) - x_46_re;
	}
	return x_46_im_s * tmp;
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    real(8) :: tmp
    if (x_46re <= 2.7d+166) then
        tmp = (x_46im_m * ((x_46re - x_46im_m) * (x_46im_m + x_46re))) - (x_46im_m * x_46re)
    else
        tmp = ((x_46im_m + x_46re) * (x_46im_m * (x_46re - x_46im_m))) - x_46re
    end if
    code = x_46im_s * tmp
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	double tmp;
	if (x_46_re <= 2.7e+166) {
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) - (x_46_im_m * x_46_re);
	} else {
		tmp = ((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) - x_46_re;
	}
	return x_46_im_s * tmp;
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	tmp = 0
	if x_46_re <= 2.7e+166:
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) - (x_46_im_m * x_46_re)
	else:
		tmp = ((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) - x_46_re
	return x_46_im_s * tmp
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = 0.0
	if (x_46_re <= 2.7e+166)
		tmp = Float64(Float64(x_46_im_m * Float64(Float64(x_46_re - x_46_im_m) * Float64(x_46_im_m + x_46_re))) - Float64(x_46_im_m * x_46_re));
	else
		tmp = Float64(Float64(Float64(x_46_im_m + x_46_re) * Float64(x_46_im_m * Float64(x_46_re - x_46_im_m))) - x_46_re);
	end
	return Float64(x_46_im_s * tmp)
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp_2 = code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = 0.0;
	if (x_46_re <= 2.7e+166)
		tmp = (x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) - (x_46_im_m * x_46_re);
	else
		tmp = ((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) - x_46_re;
	end
	tmp_2 = x_46_im_s * tmp;
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := N[(x$46$im$95$s * If[LessEqual[x$46$re, 2.7e+166], N[(N[(x$46$im$95$m * N[(N[(x$46$re - x$46$im$95$m), $MachinePrecision] * N[(x$46$im$95$m + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im$95$m * x$46$re), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x$46$im$95$m + x$46$re), $MachinePrecision] * N[(x$46$im$95$m * N[(x$46$re - x$46$im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x$46$re), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
x.im\_s \cdot \begin{array}{l}
\mathbf{if}\;x.re \leq 2.7 \cdot 10^{+166}:\\
\;\;\;\;x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right) - x.im\_m \cdot x.re\\

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


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

    1. Initial program 86.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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares88.2%

        \[\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 \]
      2. *-commutative88.2%

        \[\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. Applied egg-rr88.2%

      \[\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 \]
    5. Step-by-step derivation
      1. *-commutative88.2%

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

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

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

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

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

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

        \[\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.re \cdot x.im\right)\right)} \cdot x.re \]
      2. count-288.2%

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

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\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 \]
      4. difference-of-squares0.0%

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

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

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

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

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \frac{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot \log 1}{\color{blue}{0}} \cdot x.re \]
      9. metadata-eval0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \frac{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot \log 1}{\color{blue}{\log 1}} \cdot x.re \]
      10. associate-*r/0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot \frac{\log 1}{\log 1}\right)} \cdot x.re \]
      11. metadata-eval0.0%

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

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot \frac{\color{blue}{\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)}}{\log 1}\right) \cdot x.re \]
      13. metadata-eval0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot \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)}{\color{blue}{0}}\right) \cdot x.re \]
      14. +-inverses0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot \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)}{\color{blue}{x.re \cdot x.im - x.re \cdot x.im}}\right) \cdot x.re \]
      15. flip-+62.6%

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

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

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

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

    if 2.70000000000000012e166 < x.re

    1. Initial program 51.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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares58.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 \]
      2. *-commutative58.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. Applied egg-rr58.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 \]
    5. Step-by-step derivation
      1. expm1-log1p-u26.1%

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

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

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)} - 1\right) \cdot x.re \]
      4. flip-+0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(\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}}\right)} - 1\right) \cdot x.re \]
      5. +-inverses0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 61.6% accurate, 1.7× speedup?

\[\begin{array}{l} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ x.im\_s \cdot \left(x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right) - x.re\right) \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m)
 :precision binary64
 (* x.im_s (- (* x.im_m (* (- x.re x.im_m) (+ x.im_m x.re))) x.re)))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * ((x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) - x_46_re);
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    code = x_46im_s * ((x_46im_m * ((x_46re - x_46im_m) * (x_46im_m + x_46re))) - x_46re)
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * ((x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) - x_46_re);
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	return x_46_im_s * ((x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) - x_46_re)
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	return Float64(x_46_im_s * Float64(Float64(x_46_im_m * Float64(Float64(x_46_re - x_46_im_m) * Float64(x_46_im_m + x_46_re))) - x_46_re))
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp = code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = x_46_im_s * ((x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) - x_46_re);
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := N[(x$46$im$95$s * N[(N[(x$46$im$95$m * N[(N[(x$46$re - x$46$im$95$m), $MachinePrecision] * N[(x$46$im$95$m + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
x.im\_s \cdot \left(x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right) - x.re\right)
\end{array}
Derivation
  1. Initial program 82.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. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares84.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 \]
    2. *-commutative84.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. Applied egg-rr84.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 \]
  5. Step-by-step derivation
    1. expm1-log1p-u69.0%

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

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

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)} - 1\right) \cdot x.re \]
    4. flip-+0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(\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}}\right)} - 1\right) \cdot x.re \]
    5. +-inverses0.0%

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

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

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

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

    \[\leadsto x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) - x.re \]
  9. Add Preprocessing

Alternative 7: 61.8% accurate, 1.7× speedup?

\[\begin{array}{l} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ x.im\_s \cdot \left(\left(x.im\_m + x.re\right) \cdot \left(x.im\_m \cdot \left(x.re - x.im\_m\right)\right) - x.re\right) \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m)
 :precision binary64
 (* x.im_s (- (* (+ x.im_m x.re) (* x.im_m (- x.re x.im_m))) x.re)))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * (((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) - x_46_re);
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    code = x_46im_s * (((x_46im_m + x_46re) * (x_46im_m * (x_46re - x_46im_m))) - x_46re)
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * (((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) - x_46_re);
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	return x_46_im_s * (((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) - x_46_re)
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	return Float64(x_46_im_s * Float64(Float64(Float64(x_46_im_m + x_46_re) * Float64(x_46_im_m * Float64(x_46_re - x_46_im_m))) - x_46_re))
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp = code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = x_46_im_s * (((x_46_im_m + x_46_re) * (x_46_im_m * (x_46_re - x_46_im_m))) - x_46_re);
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := N[(x$46$im$95$s * N[(N[(N[(x$46$im$95$m + x$46$re), $MachinePrecision] * N[(x$46$im$95$m * N[(x$46$re - x$46$im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
x.im\_s \cdot \left(\left(x.im\_m + x.re\right) \cdot \left(x.im\_m \cdot \left(x.re - x.im\_m\right)\right) - x.re\right)
\end{array}
Derivation
  1. Initial program 82.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. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares84.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 \]
    2. *-commutative84.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. Applied egg-rr84.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 \]
  5. Step-by-step derivation
    1. expm1-log1p-u69.0%

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

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

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)} - 1\right) \cdot x.re \]
    4. flip-+0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(\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}}\right)} - 1\right) \cdot x.re \]
    5. +-inverses0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 58.1% accurate, 1.7× speedup?

\[\begin{array}{l} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ x.im\_s \cdot \left(x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right) + -1\right) \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m)
 :precision binary64
 (* x.im_s (+ (* x.im_m (* (- x.re x.im_m) (+ x.im_m x.re))) -1.0)))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * ((x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0);
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    code = x_46im_s * ((x_46im_m * ((x_46re - x_46im_m) * (x_46im_m + x_46re))) + (-1.0d0))
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * ((x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0);
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	return x_46_im_s * ((x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0)
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	return Float64(x_46_im_s * Float64(Float64(x_46_im_m * Float64(Float64(x_46_re - x_46_im_m) * Float64(x_46_im_m + x_46_re))) + -1.0))
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp = code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = x_46_im_s * ((x_46_im_m * ((x_46_re - x_46_im_m) * (x_46_im_m + x_46_re))) + -1.0);
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := N[(x$46$im$95$s * N[(N[(x$46$im$95$m * N[(N[(x$46$re - x$46$im$95$m), $MachinePrecision] * N[(x$46$im$95$m + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
x.im\_s \cdot \left(x.im\_m \cdot \left(\left(x.re - x.im\_m\right) \cdot \left(x.im\_m + x.re\right)\right) + -1\right)
\end{array}
Derivation
  1. Initial program 82.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. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares84.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 \]
    2. *-commutative84.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. Applied egg-rr84.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 \]
  5. Step-by-step derivation
    1. *-commutative84.9%

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

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

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

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

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

    \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)} \cdot x.re \]
  7. Step-by-step derivation
    1. add-log-exp52.5%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\log \left(e^{\left(x.re \cdot x.im\right) \cdot 2}\right)} \cdot x.re \]
    2. exp-lft-sqr52.5%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im} \cdot e^{x.re \cdot x.im}\right)} \cdot x.re \]
    3. exp-sum52.5%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \log \color{blue}{\left(e^{x.re \cdot x.im + x.re \cdot x.im}\right)} \cdot x.re \]
    4. add-log-exp84.9%

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

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

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)\right)} \]
    7. expm1-undefine58.1%

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

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

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

    \[\leadsto x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + -1 \]
  11. Add Preprocessing

Alternative 9: 3.5% accurate, 9.5× speedup?

\[\begin{array}{l} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ x.im\_s \cdot \left(-x.re\right) \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m) :precision binary64 (* x.im_s (- x.re)))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * -x_46_re;
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    code = x_46im_s * -x_46re
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * -x_46_re;
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	return x_46_im_s * -x_46_re
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	return Float64(x_46_im_s * Float64(-x_46_re))
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp = code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = x_46_im_s * -x_46_re;
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := N[(x$46$im$95$s * (-x$46$re)), $MachinePrecision]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
x.im\_s \cdot \left(-x.re\right)
\end{array}
Derivation
  1. Initial program 82.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. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares84.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 \]
    2. *-commutative84.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. Applied egg-rr84.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 \]
  5. Step-by-step derivation
    1. expm1-log1p-u69.0%

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

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

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)} - 1\right) \cdot x.re \]
    4. flip-+0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(\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}}\right)} - 1\right) \cdot x.re \]
    5. +-inverses0.0%

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

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

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

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

    \[\leadsto \color{blue}{-1 \cdot x.re} \]
  9. Step-by-step derivation
    1. neg-mul-13.4%

      \[\leadsto \color{blue}{-x.re} \]
  10. Simplified3.4%

    \[\leadsto \color{blue}{-x.re} \]
  11. Add Preprocessing

Alternative 10: 2.7% accurate, 19.0× speedup?

\[\begin{array}{l} x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ x.im\_s \cdot -3 \end{array} \]
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re x.im_m) :precision binary64 (* x.im_s -3.0))
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * -3.0;
}
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im_m
    code = x_46im_s * (-3.0d0)
end function
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re, double x_46_im_m) {
	return x_46_im_s * -3.0;
}
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re, x_46_im_m):
	return x_46_im_s * -3.0
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re, x_46_im_m)
	return Float64(x_46_im_s * -3.0)
end
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp = code(x_46_im_s, x_46_re, x_46_im_m)
	tmp = x_46_im_s * -3.0;
end
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re_, x$46$im$95$m_] := N[(x$46$im$95$s * -3.0), $MachinePrecision]
\begin{array}{l}
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
x.im\_s \cdot -3
\end{array}
Derivation
  1. Initial program 82.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. Simplified86.2%

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

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

    \[\leadsto \color{blue}{-3} \]
  6. Add Preprocessing

Developer target: 91.4% 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 2024096 
(FPCore (x.re x.im)
  :name "math.cube on complex, imaginary part"
  :precision binary64

  :alt
  (+ (* (* 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)))