
(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.f6499.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.2%
Final simplification99.2%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* t z) -1.85e-35)
(* t z)
(if (<= (* t z) -9.5e-183)
(* x y)
(if (<= (* t z) 8.6e-275)
(* a b)
(if (<= (* t z) 8.2e+37) (* x y) (* t z))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t * z) <= -1.85e-35) {
tmp = t * z;
} else if ((t * z) <= -9.5e-183) {
tmp = x * y;
} else if ((t * z) <= 8.6e-275) {
tmp = a * b;
} else if ((t * z) <= 8.2e+37) {
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) <= (-1.85d-35)) then
tmp = t * z
else if ((t * z) <= (-9.5d-183)) then
tmp = x * y
else if ((t * z) <= 8.6d-275) then
tmp = a * b
else if ((t * z) <= 8.2d+37) 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) <= -1.85e-35) {
tmp = t * z;
} else if ((t * z) <= -9.5e-183) {
tmp = x * y;
} else if ((t * z) <= 8.6e-275) {
tmp = a * b;
} else if ((t * z) <= 8.2e+37) {
tmp = x * y;
} else {
tmp = t * z;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t * z) <= -1.85e-35: tmp = t * z elif (t * z) <= -9.5e-183: tmp = x * y elif (t * z) <= 8.6e-275: tmp = a * b elif (t * z) <= 8.2e+37: tmp = x * y else: tmp = t * z return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(t * z) <= -1.85e-35) tmp = Float64(t * z); elseif (Float64(t * z) <= -9.5e-183) tmp = Float64(x * y); elseif (Float64(t * z) <= 8.6e-275) tmp = Float64(a * b); elseif (Float64(t * z) <= 8.2e+37) 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) <= -1.85e-35) tmp = t * z; elseif ((t * z) <= -9.5e-183) tmp = x * y; elseif ((t * z) <= 8.6e-275) tmp = a * b; elseif ((t * z) <= 8.2e+37) 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], -1.85e-35], N[(t * z), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], -9.5e-183], N[(x * y), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 8.6e-275], N[(a * b), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 8.2e+37], N[(x * y), $MachinePrecision], N[(t * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -1.85 \cdot 10^{-35}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;t \cdot z \leq -9.5 \cdot 10^{-183}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;t \cdot z \leq 8.6 \cdot 10^{-275}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;t \cdot z \leq 8.2 \cdot 10^{+37}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if (*.f64 z t) < -1.8499999999999999e-35 or 8.1999999999999996e37 < (*.f64 z t) Initial program 97.6%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6467.1
Applied rewrites67.1%
if -1.8499999999999999e-35 < (*.f64 z t) < -9.5000000000000008e-183 or 8.59999999999999953e-275 < (*.f64 z t) < 8.1999999999999996e37Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6454.2
Applied rewrites54.2%
if -9.5000000000000008e-183 < (*.f64 z t) < 8.59999999999999953e-275Initial program 100.0%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6463.4
Applied rewrites63.4%
Final simplification62.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -4e+78) (fma y x (* t z)) (if (<= (* x y) 4e+26) (fma z t (* a b)) (fma b a (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -4e+78) {
tmp = fma(y, x, (t * z));
} else if ((x * y) <= 4e+26) {
tmp = fma(z, t, (a * b));
} else {
tmp = fma(b, a, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -4e+78) tmp = fma(y, x, Float64(t * z)); elseif (Float64(x * y) <= 4e+26) tmp = fma(z, t, Float64(a * b)); else tmp = fma(b, a, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -4e+78], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 4e+26], N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -4 \cdot 10^{+78}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{+26}:\\
\;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -4.00000000000000003e78Initial program 96.0%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.9
Applied rewrites92.9%
if -4.00000000000000003e78 < (*.f64 x y) < 4.00000000000000019e26Initial program 99.3%
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
*-commutativeN/A
lower-*.f6493.2
Applied rewrites93.2%
if 4.00000000000000019e26 < (*.f64 x y) Initial program 100.0%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.1
Applied rewrites85.1%
Final simplification91.1%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -4e+78) (fma y x (* t z)) (if (<= (* x y) 4e+26) (fma b a (* t z)) (fma b a (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -4e+78) {
tmp = fma(y, x, (t * z));
} else if ((x * y) <= 4e+26) {
tmp = fma(b, a, (t * z));
} else {
tmp = fma(b, a, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -4e+78) tmp = fma(y, x, Float64(t * z)); elseif (Float64(x * y) <= 4e+26) tmp = fma(b, a, Float64(t * z)); else tmp = fma(b, a, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -4e+78], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 4e+26], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -4 \cdot 10^{+78}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{+26}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -4.00000000000000003e78Initial program 96.0%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.9
Applied rewrites92.9%
if -4.00000000000000003e78 < (*.f64 x y) < 4.00000000000000019e26Initial program 99.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.5
Applied rewrites92.5%
if 4.00000000000000019e26 < (*.f64 x y) Initial program 100.0%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.1
Applied rewrites85.1%
Final simplification90.8%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma b a (* t z))))
(if (<= (* t z) -1.85e-35)
t_1
(if (<= (* t z) 8.2e+37) (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) <= -1.85e-35) {
tmp = t_1;
} else if ((t * z) <= 8.2e+37) {
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) <= -1.85e-35) tmp = t_1; elseif (Float64(t * z) <= 8.2e+37) 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], -1.85e-35], t$95$1, If[LessEqual[N[(t * z), $MachinePrecision], 8.2e+37], 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 -1.85 \cdot 10^{-35}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \cdot z \leq 8.2 \cdot 10^{+37}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -1.8499999999999999e-35 or 8.1999999999999996e37 < (*.f64 z t) Initial program 97.6%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6484.3
Applied rewrites84.3%
if -1.8499999999999999e-35 < (*.f64 z t) < 8.1999999999999996e37Initial program 100.0%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.0
Applied rewrites92.0%
Final simplification88.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* t z) -7e+197) (* t z) (if (<= (* t z) 2.2e+193) (fma b a (* x y)) (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t * z) <= -7e+197) {
tmp = t * z;
} else if ((t * z) <= 2.2e+193) {
tmp = fma(b, a, (x * y));
} else {
tmp = t * z;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(t * z) <= -7e+197) tmp = Float64(t * z); elseif (Float64(t * z) <= 2.2e+193) tmp = fma(b, a, Float64(x * y)); else tmp = Float64(t * z); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(t * z), $MachinePrecision], -7e+197], N[(t * z), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 2.2e+193], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -7 \cdot 10^{+197}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;t \cdot z \leq 2.2 \cdot 10^{+193}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if (*.f64 z t) < -6.99999999999999999e197 or 2.19999999999999986e193 < (*.f64 z t) Initial program 95.4%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6487.7
Applied rewrites87.7%
if -6.99999999999999999e197 < (*.f64 z t) < 2.19999999999999986e193Initial program 100.0%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6480.9
Applied rewrites80.9%
Final simplification82.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -2e+93) (* x y) (if (<= (* x y) 2000000000.0) (* a b) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2e+93) {
tmp = x * y;
} else if ((x * y) <= 2000000000.0) {
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) <= (-2d+93)) then
tmp = x * y
else if ((x * y) <= 2000000000.0d0) 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) <= -2e+93) {
tmp = x * y;
} else if ((x * y) <= 2000000000.0) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -2e+93: tmp = x * y elif (x * y) <= 2000000000.0: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2e+93) tmp = Float64(x * y); elseif (Float64(x * y) <= 2000000000.0) 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) <= -2e+93) tmp = x * y; elseif ((x * y) <= 2000000000.0) 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], -2e+93], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2000000000.0], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+93}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 2000000000:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -2.00000000000000009e93 or 2e9 < (*.f64 x y) Initial program 99.1%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6465.1
Applied rewrites65.1%
if -2.00000000000000009e93 < (*.f64 x y) < 2e9Initial program 98.5%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6447.9
Applied rewrites47.9%
Final simplification55.7%
(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-*.f6433.7
Applied rewrites33.7%
Final simplification33.7%
herbie shell --seed 2024249
(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)))