
(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 96.9%
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.4
Applied rewrites98.4%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* x y) -2.45e-17)
(* x y)
(if (<= (* x y) 2.1e-92)
(* z t)
(if (<= (* x y) 1.05e+160) (* a b) (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2.45e-17) {
tmp = x * y;
} else if ((x * y) <= 2.1e-92) {
tmp = z * t;
} else if ((x * y) <= 1.05e+160) {
tmp = a * b;
} else {
tmp = x * y;
}
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 ((x * y) <= (-2.45d-17)) then
tmp = x * y
else if ((x * y) <= 2.1d-92) then
tmp = z * t
else if ((x * y) <= 1.05d+160) then
tmp = a * b
else
tmp = x * y
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 ((x * y) <= -2.45e-17) {
tmp = x * y;
} else if ((x * y) <= 2.1e-92) {
tmp = z * t;
} else if ((x * y) <= 1.05e+160) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -2.45e-17: tmp = x * y elif (x * y) <= 2.1e-92: tmp = z * t elif (x * y) <= 1.05e+160: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2.45e-17) tmp = Float64(x * y); elseif (Float64(x * y) <= 2.1e-92) tmp = Float64(z * t); elseif (Float64(x * y) <= 1.05e+160) tmp = Float64(a * b); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((x * y) <= -2.45e-17) tmp = x * y; elseif ((x * y) <= 2.1e-92) tmp = z * t; elseif ((x * y) <= 1.05e+160) tmp = a * b; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2.45e-17], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2.1e-92], N[(z * t), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1.05e+160], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2.45 \cdot 10^{-17}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 2.1 \cdot 10^{-92}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;x \cdot y \leq 1.05 \cdot 10^{+160}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -2.45000000000000006e-17 or 1.04999999999999998e160 < (*.f64 x y) Initial program 93.1%
Taylor expanded in x around inf
lower-*.f6476.5
Applied rewrites76.5%
if -2.45000000000000006e-17 < (*.f64 x y) < 2.1e-92Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6453.4
Applied rewrites53.4%
if 2.1e-92 < (*.f64 x y) < 1.04999999999999998e160Initial program 97.9%
Taylor expanded in a around inf
lower-*.f6449.4
Applied rewrites49.4%
Final simplification61.8%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -1.22e-17) (fma t z (* x y)) (if (<= (* x y) 5.6e+204) (fma a b (* z t)) (fma a b (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1.22e-17) {
tmp = fma(t, z, (x * y));
} else if ((x * y) <= 5.6e+204) {
tmp = fma(a, b, (z * t));
} else {
tmp = fma(a, b, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -1.22e-17) tmp = fma(t, z, Float64(x * y)); elseif (Float64(x * y) <= 5.6e+204) tmp = fma(a, b, Float64(z * t)); else tmp = fma(a, b, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -1.22e-17], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5.6e+204], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1.22 \cdot 10^{-17}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{elif}\;x \cdot y \leq 5.6 \cdot 10^{+204}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.22e-17Initial program 98.5%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6488.3
Applied rewrites88.3%
if -1.22e-17 < (*.f64 x y) < 5.60000000000000049e204Initial program 99.3%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6490.7
Applied rewrites90.7%
if 5.60000000000000049e204 < (*.f64 x y) Initial program 81.3%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6490.6
Applied rewrites90.6%
Final simplification90.0%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma a b (* x y))))
(if (<= (* x y) -2.45e-17)
t_1
(if (<= (* x y) 5.6e+204) (fma a b (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (x * y));
double tmp;
if ((x * y) <= -2.45e-17) {
tmp = t_1;
} else if ((x * y) <= 5.6e+204) {
tmp = fma(a, b, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -2.45e-17) tmp = t_1; elseif (Float64(x * y) <= 5.6e+204) tmp = fma(a, b, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2.45e-17], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 5.6e+204], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -2.45 \cdot 10^{-17}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 5.6 \cdot 10^{+204}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -2.45000000000000006e-17 or 5.60000000000000049e204 < (*.f64 x y) Initial program 92.9%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6487.1
Applied rewrites87.1%
if -2.45000000000000006e-17 < (*.f64 x y) < 5.60000000000000049e204Initial program 99.3%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6490.7
Applied rewrites90.7%
Final simplification89.3%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -8.5e+42) (* x y) (if (<= (* x y) 1.22e+205) (fma a b (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -8.5e+42) {
tmp = x * y;
} else if ((x * y) <= 1.22e+205) {
tmp = fma(a, b, (z * t));
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -8.5e+42) tmp = Float64(x * y); elseif (Float64(x * y) <= 1.22e+205) tmp = fma(a, b, Float64(z * t)); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -8.5e+42], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1.22e+205], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -8.5 \cdot 10^{+42}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 1.22 \cdot 10^{+205}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -8.5000000000000003e42 or 1.21999999999999989e205 < (*.f64 x y) Initial program 92.0%
Taylor expanded in x around inf
lower-*.f6483.0
Applied rewrites83.0%
if -8.5000000000000003e42 < (*.f64 x y) < 1.21999999999999989e205Initial program 99.4%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6488.8
Applied rewrites88.8%
Final simplification86.8%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -5.8e+74) (* a b) (if (<= (* a b) 1.06e+36) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -5.8e+74) {
tmp = a * b;
} else if ((a * b) <= 1.06e+36) {
tmp = z * t;
} else {
tmp = a * b;
}
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 ((a * b) <= (-5.8d+74)) then
tmp = a * b
else if ((a * b) <= 1.06d+36) then
tmp = z * t
else
tmp = a * b
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 ((a * b) <= -5.8e+74) {
tmp = a * b;
} else if ((a * b) <= 1.06e+36) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -5.8e+74: tmp = a * b elif (a * b) <= 1.06e+36: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -5.8e+74) tmp = Float64(a * b); elseif (Float64(a * b) <= 1.06e+36) tmp = Float64(z * t); else tmp = Float64(a * b); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((a * b) <= -5.8e+74) tmp = a * b; elseif ((a * b) <= 1.06e+36) tmp = z * t; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -5.8e+74], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.06e+36], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5.8 \cdot 10^{+74}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 1.06 \cdot 10^{+36}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -5.8000000000000005e74 or 1.06000000000000002e36 < (*.f64 a b) Initial program 92.7%
Taylor expanded in a around inf
lower-*.f6468.4
Applied rewrites68.4%
if -5.8000000000000005e74 < (*.f64 a b) < 1.06000000000000002e36Initial program 99.3%
Taylor expanded in z around inf
lower-*.f6447.4
Applied rewrites47.4%
Final simplification55.3%
(FPCore (x y z t a b) :precision binary64 (* a b))
double code(double x, double y, double z, double t, double a, double b) {
return 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 = a * b
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return a * b;
}
def code(x, y, z, t, a, b): return a * b
function code(x, y, z, t, a, b) return Float64(a * b) end
function tmp = code(x, y, z, t, a, b) tmp = a * b; end
code[x_, y_, z_, t_, a_, b_] := N[(a * b), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b
\end{array}
Initial program 96.9%
Taylor expanded in a around inf
lower-*.f6433.3
Applied rewrites33.3%
herbie shell --seed 2024228
(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)))