
(FPCore re_sqr (re im) :precision binary64 (- (* re re) (* im im)))
double re_sqr(double re, double im) {
return (re * re) - (im * im);
}
real(8) function re_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
re_sqr = (re * re) - (im * im)
end function
public static double re_sqr(double re, double im) {
return (re * re) - (im * im);
}
def re_sqr(re, im): return (re * re) - (im * im)
function re_sqr(re, im) return Float64(Float64(re * re) - Float64(im * im)) end
function tmp = re_sqr(re, im) tmp = (re * re) - (im * im); end
re$95$sqr[re_, im_] := N[(N[(re * re), $MachinePrecision] - N[(im * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot re - im \cdot im
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore re_sqr (re im) :precision binary64 (- (* re re) (* im im)))
double re_sqr(double re, double im) {
return (re * re) - (im * im);
}
real(8) function re_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
re_sqr = (re * re) - (im * im)
end function
public static double re_sqr(double re, double im) {
return (re * re) - (im * im);
}
def re_sqr(re, im): return (re * re) - (im * im)
function re_sqr(re, im) return Float64(Float64(re * re) - Float64(im * im)) end
function tmp = re_sqr(re, im) tmp = (re * re) - (im * im); end
re$95$sqr[re_, im_] := N[(N[(re * re), $MachinePrecision] - N[(im * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot re - im \cdot im
\end{array}
(FPCore re_sqr (re im) :precision binary64 (* (- re im) (+ re im)))
double re_sqr(double re, double im) {
return (re - im) * (re + im);
}
real(8) function re_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
re_sqr = (re - im) * (re + im)
end function
public static double re_sqr(double re, double im) {
return (re - im) * (re + im);
}
def re_sqr(re, im): return (re - im) * (re + im)
function re_sqr(re, im) return Float64(Float64(re - im) * Float64(re + im)) end
function tmp = re_sqr(re, im) tmp = (re - im) * (re + im); end
re$95$sqr[re_, im_] := N[(N[(re - im), $MachinePrecision] * N[(re + im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(re - im\right) \cdot \left(re + im\right)
\end{array}
Initial program 95.3%
difference-of-squares100.0%
add-sqr-sqrt49.5%
sqrt-prod79.0%
sqr-neg79.0%
sqrt-unprod29.8%
add-sqr-sqrt49.6%
sub-neg49.6%
pow149.6%
pow149.6%
pow-prod-up49.6%
add-sqr-sqrt26.4%
add-sqr-sqrt10.2%
difference-of-squares10.2%
metadata-eval10.2%
unpow-prod-down10.2%
Applied egg-rr10.2%
unpow210.2%
unpow210.2%
unswap-sqr10.2%
difference-of-squares10.2%
unpow1/210.2%
unpow1/210.2%
pow-sqr10.2%
metadata-eval10.2%
unpow110.2%
unpow1/210.2%
unpow1/210.2%
pow-sqr10.2%
metadata-eval10.2%
unpow110.2%
difference-of-squares10.2%
unpow1/210.2%
unpow1/210.2%
pow-sqr19.8%
metadata-eval19.8%
unpow119.8%
Simplified49.6%
Applied egg-rr22.5%
times-frac37.0%
associate-*r/30.0%
unpow230.0%
associate-/l*30.0%
*-inverses30.0%
/-rgt-identity30.0%
associate-/l*36.9%
+-commutative36.9%
+-commutative36.9%
Simplified36.9%
clear-num36.8%
associate-/r/36.9%
clear-num37.0%
fma-udef36.9%
+-commutative36.9%
distribute-rgt-in36.9%
unpow236.9%
flip3--100.0%
+-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore re_sqr (re im) :precision binary64 (* re (+ re (* im -2.0))))
double re_sqr(double re, double im) {
return re * (re + (im * -2.0));
}
real(8) function re_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
re_sqr = re * (re + (im * (-2.0d0)))
end function
public static double re_sqr(double re, double im) {
return re * (re + (im * -2.0));
}
def re_sqr(re, im): return re * (re + (im * -2.0))
function re_sqr(re, im) return Float64(re * Float64(re + Float64(im * -2.0))) end
function tmp = re_sqr(re, im) tmp = re * (re + (im * -2.0)); end
re$95$sqr[re_, im_] := N[(re * N[(re + N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot \left(re + im \cdot -2\right)
\end{array}
Initial program 95.3%
difference-of-squares100.0%
add-sqr-sqrt49.5%
sqrt-prod79.0%
sqr-neg79.0%
sqrt-unprod29.8%
add-sqr-sqrt49.6%
sub-neg49.6%
pow149.6%
pow149.6%
pow-prod-up49.6%
add-sqr-sqrt26.4%
add-sqr-sqrt10.2%
difference-of-squares10.2%
metadata-eval10.2%
unpow-prod-down10.2%
Applied egg-rr10.2%
unpow210.2%
unpow210.2%
unswap-sqr10.2%
difference-of-squares10.2%
unpow1/210.2%
unpow1/210.2%
pow-sqr10.2%
metadata-eval10.2%
unpow110.2%
unpow1/210.2%
unpow1/210.2%
pow-sqr10.2%
metadata-eval10.2%
unpow110.2%
difference-of-squares10.2%
unpow1/210.2%
unpow1/210.2%
pow-sqr19.8%
metadata-eval19.8%
unpow119.8%
Simplified49.6%
Taylor expanded in re around inf 49.4%
associate-*r*49.4%
unpow249.4%
distribute-rgt-out53.7%
*-commutative53.7%
Simplified53.7%
Final simplification53.7%
(FPCore re_sqr (re im) :precision binary64 (* -2.0 (* re im)))
double re_sqr(double re, double im) {
return -2.0 * (re * im);
}
real(8) function re_sqr(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
re_sqr = (-2.0d0) * (re * im)
end function
public static double re_sqr(double re, double im) {
return -2.0 * (re * im);
}
def re_sqr(re, im): return -2.0 * (re * im)
function re_sqr(re, im) return Float64(-2.0 * Float64(re * im)) end
function tmp = re_sqr(re, im) tmp = -2.0 * (re * im); end
re$95$sqr[re_, im_] := N[(-2.0 * N[(re * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(re \cdot im\right)
\end{array}
Initial program 95.3%
difference-of-squares100.0%
add-sqr-sqrt49.5%
sqrt-prod79.0%
sqr-neg79.0%
sqrt-unprod29.8%
add-sqr-sqrt49.6%
sub-neg49.6%
pow149.6%
pow149.6%
pow-prod-up49.6%
add-sqr-sqrt26.4%
add-sqr-sqrt10.2%
difference-of-squares10.2%
metadata-eval10.2%
unpow-prod-down10.2%
Applied egg-rr10.2%
unpow210.2%
unpow210.2%
unswap-sqr10.2%
difference-of-squares10.2%
unpow1/210.2%
unpow1/210.2%
pow-sqr10.2%
metadata-eval10.2%
unpow110.2%
unpow1/210.2%
unpow1/210.2%
pow-sqr10.2%
metadata-eval10.2%
unpow110.2%
difference-of-squares10.2%
unpow1/210.2%
unpow1/210.2%
pow-sqr19.8%
metadata-eval19.8%
unpow119.8%
Simplified49.6%
Taylor expanded in re around inf 49.4%
associate-*r*49.4%
unpow249.4%
distribute-rgt-out53.7%
*-commutative53.7%
Simplified53.7%
Taylor expanded in re around 0 13.6%
Final simplification13.6%
herbie shell --seed 2024029
(FPCore re_sqr (re im)
:name "math.square on complex, real part"
:precision binary64
(- (* re re) (* im im)))