
(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 y x (fma b a (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(y, x, fma(b, a, (z * t)));
}
function code(x, y, z, t, a, b) return fma(y, x, fma(b, a, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(y * x + N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(b, a, z \cdot t\right)\right)
\end{array}
Initial program 98.4%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1e+35) (* a b) (if (<= (* a b) 2e-278) (* x y) (if (<= (* a b) 5e+36) (* z t) (* a b)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1e+35) {
tmp = a * b;
} else if ((a * b) <= 2e-278) {
tmp = x * y;
} else if ((a * b) <= 5e+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) <= (-1d+35)) then
tmp = a * b
else if ((a * b) <= 2d-278) then
tmp = x * y
else if ((a * b) <= 5d+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) <= -1e+35) {
tmp = a * b;
} else if ((a * b) <= 2e-278) {
tmp = x * y;
} else if ((a * b) <= 5e+36) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1e+35: tmp = a * b elif (a * b) <= 2e-278: tmp = x * y elif (a * b) <= 5e+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) <= -1e+35) tmp = Float64(a * b); elseif (Float64(a * b) <= 2e-278) tmp = Float64(x * y); elseif (Float64(a * b) <= 5e+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) <= -1e+35) tmp = a * b; elseif ((a * b) <= 2e-278) tmp = x * y; elseif ((a * b) <= 5e+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], -1e+35], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e-278], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e+36], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+35}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-278}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{+36}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -9.9999999999999997e34 or 4.99999999999999977e36 < (*.f64 a b) Initial program 96.3%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6474.3
Applied rewrites74.3%
if -9.9999999999999997e34 < (*.f64 a b) < 1.99999999999999988e-278Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6455.5
Applied rewrites55.5%
if 1.99999999999999988e-278 < (*.f64 a b) < 4.99999999999999977e36Initial program 100.0%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6460.3
Applied rewrites60.3%
Final simplification64.5%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -2e-21) (fma y x (* a b)) (if (<= (* x y) 2e+50) (fma b a (* z t)) (fma y x (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2e-21) {
tmp = fma(y, x, (a * b));
} else if ((x * y) <= 2e+50) {
tmp = fma(b, a, (z * t));
} else {
tmp = fma(y, x, (z * t));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2e-21) tmp = fma(y, x, Float64(a * b)); elseif (Float64(x * y) <= 2e+50) tmp = fma(b, a, Float64(z * t)); else tmp = fma(y, x, Float64(z * t)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2e-21], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+50], N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(z * t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+50}:\\
\;\;\;\;\mathsf{fma}\left(b, a, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z \cdot t\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999982e-21Initial program 95.5%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.5
Applied rewrites98.5%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6486.8
Applied rewrites86.8%
if -1.99999999999999982e-21 < (*.f64 x y) < 2.0000000000000002e50Initial program 99.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6496.1
Applied rewrites96.1%
if 2.0000000000000002e50 < (*.f64 x y) Initial program 100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.4
Applied rewrites88.4%
Final simplification92.1%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -2e-21) (fma b a (* x y)) (if (<= (* x y) 2e+50) (fma b a (* z t)) (fma y x (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2e-21) {
tmp = fma(b, a, (x * y));
} else if ((x * y) <= 2e+50) {
tmp = fma(b, a, (z * t));
} else {
tmp = fma(y, x, (z * t));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2e-21) tmp = fma(b, a, Float64(x * y)); elseif (Float64(x * y) <= 2e+50) tmp = fma(b, a, Float64(z * t)); else tmp = fma(y, x, Float64(z * t)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2e-21], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+50], N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(z * t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+50}:\\
\;\;\;\;\mathsf{fma}\left(b, a, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z \cdot t\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999982e-21Initial program 95.5%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6483.9
Applied rewrites83.9%
if -1.99999999999999982e-21 < (*.f64 x y) < 2.0000000000000002e50Initial program 99.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6496.1
Applied rewrites96.1%
if 2.0000000000000002e50 < (*.f64 x y) Initial program 100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.4
Applied rewrites88.4%
Final simplification91.3%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma b a (* x y)))) (if (<= (* x y) -2e-21) t_1 (if (<= (* x y) 2e+62) (fma b a (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, a, (x * y));
double tmp;
if ((x * y) <= -2e-21) {
tmp = t_1;
} else if ((x * y) <= 2e+62) {
tmp = fma(b, a, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, a, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -2e-21) tmp = t_1; elseif (Float64(x * y) <= 2e+62) tmp = fma(b, a, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2e-21], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 2e+62], N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-21}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+62}:\\
\;\;\;\;\mathsf{fma}\left(b, a, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999982e-21 or 2.00000000000000007e62 < (*.f64 x y) Initial program 97.5%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6482.7
Applied rewrites82.7%
if -1.99999999999999982e-21 < (*.f64 x y) < 2.00000000000000007e62Initial program 99.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6496.2
Applied rewrites96.2%
Final simplification90.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -6.2e+136) (* z t) (if (<= (* z t) 1.6e+190) (fma b a (* x y)) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -6.2e+136) {
tmp = z * t;
} else if ((z * t) <= 1.6e+190) {
tmp = fma(b, a, (x * y));
} else {
tmp = z * t;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -6.2e+136) tmp = Float64(z * t); elseif (Float64(z * t) <= 1.6e+190) tmp = fma(b, a, Float64(x * y)); else tmp = Float64(z * t); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -6.2e+136], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1.6e+190], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -6.2 \cdot 10^{+136}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 1.6 \cdot 10^{+190}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -6.19999999999999967e136 or 1.6e190 < (*.f64 z t) Initial program 96.8%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6486.9
Applied rewrites86.9%
if -6.19999999999999967e136 < (*.f64 z t) < 1.6e190Initial program 98.9%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6483.6
Applied rewrites83.6%
Final simplification84.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -1e+37) (* x y) (if (<= (* x y) 2e+50) (* a b) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1e+37) {
tmp = x * y;
} else if ((x * y) <= 2e+50) {
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) <= (-1d+37)) then
tmp = x * y
else if ((x * y) <= 2d+50) 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) <= -1e+37) {
tmp = x * y;
} else if ((x * y) <= 2e+50) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -1e+37: tmp = x * y elif (x * y) <= 2e+50: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -1e+37) tmp = Float64(x * y); elseif (Float64(x * y) <= 2e+50) 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) <= -1e+37) tmp = x * y; elseif ((x * y) <= 2e+50) 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], -1e+37], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+50], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+37}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+50}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -9.99999999999999954e36 or 2.0000000000000002e50 < (*.f64 x y) Initial program 97.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6468.3
Applied rewrites68.3%
if -9.99999999999999954e36 < (*.f64 x y) < 2.0000000000000002e50Initial program 99.3%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6452.3
Applied rewrites52.3%
Final simplification59.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.4%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6438.4
Applied rewrites38.4%
Final simplification38.4%
herbie shell --seed 2024248
(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)))