
(FPCore im_sqr (re im) :precision binary64 (+ (* re im) (* im re)))
double im_sqr(double re, double im) {
return (re * im) + (im * re);
}
real(8) function im_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
im_sqr = (re * im) + (im * re)
end function
public static double im_sqr(double re, double im) {
return (re * im) + (im * re);
}
def im_sqr(re, im): return (re * im) + (im * re)
function im_sqr(re, im) return Float64(Float64(re * im) + Float64(im * re)) end
function tmp = im_sqr(re, im) tmp = (re * im) + (im * re); end
im$95$sqr[re_, im_] := N[(N[(re * im), $MachinePrecision] + N[(im * re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot im + im \cdot re
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 1 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore im_sqr (re im) :precision binary64 (+ (* re im) (* im re)))
double im_sqr(double re, double im) {
return (re * im) + (im * re);
}
real(8) function im_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
im_sqr = (re * im) + (im * re)
end function
public static double im_sqr(double re, double im) {
return (re * im) + (im * re);
}
def im_sqr(re, im): return (re * im) + (im * re)
function im_sqr(re, im) return Float64(Float64(re * im) + Float64(im * re)) end
function tmp = im_sqr(re, im) tmp = (re * im) + (im * re); end
im$95$sqr[re_, im_] := N[(N[(re * im), $MachinePrecision] + N[(im * re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot im + im \cdot re
\end{array}
re\_m = (fabs.f64 re) re\_s = (copysign.f64 #s(literal 1 binary64) re) NOTE: re_m and im should be sorted in increasing order before calling this function. (FPCore im_sqr (re_s re_m im) :precision binary64 (* re_s (* im (* re_m 2.0))))
re\_m = fabs(re);
re\_s = copysign(1.0, re);
assert(re_m < im);
double im_sqr(double re_s, double re_m, double im) {
return re_s * (im * (re_m * 2.0));
}
re\_m = abs(re)
re\_s = copysign(1.0d0, re)
NOTE: re_m and im should be sorted in increasing order before calling this function.
real(8) function im_sqr(re_s, re_m, im)
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im
im_sqr = re_s * (im * (re_m * 2.0d0))
end function
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
assert re_m < im;
public static double im_sqr(double re_s, double re_m, double im) {
return re_s * (im * (re_m * 2.0));
}
re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) [re_m, im] = sort([re_m, im]) def im_sqr(re_s, re_m, im): return re_s * (im * (re_m * 2.0))
re\_m = abs(re) re\_s = copysign(1.0, re) re_m, im = sort([re_m, im]) function im_sqr(re_s, re_m, im) return Float64(re_s * Float64(im * Float64(re_m * 2.0))) end
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
re_m, im = num2cell(sort([re_m, im])){:}
function tmp = im_sqr(re_s, re_m, im)
tmp = re_s * (im * (re_m * 2.0));
end
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: re_m and im should be sorted in increasing order before calling this function.
im$95$sqr[re$95$s_, re$95$m_, im_] := N[(re$95$s * N[(im * N[(re$95$m * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
[re_m, im] = \mathsf{sort}([re_m, im])\\
\\
re\_s \cdot \left(im \cdot \left(re\_m \cdot 2\right)\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
count-2100.0%
*-commutative100.0%
associate-*l*99.6%
Simplified99.6%
herbie shell --seed 2024138
(FPCore im_sqr (re im)
:name "math.square on complex, imaginary part"
:precision binary64
(+ (* re im) (* im re)))