
(FPCore (x.re x.im y.re y.im) :precision binary64 (- (* x.re y.re) (* x.im y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_re) - (x_46_im * y_46_im);
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = (x_46re * y_46re) - (x_46im * y_46im)
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_re) - (x_46_im * y_46_im);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return (x_46_re * y_46_re) - (x_46_im * y_46_im)
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(x_46_re * y_46_re) - Float64(x_46_im * y_46_im)) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = (x_46_re * y_46_re) - (x_46_im * y_46_im); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(x$46$re * y$46$re), $MachinePrecision] - N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x.re \cdot y.re - x.im \cdot y.im
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x.re x.im y.re y.im) :precision binary64 (- (* x.re y.re) (* x.im y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_re) - (x_46_im * y_46_im);
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = (x_46re * y_46re) - (x_46im * y_46im)
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_re) - (x_46_im * y_46_im);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return (x_46_re * y_46_re) - (x_46_im * y_46_im)
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(x_46_re * y_46_re) - Float64(x_46_im * y_46_im)) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = (x_46_re * y_46_re) - (x_46_im * y_46_im); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(x$46$re * y$46$re), $MachinePrecision] - N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x.re \cdot y.re - x.im \cdot y.im
\end{array}
(FPCore (x.re x.im y.re y.im) :precision binary64 (fma y.re x.re (* (- x.im) y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return fma(y_46_re, x_46_re, (-x_46_im * y_46_im));
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) return fma(y_46_re, x_46_re, Float64(Float64(-x_46_im) * y_46_im)) end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(y$46$re * x$46$re + N[((-x$46$im) * y$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y.re, x.re, \left(-x.im\right) \cdot y.im\right)
\end{array}
Initial program 98.0%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (* (- x.im) y.im)))
(if (<= (* x.im y.im) -50.0)
t_0
(if (<= (* x.im y.im) 1e-52) (fma y.re x.re (* x.im y.im)) t_0))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = -x_46_im * y_46_im;
double tmp;
if ((x_46_im * y_46_im) <= -50.0) {
tmp = t_0;
} else if ((x_46_im * y_46_im) <= 1e-52) {
tmp = fma(y_46_re, x_46_re, (x_46_im * y_46_im));
} else {
tmp = t_0;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(Float64(-x_46_im) * y_46_im) tmp = 0.0 if (Float64(x_46_im * y_46_im) <= -50.0) tmp = t_0; elseif (Float64(x_46_im * y_46_im) <= 1e-52) tmp = fma(y_46_re, x_46_re, Float64(x_46_im * y_46_im)); else tmp = t_0; end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[((-x$46$im) * y$46$im), $MachinePrecision]}, If[LessEqual[N[(x$46$im * y$46$im), $MachinePrecision], -50.0], t$95$0, If[LessEqual[N[(x$46$im * y$46$im), $MachinePrecision], 1e-52], N[(y$46$re * x$46$re + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-x.im\right) \cdot y.im\\
\mathbf{if}\;x.im \cdot y.im \leq -50:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x.im \cdot y.im \leq 10^{-52}:\\
\;\;\;\;\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x.im y.im) < -50 or 1e-52 < (*.f64 x.im y.im) Initial program 96.4%
Taylor expanded in x.re around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6476.1
Applied rewrites76.1%
if -50 < (*.f64 x.im y.im) < 1e-52Initial program 100.0%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
lift-neg.f64N/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
lift-neg.f64N/A
lift-neg.f64N/A
pow-prod-downN/A
sqr-powN/A
lift-neg.f64N/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
distribute-neg-fracN/A
flip3--N/A
neg-sub0N/A
remove-double-neg80.2
Applied rewrites80.2%
Final simplification78.0%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (* (- x.im) y.im)))
(if (<= (* x.im y.im) -50.0)
t_0
(if (<= (* x.im y.im) 1e-52) (fma y.im x.im (* x.re y.re)) t_0))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = -x_46_im * y_46_im;
double tmp;
if ((x_46_im * y_46_im) <= -50.0) {
tmp = t_0;
} else if ((x_46_im * y_46_im) <= 1e-52) {
tmp = fma(y_46_im, x_46_im, (x_46_re * y_46_re));
} else {
tmp = t_0;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(Float64(-x_46_im) * y_46_im) tmp = 0.0 if (Float64(x_46_im * y_46_im) <= -50.0) tmp = t_0; elseif (Float64(x_46_im * y_46_im) <= 1e-52) tmp = fma(y_46_im, x_46_im, Float64(x_46_re * y_46_re)); else tmp = t_0; end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[((-x$46$im) * y$46$im), $MachinePrecision]}, If[LessEqual[N[(x$46$im * y$46$im), $MachinePrecision], -50.0], t$95$0, If[LessEqual[N[(x$46$im * y$46$im), $MachinePrecision], 1e-52], N[(y$46$im * x$46$im + N[(x$46$re * y$46$re), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-x.im\right) \cdot y.im\\
\mathbf{if}\;x.im \cdot y.im \leq -50:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x.im \cdot y.im \leq 10^{-52}:\\
\;\;\;\;\mathsf{fma}\left(y.im, x.im, x.re \cdot y.re\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x.im y.im) < -50 or 1e-52 < (*.f64 x.im y.im) Initial program 96.4%
Taylor expanded in x.re around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6476.1
Applied rewrites76.1%
if -50 < (*.f64 x.im y.im) < 1e-52Initial program 100.0%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-fma.f64100.0
Applied rewrites80.2%
Final simplification78.0%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (<= (* x.im y.im) 1e+292) (- (* x.re y.re) (* x.im y.im)) (* (- x.im) y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((x_46_im * y_46_im) <= 1e+292) {
tmp = (x_46_re * y_46_re) - (x_46_im * y_46_im);
} else {
tmp = -x_46_im * y_46_im;
}
return tmp;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
real(8) :: tmp
if ((x_46im * y_46im) <= 1d+292) then
tmp = (x_46re * y_46re) - (x_46im * y_46im)
else
tmp = -x_46im * y_46im
end if
code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((x_46_im * y_46_im) <= 1e+292) {
tmp = (x_46_re * y_46_re) - (x_46_im * y_46_im);
} else {
tmp = -x_46_im * y_46_im;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): tmp = 0 if (x_46_im * y_46_im) <= 1e+292: tmp = (x_46_re * y_46_re) - (x_46_im * y_46_im) else: tmp = -x_46_im * y_46_im return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if (Float64(x_46_im * y_46_im) <= 1e+292) tmp = Float64(Float64(x_46_re * y_46_re) - Float64(x_46_im * y_46_im)); else tmp = Float64(Float64(-x_46_im) * y_46_im); end return tmp end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0; if ((x_46_im * y_46_im) <= 1e+292) tmp = (x_46_re * y_46_re) - (x_46_im * y_46_im); else tmp = -x_46_im * y_46_im; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[N[(x$46$im * y$46$im), $MachinePrecision], 1e+292], N[(N[(x$46$re * y$46$re), $MachinePrecision] - N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision], N[((-x$46$im) * y$46$im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x.im \cdot y.im \leq 10^{+292}:\\
\;\;\;\;x.re \cdot y.re - x.im \cdot y.im\\
\mathbf{else}:\\
\;\;\;\;\left(-x.im\right) \cdot y.im\\
\end{array}
\end{array}
if (*.f64 x.im y.im) < 1e292Initial program 100.0%
if 1e292 < (*.f64 x.im y.im) Initial program 82.1%
Taylor expanded in x.re around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6496.4
Applied rewrites96.4%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* (- x.im) y.im))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return -x_46_im * y_46_im;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = -x_46im * y_46im
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return -x_46_im * y_46_im;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return -x_46_im * y_46_im
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(-x_46_im) * y_46_im) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = -x_46_im * y_46_im; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[((-x$46$im) * y$46$im), $MachinePrecision]
\begin{array}{l}
\\
\left(-x.im\right) \cdot y.im
\end{array}
Initial program 98.0%
Taylor expanded in x.re around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6453.3
Applied rewrites53.3%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* x.im y.im))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return x_46_im * y_46_im;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = x_46im * y_46im
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return x_46_im * y_46_im;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return x_46_im * y_46_im
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(x_46_im * y_46_im) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = x_46_im * y_46_im; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$im * y$46$im), $MachinePrecision]
\begin{array}{l}
\\
x.im \cdot y.im
\end{array}
Initial program 98.0%
Taylor expanded in x.re around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6453.3
Applied rewrites53.3%
Applied rewrites3.8%
Final simplification3.8%
herbie shell --seed 2024288
(FPCore (x.re x.im y.re y.im)
:name "_multiplyComplex, real part"
:precision binary64
(- (* x.re y.re) (* x.im y.im)))