
(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 3 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}
NOTE: re and im should be sorted in increasing order before calling this function. (FPCore im_sqr (re im) :precision binary64 (* (* re 2.0) im))
assert(re < im);
double im_sqr(double re, double im) {
return (re * 2.0) * im;
}
NOTE: re and im should be sorted in increasing order before calling this function.
real(8) function im_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
im_sqr = (re * 2.0d0) * im
end function
assert re < im;
public static double im_sqr(double re, double im) {
return (re * 2.0) * im;
}
[re, im] = sort([re, im]) def im_sqr(re, im): return (re * 2.0) * im
re, im = sort([re, im]) function im_sqr(re, im) return Float64(Float64(re * 2.0) * im) end
re, im = num2cell(sort([re, im])){:}
function tmp = im_sqr(re, im)
tmp = (re * 2.0) * im;
end
NOTE: re and im should be sorted in increasing order before calling this function. im$95$sqr[re_, im_] := N[(N[(re * 2.0), $MachinePrecision] * im), $MachinePrecision]
\begin{array}{l}
[re, im] = \mathsf{sort}([re, im])\\
\\
\left(re \cdot 2\right) \cdot im
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft-in99.6%
count-299.6%
associate-*r*99.6%
Applied egg-rr99.6%
Final simplification99.6%
NOTE: re and im should be sorted in increasing order before calling this function. (FPCore im_sqr (re im) :precision binary64 (* re (+ im im)))
assert(re < im);
double im_sqr(double re, double im) {
return re * (im + im);
}
NOTE: re and im should be sorted in increasing order before calling this function.
real(8) function im_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
im_sqr = re * (im + im)
end function
assert re < im;
public static double im_sqr(double re, double im) {
return re * (im + im);
}
[re, im] = sort([re, im]) def im_sqr(re, im): return re * (im + im)
re, im = sort([re, im]) function im_sqr(re, im) return Float64(re * Float64(im + im)) end
re, im = num2cell(sort([re, im])){:}
function tmp = im_sqr(re, im)
tmp = re * (im + im);
end
NOTE: re and im should be sorted in increasing order before calling this function. im$95$sqr[re_, im_] := N[(re * N[(im + im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[re, im] = \mathsf{sort}([re, im])\\
\\
re \cdot \left(im + im\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-rgt-out99.6%
Simplified99.6%
Final simplification99.6%
NOTE: re and im should be sorted in increasing order before calling this function. (FPCore im_sqr (re im) :precision binary64 -2.0)
assert(re < im);
double im_sqr(double re, double im) {
return -2.0;
}
NOTE: re and im should be sorted in increasing order before calling this function.
real(8) function im_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
im_sqr = -2.0d0
end function
assert re < im;
public static double im_sqr(double re, double im) {
return -2.0;
}
[re, im] = sort([re, im]) def im_sqr(re, im): return -2.0
re, im = sort([re, im]) function im_sqr(re, im) return -2.0 end
re, im = num2cell(sort([re, im])){:}
function tmp = im_sqr(re, im)
tmp = -2.0;
end
NOTE: re and im should be sorted in increasing order before calling this function. im$95$sqr[re_, im_] := -2.0
\begin{array}{l}
[re, im] = \mathsf{sort}([re, im])\\
\\
-2
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-rgt-out99.6%
Simplified99.6%
expm1-log1p-u70.8%
expm1-udef35.0%
log1p-udef35.0%
add-exp-log63.8%
distribute-rgt-in64.2%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified3.7%
Final simplification3.7%
herbie shell --seed 2023196
(FPCore im_sqr (re im)
:name "math.square on complex, imaginary part"
:precision binary64
(+ (* re im) (* im re)))