
(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:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (x.re x.im) :precision binary64 (fma (* x.re x.im) (* x.im -3.0) (pow x.re 3.0)))
double code(double x_46_re, double x_46_im) {
return fma((x_46_re * x_46_im), (x_46_im * -3.0), pow(x_46_re, 3.0));
}
function code(x_46_re, x_46_im) return fma(Float64(x_46_re * x_46_im), Float64(x_46_im * -3.0), (x_46_re ^ 3.0)) end
code[x$46$re_, x$46$im_] := N[(N[(x$46$re * x$46$im), $MachinePrecision] * N[(x$46$im * -3.0), $MachinePrecision] + N[Power[x$46$re, 3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x.re \cdot x.im, x.im \cdot -3, {x.re}^{3}\right)
\end{array}
Initial program 83.7%
Simplified83.0%
associate-*r*83.0%
associate-*l*83.0%
+-commutative83.0%
associate-*r*87.4%
associate-*r*87.4%
fma-define88.9%
Applied egg-rr88.9%
Final simplification88.9%
(FPCore (x.re x.im) :precision binary64 (+ (pow x.re 3.0) (* (* x.re x.im) (* x.im -3.0))))
double code(double x_46_re, double x_46_im) {
return pow(x_46_re, 3.0) + ((x_46_re * x_46_im) * (x_46_im * -3.0));
}
real(8) function code(x_46re, x_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
code = (x_46re ** 3.0d0) + ((x_46re * x_46im) * (x_46im * (-3.0d0)))
end function
public static double code(double x_46_re, double x_46_im) {
return Math.pow(x_46_re, 3.0) + ((x_46_re * x_46_im) * (x_46_im * -3.0));
}
def code(x_46_re, x_46_im): return math.pow(x_46_re, 3.0) + ((x_46_re * x_46_im) * (x_46_im * -3.0))
function code(x_46_re, x_46_im) return Float64((x_46_re ^ 3.0) + Float64(Float64(x_46_re * x_46_im) * Float64(x_46_im * -3.0))) end
function tmp = code(x_46_re, x_46_im) tmp = (x_46_re ^ 3.0) + ((x_46_re * x_46_im) * (x_46_im * -3.0)); end
code[x$46$re_, x$46$im_] := N[(N[Power[x$46$re, 3.0], $MachinePrecision] + N[(N[(x$46$re * x$46$im), $MachinePrecision] * N[(x$46$im * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{x.re}^{3} + \left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)
\end{array}
Initial program 83.7%
Simplified83.0%
associate-*r*83.0%
associate-*l*83.0%
+-commutative83.0%
associate-*r*87.4%
associate-*r*87.4%
fma-define88.9%
Applied egg-rr88.9%
fma-undefine87.4%
+-commutative87.4%
Applied egg-rr87.4%
Final simplification87.4%
(FPCore (x.re x.im) :precision binary64 (- (* x.re (* (- x.re x.im) (+ x.re x.im))) (* 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_re - x_46_im) * (x_46_re + x_46_im))) - (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_46re - x_46im) * (x_46re + x_46im))) - (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_re - x_46_im) * (x_46_re + x_46_im))) - (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_re - x_46_im) * (x_46_re + x_46_im))) - (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(x_46_re * Float64(Float64(x_46_re - x_46_im) * Float64(x_46_re + x_46_im))) - Float64(x_46_im * Float64(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_re - x_46_im) * (x_46_re + x_46_im))) - (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[(x$46$re * N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$re + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im * N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x.re \cdot \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)
\end{array}
Initial program 83.7%
difference-of-squares80.1%
*-commutative80.1%
Applied egg-rr86.1%
Final simplification86.1%
(FPCore (x.re x.im) :precision binary64 (let* ((t_0 (* x.re (- x.re x.im)))) (+ (* x.re t_0) (* x.im t_0))))
double code(double x_46_re, double x_46_im) {
double t_0 = x_46_re * (x_46_re - x_46_im);
return (x_46_re * t_0) + (x_46_im * t_0);
}
real(8) function code(x_46re, x_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8) :: t_0
t_0 = x_46re * (x_46re - x_46im)
code = (x_46re * t_0) + (x_46im * t_0)
end function
public static double code(double x_46_re, double x_46_im) {
double t_0 = x_46_re * (x_46_re - x_46_im);
return (x_46_re * t_0) + (x_46_im * t_0);
}
def code(x_46_re, x_46_im): t_0 = x_46_re * (x_46_re - x_46_im) return (x_46_re * t_0) + (x_46_im * t_0)
function code(x_46_re, x_46_im) t_0 = Float64(x_46_re * Float64(x_46_re - x_46_im)) return Float64(Float64(x_46_re * t_0) + Float64(x_46_im * t_0)) end
function tmp = code(x_46_re, x_46_im) t_0 = x_46_re * (x_46_re - x_46_im); tmp = (x_46_re * t_0) + (x_46_im * t_0); end
code[x$46$re_, x$46$im_] := Block[{t$95$0 = N[(x$46$re * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision]}, N[(N[(x$46$re * t$95$0), $MachinePrecision] + N[(x$46$im * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x.re \cdot \left(x.re - x.im\right)\\
x.re \cdot t\_0 + x.im \cdot t\_0
\end{array}
\end{array}
Initial program 83.7%
*-commutative83.7%
*-commutative83.7%
flip-+0.0%
+-inverses0.0%
metadata-eval0.0%
+-inverses0.0%
metadata-eval0.0%
associate-*r/0.0%
metadata-eval0.0%
metadata-eval0.0%
Applied egg-rr0.0%
Simplified74.7%
difference-of-squares80.1%
*-commutative80.1%
Applied egg-rr80.1%
*-commutative80.1%
distribute-rgt-in73.9%
distribute-rgt-in70.0%
Applied egg-rr70.0%
Taylor expanded in x.im around 0 61.1%
neg-mul-161.1%
neg-sub061.1%
+-commutative61.1%
neg-sub061.1%
unsub-neg61.1%
unpow261.1%
distribute-rgt-out--66.6%
Simplified66.6%
Final simplification66.6%
(FPCore (x.re x.im) :precision binary64 (* x.re (* (- x.re 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_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_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_re + x_46_im));
}
def code(x_46_re, x_46_im): return x_46_re * ((x_46_re - x_46_im) * (x_46_re + x_46_im))
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 + 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_re + x_46_im)); 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 + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x.re \cdot \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)
\end{array}
Initial program 83.7%
*-commutative83.7%
*-commutative83.7%
flip-+0.0%
+-inverses0.0%
metadata-eval0.0%
+-inverses0.0%
metadata-eval0.0%
associate-*r/0.0%
metadata-eval0.0%
metadata-eval0.0%
Applied egg-rr0.0%
Simplified74.7%
difference-of-squares80.1%
*-commutative80.1%
Applied egg-rr80.1%
Final simplification80.1%
(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}
herbie shell --seed 2024066
(FPCore (x.re x.im)
:name "math.cube on complex, real part"
:precision binary64
:alt
(+ (* (* 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)))