
(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 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 97.7%
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 (or (<= (* x y) -1e-97) (not (<= (* x y) 5e+155))) (fma b a (* x y)) (fma b a (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -1e-97) || !((x * y) <= 5e+155)) {
tmp = fma(b, a, (x * y));
} else {
tmp = fma(b, a, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -1e-97) || !(Float64(x * y) <= 5e+155)) tmp = fma(b, a, Float64(x * y)); else tmp = fma(b, a, Float64(t * z)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -1e-97], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5e+155]], $MachinePrecision]], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-97} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{+155}\right):\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.00000000000000004e-97 or 4.9999999999999999e155 < (*.f64 x y) Initial program 96.5%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6484.1
Applied rewrites84.1%
if -1.00000000000000004e-97 < (*.f64 x y) < 4.9999999999999999e155Initial program 98.6%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6493.7
Applied rewrites93.7%
Final simplification89.4%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* t z) -1.05e+140) (not (<= (* t z) 9.8e+250))) (* t z) (fma b a (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((t * z) <= -1.05e+140) || !((t * z) <= 9.8e+250)) {
tmp = t * z;
} else {
tmp = fma(b, a, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(t * z) <= -1.05e+140) || !(Float64(t * z) <= 9.8e+250)) tmp = Float64(t * z); else tmp = fma(b, a, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(t * z), $MachinePrecision], -1.05e+140], N[Not[LessEqual[N[(t * z), $MachinePrecision], 9.8e+250]], $MachinePrecision]], N[(t * z), $MachinePrecision], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -1.05 \cdot 10^{+140} \lor \neg \left(t \cdot z \leq 9.8 \cdot 10^{+250}\right):\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -1.0500000000000001e140 or 9.79999999999999986e250 < (*.f64 z t) Initial program 91.9%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6485.4
Applied rewrites85.4%
if -1.0500000000000001e140 < (*.f64 z t) < 9.79999999999999986e250Initial program 99.5%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6481.7
Applied rewrites81.7%
Final simplification82.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -0.001) (fma y x (* t z)) (if (<= (* x y) 5e+155) (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) <= -0.001) {
tmp = fma(y, x, (t * z));
} else if ((x * y) <= 5e+155) {
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) <= -0.001) tmp = fma(y, x, Float64(t * z)); elseif (Float64(x * y) <= 5e+155) 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], -0.001], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+155], 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 -0.001:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+155}:\\
\;\;\;\;\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) < -1e-3Initial program 93.8%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6480.3
Applied rewrites80.3%
if -1e-3 < (*.f64 x y) < 4.9999999999999999e155Initial program 98.7%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.4
Applied rewrites92.4%
if 4.9999999999999999e155 < (*.f64 x y) Initial program 100.0%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6494.3
Applied rewrites94.3%
Final simplification89.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -500.0) (not (<= (* a b) 2e+15))) (* a b) (* t z)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -500.0) || !((a * b) <= 2e+15)) {
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 (((a * b) <= (-500.0d0)) .or. (.not. ((a * b) <= 2d+15))) 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 (((a * b) <= -500.0) || !((a * b) <= 2e+15)) {
tmp = a * b;
} else {
tmp = t * z;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -500.0) or not ((a * b) <= 2e+15): tmp = a * b else: tmp = t * z return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -500.0) || !(Float64(a * b) <= 2e+15)) 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 (((a * b) <= -500.0) || ~(((a * b) <= 2e+15))) tmp = a * b; else tmp = t * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -500.0], N[Not[LessEqual[N[(a * b), $MachinePrecision], 2e+15]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(t * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -500 \lor \neg \left(a \cdot b \leq 2 \cdot 10^{+15}\right):\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if (*.f64 a b) < -500 or 2e15 < (*.f64 a b) Initial program 96.4%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6464.8
Applied rewrites64.8%
if -500 < (*.f64 a b) < 2e15Initial program 99.1%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6456.8
Applied rewrites56.8%
Final simplification61.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -0.001) (not (<= (* x y) 5e+155))) (* x y) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -0.001) || !((x * y) <= 5e+155)) {
tmp = x * y;
} 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 (((x * y) <= (-0.001d0)) .or. (.not. ((x * y) <= 5d+155))) then
tmp = x * y
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 (((x * y) <= -0.001) || !((x * y) <= 5e+155)) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -0.001) or not ((x * y) <= 5e+155): tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -0.001) || !(Float64(x * y) <= 5e+155)) tmp = Float64(x * y); else tmp = Float64(a * b); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((x * y) <= -0.001) || ~(((x * y) <= 5e+155))) tmp = x * y; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -0.001], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5e+155]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -0.001 \lor \neg \left(x \cdot y \leq 5 \cdot 10^{+155}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 x y) < -1e-3 or 4.9999999999999999e155 < (*.f64 x y) Initial program 96.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6466.6
Applied rewrites66.6%
if -1e-3 < (*.f64 x y) < 4.9999999999999999e155Initial program 98.7%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6450.6
Applied rewrites50.6%
Final simplification56.8%
(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 97.7%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6439.8
Applied rewrites39.8%
Final simplification39.8%
herbie shell --seed 2024271
(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)))