
(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 x y (fma a b (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(x, y, fma(a, b, (z * t)));
}
function code(x, y, z, t, a, b) return fma(x, y, fma(a, b, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(x * y + N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)
\end{array}
Initial program 98.0%
associate-+l+98.0%
fma-def98.4%
+-commutative98.4%
fma-def98.8%
Simplified98.8%
Final simplification98.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 98.0%
fma-def98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -8.2e+99)
(* a b)
(if (<= (* a b) -2.3e-101)
(* z t)
(if (<= (* a b) -9.5e-157)
(* x y)
(if (<= (* a b) 1.3e-184)
(* z t)
(if (<= (* a b) 3.1e-149)
(* x y)
(if (<= (* a b) 2.8e+54) (* z t) (* a b))))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -8.2e+99) {
tmp = a * b;
} else if ((a * b) <= -2.3e-101) {
tmp = z * t;
} else if ((a * b) <= -9.5e-157) {
tmp = x * y;
} else if ((a * b) <= 1.3e-184) {
tmp = z * t;
} else if ((a * b) <= 3.1e-149) {
tmp = x * y;
} else if ((a * b) <= 2.8e+54) {
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) <= (-8.2d+99)) then
tmp = a * b
else if ((a * b) <= (-2.3d-101)) then
tmp = z * t
else if ((a * b) <= (-9.5d-157)) then
tmp = x * y
else if ((a * b) <= 1.3d-184) then
tmp = z * t
else if ((a * b) <= 3.1d-149) then
tmp = x * y
else if ((a * b) <= 2.8d+54) 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) <= -8.2e+99) {
tmp = a * b;
} else if ((a * b) <= -2.3e-101) {
tmp = z * t;
} else if ((a * b) <= -9.5e-157) {
tmp = x * y;
} else if ((a * b) <= 1.3e-184) {
tmp = z * t;
} else if ((a * b) <= 3.1e-149) {
tmp = x * y;
} else if ((a * b) <= 2.8e+54) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -8.2e+99: tmp = a * b elif (a * b) <= -2.3e-101: tmp = z * t elif (a * b) <= -9.5e-157: tmp = x * y elif (a * b) <= 1.3e-184: tmp = z * t elif (a * b) <= 3.1e-149: tmp = x * y elif (a * b) <= 2.8e+54: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -8.2e+99) tmp = Float64(a * b); elseif (Float64(a * b) <= -2.3e-101) tmp = Float64(z * t); elseif (Float64(a * b) <= -9.5e-157) tmp = Float64(x * y); elseif (Float64(a * b) <= 1.3e-184) tmp = Float64(z * t); elseif (Float64(a * b) <= 3.1e-149) tmp = Float64(x * y); elseif (Float64(a * b) <= 2.8e+54) 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) <= -8.2e+99) tmp = a * b; elseif ((a * b) <= -2.3e-101) tmp = z * t; elseif ((a * b) <= -9.5e-157) tmp = x * y; elseif ((a * b) <= 1.3e-184) tmp = z * t; elseif ((a * b) <= 3.1e-149) tmp = x * y; elseif ((a * b) <= 2.8e+54) 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], -8.2e+99], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2.3e-101], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -9.5e-157], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.3e-184], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 3.1e-149], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.8e+54], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -8.2 \cdot 10^{+99}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -2.3 \cdot 10^{-101}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq -9.5 \cdot 10^{-157}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 1.3 \cdot 10^{-184}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 3.1 \cdot 10^{-149}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 2.8 \cdot 10^{+54}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -8.19999999999999959e99 or 2.80000000000000015e54 < (*.f64 a b) Initial program 97.9%
Taylor expanded in a around inf 69.3%
if -8.19999999999999959e99 < (*.f64 a b) < -2.2999999999999999e-101 or -9.50000000000000019e-157 < (*.f64 a b) < 1.29999999999999989e-184 or 3.09999999999999987e-149 < (*.f64 a b) < 2.80000000000000015e54Initial program 98.5%
Taylor expanded in x around 0 69.2%
Taylor expanded in t around inf 56.3%
if -2.2999999999999999e-101 < (*.f64 a b) < -9.50000000000000019e-157 or 1.29999999999999989e-184 < (*.f64 a b) < 3.09999999999999987e-149Initial program 95.5%
Taylor expanded in x around inf 73.7%
Taylor expanded in x around inf 72.0%
Final simplification62.4%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -2.05e+183) (not (<= (* x y) 2.4e+147))) (* 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.05e+183) || !((x * y) <= 2.4e+147)) {
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.05d+183)) .or. (.not. ((x * y) <= 2.4d+147))) 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.05e+183) || !((x * y) <= 2.4e+147)) {
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.05e+183) or not ((x * y) <= 2.4e+147): 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.05e+183) || !(Float64(x * y) <= 2.4e+147)) 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.05e+183) || ~(((x * y) <= 2.4e+147))) 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.05e+183], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2.4e+147]], $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.05 \cdot 10^{+183} \lor \neg \left(x \cdot y \leq 2.4 \cdot 10^{+147}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -2.05000000000000007e183 or 2.40000000000000002e147 < (*.f64 x y) Initial program 93.0%
Taylor expanded in x around inf 82.5%
Taylor expanded in x around inf 78.9%
if -2.05000000000000007e183 < (*.f64 x y) < 2.40000000000000002e147Initial program 99.5%
Taylor expanded in x around 0 85.2%
Final simplification83.8%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -8e+111) (not (<= (* x y) 2.9e+89))) (+ (* 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) <= -8e+111) || !((x * y) <= 2.9e+89)) {
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) <= (-8d+111)) .or. (.not. ((x * y) <= 2.9d+89))) 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) <= -8e+111) || !((x * y) <= 2.9e+89)) {
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) <= -8e+111) or not ((x * y) <= 2.9e+89): 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) <= -8e+111) || !(Float64(x * y) <= 2.9e+89)) 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) <= -8e+111) || ~(((x * y) <= 2.9e+89))) 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], -8e+111], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2.9e+89]], $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 -8 \cdot 10^{+111} \lor \neg \left(x \cdot y \leq 2.9 \cdot 10^{+89}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -7.99999999999999965e111 or 2.90000000000000025e89 < (*.f64 x y) Initial program 95.0%
Taylor expanded in x around inf 79.2%
if -7.99999999999999965e111 < (*.f64 x y) < 2.90000000000000025e89Initial program 99.4%
Taylor expanded in x around 0 88.8%
Final simplification85.8%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -1.1e+100) (not (<= (* a b) 3.6e+54))) (* a b) (* z t)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -1.1e+100) || !((a * b) <= 3.6e+54)) {
tmp = a * b;
} else {
tmp = 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 (((a * b) <= (-1.1d+100)) .or. (.not. ((a * b) <= 3.6d+54))) then
tmp = a * b
else
tmp = 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 (((a * b) <= -1.1e+100) || !((a * b) <= 3.6e+54)) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -1.1e+100) or not ((a * b) <= 3.6e+54): tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -1.1e+100) || !(Float64(a * b) <= 3.6e+54)) tmp = Float64(a * b); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((a * b) <= -1.1e+100) || ~(((a * b) <= 3.6e+54))) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -1.1e+100], N[Not[LessEqual[N[(a * b), $MachinePrecision], 3.6e+54]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.1 \cdot 10^{+100} \lor \neg \left(a \cdot b \leq 3.6 \cdot 10^{+54}\right):\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 a b) < -1.1e100 or 3.6000000000000001e54 < (*.f64 a b) Initial program 97.9%
Taylor expanded in a around inf 69.3%
if -1.1e100 < (*.f64 a b) < 3.6000000000000001e54Initial program 98.1%
Taylor expanded in x around 0 63.9%
Taylor expanded in t around inf 52.7%
Final simplification58.8%
(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 98.0%
Final simplification98.0%
(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.0%
Taylor expanded in a around inf 34.0%
Final simplification34.0%
herbie shell --seed 2023298
(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)))