math.cube on complex, real part

Percentage Accurate: 83.0% → 58.6%
Time: 6.5s
Alternatives: 7
Speedup: N/A×

Specification

?
\[\begin{array}{l} \\ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (-
  (* (- (* x.re x.re) (* x.im x.im)) x.re)
  (* (+ (* x.re x.im) (* x.im x.re)) x.im)))
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_re) - (((x_46_re * x_46_im) + (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_46re) - (x_46im * x_46im)) * x_46re) - (((x_46re * x_46im) + (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_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
}
def code(x_46_re, x_46_im):
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im)
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_re) - Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_im))
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_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
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$re), $MachinePrecision] - N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

\[\begin{array}{l} \\ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (-
  (* (- (* x.re x.re) (* x.im x.im)) x.re)
  (* (+ (* x.re x.im) (* x.im x.re)) x.im)))
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_re) - (((x_46_re * x_46_im) + (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_46re) - (x_46im * x_46im)) * x_46re) - (((x_46re * x_46im) + (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_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
}
def code(x_46_re, x_46_im):
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im)
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_re) - Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_im))
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_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
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$re), $MachinePrecision] - N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 58.6% accurate, 0.2× speedup?

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

\\
{x.re}^{3}
\end{array}
Derivation
  1. Initial program 80.3%

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
  2. Simplified77.6%

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

    \[\leadsto \color{blue}{{x.re}^{3}} \]
  5. Final simplification57.7%

    \[\leadsto {x.re}^{3} \]
  6. Add Preprocessing

Alternative 2: 51.1% accurate, 2.1× speedup?

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

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

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares83.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{x.re \cdot \left(\left(x.im + x.re\right) \cdot \left(x.re + -27\right)\right)} \]
  9. Final simplification52.4%

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

Alternative 3: 35.7% accurate, 2.7× speedup?

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

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

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares83.4%

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

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

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

    \[\leadsto \color{blue}{x.re \cdot \left(-27 \cdot x.im - 2 \cdot {x.im}^{2}\right)} \]
  7. Step-by-step derivation
    1. cancel-sign-sub-inv33.0%

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

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

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

      \[\leadsto x.re \cdot \left(x.im \cdot -27 + \color{blue}{{x.im}^{2} \cdot -2}\right) \]
    5. unpow233.0%

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

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

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

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

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

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

    \[\leadsto x.im \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot -2\right)\right)} \]
  12. Final simplification35.1%

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

Alternative 4: 28.1% accurate, 2.7× speedup?

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

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

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares83.4%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{x.im \cdot \left(x.re \cdot \left(x.re - 27\right)\right)} \]
  10. Final simplification28.2%

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

Alternative 5: 19.7% accurate, 3.8× speedup?

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

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

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares83.4%

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

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

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

    \[\leadsto \color{blue}{x.re \cdot \left(-27 \cdot x.im - 2 \cdot {x.im}^{2}\right)} \]
  7. Step-by-step derivation
    1. cancel-sign-sub-inv33.0%

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

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

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

      \[\leadsto x.re \cdot \left(x.im \cdot -27 + \color{blue}{{x.im}^{2} \cdot -2}\right) \]
    5. unpow233.0%

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

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

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

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

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

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

Alternative 6: 19.7% accurate, 3.8× speedup?

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

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

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares83.4%

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

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

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

    \[\leadsto \color{blue}{x.re \cdot \left(-27 \cdot x.im - 2 \cdot {x.im}^{2}\right)} \]
  7. Step-by-step derivation
    1. cancel-sign-sub-inv33.0%

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

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

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

      \[\leadsto x.re \cdot \left(x.im \cdot -27 + \color{blue}{{x.im}^{2} \cdot -2}\right) \]
    5. unpow233.0%

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

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

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

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

    \[\leadsto x.re \cdot \color{blue}{\left(-27 \cdot x.im\right)} \]
  10. Simplified22.4%

    \[\leadsto x.re \cdot \color{blue}{\left(x.im \cdot -27\right)} \]
  11. Final simplification22.4%

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

Alternative 7: 3.1% accurate, 9.5× speedup?

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

\\
-x.re
\end{array}
Derivation
  1. Initial program 80.3%

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
  2. Simplified77.6%

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

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

    \[\leadsto \color{blue}{-x.re} \]
  6. Final simplification3.2%

    \[\leadsto -x.re \]
  7. Add Preprocessing

Developer target: 87.9% accurate, 1.1× speedup?

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

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

Reproduce

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

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

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