
(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 a b (fma x y (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(a, b, fma(x, y, (z * t)));
}
function code(x, y, z, t, a, b) return fma(a, b, fma(x, y, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(a * b + N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(a, b, \mathsf{fma}\left(x, y, z \cdot t\right)\right)
\end{array}
Initial program 97.7%
+-commutative97.7%
fma-define98.4%
fma-define98.8%
Simplified98.8%
(FPCore (x y z t a b) :precision binary64 (+ (fma x y (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return fma(x, y, (z * t)) + (a * b);
}
function code(x, y, z, t, a, b) return Float64(fma(x, y, Float64(z * t)) + Float64(a * b)) end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, z \cdot t\right) + a \cdot b
\end{array}
Initial program 97.7%
fma-define98.0%
Simplified98.0%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* x y) -5.6e+94)
(* x y)
(if (<= (* x y) -4.4e+61)
(* a b)
(if (<= (* x y) -4.6e-72)
(* x y)
(if (<= (* x y) -7.6e-173)
(* a b)
(if (<= (* x y) 3.55e+15) (* z t) (* x y)))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -5.6e+94) {
tmp = x * y;
} else if ((x * y) <= -4.4e+61) {
tmp = a * b;
} else if ((x * y) <= -4.6e-72) {
tmp = x * y;
} else if ((x * y) <= -7.6e-173) {
tmp = a * b;
} else if ((x * y) <= 3.55e+15) {
tmp = z * t;
} 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) <= (-5.6d+94)) then
tmp = x * y
else if ((x * y) <= (-4.4d+61)) then
tmp = a * b
else if ((x * y) <= (-4.6d-72)) then
tmp = x * y
else if ((x * y) <= (-7.6d-173)) then
tmp = a * b
else if ((x * y) <= 3.55d+15) then
tmp = z * t
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) <= -5.6e+94) {
tmp = x * y;
} else if ((x * y) <= -4.4e+61) {
tmp = a * b;
} else if ((x * y) <= -4.6e-72) {
tmp = x * y;
} else if ((x * y) <= -7.6e-173) {
tmp = a * b;
} else if ((x * y) <= 3.55e+15) {
tmp = z * t;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -5.6e+94: tmp = x * y elif (x * y) <= -4.4e+61: tmp = a * b elif (x * y) <= -4.6e-72: tmp = x * y elif (x * y) <= -7.6e-173: tmp = a * b elif (x * y) <= 3.55e+15: tmp = z * t else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -5.6e+94) tmp = Float64(x * y); elseif (Float64(x * y) <= -4.4e+61) tmp = Float64(a * b); elseif (Float64(x * y) <= -4.6e-72) tmp = Float64(x * y); elseif (Float64(x * y) <= -7.6e-173) tmp = Float64(a * b); elseif (Float64(x * y) <= 3.55e+15) tmp = Float64(z * t); 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) <= -5.6e+94) tmp = x * y; elseif ((x * y) <= -4.4e+61) tmp = a * b; elseif ((x * y) <= -4.6e-72) tmp = x * y; elseif ((x * y) <= -7.6e-173) tmp = a * b; elseif ((x * y) <= 3.55e+15) tmp = z * t; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -5.6e+94], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -4.4e+61], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -4.6e-72], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -7.6e-173], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 3.55e+15], N[(z * t), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5.6 \cdot 10^{+94}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq -4.4 \cdot 10^{+61}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq -4.6 \cdot 10^{-72}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq -7.6 \cdot 10^{-173}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq 3.55 \cdot 10^{+15}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -5.59999999999999997e94 or -4.4000000000000001e61 < (*.f64 x y) < -4.59999999999999989e-72 or 3.55e15 < (*.f64 x y) Initial program 95.5%
associate-+l+95.5%
fma-define97.0%
fma-define97.0%
Simplified97.0%
Taylor expanded in x around inf 69.6%
if -5.59999999999999997e94 < (*.f64 x y) < -4.4000000000000001e61 or -4.59999999999999989e-72 < (*.f64 x y) < -7.6000000000000006e-173Initial program 100.0%
associate-+l+100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in a around inf 64.0%
if -7.6000000000000006e-173 < (*.f64 x y) < 3.55e15Initial program 100.0%
associate-+l+100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 56.5%
Final simplification64.0%
(FPCore (x y z t a b)
:precision binary64
(if (or (<= (* x y) -2.25e+98)
(not
(or (<= (* x y) -5.6e-24)
(and (not (<= (* x y) -4.6e-72)) (<= (* x y) 6.2e+88)))))
(* x y)
(+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -2.25e+98) || !(((x * y) <= -5.6e-24) || (!((x * y) <= -4.6e-72) && ((x * y) <= 6.2e+88)))) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
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.25d+98)) .or. (.not. ((x * y) <= (-5.6d-24)) .or. (.not. ((x * y) <= (-4.6d-72))) .and. ((x * y) <= 6.2d+88))) then
tmp = x * y
else
tmp = (a * b) + (z * t)
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.25e+98) || !(((x * y) <= -5.6e-24) || (!((x * y) <= -4.6e-72) && ((x * y) <= 6.2e+88)))) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -2.25e+98) or not (((x * y) <= -5.6e-24) or (not ((x * y) <= -4.6e-72) and ((x * y) <= 6.2e+88))): tmp = x * y else: tmp = (a * b) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -2.25e+98) || !((Float64(x * y) <= -5.6e-24) || (!(Float64(x * y) <= -4.6e-72) && (Float64(x * y) <= 6.2e+88)))) tmp = Float64(x * y); else tmp = Float64(Float64(a * b) + Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((x * y) <= -2.25e+98) || ~((((x * y) <= -5.6e-24) || (~(((x * y) <= -4.6e-72)) && ((x * y) <= 6.2e+88))))) tmp = x * y; else tmp = (a * b) + (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -2.25e+98], N[Not[Or[LessEqual[N[(x * y), $MachinePrecision], -5.6e-24], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], -4.6e-72]], $MachinePrecision], LessEqual[N[(x * y), $MachinePrecision], 6.2e+88]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2.25 \cdot 10^{+98} \lor \neg \left(x \cdot y \leq -5.6 \cdot 10^{-24} \lor \neg \left(x \cdot y \leq -4.6 \cdot 10^{-72}\right) \land x \cdot y \leq 6.2 \cdot 10^{+88}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -2.2500000000000001e98 or -5.6000000000000003e-24 < (*.f64 x y) < -4.59999999999999989e-72 or 6.2000000000000003e88 < (*.f64 x y) Initial program 94.0%
associate-+l+94.0%
fma-define96.0%
fma-define96.0%
Simplified96.0%
Taylor expanded in x around inf 79.1%
if -2.2500000000000001e98 < (*.f64 x y) < -5.6000000000000003e-24 or -4.59999999999999989e-72 < (*.f64 x y) < 6.2000000000000003e88Initial program 100.0%
associate-+l+100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around 0 87.1%
Final simplification84.0%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -2.8e-72) (not (<= (* x y) 1.02e+18))) (+ (* a b) (* x y)) (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -2.8e-72) || !((x * y) <= 1.02e+18)) {
tmp = (a * b) + (x * y);
} else {
tmp = (a * b) + (z * t);
}
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.8d-72)) .or. (.not. ((x * y) <= 1.02d+18))) then
tmp = (a * b) + (x * y)
else
tmp = (a * b) + (z * t)
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.8e-72) || !((x * y) <= 1.02e+18)) {
tmp = (a * b) + (x * y);
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -2.8e-72) or not ((x * y) <= 1.02e+18): tmp = (a * b) + (x * y) else: tmp = (a * b) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -2.8e-72) || !(Float64(x * y) <= 1.02e+18)) tmp = Float64(Float64(a * b) + Float64(x * y)); else tmp = Float64(Float64(a * b) + Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((x * y) <= -2.8e-72) || ~(((x * y) <= 1.02e+18))) tmp = (a * b) + (x * y); else tmp = (a * b) + (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -2.8e-72], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1.02e+18]], $MachinePrecision]], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2.8 \cdot 10^{-72} \lor \neg \left(x \cdot y \leq 1.02 \cdot 10^{+18}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -2.7999999999999998e-72 or 1.02e18 < (*.f64 x y) Initial program 95.8%
associate-+l+95.8%
fma-define97.2%
fma-define97.2%
Simplified97.2%
Taylor expanded in z around 0 82.5%
if -2.7999999999999998e-72 < (*.f64 x y) < 1.02e18Initial program 100.0%
associate-+l+100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around 0 94.2%
Final simplification87.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= t -5.8e-33) (not (<= t 9.4e+64))) (* z t) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t <= -5.8e-33) || !(t <= 9.4e+64)) {
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 ((t <= (-5.8d-33)) .or. (.not. (t <= 9.4d+64))) 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 ((t <= -5.8e-33) || !(t <= 9.4e+64)) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t <= -5.8e-33) or not (t <= 9.4e+64): tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((t <= -5.8e-33) || !(t <= 9.4e+64)) 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 ((t <= -5.8e-33) || ~((t <= 9.4e+64))) tmp = z * t; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[t, -5.8e-33], N[Not[LessEqual[t, 9.4e+64]], $MachinePrecision]], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.8 \cdot 10^{-33} \lor \neg \left(t \leq 9.4 \cdot 10^{+64}\right):\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if t < -5.80000000000000005e-33 or 9.40000000000000058e64 < t Initial program 97.0%
associate-+l+97.0%
fma-define97.8%
fma-define97.8%
Simplified97.8%
Taylor expanded in z around inf 54.4%
if -5.80000000000000005e-33 < t < 9.40000000000000058e64Initial program 98.3%
associate-+l+98.3%
fma-define99.2%
fma-define99.2%
Simplified99.2%
Taylor expanded in a around inf 45.1%
Final simplification50.0%
(FPCore (x y z t a b) :precision binary64 (+ (* a b) (+ (* x y) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + ((x * y) + (z * t));
}
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) + ((x * y) + (z * t))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + ((x * y) + (z * t));
}
def code(x, y, z, t, a, b): return (a * b) + ((x * y) + (z * t))
function code(x, y, z, t, a, b) return Float64(Float64(a * b) + Float64(Float64(x * y) + Float64(z * t))) end
function tmp = code(x, y, z, t, a, b) tmp = (a * b) + ((x * y) + (z * t)); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(a * b), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b + \left(x \cdot y + z \cdot t\right)
\end{array}
Initial program 97.7%
Final simplification97.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 97.7%
associate-+l+97.7%
fma-define98.4%
fma-define98.4%
Simplified98.4%
Taylor expanded in a around inf 30.7%
herbie shell --seed 2024111
(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)))