
(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.im) x.im (* y.re x.re)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return fma(-y_46_im, x_46_im, (y_46_re * x_46_re));
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) return fma(Float64(-y_46_im), x_46_im, Float64(y_46_re * x_46_re)) end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[((-y$46$im) * x$46$im + N[(y$46$re * x$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-y.im, x.im, y.re \cdot x.re\right)
\end{array}
Initial program 98.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= (* x.im y.im) -5e+93) (not (<= (* x.im y.im) 1e-92))) (* (- x.im) y.im) (fma y.im x.im (* y.re x.re))))
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) <= -5e+93) || !((x_46_im * y_46_im) <= 1e-92)) {
tmp = -x_46_im * y_46_im;
} else {
tmp = fma(y_46_im, x_46_im, (y_46_re * x_46_re));
}
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) <= -5e+93) || !(Float64(x_46_im * y_46_im) <= 1e-92)) tmp = Float64(Float64(-x_46_im) * y_46_im); else tmp = fma(y_46_im, x_46_im, Float64(y_46_re * x_46_re)); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[N[(x$46$im * y$46$im), $MachinePrecision], -5e+93], N[Not[LessEqual[N[(x$46$im * y$46$im), $MachinePrecision], 1e-92]], $MachinePrecision]], N[((-x$46$im) * y$46$im), $MachinePrecision], N[(y$46$im * x$46$im + N[(y$46$re * x$46$re), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x.im \cdot y.im \leq -5 \cdot 10^{+93} \lor \neg \left(x.im \cdot y.im \leq 10^{-92}\right):\\
\;\;\;\;\left(-x.im\right) \cdot y.im\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)\\
\end{array}
\end{array}
if (*.f64 x.im y.im) < -5.0000000000000001e93 or 9.99999999999999988e-93 < (*.f64 x.im y.im) Initial program 97.8%
Taylor expanded in x.re around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6479.6
Applied rewrites79.6%
if -5.0000000000000001e93 < (*.f64 x.im y.im) < 9.99999999999999988e-93Initial 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 rewrites84.5%
Final simplification81.8%
(FPCore (x.re x.im y.re y.im) :precision binary64 (fma y.re x.re (* (- y.im) x.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, (-y_46_im * x_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(-y_46_im) * x_46_im)) end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(y$46$re * x$46$re + N[((-y$46$im) * x$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y.re, x.re, \left(-y.im\right) \cdot x.im\right)
\end{array}
Initial program 98.8%
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.2
Applied rewrites99.2%
(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}
Initial program 98.8%
(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.8%
Taylor expanded in x.re around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6453.4
Applied rewrites53.4%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* y.im x.im))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return y_46_im * x_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 = y_46im * x_46im
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return y_46_im * x_46_im;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return y_46_im * x_46_im
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(y_46_im * x_46_im) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = y_46_im * x_46_im; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(y$46$im * x$46$im), $MachinePrecision]
\begin{array}{l}
\\
y.im \cdot x.im
\end{array}
Initial program 98.8%
Taylor expanded in x.re around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6453.4
Applied rewrites53.4%
Applied rewrites4.6%
herbie shell --seed 2024313
(FPCore (x.re x.im y.re y.im)
:name "_multiplyComplex, real part"
:precision binary64
(- (* x.re y.re) (* x.im y.im)))