
(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%
*-commutativeN/A
distribute-lft-outN/A
*-lowering-*.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.7%
Applied egg-rr99.7%
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(re * Float64(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[(re * N[(2.0 * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[re, im] = \mathsf{sort}([re, im])\\
\\
re \cdot \left(2 \cdot im\right)
\end{array}
Initial program 100.0%
*-commutativeN/A
distribute-lft-outN/A
*-lowering-*.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
Final simplification100.0%
NOTE: re and im should be sorted in increasing order before calling this function. (FPCore im_sqr (re im) :precision binary64 (/ 0.0 0.0))
assert(re < im);
double im_sqr(double re, double im) {
return 0.0 / 0.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 = 0.0d0 / 0.0d0
end function
assert re < im;
public static double im_sqr(double re, double im) {
return 0.0 / 0.0;
}
[re, im] = sort([re, im]) def im_sqr(re, im): return 0.0 / 0.0
re, im = sort([re, im]) function im_sqr(re, im) return Float64(0.0 / 0.0) end
re, im = num2cell(sort([re, im])){:}
function tmp = im_sqr(re, im)
tmp = 0.0 / 0.0;
end
NOTE: re and im should be sorted in increasing order before calling this function. im$95$sqr[re_, im_] := N[(0.0 / 0.0), $MachinePrecision]
\begin{array}{l}
[re, im] = \mathsf{sort}([re, im])\\
\\
\frac{0}{0}
\end{array}
Initial program 100.0%
*-commutativeN/A
distribute-lft-outN/A
*-lowering-*.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
associate-*r*N/A
*-commutativeN/A
count-2N/A
*-commutativeN/A
flip-+N/A
*-commutativeN/A
+-inversesN/A
+-inversesN/A
*-commutativeN/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
*-commutativeN/A
+-inversesN/A
*-commutativeN/A
*-commutativeN/A
+-inverses0.0%
Applied egg-rr0.0%
herbie shell --seed 2024139
(FPCore im_sqr (re im)
:name "math.square on complex, imaginary part"
:precision binary64
(+ (* re im) (* im re)))