
(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 5 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 (* x.re y.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, (x_46_re * y_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(x_46_re * y_46_re)) end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[((-y$46$im) * x$46$im + N[(x$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-y.im, x.im, x.re \cdot y.re\right)
\end{array}
Initial program 99.2%
lift-*.f64N/A
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
Applied rewrites99.6%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (- (* y.im x.im))))
(if (<= (* y.im x.im) -2e+30)
t_0
(if (<= (* y.im x.im) 2e-14) (* 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 = -(y_46_im * x_46_im);
double tmp;
if ((y_46_im * x_46_im) <= -2e+30) {
tmp = t_0;
} else if ((y_46_im * x_46_im) <= 2e-14) {
tmp = x_46_re * y_46_re;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = -(y_46im * x_46im)
if ((y_46im * x_46im) <= (-2d+30)) then
tmp = t_0
else if ((y_46im * x_46im) <= 2d-14) then
tmp = x_46re * y_46re
else
tmp = t_0
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 t_0 = -(y_46_im * x_46_im);
double tmp;
if ((y_46_im * x_46_im) <= -2e+30) {
tmp = t_0;
} else if ((y_46_im * x_46_im) <= 2e-14) {
tmp = x_46_re * y_46_re;
} else {
tmp = t_0;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): t_0 = -(y_46_im * x_46_im) tmp = 0 if (y_46_im * x_46_im) <= -2e+30: tmp = t_0 elif (y_46_im * x_46_im) <= 2e-14: tmp = 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(y_46_im * x_46_im)) tmp = 0.0 if (Float64(y_46_im * x_46_im) <= -2e+30) tmp = t_0; elseif (Float64(y_46_im * x_46_im) <= 2e-14) tmp = Float64(x_46_re * y_46_re); else tmp = t_0; end return tmp end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = -(y_46_im * x_46_im); tmp = 0.0; if ((y_46_im * x_46_im) <= -2e+30) tmp = t_0; elseif ((y_46_im * x_46_im) <= 2e-14) tmp = x_46_re * y_46_re; else tmp = t_0; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = (-N[(y$46$im * x$46$im), $MachinePrecision])}, If[LessEqual[N[(y$46$im * x$46$im), $MachinePrecision], -2e+30], t$95$0, If[LessEqual[N[(y$46$im * x$46$im), $MachinePrecision], 2e-14], N[(x$46$re * y$46$re), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y.im \cdot x.im\\
\mathbf{if}\;y.im \cdot x.im \leq -2 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \cdot x.im \leq 2 \cdot 10^{-14}:\\
\;\;\;\;x.re \cdot y.re\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x.im y.im) < -2e30 or 2e-14 < (*.f64 x.im y.im) Initial program 98.4%
Taylor expanded in x.re around 0
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6479.3
Applied rewrites79.3%
if -2e30 < (*.f64 x.im y.im) < 2e-14Initial program 100.0%
Taylor expanded in x.re around inf
lower-*.f6480.9
Applied rewrites80.9%
Final simplification80.1%
(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, -y.im \cdot x.im\right)
\end{array}
Initial program 99.2%
lift-*.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (- (* x.re y.re) (* y.im x.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) - (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 = (x_46re * y_46re) - (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 (x_46_re * y_46_re) - (y_46_im * x_46_im);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return (x_46_re * y_46_re) - (y_46_im * x_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(y_46_im * x_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) - (y_46_im * x_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[(y$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x.re \cdot y.re - y.im \cdot x.im
\end{array}
Initial program 99.2%
Final simplification99.2%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* x.re y.re))
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;
}
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
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;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return x_46_re * y_46_re
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(x_46_re * y_46_re) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = x_46_re * y_46_re; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$re * y$46$re), $MachinePrecision]
\begin{array}{l}
\\
x.re \cdot y.re
\end{array}
Initial program 99.2%
Taylor expanded in x.re around inf
lower-*.f6452.4
Applied rewrites52.4%
herbie shell --seed 2024220
(FPCore (x.re x.im y.re y.im)
:name "_multiplyComplex, real part"
:precision binary64
(- (* x.re y.re) (* x.im y.im)))