
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
(FPCore (x y z t a b) :precision binary64 (fma z t (fma x y (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(x, y, (a * b)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(x, y, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(x * y + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(x, y, a \cdot b\right)\right)
\end{array}
Initial program 98.0%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6498.8
Applied rewrites98.8%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* z t) -2e-107)
(* z t)
(if (<= (* z t) -5e-324)
(* a b)
(if (<= (* z t) 5e-39)
(* x y)
(if (<= (* z t) 50000000.0) (* a b) (* z t))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -2e-107) {
tmp = z * t;
} else if ((z * t) <= -5e-324) {
tmp = a * b;
} else if ((z * t) <= 5e-39) {
tmp = x * y;
} else if ((z * t) <= 50000000.0) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((z * t) <= (-2d-107)) then
tmp = z * t
else if ((z * t) <= (-5d-324)) then
tmp = a * b
else if ((z * t) <= 5d-39) then
tmp = x * y
else if ((z * t) <= 50000000.0d0) then
tmp = a * b
else
tmp = z * t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -2e-107) {
tmp = z * t;
} else if ((z * t) <= -5e-324) {
tmp = a * b;
} else if ((z * t) <= 5e-39) {
tmp = x * y;
} else if ((z * t) <= 50000000.0) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -2e-107: tmp = z * t elif (z * t) <= -5e-324: tmp = a * b elif (z * t) <= 5e-39: tmp = x * y elif (z * t) <= 50000000.0: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -2e-107) tmp = Float64(z * t); elseif (Float64(z * t) <= -5e-324) tmp = Float64(a * b); elseif (Float64(z * t) <= 5e-39) tmp = Float64(x * y); elseif (Float64(z * t) <= 50000000.0) tmp = Float64(a * b); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((z * t) <= -2e-107) tmp = z * t; elseif ((z * t) <= -5e-324) tmp = a * b; elseif ((z * t) <= 5e-39) tmp = x * y; elseif ((z * t) <= 50000000.0) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -2e-107], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], -5e-324], N[(a * b), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e-39], N[(x * y), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 50000000.0], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{-107}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq -5 \cdot 10^{-324}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{-39}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \cdot t \leq 50000000:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -2e-107 or 5e7 < (*.f64 z t) Initial program 96.4%
Taylor expanded in z around inf
lower-*.f6455.1
Applied rewrites55.1%
if -2e-107 < (*.f64 z t) < -4.94066e-324 or 4.9999999999999998e-39 < (*.f64 z t) < 5e7Initial program 99.0%
Taylor expanded in a around inf
lower-*.f6446.7
Applied rewrites46.7%
if -4.94066e-324 < (*.f64 z t) < 4.9999999999999998e-39Initial program 99.3%
Taylor expanded in x around inf
lower-*.f6449.2
Applied rewrites49.2%
Final simplification52.2%
herbie shell --seed 2024223
(FPCore (x y z t a b)
:name "Linear.V3:$cdot from linear-1.19.1.3, B"
:precision binary64
(+ (+ (* x y) (* z t)) (* a b)))