
(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 8 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 b a (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(b, a, (x * y)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(b, a, Float64(x * y))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, x \cdot y\right)\right)
\end{array}
Initial program 98.8%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.8
Applied rewrites98.8%
Final simplification98.8%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* t z) -5e+37)
(* t z)
(if (<= (* t z) 2e-230)
(* x y)
(if (<= (* t z) 2e-70) (* a b) (if (<= (* t z) 5e+33) (* x y) (* t z))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t * z) <= -5e+37) {
tmp = t * z;
} else if ((t * z) <= 2e-230) {
tmp = x * y;
} else if ((t * z) <= 2e-70) {
tmp = a * b;
} else if ((t * z) <= 5e+33) {
tmp = x * y;
} else {
tmp = t * z;
}
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 ((t * z) <= (-5d+37)) then
tmp = t * z
else if ((t * z) <= 2d-230) then
tmp = x * y
else if ((t * z) <= 2d-70) then
tmp = a * b
else if ((t * z) <= 5d+33) then
tmp = x * y
else
tmp = t * z
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 ((t * z) <= -5e+37) {
tmp = t * z;
} else if ((t * z) <= 2e-230) {
tmp = x * y;
} else if ((t * z) <= 2e-70) {
tmp = a * b;
} else if ((t * z) <= 5e+33) {
tmp = x * y;
} else {
tmp = t * z;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t * z) <= -5e+37: tmp = t * z elif (t * z) <= 2e-230: tmp = x * y elif (t * z) <= 2e-70: tmp = a * b elif (t * z) <= 5e+33: tmp = x * y else: tmp = t * z return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(t * z) <= -5e+37) tmp = Float64(t * z); elseif (Float64(t * z) <= 2e-230) tmp = Float64(x * y); elseif (Float64(t * z) <= 2e-70) tmp = Float64(a * b); elseif (Float64(t * z) <= 5e+33) tmp = Float64(x * y); else tmp = Float64(t * z); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((t * z) <= -5e+37) tmp = t * z; elseif ((t * z) <= 2e-230) tmp = x * y; elseif ((t * z) <= 2e-70) tmp = a * b; elseif ((t * z) <= 5e+33) tmp = x * y; else tmp = t * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(t * z), $MachinePrecision], -5e+37], N[(t * z), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 2e-230], N[(x * y), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 2e-70], N[(a * b), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 5e+33], N[(x * y), $MachinePrecision], N[(t * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -5 \cdot 10^{+37}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;t \cdot z \leq 2 \cdot 10^{-230}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;t \cdot z \leq 2 \cdot 10^{-70}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;t \cdot z \leq 5 \cdot 10^{+33}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if (*.f64 z t) < -4.99999999999999989e37 or 4.99999999999999973e33 < (*.f64 z t) Initial program 97.4%
Taylor expanded in t around inf
lower-*.f6470.5
Applied rewrites70.5%
if -4.99999999999999989e37 < (*.f64 z t) < 2.00000000000000009e-230 or 1.99999999999999999e-70 < (*.f64 z t) < 4.99999999999999973e33Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6458.5
Applied rewrites58.5%
if 2.00000000000000009e-230 < (*.f64 z t) < 1.99999999999999999e-70Initial program 100.0%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6468.7
Applied rewrites68.7%
Final simplification65.2%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma t z (* x y))))
(if (<= (* x y) -1e-85)
t_1
(if (<= (* x y) 50000.0) (fma z t (* a b)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(t, z, (x * y));
double tmp;
if ((x * y) <= -1e-85) {
tmp = t_1;
} else if ((x * y) <= 50000.0) {
tmp = fma(z, t, (a * b));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(t, z, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -1e-85) tmp = t_1; elseif (Float64(x * y) <= 50000.0) tmp = fma(z, t, Float64(a * b)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1e-85], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 50000.0], N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 50000:\\
\;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -9.9999999999999998e-86 or 5e4 < (*.f64 x y) Initial program 97.9%
Taylor expanded in b around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.2
Applied rewrites87.2%
if -9.9999999999999998e-86 < (*.f64 x y) < 5e4Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in b around inf
lower-*.f6495.4
Applied rewrites95.4%
Final simplification90.8%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma t z (* x y))))
(if (<= (* x y) -1e-85)
t_1
(if (<= (* x y) 50000.0) (fma b a (* t z)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(t, z, (x * y));
double tmp;
if ((x * y) <= -1e-85) {
tmp = t_1;
} else if ((x * y) <= 50000.0) {
tmp = fma(b, a, (t * z));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(t, z, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -1e-85) tmp = t_1; elseif (Float64(x * y) <= 50000.0) tmp = fma(b, a, Float64(t * z)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1e-85], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 50000.0], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 50000:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -9.9999999999999998e-86 or 5e4 < (*.f64 x y) Initial program 97.9%
Taylor expanded in b around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.2
Applied rewrites87.2%
if -9.9999999999999998e-86 < (*.f64 x y) < 5e4Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6495.4
Applied rewrites95.4%
Final simplification90.8%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma b a (* t z)))) (if (<= (* t z) -5e+37) t_1 (if (<= (* t z) 1e+36) (fma b a (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, a, (t * z));
double tmp;
if ((t * z) <= -5e+37) {
tmp = t_1;
} else if ((t * z) <= 1e+36) {
tmp = fma(b, a, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, a, Float64(t * z)) tmp = 0.0 if (Float64(t * z) <= -5e+37) tmp = t_1; elseif (Float64(t * z) <= 1e+36) tmp = fma(b, a, Float64(x * y)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t * z), $MachinePrecision], -5e+37], t$95$1, If[LessEqual[N[(t * z), $MachinePrecision], 1e+36], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{if}\;t \cdot z \leq -5 \cdot 10^{+37}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \cdot z \leq 10^{+36}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -4.99999999999999989e37 or 1.00000000000000004e36 < (*.f64 z t) Initial program 97.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6483.2
Applied rewrites83.2%
if -4.99999999999999989e37 < (*.f64 z t) < 1.00000000000000004e36Initial program 100.0%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.4
Applied rewrites89.4%
Final simplification86.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -4e+62) (* x y) (if (<= (* x y) 5e+112) (fma b a (* t z)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -4e+62) {
tmp = x * y;
} else if ((x * y) <= 5e+112) {
tmp = fma(b, a, (t * z));
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -4e+62) tmp = Float64(x * y); elseif (Float64(x * y) <= 5e+112) tmp = fma(b, a, Float64(t * z)); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -4e+62], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+112], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -4 \cdot 10^{+62}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+112}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -4.00000000000000014e62 or 5e112 < (*.f64 x y) Initial program 98.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6473.2
Applied rewrites73.2%
if -4.00000000000000014e62 < (*.f64 x y) < 5e112Initial program 99.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6487.4
Applied rewrites87.4%
Final simplification81.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* t z) -5e-42) (* t z) (if (<= (* t z) 1e-13) (* a b) (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t * z) <= -5e-42) {
tmp = t * z;
} else if ((t * z) <= 1e-13) {
tmp = a * b;
} else {
tmp = t * z;
}
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 ((t * z) <= (-5d-42)) then
tmp = t * z
else if ((t * z) <= 1d-13) then
tmp = a * b
else
tmp = t * z
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 ((t * z) <= -5e-42) {
tmp = t * z;
} else if ((t * z) <= 1e-13) {
tmp = a * b;
} else {
tmp = t * z;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t * z) <= -5e-42: tmp = t * z elif (t * z) <= 1e-13: tmp = a * b else: tmp = t * z return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(t * z) <= -5e-42) tmp = Float64(t * z); elseif (Float64(t * z) <= 1e-13) tmp = Float64(a * b); else tmp = Float64(t * z); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((t * z) <= -5e-42) tmp = t * z; elseif ((t * z) <= 1e-13) tmp = a * b; else tmp = t * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(t * z), $MachinePrecision], -5e-42], N[(t * z), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 1e-13], N[(a * b), $MachinePrecision], N[(t * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -5 \cdot 10^{-42}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;t \cdot z \leq 10^{-13}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if (*.f64 z t) < -5.00000000000000003e-42 or 1e-13 < (*.f64 z t) Initial program 97.9%
Taylor expanded in t around inf
lower-*.f6462.2
Applied rewrites62.2%
if -5.00000000000000003e-42 < (*.f64 z t) < 1e-13Initial program 100.0%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6448.3
Applied rewrites48.3%
Final simplification56.1%
(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 98.8%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6430.1
Applied rewrites30.1%
Final simplification30.1%
herbie shell --seed 2024276
(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)))