
(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:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (x.re x.im) :precision binary64 (* (- 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_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_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_im) * (x_46_im * (x_46_re + x_46_im));
}
def code(x_46_re, x_46_im): return (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(x_46_re - x_46_im) * Float64(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) * (x_46_im * (x_46_re + x_46_im)); end
code[x$46$re_, x$46$im_] := N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$im * N[(x$46$re + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x.re - x.im\right) \cdot \left(x.im \cdot \left(x.re + x.im\right)\right)
\end{array}
Initial program 80.7%
expm1-log1p-u65.9%
expm1-udef56.3%
*-commutative56.3%
*-commutative56.3%
count-256.3%
*-commutative56.3%
associate-*r*56.3%
associate-*r*56.3%
*-commutative56.3%
count-256.3%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified72.2%
difference-of-squares80.1%
*-commutative80.1%
Applied egg-rr80.1%
*-commutative80.1%
distribute-rgt-in70.3%
distribute-lft-in64.4%
Applied egg-rr64.4%
Simplified70.3%
distribute-lft-in64.4%
*-commutative64.4%
associate-*r*64.4%
*-commutative64.4%
associate-*l*64.4%
unpow264.4%
Applied egg-rr64.4%
associate-*r*65.0%
*-commutative65.0%
distribute-rgt-in73.6%
unpow273.6%
distribute-lft-in80.6%
+-commutative80.6%
Simplified80.6%
Final simplification80.6%
(FPCore (x.re x.im) :precision binary64 (* x.im (* (- x.re x.im) (+ x.re x.im))))
double code(double x_46_re, double x_46_im) {
return 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_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_im * ((x_46_re - x_46_im) * (x_46_re + x_46_im));
}
def code(x_46_re, x_46_im): return 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(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_im * ((x_46_re - x_46_im) * (x_46_re + x_46_im)); end
code[x$46$re_, x$46$im_] := N[(x$46$im * N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$re + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)
\end{array}
Initial program 80.7%
expm1-log1p-u65.9%
expm1-udef56.3%
*-commutative56.3%
*-commutative56.3%
count-256.3%
*-commutative56.3%
associate-*r*56.3%
associate-*r*56.3%
*-commutative56.3%
count-256.3%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified72.2%
difference-of-squares80.1%
*-commutative80.1%
Applied egg-rr80.1%
Final simplification80.1%
(FPCore (x.re x.im) :precision binary64 (* x.re (* 3.0 (* x.re x.im))))
double code(double x_46_re, double x_46_im) {
return x_46_re * (3.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 = x_46re * (3.0d0 * (x_46re * x_46im))
end function
public static double code(double x_46_re, double x_46_im) {
return x_46_re * (3.0 * (x_46_re * x_46_im));
}
def code(x_46_re, x_46_im): return x_46_re * (3.0 * (x_46_re * x_46_im))
function code(x_46_re, x_46_im) return Float64(x_46_re * Float64(3.0 * Float64(x_46_re * x_46_im))) end
function tmp = code(x_46_re, x_46_im) tmp = x_46_re * (3.0 * (x_46_re * x_46_im)); end
code[x$46$re_, x$46$im_] := N[(x$46$re * N[(3.0 * N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x.re \cdot \left(3 \cdot \left(x.re \cdot x.im\right)\right)
\end{array}
Initial program 80.7%
Taylor expanded in x.re around inf 51.6%
Simplified51.6%
add-sqr-sqrt24.6%
sqrt-unprod24.6%
sqrt-unprod24.6%
unpow224.6%
swap-sqr27.1%
pow227.1%
sqrt-unprod27.1%
Applied egg-rr27.1%
unpow227.1%
*-commutative27.1%
*-commutative27.1%
swap-sqr24.6%
add-sqr-sqrt51.6%
associate-*r*56.3%
Applied egg-rr56.3%
Taylor expanded in x.im around 0 56.3%
Final simplification56.3%
(FPCore (x.re x.im) :precision binary64 (* x.re (* x.im (* x.re 3.0))))
double code(double x_46_re, double x_46_im) {
return x_46_re * (x_46_im * (x_46_re * 3.0));
}
real(8) function code(x_46re, x_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
code = x_46re * (x_46im * (x_46re * 3.0d0))
end function
public static double code(double x_46_re, double x_46_im) {
return x_46_re * (x_46_im * (x_46_re * 3.0));
}
def code(x_46_re, x_46_im): return x_46_re * (x_46_im * (x_46_re * 3.0))
function code(x_46_re, x_46_im) return Float64(x_46_re * Float64(x_46_im * Float64(x_46_re * 3.0))) end
function tmp = code(x_46_re, x_46_im) tmp = x_46_re * (x_46_im * (x_46_re * 3.0)); end
code[x$46$re_, x$46$im_] := N[(x$46$re * N[(x$46$im * N[(x$46$re * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right)
\end{array}
Initial program 80.7%
Taylor expanded in x.re around inf 51.6%
Simplified51.6%
add-sqr-sqrt24.6%
sqrt-unprod24.6%
sqrt-unprod24.6%
unpow224.6%
swap-sqr27.1%
pow227.1%
sqrt-unprod27.1%
Applied egg-rr27.1%
unpow227.1%
*-commutative27.1%
*-commutative27.1%
swap-sqr24.6%
add-sqr-sqrt51.6%
associate-*r*56.3%
Applied egg-rr56.3%
Taylor expanded in x.im around 0 56.3%
associate-*r*56.3%
*-commutative56.3%
associate-*l*56.3%
Simplified56.3%
Final simplification56.3%
(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}
herbie shell --seed 2024033
(FPCore (x.re x.im)
:name "math.cube on complex, imaginary part"
:precision binary64
:herbie-target
(+ (* (* x.re x.im) (* 2.0 x.re)) (* (* x.im (- x.re x.im)) (+ x.re x.im)))
(+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re)))