
(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 (+ (* 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.8%
Final simplification98.8%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -8.2e+90)
(* a b)
(if (<= (* a b) 6e-198)
(* x y)
(if (<= (* a b) 1.85e+84) (* 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+90) {
tmp = a * b;
} else if ((a * b) <= 6e-198) {
tmp = x * y;
} else if ((a * b) <= 1.85e+84) {
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+90)) then
tmp = a * b
else if ((a * b) <= 6d-198) then
tmp = x * y
else if ((a * b) <= 1.85d+84) 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+90) {
tmp = a * b;
} else if ((a * b) <= 6e-198) {
tmp = x * y;
} else if ((a * b) <= 1.85e+84) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -8.2e+90: tmp = a * b elif (a * b) <= 6e-198: tmp = x * y elif (a * b) <= 1.85e+84: 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+90) tmp = Float64(a * b); elseif (Float64(a * b) <= 6e-198) tmp = Float64(x * y); elseif (Float64(a * b) <= 1.85e+84) 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+90) tmp = a * b; elseif ((a * b) <= 6e-198) tmp = x * y; elseif ((a * b) <= 1.85e+84) 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+90], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 6e-198], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.85e+84], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -8.2 \cdot 10^{+90}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 6 \cdot 10^{-198}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 1.85 \cdot 10^{+84}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -8.20000000000000083e90 or 1.85e84 < (*.f64 a b) Initial program 96.9%
Taylor expanded in a around inf
*-lowering-*.f6470.5%
Simplified70.5%
if -8.20000000000000083e90 < (*.f64 a b) < 6.0000000000000002e-198Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f6455.0%
Simplified55.0%
if 6.0000000000000002e-198 < (*.f64 a b) < 1.85e84Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6462.3%
Simplified62.3%
Final simplification62.3%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -8.2e+90) (+ (* a b) (* z t)) (if (<= (* a b) 1.32e+77) (+ (* x y) (* z t)) (+ (* x y) (* a b)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -8.2e+90) {
tmp = (a * b) + (z * t);
} else if ((a * b) <= 1.32e+77) {
tmp = (x * y) + (z * t);
} else {
tmp = (x * y) + (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+90)) then
tmp = (a * b) + (z * t)
else if ((a * b) <= 1.32d+77) then
tmp = (x * y) + (z * t)
else
tmp = (x * y) + (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+90) {
tmp = (a * b) + (z * t);
} else if ((a * b) <= 1.32e+77) {
tmp = (x * y) + (z * t);
} else {
tmp = (x * y) + (a * b);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -8.2e+90: tmp = (a * b) + (z * t) elif (a * b) <= 1.32e+77: tmp = (x * y) + (z * t) else: tmp = (x * y) + (a * b) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -8.2e+90) tmp = Float64(Float64(a * b) + Float64(z * t)); elseif (Float64(a * b) <= 1.32e+77) tmp = Float64(Float64(x * y) + Float64(z * t)); else tmp = Float64(Float64(x * y) + 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+90) tmp = (a * b) + (z * t); elseif ((a * b) <= 1.32e+77) tmp = (x * y) + (z * t); else tmp = (x * y) + (a * b); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -8.2e+90], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.32e+77], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -8.2 \cdot 10^{+90}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 1.32 \cdot 10^{+77}:\\
\;\;\;\;x \cdot y + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -8.20000000000000083e90Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6497.6%
Simplified97.6%
if -8.20000000000000083e90 < (*.f64 a b) < 1.32e77Initial program 100.0%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6494.2%
Simplified94.2%
if 1.32e77 < (*.f64 a b) Initial program 94.9%
Taylor expanded in x around inf
*-lowering-*.f6488.4%
Simplified88.4%
Final simplification93.4%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ (* a b) (* z t))))
(if (<= (* a b) -3.4e+89)
t_1
(if (<= (* a b) 2.3e+83) (+ (* x y) (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + (z * t);
double tmp;
if ((a * b) <= -3.4e+89) {
tmp = t_1;
} else if ((a * b) <= 2.3e+83) {
tmp = (x * y) + (z * t);
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_1 = (a * b) + (z * t)
if ((a * b) <= (-3.4d+89)) then
tmp = t_1
else if ((a * b) <= 2.3d+83) then
tmp = (x * y) + (z * t)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + (z * t);
double tmp;
if ((a * b) <= -3.4e+89) {
tmp = t_1;
} else if ((a * b) <= 2.3e+83) {
tmp = (x * y) + (z * t);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (a * b) + (z * t) tmp = 0 if (a * b) <= -3.4e+89: tmp = t_1 elif (a * b) <= 2.3e+83: tmp = (x * y) + (z * t) else: tmp = t_1 return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(a * b) + Float64(z * t)) tmp = 0.0 if (Float64(a * b) <= -3.4e+89) tmp = t_1; elseif (Float64(a * b) <= 2.3e+83) tmp = Float64(Float64(x * y) + Float64(z * t)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (a * b) + (z * t); tmp = 0.0; if ((a * b) <= -3.4e+89) tmp = t_1; elseif ((a * b) <= 2.3e+83) tmp = (x * y) + (z * t); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -3.4e+89], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 2.3e+83], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
\mathbf{if}\;a \cdot b \leq -3.4 \cdot 10^{+89}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 2.3 \cdot 10^{+83}:\\
\;\;\;\;x \cdot y + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -3.4000000000000002e89 or 2.29999999999999995e83 < (*.f64 a b) Initial program 96.9%
Taylor expanded in x around 0
*-lowering-*.f6486.1%
Simplified86.1%
if -3.4000000000000002e89 < (*.f64 a b) < 2.29999999999999995e83Initial program 100.0%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6494.3%
Simplified94.3%
Final simplification91.1%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -2.5e+189) (* x y) (if (<= (* x y) 3.8e+181) (+ (* a b) (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2.5e+189) {
tmp = x * y;
} else if ((x * y) <= 3.8e+181) {
tmp = (a * b) + (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) <= (-2.5d+189)) then
tmp = x * y
else if ((x * y) <= 3.8d+181) then
tmp = (a * b) + (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) <= -2.5e+189) {
tmp = x * y;
} else if ((x * y) <= 3.8e+181) {
tmp = (a * b) + (z * t);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -2.5e+189: tmp = x * y elif (x * y) <= 3.8e+181: tmp = (a * b) + (z * t) else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2.5e+189) tmp = Float64(x * y); elseif (Float64(x * y) <= 3.8e+181) tmp = Float64(Float64(a * b) + 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) <= -2.5e+189) tmp = x * y; elseif ((x * y) <= 3.8e+181) tmp = (a * b) + (z * t); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2.5e+189], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 3.8e+181], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2.5 \cdot 10^{+189}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 3.8 \cdot 10^{+181}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -2.5000000000000002e189 or 3.8000000000000001e181 < (*.f64 x y) Initial program 98.4%
Taylor expanded in x around inf
*-lowering-*.f6485.7%
Simplified85.7%
if -2.5000000000000002e189 < (*.f64 x y) < 3.8000000000000001e181Initial program 99.0%
Taylor expanded in x around 0
*-lowering-*.f6481.0%
Simplified81.0%
Final simplification82.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1.7e+183) (* a b) (if (<= (* a b) 1.8e+83) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1.7e+183) {
tmp = a * b;
} else if ((a * b) <= 1.8e+83) {
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) <= (-1.7d+183)) then
tmp = a * b
else if ((a * b) <= 1.8d+83) 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) <= -1.7e+183) {
tmp = a * b;
} else if ((a * b) <= 1.8e+83) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1.7e+183: tmp = a * b elif (a * b) <= 1.8e+83: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1.7e+183) tmp = Float64(a * b); elseif (Float64(a * b) <= 1.8e+83) 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) <= -1.7e+183) tmp = a * b; elseif ((a * b) <= 1.8e+83) 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], -1.7e+183], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.8e+83], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.7 \cdot 10^{+183}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 1.8 \cdot 10^{+83}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.7e183 or 1.7999999999999999e83 < (*.f64 a b) Initial program 96.5%
Taylor expanded in a around inf
*-lowering-*.f6476.3%
Simplified76.3%
if -1.7e183 < (*.f64 a b) < 1.7999999999999999e83Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6448.8%
Simplified48.8%
Final simplification58.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.8%
Taylor expanded in a around inf
*-lowering-*.f6431.9%
Simplified31.9%
herbie shell --seed 2024155
(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)))